-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathDeclaration.qll
More file actions
133 lines (98 loc) · 4.2 KB
/
Declaration.qll
File metadata and controls
133 lines (98 loc) · 4.2 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
/**
* Provides classes for declarations and members.
*/
import CIL
private import dotnet
private import semmle.code.csharp.Member as CS
/**
* A declaration. Either a member (`Member`) or a variable (`Variable`).
*/
class Declaration extends DotNet::Declaration, Element, @cil_declaration {
/** Gets an attribute (for example `[Obsolete]`) of this declaration, if any. */
Attribute getAnAttribute() { result.getDeclaration() = this }
/**
* Gets the C# declaration corresponding to this CIL declaration, if any.
* Note that this is only for source/unconstructed declarations.
*/
CS::Declaration getCSharpDeclaration() {
result = toCSharpNonTypeParameter(this) or
result = toCSharpTypeParameter(this)
}
override Declaration getUnboundDeclaration() { result = this }
/**
* DEPRECATED: Use `isUnboundDeclaration()` instead.
*
* Holds if this declaration is a source declaration.
*/
deprecated final predicate isSourceDeclaration() { this.isUnboundDeclaration() }
}
private CS::Declaration toCSharpNonTypeParameter(Declaration d) { result.matchesHandle(d) }
private CS::TypeParameter toCSharpTypeParameter(TypeParameter tp) {
toCSharpTypeParameterJoin(tp, result.getIndex(), result.getGeneric())
}
pragma[nomagic]
private predicate toCSharpTypeParameterJoin(TypeParameter tp, int i, CS::UnboundGeneric ug) {
exists(TypeContainer tc |
tp.getIndex() = i and
tc = tp.getGeneric() and
ug = toCSharpNonTypeParameter(tc)
)
}
/**
* A member of a type. Either a type (`Type`), a method (`Method`), a property (`Property`), or an event (`Event`).
*/
class Member extends DotNet::Member, Declaration, @cil_member {
override predicate isPublic() { cil_public(this) }
override predicate isProtected() { cil_protected(this) }
override predicate isPrivate() { cil_private(this) }
override predicate isInternal() { cil_internal(this) }
override predicate isSealed() { cil_sealed(this) }
override predicate isAbstract() { cil_abstract(this) }
override predicate isStatic() { cil_static(this) }
/** Holds if this member has a security attribute. */
predicate hasSecurity() { cil_security(this) }
override Location getLocation() { result = getDeclaringType().getLocation() }
}
/** A property. */
class Property extends DotNet::Property, Member, CustomModifierReceiver, @cil_property {
override string getName() { cil_property(this, _, result, _) }
/** Gets the type of this property. */
override Type getType() { cil_property(this, _, _, result) }
override ValueOrRefType getDeclaringType() { cil_property(this, result, _, _) }
/** Gets the getter of this property, if any. */
override Getter getGetter() { this = result.getProperty() }
/** Gets the setter of this property, if any. */
override Setter getSetter() { this = result.getProperty() }
/** Gets an accessor of this property. */
Accessor getAnAccessor() { result = getGetter() or result = getSetter() }
override string toString() { result = "property " + getName() }
override string toStringWithTypes() {
result =
getType().toStringWithTypes() + " " + getDeclaringType().toStringWithTypes() + "." + getName()
}
}
/** A property that is trivial (wraps a field). */
class TrivialProperty extends Property {
TrivialProperty() {
getGetter().(TrivialGetter).getField() = getSetter().(TrivialSetter).getField()
}
/** Gets the underlying field of this property. */
Field getField() { result = getGetter().(TrivialGetter).getField() }
}
/** An event. */
class Event extends DotNet::Event, Member, @cil_event {
override string getName() { cil_event(this, _, result, _) }
/** Gets the type of this event. */
Type getType() { cil_event(this, _, _, result) }
override ValueOrRefType getDeclaringType() { cil_event(this, result, _, _) }
/** Gets the add event accessor. */
Method getAddEventAccessor() { cil_adder(this, result) }
/** Gets the remove event accessor. */
Method getRemoveEventAccessor() { cil_remover(this, result) }
/** Gets the raiser. */
Method getRaiser() { cil_raiser(this, result) }
override string toString() { result = "event " + getName() }
override string toStringWithTypes() {
result = getDeclaringType().toStringWithTypes() + "." + getName()
}
}