Skip to content

Commit e00a8f7

Browse files
author
Dave Bartolomeo
authored
Merge pull request github#3815 from jbj/getAPrimaryQlClass
C++: getCanonicalQLClass -> getAPrimaryQlClass
2 parents 3aefb7f + a22fb76 commit e00a8f7

40 files changed

+376
-375
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private import semmle.code.cpp.internal.ResolveClass
3333
class Class extends UserType {
3434
Class() { isClass(underlyingElement(this)) }
3535

36-
override string getCanonicalQLClass() { result = "Class" }
36+
override string getAPrimaryQlClass() { result = "Class" }
3737

3838
/** Gets a child declaration of this class, struct or union. */
3939
override Declaration getADeclaration() { result = this.getAMember() }
@@ -768,7 +768,7 @@ class ClassDerivation extends Locatable, @derivation {
768768
*/
769769
Class getBaseClass() { result = getBaseType().getUnderlyingType() }
770770

771-
override string getCanonicalQLClass() { result = "ClassDerivation" }
771+
override string getAPrimaryQlClass() { result = "ClassDerivation" }
772772

773773
/**
774774
* Gets the type from which we are deriving, without resolving any
@@ -849,9 +849,7 @@ class ClassDerivation extends Locatable, @derivation {
849849
class LocalClass extends Class {
850850
LocalClass() { isLocal() }
851851

852-
override string getCanonicalQLClass() {
853-
not this instanceof LocalStruct and result = "LocalClass"
854-
}
852+
override string getAPrimaryQlClass() { not this instanceof LocalStruct and result = "LocalClass" }
855853

856854
override Function getEnclosingAccessHolder() { result = this.getEnclosingFunction() }
857855
}
@@ -872,7 +870,7 @@ class LocalClass extends Class {
872870
class NestedClass extends Class {
873871
NestedClass() { this.isMember() }
874872

875-
override string getCanonicalQLClass() {
873+
override string getAPrimaryQlClass() {
876874
not this instanceof NestedStruct and result = "NestedClass"
877875
}
878876

@@ -893,7 +891,7 @@ class NestedClass extends Class {
893891
class AbstractClass extends Class {
894892
AbstractClass() { exists(PureVirtualFunction f | this.getAMemberFunction() = f) }
895893

896-
override string getCanonicalQLClass() { result = "AbstractClass" }
894+
override string getAPrimaryQlClass() { result = "AbstractClass" }
897895
}
898896

899897
/**
@@ -934,7 +932,7 @@ class TemplateClass extends Class {
934932
exists(result.getATemplateArgument())
935933
}
936934

937-
override string getCanonicalQLClass() { result = "TemplateClass" }
935+
override string getAPrimaryQlClass() { result = "TemplateClass" }
938936
}
939937

940938
/**
@@ -955,7 +953,7 @@ class ClassTemplateInstantiation extends Class {
955953

956954
ClassTemplateInstantiation() { tc.getAnInstantiation() = this }
957955

958-
override string getCanonicalQLClass() { result = "ClassTemplateInstantiation" }
956+
override string getAPrimaryQlClass() { result = "ClassTemplateInstantiation" }
959957

960958
/**
961959
* Gets the class template from which this instantiation was instantiated.
@@ -996,7 +994,7 @@ abstract class ClassTemplateSpecialization extends Class {
996994
count(int i | exists(result.getTemplateArgument(i)))
997995
}
998996

999-
override string getCanonicalQLClass() { result = "ClassTemplateSpecialization" }
997+
override string getAPrimaryQlClass() { result = "ClassTemplateSpecialization" }
1000998
}
1001999

10021000
/**
@@ -1025,7 +1023,7 @@ class FullClassTemplateSpecialization extends ClassTemplateSpecialization {
10251023
not this instanceof ClassTemplateInstantiation
10261024
}
10271025

1028-
override string getCanonicalQLClass() { result = "FullClassTemplateSpecialization" }
1026+
override string getAPrimaryQlClass() { result = "FullClassTemplateSpecialization" }
10291027
}
10301028

10311029
/**
@@ -1064,7 +1062,7 @@ class PartialClassTemplateSpecialization extends ClassTemplateSpecialization {
10641062
count(int i | exists(getTemplateArgument(i)))
10651063
}
10661064

1067-
override string getCanonicalQLClass() { result = "PartialClassTemplateSpecialization" }
1065+
override string getAPrimaryQlClass() { result = "PartialClassTemplateSpecialization" }
10681066
}
10691067

10701068
/**
@@ -1089,7 +1087,7 @@ deprecated class Interface extends Class {
10891087
)
10901088
}
10911089

1092-
override string getCanonicalQLClass() { result = "Interface" }
1090+
override string getAPrimaryQlClass() { result = "Interface" }
10931091
}
10941092

10951093
/**
@@ -1104,7 +1102,7 @@ deprecated class Interface extends Class {
11041102
class VirtualClassDerivation extends ClassDerivation {
11051103
VirtualClassDerivation() { hasSpecifier("virtual") }
11061104

1107-
override string getCanonicalQLClass() { result = "VirtualClassDerivation" }
1105+
override string getAPrimaryQlClass() { result = "VirtualClassDerivation" }
11081106
}
11091107

11101108
/**
@@ -1124,7 +1122,7 @@ class VirtualClassDerivation extends ClassDerivation {
11241122
class VirtualBaseClass extends Class {
11251123
VirtualBaseClass() { exists(VirtualClassDerivation cd | cd.getBaseClass() = this) }
11261124

1127-
override string getCanonicalQLClass() { result = "VirtualBaseClass" }
1125+
override string getAPrimaryQlClass() { result = "VirtualBaseClass" }
11281126

11291127
/** A virtual class derivation of which this class/struct is the base. */
11301128
VirtualClassDerivation getAVirtualDerivation() { result.getBaseClass() = this }
@@ -1146,7 +1144,7 @@ class VirtualBaseClass extends Class {
11461144
class ProxyClass extends UserType {
11471145
ProxyClass() { usertypes(underlyingElement(this), _, 9) }
11481146

1149-
override string getCanonicalQLClass() { result = "ProxyClass" }
1147+
override string getAPrimaryQlClass() { result = "ProxyClass" }
11501148

11511149
/** Gets the location of the proxy class. */
11521150
override Location getLocation() { result = getTemplateParameter().getDefinitionLocation() }

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,21 @@ class ElementBase extends @element {
5555
cached
5656
string toString() { none() }
5757

58+
/** DEPRECATED: use `getAPrimaryQlClass` instead. */
59+
deprecated string getCanonicalQLClass() { result = this.getAPrimaryQlClass() }
60+
5861
/**
59-
* Canonical QL class corresponding to this element.
62+
* Gets the name of a primary CodeQL class to which this element belongs.
63+
*
64+
* For most elements, this is simply the most precise syntactic category to
65+
* which they belong; for example, `AddExpr` is a primary class, but
66+
* `BinaryOperation` is not.
6067
*
61-
* ElementBase is the root class for this predicate.
68+
* This predicate always has a result. If no primary class can be
69+
* determined, the result is `"???"`. If multiple primary classes match,
70+
* this predicate can have multiple results.
6271
*/
63-
string getCanonicalQLClass() { result = "???" }
72+
string getAPrimaryQlClass() { result = "???" }
6473
}
6574

6675
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Enum extends UserType, IntegralOrEnumType {
3838
enumconstants(unresolveElement(result), underlyingElement(this), index, _, _, _)
3939
}
4040

41-
override string getCanonicalQLClass() { result = "Enum" }
41+
override string getAPrimaryQlClass() { result = "Enum" }
4242

4343
/**
4444
* Gets a descriptive string for the enum. This method is only intended to
@@ -87,7 +87,7 @@ class Enum extends UserType, IntegralOrEnumType {
8787
class LocalEnum extends Enum {
8888
LocalEnum() { isLocal() }
8989

90-
override string getCanonicalQLClass() { result = "LocalEnum" }
90+
override string getAPrimaryQlClass() { result = "LocalEnum" }
9191
}
9292

9393
/**
@@ -105,7 +105,7 @@ class LocalEnum extends Enum {
105105
class NestedEnum extends Enum {
106106
NestedEnum() { this.isMember() }
107107

108-
override string getCanonicalQLClass() { result = "NestedEnum" }
108+
override string getAPrimaryQlClass() { result = "NestedEnum" }
109109

110110
/** Holds if this member is private. */
111111
predicate isPrivate() { this.hasSpecifier("private") }
@@ -130,7 +130,7 @@ class NestedEnum extends Enum {
130130
class ScopedEnum extends Enum {
131131
ScopedEnum() { usertypes(underlyingElement(this), _, 13) }
132132

133-
override string getCanonicalQLClass() { result = "ScopedEnum" }
133+
override string getAPrimaryQlClass() { result = "ScopedEnum" }
134134
}
135135

136136
/**
@@ -153,7 +153,7 @@ class EnumConstant extends Declaration, @enumconstant {
153153
enumconstants(underlyingElement(this), unresolveElement(result), _, _, _, _)
154154
}
155155

156-
override string getCanonicalQLClass() { result = "EnumConstant" }
156+
override string getAPrimaryQlClass() { result = "EnumConstant" }
157157

158158
override Class getDeclaringType() { result = this.getDeclaringEnum().getDeclaringType() }
159159

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import semmle.code.cpp.exprs.Access
2323
class Field extends MemberVariable {
2424
Field() { fieldoffsets(underlyingElement(this), _, _) }
2525

26-
override string getCanonicalQLClass() { result = "Field" }
26+
override string getAPrimaryQlClass() { result = "Field" }
2727

2828
/**
2929
* Gets the offset of this field in bytes from the start of its declaring
@@ -90,7 +90,7 @@ class Field extends MemberVariable {
9090
class BitField extends Field {
9191
BitField() { bitfield(underlyingElement(this), _, _) }
9292

93-
override string getCanonicalQLClass() { result = "BitField" }
93+
override string getAPrimaryQlClass() { result = "BitField" }
9494

9595
/**
9696
* Gets the size of this bitfield in bits (on the machine where facts

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Folder extends Container, @folder {
178178
result.hasLocationInfo(_, 0, 0, 0, 0)
179179
}
180180

181-
override string getCanonicalQLClass() { result = "Folder" }
181+
override string getAPrimaryQlClass() { result = "Folder" }
182182

183183
/**
184184
* DEPRECATED: Use `getLocation` instead.
@@ -246,7 +246,7 @@ class File extends Container, @file {
246246

247247
override string toString() { result = Container.super.toString() }
248248

249-
override string getCanonicalQLClass() { result = "File" }
249+
override string getAPrimaryQlClass() { result = "File" }
250250

251251
override Location getLocation() {
252252
result.getContainer() = this and
@@ -382,7 +382,7 @@ class HeaderFile extends File {
382382
exists(Include i | i.getIncludedFile() = this)
383383
}
384384

385-
override string getCanonicalQLClass() { result = "HeaderFile" }
385+
override string getAPrimaryQlClass() { result = "HeaderFile" }
386386

387387
/**
388388
* Holds if this header file does not contain any declaration entries or top level
@@ -408,7 +408,7 @@ class HeaderFile extends File {
408408
class CFile extends File {
409409
CFile() { exists(string ext | ext = this.getExtension().toLowerCase() | ext = "c" or ext = "i") }
410410

411-
override string getCanonicalQLClass() { result = "CFile" }
411+
override string getAPrimaryQlClass() { result = "CFile" }
412412
}
413413

414414
/**
@@ -436,7 +436,7 @@ class CppFile extends File {
436436
)
437437
}
438438

439-
override string getCanonicalQLClass() { result = "CppFile" }
439+
override string getAPrimaryQlClass() { result = "CppFile" }
440440
}
441441

442442
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class FriendDecl extends Declaration, @frienddecl {
2727
*/
2828
override Location getADeclarationLocation() { result = this.getLocation() }
2929

30-
override string getCanonicalQLClass() { result = "FriendDecl" }
30+
override string getAPrimaryQlClass() { result = "FriendDecl" }
3131

3232
/**
3333
* Implements the abstract method `Declaration.getDefinitionLocation`. A

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ class FunctionDeclarationEntry extends DeclarationEntry, @fun_decl {
513513
/** Gets the function which is being declared or defined. */
514514
override Function getDeclaration() { result = getFunction() }
515515

516-
override string getCanonicalQLClass() { result = "FunctionDeclarationEntry" }
516+
override string getAPrimaryQlClass() { result = "FunctionDeclarationEntry" }
517517

518518
/** Gets the function which is being declared or defined. */
519519
Function getFunction() { fun_decls(underlyingElement(this), unresolveElement(result), _, _, _) }
@@ -698,7 +698,7 @@ class FunctionDeclarationEntry extends DeclarationEntry, @fun_decl {
698698
class TopLevelFunction extends Function {
699699
TopLevelFunction() { not this.isMember() }
700700

701-
override string getCanonicalQLClass() { result = "TopLevelFunction" }
701+
override string getAPrimaryQlClass() { result = "TopLevelFunction" }
702702
}
703703

704704
/**
@@ -707,7 +707,7 @@ class TopLevelFunction extends Function {
707707
class Operator extends Function {
708708
Operator() { functions(underlyingElement(this), _, 5) }
709709

710-
override string getCanonicalQLClass() {
710+
override string getAPrimaryQlClass() {
711711
not this instanceof MemberFunction and result = "Operator"
712712
}
713713
}
@@ -738,7 +738,7 @@ class TemplateFunction extends Function {
738738
is_function_template(underlyingElement(this)) and exists(getATemplateArgument())
739739
}
740740

741-
override string getCanonicalQLClass() { result = "TemplateFunction" }
741+
override string getAPrimaryQlClass() { result = "TemplateFunction" }
742742

743743
/**
744744
* Gets a compiler-generated instantiation of this function template.
@@ -778,7 +778,7 @@ class FunctionTemplateInstantiation extends Function {
778778

779779
FunctionTemplateInstantiation() { tf.getAnInstantiation() = this }
780780

781-
override string getCanonicalQLClass() { result = "FunctionTemplateInstantiation" }
781+
override string getAPrimaryQlClass() { result = "FunctionTemplateInstantiation" }
782782

783783
/**
784784
* Gets the function template from which this instantiation was instantiated.
@@ -823,7 +823,7 @@ class FunctionTemplateInstantiation extends Function {
823823
class FunctionTemplateSpecialization extends Function {
824824
FunctionTemplateSpecialization() { this.isSpecialization() }
825825

826-
override string getCanonicalQLClass() { result = "FunctionTemplateSpecialization" }
826+
override string getAPrimaryQlClass() { result = "FunctionTemplateSpecialization" }
827827

828828
/**
829829
* Gets the primary template for the specialization (the function template

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

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

25-
override string getCanonicalQLClass() { result = "Initializer" }
25+
override string getAPrimaryQlClass() { result = "Initializer" }
2626

2727
/** Holds if this initializer is explicit in the source. */
2828
override predicate fromSource() { not this.getLocation() instanceof UnknownLocation }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Macro extends PreprocessorDirective, @ppd_define {
1313
*/
1414
override string getHead() { preproctext(underlyingElement(this), result, _) }
1515

16-
override string getCanonicalQLClass() { result = "Macro" }
16+
override string getAPrimaryQlClass() { result = "Macro" }
1717

1818
/**
1919
* Gets the body of this macro. For example, `(((x)>(y))?(x):(y))` in
@@ -74,7 +74,7 @@ class MacroAccess extends Locatable, @macroinvocation {
7474
*/
7575
override Location getLocation() { result = this.getOutermostMacroAccess().getActualLocation() }
7676

77-
override string getCanonicalQLClass() { result = "MacroAccess" }
77+
override string getAPrimaryQlClass() { result = "MacroAccess" }
7878

7979
/**
8080
* Gets the location of this macro access. For a nested access, where
@@ -147,7 +147,7 @@ class MacroAccess extends Locatable, @macroinvocation {
147147
class MacroInvocation extends MacroAccess {
148148
MacroInvocation() { macroinvocations(underlyingElement(this), _, _, 1) }
149149

150-
override string getCanonicalQLClass() { result = "MacroInvocation" }
150+
override string getAPrimaryQlClass() { result = "MacroInvocation" }
151151

152152
/**
153153
* Gets an element that occurs in this macro invocation or a nested macro

0 commit comments

Comments
 (0)