[CPP-386] Provide `getCanonicalQLClass()` predicate for many AST elements.

This commit is contained in:
Ziemowit Laski 2019-07-02 17:29:47 -07:00
Родитель a4affbebbf
Коммит ddb0fd90e9
21 изменённых файлов: 304 добавлений и 7 удалений

Просмотреть файл

@ -53,7 +53,7 @@ class ElementBase extends @element {
/** Gets a textual representation of this element. */
string toString() { none() }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { none() }
string getCanonicalQLClass() { result = "ElementBase" }
}
/**
@ -64,6 +64,9 @@ class Element extends ElementBase {
/** Gets the primary file where this element occurs. */
File getFile() { result = this.getLocation().getFile() }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Element" }
/**
* Holds if this element may be from source.
*

Просмотреть файл

@ -707,6 +707,8 @@ class TopLevelFunction extends Function {
TopLevelFunction() {
not this.isMember()
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "TopLevelFunction" }
}
/**
@ -718,6 +720,9 @@ class MemberFunction extends Function {
this.isMember()
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "MemberFunction" }
/**
* Gets the number of parameters of this function, including any implicit
* `this` parameter.

Просмотреть файл

@ -6,6 +6,9 @@ import semmle.code.cpp.controlflow.ControlFlowGraph
class Initializer extends ControlFlowNode, @initialiser {
override Location getLocation() { initialisers(underlyingElement(this),_,_,result) }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Initializer" }
/** Holds if this initializer is explicit in the source. */
override predicate fromSource() {
not (this.getLocation() instanceof UnknownLocation)

Просмотреть файл

@ -33,6 +33,9 @@ class Parameter extends LocalScopeVariable, @parameter {
result = "p#" + this.getIndex().toString())
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Parameter" }
/**
* Gets the name of this parameter, including it's type.
*

Просмотреть файл

@ -159,6 +159,11 @@ class PrintASTNode extends TPrintASTNode {
}
}
/**
* A concatenation of all the leaf QL types of `el`
*/
private string qlClass(ElementBase el) { result = "["+ el.getCanonicalQLClass() + "]: " }
/**
* A node representing an AST node.
*/
@ -170,7 +175,7 @@ abstract class ASTNode extends PrintASTNode, TASTNode {
}
override string toString() {
result = ast.toString()
result = qlClass(ast) + ast.toString()
}
override final Location getLocation() {
@ -203,11 +208,11 @@ class ExprNode extends ASTNode {
result = super.getProperty(key) or
(
key = "Value" and
result = getValue()
result = qlClass(expr) + getValue()
) or
(
key = "Type" and
result = expr.getType().toString()
result = qlClass(expr.getType()) + expr.getType().toString()
) or
(
key = "ValueCategory" and
@ -294,7 +299,7 @@ class DeclarationEntryNode extends ASTNode {
result = super.getProperty(key) or
(
key = "Type" and
result = entry.getType().toString()
result = qlClass(entry.getType()) + entry.getType().toString()
)
}
}
@ -373,7 +378,7 @@ class ParameterNode extends ASTNode {
result = super.getProperty(key) or
(
key = "Type" and
result = param.getType().toString()
result = qlClass(param.getType()) + param.getType().toString()
)
}
}
@ -491,7 +496,7 @@ class FunctionNode extends ASTNode {
}
override string toString() {
result = getIdentityString(func)
result = qlClass(func) + getIdentityString(func)
}
override PrintASTNode getChild(int childIndex) {

Просмотреть файл

@ -485,6 +485,8 @@ class BoolType extends IntegralType {
BoolType() { builtintypes(underlyingElement(this),_,4,_,_,_) }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "BoolType" }
}
/**
@ -499,6 +501,8 @@ class PlainCharType extends CharType {
PlainCharType() {
builtintypes(underlyingElement(this),_,5,_,_,_)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PlainCharType" }
}
/**
@ -508,6 +512,8 @@ class UnsignedCharType extends CharType {
UnsignedCharType() {
builtintypes(underlyingElement(this),_,6,_,_,_)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "UnsignedCharType" }
}
/**
@ -517,6 +523,8 @@ class SignedCharType extends CharType {
SignedCharType() {
builtintypes(underlyingElement(this),_,7,_,_,_)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "SignedCharType" }
}
/**
@ -528,6 +536,8 @@ class ShortType extends IntegralType {
builtintypes(underlyingElement(this),_,8,_,_,_) or builtintypes(underlyingElement(this),_,9,_,_,_) or builtintypes(underlyingElement(this),_,10,_,_,_)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ShortType" }
}
/**
@ -539,6 +549,8 @@ class IntType extends IntegralType {
builtintypes(underlyingElement(this),_,11,_,_,_) or builtintypes(underlyingElement(this),_,12,_,_,_) or builtintypes(underlyingElement(this),_,13,_,_,_)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "IntType" }
}
/**
@ -550,6 +562,8 @@ class LongType extends IntegralType {
builtintypes(underlyingElement(this),_,14,_,_,_) or builtintypes(underlyingElement(this),_,15,_,_,_) or builtintypes(underlyingElement(this),_,16,_,_,_)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "LongType" }
}
/**
@ -561,6 +575,8 @@ class LongLongType extends IntegralType {
builtintypes(underlyingElement(this),_,17,_,_,_) or builtintypes(underlyingElement(this),_,18,_,_,_) or builtintypes(underlyingElement(this),_,19,_,_,_)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "LongLongType" }
}
/**
@ -592,6 +608,8 @@ class FloatType extends FloatingPointType {
FloatType() { builtintypes(underlyingElement(this),_,24,_,_,_) }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "FloatType" }
}
/**
@ -601,6 +619,8 @@ class DoubleType extends FloatingPointType {
DoubleType() { builtintypes(underlyingElement(this),_,25,_,_,_) }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "DoubleType" }
}
/**
@ -610,6 +630,8 @@ class LongDoubleType extends FloatingPointType {
LongDoubleType() { builtintypes(underlyingElement(this),_,26,_,_,_) }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "LongDoubleType" }
}
/**
@ -655,6 +677,8 @@ class VoidType extends BuiltInType {
VoidType() { builtintypes(underlyingElement(this),_,3,_,_,_) }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "VoidType" }
}
/**
@ -967,6 +991,9 @@ class ArrayType extends DerivedType {
ArrayType() { derivedtypes(underlyingElement(this),_,4,_) }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ArrayType" }
predicate hasArraySize() { arraysizes(underlyingElement(this),_,_,_) }
/**

Просмотреть файл

@ -174,6 +174,9 @@ class Variable extends Declaration, @variable {
class VariableDeclarationEntry extends DeclarationEntry, @var_decl {
override Variable getDeclaration() { result = getVariable() }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "VariableDeclarationEntry" }
/**
* Gets the variable which is being declared or defined.
*/

Просмотреть файл

@ -7,6 +7,8 @@ class CharPointerType extends PointerType {
CharPointerType() { this.getBaseType() instanceof CharType }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "CharPointerType" }
}
/**
@ -16,6 +18,8 @@ class IntPointerType extends PointerType {
IntPointerType() { this.getBaseType() instanceof IntType }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "IntPointerType" }
}
@ -26,6 +30,8 @@ class VoidPointerType extends PointerType {
VoidPointerType() { this.getBaseType() instanceof VoidType }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "VoidPointerType" }
}
/**
@ -36,6 +42,8 @@ class Size_t extends Type {
this.getUnderlyingType() instanceof IntegralType and
this.hasName("size_t")
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Size_t" }
}
/**
@ -46,6 +54,8 @@ class Ssize_t extends Type {
this.getUnderlyingType() instanceof IntegralType and
this.hasName("ssize_t")
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Ssize_t" }
}
/**
@ -56,6 +66,8 @@ class Ptrdiff_t extends Type {
this.getUnderlyingType() instanceof IntegralType and
this.hasName("ptrdiff_t")
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Ptrdiff_t" }
}
/**
@ -90,6 +102,8 @@ class Wchar_t extends Type {
this.getUnderlyingType() instanceof IntegralType and
this.hasName("wchar_t")
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Wchar_t" }
}
/**

Просмотреть файл

@ -75,6 +75,9 @@ class UserDefinedFormattingFunction extends FormattingFunction {
class FormattingFunctionCall extends Expr {
FormattingFunctionCall() { this.(Call).getTarget() instanceof FormattingFunction }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "FormattingFunctionCall" }
/**
* Gets the formatting function being called.
*/

Просмотреть файл

@ -14,6 +14,9 @@ abstract class NullValue extends Expr
class Zero extends NullValue
{
Zero() { this.(Literal).getValue() = "0" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Zero" }
}
/**

Просмотреть файл

@ -24,6 +24,9 @@ abstract class Access extends Expr, NameQualifiableElement {
* A C/C++ enum constant access expression.
*/
class EnumConstantAccess extends Access, @varaccess {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "EnumConstantAccess" }
EnumConstantAccess() {
exists(EnumConstant c | varbind(underlyingElement(this), unresolveElement(c)))
}
@ -39,6 +42,9 @@ class EnumConstantAccess extends Access, @varaccess {
* A C/C++ variable access expression.
*/
class VariableAccess extends Access, @varaccess {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "VariableAccess" }
VariableAccess() {
not exists(EnumConstant c | varbind(underlyingElement(this), unresolveElement(c)))
}
@ -133,6 +139,9 @@ class VariableAccess extends Access, @varaccess {
* A C/C++ field access expression.
*/
class FieldAccess extends VariableAccess {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "FieldAccess" }
FieldAccess() { exists(Field f | varbind(underlyingElement(this), unresolveElement(f))) }
/** Gets the accessed field. */
@ -280,6 +289,9 @@ class TypeName extends Expr, @type_operand {
* For calls to operator[], which look syntactically identical, see OverloadedArrayExpr.
*/
class ArrayExpr extends Expr, @subscriptexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ArrayExpr" }
/**
* Gets the array or pointer expression being subscripted.
*

Просмотреть файл

@ -12,6 +12,9 @@ abstract class UnaryArithmeticOperation extends UnaryOperation {
class UnaryMinusExpr extends UnaryArithmeticOperation, @arithnegexpr {
override string getOperator() { result = "-" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "UnaryMinusExpr" }
override int getPrecedence() { result = 15 }
}
@ -21,6 +24,9 @@ class UnaryMinusExpr extends UnaryArithmeticOperation, @arithnegexpr {
class UnaryPlusExpr extends UnaryArithmeticOperation, @unaryplusexpr {
override string getOperator() { result = "+" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "UnaryPlusExpr" }
override int getPrecedence() { result = 15 }
}
@ -90,6 +96,9 @@ abstract class PostfixCrementOperation extends CrementOperation {
class PrefixIncrExpr extends IncrementOperation, PrefixCrementOperation, @preincrexpr {
override string getOperator() { result = "++" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PrefixIncrExpr" }
override int getPrecedence() { result = 15 }
}
@ -101,6 +110,9 @@ class PrefixIncrExpr extends IncrementOperation, PrefixCrementOperation, @preinc
class PrefixDecrExpr extends DecrementOperation, PrefixCrementOperation, @predecrexpr {
override string getOperator() { result = "--" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PrefixDecrExpr" }
override int getPrecedence() { result = 15 }
}
@ -112,6 +124,9 @@ class PrefixDecrExpr extends DecrementOperation, PrefixCrementOperation, @predec
class PostfixIncrExpr extends IncrementOperation, PostfixCrementOperation, @postincrexpr {
override string getOperator() { result = "++" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PostfixIncrExpr" }
override int getPrecedence() { result = 16 }
override string toString() { result = "... " + getOperator() }
@ -125,6 +140,9 @@ class PostfixIncrExpr extends IncrementOperation, PostfixCrementOperation, @post
class PostfixDecrExpr extends DecrementOperation, PostfixCrementOperation, @postdecrexpr {
override string getOperator() { result = "--" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PostfixDecrExpr" }
override int getPrecedence() { result = 16 }
override string toString() { result = "... " + getOperator() }
@ -156,6 +174,9 @@ abstract class BinaryArithmeticOperation extends BinaryOperation {
class AddExpr extends BinaryArithmeticOperation, @addexpr {
override string getOperator() { result = "+" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AddExpr" }
override int getPrecedence() { result = 12 }
}
@ -165,6 +186,9 @@ class AddExpr extends BinaryArithmeticOperation, @addexpr {
class SubExpr extends BinaryArithmeticOperation, @subexpr {
override string getOperator() { result = "-" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "SubExpr" }
override int getPrecedence() { result = 12 }
}
@ -174,6 +198,9 @@ class SubExpr extends BinaryArithmeticOperation, @subexpr {
class MulExpr extends BinaryArithmeticOperation, @mulexpr {
override string getOperator() { result = "*" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "MulExpr" }
override int getPrecedence() { result = 13 }
}
@ -183,6 +210,9 @@ class MulExpr extends BinaryArithmeticOperation, @mulexpr {
class DivExpr extends BinaryArithmeticOperation, @divexpr {
override string getOperator() { result = "/" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "DivExpr" }
override int getPrecedence() { result = 13 }
}
@ -192,6 +222,9 @@ class DivExpr extends BinaryArithmeticOperation, @divexpr {
class RemExpr extends BinaryArithmeticOperation, @remexpr {
override string getOperator() { result = "%" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "RemExpr" }
override int getPrecedence() { result = 13 }
}
@ -275,6 +308,9 @@ abstract class PointerArithmeticOperation extends BinaryArithmeticOperation {
class PointerAddExpr extends PointerArithmeticOperation, @paddexpr {
override string getOperator() { result = "+" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PointerAddExpr" }
override int getPrecedence() { result = 12 }
}
@ -284,6 +320,9 @@ class PointerAddExpr extends PointerArithmeticOperation, @paddexpr {
class PointerSubExpr extends PointerArithmeticOperation, @psubexpr {
override string getOperator() { result = "-" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PointerSubExpr" }
override int getPrecedence() { result = 12 }
}
@ -293,5 +332,8 @@ class PointerSubExpr extends PointerArithmeticOperation, @psubexpr {
class PointerDiffExpr extends PointerArithmeticOperation, @pdiffexpr {
override string getOperator() { result = "-" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PointerDiffExpr" }
override int getPrecedence() { result = 12 }
}

Просмотреть файл

@ -32,6 +32,9 @@ abstract class Assignment extends Operation {
class AssignExpr extends Assignment, @assignexpr {
override string getOperator() { result = "=" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignExpr" }
/** Gets a textual representation of this assignment. */
override string toString() { result = "... = ..." }
}
@ -54,6 +57,9 @@ abstract class AssignArithmeticOperation extends AssignOperation {
* A non-overloaded `+=` assignment expression on a non-pointer lvalue.
*/
class AssignAddExpr extends AssignArithmeticOperation, @assignaddexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignAddExpr" }
override string getOperator() { result = "+=" }
}
@ -61,6 +67,9 @@ class AssignAddExpr extends AssignArithmeticOperation, @assignaddexpr {
* A non-overloaded `-=` assignment expression on a non-pointer lvalue.
*/
class AssignSubExpr extends AssignArithmeticOperation, @assignsubexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignSubExpr" }
override string getOperator() { result = "-=" }
}
@ -68,6 +77,9 @@ class AssignSubExpr extends AssignArithmeticOperation, @assignsubexpr {
* A non-overloaded `*=` assignment expression.
*/
class AssignMulExpr extends AssignArithmeticOperation, @assignmulexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignMulExpr" }
override string getOperator() { result = "*=" }
}
@ -75,6 +87,9 @@ class AssignMulExpr extends AssignArithmeticOperation, @assignmulexpr {
* A non-overloaded `/=` assignment expression.
*/
class AssignDivExpr extends AssignArithmeticOperation, @assigndivexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignDivExpr" }
override string getOperator() { result = "/=" }
}
@ -82,6 +97,9 @@ class AssignDivExpr extends AssignArithmeticOperation, @assigndivexpr {
* A non-overloaded `%=` assignment expression.
*/
class AssignRemExpr extends AssignArithmeticOperation, @assignremexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignRemExpr" }
override string getOperator() { result = "%=" }
}
@ -96,6 +114,9 @@ abstract class AssignBitwiseOperation extends AssignOperation {
* A non-overloaded `&=` assignment expression.
*/
class AssignAndExpr extends AssignBitwiseOperation, @assignandexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignAndExpr" }
override string getOperator() { result = "&=" }
}
@ -103,6 +124,9 @@ class AssignAndExpr extends AssignBitwiseOperation, @assignandexpr {
* A non-overloaded `|=` assignment expression.
*/
class AssignOrExpr extends AssignBitwiseOperation, @assignorexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignOrExpr" }
override string getOperator() { result = "|=" }
}
@ -110,6 +134,9 @@ class AssignOrExpr extends AssignBitwiseOperation, @assignorexpr {
* A non-overloaded `^=` assignment expression.
*/
class AssignXorExpr extends AssignBitwiseOperation, @assignxorexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignXorExpr" }
override string getOperator() { result = "^=" }
}
@ -117,6 +144,9 @@ class AssignXorExpr extends AssignBitwiseOperation, @assignxorexpr {
* A non-overloaded `<<=` assignment expression.
*/
class AssignLShiftExpr extends AssignBitwiseOperation, @assignlshiftexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignLShiftExpr" }
override string getOperator() { result = "<<=" }
}
@ -124,6 +154,9 @@ class AssignLShiftExpr extends AssignBitwiseOperation, @assignlshiftexpr {
* A non-overloaded `>>=` assignment expression.
*/
class AssignRShiftExpr extends AssignBitwiseOperation, @assignrshiftexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignRShiftExpr" }
override string getOperator() { result = ">>=" }
}
@ -131,6 +164,9 @@ class AssignRShiftExpr extends AssignBitwiseOperation, @assignrshiftexpr {
* A non-overloaded `+=` pointer assignment expression.
*/
class AssignPointerAddExpr extends AssignOperation, @assignpaddexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignPointerAddExpr" }
override string getOperator() { result = "+=" }
}
@ -138,6 +174,9 @@ class AssignPointerAddExpr extends AssignOperation, @assignpaddexpr {
* A non-overloaded `-=` pointer assignment expression.
*/
class AssignPointerSubExpr extends AssignOperation, @assignpsubexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AssignPointerSubExpr" }
override string getOperator() { result = "-=" }
}

Просмотреть файл

@ -149,6 +149,9 @@ class FunctionCall extends Call, @funbindexpr {
iscall(underlyingElement(this),_)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "FunctionCall" }
/** Gets an explicit template argument for this call. */
Type getAnExplicitTemplateArgument() {
result = getExplicitTemplateArgument(_)

Просмотреть файл

@ -155,6 +155,9 @@ class IntegralConversion extends ArithmeticConversion {
isIntegralOrEnum(getExpr().getUnspecifiedType())
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "IntegralConversion" }
override string getSemanticConversionString() {
result = "integral conversion"
}
@ -215,6 +218,9 @@ class PointerConversion extends Cast {
isPointerOrNullPointer(getExpr().getUnspecifiedType())
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PointerConversion" }
override string getSemanticConversionString() {
result = "pointer conversion"
}
@ -586,6 +592,9 @@ abstract class SizeofOperator extends Expr, @runtime_sizeof {
class SizeofExprOperator extends SizeofOperator {
SizeofExprOperator() { exists(Expr e | this.getChild(0) = e) }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "SizeofExprOperator" }
/** Gets the contained expression. */
Expr getExprOperand() { result = this.getChild(0) }
@ -682,6 +691,9 @@ class ArrayToPointerConversion extends Conversion, @array_to_pointer {
/** Gets a textual representation of this conversion. */
override string toString() { result = "array to pointer conversion" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ArrayToPointerConversion" }
override predicate mayBeImpure() {
none()
}

Просмотреть файл

@ -17,6 +17,9 @@ abstract class EqualityOperation extends ComparisonOperation {
* A C/C++ equal expression.
*/
class EQExpr extends EqualityOperation, @eqexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "EQExpr" }
override string getOperator() { result = "==" }
}
@ -24,6 +27,9 @@ class EQExpr extends EqualityOperation, @eqexpr {
* A C/C++ not equal expression.
*/
class NEExpr extends EqualityOperation, @neexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "NEExpr" }
override string getOperator() { result = "!=" }
}
@ -70,6 +76,9 @@ abstract class RelationalOperation extends ComparisonOperation {
* A C/C++ greater than expression.
*/
class GTExpr extends RelationalOperation, @gtexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "GTExpr" }
override string getOperator() { result = ">" }
override Expr getGreaterOperand() { result = getLeftOperand() }
@ -80,6 +89,9 @@ class GTExpr extends RelationalOperation, @gtexpr {
* A C/C++ lesser than expression.
*/
class LTExpr extends RelationalOperation, @ltexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "LTExpr" }
override string getOperator() { result = "<" }
override Expr getGreaterOperand() { result = getRightOperand() }
@ -90,6 +102,9 @@ class LTExpr extends RelationalOperation, @ltexpr {
* A C/C++ greater than or equal expression.
*/
class GEExpr extends RelationalOperation, @geexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "GEExpr" }
override string getOperator() { result = ">=" }
override Expr getGreaterOperand() { result = getLeftOperand() }
@ -100,6 +115,9 @@ class GEExpr extends RelationalOperation, @geexpr {
* A C/C++ lesser than or equal expression.
*/
class LEExpr extends RelationalOperation, @leexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "LEExpr" }
override string getOperator() { result = "<=" }
override Expr getGreaterOperand() { result = getRightOperand() }

Просмотреть файл

@ -492,6 +492,9 @@ class AssumeExpr extends Expr, @assume {
* A C/C++ comma expression.
*/
class CommaExpr extends Expr, @commaexpr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "CommaExpr" }
/**
* Gets the left operand, which is the one whose value is discarded.
*/
@ -521,6 +524,9 @@ class CommaExpr extends Expr, @commaexpr {
* A C/C++ address-of expression.
*/
class AddressOfExpr extends UnaryOperation, @address_of {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "AddressOfExpr" }
/** Gets the function or variable whose address is taken. */
Declaration getAddressable() {
result = this.getOperand().(Access).getTarget()
@ -559,6 +565,9 @@ class ReferenceToExpr extends Conversion, @reference_to {
* For user-defined types, see OverloadedPointerDereferenceExpr.
*/
class PointerDereferenceExpr extends UnaryOperation, @indirect {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "PointerDereferenceExpr" }
/**
* DEPRECATED: Use getOperand() instead.
*
@ -694,6 +703,9 @@ class NewOrNewArrayExpr extends Expr, @any_new_expr {
class NewExpr extends NewOrNewArrayExpr, @new_expr {
override string toString() { result = "new" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "NewExpr" }
/**
* Gets the type that is being allocated.
*
@ -718,6 +730,9 @@ class NewExpr extends NewOrNewArrayExpr, @new_expr {
class NewArrayExpr extends NewOrNewArrayExpr, @new_array_expr {
override string toString() { result = "new[]" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "NewArrayExpr" }
/**
* Gets the type that is being allocated.
*
@ -761,6 +776,9 @@ class NewArrayExpr extends NewOrNewArrayExpr, @new_array_expr {
class DeleteExpr extends Expr, @delete_expr {
override string toString() { result = "delete" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "DeleteExpr" }
override int getPrecedence() { result = 15 }
/**
@ -829,6 +847,9 @@ class DeleteExpr extends Expr, @delete_expr {
class DeleteArrayExpr extends Expr, @delete_array_expr {
override string toString() { result = "delete[]" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "DeleteArrayExpr" }
override int getPrecedence() { result = 15 }
/**
@ -927,6 +948,9 @@ private Expr getStmtResultExpr(Stmt stmt) {
class ThisExpr extends Expr, @thisaccess {
override string toString() { result = "this" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ThisExpr" }
override predicate mayBeImpure() {
none()
}
@ -962,6 +986,9 @@ class BlockExpr extends Literal {
class NoExceptExpr extends Expr, @noexceptexpr {
override string toString() { result = "noexcept(...)" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "NoExceptExpr" }
/**
* Gets the expression inside this noexcept expression.
*/

Просмотреть файл

@ -13,6 +13,9 @@ class Literal extends Expr, @literal {
)
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Literal" }
override predicate mayBeImpure() {
none()
}
@ -117,6 +120,9 @@ class StringLiteral extends TextLiteral
// Note that `AggregateLiteral`s can also have an array type, but they derive from
// @aggregateliteral rather than @literal.
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "StringLiteral" }
}
/**

Просмотреть файл

@ -12,6 +12,9 @@ abstract class UnaryLogicalOperation extends UnaryOperation {
class NotExpr extends UnaryLogicalOperation, @notexpr {
override string getOperator() { result = "!" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "NotExpr" }
override int getPrecedence() { result = 15 }
}
@ -38,6 +41,9 @@ abstract class BinaryLogicalOperation extends BinaryOperation {
class LogicalAndExpr extends BinaryLogicalOperation, @andlogicalexpr {
override string getOperator() { result = "&&" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "LogicalAndExpr" }
override int getPrecedence() { result = 5 }
override predicate impliesValue(Expr part, boolean partIsTrue, boolean wholeIsTrue) {
@ -53,6 +59,9 @@ class LogicalAndExpr extends BinaryLogicalOperation, @andlogicalexpr {
class LogicalOrExpr extends BinaryLogicalOperation, @orlogicalexpr {
override string getOperator() { result = "||" }
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "LogicalOrExpr" }
override int getPrecedence() { result = 4 }
override predicate impliesValue(Expr part, boolean partIsTrue, boolean wholeIsTrue) {
@ -71,6 +80,9 @@ class ConditionalExpr extends Operation, @conditionalexpr {
expr_cond_guard(underlyingElement(this), unresolveElement(result))
}
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ConditionalExpr" }
/** Gets the 'then' expression of this conditional expression. */
Expr getThen() {
if this.isTwoOperand()

Просмотреть файл

@ -11,6 +11,9 @@ import semmle.code.cpp.stmts.Stmt
*/
class Block extends Stmt, @stmt_block {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "Block" }
/**
* Gets a child declaration of this block.
*

Просмотреть файл

@ -167,6 +167,9 @@ abstract class StmtParent extends ControlFlowNode {
*/
class ExprStmt extends Stmt, @stmt_expr {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ExprStmt" }
/**
* Gets the expression of this 'expression' statement.
*
@ -219,6 +222,9 @@ abstract class ConditionalStmt extends ControlStructure {
*/
class IfStmt extends ConditionalStmt, @stmt_if {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "IfStmt" }
/**
* Gets the condition expression of this 'if' statement.
*
@ -312,6 +318,9 @@ abstract class Loop extends ControlStructure {
* ```
*/
class WhileStmt extends Loop, @stmt_while {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "WhileStmt" }
override Expr getCondition() { result = this.getChild(0) }
override Expr getControllingExpr() { result = this.getCondition() }
override Stmt getStmt() { while_body(underlyingElement(this), unresolveElement(result)) }
@ -378,6 +387,9 @@ class WhileStmt extends Loop, @stmt_while {
*/
abstract class JumpStmt extends Stmt, @jump {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "JumpStmt" }
/** Gets the target of this jump statement. */
Stmt getTarget() { jumpinfo(underlyingElement(this),_,unresolveElement(result)) }
}
@ -392,6 +404,9 @@ abstract class JumpStmt extends Stmt, @jump {
*/
class GotoStmt extends JumpStmt, @stmt_goto {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "GotoStmt" }
/**
* Gets the name of the label this 'goto' statement refers to.
*
@ -483,6 +498,9 @@ class ComputedGotoStmt extends Stmt, @stmt_assigned_goto {
*/
class ContinueStmt extends JumpStmt, @stmt_continue {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ContinueStmt" }
override string toString() { result = "continue;" }
override predicate mayBeImpure() { none() }
@ -512,6 +530,9 @@ private Stmt getEnclosingContinuable(Stmt s) {
*/
class BreakStmt extends JumpStmt, @stmt_break {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "BreakStmt" }
override string toString() { result = "break;" }
override predicate mayBeImpure() { none() }
@ -541,6 +562,9 @@ private Stmt getEnclosingBreakable(Stmt s) {
*/
class LabelStmt extends Stmt, @stmt_label {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "LabelStmt" }
/** Gets the name of this 'label' statement. */
string getName() { jumpinfo(underlyingElement(this),result,_) and result != "" }
@ -567,6 +591,9 @@ class LabelStmt extends Stmt, @stmt_label {
*/
class ReturnStmt extends Stmt, @stmt_return {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ReturnStmt" }
/**
* Gets the expression of this 'return' statement.
*
@ -617,6 +644,9 @@ class ReturnStmt extends Stmt, @stmt_return {
*/
class DoStmt extends Loop, @stmt_end_test_while {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "DoStmt" }
override Expr getCondition() { result = this.getChild(0) }
override Expr getControllingExpr() { result = this.getCondition() }
override Stmt getStmt() { do_body(underlyingElement(this), unresolveElement(result)) }
@ -661,6 +691,9 @@ class DoStmt extends Loop, @stmt_end_test_while {
* where `begin_expr` and `end_expr` depend on the type of `xs`.
*/
class RangeBasedForStmt extends Loop, @stmt_range_based_for {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "RangeBasedForStmt" }
/**
* Gets the 'body' statement of this range-based 'for' statement.
*
@ -754,6 +787,9 @@ class RangeBasedForStmt extends Loop, @stmt_range_based_for {
*/
class ForStmt extends Loop, @stmt_for {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "ForStmt" }
/**
* Gets the initialization statement of this 'for' statement.
*
@ -980,6 +1016,9 @@ private predicate inForUpdate(Expr forUpdate, Expr child) {
*/
class SwitchCase extends Stmt, @stmt_switch_case {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "SwitchCase" }
/**
* Gets the expression of this 'switch case' statement (or the start of
* the range if there is a GNU case range). Does not exist for a
@ -1340,6 +1379,9 @@ class DefaultCase extends SwitchCase {
* ```
*/
class SwitchStmt extends ConditionalStmt, @stmt_switch {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "SwitchStmt" }
/**
* Gets the expression that this 'switch' statement switches on.
*
@ -1604,6 +1646,9 @@ deprecated class FinallyEnd extends Stmt {
*/
class TryStmt extends Stmt, @stmt_try_block {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "TryStmt" }
override string toString() { result = "try { ... }" }
/**
@ -1687,6 +1732,9 @@ class FunctionTryStmt extends TryStmt {
* A 'catch block', from either C++'s `catch` or Objective C's `@catch`.
*/
class CatchBlock extends Block {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "CatchBlock" }
CatchBlock() { ishandler(underlyingElement(this)) }
/**
@ -1767,6 +1815,9 @@ class MicrosoftTryFinallyStmt extends MicrosoftTryStmt {
*/
class DeclStmt extends Stmt, @stmt_decl {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "DeclStmt" }
/**
* Gets the `i`th declaration entry declared by this 'declaration' statement.
*
@ -1846,6 +1897,9 @@ class DeclStmt extends Stmt, @stmt_decl {
*/
class EmptyStmt extends Stmt, @stmt_empty {
/** Retrieves canonical QL class(es) corresponding to this element. */
string getCanonicalQLClass() { result = "EmptyStmt" }
override string toString() { result = ";" }
override predicate mayBeImpure() { none() }