-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathIRCSharpLanguage.qll
More file actions
158 lines (111 loc) · 4.19 KB
/
IRCSharpLanguage.qll
File metadata and controls
158 lines (111 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
private import csharp as CSharp
private import IRUtilities
import CSharpType
class LanguageType = CSharpType;
class OpaqueTypeTag = CSharp::ValueOrRefType;
class Function = CSharp::Callable;
class Location = CSharp::Location;
class UnknownLocation = CSharp::EmptyLocation;
class UnknownDefaultLocation = CSharp::EmptyLocation;
class File = CSharp::File;
class AST = CSharp::Element;
class Type = CSharp::Type;
class UnknownType = CSharp::NullType;
class VoidType = CSharp::VoidType;
class IntegralType = CSharp::IntegralType;
class FloatingPointType = CSharp::FloatingPointType;
private newtype TTypeDomain = TRealDomain()
/**
* The type domain of a floating-point type. One of `RealDomain`, `ComplexDomain`, or
* `ImaginaryDomain`.
*/
class TypeDomain extends TTypeDomain {
/** Gets a textual representation of this type domain. */
string toString() { none() }
}
/**
* The type domain of a floating-point type that represents a real number.
*/
class RealDomain extends TypeDomain, TRealDomain {
final override string toString() { result = "real" }
}
/**
* The type domain of a floating-point type that represents a complex number. Not currently used in
* C#.
*/
class ComplexDomain extends TypeDomain {
ComplexDomain() { none() }
final override string toString() { result = "complex" }
}
/**
* The type domain of a floating-point type that represents an imaginary number. Not currently used
* in C#.
*/
class ImaginaryDomain extends TypeDomain {
ImaginaryDomain() { none() }
final override string toString() { result = "imaginary" }
}
private newtype TClassDerivation =
// Note that this is the `Class` type exported from this module, not CSharp::Class.
MkClassDerivation(Class base, Class derived) { derived.getABaseType() = base }
private newtype TBuiltInOperation = NoOp()
class BuiltInOperation extends TBuiltInOperation {
string toString() { result = "BuiltInOp" }
}
class ClassDerivation extends MkClassDerivation {
Class baseClass;
Class derivedClass;
ClassDerivation() { this = MkClassDerivation(baseClass, derivedClass) }
string toString() { result = "ClassDerivation" }
final Class getBaseClass() { result = baseClass }
final Class getDerivedClass() { result = derivedClass }
final int getByteOffset() {
// Inheritance never requires adjusting the `this` pointer in C#.
result = 0
}
}
class StringLiteral = CSharp::StringLiteral;
class Variable = CSharp::Variable;
class AutomaticVariable = CSharp::LocalScopeVariable;
class StaticVariable = CSharp::Variable;
class Parameter = CSharp::Parameter;
class Field = CSharp::Field;
// TODO: Remove necessity for these.
class Expr = CSharp::Expr;
class Class = CSharp::ValueOrRefType; // Used for inheritance conversions
string getIdentityString(Function func) { result = func.getLabel() }
predicate hasCaseEdge(string minValue, string maxValue) {
// TODO: Need to handle pattern matching
exists(CSharp::CaseStmt cst | hasCaseEdge(cst, minValue, maxValue))
}
predicate hasPositionalArgIndex(int argIndex) {
exists(CSharp::MethodCall call | exists(call.getArgument(argIndex)))
or
// Quick fix so that generated calls (`Invoke` etc) will have the
// correct number of parameters; it is an overestimation,
// since we don't care about all the callables, so it
// should be restricted more
argIndex in [0 .. any(CSharp::Callable c).getNumberOfParameters() - 1]
}
predicate hasAsmOperandIndex(int operandIndex) { none() }
predicate isVariableAutomatic(Variable var) { var instanceof CSharp::LocalScopeVariable }
string getStringLiteralText(StringLiteral s) {
// REVIEW: Is this the right escaping?
result = s.toString()
}
predicate hasPotentialLoop(Function f) {
exists(CSharp::LoopStmt l | l.getEnclosingCallable() = f) or
exists(CSharp::GotoStmt s | s.getEnclosingCallable() = f)
}
predicate hasGoto(Function f) { exists(CSharp::GotoStmt s | s.getEnclosingCallable() = f) }
/**
* Gets the offset of field `field` in bits.
*/
int getFieldBitOffset(Field f) {
//REVIEW: Implement this once layout has been synthesized.
none()
}
/**
* Holds if the specified `Function` can be overridden in a derived class.
*/
predicate isFunctionVirtual(Function f) { f.(CSharp::Virtualizable).isOverridableOrImplementable() }