Skip to content

Commit 45d9444

Browse files
committed
[CPP-386] Fix Local{Class,Struct,Union}, macro invocations,
printing of member functions and operators.
1 parent 9267425 commit 45d9444

File tree

8 files changed

+362
-45
lines changed

8 files changed

+362
-45
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,8 @@ class LocalClass extends Class {
824824
isLocal()
825825
}
826826

827-
override string getCanonicalQLClass() { result = "LocalClass" }
827+
override string getCanonicalQLClass()
828+
{ not this instanceof LocalStruct and result = "LocalClass" }
828829

829830
override Function getEnclosingAccessHolder() {
830831
result = this.getEnclosingFunction()
@@ -861,6 +862,8 @@ class AbstractClass extends Class {
861862
AbstractClass() {
862863
exists(PureVirtualFunction f| this.getAMemberFunction() = f)
863864
}
865+
866+
override string getCanonicalQLClass() { result = "AbstractClass" }
864867
}
865868

866869
/**
@@ -873,6 +876,8 @@ class TemplateClass extends Class {
873876
result.isConstructedFrom(this) and
874877
exists(result.getATemplateArgument())
875878
}
879+
880+
override string getCanonicalQLClass() { result = "TemplateClass" }
876881
}
877882

878883
/**
@@ -885,6 +890,8 @@ class ClassTemplateInstantiation extends Class {
885890
tc.getAnInstantiation() = this
886891
}
887892

893+
override string getCanonicalQLClass() { result = "ClassTemplateInstantiation" }
894+
888895
/**
889896
* Gets the class template from which this instantiation was instantiated.
890897
*
@@ -916,6 +923,8 @@ abstract class ClassTemplateSpecialization extends Class {
916923
and count(TemplateParameter tp | tp = result.getATemplateArgument()) =
917924
count(int i | exists(result.getTemplateArgument(i)))
918925
}
926+
927+
override string getCanonicalQLClass() { result = "ClassTemplateSpecialization" }
919928
}
920929

921930
/**
@@ -933,6 +942,8 @@ class FullClassTemplateSpecialization extends ClassTemplateSpecialization {
933942
// This class is not an instantiation of a class template.
934943
and not this instanceof ClassTemplateInstantiation
935944
}
945+
946+
override string getCanonicalQLClass() { result = "FullClassTemplateSpecialization" }
936947
}
937948

938949
/**
@@ -957,6 +968,8 @@ class PartialClassTemplateSpecialization extends ClassTemplateSpecialization {
957968
and count(TemplateParameter tp | tp = getATemplateArgument()) !=
958969
count(int i | exists(getTemplateArgument(i)))
959970
}
971+
972+
override string getCanonicalQLClass() { result = "PartialClassTemplateSpecialization" }
960973
}
961974

962975
/**
@@ -967,6 +980,8 @@ class Interface extends Class {
967980
Interface() {
968981
forex(Declaration m | m.getDeclaringType() = this.getABaseClass*() and not compgenerated(unresolveElement(m)) | m instanceof PureVirtualFunction)
969982
}
983+
984+
override string getCanonicalQLClass() { result = "Interface" }
970985
}
971986

972987
/**
@@ -977,6 +992,8 @@ class VirtualClassDerivation extends ClassDerivation {
977992
VirtualClassDerivation() {
978993
hasSpecifier("virtual")
979994
}
995+
996+
override string getCanonicalQLClass() { result = "VirtualClassDerivation" }
980997
}
981998

982999
/**

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,9 @@ class MemberFunction extends Function {
723723
}
724724

725725
override string getCanonicalQLClass()
726-
{ not this instanceof Operator and result = "MemberFunction" }
726+
{ not this instanceof CopyAssignmentOperator and
727+
not this instanceof MoveAssignmentOperator and
728+
result = "MemberFunction" }
727729

728730
/**
729731
* Gets the number of parameters of this function, including any implicit
@@ -864,7 +866,8 @@ class ConversionConstructor extends Constructor, ImplicitConversionFunction {
864866
and not(this instanceof CopyConstructor)
865867
}
866868

867-
override string getCanonicalQLClass() { result = "ConversionConstructor" }
869+
override string getCanonicalQLClass()
870+
{ not this instanceof MoveConstructor and result = "ConversionConstructor" }
868871

869872
/** Gets the type this `ConversionConstructor` takes as input. */
870873
override Type getSourceType() { result = this.getParameter(0).getType() }
@@ -1046,7 +1049,8 @@ class Operator extends Function {
10461049

10471050
Operator() { functions(underlyingElement(this),_,5) }
10481051

1049-
override string getCanonicalQLClass() { result = "Operator" }
1052+
override string getCanonicalQLClass()
1053+
{ not this instanceof MemberFunction and result = "Operator" }
10501054
}
10511055

10521056
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Macro extends PreprocessorDirective, @ppd_define {
1111
*/
1212
override string getHead() { preproctext(underlyingElement(this),result,_) }
1313

14+
override string getCanonicalQLClass() { result = "Macro" }
15+
1416
/**
1517
* Gets the body of this macro. For example, `(((x)>(y))?(x):(y))` in
1618
* `#define MAX(x,y) (((x)>(y))?(x):(y))`.
@@ -275,6 +277,8 @@ deprecated class MacroInvocationExpr extends Expr {
275277
exists(MacroInvocation i | this = i.getExpr())
276278
}
277279

280+
override string getCanonicalQLClass() { result = "MacroInvocationExpr" }
281+
278282
/**
279283
* Gets the macro invocation of which this is the top-level expression.
280284
*/
@@ -301,6 +305,8 @@ deprecated class MacroInvocationStmt extends Stmt {
301305
exists(MacroInvocation i | this = i.getStmt())
302306
}
303307

308+
override string getCanonicalQLClass() { result = "MacroInvocationStmt" }
309+
304310
/**
305311
* Gets the macro invocation of which this is the top-level statement.
306312
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class LocalStruct extends Struct {
2323
isLocal()
2424
}
2525

26-
override string getCanonicalQLClass() { result = "LocalStruct" }
26+
override string getCanonicalQLClass()
27+
{ not this instanceof LocalUnion and result = "LocalStruct" }
2728
}
2829

2930
/**

cpp/ql/src/semmle/code/cpp/stmts/Stmt.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ class VlaDimensionStmt extends Stmt, @stmt_set_vla_size {
19241924
class VlaDeclStmt extends Stmt, @stmt_vla_decl {
19251925
override string toString() { result = "VLA declaration" }
19261926

1927-
override string getCanonicalQLClass() { result = "VlaDeclStmtlll;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" }
1927+
override string getCanonicalQLClass() { result = "VlaDeclStmt" }
19281928

19291929
/**
19301930
* Gets the number of VLA dimension statements in this VLA

0 commit comments

Comments
 (0)