Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

CodeQL library for C and C++

When analyzing C or C++ code, you can use the large collection of classes in the CodeQL library for C and C++.

About the CodeQL library for C and C++

There is an extensive library for analyzing CodeQL databases extracted from C/C++ projects. The classes in this library present the data from a database in an object-oriented form and provide abstractions and predicates to help you with common analysis tasks.The library is implemented as a set of QL modules, that is, files with the extension.qll. The modulecpp.qll imports all the core C/C++ library modules, so you can include the complete library by beginning your query with:

importcpp

The rest of this topic summarizes the available CodeQL classes and corresponding C/C++ constructs.

Commonly-used library classes

The most commonly used standard library classes are listed below. The listing is broken down by functionality. Each library class is annotated with a C/C++ construct it corresponds to.

Declaration classes

This table listsDeclaration classes representing C/C++ declarations.

Example syntax

CodeQL class

Remarks

intvar;

GlobalVariable

namespaceN{floatvar;}

NamespaceVariable

intfunc(void){floatvar;}

LocalVariable

See alsoInitializer

classC{intvar;}

MemberVariable

intfunc(constcharparam);

Function

template<typenameT>
voidfunc(Tparam);

TemplateFunction

intfunc(constchar*format,...)
{}

FormattingFunction

func<int,float>();

FunctionTemplateInstantiation

template<typenameT>
func<int,T>(){}

FunctionTemplateSpecialization

classC{
intfunc(floatparam);};

MemberFunction

classC{
intfunc(floatparam)const;};

ConstMemberFunction

classC{virtualintfunc(){}};

VirtualFunction

classC{C(){}};

Constructor

C::operatorfloat()const;

ConversionOperator

classC{~C(void){}};

Destructor

classC{
C(constD&d){}};

ConversionConstructor

C&C::operator=(constC&);

CopyAssignmentOperator

C&C::operator=(C&&);

MoveAssignmentOperator

C::C(constC&);

CopyConstructor

C::C(C&&);

MoveConstructor

C::C(void);

NoArgConstructor

Default constructor

enumen{val1,val2}

EnumConstant

friendvoidfunc(int);
friendclassB;

FriendDecl

intfunc(void){
enumen{val1,val2};}

LocalEnum

classC{
enumen{val1,val2}}

NestedEnum

enumclassen:short{val1,val2}

ScopedEnum

classC{
virtualvoidfunc(int)=0;};

AbstractClass

template<int,float>classC{};

ClassTemplateInstantiation

template<>classC<Type>{};

FullClassTemplateSpecialization

template<typenameT>
classC<T,5>{};

PartialClassTemplateSpecialization

intfunc(void){classC{};}

LocalClass

classC{classD{};};

NestedClass

classC{
Typevar;
Typefunc(Parameter){}};

Class

structS{
Typevar;
Typefunc(Parameter){}};
unionU{
Typevar1;
Typevar2;};
template<typenameT>
structC:T{};

ProxyClass

Appears only inuninstantiatedtemplates

intfunc(void){
structS{};}

LocalStruct

classC{
structS{};};

NestedStruct

int*func(void){unionU{};}

LocalUnion

classC{unionU{};};

NestedUnion

typedefintT;

TypedefType

intfunc(void){
typedefintT;}

LocalTypedefType

classC{
typedefintT;};

NestedTypedefType

classV:publicB{};

ClassDerivation

classV:virtualB{};

VirtualClassDerivation

template<typenameT>
classC{};

TemplateClass

intfoo(Typeparam1,Typeparam2);

Parameter

template<typenameT>Tt;

TemplateVariable

Since C++14

Statement classes

This table lists subclasses ofStmt representing C/C++ statements.

Example syntax

CodeQL class

Remarks

__asm__("movb %bh, (%eax)");

AsmStmt

Specific to a given CPU instruction set

{Stmt}

BlockStmt

catch(Parameter)BlockStmt

CatchBlock

catch(...)BlockStmt

CatchAnyBlock

goto*labelptr;

ComputedGotoStmt

GNU extension; use withLabelLiteral

Typei,j;

DeclStmt

if(Expr)StmtelseStmt

IfStmt

switch(Expr){SwitchCase}

SwitchStmt

doStmtwhile(Expr)

DoStmt

for(DeclStmt;Expr;Expr)Stmt

ForStmt

for(DeclStmt:Expr)Stmt

RangeBasedForStmt

while(Expr)Stmt

WhileStmt

Expr;

ExprStmt

__try{}__except(Expr){}

MicrosoftTryExceptStmt

Structured exception handling (SEH) under Windows

__try{}__finally{}

MicrosoftTryFinallyStmt

Structured exception handling (SEH) under Windows

returnExpr;

ReturnStmt

caseExpr:

SwitchCase

try{Stmt}CatchBlockCatchAnyBlock

TryStmt

voidfunc(void)try{Stmt}

FunctionTryStmt

;

EmptyStmt

break;

BreakStmt

continue;

ContinueStmt

gotoLabelStmt;

GotoStmt

slabel:

LabelStmt

floatarr[Expr][Expr];

VlaDeclStmt

C99 variable-length array

Expression classes

This table lists subclasses ofExpr representing C/C++ expressions.

Example syntax

CodeQL class(es)

Remarks

{Expr}

alignof(Expr)

AlignofExprOperator

alignof(Type)

AlignofTypeOperator

Expr[Expr]

ArrayExpr

__assume(Expr)

AssumeExpr

Microsoft extension

static_assert(Expr,StringLiteral)_Static_assert(Expr,StringLiteral)

StaticAssert

C++11
C11

__noop;

BuiltInNoOp

Microsoft extension

Expr(Expr)

ExprCall

func(Expr)
instance.func(Expr)

FunctionCall

Expr,Expr

CommaExpr

if(Typearg=Expr)

ConditionDeclExpr

(Type)Expr

CStyleCast

const_cast<Type>(Expr)

ConstCast

dynamic_cast<Type>(Expr)

DynamicCast

reinterpret_cast<Type>(Expr)

ReinterpretCast

static_cast<Type>(Expr)

StaticCast

template<typename...T>
autosum(Tt)
{return(t+...+0);}

FoldExpr

Appears only inuninstantiatedtemplates

intfunc(format,...);

FormattingFunctionCall

[=](floatb)->float
{returncaptured*b;}

LambdaExpression

C++11

^int(intx,inty){
{Stmt;returnx+y;}

BlockExpr

Apple extension

void*labelptr=&&label;

LabelLiteral

GNU extension; use withComputedGotoStmt

“%3d %s\n”

FormatLiteral

0xdbceffca

HexLiteral

0167

OctalLiteral

‘c’

CharLiteral

“abcdefgh”,L”wide”

StringLiteral

newType[Expr]

NewArrayExpr

newType

NewExpr

delete[]Expr;

DeleteArrayExpr

deleteExpr;

DeleteExpr

noexcept(Expr)

NoExceptExpr

Expr=Expr

AssignExpr

See alsoInitializer

Expr+=Expr

Expr/=Expr

AssignDivExpr

Expr*=Expr

AssignMulExpr

Expr%=Expr

AssignRemExpr

Expr-=Expr

Expr&=Expr

AssignAndExpr

Expr<<=Expr

AssignLShiftExpr

Expr ``

=``Expr

AssignOrExpr

Expr>>=Expr

AssignRShiftExpr

Expr^=Expr

AssignXorExpr

Expr+Expr



C99
C99

Expr/Expr


C99

Expr>?Expr

MaxExpr

GNU extension

Expr<?Expr

MinExpr

GNU extension

Expr*Expr


C99

Expr%Expr

RemExpr

Expr-Expr




C99
C99

Expr&Expr

BitwiseAndExpr

Expr|Expr

BitwiseOrExpr

Expr^Expr

BitwiseXorExpr

Expr<<Expr

LShiftExpr

Expr>>Expr

RShiftExpr

Expr&&Expr

LogicalAndExpr

Expr||Expr

LogicalOrExpr

Expr==Expr

EQExpr

Expr!=Expr

NEExpr

Expr>=Expr

GEExpr

Expr>Expr

GTExpr

Expr<=Expr

LEExpr

Expr<Expr

LTExpr

Expr?Expr:Expr

ConditionalExpr

&Expr

AddressOfExpr

*Expr

PointerDereferenceExpr

Expr--

PostfixDecrExpr

--Expr

PrefixDecrExpr

Expr++

PostfixIncrExpr

++Expr

PrefixIncrExpr

__imag(Expr)

ImaginaryPartExpr

GNU extension

__real(Expr)

RealPartExpr

GNU extension

-Expr

UnaryMinusExpr

+Expr

UnaryPlusExpr

~Expr


GNU extension

!Expr

NotExpr

intvect__attribute__
((vector_size(16)))
={3,8,32,33};

VectorFillOperation

GNU extension

sizeof(Expr)

SizeofExprOperator

sizeof(Type)

SizeofTypeOperator

template<typename...T>
intcount(T&&...t)
{returnsizeof...(t);}

SizeofPackOperator

({Stmt;Expr})

StmtExpr

GNU/Clang extension

this

ThisExpr

throw(Expr);

ThrowExpr

throw;

ReThrowExpr

typeid(Expr)
typeid(Type)

TypeidOperator

__uuidof(Expr)

UuidofOperator

Microsoft extension

Type classes

This table lists subclasses ofType representing C/C++ types.

Example syntax

CodeQL class

Remarks

void

VoidType

_Bool orbool

BoolType

char16_t

Char16Type

C11, C++11

char32_t

Char32Type

C11, C++11

char

PlainCharType

signedchar

SignedCharType

unsignedchar

UnsignedCharType

int

IntType

longlong

LongLongType

long

LongType

short

ShortType

wchar_t

WideCharType

nullptr_t

NullPointerType

double

DoubleType

longdouble

LongDoubleType

float

FloatType

auto

AutoType

decltype(Expr)

Decltype

Type[n]

ArrayType

Type(^blockptr)(Parameter)

BlockType

Apple extension

Type(*funcptr)(Parameter)

FunctionPointerType

Type(&funcref)(Parameter)

FunctionReferenceType

Type__attribute__((vector_size(n)))

GNUVectorType

Type*

PointerType

Type&

LValueReferenceType

Type&&

RValueReferenceType

Type(Class*::membptr)(Parameter)

PointerToMemberType

template<template<typename>classC>

TemplateTemplateParameter

template<typenameT>

TemplateParameter

Preprocessor classes

This table listsPreprocessor classes representing C/C++ preprocessing directives.

Example syntax

CodeQL class

Remarks

#elifcondition

PreprocessorElif

#ifcondition

PreprocessorIf

#ifdefmacro

PreprocessorIfdef

#ifndefmacro

PreprocessorIfndef

#else

PreprocessorElse

#endif

PreprocessorEndif

#lineline_numberfile_name

PreprocessorLine

#pragmapragma_property

PreprocessorPragma

#undefmacro

PreprocessorUndef

#warningmessage

PreprocessorWarning

#errormessage

PreprocessorError

#includefile_name

Include

#importfile_name

Import

Apple/NeXT extension

#include_nextfile_name

IncludeNext

Apple/NeXT extension

#definemacro

Macro

Further reading


[8]ページ先頭

©2009-2025 Movatter.jp