mirror of
https://github.com/github/codeql.git
synced 2026-04-20 06:24:03 +02:00
Merge pull request #15089 from github/koesie10/csharp-model-editor-generics
C#: Fix names of generic types/methods in model editor queries
This commit is contained in:
@@ -284,7 +284,7 @@ private predicate elementSpec(
|
||||
UnboundValueOrRefType t
|
||||
) {
|
||||
elementSpec(namespace, type, subtypes, name, signature, ext) and
|
||||
QN::hasQualifiedName(t, namespace, type)
|
||||
hasQualifiedTypeName(t, namespace, type)
|
||||
}
|
||||
|
||||
private class UnboundValueOrRefType extends ValueOrRefType {
|
||||
@@ -352,7 +352,7 @@ Declaration interpretBaseDeclaration(string namespace, string type, string name,
|
||||
exists(UnboundValueOrRefType t | elementSpec(namespace, type, _, name, signature, _, t) |
|
||||
result =
|
||||
any(Declaration d |
|
||||
QN::hasQualifiedName(d, namespace, type, name) and
|
||||
hasQualifiedMethodName(d, namespace, type, name) and
|
||||
(
|
||||
signature = ""
|
||||
or
|
||||
@@ -458,6 +458,19 @@ private module QualifiedNameInput implements QualifiedNameInputSig {
|
||||
|
||||
private module QN = QualifiedName<QualifiedNameInput>;
|
||||
|
||||
/** Holds if declaration `d` has the qualified name `qualifier`.`name`. */
|
||||
predicate hasQualifiedTypeName(Type t, string namespace, string type) {
|
||||
QN::hasQualifiedName(t, namespace, type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if declaration `d` has name `name` and is defined in type `type`
|
||||
* with namespace `namespace`.
|
||||
*/
|
||||
predicate hasQualifiedMethodName(Declaration d, string namespace, string type, string name) {
|
||||
QN::hasQualifiedName(d, namespace, type, name)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private string parameterQualifiedType(Parameter p) {
|
||||
exists(string qualifier, string name |
|
||||
|
||||
@@ -18,6 +18,6 @@ where
|
||||
usage = aUsage(endpoint) and
|
||||
type = supportedType(endpoint) and
|
||||
classification = methodClassification(usage)
|
||||
select usage, endpoint.getNamespace(), endpoint.getTypeName(), endpoint.getName(),
|
||||
select usage, endpoint.getNamespace(), endpoint.getTypeName(), endpoint.getEndpointName(),
|
||||
endpoint.getParameterTypes(), supported, endpoint.dllName(), endpoint.dllVersion(), type,
|
||||
classification
|
||||
|
||||
@@ -14,5 +14,5 @@ from PublicEndpointFromSource endpoint, boolean supported, string type
|
||||
where
|
||||
supported = isSupported(endpoint) and
|
||||
type = supportedType(endpoint)
|
||||
select endpoint, endpoint.getNamespace(), endpoint.getTypeName(), endpoint.getName(),
|
||||
select endpoint, endpoint.getNamespace(), endpoint.getTypeName(), endpoint.getEndpointName(),
|
||||
endpoint.getParameterTypes(), supported, endpoint.getFile().getBaseName(), type
|
||||
|
||||
@@ -34,7 +34,17 @@ class Endpoint extends Callable {
|
||||
* Gets the unbound type name of this endpoint.
|
||||
*/
|
||||
bindingset[this]
|
||||
string getTypeName() { result = nestedName(this.getDeclaringType().getUnboundDeclaration()) }
|
||||
string getTypeName() {
|
||||
result = qualifiedTypeName(this.getNamespace(), this.getDeclaringType().getUnboundDeclaration())
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the qualified name of this endpoint.
|
||||
*/
|
||||
bindingset[this]
|
||||
string getEndpointName() {
|
||||
result = qualifiedCallableName(this.getNamespace(), this.getTypeName(), this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameter types of this endpoint.
|
||||
@@ -107,15 +117,15 @@ string methodClassification(Call method) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nested name of the type `t`.
|
||||
*
|
||||
* If the type is not a nested type, the result is the same as `getName()`.
|
||||
* Otherwise the name of the nested type is prefixed with a `+` and appended to
|
||||
* the name of the enclosing type, which might be a nested type as well.
|
||||
* Gets the fully qualified name of the type `t`.
|
||||
*/
|
||||
private string nestedName(Type t) {
|
||||
not exists(t.getDeclaringType().getUnboundDeclaration()) and
|
||||
result = t.getName()
|
||||
or
|
||||
nestedName(t.getDeclaringType().getUnboundDeclaration()) + "+" + t.getName() = result
|
||||
private string qualifiedTypeName(string namespace, Type t) {
|
||||
exists(string type | hasQualifiedTypeName(t, namespace, type) | result = type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fully qualified name of the callable `c`.
|
||||
*/
|
||||
private string qualifiedCallableName(string namespace, string type, Callable c) {
|
||||
exists(string name | hasQualifiedMethodName(c, namespace, type, name) | result = name)
|
||||
}
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
| PublicClass.cs:40:19:40:29 | sourceStuff | GitHub.CodeQL | PublicClass | sourceStuff | () | true | PublicClass.cs | source |
|
||||
| PublicClass.cs:45:17:45:25 | sinkStuff | GitHub.CodeQL | PublicClass | sinkStuff | (System.String) | true | PublicClass.cs | sink |
|
||||
| PublicClass.cs:50:17:50:28 | neutralStuff | GitHub.CodeQL | PublicClass | neutralStuff | (System.String) | true | PublicClass.cs | neutral |
|
||||
| PublicGenericClass.cs:7:17:7:21 | stuff | GitHub.CodeQL | PublicGenericClass`2 | stuff | (T) | false | PublicGenericClass.cs | |
|
||||
| PublicGenericClass.cs:12:17:12:26 | stuff2`1 | GitHub.CodeQL | PublicGenericClass`2 | stuff2`1 | (T2) | false | PublicGenericClass.cs | |
|
||||
| PublicGenericInterface.cs:7:10:7:14 | stuff | GitHub.CodeQL | PublicGenericInterface`1 | stuff | (T) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericInterface.cs:9:10:9:19 | stuff2`1 | GitHub.CodeQL | PublicGenericInterface`1 | stuff2`1 | (T2) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericInterface.cs:11:17:11:27 | staticStuff | GitHub.CodeQL | PublicGenericInterface`1 | staticStuff | (System.String) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericClass.cs:7:17:7:21 | stuff | GitHub.CodeQL | PublicGenericClass<T,T2> | stuff | (T) | false | PublicGenericClass.cs | |
|
||||
| PublicGenericClass.cs:12:17:12:26 | stuff2`1 | GitHub.CodeQL | PublicGenericClass<T,T2> | stuff2<T2> | (T2) | false | PublicGenericClass.cs | |
|
||||
| PublicGenericClass.cs:17:18:17:36 | summaryStuff`1 | GitHub.CodeQL | PublicGenericClass<T,T2> | summaryStuff<TNode> | (TNode) | true | PublicGenericClass.cs | summary |
|
||||
| PublicGenericInterface.cs:7:10:7:14 | stuff | GitHub.CodeQL | PublicGenericInterface<T> | stuff | (T) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericInterface.cs:9:10:9:19 | stuff2`1 | GitHub.CodeQL | PublicGenericInterface<T> | stuff2<T2> | (T2) | false | PublicGenericInterface.cs | |
|
||||
| PublicGenericInterface.cs:11:17:11:27 | staticStuff | GitHub.CodeQL | PublicGenericInterface<T> | staticStuff | (System.String) | false | PublicGenericInterface.cs | |
|
||||
| PublicInterface.cs:7:10:7:14 | stuff | GitHub.CodeQL | PublicInterface | stuff | (System.String) | false | PublicInterface.cs | |
|
||||
| PublicInterface.cs:9:29:9:31 | get_PublicProperty | GitHub.CodeQL | PublicInterface | get_PublicProperty | () | false | PublicInterface.cs | |
|
||||
| PublicInterface.cs:9:34:9:36 | set_PublicProperty | GitHub.CodeQL | PublicInterface | set_PublicProperty | (System.String) | false | PublicInterface.cs | |
|
||||
|
||||
@@ -16,6 +16,7 @@ extensions:
|
||||
extensible: summaryModel
|
||||
data:
|
||||
- ["GitHub.CodeQL","PublicClass",true,"summaryStuff","(System.String)","","Argument[0]","ReturnValue","taint","manual"]
|
||||
- ["GitHub.CodeQL","PublicGenericClass<T,T2>",true,"summaryStuff<TNode>","(TNode)","","Argument[0]","ReturnValue","value","manual"]
|
||||
|
||||
- addsTo:
|
||||
pack: codeql/csharp-all
|
||||
|
||||
@@ -13,4 +13,9 @@ public class PublicGenericClass<T, T2> : PublicGenericInterface<T>
|
||||
{
|
||||
Console.WriteLine(arg);
|
||||
}
|
||||
|
||||
public TNode summaryStuff<TNode>(TNode arg)
|
||||
{
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user