3
3
* (both AST generated and compiler generated).
4
4
*/
5
5
6
-
7
6
import csharp
8
7
private import semmle.code.csharp.ir.implementation.Opcode
9
8
private import semmle.code.csharp.ir.implementation.internal.OperandTag
@@ -18,129 +17,112 @@ abstract class TranslatedCallBase extends TranslatedElement {
18
17
override final TranslatedElement getChild ( int id ) {
19
18
// We choose the child's id in the order of evaluation.
20
19
// Note: some calls do need qualifiers, though instructions for them have already
21
- // been generated; eg. a constructor does not need to generate a qualifier,
20
+ // been generated; eg. a constructor does not need to generate a qualifier,
22
21
// though the `this` argument exists and is the result of the instruction
23
22
// that allocated the new object. For those calls, `getQualifier()` should
24
23
// be void.
25
- id = - 1 and result = getQualifier ( ) or
24
+ id = - 1 and result = getQualifier ( )
25
+ or
26
26
result = getArgument ( id )
27
27
}
28
28
29
- override final Instruction getFirstInstruction ( ) {
30
- if exists ( getQualifier ( ) ) then
31
- result = getQualifier ( ) .getFirstInstruction ( )
32
- else
33
- result = getInstruction ( CallTargetTag ( ) )
29
+ final override Instruction getFirstInstruction ( ) {
30
+ if exists ( getQualifier ( ) )
31
+ then result = getQualifier ( ) .getFirstInstruction ( )
32
+ else result = getInstruction ( CallTargetTag ( ) )
34
33
}
35
34
36
- override predicate hasInstruction ( Opcode opcode , InstructionTag tag ,
37
- Type resultType , boolean isLValue ) {
38
- (
39
- tag = CallTag ( ) and
40
- opcode instanceof Opcode:: Call and
41
- resultType = getCallResultType ( ) and
42
- isLValue = false
43
- ) or
44
- (
45
- hasSideEffect ( ) and
46
- tag = CallSideEffectTag ( ) and
47
- (
48
- if hasWriteSideEffect ( ) then (
49
- opcode instanceof Opcode:: CallSideEffect and
50
- resultType instanceof Language:: UnknownType
51
- )
52
- else (
53
- opcode instanceof Opcode:: CallReadSideEffect and
54
- resultType instanceof Language:: UnknownType
55
- )
56
- ) and
57
- isLValue = false
58
- ) or
35
+ override predicate hasInstruction (
36
+ Opcode opcode , InstructionTag tag , Type resultType , boolean isLValue
37
+ ) {
38
+ tag = CallTag ( ) and
39
+ opcode instanceof Opcode:: Call and
40
+ resultType = getCallResultType ( ) and
41
+ isLValue = false
42
+ or
43
+ hasSideEffect ( ) and
44
+ tag = CallSideEffectTag ( ) and
59
45
(
60
- tag = CallTargetTag ( ) and
61
- opcode instanceof Opcode:: FunctionAddress and
62
- // Since the DB does not have a function type,
63
- // we just use the UnknownType
64
- resultType instanceof Language:: UnknownType and
65
- isLValue = true
66
- )
46
+ if hasWriteSideEffect ( )
47
+ then (
48
+ opcode instanceof Opcode:: CallSideEffect and
49
+ resultType instanceof Language:: UnknownType
50
+ ) else (
51
+ opcode instanceof Opcode:: CallReadSideEffect and
52
+ resultType instanceof Language:: UnknownType
53
+ )
54
+ ) and
55
+ isLValue = false
56
+ or
57
+ tag = CallTargetTag ( ) and
58
+ opcode instanceof Opcode:: FunctionAddress and
59
+ // Since the DB does not have a function type,
60
+ // we just use the UnknownType
61
+ resultType instanceof Language:: UnknownType and
62
+ isLValue = true
67
63
}
64
+
68
65
override Instruction getChildSuccessor ( TranslatedElement child ) {
69
- (
70
- child = getQualifier ( ) and
71
- result = getInstruction ( CallTargetTag ( ) )
72
- ) or
66
+ child = getQualifier ( ) and
67
+ result = getInstruction ( CallTargetTag ( ) )
68
+ or
73
69
exists ( int argIndex |
74
70
child = getArgument ( argIndex ) and
75
- if exists ( getArgument ( argIndex + 1 ) ) then
76
- result = getArgument ( argIndex + 1 ) .getFirstInstruction ( )
77
- else
78
- result = getInstruction ( CallTag ( ) )
71
+ if exists ( getArgument ( argIndex + 1 ) )
72
+ then result = getArgument ( argIndex + 1 ) .getFirstInstruction ( )
73
+ else result = getInstruction ( CallTag ( ) )
79
74
)
80
75
}
81
-
82
- override Instruction getInstructionSuccessor ( InstructionTag tag ,
83
- EdgeKind kind ) {
76
+
77
+ override Instruction getInstructionSuccessor ( InstructionTag tag , EdgeKind kind ) {
84
78
kind instanceof GotoEdge and
85
79
(
86
80
(
87
81
tag = CallTag ( ) and
88
- if hasSideEffect ( ) then
89
- result = getInstruction ( CallSideEffectTag ( ) )
90
- else
91
- result = getParent ( ) .getChildSuccessor ( this )
92
- ) or
93
- (
94
- hasSideEffect ( ) and
95
- tag = CallSideEffectTag ( ) and
96
- result = getParent ( ) .getChildSuccessor ( this )
97
- ) or
98
- (
99
- tag = CallTargetTag ( ) and
100
- kind instanceof GotoEdge and
101
- result = getFirstArgumentOrCallInstruction ( )
82
+ if hasSideEffect ( )
83
+ then result = getInstruction ( CallSideEffectTag ( ) )
84
+ else result = getParent ( ) .getChildSuccessor ( this )
102
85
)
86
+ or
87
+ hasSideEffect ( ) and
88
+ tag = CallSideEffectTag ( ) and
89
+ result = getParent ( ) .getChildSuccessor ( this )
90
+ or
91
+ tag = CallTargetTag ( ) and
92
+ kind instanceof GotoEdge and
93
+ result = getFirstArgumentOrCallInstruction ( )
103
94
)
104
95
}
105
96
106
- override Instruction getInstructionOperand ( InstructionTag tag ,
107
- OperandTag operandTag ) {
97
+ override Instruction getInstructionOperand ( InstructionTag tag , OperandTag operandTag ) {
98
+ tag = CallTag ( ) and
108
99
(
109
- tag = CallTag ( ) and
110
- (
111
- (
112
- operandTag instanceof CallTargetOperandTag and
113
- result = getInstruction ( CallTargetTag ( ) )
114
- ) or
115
- (
116
- operandTag instanceof ThisArgumentOperandTag and
117
- result = getQualifierResult ( )
118
- ) or
119
- exists ( PositionalArgumentOperandTag argTag |
120
- argTag = operandTag and
121
- result = getArgument ( argTag .getArgIndex ( ) ) .getResult ( )
122
- )
100
+ operandTag instanceof CallTargetOperandTag and
101
+ result = getInstruction ( CallTargetTag ( ) )
102
+ or
103
+ operandTag instanceof ThisArgumentOperandTag and
104
+ result = getQualifierResult ( )
105
+ or
106
+ exists ( PositionalArgumentOperandTag argTag |
107
+ argTag = operandTag and
108
+ result = getArgument ( argTag .getArgIndex ( ) ) .getResult ( )
123
109
)
124
- ) or
125
- (
126
- tag = CallSideEffectTag ( ) and
127
- hasSideEffect ( ) and
128
- operandTag instanceof SideEffectOperandTag and
129
- result = getUnmodeledDefinitionInstruction ( )
130
110
)
111
+ or
112
+ tag = CallSideEffectTag ( ) and
113
+ hasSideEffect ( ) and
114
+ operandTag instanceof SideEffectOperandTag and
115
+ result = getUnmodeledDefinitionInstruction ( )
131
116
}
132
117
133
- override final Type getInstructionOperandType ( InstructionTag tag ,
134
- TypedOperandTag operandTag ) {
118
+ final override Type getInstructionOperandType ( InstructionTag tag , TypedOperandTag operandTag ) {
135
119
tag = CallSideEffectTag ( ) and
136
120
hasSideEffect ( ) and
137
121
operandTag instanceof SideEffectOperandTag and
138
122
result instanceof Language:: UnknownType
139
123
}
140
124
141
- Instruction getResult ( ) {
142
- result = getInstruction ( CallTag ( ) )
143
- }
125
+ Instruction getResult ( ) { result = getInstruction ( CallTag ( ) ) }
144
126
145
127
/**
146
128
* Gets the result type of the call.
@@ -152,16 +134,14 @@ abstract class TranslatedCallBase extends TranslatedElement {
152
134
* function (of the element this call is attached to).
153
135
*/
154
136
abstract Instruction getUnmodeledDefinitionInstruction ( ) ;
155
-
137
+
156
138
/**
157
139
* Holds if the call has a `this` argument.
158
140
*/
159
- predicate hasQualifier ( ) {
160
- exists ( getQualifier ( ) )
161
- }
141
+ predicate hasQualifier ( ) { exists ( getQualifier ( ) ) }
162
142
163
143
/**
164
- * Gets the expr for the qualifier of the call.
144
+ * Gets the expr for the qualifier of the call.
165
145
*/
166
146
abstract TranslatedExprBase getQualifier ( ) ;
167
147
@@ -186,10 +166,9 @@ abstract class TranslatedCallBase extends TranslatedElement {
186
166
* argument. Otherwise, returns the call instruction.
187
167
*/
188
168
final Instruction getFirstArgumentOrCallInstruction ( ) {
189
- if hasArguments ( ) then
190
- result = getArgument ( 0 ) .getFirstInstruction ( )
191
- else
192
- result = getInstruction ( CallTag ( ) )
169
+ if hasArguments ( )
170
+ then result = getArgument ( 0 ) .getFirstInstruction ( )
171
+ else result = getInstruction ( CallTag ( ) )
193
172
}
194
173
195
174
/**
@@ -199,21 +178,15 @@ abstract class TranslatedCallBase extends TranslatedElement {
199
178
exists ( getArgument ( 0 ) )
200
179
}
201
180
202
- predicate hasReadSideEffect ( ) {
203
- any ( )
204
- }
181
+ predicate hasReadSideEffect ( ) { any ( ) }
205
182
206
- predicate hasWriteSideEffect ( ) {
207
- any ( )
208
- }
183
+ predicate hasWriteSideEffect ( ) { any ( ) }
209
184
210
- private predicate hasSideEffect ( ) {
211
- hasReadSideEffect ( ) or hasWriteSideEffect ( )
212
- }
185
+ private predicate hasSideEffect ( ) { hasReadSideEffect ( ) or hasWriteSideEffect ( ) }
213
186
214
187
override Instruction getPrimaryInstructionForSideEffect ( InstructionTag tag ) {
215
- hasSideEffect ( ) and
216
- tag = CallSideEffectTag ( ) and
217
- result = getResult ( )
188
+ hasSideEffect ( ) and
189
+ tag = CallSideEffectTag ( ) and
190
+ result = getResult ( )
218
191
}
219
- }
192
+ }
0 commit comments