C 和 C++ 的 CodeQL 库¶
分析 C 或 C++ 代码时,可以使用 C 和 C++ 的 CodeQL 库中的大量类集合。
关于 C 和 C++ 的 CodeQL 库¶
有一个广泛的库用于分析从 C/C++ 项目中提取的 CodeQL 数据库。该库中的类以面向对象的格式呈现来自数据库的数据,并提供抽象和谓词来帮助您完成常见的分析任务。该库实现为一组 QL 模块,即扩展名为 .qll
的文件。模块 cpp.qll
导入所有核心 C/C++ 库模块,因此您可以通过以下方式包含整个库:以以下方式开始您的查询
import cpp
本主题的其余部分总结了可用的 CodeQL 类和相应的 C/C++ 结构。
常用库类¶
下面列出了最常用的标准库类。该列表按功能分类。每个库类都标注了它对应的 C/C++ 结构。
声明类¶
此表列出了 Declaration 类,代表 C/C++ 声明。
示例语法 | CodeQL 类 | 备注 |
---|---|---|
int var ; |
GlobalVariable | |
namespace N { … float var ; … } |
NamespaceVariable | |
int func ( void ) { … float var ; … } |
LocalVariable | 另请参见 Initializer |
class C { … int var ; … } |
MemberVariable | |
int func ( const char param ); |
Function | |
template < typename T > void func ( T param); |
TemplateFunction | |
int func ( const char* format , ...) { … } |
FormattingFunction | |
func < int, float > ( … ); |
FunctionTemplateInstantiation | |
template < typename T > func
< int, T > ( … ) { … } |
FunctionTemplateSpecialization | |
class C { …int func ( float param ); … }; |
MemberFunction | |
class C { …int func ( float param ) const; … }; |
ConstMemberFunction | |
class C { … virtual int func ( … ) { … } }; |
VirtualFunction | |
class C { … C ( … ) { … } … }; |
Constructor | |
C::operator float () const; |
ConversionOperator | |
class C { … ~ C ( void ) { … } … }; |
Destructor | |
class C { …C
( const D & d ) { … } … }; |
ConversionConstructor | |
C & C :: operator= (const C & ); |
CopyAssignmentOperator | |
C & C :: operator= ( C && ); |
MoveAssignmentOperator | |
C :: C (const C & ); |
CopyConstructor | |
C :: C ( C && ); |
MoveConstructor | |
C :: C (void); |
NoArgConstructor | 默认构造函数 |
enum en { val1 , val2 … } |
EnumConstant | |
friend void func ( int ); friend class B ; |
FriendDecl | |
int func ( void ) { …enum en { val1 , val2 … }; … } |
LocalEnum | |
class C { …enum en { val1 , val2 … } … } |
NestedEnum | |
enum class en : short { val1 , val2 … } |
ScopedEnum | |
class C { …virtual void func ( int ) = 0; … }; |
AbstractClass | |
template < int , float > class C { … }; |
ClassTemplateInstantiation | |
template < > class C < Type > { … }; |
完全类模板特化 | |
template < typename T > class C < T , 5 > { … }; |
偏特化类模板 | |
int func ( void ) { … class C { … }; … } |
局部类 | |
class C { … class D { … }; … }; |
嵌套类 | |
类 | ||
template < typename T > struct C : T { … }; |
代理类 | 仅在*未实例化*的模板中出现 |
int func ( void ) { …struct S { … }; … } |
局部结构体 | |
class C { …struct S { … }; … }; |
嵌套结构体 | |
int * func ( void ) { … union U { … }; … } |
局部联合体 | |
class C { … union U { … }; … }; |
嵌套联合体 | |
typedef int T ; |
typedef 类型 | |
int func ( void ) { …typedef int T ; … } |
局部 typedef 类型 | |
class C { …typedef int T ; … }; |
嵌套 typedef 类型 | |
class V : … public B … { … }; |
类派生 | |
class V : … virtual B … { … }; |
虚类派生 | |
template < typename T > class C { … }; |
模板类 | |
int foo ( Type param1 , Type param2 … ); |
参数 | |
template <typename T > T t ; |
模板变量 | 自 C++14 起 |
语句类¶
该表列出了表示 C/C++ 语句的 Stmt 子类。
示例语法 | CodeQL 类 | 备注 |
---|---|---|
__asm__ (" movb %bh, (%eax) "); |
AsmStmt | 特定于给定 CPU 指令集 |
{ Stmt… } |
BlockStmt | |
catch ( Parameter ) BlockStmt |
CatchBlock | |
catch ( ... ) BlockStmt |
CatchAnyBlock | |
goto * labelptr ; |
ComputedGotoStmt | GNU 扩展;与 LabelLiteral 结合使用 |
Type i , j ; |
DeclStmt | |
if ( Expr ) Stmt else Stmt |
IfStmt | |
switch ( Expr ) { SwitchCase… } |
SwitchStmt | |
do Stmt while ( Expr ) |
DoStmt | |
for ( DeclStmt ; Expr ; Expr ) Stmt |
ForStmt | |
for ( DeclStmt : Expr ) Stmt |
RangeBasedForStmt | |
while ( Expr ) Stmt |
WhileStmt | |
Expr ; |
ExprStmt | |
__try { … } __except ( Expr ) { … } |
MicrosoftTryExceptStmt | Windows 下的结构化异常处理 (SEH) |
__try { … } __finally { … } |
MicrosoftTryFinallyStmt | Windows 下的结构化异常处理 (SEH) |
return Expr ; |
ReturnStmt | |
case Expr : |
SwitchCase | |
try { Stmt… } CatchBlock… CatchAnyBlock |
TryStmt | |
FunctionTryStmt | ||
; |
EmptyStmt | |
break; |
BreakStmt | |
continue; |
ContinueStmt | |
goto LabelStmt ; |
GotoStmt | |
slabel : |
LabelStmt | |
float arr [ Expr ] [ Expr ]; |
VlaDeclStmt | C99 可变长数组 |
表达式类¶
此表列出了表示 C/C++ 表达式的 Expr 的子类。
类型类¶
此表列出了表示 C/C++ 类型的 Type 的子类。
示例语法 | CodeQL 类 | 备注 |
---|---|---|
void |
VoidType | |
_Bool 或 bool |
BoolType | |
char16_t |
Char16Type | C11, C++11 |
char32_t |
Char32Type | C11, C++11 |
char |
PlainCharType | |
signed char |
SignedCharType | |
unsigned char |
UnsignedCharType | |
int |
IntType | |
long long |
LongLongType | |
long |
LongType | |
short |
ShortType | |
wchar_t |
WideCharType | |
nullptr_t |
NullPointerType | |
double |
DoubleType | |
long double |
LongDoubleType | |
float |
FloatType | |
auto |
AutoType | |
decltype ( Expr ) |
Decltype | |
Type [ n ] |
ArrayType | |
Type ( ^ blockptr ) ( Parameter… ) |
BlockType | Apple 扩展 |
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 > class C > |
TemplateTemplateParameter | |
template < typename T > |
TemplateParameter |
预处理器类¶
此表列出了表示 C/C++ 预处理指令的 Preprocessor 类。
示例语法 | CodeQL 类 | 备注 |
---|---|---|
#elif condition |
PreprocessorElif | |
#if condition |
PreprocessorIf | |
#ifdef macro |
PreprocessorIfdef | |
#ifndef macro |
PreprocessorIfndef | |
#else |
PreprocessorElse | |
#endif |
PreprocessorEndif | |
#line line_number file_name |
PreprocessorLine | |
#pragma pragma_property |
PreprocessorPragma | |
#undef macro |
PreprocessorUndef | |
#warning message |
PreprocessorWarning | |
#error message |
PreprocessorError | |
#include file_name |
Include | |
#import file_name |
Import | Apple/NeXT 扩展 |
#include_next file_name |
IncludeNext | Apple/NeXT 扩展 |
#define macro … |
Macro |