From 8cbe8bc6b5d34e2d383a0992d5b86cecffecf873 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Thu, 12 Nov 2020 11:51:57 +0100 Subject: [PATCH] C#: Fix parent of 'TypeMention' for some variable declaration --- .../Expressions/VariableDeclaration.cs | 2 +- .../test/experimental/ir/ir/PrintAst.expected | 4 +-- .../library-tests/csharp7/PrintAst.expected | 14 +++++----- .../library-tests/csharp8/PrintAst.expected | 26 +++++++++---------- .../definitions/PrintAst.expected | 6 ++--- .../test/library-tests/linq/PrintAst.expected | 4 +-- .../library-tests/methods/PrintAst.expected | 2 +- .../statements/PrintAst.expected | 4 +-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs index c0b561dd8430..84b61956ae60 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs @@ -19,7 +19,7 @@ public static VariableDeclaration Create(Context cx, ISymbol symbol, AnnotatedTy var l = LocalVariable.Create(cx, symbol); l.PopulateManual(ret, isVar); if (optionalSyntax != null) - TypeMention.Create(cx, optionalSyntax, parent, type); + TypeMention.Create(cx, optionalSyntax, ret, type); }); return ret; } diff --git a/csharp/ql/test/experimental/ir/ir/PrintAst.expected b/csharp/ql/test/experimental/ir/ir/PrintAst.expected index f779d3b01c03..61ffd2f82668 100644 --- a/csharp/ql/test/experimental/ir/ir/PrintAst.expected +++ b/csharp/ql/test/experimental/ir/ir/PrintAst.expected @@ -465,8 +465,8 @@ foreach.cs: # 5| 5: [IntLiteral] 6 # 5| 6: [IntLiteral] 7 # 7| 1: [ForeachStmt] foreach (... ... in ...) ... -# 7| -1: [TypeMention] int # 7| 0: [LocalVariableDeclExpr] Int32 items +# 7| 0: [TypeMention] int # 7| 1: [LocalVariableAccess] access to local variable a_array # 8| 2: [BlockStmt] {...} # 9| 0: [LocalVariableDeclStmt] ... ...; @@ -725,9 +725,9 @@ isexpr.cs: # 12| 1: [LocalVariableAccess] access to local variable obj # 13| 2: [IfStmt] if (...) ... # 13| 0: [IsExpr] ... is ... -# 13| -1: [TypeMention] Is_A # 13| 0: [LocalVariableAccess] access to local variable o # 13| 1: [VariablePatternExpr] Is_A tmp +# 13| 0: [TypeMention] Is_A # 14| 1: [BlockStmt] {...} # 15| 0: [LocalVariableDeclStmt] ... ...; # 15| 0: [LocalVariableDeclAndInitExpr] Int32 res = ... diff --git a/csharp/ql/test/library-tests/csharp7/PrintAst.expected b/csharp/ql/test/library-tests/csharp7/PrintAst.expected index f4d3a39b1c13..b715757c33e3 100644 --- a/csharp/ql/test/library-tests/csharp7/PrintAst.expected +++ b/csharp/ql/test/library-tests/csharp7/PrintAst.expected @@ -722,9 +722,9 @@ CSharp7.cs: # 235| 1: [IfStmt] if (...) ... # 235| 0: [LogicalAndExpr] ... && ... # 235| 0: [IsExpr] ... is ... -# 235| -1: [TypeMention] int # 235| 0: [LocalVariableAccess] access to local variable o # 235| 1: [VariablePatternExpr] Int32 i1 +# 235| 0: [TypeMention] int # 235| 1: [GTExpr] ... > ... # 235| 0: [LocalVariableAccess] access to local variable i1 # 235| 1: [IntLiteral] 0 @@ -738,9 +738,9 @@ CSharp7.cs: # 237| 1: [LocalVariableAccess] access to local variable i1 # 239| 2: [IfStmt] if (...) ... # 239| 0: [IsExpr] ... is ... -# 239| -1: [TypeMention] string # 239| 0: [LocalVariableAccess] access to local variable o # 239| 1: [VariablePatternExpr] String s1 +# 239| 0: [TypeMention] string # 240| 1: [BlockStmt] {...} # 241| 0: [ExprStmt] ...; # 241| 0: [MethodCall] call to method WriteLine @@ -774,9 +774,9 @@ CSharp7.cs: # 256| 4: [ConstCase] case ...: # 256| 0: [ConstantPatternExpr,StringLiteral] "x" # 256| 1: [IsExpr] ... is ... -# 256| -1: [TypeMention] string # 256| 0: [LocalVariableAccess] access to local variable o # 256| 1: [VariablePatternExpr] String s4 +# 256| 0: [TypeMention] string # 257| 5: [ExprStmt] ...; # 257| 0: [MethodCall] call to method WriteLine # 257| -1: [TypeAccess] access to type Console @@ -786,8 +786,8 @@ CSharp7.cs: # 257| 1: [LocalVariableAccess] access to local variable s4 # 258| 6: [BreakStmt] break; # 259| 7: [CaseStmt] case ...: -# 259| -1: [TypeMention] int # 259| 0: [VariablePatternExpr] Int32 i2 +# 259| 0: [TypeMention] int # 259| 1: [GTExpr] ... > ... # 259| 0: [LocalVariableAccess] access to local variable i2 # 259| 1: [IntLiteral] 0 @@ -800,8 +800,8 @@ CSharp7.cs: # 260| 1: [LocalVariableAccess] access to local variable i2 # 261| 9: [BreakStmt] break; # 262| 10: [CaseStmt] case ...: -# 262| -1: [TypeMention] int # 262| 0: [VariablePatternExpr] Int32 i3 +# 262| 0: [TypeMention] int # 263| 11: [ExprStmt] ...; # 263| 0: [MethodCall] call to method WriteLine # 263| -1: [TypeAccess] access to type Console @@ -811,8 +811,8 @@ CSharp7.cs: # 263| 1: [LocalVariableAccess] access to local variable i3 # 264| 12: [BreakStmt] break; # 265| 13: [CaseStmt] case ...: -# 265| -1: [TypeMention] string # 265| 0: [VariablePatternExpr] String s2 +# 265| 0: [TypeMention] string # 266| 14: [ExprStmt] ...; # 266| 0: [MethodCall] call to method WriteLine # 266| -1: [TypeAccess] access to type Console @@ -898,9 +898,9 @@ CSharp7.cs: # 299| 0: [LocalVariableAccess] access to local variable x # 299| 1: [IntLiteral] 10 # 299| 1: [IsExpr] ... is ... -# 299| -1: [TypeMention] int # 299| 0: [LocalVariableAccess] access to local variable x # 299| 1: [VariablePatternExpr] Int32 y +# 299| 0: [TypeMention] int # 299| 1: [PreIncrExpr] ++... # 299| 0: [LocalVariableAccess] access to local variable x # 300| 2: [BlockStmt] {...} diff --git a/csharp/ql/test/library-tests/csharp8/PrintAst.expected b/csharp/ql/test/library-tests/csharp8/PrintAst.expected index 93e2d6d8a878..b392bec6dc7a 100644 --- a/csharp/ql/test/library-tests/csharp8/PrintAst.expected +++ b/csharp/ql/test/library-tests/csharp8/PrintAst.expected @@ -36,8 +36,8 @@ AsyncStreams.cs: # 17| -1: [TypeMention] Void # 18| 4: [BlockStmt] {...} # 19| 0: [ForeachStmt] foreach (... ... in ...) ... -# 19| -1: [TypeMention] int # 19| 0: [LocalVariableDeclExpr] Int32 item +# 19| 0: [TypeMention] int # 19| 1: [MethodCall] call to method Items # 20| 2: [ExprStmt] ...; # 20| 0: [MethodCall] call to method WriteLine @@ -744,9 +744,9 @@ patterns.cs: # 7| 1: [IntLiteral] 2 # 9| 1: [IfStmt] if (...) ... # 9| 0: [IsExpr] ... is ... -# 9| -1: [TypeMention] MyStruct # 9| 0: [LocalVariableAccess] access to local variable o # 9| 1: [VariablePatternExpr] MyStruct ms1 +# 9| 0: [TypeMention] MyStruct # 10| 1: [BlockStmt] {...} # 13| 2: [IfStmt] if (...) ... # 13| 0: [LogicalAndExpr] ... && ... @@ -758,8 +758,8 @@ patterns.cs: # 13| 1: [TypeAccess] access to type MyStruct # 13| 0: [TypeMention] MyStruct # 13| 3: [PropertyPatternExpr] { ... } -# 13| -1: [TypeMention] int # 13| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x +# 13| 0: [TypeMention] int # 13| 1: [LTExpr] ... < ... # 13| 0: [LocalVariableAccess] access to local variable x # 13| 1: [IntLiteral] 4 @@ -818,8 +818,8 @@ patterns.cs: # 36| 1: [SwitchStmt] switch (...) {...} # 36| 0: [LocalVariableAccess] access to local variable s # 38| 0: [CaseStmt] case ...: -# 38| -1: [TypeMention] MyStruct # 38| 0: [VariablePatternExpr] MyStruct ms1 +# 38| 0: [TypeMention] MyStruct # 38| 1: [EQExpr] ... == ... # 38| 0: [FieldAccess] access to field X # 38| -1: [LocalVariableAccess] access to local variable ms1 @@ -831,8 +831,8 @@ patterns.cs: # 39| 0: [StringLiteral] "Hit the breakpoint" # 40| 2: [BreakStmt] break; # 41| 3: [CaseStmt] case ...: -# 41| -1: [TypeMention] MyStruct # 41| 0: [VariablePatternExpr] MyStruct ms2 +# 41| 0: [TypeMention] MyStruct # 41| 1: [LTExpr] ... < ... # 41| 0: [FieldAccess] access to field X # 41| -1: [LocalVariableAccess] access to local variable ms2 @@ -850,8 +850,8 @@ patterns.cs: # 48| 1: [TypeAccess] access to type MyStruct # 48| 0: [TypeMention] MyStruct # 48| 3: [PropertyPatternExpr] { ... } -# 48| -1: [TypeMention] int # 48| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x +# 48| 0: [TypeMention] int # 48| 1: [GTExpr] ... > ... # 48| 0: [LocalVariableAccess] access to local variable x # 48| 1: [IntLiteral] 2 @@ -877,8 +877,8 @@ patterns.cs: # 54| 6: [CaseStmt] case ...: # 54| 0: [RecursivePatternExpr] { ... } # 54| 3: [PropertyPatternExpr] { ... } -# 54| -1: [TypeMention] int # 54| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x2 +# 54| 0: [TypeMention] int # 54| 1: [GTExpr] ... > ... # 54| 0: [LocalVariableAccess] access to local variable x2 # 54| 1: [IntLiteral] 2 @@ -908,8 +908,8 @@ patterns.cs: # 67| 1: [TypeAccess] access to type MyStruct # 67| 0: [TypeMention] MyStruct # 67| 3: [PropertyPatternExpr] { ... } -# 67| -1: [TypeMention] int # 67| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x +# 67| 0: [TypeMention] int # 67| 1: [GTExpr] ... > ... # 67| 0: [LocalVariableAccess] access to local variable x # 67| 1: [IntLiteral] 2 @@ -942,10 +942,10 @@ patterns.cs: # 78| 0: [CaseStmt] case ...: # 78| 0: [RecursivePatternExpr] { ... } # 78| 2: [PositionalPatternExpr] ( ... ) -# 78| -1: [TypeMention] int -# 78| -1: [TypeMention] float # 78| 0: [VariablePatternExpr] Int32 x +# 78| 0: [TypeMention] int # 78| 1: [VariablePatternExpr] Single y +# 78| 0: [TypeMention] float # 78| 1: [LTExpr] ... < ... # 78| 0: [CastExpr] (...) ... # 78| 1: [LocalVariableAccess] access to local variable x @@ -998,8 +998,8 @@ patterns.cs: # 100| 1: [SwitchExpr] ... switch { ... } # 100| -1: [ParameterAccess] access to parameter x # 101| 0: [SwitchCaseExpr] ... => ... -# 101| -1: [TypeMention] int # 101| 0: [VariablePatternExpr] Int32 y +# 101| 0: [TypeMention] int # 101| 1: [GTExpr] ... > ... # 101| 0: [LocalVariableAccess] access to local variable y # 101| 1: [IntLiteral] 10 @@ -1101,8 +1101,8 @@ patterns.cs: # 128| 1: [TypeAccess] access to type MyStruct # 128| 0: [TypeMention] MyStruct # 128| 3: [PropertyPatternExpr] { ... } -# 128| -1: [TypeMention] int # 128| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x +# 128| 0: [TypeMention] int # 128| 1: [GTExpr] ... > ... # 128| 0: [LocalVariableAccess] access to local variable x # 128| 1: [IntLiteral] 2 @@ -1142,8 +1142,8 @@ patterns.cs: # 139| 0: [ConstantPatternExpr,IntLiteral] 2 # 139| 2: [IntLiteral] 3 # 140| 2: [SwitchCaseExpr] ... => ... -# 140| -1: [TypeMention] object # 140| 0: [VariablePatternExpr] Object y +# 140| 0: [TypeMention] object # 140| 1: [IsExpr] ... is ... # 140| 0: [LocalVariableAccess] access to local variable y # 140| 1: [RecursivePatternExpr] { ... } diff --git a/csharp/ql/test/library-tests/definitions/PrintAst.expected b/csharp/ql/test/library-tests/definitions/PrintAst.expected index 0c2977ca4333..05e72d200ae8 100644 --- a/csharp/ql/test/library-tests/definitions/PrintAst.expected +++ b/csharp/ql/test/library-tests/definitions/PrintAst.expected @@ -204,8 +204,8 @@ definitions.cs: # 86| 0: [TypeMention] Exception # 87| 1: [BlockStmt] {...} # 88| 0: [ForeachStmt] foreach (... ... in ...) ... -# 88| -1: [TypeMention] S1 # 88| 0: [LocalVariableDeclExpr] S1 s +# 88| 0: [TypeMention] S1 # 88| 1: [ParameterAccess] access to parameter ss # 89| 2: [BlockStmt] {...} # 92| 1: [LocalVariableDeclStmt] ... ...; @@ -507,9 +507,9 @@ definitions.cs: # 210| 1: [NullLiteral] null # 211| 1: [IfStmt] if (...) ... # 211| 0: [IsExpr] ... is ... -# 211| -1: [TypeMention] C8 # 211| 0: [LocalVariableAccess] access to local variable c8a # 211| 1: [VariablePatternExpr] C8 c8b +# 211| 0: [TypeMention] C8 # 212| 1: [ExprStmt] ...; # 212| 0: [AssignExpr] ... = ... # 212| 0: [LocalVariableAccess] access to local variable c8a @@ -517,8 +517,8 @@ definitions.cs: # 213| 2: [SwitchStmt] switch (...) {...} # 213| 0: [LocalVariableAccess] access to local variable c8a # 215| 0: [CaseStmt] case ...: -# 215| -1: [TypeMention] C8 # 215| 0: [VariablePatternExpr] C8 c8c +# 215| 0: [TypeMention] C8 # 215| 1: [NEExpr] ... != ... # 215| 0: [LocalVariableAccess] access to local variable c8c # 215| 1: [NullLiteral] null diff --git a/csharp/ql/test/library-tests/linq/PrintAst.expected b/csharp/ql/test/library-tests/linq/PrintAst.expected index b036da79fd32..3d83c199cd95 100644 --- a/csharp/ql/test/library-tests/linq/PrintAst.expected +++ b/csharp/ql/test/library-tests/linq/PrintAst.expected @@ -151,8 +151,8 @@ queries.cs: # 39| -1: [TypeMention] IEnumerable # 39| 0: [LocalVariableAccess] access to local variable list8 # 41| 1: [MethodCall] call to method Select -# 40| -1: [TypeMention] object # 40| 0: [LocalVariableDeclAndInitExpr] Object a = ... +# 40| -1: [TypeMention] object # 40| 0: [LocalVariableAccess] access to local variable a # 40| 1: [LocalVariableAccess] access to local variable list7 # 41| 1: [LocalVariableAccess] access to local variable a @@ -176,8 +176,8 @@ queries.cs: # 49| -1: [TypeMention] IEnumerable # 49| 0: [LocalVariableAccess] access to local variable list11 # 51| 1: [MethodCall] call to method Select -# 50| -1: [TypeMention] string # 50| 0: [LocalVariableDeclAndInitExpr] String a = ... +# 50| -1: [TypeMention] string # 50| 0: [LocalVariableAccess] access to local variable a # 50| 1: [LocalVariableAccess] access to local variable list7 # 51| 1: [LocalVariableAccess] access to local variable a diff --git a/csharp/ql/test/library-tests/methods/PrintAst.expected b/csharp/ql/test/library-tests/methods/PrintAst.expected index b8b3c66e9e57..a41e03620948 100644 --- a/csharp/ql/test/library-tests/methods/PrintAst.expected +++ b/csharp/ql/test/library-tests/methods/PrintAst.expected @@ -324,8 +324,8 @@ methods.cs: # 126| 2: [StringLiteral] "333" # 126| 3: [StringLiteral] "4444" # 127| 1: [ForeachStmt] foreach (... ... in ...) ... -# 127| -1: [TypeMention] string # 127| 0: [LocalVariableDeclExpr] String s +# 127| 0: [TypeMention] string # 127| 1: [MethodCall] call to method Slice # 127| -1: [LocalVariableAccess] access to local variable strings # 127| 0: [IntLiteral] 1 diff --git a/csharp/ql/test/library-tests/statements/PrintAst.expected b/csharp/ql/test/library-tests/statements/PrintAst.expected index 50ea8610f038..b8a692755e89 100644 --- a/csharp/ql/test/library-tests/statements/PrintAst.expected +++ b/csharp/ql/test/library-tests/statements/PrintAst.expected @@ -358,8 +358,8 @@ statements.cs: # 140| 1: [TypeMention] string # 141| 4: [BlockStmt] {...} # 142| 0: [ForeachStmt] foreach (... ... in ...) ... -# 142| -1: [TypeMention] string # 142| 0: [LocalVariableDeclExpr] String s +# 142| 0: [TypeMention] string # 142| 1: [ParameterAccess] access to parameter args # 143| 2: [BlockStmt] {...} # 144| 0: [ExprStmt] ...; @@ -502,8 +502,8 @@ statements.cs: # 193| -1: [TypeMention] Void # 194| 4: [BlockStmt] {...} # 195| 0: [ForeachStmt] foreach (... ... in ...) ... -# 195| -1: [TypeMention] int # 195| 0: [LocalVariableDeclExpr] Int32 x +# 195| 0: [TypeMention] int # 195| 1: [MethodCall] call to method Range # 195| 0: [UnaryMinusExpr] -... # 195| 0: [IntLiteral] 10