Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
b62736c3
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,发现更多精彩内容 >>
提交
b62736c3
编写于
7月 18, 2017
作者:
H
Heejae Chang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added semantic model to all operation
上级
d2078351
变更
12
展开全部
显示空白变更内容
内联
并排
Showing
12 changed file
with
708 addition
and
674 deletion
+708
-674
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs
...arp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs
+6
-5
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs
...lers/CSharp/Portable/Operations/CSharpOperationFactory.cs
+104
-97
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs
...arp/Portable/Operations/CSharpOperationFactory_Methods.cs
+9
-6
src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs
...ilers/Core/Portable/Generated/Operations.xml.Generated.cs
+422
-422
src/Compilers/Core/Portable/Operations/Operation.cs
src/Compilers/Core/Portable/Operations/Operation.cs
+2
-2
src/Compilers/Core/Portable/Operations/OperationFactory.cs
src/Compilers/Core/Portable/Operations/OperationFactory.cs
+27
-23
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
+1
-0
src/Compilers/VisualBasic/Portable/Binding/MemberSemanticModel.vb
...ilers/VisualBasic/Portable/Binding/MemberSemanticModel.vb
+1
-1
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory.vb
...lBasic/Portable/Operations/VisualBasicOperationFactory.vb
+89
-83
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb
...ortable/Operations/VisualBasicOperationFactory_Methods.vb
+40
-29
src/Test/Utilities/Portable/Diagnostics/CouldHaveMoreSpecificTypeAnalyzer.cs
...Portable/Diagnostics/CouldHaveMoreSpecificTypeAnalyzer.cs
+1
-1
src/Test/Utilities/Portable/Diagnostics/OperationTestAnalyzer.cs
...t/Utilities/Portable/Diagnostics/OperationTestAnalyzer.cs
+6
-5
未找到文件。
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs
浏览文件 @
b62736c3
...
...
@@ -525,10 +525,11 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind
ImmutableArray
<
ParameterSymbol
>
parameters
=
methodOrIndexer
.
GetParameters
();
ArrayBuilder
<
IArgument
>
argumentsBuilder
=
ArrayBuilder
<
IArgument
>.
GetInstance
(
arguments
.
Length
);
int
i
=
0
;
for
(;
i
<
parameters
.
Length
;
++
i
)
{
argumentsBuilder
.
Add
(
CSharpOperationFactory
.
CreateArgumentOperation
(
ArgumentKind
.
Explicit
,
parameters
[
i
],
operationFactory
.
Create
(
arguments
[
i
])
));
argumentsBuilder
.
Add
(
operationFactory
.
CreateArgumentOperation
(
ArgumentKind
.
Explicit
,
parameters
[
i
],
arguments
[
i
]
));
}
// TODO: In case of __arglist, we will have more arguments than parameters,
...
...
@@ -536,7 +537,7 @@ private static bool IsSafeForReordering(BoundExpression expression, RefKind kind
// https://github.com/dotnet/roslyn/issues/19673
for
(;
i
<
arguments
.
Length
;
++
i
)
{
argumentsBuilder
.
Add
(
CSharpOperationFactory
.
CreateArgumentOperation
(
ArgumentKind
.
Explicit
,
null
,
operationFactory
.
Create
(
arguments
[
i
])
));
argumentsBuilder
.
Add
(
operationFactory
.
CreateArgumentOperation
(
ArgumentKind
.
Explicit
,
null
,
arguments
[
i
]
));
}
Debug
.
Assert
(
methodOrIndexer
.
GetIsVararg
()
^
parameters
.
Length
==
arguments
.
Length
);
...
...
@@ -713,7 +714,7 @@ private static ImmutableArray<RefKind> GetRefKindsOrNull(ArrayBuilder<RefKind> r
argument
=
CreateParamArrayArgument
(
syntax
,
parameter
.
Type
,
paramArray
.
ToImmutableAndFree
(),
null
,
binder
);
}
argumentsInEvaluationBuilder
.
Add
(
CSharpOperationFactory
.
CreateArgumentOperation
(
kind
,
parameter
,
operationFactory
.
Create
(
argument
)
));
argumentsInEvaluationBuilder
.
Add
(
operationFactory
.
CreateArgumentOperation
(
kind
,
parameter
,
argument
));
}
// Collect parameters with missing arguments.
...
...
@@ -1065,7 +1066,7 @@ private static BoundExpression MakeLiteral(SyntaxNode syntax, ConstantValue cons
unusedDiagnostics
.
Free
();
}
argumentsBuilder
.
Add
(
CSharpOperationFactory
.
CreateArgumentOperation
(
kind
,
parameter
,
operationFactory
.
Create
(
argument
)
));
argumentsBuilder
.
Add
(
operationFactory
.
CreateArgumentOperation
(
kind
,
parameter
,
argument
));
}
}
...
...
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs
浏览文件 @
b62736c3
此差异已折叠。
点击以展开。
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs
浏览文件 @
b62736c3
...
...
@@ -32,13 +32,16 @@ private ImmutableArray<IOperation> ToStatements(BoundStatement statement)
return
ImmutableArray
.
Create
(
Create
(
statement
));
}
internal
static
IArgument
CreateArgumentOperation
(
ArgumentKind
kind
,
IParameterSymbol
parameter
,
IOperation
value
)
internal
IArgument
CreateArgumentOperation
(
ArgumentKind
kind
,
IParameterSymbol
parameter
,
BoundExpression
expression
)
{
var
value
=
Create
(
expression
);
return
new
Argument
(
kind
,
parameter
,
value
,
inConversion
:
null
,
outConversion
:
null
,
semanticModel
:
_semanticModel
,
syntax
:
value
.
Syntax
,
type
:
value
.
Type
,
constantValue
:
default
);
...
...
@@ -79,7 +82,7 @@ internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterS
{
// optionalParametersMethod can be null if we are writing to a readonly indexer or reading from an writeonly indexer,
// in which case HasErrors property would be true, but we still want to treat this as invalid invocation.
return
boundArguments
.
SelectAsArray
(
arg
=>
CreateArgumentOperation
(
ArgumentKind
.
Explicit
,
null
,
Create
(
arg
)
));
return
boundArguments
.
SelectAsArray
(
arg
=>
CreateArgumentOperation
(
ArgumentKind
.
Explicit
,
null
,
arg
));
}
return
LocalRewriter
.
MakeArgumentsInEvaluationOrder
(
...
...
@@ -113,7 +116,7 @@ private ImmutableArray<IOperation> GetAnonymousObjectCreationInitializers(BoundA
SyntaxNode
syntax
=
value
.
Syntax
?.
Parent
??
expression
.
Syntax
;
ITypeSymbol
type
=
target
.
Type
;
Optional
<
object
>
constantValue
=
value
.
ConstantValue
;
var
assignment
=
new
SimpleAssignmentExpression
(
target
,
value
,
syntax
,
type
,
constantValue
);
var
assignment
=
new
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
);
builder
.
Add
(
assignment
);
}
...
...
@@ -185,7 +188,7 @@ private ImmutableArray<ISwitchCase> GetSwitchStatementCases(BoundSwitchStatement
var
clauses
=
switchSection
.
SwitchLabels
.
SelectAsArray
(
s
=>
(
ICaseClause
)
Create
(
s
));
var
body
=
switchSection
.
Statements
.
SelectAsArray
(
s
=>
Create
(
s
));
return
(
ISwitchCase
)
new
SwitchCase
(
clauses
,
body
,
switchSection
.
Syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
return
(
ISwitchCase
)
new
SwitchCase
(
clauses
,
body
,
_semanticModel
,
switchSection
.
Syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
});
}
...
...
@@ -196,7 +199,7 @@ private ImmutableArray<ISwitchCase> GetPatternSwitchStatementCases(BoundPatternS
var
clauses
=
switchSection
.
SwitchLabels
.
SelectAsArray
(
s
=>
(
ICaseClause
)
Create
(
s
));
var
body
=
switchSection
.
Statements
.
SelectAsArray
(
s
=>
Create
(
s
));
return
(
ISwitchCase
)
new
SwitchCase
(
clauses
,
body
,
switchSection
.
Syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
return
(
ISwitchCase
)
new
SwitchCase
(
clauses
,
body
,
_semanticModel
,
switchSection
.
Syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
});
}
...
...
src/Compilers/Core/Portable/Generated/Operations.xml.Generated.cs
浏览文件 @
b62736c3
此差异已折叠。
点击以展开。
src/Compilers/Core/Portable/Operations/Operation.cs
浏览文件 @
b62736c3
...
...
@@ -20,7 +20,7 @@ internal abstract class Operation : IOperation
// but once initialized, will never change
private
IOperation
_parentDoNotAccessDirectly
;
public
Operation
(
SemanticModel
semanticModel
,
OperationKind
kind
,
SyntaxNode
syntax
,
ITypeSymbol
type
,
Optional
<
object
>
constantValue
)
public
Operation
(
OperationKind
kind
,
SemanticModel
semanticModel
,
SyntaxNode
syntax
,
ITypeSymbol
type
,
Optional
<
object
>
constantValue
)
{
_semanticModel
=
semanticModel
;
...
...
@@ -99,7 +99,7 @@ private class NoneOperation : Operation
private
readonly
Func
<
ImmutableArray
<
IOperation
>>
_getChildren
;
public
NoneOperation
(
SemanticModel
semanticMode
,
SyntaxNode
node
,
Optional
<
object
>
constantValue
,
Func
<
ImmutableArray
<
IOperation
>>
getChildren
)
:
base
(
semanticMode
,
OperationKind
.
Non
e
,
node
,
type
:
null
,
constantValue
:
constantValue
)
base
(
OperationKind
.
None
,
semanticMod
e
,
node
,
type
:
null
,
constantValue
:
constantValue
)
{
_getChildren
=
getChildren
;
}
...
...
src/Compilers/Core/Portable/Operations/OperationFactory.cs
浏览文件 @
b62736c3
...
...
@@ -7,40 +7,42 @@ namespace Microsoft.CodeAnalysis.Semantics
{
internal
static
class
OperationFactory
{
public
static
IVariableDeclaration
CreateVariableDeclaration
(
ILocalSymbol
variable
,
IOperation
initialValue
,
SyntaxNode
syntax
)
public
static
IVariableDeclaration
CreateVariableDeclaration
(
ILocalSymbol
variable
,
IOperation
initialValue
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
return
CreateVariableDeclaration
(
ImmutableArray
.
Create
(
variable
),
initialValue
,
syntax
);
return
CreateVariableDeclaration
(
ImmutableArray
.
Create
(
variable
),
initialValue
,
s
emanticModel
,
s
yntax
);
}
public
static
VariableDeclaration
CreateVariableDeclaration
(
ImmutableArray
<
ILocalSymbol
>
variables
,
IOperation
initialValue
,
SyntaxNode
syntax
)
public
static
VariableDeclaration
CreateVariableDeclaration
(
ImmutableArray
<
ILocalSymbol
>
variables
,
IOperation
initialValue
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
return
new
VariableDeclaration
(
variables
,
initialValue
,
semanticModel
,
syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
}
public
static
IConditionalChoiceExpression
CreateConditionalChoiceExpression
(
IOperation
condition
,
IOperation
ifTrue
,
IOperation
ifFalse
,
ITypeSymbol
resultType
,
SyntaxNode
syntax
)
public
static
IConditionalChoiceExpression
CreateConditionalChoiceExpression
(
IOperation
condition
,
IOperation
ifTrue
,
IOperation
ifFalse
,
ITypeSymbol
resultType
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
return
new
ConditionalChoiceExpression
(
condition
,
ifTrue
,
ifFalse
,
semanticModel
,
syntax
,
resultType
,
default
(
Optional
<
object
>));
}
public
static
IExpressionStatement
CreateSimpleAssignmentExpressionStatement
(
IOperation
target
,
IOperation
value
,
SyntaxNode
syntax
)
public
static
IExpressionStatement
CreateSimpleAssignmentExpressionStatement
(
IOperation
target
,
IOperation
value
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
var
expression
=
new
SimpleAssignmentExpression
(
target
,
value
,
syntax
,
target
.
Type
,
default
(
Optional
<
object
>));
return
new
ExpressionStatement
(
expression
,
syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
var
expression
=
new
SimpleAssignmentExpression
(
target
,
value
,
s
emanticModel
,
s
yntax
,
target
.
Type
,
default
(
Optional
<
object
>));
return
new
ExpressionStatement
(
expression
,
s
emanticModel
,
s
yntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
}
public
static
IExpressionStatement
CreateCompoundAssignmentExpressionStatement
(
IOperation
target
,
IOperation
value
,
BinaryOperationKind
binaryOperationKind
,
IMethodSymbol
operatorMethod
,
SyntaxNode
syntax
)
IOperation
target
,
IOperation
value
,
BinaryOperationKind
binaryOperationKind
,
IMethodSymbol
operatorMethod
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
var
expression
=
new
CompoundAssignmentExpression
(
binaryOperationKind
,
...
...
@@ -48,53 +50,55 @@ public static IExpressionStatement CreateSimpleAssignmentExpressionStatement(IOp
value
,
operatorMethod
!=
null
,
operatorMethod
,
semanticModel
,
syntax
,
target
.
Type
,
default
(
Optional
<
object
>));
return
new
ExpressionStatement
(
expression
,
syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
return
new
ExpressionStatement
(
expression
,
s
emanticModel
,
s
yntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
}
public
static
ILiteralExpression
CreateLiteralExpression
(
long
value
,
ITypeSymbol
resultType
,
SyntaxNode
syntax
)
public
static
ILiteralExpression
CreateLiteralExpression
(
long
value
,
ITypeSymbol
resultType
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
return
new
LiteralExpression
(
value
.
ToString
(),
s
yntax
:
syntax
,
type
:
resultType
,
constantValue
:
new
Optional
<
object
>(
value
));
return
new
LiteralExpression
(
value
.
ToString
(),
s
emanticModel
,
syntax
,
resultType
,
constantValue
:
new
Optional
<
object
>(
value
));
}
public
static
ILiteralExpression
CreateLiteralExpression
(
ConstantValue
value
,
ITypeSymbol
resultType
,
SyntaxNode
syntax
)
public
static
ILiteralExpression
CreateLiteralExpression
(
ConstantValue
value
,
ITypeSymbol
resultType
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
return
new
LiteralExpression
(
value
.
GetValueToDisplay
(),
syntax
,
resultType
,
new
Optional
<
object
>(
value
.
Value
));
return
new
LiteralExpression
(
value
.
GetValueToDisplay
(),
s
emanticModel
,
s
yntax
,
resultType
,
new
Optional
<
object
>(
value
.
Value
));
}
public
static
IBinaryOperatorExpression
CreateBinaryOperatorExpression
(
BinaryOperationKind
binaryOperationKind
,
IOperation
left
,
IOperation
right
,
ITypeSymbol
resultType
,
SyntaxNode
syntax
)
BinaryOperationKind
binaryOperationKind
,
IOperation
left
,
IOperation
right
,
ITypeSymbol
resultType
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
return
new
BinaryOperatorExpression
(
binaryOperationKind
,
left
,
right
,
usesOperatorMethod
:
false
,
operatorMethod
:
null
,
syntax
:
syntax
,
type
:
resultType
,
constantValue
:
default
(
Optional
<
object
>));
s
emanticModel
:
semanticModel
,
s
yntax
:
syntax
,
type
:
resultType
,
constantValue
:
default
(
Optional
<
object
>));
}
public
static
IArrayCreationExpression
CreateArrayCreationExpression
(
IArrayTypeSymbol
arrayType
,
ImmutableArray
<
IOperation
>
elementValues
,
SyntaxNode
syntax
)
IArrayTypeSymbol
arrayType
,
ImmutableArray
<
IOperation
>
elementValues
,
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
var
initializer
=
new
ArrayInitializer
(
elementValues
,
syntax
,
arrayType
,
default
(
Optional
<
object
>));
var
initializer
=
new
ArrayInitializer
(
elementValues
,
s
emanticModel
,
s
yntax
,
arrayType
,
default
(
Optional
<
object
>));
return
new
ArrayCreationExpression
(
arrayType
.
ElementType
,
ImmutableArray
.
Create
<
IOperation
>(
CreateLiteralExpression
(
elementValues
.
Count
(),
resultType
:
null
,
syntax
:
syntax
)),
ImmutableArray
.
Create
<
IOperation
>(
CreateLiteralExpression
(
elementValues
.
Count
(),
resultType
:
null
,
s
emanticModel
:
semanticModel
,
s
yntax
:
syntax
)),
initializer
,
semanticModel
,
syntax
,
arrayType
,
default
(
Optional
<
object
>));
}
public
static
IInvalidExpression
CreateInvalidExpression
(
SyntaxNode
syntax
)
public
static
IInvalidExpression
CreateInvalidExpression
(
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
)
{
return
CreateInvalidExpression
(
syntax
,
ImmutableArray
<
IOperation
>.
Empty
);
return
CreateInvalidExpression
(
s
emanticModel
,
s
yntax
,
ImmutableArray
<
IOperation
>.
Empty
);
}
public
static
IInvalidExpression
CreateInvalidExpression
(
SyntaxNode
syntax
,
ImmutableArray
<
IOperation
>
children
)
public
static
IInvalidExpression
CreateInvalidExpression
(
S
emanticModel
semanticModel
,
S
yntaxNode
syntax
,
ImmutableArray
<
IOperation
>
children
)
{
return
new
InvalidExpression
(
children
:
children
,
syntax
:
syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
return
new
InvalidExpression
(
children
,
semanticModel
,
syntax
,
type
:
null
,
constantValue
:
default
(
Optional
<
object
>));
}
}
}
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
浏览文件 @
b62736c3
...
...
@@ -44,6 +44,7 @@ Microsoft.CodeAnalysis.IOperation.ConstantValue.get -> Microsoft.CodeAnalysis.Op
Microsoft.CodeAnalysis.IOperation.Kind.get -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.IOperation.Syntax.get -> Microsoft.CodeAnalysis.SyntaxNode
Microsoft.CodeAnalysis.IOperation.Type.get -> Microsoft.CodeAnalysis.ITypeSymbol
Microsoft.CodeAnalysis.IOperation.Parent.get -> Microsoft.CodeAnalysis.IOperation
Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.AddressOfExpression = 515 -> Microsoft.CodeAnalysis.OperationKind
Microsoft.CodeAnalysis.OperationKind.AnonymousObjectCreationExpression = 287 -> Microsoft.CodeAnalysis.OperationKind
...
...
src/Compilers/VisualBasic/Portable/Binding/MemberSemanticModel.vb
浏览文件 @
b62736c3
...
...
@@ -37,7 +37,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
_parentSemanticModelOpt
=
parentSemanticModelOpt
_speculatedPosition
=
speculatedPosition
_operationFactory
=
New
VisualBasicOperationFactory
()
_operationFactory
=
New
VisualBasicOperationFactory
(
Me
)
End
Sub
Friend
ReadOnly
Property
RootBinder
As
Binder
...
...
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory.vb
浏览文件 @
b62736c3
此差异已折叠。
点击以展开。
src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb
浏览文件 @
b62736c3
...
...
@@ -41,7 +41,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Return
child
End
If
Return
OperationFactory
.
CreateInvalidExpression
(
[
operator
]
.
UnderlyingExpression
.
Syntax
,
ImmutableArray
(
Of
IOperation
).
Empty
)
Return
OperationFactory
.
CreateInvalidExpression
(
_semanticModel
,
[
operator
]
.
UnderlyingExpression
.
Syntax
,
ImmutableArray
(
Of
IOperation
).
Empty
)
End
Function
Private
Shared
Function
GetUserDefinedBinaryOperatorChildBoundNode
(
[
operator
]
As
BoundUserDefinedBinaryOperator
,
index
As
Integer
)
As
BoundNode
...
...
@@ -82,6 +82,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
value
,
Create
(
byRefArgument
.
InConversion
),
Create
(
byRefArgument
.
OutConversion
),
_semanticModel
,
value
.
Syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
)
...
...
@@ -102,6 +103,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
value
,
inConversion
:
=
Nothing
,
outConversion
:
=
Nothing
,
semanticModel
:
=
_semanticModel
,
syntax
:
=
value
.
Syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
)
...
...
@@ -120,6 +122,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
value
,
inConversion
:
=
Nothing
,
outConversion
:
=
Nothing
,
semanticModel
:
=
_semanticModel
,
syntax
:
=
value
.
Syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
)
...
...
@@ -137,7 +140,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Return
child
End
If
Return
OperationFactory
.
CreateInvalidExpression
(
parent
.
Syntax
,
ImmutableArray
(
Of
IOperation
).
Empty
)
Return
OperationFactory
.
CreateInvalidExpression
(
_semanticModel
,
parent
.
Syntax
,
ImmutableArray
(
Of
IOperation
).
Empty
)
End
Function
Private
Shared
Function
GetChildOfBadExpressionBoundNode
(
parent
As
BoundNode
,
index
As
Integer
)
As
BoundNode
...
...
@@ -171,7 +174,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Dim
syntax
As
SyntaxNode
=
If
(
value
.
Syntax
?
.
Parent
,
expression
.
Syntax
)
Dim
type
As
ITypeSymbol
=
target
.
Type
Dim
constantValue
As
[
Optional
]
(
Of
Object
)
=
value
.
ConstantValue
Dim
assignment
=
New
SimpleAssignmentExpression
(
target
,
value
,
syntax
,
type
,
constantValue
)
Dim
assignment
=
New
SimpleAssignmentExpression
(
target
,
value
,
_semanticModel
,
syntax
,
type
,
constantValue
)
builder
.
Add
(
assignment
)
Next
i
...
...
@@ -188,7 +191,8 @@ Namespace Microsoft.CodeAnalysis.Semantics
If
caseStatement
.
CaseClauses
.
IsEmpty
AndAlso
caseStatement
.
Syntax
.
Kind
()
=
SyntaxKind
.
CaseElseStatement
Then
clauses
=
ImmutableArray
.
Create
(
Of
ICaseClause
)(
New
DefaultCaseClause
(
syntax
:
=
caseStatement
.
Syntax
,
_semanticModel
,
caseStatement
.
Syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
))
Else
...
...
@@ -197,7 +201,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Dim
body
=
ImmutableArray
.
Create
(
Create
(
boundCaseBlock
.
Body
))
Dim
syntax
=
boundCaseBlock
.
Syntax
Return
DirectCast
(
New
SwitchCase
(
clauses
,
body
,
syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
),
ISwitchCase
)
Return
DirectCast
(
New
SwitchCase
(
clauses
,
body
,
_semanticModel
,
syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
),
ISwitchCase
)
End
Function
)
End
Function
...
...
@@ -257,7 +261,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
' ControlVariable = InitialValue
Dim
controlReference
As
IOperation
=
Create
(
boundFor
.
ControlVariable
)
If
controlReference
IsNot
Nothing
Then
statements
.
Add
(
OperationFactory
.
CreateSimpleAssignmentExpressionStatement
(
controlReference
,
Create
(
boundFor
.
InitialValue
),
boundFor
.
InitialValue
.
Syntax
))
statements
.
Add
(
OperationFactory
.
CreateSimpleAssignmentExpressionStatement
(
controlReference
,
Create
(
boundFor
.
InitialValue
),
_semanticModel
,
boundFor
.
InitialValue
.
Syntax
))
End
If
' T0 = LimitValue
...
...
@@ -268,9 +272,10 @@ Namespace Microsoft.CodeAnalysis.Semantics
New
SyntheticLocalReferenceExpression
(
SyntheticLocalKind
.
ForLoopLimitValue
,
Create
(
boundFor
),
syntax
:
=
value
.
Syntax
,
type
:
=
value
.
Type
,
constantValue
:
=
Nothing
),
value
,
value
.
Syntax
))
_semanticModel
,
value
.
Syntax
,
value
.
Type
,
constantValue
:
=
Nothing
),
value
,
_semanticModel
,
value
.
Syntax
))
End
If
' T1 = StepValue
...
...
@@ -281,9 +286,10 @@ Namespace Microsoft.CodeAnalysis.Semantics
New
SyntheticLocalReferenceExpression
(
SyntheticLocalKind
.
ForLoopStepValue
,
Create
(
boundFor
),
syntax
:
=
value
.
Syntax
,
type
:
=
value
.
Type
,
constantValue
:
=
Nothing
),
value
,
value
.
Syntax
))
_semanticModel
,
value
.
Syntax
,
value
.
Type
,
constantValue
:
=
Nothing
),
value
,
_semanticModel
,
value
.
Syntax
))
End
If
Return
statements
.
ToImmutableAndFree
()
...
...
@@ -311,10 +317,11 @@ Namespace Microsoft.CodeAnalysis.Semantics
New
SyntheticLocalReferenceExpression
(
SyntheticLocalKind
.
ForLoopStepValue
,
Create
(
boundFor
),
syntax
:
=
value
.
Syntax
,
type
:
=
value
.
Type
,
_semanticModel
,
value
.
Syntax
,
value
.
Type
,
constantValue
:
=
Nothing
))
statements
.
Add
(
OperationFactory
.
CreateCompoundAssignmentExpressionStatement
(
controlReference
,
stepOperand
,
Semantics
.
Expression
.
DeriveAdditionKind
(
controlType
),
Nothing
,
stepValue
.
Syntax
))
statements
.
Add
(
OperationFactory
.
CreateCompoundAssignmentExpressionStatement
(
controlReference
,
stepOperand
,
Semantics
.
Expression
.
DeriveAdditionKind
(
controlType
),
Nothing
,
_semanticModel
,
stepValue
.
Syntax
))
End
If
End
If
...
...
@@ -329,8 +336,9 @@ Namespace Microsoft.CodeAnalysis.Semantics
New
SyntheticLocalReferenceExpression
(
SyntheticLocalKind
.
ForLoopLimitValue
,
Create
(
boundFor
),
syntax
:
=
operationValue
.
Syntax
,
type
:
=
operationValue
.
Type
,
_semanticModel
,
operationValue
.
Syntax
,
operationValue
.
Type
,
constantValue
:
=
Nothing
))
Dim
controlVariable
As
BoundExpression
=
boundFor
.
ControlVariable
...
...
@@ -347,7 +355,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
' Either ControlVariable <= LimitValue or ControlVariable >= LimitValue, depending on whether the step value is negative.
Dim
relationalCode
As
BinaryOperationKind
=
Helper
.
DeriveBinaryOperationKind
(
If
(
boundFor
.
StepValue
IsNot
Nothing
AndAlso
boundFor
.
StepValue
.
ConstantValueOpt
.
IsNegativeNumeric
,
BinaryOperatorKind
.
GreaterThanOrEqual
,
BinaryOperatorKind
.
LessThanOrEqual
),
controlVariable
)
Return
OperationFactory
.
CreateBinaryOperatorExpression
(
relationalCode
,
Create
(
controlVariable
),
limitValue
,
booleanType
,
limitValue
.
Syntax
)
Return
OperationFactory
.
CreateBinaryOperatorExpression
(
relationalCode
,
Create
(
controlVariable
),
limitValue
,
booleanType
,
_semanticModel
,
limitValue
.
Syntax
)
Else
' If(StepValue >= 0, ControlVariable <= LimitValue, ControlVariable >= LimitValue)
...
...
@@ -355,24 +363,26 @@ Namespace Microsoft.CodeAnalysis.Semantics
Dim
stepValue
As
IOperation
=
New
SyntheticLocalReferenceExpression
(
SyntheticLocalKind
.
ForLoopStepValue
,
Create
(
boundFor
),
syntax
:
=
value
.
Syntax
,
type
:
=
value
.
Type
,
_semanticModel
,
value
.
Syntax
,
value
.
Type
,
constantValue
:
=
Nothing
)
Dim
stepRelationalCode
As
BinaryOperationKind
=
Helper
.
DeriveBinaryOperationKind
(
BinaryOperatorKind
.
GreaterThanOrEqual
,
boundFor
.
StepValue
)
Dim
stepCondition
As
IOperation
=
OperationFactory
.
CreateBinaryOperatorExpression
(
stepRelationalCode
,
stepValue
,
OperationFactory
.
CreateLiteralExpression
(
Semantics
.
Expression
.
SynthesizeNumeric
(
stepValue
.
Type
,
0
),
boundFor
.
StepValue
.
Type
,
boundFor
.
StepValue
.
Syntax
),
OperationFactory
.
CreateLiteralExpression
(
Semantics
.
Expression
.
SynthesizeNumeric
(
stepValue
.
Type
,
0
),
boundFor
.
StepValue
.
Type
,
_semanticModel
,
boundFor
.
StepValue
.
Syntax
),
booleanType
,
_semanticModel
,
boundFor
.
StepValue
.
Syntax
)
Dim
positiveStepRelationalCode
As
BinaryOperationKind
=
Helper
.
DeriveBinaryOperationKind
(
BinaryOperatorKind
.
LessThanOrEqual
,
controlVariable
)
Dim
positiveStepCondition
As
IOperation
=
OperationFactory
.
CreateBinaryOperatorExpression
(
positiveStepRelationalCode
,
Create
(
controlVariable
),
limitValue
,
booleanType
,
limitValue
.
Syntax
)
Dim
positiveStepCondition
As
IOperation
=
OperationFactory
.
CreateBinaryOperatorExpression
(
positiveStepRelationalCode
,
Create
(
controlVariable
),
limitValue
,
booleanType
,
_semanticModel
,
limitValue
.
Syntax
)
Dim
negativeStepRelationalCode
As
BinaryOperationKind
=
Helper
.
DeriveBinaryOperationKind
(
BinaryOperatorKind
.
GreaterThanOrEqual
,
controlVariable
)
Dim
negativeStepCondition
As
IOperation
=
OperationFactory
.
CreateBinaryOperatorExpression
(
negativeStepRelationalCode
,
Create
(
controlVariable
),
limitValue
,
booleanType
,
limitValue
.
Syntax
)
Dim
negativeStepCondition
As
IOperation
=
OperationFactory
.
CreateBinaryOperatorExpression
(
negativeStepRelationalCode
,
Create
(
controlVariable
),
limitValue
,
booleanType
,
_semanticModel
,
limitValue
.
Syntax
)
Return
OperationFactory
.
CreateConditionalChoiceExpression
(
stepCondition
,
positiveStepCondition
,
negativeStepCondition
,
booleanType
,
limitValue
.
Syntax
)
Return
OperationFactory
.
CreateConditionalChoiceExpression
(
stepCondition
,
positiveStepCondition
,
negativeStepCondition
,
booleanType
,
_semanticModel
,
limitValue
.
Syntax
)
End
If
End
If
End
Function
...
...
@@ -382,11 +392,11 @@ Namespace Microsoft.CodeAnalysis.Semantics
For
Each
base
In
statement
.
LocalDeclarations
If
base
.
Kind
=
BoundKind
.
LocalDeclaration
Then
Dim
declaration
=
DirectCast
(
base
,
BoundLocalDeclaration
)
builder
.
Add
(
OperationFactory
.
CreateVariableDeclaration
(
declaration
.
LocalSymbol
,
Create
(
declaration
.
InitializerOpt
),
declaration
.
Syntax
))
builder
.
Add
(
OperationFactory
.
CreateVariableDeclaration
(
declaration
.
LocalSymbol
,
Create
(
declaration
.
InitializerOpt
),
_semanticModel
,
declaration
.
Syntax
))
ElseIf
base
.
Kind
=
BoundKind
.
AsNewLocalDeclarations
Then
Dim
asNewDeclarations
=
DirectCast
(
base
,
BoundAsNewLocalDeclarations
)
Dim
localSymbols
=
asNewDeclarations
.
LocalDeclarations
.
SelectAsArray
(
Of
ILocalSymbol
)(
Function
(
declaration
)
declaration
.
LocalSymbol
)
builder
.
Add
(
OperationFactory
.
CreateVariableDeclaration
(
localSymbols
,
Create
(
asNewDeclarations
.
Initializer
),
asNewDeclarations
.
Syntax
))
builder
.
Add
(
OperationFactory
.
CreateVariableDeclaration
(
localSymbols
,
Create
(
asNewDeclarations
.
Initializer
),
_semanticModel
,
asNewDeclarations
.
Syntax
))
End
If
Next
...
...
@@ -401,7 +411,8 @@ Namespace Microsoft.CodeAnalysis.Semantics
Dim
syntax
=
DirectCast
(
boundUsing
.
Syntax
,
UsingBlockSyntax
).
UsingStatement
Return
New
VariableDeclarationStatement
(
declaration
,
syntax
:
=
syntax
,
_semanticModel
,
syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
)
End
Function
...
...
@@ -412,7 +423,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Dim
instance
=
If
(
[
event
]
Is
Nothing
OrElse
[
event
]
.
IsStatic
,
Nothing
,
If
(
eventAccess
IsNot
Nothing
,
Create
(
eventAccess
.
ReceiverOpt
),
Nothing
))
Return
New
EventAssignmentExpression
(
[
event
]
,
instance
,
Create
(
statement
.
Handler
),
adds
:
=
True
,
syntax
:
=
statement
.
Syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
)
[
event
]
,
instance
,
Create
(
statement
.
Handler
),
adds
:
=
True
,
s
emanticModel
:
=
_semanticModel
,
s
yntax
:
=
statement
.
Syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
)
End
Function
Private
Function
GetRemoveStatementExpression
(
statement
As
BoundRemoveHandlerStatement
)
As
IOperation
...
...
@@ -421,7 +432,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Dim
instance
=
If
(
[
event
]
Is
Nothing
OrElse
[
event
]
.
IsStatic
,
Nothing
,
If
(
eventAccess
IsNot
Nothing
,
Create
(
eventAccess
.
ReceiverOpt
),
Nothing
))
Return
New
EventAssignmentExpression
(
[
event
]
,
instance
,
Create
(
statement
.
Handler
),
adds
:
=
False
,
syntax
:
=
statement
.
Syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
)
[
event
]
,
instance
,
Create
(
statement
.
Handler
),
adds
:
=
False
,
s
emanticModel
:
=
_semanticModel
,
s
yntax
:
=
statement
.
Syntax
,
type
:
=
Nothing
,
constantValue
:
=
Nothing
)
End
Function
Private
Shared
Function
GetConversionKind
(
kind
As
VisualBasic
.
ConversionKind
)
As
Semantics
.
ConversionKind
...
...
src/Test/Utilities/Portable/Diagnostics/CouldHaveMoreSpecificTypeAnalyzer.cs
浏览文件 @
b62736c3
...
...
@@ -65,7 +65,7 @@ public sealed override void Initialize(AnalysisContext context)
SyntaxNode
syntax
=
increment
.
Syntax
;
ITypeSymbol
type
=
increment
.
Type
;
Optional
<
object
>
constantValue
=
new
Optional
<
object
>(
1
);
var
value
=
new
LiteralExpression
(
text
,
syntax
,
type
,
constantValue
);
var
value
=
new
LiteralExpression
(
text
,
operationContext
.
Compilation
.
GetSemanticModel
(
syntax
.
SyntaxTree
),
syntax
,
type
,
constantValue
);
AssignTo
(
increment
.
Target
,
localsSourceTypes
,
fieldsSourceTypes
,
value
);
}
...
...
src/Test/Utilities/Portable/Diagnostics/OperationTestAnalyzer.cs
浏览文件 @
b62736c3
...
...
@@ -181,10 +181,11 @@ private void AnalyzeOperation(OperationAnalysisContext operationContext)
if
(
advance
.
Kind
==
OperationKind
.
ExpressionStatement
)
{
IOperation
advanceExpression
=
((
IExpressionStatement
)
advance
).
Expression
;
SemanticModel
semanticModel
=
operationContext
.
Compilation
.
GetSemanticModel
(
advance
.
Syntax
.
SyntaxTree
);
IOperation
advanceIncrement
;
BinaryOperationKind
advanceOperationCode
;
GetOperationKindAndValue
(
testVariable
,
advanceExpression
,
out
advanceOperationCode
,
out
advanceIncrement
);
GetOperationKindAndValue
(
semanticModel
,
testVariable
,
advanceExpression
,
out
advanceOperationCode
,
out
advanceIncrement
);
if
(
advanceIncrement
!=
null
)
{
...
...
@@ -221,7 +222,7 @@ private void AnalyzeOperation(OperationAnalysisContext operationContext)
}
private
void
GetOperationKindAndValue
(
ILocalSymbol
testVariable
,
IOperation
advanceExpression
,
SemanticModel
semanticModel
,
ILocalSymbol
testVariable
,
IOperation
advanceExpression
,
out
BinaryOperationKind
advanceOperationCode
,
out
IOperation
advanceIncrement
)
{
advanceIncrement
=
null
;
...
...
@@ -273,20 +274,20 @@ private void AnalyzeOperation(OperationAnalysisContext operationContext)
((
ILocalReferenceExpression
)
advanceAssignment
.
Target
).
Local
==
testVariable
)
{
// Advance binary operation is known to involve a reference to the local used in the test and a constant.
advanceIncrement
=
CreateIncrementOneLiteralExpression
(
advanceAssignment
);
advanceIncrement
=
CreateIncrementOneLiteralExpression
(
semanticModel
,
advanceAssignment
);
advanceOperationCode
=
CSharpOperationFactory
.
Helper
.
DeriveBinaryOperationKind
(
advanceAssignment
.
IncrementOperationKind
);
}
}
}
private
static
ILiteralExpression
CreateIncrementOneLiteralExpression
(
IIncrementExpression
increment
)
private
static
ILiteralExpression
CreateIncrementOneLiteralExpression
(
SemanticModel
semanticModel
,
IIncrementExpression
increment
)
{
string
text
=
increment
.
Syntax
.
ToString
();
SyntaxNode
syntax
=
increment
.
Syntax
;
ITypeSymbol
type
=
increment
.
Type
;
Optional
<
object
>
constantValue
=
new
Optional
<
object
>(
1
);
return
new
LiteralExpression
(
text
,
syntax
,
type
,
constantValue
);
return
new
LiteralExpression
(
text
,
s
emanticModel
,
s
yntax
,
type
,
constantValue
);
}
private
static
int
Abs
(
int
value
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录