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

Skip to content

Commit ab82aeb

Browse files
committed
[CPP-386] Add override keyword as needed; annotate a few more classes.
1 parent e5fc076 commit ab82aeb

30 files changed

Lines changed: 242 additions & 203 deletions

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Class extends UserType {
1616
}
1717

1818
/** Canonical QL class corresponding to this element. */
19-
string getCanonicalQLClass() { result = "Class" }
19+
override string getCanonicalQLClass() { result = "Class" }
2020

2121
/** Gets a child declaration of this class. */
2222
override Declaration getADeclaration() { result = this.getAMember() }
@@ -824,6 +824,8 @@ class LocalClass extends Class {
824824
LocalClass() {
825825
isLocal()
826826
}
827+
/** Canonical QL class corresponding to this element. */
828+
override string getCanonicalQLClass() { result = "LocalClass" }
827829

828830
override Function getEnclosingAccessHolder() {
829831
result = this.getEnclosingFunction()
@@ -838,6 +840,9 @@ class NestedClass extends Class {
838840
this.isMember()
839841
}
840842

843+
/** Canonical QL class corresponding to this element. */
844+
override string getCanonicalQLClass() { result = "NestedClass" }
845+
841846
/** Holds if this member is private. */
842847
predicate isPrivate() { this.hasSpecifier("private") }
843848

@@ -984,7 +989,7 @@ class VirtualBaseClass extends Class {
984989
}
985990

986991
/** Canonical QL class corresponding to this element. */
987-
string getCanonicalQLClass() { result = "VirtualBaseClass" }
992+
override string getCanonicalQLClass() { result = "VirtualBaseClass" }
988993

989994
/** A virtual class derivation of which this class is the base. */
990995
VirtualClassDerivation getAVirtualDerivation() {
@@ -1011,7 +1016,7 @@ class ProxyClass extends UserType {
10111016
}
10121017

10131018
/** Canonical QL class corresponding to this element. */
1014-
string getCanonicalQLClass() { result = "ProxyClass" }
1019+
override string getCanonicalQLClass() { result = "ProxyClass" }
10151020

10161021
/** Gets the location of the proxy class. */
10171022
override Location getLocation() {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ class ElementBase extends @element {
5353
/** Gets a textual representation of this element. */
5454
string toString() { none() }
5555

56-
/** Canonical QL class corresponding to this element. */
56+
/**
57+
* Canonical QL class corresponding to this element.
58+
*
59+
* ElementBase is the root class for this predicate.
60+
*/
5761
string getCanonicalQLClass() { result = "???" }
5862
}
5963

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Enum extends UserType, IntegralOrEnumType {
1010
EnumConstant getEnumConstant(int index) { enumconstants(unresolveElement(result),underlyingElement(this),index,_,_,_) }
1111

1212
/** Canonical QL class corresponding to this element. */
13-
string getCanonicalQLClass() { result = "Enum" }
13+
override string getCanonicalQLClass() { result = "Enum" }
1414

1515
/**
1616
* Gets a descriptive string for the enum. This method is only intended to
@@ -54,7 +54,7 @@ class LocalEnum extends Enum {
5454
isLocal()
5555
}
5656
/** Canonical QL class corresponding to this element. */
57-
string getCanonicalQLClass() { result = "LocalEnum" }
57+
override string getCanonicalQLClass() { result = "LocalEnum" }
5858
}
5959

6060
/**
@@ -67,7 +67,7 @@ class NestedEnum extends Enum {
6767
}
6868

6969
/** Canonical QL class corresponding to this element. */
70-
string getCanonicalQLClass() { result = "NestedEnum" }
70+
override string getCanonicalQLClass() { result = "NestedEnum" }
7171

7272
/** Holds if this member is private. */
7373
predicate isPrivate() { this.hasSpecifier("private") }
@@ -90,7 +90,7 @@ class ScopedEnum extends Enum {
9090
usertypes(underlyingElement(this),_,13)
9191
}
9292
/** Canonical QL class corresponding to this element. */
93-
string getCanonicalQLClass() { result = "ScopedEnum" }
93+
override string getCanonicalQLClass() { result = "ScopedEnum" }
9494
}
9595

9696
/**
@@ -107,7 +107,7 @@ class EnumConstant extends Declaration, @enumconstant {
107107
Enum getDeclaringEnum() { enumconstants(underlyingElement(this),unresolveElement(result),_,_,_,_) }
108108

109109
/** Canonical QL class corresponding to this element. */
110-
string getCanonicalQLClass() { result = "EnumConstant" }
110+
override string getCanonicalQLClass() { result = "EnumConstant" }
111111

112112
override Class getDeclaringType() {
113113
result = this.getDeclaringEnum().getDeclaringType()

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ class TopLevelFunction extends Function {
708708
not this.isMember()
709709
}
710710
/** Canonical QL class corresponding to this element. */
711-
string getCanonicalQLClass() { result = "TopLevelFunction" }
711+
override string getCanonicalQLClass() { result = "TopLevelFunction" }
712712
}
713713

714714
/**
@@ -721,7 +721,7 @@ class MemberFunction extends Function {
721721
}
722722

723723
/** Canonical QL class corresponding to this element. */
724-
string getCanonicalQLClass() { result = "MemberFunction" }
724+
override string getCanonicalQLClass() { result = "MemberFunction" }
725725

726726
/**
727727
* Gets the number of parameters of this function, including any implicit
@@ -775,7 +775,7 @@ class VirtualFunction extends MemberFunction {
775775
}
776776

777777
/** Canonical QL class corresponding to this element. */
778-
string getCanonicalQLClass() { result = "VirtualFunction" }
778+
override string getCanonicalQLClass() { result = "VirtualFunction" }
779779

780780
/** Holds if this virtual function is pure. */
781781
predicate isPure() { this instanceof PureVirtualFunction }
@@ -795,7 +795,7 @@ class PureVirtualFunction extends VirtualFunction {
795795
PureVirtualFunction() { purefunctions(underlyingElement(this)) }
796796

797797
/** Canonical QL class corresponding to this element. */
798-
string getCanonicalQLClass() { result = "PureVirtualFunction" }
798+
override string getCanonicalQLClass() { result = "PureVirtualFunction" }
799799
}
800800

801801
/**
@@ -808,7 +808,7 @@ class ConstMemberFunction extends MemberFunction {
808808
ConstMemberFunction() { this.hasSpecifier("const") }
809809

810810
/** Canonical QL class corresponding to this element. */
811-
string getCanonicalQLClass() { result = "ConstMemberFunction" }
811+
override string getCanonicalQLClass() { result = "ConstMemberFunction" }
812812
}
813813

814814
/**
@@ -819,7 +819,7 @@ class Constructor extends MemberFunction {
819819
Constructor() { functions(underlyingElement(this),_,2) }
820820

821821
/** Canonical QL class corresponding to this element. */
822-
string getCanonicalQLClass() { result = "Constructor" }
822+
override string getCanonicalQLClass() { result = "Constructor" }
823823

824824
/**
825825
* Holds if this constructor serves as a default constructor.
@@ -867,7 +867,7 @@ class ConversionConstructor extends Constructor, ImplicitConversionFunction {
867867
}
868868

869869
/** Canonical QL class corresponding to this element. */
870-
string getCanonicalQLClass() { result = "ConversionConstructor" }
870+
override string getCanonicalQLClass() { result = "ConversionConstructor" }
871871

872872
/** Gets the type this `ConversionConstructor` takes as input. */
873873
override Type getSourceType() { result = this.getParameter(0).getType() }
@@ -925,7 +925,7 @@ class CopyConstructor extends Constructor {
925925
}
926926

927927
/** Canonical QL class corresponding to this element. */
928-
string getCanonicalQLClass() { result = "CopyConstructor" }
928+
override string getCanonicalQLClass() { result = "CopyConstructor" }
929929

930930
/**
931931
* Holds if we cannot determine that this constructor will become a copy
@@ -976,7 +976,7 @@ class MoveConstructor extends Constructor {
976976
}
977977

978978
/** Canonical QL class corresponding to this element. */
979-
string getCanonicalQLClass() { result = "MoveConstructor" }
979+
override string getCanonicalQLClass() { result = "MoveConstructor" }
980980

981981
/**
982982
* Holds if we cannot determine that this constructor will become a move
@@ -1011,7 +1011,7 @@ class Destructor extends MemberFunction {
10111011
Destructor() { functions(underlyingElement(this),_,3) }
10121012

10131013
/** Canonical QL class corresponding to this element. */
1014-
string getCanonicalQLClass() { result = "Destructor" }
1014+
override string getCanonicalQLClass() { result = "Destructor" }
10151015

10161016
/**
10171017
* Gets a compiler-generated action which destructs a base class or member
@@ -1073,7 +1073,7 @@ class CopyAssignmentOperator extends Operator {
10731073
not exists(getATemplateArgument())
10741074
}
10751075
/** Canonical QL class corresponding to this element. */
1076-
string getCanonicalQLClass() { result = "CopyAssignmentOperator" }
1076+
override string getCanonicalQLClass() { result = "CopyAssignmentOperator" }
10771077
}
10781078

10791079

@@ -1094,7 +1094,7 @@ class MoveAssignmentOperator extends Operator {
10941094
not exists(getATemplateArgument())
10951095
}
10961096
/** Canonical QL class corresponding to this element. */
1097-
string getCanonicalQLClass() { result = "MoveAssignmentOperator" }
1097+
override string getCanonicalQLClass() { result = "MoveAssignmentOperator" }
10981098
}
10991099

11001100

@@ -1116,7 +1116,7 @@ class TemplateFunction extends Function {
11161116
TemplateFunction() { is_function_template(underlyingElement(this)) and exists(getATemplateArgument()) }
11171117

11181118
/** Canonical QL class corresponding to this element. */
1119-
string getCanonicalQLClass() { result = "TemplateFunction" }
1119+
override string getCanonicalQLClass() { result = "TemplateFunction" }
11201120
/**
11211121
* Gets a compiler-generated instantiation of this function template.
11221122
*/
@@ -1149,7 +1149,7 @@ class FunctionTemplateInstantiation extends Function {
11491149
}
11501150

11511151
/** Canonical QL class corresponding to this element. */
1152-
string getCanonicalQLClass() { result = "FunctionTemplateSpecialization" }
1152+
override string getCanonicalQLClass() { result = "FunctionTemplateInstantiation" }
11531153

11541154
/**
11551155
* Gets the function template from which this instantiation was instantiated.
@@ -1188,7 +1188,7 @@ class FunctionTemplateSpecialization extends Function {
11881188
}
11891189

11901190
/** Canonical QL class corresponding to this element. */
1191-
string getCanonicalQLClass() { result = "FunctionTemplateSpecialization" }
1191+
override string getCanonicalQLClass() { result = "FunctionTemplateSpecialization" }
11921192

11931193
/**
11941194
* 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
@@ -7,7 +7,7 @@ class Initializer extends ControlFlowNode, @initialiser {
77
override Location getLocation() { initialisers(underlyingElement(this),_,_,result) }
88

99
/** Canonical QL class corresponding to this element. */
10-
string getCanonicalQLClass() { result = "Initializer" }
10+
override string getCanonicalQLClass() { result = "Initializer" }
1111

1212
/** Holds if this initializer is explicit in the source. */
1313
override predicate fromSource() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Parameter extends LocalScopeVariable, @parameter {
3434
}
3535

3636
/** Canonical QL class corresponding to this element. */
37-
string getCanonicalQLClass() { result = "Parameter" }
37+
override string getCanonicalQLClass() { result = "Parameter" }
3838

3939
/**
4040
* Gets the name of this parameter, including it's type.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ class PrintASTNode extends TPrintASTNode {
160160
}
161161

162162
/**
163-
* A concatenation of all the leaf QL types of `el`
163+
* Retrieves the caonical QL class for entity `el`
164164
*/
165165
private string qlClass(ElementBase el) { result = "["+ el.getCanonicalQLClass() + "]: " }
166+
167+
// Do not delete this - it is useful for QL class discovery
166168
//private string qlClass(ElementBase el) { result = "["+ concat(el.getAQlClass(), ",") + "]: " }
167169

168170
/**

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Struct extends Class {
99
Struct() { usertypes(underlyingElement(this),_,1) or usertypes(underlyingElement(this),_,3) }
1010

1111
/** Canonical QL class corresponding to this element. */
12-
string getCanonicalQLClass() { result = "Struct" }
12+
override string getCanonicalQLClass() { result = "Struct" }
1313

1414
override string explain() { result = "struct " + this.getName() }
1515

@@ -23,6 +23,8 @@ class LocalStruct extends Struct {
2323
LocalStruct() {
2424
isLocal()
2525
}
26+
/** Canonical QL class corresponding to this element. */
27+
override string getCanonicalQLClass() { result = "LocalStruct" }
2628
}
2729

2830
/**
@@ -33,6 +35,9 @@ class NestedStruct extends Struct {
3335
this.isMember()
3436
}
3537

38+
/** Canonical QL class corresponding to this element. */
39+
override string getCanonicalQLClass() { result = "NestedStruct" }
40+
3641
/** Holds if this member is private. */
3742
predicate isPrivate() { this.hasSpecifier("private") }
3843

0 commit comments

Comments
 (0)