mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.ast: document vlib/v/ast/ast.v (#7624)
This commit is contained in:
parent
3f3ae67b55
commit
ecc7c27c9c
@ -158,25 +158,27 @@ pub mut:
|
|||||||
typ table.Type
|
typ table.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const field in const declaration group
|
||||||
pub struct ConstField {
|
pub struct ConstField {
|
||||||
pub:
|
pub:
|
||||||
mod string
|
mod string
|
||||||
name string
|
name string
|
||||||
expr Expr
|
expr Expr // the value expr of field; everything after `=`
|
||||||
is_pub bool
|
is_pub bool
|
||||||
pos token.Position
|
pos token.Position
|
||||||
pub mut:
|
pub mut:
|
||||||
typ table.Type
|
typ table.Type // the type of the const field, it can be any type in V
|
||||||
comments []Comment
|
comments []Comment // comments before current const field
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const declaration
|
||||||
pub struct ConstDecl {
|
pub struct ConstDecl {
|
||||||
pub:
|
pub:
|
||||||
is_pub bool
|
is_pub bool
|
||||||
pos token.Position
|
pos token.Position
|
||||||
pub mut:
|
pub mut:
|
||||||
fields []ConstField
|
fields []ConstField // all the const fields in the `const (...)` block
|
||||||
end_comments []Comment
|
end_comments []Comment // comments that after last const field
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StructDecl {
|
pub struct StructDecl {
|
||||||
@ -258,26 +260,29 @@ pub mut:
|
|||||||
// import statement
|
// import statement
|
||||||
pub struct Import {
|
pub struct Import {
|
||||||
pub:
|
pub:
|
||||||
|
mod string // the module name of the import
|
||||||
|
alias string // the `x` in `import xxx as x`
|
||||||
pos token.Position
|
pos token.Position
|
||||||
mod string
|
|
||||||
alias string
|
|
||||||
pub mut:
|
pub mut:
|
||||||
syms []ImportSymbol
|
syms []ImportSymbol // the list of symbols in `import {symbol1, symbol2}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// import symbol,for import {symbol} syntax
|
||||||
pub struct ImportSymbol {
|
pub struct ImportSymbol {
|
||||||
pub:
|
pub:
|
||||||
pos token.Position
|
pos token.Position
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// anonymous function
|
||||||
pub struct AnonFn {
|
pub struct AnonFn {
|
||||||
pub:
|
pub:
|
||||||
decl FnDecl
|
decl FnDecl
|
||||||
pub mut:
|
pub mut:
|
||||||
typ table.Type
|
typ table.Type // the type of anonymous fn. Both .typ and .decl.name are auto generated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function or method declaration
|
||||||
pub struct FnDecl {
|
pub struct FnDecl {
|
||||||
pub:
|
pub:
|
||||||
name string
|
name string
|
||||||
@ -319,6 +324,7 @@ pub:
|
|||||||
pos token.Position
|
pos token.Position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function or method call expr
|
||||||
pub struct CallExpr {
|
pub struct CallExpr {
|
||||||
pub:
|
pub:
|
||||||
pos token.Position
|
pos token.Position
|
||||||
@ -349,6 +355,7 @@ pub struct AutofreeArgVar {
|
|||||||
idx int
|
idx int
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
// function call argument: `f(callarg)`
|
||||||
pub struct CallArg {
|
pub struct CallArg {
|
||||||
pub:
|
pub:
|
||||||
is_mut bool
|
is_mut bool
|
||||||
@ -362,6 +369,7 @@ pub mut:
|
|||||||
// tmp_name string // for autofree
|
// tmp_name string // for autofree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function return statement
|
||||||
pub struct Return {
|
pub struct Return {
|
||||||
pub:
|
pub:
|
||||||
pos token.Position
|
pos token.Position
|
||||||
@ -434,18 +442,21 @@ pub mut:
|
|||||||
end_comments []Comment
|
end_comments []Comment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Each V source file is represented by one ast.File structure.
|
||||||
|
// When the V compiler runs, the parser will fill an []ast.File.
|
||||||
|
// That array is then passed to V's checker.
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub:
|
pub:
|
||||||
path string
|
path string // path of the source file
|
||||||
mod Module
|
mod Module // the module of the source file (from `module xyz` at the top)
|
||||||
global_scope &Scope
|
global_scope &Scope
|
||||||
pub mut:
|
pub mut:
|
||||||
scope &Scope
|
scope &Scope
|
||||||
stmts []Stmt
|
stmts []Stmt // all the statements in the source file
|
||||||
imports []Import
|
imports []Import // all the imports
|
||||||
imported_symbols map[string]string // 'Type' => 'module.Type'
|
imported_symbols map[string]string // used for `import {symbol}`, it maps symbol => module.symbol
|
||||||
errors []errors.Error
|
errors []errors.Error // all the checker errors in the file
|
||||||
warnings []errors.Warning
|
warnings []errors.Warning // all the checker warings in the file
|
||||||
generic_fns []&FnDecl
|
generic_fns []&FnDecl
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,10 +734,11 @@ pub:
|
|||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
// variable assign statement
|
||||||
pub struct AssignStmt {
|
pub struct AssignStmt {
|
||||||
pub:
|
pub:
|
||||||
right []Expr
|
right []Expr
|
||||||
op token.Kind
|
op token.Kind // include: =,:=,+=,-=,*=,/= and so on; for a list of all the assign operators, see vlib/token/token.v
|
||||||
pos token.Position
|
pos token.Position
|
||||||
comments []Comment
|
comments []Comment
|
||||||
end_comments []Comment
|
end_comments []Comment
|
||||||
@ -748,6 +760,7 @@ pub mut:
|
|||||||
expr_type table.Type
|
expr_type table.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// an enum value, like OS.macos or .macos
|
||||||
pub struct EnumVal {
|
pub struct EnumVal {
|
||||||
pub:
|
pub:
|
||||||
enum_name string
|
enum_name string
|
||||||
@ -758,25 +771,27 @@ pub mut:
|
|||||||
typ table.Type
|
typ table.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enum field in enum declaration
|
||||||
pub struct EnumField {
|
pub struct EnumField {
|
||||||
pub:
|
pub:
|
||||||
name string
|
name string
|
||||||
pos token.Position
|
pos token.Position
|
||||||
comments []Comment
|
comments []Comment // comment after Enumfield in the same line
|
||||||
next_comments []Comment
|
next_comments []Comment // comments between current EnumField and next EnumField
|
||||||
expr Expr
|
expr Expr // the value of current EnumField; 123 in `ename = 123`
|
||||||
has_expr bool
|
has_expr bool // true, when .expr has a value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enum declaration
|
||||||
pub struct EnumDecl {
|
pub struct EnumDecl {
|
||||||
pub:
|
pub:
|
||||||
name string
|
name string
|
||||||
is_pub bool
|
is_pub bool
|
||||||
is_flag bool // true when the enum has [flag] tag
|
is_flag bool // true when the enum has [flag] tag,for bit field enum
|
||||||
is_multi_allowed bool
|
is_multi_allowed bool // true when the enum has [_allow_multiple_values] tag
|
||||||
comments []Comment // enum Abc { /* comments */ ... }
|
comments []Comment // comments before the first EnumField
|
||||||
fields []EnumField
|
fields []EnumField // all the enum fields
|
||||||
attrs []table.Attr
|
attrs []table.Attr // attributes of enum declaration
|
||||||
pos token.Position
|
pos token.Position
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user