Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
b42adadd
R
runtime
项目概览
dotNET Platform
/
runtime
大约 1 年 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b42adadd
编写于
4月 25, 2022
作者:
S
Stephen Toub
提交者:
GitHub
4月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix nullable reference type warnings in RegexGenerator (#68516)
上级
ffe71b9a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
19 deletion
+19
-19
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs
...tem.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs
+15
-15
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Parser.cs
...stem.Text.RegularExpressions/gen/RegexGenerator.Parser.cs
+1
-1
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs
...ries/System.Text.RegularExpressions/gen/RegexGenerator.cs
+3
-3
未找到文件。
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs
浏览文件 @
b42adadd
...
...
@@ -917,7 +917,7 @@ void EmitLiteralAfterAtomicLoop()
Debug
.
Assert
(
target
.
LoopNode
.
Kind
is
RegexNodeKind
.
Setloop
or
RegexNodeKind
.
Setlazy
or
RegexNodeKind
.
Setloopatomic
);
Debug
.
Assert
(
target
.
LoopNode
.
N
==
int
.
MaxValue
);
writer
.
Write
(
$"// The pattern begins with an atomic loop for
{
DescribeSet
(
target
.
LoopNode
.
Str
)}
, followed by "
);
writer
.
Write
(
$"// The pattern begins with an atomic loop for
{
DescribeSet
(
target
.
LoopNode
.
Str
!
)}
, followed by "
);
writer
.
WriteLine
(
target
.
Literal
.
String
is
not
null
?
$"the string
{
Literal
(
target
.
Literal
.
String
)}
."
:
target
.
Literal
.
Chars
is
not
null
?
$"one of the characters
{
Literal
(
new
string
(
target
.
Literal
.
Chars
))}
"
:
...
...
@@ -1027,7 +1027,7 @@ private static void EmitTryMatchAtCurrentPosition(IndentedTextWriter writer, Reg
// Helper to define names. Names start unadorned, but as soon as there's repetition,
// they begin to have a numbered suffix.
var
usedNames
=
new
Dictionary
<
string
,
int
>
();
Dictionary
<
string
,
int
>
usedNames
=
new
();
// Every RegexTree is rooted in the implicit Capture for the whole expression.
// Skip the Capture node. We handle the implicit root capture specially.
...
...
@@ -1039,8 +1039,8 @@ private static void EmitTryMatchAtCurrentPosition(IndentedTextWriter writer, Reg
// In some cases, we need to emit declarations at the beginning of the method, but we only discover we need them later.
// To handle that, we build up a collection of all the declarations to include, track where they should be inserted,
// and then insert them at that position once everything else has been output.
var
additionalDeclarations
=
new
HashSet
<
string
>
();
var
additionalLocalFunctions
=
new
Dictionary
<
string
,
string
[
]>
();
HashSet
<
string
>
additionalDeclarations
=
new
();
Dictionary
<
string
,
string
[
]>
additionalLocalFunctions
=
new
();
// Declare some locals.
string
sliceSpan
=
"slice"
;
...
...
@@ -3217,7 +3217,7 @@ void EmitLazy(RegexNode node)
// additional checks if we can prove that the loop can never match empty, which we can do by computing
// the minimum length of the child; only if it's 0 might iterations be empty.
bool
iterationMayBeEmpty
=
child
.
ComputeMinLength
()
==
0
;
string
startingPos
=
null
,
sawEmpty
=
null
;
string
?
startingPos
=
null
,
sawEmpty
=
null
;
if
(
iterationMayBeEmpty
)
{
startingPos
=
ReserveName
(
"lazyloop_starting_pos"
);
...
...
@@ -3243,8 +3243,8 @@ void EmitLazy(RegexNode node)
// iterations, this state needs to be stored on to the backtracking stack.
int
entriesPerIteration
=
1
/*pos*/
+
(
iterationMayBeEmpty
?
2
/*startingPos+sawEmpty*/
:
0
)
+
(
expressionHasCaptures
?
1
/*Crawlpos*/
:
0
);
EmitStackPush
(
expressionHasCaptures
&&
iterationMayBeEmpty
?
new
[]
{
"pos"
,
startingPos
,
sawEmpty
,
"base.Crawlpos()"
}
:
iterationMayBeEmpty
?
new
[]
{
"pos"
,
startingPos
,
sawEmpty
}
:
expressionHasCaptures
&&
iterationMayBeEmpty
?
new
[]
{
"pos"
,
startingPos
!,
sawEmpty
!
,
"base.Crawlpos()"
}
:
iterationMayBeEmpty
?
new
[]
{
"pos"
,
startingPos
!,
sawEmpty
!
}
:
expressionHasCaptures
?
new
[]
{
"pos"
,
"base.Crawlpos()"
}
:
new
[]
{
"pos"
});
...
...
@@ -3323,7 +3323,7 @@ void EmitLazy(RegexNode node)
EmitUncaptureUntil
(
StackPop
());
}
EmitStackPop
(
iterationMayBeEmpty
?
new
[]
{
sawEmpty
,
startingPos
,
"pos"
}
:
new
[]
{
sawEmpty
!,
startingPos
!
,
"pos"
}
:
new
[]
{
"pos"
});
SliceInputSpan
();
...
...
@@ -3373,7 +3373,7 @@ void EmitLazy(RegexNode node)
if
(
rm
.
Analysis
.
IsInLoop
(
node
))
{
EmitStackPush
(
iterationMayBeEmpty
?
new
[]
{
iterationCount
,
startingPos
,
sawEmpty
}
:
new
[]
{
iterationCount
,
startingPos
!,
sawEmpty
!
}
:
new
[]
{
iterationCount
});
}
...
...
@@ -3392,7 +3392,7 @@ void EmitLazy(RegexNode node)
if
(
rm
.
Analysis
.
IsInLoop
(
node
))
{
EmitStackPop
(
iterationMayBeEmpty
?
new
[]
{
sawEmpty
,
startingPos
,
iterationCount
}
:
new
[]
{
sawEmpty
!,
startingPos
!
,
iterationCount
}
:
new
[]
{
iterationCount
});
}
...
...
@@ -3818,9 +3818,9 @@ void EmitLoop(RegexNode node)
// here we still need the stack, because each iteration of _this_ loop may have its own state, e.g. we
// need to know where each iteration began so when backtracking we can jump back to that location.
EmitStackPush
(
expressionHasCaptures
&&
iterationMayBeEmpty
?
new
[]
{
"base.Crawlpos()"
,
startingPos
,
"pos"
}
:
expressionHasCaptures
&&
iterationMayBeEmpty
?
new
[]
{
"base.Crawlpos()"
,
startingPos
!
,
"pos"
}
:
expressionHasCaptures
?
new
[]
{
"base.Crawlpos()"
,
"pos"
}
:
iterationMayBeEmpty
?
new
[]
{
startingPos
,
"pos"
}
:
iterationMayBeEmpty
?
new
[]
{
startingPos
!
,
"pos"
}
:
new
[]
{
"pos"
});
writer
.
WriteLine
();
...
...
@@ -3928,7 +3928,7 @@ void EmitLoop(RegexNode node)
Goto
(
originalDoneLabel
);
}
EmitStackPop
(
iterationMayBeEmpty
?
new
[]
{
"pos"
,
startingPos
}
:
new
[]
{
"pos"
,
startingPos
!
}
:
new
[]
{
"pos"
});
if
(
expressionHasCaptures
)
{
...
...
@@ -4020,7 +4020,7 @@ void EmitLoop(RegexNode node)
// Store the loop's state
EmitStackPush
(
iterationMayBeEmpty
?
new
[]
{
startingPos
,
iterationCount
}
:
new
[]
{
startingPos
!
,
iterationCount
}
:
new
[]
{
iterationCount
});
// Skip past the backtracking section
...
...
@@ -4032,7 +4032,7 @@ void EmitLoop(RegexNode node)
string
backtrack
=
ReserveName
(
"LoopBacktrack"
);
MarkLabel
(
backtrack
,
emitSemicolon
:
false
);
EmitStackPop
(
iterationMayBeEmpty
?
new
[]
{
iterationCount
,
startingPos
}
:
new
[]
{
iterationCount
,
startingPos
!
}
:
new
[]
{
iterationCount
});
// We're backtracking. Check the timeout.
...
...
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Parser.cs
浏览文件 @
b42adadd
...
...
@@ -238,7 +238,7 @@ private static bool IsSemanticTargetForGeneration(SemanticModel semanticModel, M
/// <summary>A regex method.</summary>
internal
sealed
record
RegexMethod
(
RegexType
DeclaringType
,
MethodDeclarationSyntax
MethodSyntax
,
string
MethodName
,
string
Modifiers
,
string
Pattern
,
RegexOptions
Options
,
int
?
MatchTimeout
,
RegexTree
Tree
,
AnalysisResults
Analysis
)
{
public
string
GeneratedName
{
get
;
set
;
}
public
string
?
GeneratedName
{
get
;
set
;
}
public
bool
IsDuplicate
{
get
;
set
;
}
}
...
...
src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.cs
浏览文件 @
b42adadd
...
...
@@ -47,7 +47,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
// - Diagnostic in the case of a failure that should end the compilation
// - (RegexMethod regexMethod, string runnerFactoryImplementation, Dictionary<string, string[]> requiredHelpers) in the case of valid regex
// - (RegexMethod regexMethod, string reason, Diagnostic diagnostic) in the case of a limited-support regex
IncrementalValueProvider
<
ImmutableArray
<
object
?
>>
codeOrDiagnostics
=
IncrementalValueProvider
<
ImmutableArray
<
object
>>
codeOrDiagnostics
=
context
.
SyntaxProvider
// Find all MethodDeclarationSyntax nodes attributed with RegexGenerator and gather the required information.
...
...
@@ -94,11 +94,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
// and raise all of the created diagnostics.
context
.
RegisterSourceOutput
(
codeOrDiagnostics
.
Combine
(
compilationDataProvider
),
static
(
context
,
compilationDataAndResults
)
=>
{
ImmutableArray
<
object
?
>
results
=
compilationDataAndResults
.
Left
;
ImmutableArray
<
object
>
results
=
compilationDataAndResults
.
Left
;
// Report any top-level diagnostics.
bool
allFailures
=
true
;
foreach
(
object
?
result
in
results
)
foreach
(
object
result
in
results
)
{
if
(
result
is
Diagnostic
d
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录