Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
03313351
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
03313351
编写于
10月 31, 2017
作者:
F
Fredric Silberberg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address feedback from Heejae
上级
f89c78a1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
65 addition
and
50 deletion
+65
-50
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs
...lers/CSharp/Portable/Operations/CSharpOperationFactory.cs
+33
-33
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs
...arp/Portable/Operations/CSharpOperationFactory_Methods.cs
+2
-2
src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IAnonymousFunctionExpression.cs
...Operation/IOperationTests_IAnonymousFunctionExpression.cs
+4
-4
src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IConversionExpression.cs
...antic/IOperation/IOperationTests_IConversionExpression.cs
+22
-7
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb
...ortable/Operations/VisualBasicOperationFactory_Methods.vb
+4
-4
未找到文件。
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs
浏览文件 @
03313351
...
...
@@ -278,9 +278,9 @@ private ImmutableArray<IOperation> GetIOperationChildren(BoundNode boundNode)
return
builder
.
ToImmutableAndFree
();
}
private
IVariableDeclaratorOperation
CreateVariableDeclarat
ion
(
BoundLocalDeclaration
boundNode
)
private
IVariableDeclaratorOperation
CreateVariableDeclarat
or
(
BoundLocalDeclaration
boundNode
)
{
return
(
IVariableDeclaratorOperation
)
_cache
.
GetOrAdd
(
boundNode
,
n
=>
CreateVariableDeclarat
ion
Internal
((
BoundLocalDeclaration
)
n
,
n
.
Syntax
));
return
(
IVariableDeclaratorOperation
)
_cache
.
GetOrAdd
(
boundNode
,
n
=>
CreateVariableDeclarat
or
Internal
((
BoundLocalDeclaration
)
n
,
n
.
Syntax
));
}
private
IPlaceholderOperation
CreateBoundDeconstructValuePlaceholderOperation
(
BoundDeconstructValuePlaceholder
boundDeconstructValuePlaceholder
)
...
...
@@ -894,7 +894,7 @@ private IArrayCreationOperation CreateBoundArrayCreationOperation(BoundArrayCrea
SyntaxNode
syntax
=
boundArrayCreation
.
Syntax
;
ITypeSymbol
type
=
boundArrayCreation
.
Type
;
Optional
<
object
>
constantValue
=
ConvertToOptional
(
boundArrayCreation
.
ConstantValue
);
bool
isImplicit
=
boundArrayCreation
.
WasCompilerGenerated
||
bool
isImplicit
=
boundArrayCreation
.
WasCompilerGenerated
||
(
boundArrayCreation
.
InitializerOpt
?.
Syntax
==
syntax
&&
!
boundArrayCreation
.
InitializerOpt
.
WasCompilerGenerated
);
return
new
LazyArrayCreationExpression
(
dimensionSizes
,
initializer
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
);
}
...
...
@@ -1419,7 +1419,7 @@ private ITryOperation CreateBoundTryStatementOperation(BoundTryStatement boundTr
private
ICatchClauseOperation
CreateBoundCatchBlockOperation
(
BoundCatchBlock
boundCatchBlock
)
{
var
exceptionSourceOpt
=
(
BoundLocal
)
boundCatchBlock
.
ExceptionSourceOpt
;
Lazy
<
IOperation
>
expressionDeclarationOrExpression
=
new
Lazy
<
IOperation
>(()
=>
exceptionSourceOpt
!=
null
?
CreateVariableDeclarat
ion
(
exceptionSourceOpt
)
:
null
);
Lazy
<
IOperation
>
expressionDeclarationOrExpression
=
new
Lazy
<
IOperation
>(()
=>
exceptionSourceOpt
!=
null
?
CreateVariableDeclarat
or
(
exceptionSourceOpt
)
:
null
);
ITypeSymbol
exceptionType
=
boundCatchBlock
.
ExceptionTypeOpt
;
ImmutableArray
<
ILocalSymbol
>
locals
=
boundCatchBlock
.
Locals
.
As
<
ILocalSymbol
>();
Lazy
<
IOperation
>
filter
=
new
Lazy
<
IOperation
>(()
=>
Create
(
boundCatchBlock
.
ExceptionFilterOpt
));
...
...
@@ -1518,42 +1518,42 @@ private IOperation CreateBoundLocalDeclarationOperation(BoundLocalDeclaration bo
switch
(
kind
)
{
case
SyntaxKind
.
LocalDeclarationStatement
:
{
var
statement
=
(
LocalDeclarationStatementSyntax
)
node
;
{
var
statement
=
(
LocalDeclarationStatementSyntax
)
node
;
// this happen for simple int i = 0;
// var statement points to LocalDeclarationStatementSyntax
varStatement
=
statement
;
// this happen for simple int i = 0;
// var statement points to LocalDeclarationStatementSyntax
varStatement
=
statement
;
varDeclaration
=
statement
.
Declaration
;
varDeclaration
=
statement
.
Declaration
;
varDeclarator
=
statement
.
Declaration
.
Variables
.
First
();
break
;
}
varDeclarator
=
statement
.
Declaration
.
Variables
.
First
();
break
;
}
case
SyntaxKind
.
VariableDeclarator
:
{
// this happen for 'for loop' initializer
// We generate a DeclarationGroup for this scenario to maintain tree shape consistency across IOperation.
// var statement points to VariableDeclarationSyntax
varStatement
=
node
.
Parent
;
{
// this happen for 'for loop' initializer
// We generate a DeclarationGroup for this scenario to maintain tree shape consistency across IOperation.
// var statement points to VariableDeclarationSyntax
varStatement
=
node
.
Parent
;
varDeclaration
=
node
.
Parent
;
varDeclaration
=
node
.
Parent
;
// var declaration points to VariableDeclaratorSyntax
varDeclarator
=
node
;
break
;
}
// var declaration points to VariableDeclaratorSyntax
varDeclarator
=
node
;
break
;
}
default
:
{
Debug
.
Fail
(
$"Unexpected syntax:
{
kind
}
"
);
{
Debug
.
Fail
(
$"Unexpected syntax:
{
kind
}
"
);
// otherwise, they points to whatever bound nodes are pointing to.
varStatement
=
varDeclaration
=
varDeclarator
=
node
;
break
;
}
// otherwise, they points to whatever bound nodes are pointing to.
varStatement
=
varDeclaration
=
varDeclarator
=
node
;
break
;
}
}
Lazy
<
ImmutableArray
<
IVariableDeclaratorOperation
>>
declarations
=
new
Lazy
<
ImmutableArray
<
IVariableDeclaratorOperation
>>(()
=>
ImmutableArray
.
Create
(
CreateVariableDeclarat
ion
Internal
(
boundLocalDeclaration
,
varDeclarator
)));
Lazy
<
ImmutableArray
<
IVariableDeclaratorOperation
>>
declarations
=
new
Lazy
<
ImmutableArray
<
IVariableDeclaratorOperation
>>(()
=>
ImmutableArray
.
Create
(
CreateVariableDeclarat
or
Internal
(
boundLocalDeclaration
,
varDeclarator
)));
bool
multiVariableImplicit
=
boundLocalDeclaration
.
WasCompilerGenerated
;
// In C#, the MultiVariable initializer will always be null, but we can't pass null as the actual lazy. We assume that all lazy elements always exist
Lazy
<
IVariableInitializerOperation
>
initializer
=
OperationFactory
.
EmptyInitializer
;
...
...
@@ -1568,8 +1568,8 @@ private IOperation CreateBoundLocalDeclarationOperation(BoundLocalDeclaration bo
private
IVariableDeclarationGroupOperation
CreateBoundMultipleLocalDeclarationsOperation
(
BoundMultipleLocalDeclarations
boundMultipleLocalDeclarations
)
{
Lazy
<
ImmutableArray
<
IVariableDeclaratorOperation
>>
declarat
ion
s
=
new
Lazy
<
ImmutableArray
<
IVariableDeclaratorOperation
>>(()
=>
boundMultipleLocalDeclarations
.
LocalDeclarations
.
SelectAsArray
(
declaration
=>
CreateVariableDeclarat
ion
(
declaration
)));
Lazy
<
ImmutableArray
<
IVariableDeclaratorOperation
>>
declarat
or
s
=
new
Lazy
<
ImmutableArray
<
IVariableDeclaratorOperation
>>(()
=>
boundMultipleLocalDeclarations
.
LocalDeclarations
.
SelectAsArray
(
declaration
=>
CreateVariableDeclarat
or
(
declaration
)));
// In C#, the MultiVariable initializer will always be null, but we can't pass null as the actual lazy. We assume that all lazy elements always exist
Lazy
<
IVariableInitializerOperation
>
initializer
=
OperationFactory
.
EmptyInitializer
;
...
...
@@ -1581,7 +1581,7 @@ private IVariableDeclarationGroupOperation CreateBoundMultipleLocalDeclarationsO
((
LocalDeclarationStatementSyntax
)
declarationGroupSyntax
).
Declaration
:
declarationGroupSyntax
;
bool
declarationIsImplicit
=
boundMultipleLocalDeclarations
.
WasCompilerGenerated
;
IVariableDeclarationOperation
multiVariableDeclaration
=
new
LazyVariableDeclaration
(
declarat
ion
s
,
initializer
,
_semanticModel
,
declarationSyntax
,
null
,
default
,
declarationIsImplicit
);
IVariableDeclarationOperation
multiVariableDeclaration
=
new
LazyVariableDeclaration
(
declarat
or
s
,
initializer
,
_semanticModel
,
declarationSyntax
,
null
,
default
,
declarationIsImplicit
);
ITypeSymbol
type
=
null
;
Optional
<
object
>
constantValue
=
default
(
Optional
<
object
>);
...
...
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs
浏览文件 @
03313351
...
...
@@ -51,7 +51,7 @@ internal IArgumentOperation CreateArgumentOperation(ArgumentKind kind, IParamete
isImplicit
:
expression
.
WasCompilerGenerated
||
argument
==
null
);
}
private
IVariableDeclaratorOperation
CreateVariableDeclarat
ion
Internal
(
BoundLocalDeclaration
boundLocalDeclaration
,
SyntaxNode
syntax
)
private
IVariableDeclaratorOperation
CreateVariableDeclarat
or
Internal
(
BoundLocalDeclaration
boundLocalDeclaration
,
SyntaxNode
syntax
)
{
IVariableInitializerOperation
initializer
=
null
;
if
(
boundLocalDeclaration
.
InitializerOpt
!=
null
)
...
...
@@ -87,7 +87,7 @@ private IVariableDeclaratorOperation CreateVariableDeclarationInternal(BoundLoca
return
new
VariableDeclarator
(
symbol
,
initializer
,
_semanticModel
,
syntax
,
type
,
constantValue
,
isImplicit
);
}
private
IVariableDeclaratorOperation
CreateVariableDeclarat
ion
(
BoundLocal
boundLocal
)
private
IVariableDeclaratorOperation
CreateVariableDeclarat
or
(
BoundLocal
boundLocal
)
{
return
new
VariableDeclarator
(
boundLocal
.
LocalSymbol
,
initializer
:
null
,
semanticModel
:
_semanticModel
,
syntax
:
boundLocal
.
Syntax
,
type
:
null
,
constantValue
:
default
,
isImplicit
:
false
);
}
...
...
src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IAnonymousFunctionExpression.cs
浏览文件 @
03313351
...
...
@@ -401,16 +401,16 @@ static void F()
var
variableDeclaration
=
syntaxTree
.
GetRoot
().
DescendantNodes
().
OfType
<
LocalDeclarationStatementSyntax
>().
Single
();
var
lambdaSyntax
=
(
LambdaExpressionSyntax
)
variableDeclaration
.
Declaration
.
Variables
.
Single
().
Initializer
.
Value
;
var
variableDeclarationOperation
=
(
IVariableDeclarationGroupOperation
)
semanticModel
.
GetOperationInternal
(
variableDeclaration
);
var
variableTreeLambdaOperation
=
(
IAnonymousFunctionOperation
)
variableDeclarationOperation
.
Declarations
.
Single
().
Declarators
.
Single
().
Initializer
.
Value
;
var
variableDeclaration
Group
Operation
=
(
IVariableDeclarationGroupOperation
)
semanticModel
.
GetOperationInternal
(
variableDeclaration
);
var
variableTreeLambdaOperation
=
(
IAnonymousFunctionOperation
)
variableDeclaration
Group
Operation
.
Declarations
.
Single
().
Declarators
.
Single
().
Initializer
.
Value
;
var
lambdaOperation
=
(
IAnonymousFunctionOperation
)
semanticModel
.
GetOperationInternal
(
lambdaSyntax
);
// Assert that both ways of getting to the lambda (requesting the lambda directly, and requesting via the lambda syntax)
// return the same bound node.
Assert
.
Same
(
variableTreeLambdaOperation
,
lambdaOperation
);
var
variableDeclarationOperationSecondRequest
=
(
IVariableDeclarationGroupOperation
)
semanticModel
.
GetOperationInternal
(
variableDeclaration
);
var
variableTreeLambdaOperationSecondRequest
=
(
IAnonymousFunctionOperation
)
variableDeclarationOperation
.
Declarations
.
Single
().
Declarators
.
Single
().
Initializer
.
Value
;
var
variableDeclaration
Group
OperationSecondRequest
=
(
IVariableDeclarationGroupOperation
)
semanticModel
.
GetOperationInternal
(
variableDeclaration
);
var
variableTreeLambdaOperationSecondRequest
=
(
IAnonymousFunctionOperation
)
variableDeclaration
Group
Operation
.
Declarations
.
Single
().
Declarators
.
Single
().
Initializer
.
Value
;
var
lambdaOperationSecondRequest
=
(
IAnonymousFunctionOperation
)
semanticModel
.
GetOperationInternal
(
lambdaSyntax
);
// Assert that, when request the variable declaration or the lambda for a second time, there is no rebinding of the
...
...
src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IConversionExpression.cs
浏览文件 @
03313351
...
...
@@ -134,7 +134,7 @@ static void Main(string[] args)
additionalOperationTreeVerifier
:
new
ExpectedSymbolVerifier
().
Verify
);
}
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/20175"
)
]
[
Fact
]
public
void
ConversionExpression_Implicit_NumericConversion_InvalidNoInitializer
()
{
string
source
=
@"
...
...
@@ -149,11 +149,11 @@ static void Main(string[] args)
}
"
;
string
expectedOperationTree
=
@"
IVariableDeclarat
ionStatement (1 declarators) (OperationKind.VariableDeclarationStatement, IsInvalid) (Syntax: 'int /*<bind ... *</bind>*/;
')
I
VariableDeclaration (1 variables) (OperationKind.VariableDeclaration, IsInvalid) (Syntax: 'int /*<bind ... *</bind>*/;')
Variables: Local_1: System.Int32 i1
Initializer: IConversionExpression (ConversionKind.Invalid, Implicit) (OperationKind.ConversionExpression, Type: System.Int32
, IsInvalid) (Syntax: '')
IInvalidExpression (OperationKind.InvalidExpression, Type: ?, IsInvalid) (Syntax: ''
)
IVariableDeclarat
orOperation (Symbol: System.Int32 i1) (OperationKind.VariableDeclarator, Type: null, IsInvalid) (Syntax: 'i1 =/*</bind>*/
')
I
nitializer:
IVariableInitializerOperation (OperationKind.VariableInitializer, Type: null, IsInvalid) (Syntax: '=/*</bind>*/')
IInvalidOperation (OperationKind.Invalid, Type: null
, IsInvalid) (Syntax: '')
Children(0
)
"
;
var
expectedDiagnostics
=
new
DiagnosticDescription
[]
{
// CS1525: Invalid expression term ';'
...
...
@@ -162,7 +162,22 @@ static void Main(string[] args)
};
VerifyOperationTreeAndDiagnosticsForTest
<
VariableDeclaratorSyntax
>(
source
,
expectedOperationTree
,
expectedDiagnostics
,
additionalOperationTreeVerifier
:
new
ExpectedSymbolVerifier
().
Verify
);
additionalOperationTreeVerifier
:
(
operation
,
compilation
,
syntax
)
=>
{
// This scenario, where the syntax has IsMissing set, is special cased. We remove the conversion, and leave
// just an IInvalidOperation with null type. First assert that our assumptions are true, then test the actual
// result
var
initializerSyntax
=
((
VariableDeclaratorSyntax
)
syntax
).
Initializer
.
Value
;
var
typeInfo
=
compilation
.
GetSemanticModel
(
syntax
.
SyntaxTree
).
GetTypeInfo
(
initializerSyntax
);
Assert
.
Equal
(
SyntaxKind
.
IdentifierName
,
initializerSyntax
.
Kind
());
Assert
.
True
(
initializerSyntax
.
IsMissing
);
Assert
.
Null
(
typeInfo
.
Type
);
Assert
.
Null
(
typeInfo
.
ConvertedType
);
var
initializerOperation
=
((
IVariableDeclaratorOperation
)
operation
).
Initializer
.
Value
;
Assert
.
Null
(
initializerOperation
.
Type
);
Assert
.
Equal
(
OperationKind
.
Invalid
,
initializerOperation
.
Kind
);
});
}
[
CompilerTrait
(
CompilerFeature
.
IOperation
)]
...
...
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb
浏览文件 @
03313351
...
...
@@ -265,10 +265,10 @@ Namespace Microsoft.CodeAnalysis.Operations
Dim
builder
=
ArrayBuilder
(
Of
IVariableDeclarationOperation
).
GetInstance
()
For
Each
declarationGroup
In
groupedDeclarations
Dim
first
=
declarationGroup
.
First
()
Dim
singleDeclaration
s
As
ImmutableArray
(
Of
IVariableDeclaratorOperation
)
=
Nothing
Dim
declarator
s
As
ImmutableArray
(
Of
IVariableDeclaratorOperation
)
=
Nothing
Dim
initializer
As
IVariableInitializerOperation
=
Nothing
If
first
.
Kind
=
BoundKind
.
LocalDeclaration
Then
singleDeclaration
s
=
declarationGroup
.
Cast
(
Of
BoundLocalDeclaration
).
SelectAsArray
(
AddressOf
GetVariableDeclarator
)
declarator
s
=
declarationGroup
.
Cast
(
Of
BoundLocalDeclaration
).
SelectAsArray
(
AddressOf
GetVariableDeclarator
)
' The initializer we use for this group is the initializer attached to the last declaration in this declarator, as that's
' where it will be parsed in an error case.
...
...
@@ -294,13 +294,13 @@ Namespace Microsoft.CodeAnalysis.Operations
End
If
Else
Dim
asNewDeclarations
=
DirectCast
(
first
,
BoundAsNewLocalDeclarations
)
singleDeclaration
s
=
asNewDeclarations
.
LocalDeclarations
.
SelectAsArray
(
AddressOf
GetVariableDeclarator
)
declarator
s
=
asNewDeclarations
.
LocalDeclarations
.
SelectAsArray
(
AddressOf
GetVariableDeclarator
)
Dim
initializerSyntax
As
AsClauseSyntax
=
DirectCast
(
asNewDeclarations
.
Syntax
,
VariableDeclaratorSyntax
).
AsClause
Dim
initializerValue
As
IOperation
=
Create
(
asNewDeclarations
.
Initializer
)
initializer
=
OperationFactory
.
CreateVariableInitializer
(
initializerSyntax
,
initializerValue
,
_semanticModel
,
isImplicit
:
=
False
)
End
If
builder
.
Add
(
New
VariableDeclaration
(
singleDeclaration
s
,
builder
.
Add
(
New
VariableDeclaration
(
declarator
s
,
initializer
,
_semanticModel
,
declarationGroup
.
Key
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录