mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
C++: Autoformat QualifiedName.qll
This commit is contained in:
@@ -7,9 +7,11 @@ class Namespace extends @namespace {
|
|||||||
|
|
||||||
string getQualifiedName() {
|
string getQualifiedName() {
|
||||||
if namespacembrs(_, this)
|
if namespacembrs(_, this)
|
||||||
then exists(Namespace ns |
|
then
|
||||||
|
exists(Namespace ns |
|
||||||
namespacembrs(ns, this) and
|
namespacembrs(ns, this) and
|
||||||
result = ns.getQualifiedName() + "::" + this.getName())
|
result = ns.getQualifiedName() + "::" + this.getName()
|
||||||
|
)
|
||||||
else result = this.getName()
|
else result = this.getName()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,68 +33,81 @@ abstract class Declaration extends @declaration {
|
|||||||
Namespace getNamespace() {
|
Namespace getNamespace() {
|
||||||
// Top level declaration in a namespace ...
|
// Top level declaration in a namespace ...
|
||||||
result.getADeclaration() = this
|
result.getADeclaration() = this
|
||||||
// ... or nested in another structure.
|
|
||||||
or
|
or
|
||||||
exists (Declaration m
|
// ... or nested in another structure.
|
||||||
| m = this and result = m.getDeclaringType().getNamespace())
|
exists(Declaration m | m = this and result = m.getDeclaringType().getNamespace())
|
||||||
}
|
}
|
||||||
|
|
||||||
string getQualifiedName() {
|
string getQualifiedName() {
|
||||||
// MemberFunction, MemberVariable, MemberType
|
// MemberFunction, MemberVariable, MemberType
|
||||||
exists (Declaration m
|
exists(Declaration m |
|
||||||
| m = this and
|
m = this and
|
||||||
result = m.getDeclaringType().getQualifiedName() + "::" + m.getName())
|
result = m.getDeclaringType().getQualifiedName() + "::" + m.getName()
|
||||||
|
)
|
||||||
or
|
or
|
||||||
exists (EnumConstant c
|
exists(EnumConstant c |
|
||||||
| c = this and
|
c = this and
|
||||||
result = c.getDeclaringEnum().getQualifiedName() + "::" + c.getName())
|
result = c.getDeclaringEnum().getQualifiedName() + "::" + c.getName()
|
||||||
|
)
|
||||||
or
|
or
|
||||||
exists (GlobalOrNamespaceVariable v, string s1, string s2
|
exists(GlobalOrNamespaceVariable v, string s1, string s2 |
|
||||||
| v = this and
|
v = this and
|
||||||
s2 = v.getNamespace().getQualifiedName() and
|
s2 = v.getNamespace().getQualifiedName() and
|
||||||
s1 = v.getName()
|
s1 = v.getName()
|
||||||
| (s2 != "" and result = s2 + "::" + s1) or (s2 = "" and result = s1))
|
|
|
||||||
|
s2 != "" and result = s2 + "::" + s1
|
||||||
or
|
or
|
||||||
exists (Function f, string s1, string s2
|
s2 = "" and result = s1
|
||||||
| f = this and f.isTopLevel() and
|
)
|
||||||
|
or
|
||||||
|
exists(Function f, string s1, string s2 |
|
||||||
|
f = this and
|
||||||
|
f.isTopLevel() and
|
||||||
s2 = f.getNamespace().getQualifiedName() and
|
s2 = f.getNamespace().getQualifiedName() and
|
||||||
s1 = f.getName()
|
s1 = f.getName()
|
||||||
| (s2 != "" and result = s2 + "::" + s1) or (s2 = "" and result = s1))
|
|
|
||||||
|
s2 != "" and result = s2 + "::" + s1
|
||||||
or
|
or
|
||||||
exists (UserType t, string s1, string s2
|
s2 = "" and result = s1
|
||||||
| t = this and t.isTopLevel() and
|
)
|
||||||
|
or
|
||||||
|
exists(UserType t, string s1, string s2 |
|
||||||
|
t = this and
|
||||||
|
t.isTopLevel() and
|
||||||
s2 = t.getNamespace().getQualifiedName() and
|
s2 = t.getNamespace().getQualifiedName() and
|
||||||
s1 = t.getName()
|
s1 = t.getName()
|
||||||
| (s2 != "" and result = s2 + "::" + s1) or (s2 = "" and result = s1))
|
|
|
||||||
|
s2 != "" and result = s2 + "::" + s1
|
||||||
|
or
|
||||||
|
s2 = "" and result = s1
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
predicate isTopLevel() {
|
predicate isTopLevel() {
|
||||||
not (this.isMember() or
|
not (
|
||||||
|
this.isMember() or
|
||||||
this instanceof FriendDecl or
|
this instanceof FriendDecl or
|
||||||
this instanceof EnumConstant or
|
this instanceof EnumConstant or
|
||||||
this instanceof Parameter or
|
this instanceof Parameter or
|
||||||
this instanceof ProxyClass or
|
this instanceof ProxyClass or
|
||||||
this instanceof LocalVariable or
|
this instanceof LocalVariable or
|
||||||
this instanceof TemplateParameter or
|
this instanceof TemplateParameter or
|
||||||
this.(UserType).isLocal())
|
this.(UserType).isLocal()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Holds if this declaration is a member of a class/struct/union. */
|
/** Holds if this declaration is a member of a class/struct/union. */
|
||||||
predicate isMember() { this.hasDeclaringType() }
|
predicate isMember() { this.hasDeclaringType() }
|
||||||
|
|
||||||
/** Holds if this declaration is a member of a class/struct/union. */
|
/** Holds if this declaration is a member of a class/struct/union. */
|
||||||
predicate hasDeclaringType() {
|
predicate hasDeclaringType() { exists(this.getDeclaringType()) }
|
||||||
exists(this.getDeclaringType())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the class where this member is declared, if it is a member.
|
* Gets the class where this member is declared, if it is a member.
|
||||||
* For templates, both the template itself and all instantiations of
|
* For templates, both the template itself and all instantiations of
|
||||||
* the template are considered to have the same declaring class.
|
* the template are considered to have the same declaring class.
|
||||||
*/
|
*/
|
||||||
Class getDeclaringType() {
|
Class getDeclaringType() { this = result.getAMember() }
|
||||||
this = result.getAMember()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Variable extends Declaration, @variable {
|
class Variable extends Declaration, @variable {
|
||||||
@@ -122,9 +137,7 @@ class GlobalOrNamespaceVariable extends Variable, @globalvariable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MemberVariable extends Variable, @membervariable {
|
class MemberVariable extends Variable, @membervariable {
|
||||||
MemberVariable() {
|
MemberVariable() { this.isMember() }
|
||||||
this.isMember()
|
|
||||||
}
|
|
||||||
|
|
||||||
override string getName() { membervariables(this, _, result) }
|
override string getName() { membervariables(this, _, result) }
|
||||||
}
|
}
|
||||||
@@ -140,23 +153,18 @@ class Function extends Declaration, @function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TemplateFunction extends Function {
|
class TemplateFunction extends Function {
|
||||||
TemplateFunction() {
|
TemplateFunction() { is_function_template(this) and function_template_argument(this, _, _) }
|
||||||
is_function_template(this) and function_template_argument(this, _, _)
|
|
||||||
}
|
|
||||||
|
|
||||||
Function getAnInstantiation() {
|
Function getAnInstantiation() {
|
||||||
function_instantiation(result, this)
|
function_instantiation(result, this) and
|
||||||
and not exists(@fun_decl fd |
|
not exists(@fun_decl fd | fun_decls(fd, this, _, _, _) and fun_specialized(fd))
|
||||||
fun_decls(fd, this, _, _, _) and fun_specialized(fd))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserType extends Declaration, @usertype {
|
class UserType extends Declaration, @usertype {
|
||||||
override string getName() { usertypes(this, result, _) }
|
override string getName() { usertypes(this, result, _) }
|
||||||
|
|
||||||
predicate isLocal() {
|
predicate isLocal() { enclosingfunction(this, _) }
|
||||||
enclosingfunction(this, _)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProxyClass extends UserType {
|
class ProxyClass extends UserType {
|
||||||
@@ -175,7 +183,8 @@ class Class extends UserType {
|
|||||||
result = d or
|
result = d or
|
||||||
result = d.(TemplateClass).getAnInstantiation() or
|
result = d.(TemplateClass).getAnInstantiation() or
|
||||||
result = d.(TemplateFunction).getAnInstantiation() or
|
result = d.(TemplateFunction).getAnInstantiation() or
|
||||||
result = d.(TemplateVariable).getAnInstantiation())
|
result = d.(TemplateVariable).getAnInstantiation()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,9 +204,7 @@ deprecated class Property extends Declaration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FriendDecl extends Declaration, @frienddecl {
|
class FriendDecl extends Declaration, @frienddecl {
|
||||||
override string getName() {
|
override string getName() { result = this.getDeclaringClass().getName() + "'s friend" }
|
||||||
result = this.getDeclaringClass().getName() + "'s friend"
|
|
||||||
}
|
|
||||||
|
|
||||||
Class getDeclaringClass() { frienddecls(this, result, _, _) }
|
Class getDeclaringClass() { frienddecls(this, result, _, _) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user