Abstract syntax tree classes for working with Go programs¶
CodeQL has a large selection of classes for representing the abstract syntax tree of Go programs.
The abstract syntax tree (AST) represents the syntactic structure of a program. Nodes on the AST represent elements such as statements and expressions.
Statement classes¶
This table lists all subclasses of Stmt.
Expression classes¶
There are many expression classes, so we present them by category. All classes in this section are subclasses of Expr.
Literals¶
Expression syntax example | CodeQL class | Superclass |
---|---|---|
23 |
IntLit | BasicLit |
4.2 |
FloatLit | BasicLit |
4.2 + 2.7i |
ImagLit | BasicLit |
'a' |
CharLit | BasicLit |
"Hello" |
StringLit | BasicLit |
func(x, y int) int { return x + y } |
FuncLit | FuncDef |
map[string]int{"A": 1, "B": 2} |
MapLit | CompositeLit |
Point3D{0.5, -0.5, 0.5} |
StructLit | CompositeLit |
Unary expressions¶
All classes in this subsection are subclasses of UnaryExpr.
Expression syntax | CodeQL class | Superclasses |
---|---|---|
+ Expr |
PlusExpr | ArithmeticUnaryExpr |
- Expr |
MinusExpr | ArithmeticUnaryExpr |
! Expr |
NotExpr | LogicalUnaryExpr |
^ Expr |
ComplementExpr | BitwiseUnaryExpr |
& Expr |
AddressExpr | |
<- Expr |
RecvExpr |
Binary expressions¶
All classes in this subsection are subclasses of BinaryExpr.
Expression syntax | CodeQL class | Superclasses |
---|---|---|
Expr * Expr |
MulExpr | ArithmeticBinaryExpr |
Expr / Expr |
QuoExpr | ArithmeticBinaryExpr |
Expr % Expr |
RemExpr | ArithmeticBinaryExpr |
Expr + Expr |
AddExpr | ArithmeticBinaryExpr |
Expr - Expr |
SubExpr | ArithmeticBinaryExpr |
Expr << Expr |
ShlExpr | ShiftExpr |
Expr >> Expr |
ShrExpr | ShiftExpr |
Expr && Expr |
LandExpr | LogicalBinaryExpr |
Expr || Expr |
LorExpr | LogicalBinaryExpr |
Expr < Expr |
LssExpr | RelationalComparisonExpr |
Expr > Expr |
GtrExpr | RelationalComparisonExpr |
Expr <= Expr |
LeqExpr | RelationalComparisonExpr |
Expr >= Expr |
GeqExpr | RelationalComparisonExpr |
Expr == Expr |
EqlExpr | EqualityTestExpr |
Expr != Expr |
NeqExpr | EqualityTestExpr |
Expr & Expr |
AndExpr | BitwiseBinaryExpr |
Expr | Expr |
OrExpr | BitwiseBinaryExpr |
Expr ^ Expr |
XorExpr | BitwiseBinaryExpr |
Expr &^ Expr |
AndNotExpr | BitwiseBinaryExpr |
Type expressions¶
These classes represent different expressions for types. They do not have a common superclass.
Expression syntax | CodeQL class | Superclasses |
---|---|---|
[ Expr] TypeExpr |
ArrayTypeExpr | |
struct { ... } |
StructTypeExpr | |
func FunctionName(...) (...) |
FuncTypeExpr | |
interface { ... } |
InterfaceTypeExpr | |
map[ TypeExpr] TypeExpr |
MapTypeExpr | |
chan<- TypeExpr |
SendChanTypeExpr | ChanTypeExpr |
<-chan TypeExpr |
RecvChanTypeExpr | ChanTypeExpr |
chan TypeExpr |
SendRecvChanTypeExpr | ChanTypeExpr |
Name expressions¶
All classes in this subsection are subclasses of Name.
The following classes relate to the structure of the name.
Expression syntax | CodeQL class | Superclasses |
---|---|---|
Ident | SimpleName | Ident |
Ident. Ident |
QualifiedName | SelectorExpr |
The following classes relate to what sort of entity the name refers to.
Miscellaneous¶
Expression syntax | CodeQL class | Superclasses | Remarks |
---|---|---|---|
foo |
Ident | ||
_ |
BlankIdent | ||
... |
Ellipsis | ||
( Expr) |
ParenExpr | ||
Ident. Ident |
SelectorExpr | ||
Expr[ Expr] |
IndexExpr | ||
Expr[ Expr: Expr: Expr] |
SliceExpr | ||
Expr.( TypeExpr) |
TypeAssertExpr | ||
* Expr |
StarExpr | can be a ValueExpr or TypeExpr depending on context | |
Expr: Expr |
KeyValueExpr | ||
TypeExpr( Expr) |
ConversionExpr | CallOrConversionExpr | |
Expr(...) |
CallExpr | CallOrConversionExpr | |
(anything unparseable) | BadExpr |
The following classes organize expressions by the kind of entity they refer to.
CodeQL class | Explanation |
---|---|
TypeExpr | an expression that denotes a type |
ReferenceExpr | an expression that refers to a variable, a constant, a function, a field, or an element of an array or a slice |
ValueExpr | an expression that can be evaluated to a value (as opposed to expressions that refer to a package, a type, or a statement label). This generalizes ReferenceExpr |