@@ -12,87 +12,44 @@ private import semmle.code.csharp.ir.internal.IRCSharpLanguage as Language
1212 * Gets the `TranslatedDeclarationEntry` that represents the declaration
1313 * `entry`.
1414 */
15- TranslatedDeclarationEntry getTranslatedDeclarationEntry ( Declaration entry ) {
16- result .getAST ( ) = entry
15+ TranslatedLocalDeclaration getTranslatedLocalDeclaration ( LocalVariableDeclExpr declExpr ) {
16+ result .getAST ( ) = declExpr
1717}
1818
1919/**
2020 * Represents the IR translation of a declaration within the body of a function.
21- * Most often, this is the declaration of an automatic local variable, although
22- * it can also be the declaration of a static local variable, an extern
23- * variable, or an extern function.
2421 */
25- // TODO: Make sure local decls are handeld correctly (seem to be)
26- abstract class TranslatedDeclarationEntry extends TranslatedElement , TTranslatedDeclarationEntry {
27- Declaration entry ;
22+ abstract class TranslatedLocalDeclaration extends TranslatedElement , TTranslatedDeclarationEntry {
23+ LocalVariableDeclExpr expr ;
2824
29- TranslatedDeclarationEntry ( ) {
30- this = TTranslatedDeclarationEntry ( entry )
25+ TranslatedLocalDeclaration ( ) {
26+ this = TTranslatedDeclarationEntry ( expr )
3127 }
3228
3329 override final Callable getFunction ( ) {
34- exists ( LocalVariableDeclExpr expr |
35- expr .getVariable ( ) = entry and
36- result = expr .getEnclosingCallable ( )
37- )
30+ result = expr .getEnclosingCallable ( )
3831 }
3932
4033 override final string toString ( ) {
41- result = entry .toString ( )
34+ result = expr .toString ( )
4235 }
4336
4437 override final Language:: AST getAST ( ) {
45- result = entry
46- }
47- }
48-
49- /**
50- * Represents the IR translation of a declaration within the body of a function,
51- * for declarations other than local variables. Since these have no semantic
52- * effect, they are translated as `NoOp`.
53- */
54- class TranslatedNonVariableDeclarationEntry extends TranslatedDeclarationEntry {
55- TranslatedNonVariableDeclarationEntry ( ) {
56- not entry instanceof LocalVariable
57- }
58-
59- override predicate hasInstruction ( Opcode opcode , InstructionTag tag ,
60- Type resultType , boolean isLValue ) {
61- opcode instanceof Opcode:: NoOp and
62- tag = OnlyInstructionTag ( ) and
63- resultType instanceof Language:: UnknownType and
64- isLValue = false
65- }
66-
67- override Instruction getFirstInstruction ( ) {
68- result = getInstruction ( OnlyInstructionTag ( ) )
69- }
70-
71- override TranslatedElement getChild ( int id ) {
72- none ( )
73- }
74-
75- override Instruction getInstructionSuccessor ( InstructionTag tag ,
76- EdgeKind kind ) {
77- tag = OnlyInstructionTag ( ) and
78- result = getParent ( ) .getChildSuccessor ( this ) and
79- kind instanceof GotoEdge
80- }
81-
82- override Instruction getChildSuccessor ( TranslatedElement child ) {
83- none ( )
38+ result = expr
8439 }
8540}
8641
8742/**
8843 * Represents the IR translation of the declaration of a local variable,
8944 * including its initialization, if any.
9045 */
91- abstract class TranslatedVariableDeclaration extends TranslatedElement , InitializationContext {
92- /**
93- * Gets the local variable being declared.
94- */
95- abstract LocalVariable getVariable ( ) ;
46+ class TranslatedLocalVariableDeclaration extends TranslatedLocalDeclaration ,
47+ InitializationContext {
48+ LocalVariable var ;
49+
50+ TranslatedLocalVariableDeclaration ( ) {
51+ var = expr .getVariable ( )
52+ }
9653
9754 override TranslatedElement getChild ( int id ) {
9855 id = 0 and result = getInitialization ( )
@@ -107,14 +64,14 @@ abstract class TranslatedVariableDeclaration extends TranslatedElement, Initiali
10764 (
10865 tag = InitializerVariableAddressTag ( ) and
10966 opcode instanceof Opcode:: VariableAddress and
110- resultType = getVariableType ( getVariable ( ) ) and
67+ resultType = getVariableType ( var ) and
11168 isLValue = true
11269 ) or
11370 (
11471 hasUninitializedInstruction ( ) and
11572 tag = InitializerStoreTag ( ) and
11673 opcode instanceof Opcode:: Uninitialized and
117- resultType = getVariableType ( getVariable ( ) ) and
74+ resultType = getVariableType ( var ) and
11875 isLValue = false
11976 )
12077 }
@@ -149,7 +106,7 @@ abstract class TranslatedVariableDeclaration extends TranslatedElement, Initiali
149106 tag = InitializerVariableAddressTag ( ) or
150107 hasUninitializedInstruction ( ) and tag = InitializerStoreTag ( )
151108 ) and
152- result = getIRUserVariable ( getFunction ( ) , getVariable ( ) )
109+ result = getIRUserVariable ( getFunction ( ) , var )
153110 }
154111
155112 override Instruction getInstructionOperand ( InstructionTag tag , OperandTag operandTag ) {
@@ -164,18 +121,18 @@ abstract class TranslatedVariableDeclaration extends TranslatedElement, Initiali
164121 }
165122
166123 override Type getTargetType ( ) {
167- result = getVariableType ( getVariable ( ) )
124+ result = getVariableType ( var )
168125 }
169126
170127 // TODO: All declarations which use an initializer will need a special case here
171128 private TranslatedInitialization getInitialization ( ) {
172129 // First complex initializations
173- if ( getVariable ( ) .getInitializer ( ) instanceof ArrayCreation ) then
174- result = getTranslatedInitialization ( getVariable ( ) .getInitializer ( ) .( ArrayCreation ) .getInitializer ( ) )
175- else if ( getVariable ( ) .getInitializer ( ) instanceof ObjectCreation ) then
176- result = getTranslatedInitialization ( getVariable ( ) .getInitializer ( ) )
130+ if ( var .getInitializer ( ) instanceof ArrayCreation ) then
131+ result = getTranslatedInitialization ( var .getInitializer ( ) .( ArrayCreation ) .getInitializer ( ) )
132+ else if ( var .getInitializer ( ) instanceof ObjectCreation ) then
133+ result = getTranslatedInitialization ( var .getInitializer ( ) )
177134 else // then the simple variable initialization
178- result = getTranslatedInitialization ( getVariable ( ) .getInitializer ( ) )
135+ result = getTranslatedInitialization ( var .getInitializer ( ) )
179136 }
180137
181138 private predicate hasUninitializedInstruction ( ) {
@@ -184,22 +141,6 @@ abstract class TranslatedVariableDeclaration extends TranslatedElement, Initiali
184141 }
185142}
186143
187- /**
188- * Represents the IR translation of a local variable declaration within a declaration statement.
189- */
190- class TranslatedVariableDeclarationEntry extends TranslatedVariableDeclaration ,
191- TranslatedDeclarationEntry {
192- LocalVariable var ;
193-
194- TranslatedVariableDeclarationEntry ( ) {
195- var = entry
196- }
197-
198- override LocalVariable getVariable ( ) {
199- result = var
200- }
201- }
202-
203144///**
204145// * Gets the `TranslatedRangeBasedForVariableDeclaration` that represents the declaration of
205146// * `var`.
0 commit comments