Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d1d082

Browse files
C++: Pull a bunch of language-dependent code that the IR depends on out into a separate module
1 parent e58df94 commit 5d1d082

41 files changed

Lines changed: 427 additions & 349 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp/ql/src/semmle/code/cpp/ir/IRConfiguration.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
private import cpp
1+
private import internal.IRLanguageInternal
22

33
private newtype TIRConfiguration = MkIRConfiguration()
44

@@ -13,7 +13,7 @@ class IRConfiguration extends TIRConfiguration {
1313
/**
1414
* Holds if IR should be created for function `func`. By default, holds for all functions.
1515
*/
16-
predicate shouldCreateIRForFunction(Function func) {
16+
predicate shouldCreateIRForFunction(Language::Function func) {
1717
any()
1818
}
1919
}

cpp/ql/src/semmle/code/cpp/ir/implementation/EdgeKind.qll

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cpp
1+
private import semmle.code.cpp.ir.internal.IRLanguageInternal
22

33
private newtype TEdgeKind =
44
TGotoEdge() or // Single successor (including fall-through)
@@ -7,9 +7,7 @@ private newtype TEdgeKind =
77
TExceptionEdge() or // Thrown exception
88
TDefaultEdge() or // 'default' label of switch
99
TCaseEdge(string minValue, string maxValue) { // Case label of switch
10-
exists(SwitchCase switchCase |
11-
hasCaseEdge(switchCase, minValue, maxValue)
12-
)
10+
Language::hasCaseEdge(minValue, maxValue)
1311
}
1412

1513
/**
@@ -122,20 +120,3 @@ class CaseEdge extends EdgeKind, TCaseEdge {
122120
CaseEdge caseEdge(string minValue, string maxValue) {
123121
result = TCaseEdge(minValue, maxValue)
124122
}
125-
126-
private predicate hasCaseEdge(SwitchCase switchCase, string minValue,
127-
string maxValue) {
128-
minValue = switchCase.getExpr().getFullyConverted().getValue() and
129-
if exists(switchCase.getEndExpr()) then
130-
maxValue = switchCase.getEndExpr().getFullyConverted().getValue()
131-
else
132-
maxValue = minValue
133-
}
134-
135-
EdgeKind getCaseEdge(SwitchCase switchCase) {
136-
exists(CaseEdge edge |
137-
result = edge and
138-
hasCaseEdge(switchCase, edge.getMinValue(), edge.getMaxValue())
139-
) or
140-
(switchCase instanceof DefaultCase and result instanceof DefaultEdge)
141-
}

cpp/ql/src/semmle/code/cpp/ir/implementation/MemoryAccessKind.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import cpp
2-
31
private newtype TMemoryAccessKind =
42
TIndirectMemoryAccess() or
53
TIndirectMayMemoryAccess() or

cpp/ql/src/semmle/code/cpp/ir/implementation/TempVariableTag.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import cpp
21
private import semmle.code.cpp.ir.internal.TempVariableTag
32

43
class TempVariableTag extends TTempVariableTag {

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRBlock.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class IRBlockBase extends TIRBlock {
1919
result = getFirstInstruction(this).toString()
2020
}
2121

22-
final Location getLocation() {
22+
final Language::Location getLocation() {
2323
result = getFirstInstruction().getLocation()
2424
}
2525

@@ -67,7 +67,7 @@ class IRBlockBase extends TIRBlock {
6767
result = getFirstInstruction(this).getEnclosingIRFunction()
6868
}
6969

70-
final Function getEnclosingFunction() {
70+
final Language::Function getEnclosingFunction() {
7171
result = getFirstInstruction(this).getEnclosingFunction()
7272
}
7373
}

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRFunction.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
private import internal.IRInternal
22
import Instruction
3-
private import cpp
43

54
private newtype TIRFunction =
6-
MkIRFunction(Function func) {
5+
MkIRFunction(Language::Function func) {
76
Construction::functionHasIR(func)
87
}
98

109
/**
1110
* Represents the IR for a function.
1211
*/
1312
class IRFunction extends TIRFunction {
14-
Function func;
13+
Language::Function func;
1514

1615
IRFunction() {
1716
this = MkIRFunction(func)
@@ -24,14 +23,14 @@ class IRFunction extends TIRFunction {
2423
/**
2524
* Gets the function whose IR is represented.
2625
*/
27-
final Function getFunction() {
26+
final Language::Function getFunction() {
2827
result = func
2928
}
3029

3130
/**
3231
* Gets the location of the function.
3332
*/
34-
final Location getLocation() {
33+
final Language::Location getLocation() {
3534
result = func.getLocation()
3635
}
3736

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/IRVariable.qll

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
private import internal.IRInternal
22
import IRFunction
3-
private import cpp
43
import semmle.code.cpp.ir.implementation.TempVariableTag
54
private import semmle.code.cpp.ir.internal.IRUtilities
65
private import semmle.code.cpp.ir.internal.TempVariableTag
76
private import semmle.code.cpp.ir.internal.TIRVariable
87

9-
IRUserVariable getIRUserVariable(Function func, Variable var) {
8+
IRUserVariable getIRUserVariable(Language::Function func, Language::Variable var) {
109
result.getVariable() = var and
1110
result.getEnclosingFunction() = func
1211
}
@@ -17,20 +16,20 @@ IRUserVariable getIRUserVariable(Function func, Variable var) {
1716
* generated by the AST-to-IR translation (`IRTempVariable`).
1817
*/
1918
abstract class IRVariable extends TIRVariable {
20-
Function func;
19+
Language::Function func;
2120

2221
abstract string toString();
2322

2423
/**
2524
* Gets the type of the variable.
2625
*/
27-
abstract Type getType();
26+
abstract Language::Type getType();
2827

2928
/**
3029
* Gets the AST node that declared this variable, or that introduced this
3130
* variable as part of the AST-to-IR translation.
3231
*/
33-
abstract Locatable getAST();
32+
abstract Language::AST getAST();
3433

3534
/**
3635
* Gets an identifier string for the variable. This identifier is unique
@@ -41,7 +40,7 @@ abstract class IRVariable extends TIRVariable {
4140
/**
4241
* Gets the source location of this variable.
4342
*/
44-
final Location getLocation() {
43+
final Language::Location getLocation() {
4544
result = getAST().getLocation()
4645
}
4746

@@ -55,37 +54,42 @@ abstract class IRVariable extends TIRVariable {
5554
/**
5655
* Gets the function that references this variable.
5756
*/
58-
final Function getEnclosingFunction() {
57+
final Language::Function getEnclosingFunction() {
5958
result = func
6059
}
6160
}
6261

6362
/**
6463
* Represents a user-declared variable referenced by the IR for a function.
6564
*/
66-
abstract class IRUserVariable extends IRVariable {
67-
Variable var;
65+
class IRUserVariable extends IRVariable, TIRUserVariable {
66+
Language::Variable var;
67+
Language::Type type;
6868

69-
override final string toString() {
70-
result = var.toString()
69+
IRUserVariable() {
70+
this = TIRUserVariable(var, type, func)
7171
}
7272

73-
override final Type getType() {
74-
result = getVariableType(var)
73+
override final string toString() {
74+
result = getVariable().toString()
7575
}
7676

77-
override final Locatable getAST() {
77+
override final Language::AST getAST() {
7878
result = var
7979
}
8080

8181
override final string getUniqueId() {
82-
result = var.toString() + " " + var.getLocation().toString()
82+
result = getVariable().toString() + " " + getVariable().getLocation().toString()
83+
}
84+
85+
override final Language::Type getType() {
86+
result = type
8387
}
8488

8589
/**
8690
* Gets the original user-declared variable.
8791
*/
88-
final Variable getVariable() {
92+
Language::Variable getVariable() {
8993
result = var
9094
}
9195
}
@@ -98,45 +102,49 @@ abstract class IRUserVariable extends IRVariable {
98102
abstract class IRAutomaticVariable extends IRVariable {
99103
}
100104

101-
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable,
102-
TIRAutomaticUserVariable {
103-
LocalScopeVariable localVar;
105+
class IRAutomaticUserVariable extends IRUserVariable, IRAutomaticVariable {
106+
override Language::AutomaticVariable var;
104107

105108
IRAutomaticUserVariable() {
106-
this = TIRAutomaticUserVariable(localVar, func) and
107-
var = localVar
109+
Language::isVariableAutomatic(var)
108110
}
109111

110-
final LocalScopeVariable getLocalVariable() {
111-
result = localVar
112+
final override Language::AutomaticVariable getVariable() {
113+
result = var
112114
}
113115
}
114116

115-
class IRStaticUserVariable extends IRUserVariable, TIRStaticUserVariable {
117+
class IRStaticUserVariable extends IRUserVariable {
118+
override Language::StaticVariable var;
119+
116120
IRStaticUserVariable() {
117-
this = TIRStaticUserVariable(var, func)
121+
not Language::isVariableAutomatic(var)
122+
}
123+
124+
final override Language::StaticVariable getVariable() {
125+
result = var
118126
}
119127
}
120128

121-
IRTempVariable getIRTempVariable(Locatable ast, TempVariableTag tag) {
129+
IRTempVariable getIRTempVariable(Language::AST ast, TempVariableTag tag) {
122130
result.getAST() = ast and
123131
result.getTag() = tag
124132
}
125133

126134
class IRTempVariable extends IRVariable, IRAutomaticVariable, TIRTempVariable {
127-
Locatable ast;
135+
Language::AST ast;
128136
TempVariableTag tag;
129-
Type type;
137+
Language::Type type;
130138

131139
IRTempVariable() {
132140
this = TIRTempVariable(func, ast, tag, type)
133141
}
134142

135-
override final Type getType() {
143+
override final Language::Type getType() {
136144
result = type
137145
}
138146

139-
override final Locatable getAST() {
147+
override final Language::AST getAST() {
140148
result = ast
141149
}
142150

0 commit comments

Comments
 (0)