Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5fc076

Browse files
committed
[CPP-386] Print QL AST classes next to elements in PrintAST trees.
1 parent ddb0fd9 commit e5fc076

31 files changed

Lines changed: 6573 additions & 6510 deletions

cpp/ql/src/semmle/code/cpp/Class.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Class extends UserType {
1515
isClass(underlyingElement(this))
1616
}
1717

18+
/** Canonical QL class corresponding to this element. */
19+
string getCanonicalQLClass() { result = "Class" }
20+
1821
/** Gets a child declaration of this class. */
1922
override Declaration getADeclaration() { result = this.getAMember() }
2023

@@ -980,6 +983,9 @@ class VirtualBaseClass extends Class {
980983
exists(VirtualClassDerivation cd | cd.getBaseClass() = this)
981984
}
982985

986+
/** Canonical QL class corresponding to this element. */
987+
string getCanonicalQLClass() { result = "VirtualBaseClass" }
988+
983989
/** A virtual class derivation of which this class is the base. */
984990
VirtualClassDerivation getAVirtualDerivation() {
985991
result.getBaseClass() = this
@@ -1004,6 +1010,9 @@ class ProxyClass extends UserType {
10041010
usertypes(underlyingElement(this),_,9)
10051011
}
10061012

1013+
/** Canonical QL class corresponding to this element. */
1014+
string getCanonicalQLClass() { result = "ProxyClass" }
1015+
10071016
/** Gets the location of the proxy class. */
10081017
override Location getLocation() {
10091018
result = getTemplateParameter().getDefinitionLocation()

cpp/ql/src/semmle/code/cpp/Element.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ pragma[inline]
5252
class ElementBase extends @element {
5353
/** Gets a textual representation of this element. */
5454
string toString() { none() }
55-
/** Retrieves canonical QL class(es) corresponding to this element. */
56-
string getCanonicalQLClass() { result = "ElementBase" }
55+
56+
/** Canonical QL class corresponding to this element. */
57+
string getCanonicalQLClass() { result = "???" }
5758
}
5859

5960
/**
@@ -64,9 +65,6 @@ class Element extends ElementBase {
6465
/** Gets the primary file where this element occurs. */
6566
File getFile() { result = this.getLocation().getFile() }
6667

67-
/** Retrieves canonical QL class(es) corresponding to this element. */
68-
string getCanonicalQLClass() { result = "Element" }
69-
7068
/**
7169
* Holds if this element may be from source.
7270
*

cpp/ql/src/semmle/code/cpp/Enum.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class Enum extends UserType, IntegralOrEnumType {
99
EnumConstant getAnEnumConstant() { result.getDeclaringEnum() = this }
1010
EnumConstant getEnumConstant(int index) { enumconstants(unresolveElement(result),underlyingElement(this),index,_,_,_) }
1111

12+
/** Canonical QL class corresponding to this element. */
13+
string getCanonicalQLClass() { result = "Enum" }
14+
1215
/**
1316
* Gets a descriptive string for the enum. This method is only intended to
1417
* be used for debugging purposes. For more information, see the comment
@@ -50,6 +53,8 @@ class LocalEnum extends Enum {
5053
LocalEnum() {
5154
isLocal()
5255
}
56+
/** Canonical QL class corresponding to this element. */
57+
string getCanonicalQLClass() { result = "LocalEnum" }
5358
}
5459

5560
/**
@@ -61,6 +66,9 @@ class NestedEnum extends Enum {
6166
this.isMember()
6267
}
6368

69+
/** Canonical QL class corresponding to this element. */
70+
string getCanonicalQLClass() { result = "NestedEnum" }
71+
6472
/** Holds if this member is private. */
6573
predicate isPrivate() { this.hasSpecifier("private") }
6674

@@ -81,6 +89,8 @@ class ScopedEnum extends Enum {
8189
ScopedEnum() {
8290
usertypes(underlyingElement(this),_,13)
8391
}
92+
/** Canonical QL class corresponding to this element. */
93+
string getCanonicalQLClass() { result = "ScopedEnum" }
8494
}
8595

8696
/**
@@ -96,6 +106,9 @@ class EnumConstant extends Declaration, @enumconstant {
96106
*/
97107
Enum getDeclaringEnum() { enumconstants(underlyingElement(this),unresolveElement(result),_,_,_,_) }
98108

109+
/** Canonical QL class corresponding to this element. */
110+
string getCanonicalQLClass() { result = "EnumConstant" }
111+
99112
override Class getDeclaringType() {
100113
result = this.getDeclaringEnum().getDeclaringType()
101114
}

cpp/ql/src/semmle/code/cpp/Function.qll

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ class TopLevelFunction extends Function {
707707
TopLevelFunction() {
708708
not this.isMember()
709709
}
710-
/** Retrieves canonical QL class(es) corresponding to this element. */
710+
/** Canonical QL class corresponding to this element. */
711711
string getCanonicalQLClass() { result = "TopLevelFunction" }
712712
}
713713

@@ -720,7 +720,7 @@ class MemberFunction extends Function {
720720
this.isMember()
721721
}
722722

723-
/** Retrieves canonical QL class(es) corresponding to this element. */
723+
/** Canonical QL class corresponding to this element. */
724724
string getCanonicalQLClass() { result = "MemberFunction" }
725725

726726
/**
@@ -774,6 +774,9 @@ class VirtualFunction extends MemberFunction {
774774
this.hasSpecifier("virtual") or purefunctions(underlyingElement(this))
775775
}
776776

777+
/** Canonical QL class corresponding to this element. */
778+
string getCanonicalQLClass() { result = "VirtualFunction" }
779+
777780
/** Holds if this virtual function is pure. */
778781
predicate isPure() { this instanceof PureVirtualFunction }
779782

@@ -791,6 +794,8 @@ class PureVirtualFunction extends VirtualFunction {
791794

792795
PureVirtualFunction() { purefunctions(underlyingElement(this)) }
793796

797+
/** Canonical QL class corresponding to this element. */
798+
string getCanonicalQLClass() { result = "PureVirtualFunction" }
794799
}
795800

796801
/**
@@ -802,6 +807,8 @@ class ConstMemberFunction extends MemberFunction {
802807

803808
ConstMemberFunction() { this.hasSpecifier("const") }
804809

810+
/** Canonical QL class corresponding to this element. */
811+
string getCanonicalQLClass() { result = "ConstMemberFunction" }
805812
}
806813

807814
/**
@@ -811,6 +818,9 @@ class Constructor extends MemberFunction {
811818

812819
Constructor() { functions(underlyingElement(this),_,2) }
813820

821+
/** Canonical QL class corresponding to this element. */
822+
string getCanonicalQLClass() { result = "Constructor" }
823+
814824
/**
815825
* Holds if this constructor serves as a default constructor.
816826
*
@@ -856,6 +866,9 @@ class ConversionConstructor extends Constructor, ImplicitConversionFunction {
856866
and not(this instanceof CopyConstructor)
857867
}
858868

869+
/** Canonical QL class corresponding to this element. */
870+
string getCanonicalQLClass() { result = "ConversionConstructor" }
871+
859872
/** Gets the type this `ConversionConstructor` takes as input. */
860873
override Type getSourceType() { result = this.getParameter(0).getType() }
861874

@@ -911,6 +924,9 @@ class CopyConstructor extends Constructor {
911924
not exists(getATemplateArgument())
912925
}
913926

927+
/** Canonical QL class corresponding to this element. */
928+
string getCanonicalQLClass() { result = "CopyConstructor" }
929+
914930
/**
915931
* Holds if we cannot determine that this constructor will become a copy
916932
* constructor in all instantiations. Depending on template parameters of the
@@ -959,6 +975,9 @@ class MoveConstructor extends Constructor {
959975
not exists(getATemplateArgument())
960976
}
961977

978+
/** Canonical QL class corresponding to this element. */
979+
string getCanonicalQLClass() { result = "MoveConstructor" }
980+
962981
/**
963982
* Holds if we cannot determine that this constructor will become a move
964983
* constructor in all instantiations. Depending on template parameters of the
@@ -991,6 +1010,9 @@ class NoArgConstructor extends Constructor {
9911010
class Destructor extends MemberFunction {
9921011
Destructor() { functions(underlyingElement(this),_,3) }
9931012

1013+
/** Canonical QL class corresponding to this element. */
1014+
string getCanonicalQLClass() { result = "Destructor" }
1015+
9941016
/**
9951017
* Gets a compiler-generated action which destructs a base class or member
9961018
* variable.
@@ -1050,6 +1072,8 @@ class CopyAssignmentOperator extends Operator {
10501072
not exists(this.getParameter(1)) and
10511073
not exists(getATemplateArgument())
10521074
}
1075+
/** Canonical QL class corresponding to this element. */
1076+
string getCanonicalQLClass() { result = "CopyAssignmentOperator" }
10531077
}
10541078

10551079

@@ -1069,6 +1093,8 @@ class MoveAssignmentOperator extends Operator {
10691093
not exists(this.getParameter(1)) and
10701094
not exists(getATemplateArgument())
10711095
}
1096+
/** Canonical QL class corresponding to this element. */
1097+
string getCanonicalQLClass() { result = "MoveAssignmentOperator" }
10721098
}
10731099

10741100

@@ -1089,6 +1115,8 @@ class MoveAssignmentOperator extends Operator {
10891115
class TemplateFunction extends Function {
10901116
TemplateFunction() { is_function_template(underlyingElement(this)) and exists(getATemplateArgument()) }
10911117

1118+
/** Canonical QL class corresponding to this element. */
1119+
string getCanonicalQLClass() { result = "TemplateFunction" }
10921120
/**
10931121
* Gets a compiler-generated instantiation of this function template.
10941122
*/
@@ -1120,6 +1148,9 @@ class FunctionTemplateInstantiation extends Function {
11201148
tf.getAnInstantiation() = this
11211149
}
11221150

1151+
/** Canonical QL class corresponding to this element. */
1152+
string getCanonicalQLClass() { result = "FunctionTemplateSpecialization" }
1153+
11231154
/**
11241155
* Gets the function template from which this instantiation was instantiated.
11251156
*
@@ -1156,6 +1187,9 @@ class FunctionTemplateSpecialization extends Function {
11561187
this.isSpecialization()
11571188
}
11581189

1190+
/** Canonical QL class corresponding to this element. */
1191+
string getCanonicalQLClass() { result = "FunctionTemplateSpecialization" }
1192+
11591193
/**
11601194
* Gets the primary template for the specialization (the function template
11611195
* this specializes).

cpp/ql/src/semmle/code/cpp/Initializer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import semmle.code.cpp.controlflow.ControlFlowGraph
66
class Initializer extends ControlFlowNode, @initialiser {
77
override Location getLocation() { initialisers(underlyingElement(this),_,_,result) }
88

9-
/** Retrieves canonical QL class(es) corresponding to this element. */
9+
/** Canonical QL class corresponding to this element. */
1010
string getCanonicalQLClass() { result = "Initializer" }
1111

1212
/** Holds if this initializer is explicit in the source. */

cpp/ql/src/semmle/code/cpp/Parameter.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Parameter extends LocalScopeVariable, @parameter {
3333
result = "p#" + this.getIndex().toString())
3434
}
3535

36-
/** Retrieves canonical QL class(es) corresponding to this element. */
36+
/** Canonical QL class corresponding to this element. */
3737
string getCanonicalQLClass() { result = "Parameter" }
3838

3939
/**

cpp/ql/src/semmle/code/cpp/PrintAST.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class PrintASTNode extends TPrintASTNode {
163163
* A concatenation of all the leaf QL types of `el`
164164
*/
165165
private string qlClass(ElementBase el) { result = "["+ el.getCanonicalQLClass() + "]: " }
166+
//private string qlClass(ElementBase el) { result = "["+ concat(el.getAQlClass(), ",") + "]: " }
166167

167168
/**
168169
* A node representing an AST node.

cpp/ql/src/semmle/code/cpp/Struct.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class Struct extends Class {
88

99
Struct() { usertypes(underlyingElement(this),_,1) or usertypes(underlyingElement(this),_,3) }
1010

11+
/** Canonical QL class corresponding to this element. */
12+
string getCanonicalQLClass() { result = "Struct" }
13+
1114
override string explain() { result = "struct " + this.getName() }
1215

1316
override predicate isDeeplyConstBelow() { any() } // No subparts

0 commit comments

Comments
 (0)