Skip to content

Commit 215808d

Browse files
committed
C#: Copy dotnet.Declaration implementation.
1 parent cdf3d47 commit 215808d

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

csharp/ql/lib/semmle/code/csharp/Member.qll

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,46 @@ private module FullyQualifiedNameInput implements QualifiedNameInputSig {
2626
*
2727
* Either a modifiable (`Modifiable`) or an assignable (`Assignable`).
2828
*/
29-
class Declaration extends DotNet::Declaration, Element, @declaration {
30-
override ValueOrRefType getDeclaringType() { none() }
29+
class Declaration extends NamedElement, @declaration {
30+
/** Gets the name of this declaration, without additional decoration such as `<...>`. */
31+
string getUndecoratedName() { none() }
32+
33+
/** Holds if this element has undecorated name 'name'. */
34+
final predicate hasUndecoratedName(string name) { name = this.getUndecoratedName() }
35+
36+
/**
37+
* Gets the unbound version of this declaration, that is, the declaration where
38+
* all type arguments have been removed. For example, in
39+
*
40+
* ```csharp
41+
* class C<T>
42+
* {
43+
* class Nested
44+
* {
45+
* }
46+
*
47+
* void Method<S>() { }
48+
* }
49+
* ```
50+
*
51+
* we have the following
52+
*
53+
* | Declaration | Unbound declaration |
54+
* |-------------------------|---------------------|
55+
* | `C<int>` | ``C`1`` |
56+
* | ``C`1.Nested`` | ``C`1.Nested`` |
57+
* | `C<int>.Nested` | ``C`1.Nested`` |
58+
* | ``C`1.Method`1`` | ``C`1.Method`1`` |
59+
* | ``C<int>.Method`1`` | ``C`1.Method`1`` |
60+
* | `C<int>.Method<string>` | ``C`1.Method`1`` |
61+
*/
62+
Declaration getUnboundDeclaration() { result = this }
63+
64+
/** Holds if this declaration is unbound. */
65+
final predicate isUnboundDeclaration() { this.getUnboundDeclaration() = this }
66+
67+
/** Gets the type containing this declaration, if any. */
68+
ValueOrRefType getDeclaringType() { none() }
3169

3270
/** Holds if this declaration is unconstructed and in source code. */
3371
final predicate isSourceDeclaration() { this.fromSource() and this.isUnboundDeclaration() }
@@ -222,33 +260,54 @@ class Modifiable extends Declaration, @modifiable {
222260
}
223261

224262
/** A declaration that is a member of a type. */
225-
class Member extends DotNet::Member, Modifiable, @member {
263+
class Member extends Modifiable, @member {
226264
/** Gets an access to this member. */
227265
MemberAccess getAnAccess() { result.getTarget() = this }
228266

267+
/** Holds if this member is declared `public`. */
229268
override predicate isPublic() { Modifiable.super.isPublic() }
230269

270+
/** Holds if this member is declared `protected.` */
231271
override predicate isProtected() { Modifiable.super.isProtected() }
232272

273+
/** Holds if this member is `private`. */
233274
override predicate isPrivate() { Modifiable.super.isPrivate() }
234275

276+
/** Holds if this member is `internal`. */
235277
override predicate isInternal() { Modifiable.super.isInternal() }
236278

279+
/** Holds if this member is `sealed`. */
237280
override predicate isSealed() { Modifiable.super.isSealed() }
238281

282+
/** Holds if this member is `abstract`. */
239283
override predicate isAbstract() { Modifiable.super.isAbstract() }
240284

285+
/** Holds if this member is `static`. */
241286
override predicate isStatic() { Modifiable.super.isStatic() }
242287

288+
/** Holds if this member is declared `required`. */
243289
override predicate isRequired() { Modifiable.super.isRequired() }
244290

291+
/** Holds if this member is declared `file` local. */
245292
override predicate isFile() { Modifiable.super.isFile() }
246293

247-
deprecated final override predicate hasQualifiedName(string namespace, string type, string name) {
294+
/**
295+
* DEPRECATED: Use `hasFullyQualifiedName` instead.
296+
*
297+
* Holds if this member has name `name` and is defined in type `type`
298+
* with namespace `namespace`.
299+
*/
300+
cached
301+
deprecated final predicate hasQualifiedName(string namespace, string type, string name) {
248302
QualifiedName<QualifiedNameInput>::hasQualifiedName(this, namespace, type, name)
249303
}
250304

251-
final override predicate hasFullyQualifiedName(string namespace, string type, string name) {
305+
/**
306+
* Holds if this member has name `name` and is defined in type `type`
307+
* with namespace `namespace`.
308+
*/
309+
cached
310+
final predicate hasFullyQualifiedName(string namespace, string type, string name) {
252311
QualifiedName<FullyQualifiedNameInput>::hasQualifiedName(this, namespace, type, name)
253312
}
254313
}

csharp/ql/lib/semmle/code/csharp/Property.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class DeclarationWithGetSetAccessors extends DeclarationWithAccessors, TopLevelE
113113
* }
114114
* ```
115115
*/
116-
class Property extends DotNet::Property, DeclarationWithGetSetAccessors, @property {
116+
class Property extends DeclarationWithGetSetAccessors, @property {
117117
override string getName() { properties(this, result, _, _, _) }
118118

119119
override string getUndecoratedName() { properties(this, result, _, _, _) }

0 commit comments

Comments
 (0)