C++: Autoformat QualifiedName.qll

This commit is contained in:
Jonas Jensen
2019-04-30 16:09:41 +02:00
parent b97ff1a72f
commit b51ce87ae8

View File

@@ -7,9 +7,11 @@ class Namespace extends @namespace {
string getQualifiedName() {
if namespacembrs(_, this)
then exists(Namespace ns |
namespacembrs(ns, this) and
result = ns.getQualifiedName() + "::" + this.getName())
then
exists(Namespace ns |
namespacembrs(ns, this) and
result = ns.getQualifiedName() + "::" + this.getName()
)
else result = this.getName()
}
@@ -31,68 +33,81 @@ abstract class Declaration extends @declaration {
Namespace getNamespace() {
// Top level declaration in a namespace ...
result.getADeclaration() = this
// ... or nested in another structure.
or
exists (Declaration m
| m = this and result = m.getDeclaringType().getNamespace())
// ... or nested in another structure.
exists(Declaration m | m = this and result = m.getDeclaringType().getNamespace())
}
string getQualifiedName() {
// MemberFunction, MemberVariable, MemberType
exists (Declaration m
| m = this and
result = m.getDeclaringType().getQualifiedName() + "::" + m.getName())
exists(Declaration m |
m = this and
result = m.getDeclaringType().getQualifiedName() + "::" + m.getName()
)
or
exists (EnumConstant c
| c = this and
result = c.getDeclaringEnum().getQualifiedName() + "::" + c.getName())
exists(EnumConstant c |
c = this and
result = c.getDeclaringEnum().getQualifiedName() + "::" + c.getName()
)
or
exists (GlobalOrNamespaceVariable v, string s1, string s2
| v = this and
exists(GlobalOrNamespaceVariable v, string s1, string s2 |
v = this and
s2 = v.getNamespace().getQualifiedName() and
s1 = v.getName()
| (s2 != "" and result = s2 + "::" + s1) or (s2 = "" and result = s1))
|
s2 != "" and result = s2 + "::" + s1
or
s2 = "" and result = s1
)
or
exists (Function f, string s1, string s2
| f = this and f.isTopLevel() and
exists(Function f, string s1, string s2 |
f = this and
f.isTopLevel() and
s2 = f.getNamespace().getQualifiedName() and
s1 = f.getName()
| (s2 != "" and result = s2 + "::" + s1) or (s2 = "" and result = s1))
|
s2 != "" and result = s2 + "::" + s1
or
s2 = "" and result = s1
)
or
exists (UserType t, string s1, string s2
| t = this and t.isTopLevel() and
exists(UserType t, string s1, string s2 |
t = this and
t.isTopLevel() and
s2 = t.getNamespace().getQualifiedName() and
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() {
not (this.isMember() or
this instanceof FriendDecl or
this instanceof EnumConstant or
this instanceof Parameter or
this instanceof ProxyClass or
this instanceof LocalVariable or
this instanceof TemplateParameter or
this.(UserType).isLocal())
not (
this.isMember() or
this instanceof FriendDecl or
this instanceof EnumConstant or
this instanceof Parameter or
this instanceof ProxyClass or
this instanceof LocalVariable or
this instanceof TemplateParameter or
this.(UserType).isLocal()
)
}
/** Holds if this declaration is a member of a class/struct/union. */
predicate isMember() { this.hasDeclaringType() }
/** Holds if this declaration is a member of a class/struct/union. */
predicate hasDeclaringType() {
exists(this.getDeclaringType())
}
predicate hasDeclaringType() { exists(this.getDeclaringType()) }
/**
* Gets the class where this member is declared, if it is a member.
* For templates, both the template itself and all instantiations of
* the template are considered to have the same declaring class.
*/
Class getDeclaringType() {
this = result.getAMember()
}
Class getDeclaringType() { this = result.getAMember() }
}
class Variable extends Declaration, @variable {
@@ -105,7 +120,7 @@ class TemplateVariable extends Variable {
Variable getAnInstantiation() { variable_instantiation(result, this) }
}
class LocalScopeVariable extends Variable, @localscopevariable {}
class LocalScopeVariable extends Variable, @localscopevariable { }
class LocalVariable extends LocalScopeVariable, @localvariable {
override string getName() { localvariables(this, _, result) }
@@ -122,15 +137,13 @@ class GlobalOrNamespaceVariable extends Variable, @globalvariable {
}
class MemberVariable extends Variable, @membervariable {
MemberVariable() {
this.isMember()
}
MemberVariable() { this.isMember() }
override string getName() { membervariables(this, _, result) }
}
class EnumConstant extends Declaration, @enumconstant {
override string getName() { enumconstants(this, _, _, _, result,_) }
override string getName() { enumconstants(this, _, _, _, result, _) }
UserType getDeclaringEnum() { enumconstants(this, result, _, _, _, _) }
}
@@ -140,23 +153,18 @@ class Function extends Declaration, @function {
}
class TemplateFunction extends Function {
TemplateFunction() {
is_function_template(this) and function_template_argument(this, _, _)
}
TemplateFunction() { is_function_template(this) and function_template_argument(this, _, _) }
Function getAnInstantiation() {
function_instantiation(result, this)
and not exists(@fun_decl fd |
fun_decls(fd, this, _, _, _) and fun_specialized(fd))
function_instantiation(result, this) and
not exists(@fun_decl fd | fun_decls(fd, this, _, _, _) and fun_specialized(fd))
}
}
class UserType extends Declaration, @usertype {
override string getName() { usertypes(this, result, _) }
predicate isLocal() {
enclosingfunction(this, _)
}
predicate isLocal() { enclosingfunction(this, _) }
}
class ProxyClass extends UserType {
@@ -171,11 +179,12 @@ class Class extends UserType {
Class() { ResolveClass::isClass(this) }
Declaration getAMember() {
exists(Declaration d | member(this, _ ,d) |
exists(Declaration d | member(this, _, d) |
result = d or
result = d.(TemplateClass).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 {
override string getName() {
result = this.getDeclaringClass().getName() + "'s friend"
}
override string getName() { result = this.getDeclaringClass().getName() + "'s friend" }
Class getDeclaringClass() { frienddecls(this, result, _, _) }
}