2023-03-28 23:55:57 +03:00
|
|
|
|
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
|
2019-12-22 04:34:37 +03:00
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
|
module ast
|
|
|
|
|
|
2020-04-19 01:07:57 +03:00
|
|
|
|
import v.token
|
2020-05-10 12:26:57 +03:00
|
|
|
|
import v.errors
|
2021-03-17 03:43:17 +03:00
|
|
|
|
import v.pref
|
2019-12-22 04:34:37 +03:00
|
|
|
|
|
2020-11-25 14:09:40 +03:00
|
|
|
|
pub type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl
|
2020-03-07 19:37:55 +03:00
|
|
|
|
|
2021-09-10 20:56:55 +03:00
|
|
|
|
pub type Expr = AnonFn
|
|
|
|
|
| ArrayDecompose
|
|
|
|
|
| ArrayInit
|
|
|
|
|
| AsCast
|
|
|
|
|
| Assoc
|
|
|
|
|
| AtExpr
|
|
|
|
|
| BoolLiteral
|
|
|
|
|
| CTempVar
|
|
|
|
|
| CallExpr
|
|
|
|
|
| CastExpr
|
|
|
|
|
| ChanInit
|
|
|
|
|
| CharLiteral
|
|
|
|
|
| Comment
|
|
|
|
|
| ComptimeCall
|
|
|
|
|
| ComptimeSelector
|
2022-02-21 18:42:54 +03:00
|
|
|
|
| ComptimeType
|
2021-09-10 20:56:55 +03:00
|
|
|
|
| ConcatExpr
|
|
|
|
|
| DumpExpr
|
|
|
|
|
| EmptyExpr
|
|
|
|
|
| EnumVal
|
|
|
|
|
| FloatLiteral
|
|
|
|
|
| GoExpr
|
|
|
|
|
| Ident
|
|
|
|
|
| IfExpr
|
|
|
|
|
| IfGuardExpr
|
|
|
|
|
| IndexExpr
|
|
|
|
|
| InfixExpr
|
|
|
|
|
| IntegerLiteral
|
|
|
|
|
| IsRefType
|
|
|
|
|
| Likely
|
|
|
|
|
| LockExpr
|
|
|
|
|
| MapInit
|
|
|
|
|
| MatchExpr
|
2022-07-05 22:59:54 +03:00
|
|
|
|
| Nil
|
2021-09-10 20:56:55 +03:00
|
|
|
|
| NodeError
|
|
|
|
|
| None
|
|
|
|
|
| OffsetOf
|
|
|
|
|
| OrExpr
|
|
|
|
|
| ParExpr
|
|
|
|
|
| PostfixExpr
|
|
|
|
|
| PrefixExpr
|
|
|
|
|
| RangeExpr
|
|
|
|
|
| SelectExpr
|
|
|
|
|
| SelectorExpr
|
|
|
|
|
| SizeOf
|
2023-05-28 00:33:46 +03:00
|
|
|
|
| SpawnExpr
|
2021-09-10 20:56:55 +03:00
|
|
|
|
| SqlExpr
|
|
|
|
|
| StringInterLiteral
|
|
|
|
|
| StringLiteral
|
|
|
|
|
| StructInit
|
|
|
|
|
| TypeNode
|
|
|
|
|
| TypeOf
|
|
|
|
|
| UnsafeExpr
|
|
|
|
|
|
|
|
|
|
pub type Stmt = AsmStmt
|
|
|
|
|
| AssertStmt
|
|
|
|
|
| AssignStmt
|
|
|
|
|
| Block
|
|
|
|
|
| BranchStmt
|
2021-11-17 09:29:43 +03:00
|
|
|
|
| ComptimeFor
|
2021-09-10 20:56:55 +03:00
|
|
|
|
| ConstDecl
|
|
|
|
|
| DeferStmt
|
|
|
|
|
| EmptyStmt
|
|
|
|
|
| EnumDecl
|
|
|
|
|
| ExprStmt
|
|
|
|
|
| FnDecl
|
|
|
|
|
| ForCStmt
|
|
|
|
|
| ForInStmt
|
|
|
|
|
| ForStmt
|
|
|
|
|
| GlobalDecl
|
|
|
|
|
| GotoLabel
|
|
|
|
|
| GotoStmt
|
|
|
|
|
| HashStmt
|
|
|
|
|
| Import
|
|
|
|
|
| InterfaceDecl
|
|
|
|
|
| Module
|
|
|
|
|
| NodeError
|
|
|
|
|
| Return
|
|
|
|
|
| SqlStmt
|
|
|
|
|
| StructDecl
|
|
|
|
|
| TypeDecl
|
2020-04-04 06:14:40 +03:00
|
|
|
|
|
2021-03-17 03:43:17 +03:00
|
|
|
|
pub type ScopeObject = AsmRegister | ConstField | GlobalField | Var
|
2020-04-04 06:14:40 +03:00
|
|
|
|
|
2021-04-02 01:57:09 +03:00
|
|
|
|
// TODO: replace Param
|
2021-09-10 20:56:55 +03:00
|
|
|
|
pub type Node = CallArg
|
|
|
|
|
| ConstField
|
|
|
|
|
| EmptyNode
|
|
|
|
|
| EnumField
|
|
|
|
|
| Expr
|
|
|
|
|
| File
|
|
|
|
|
| GlobalField
|
|
|
|
|
| IfBranch
|
|
|
|
|
| MatchBranch
|
|
|
|
|
| NodeError
|
|
|
|
|
| Param
|
|
|
|
|
| ScopeObject
|
|
|
|
|
| SelectBranch
|
|
|
|
|
| Stmt
|
|
|
|
|
| StructField
|
|
|
|
|
| StructInitField
|
2021-01-09 07:36:38 +03:00
|
|
|
|
|
2021-04-02 01:57:09 +03:00
|
|
|
|
pub struct TypeNode {
|
2020-03-02 12:53:38 +03:00
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2022-08-05 03:01:49 +03:00
|
|
|
|
pub mut:
|
2023-05-18 12:22:26 +03:00
|
|
|
|
typ Type
|
|
|
|
|
end_comments []Comment // comments that after current type node
|
2020-03-02 12:53:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-21 18:42:54 +03:00
|
|
|
|
pub enum ComptimeTypeKind {
|
|
|
|
|
map_
|
|
|
|
|
int
|
|
|
|
|
float
|
|
|
|
|
struct_
|
|
|
|
|
iface
|
|
|
|
|
array
|
|
|
|
|
sum_type
|
|
|
|
|
enum_
|
2023-01-10 09:49:04 +03:00
|
|
|
|
alias
|
|
|
|
|
function
|
2023-03-10 13:17:25 +03:00
|
|
|
|
option
|
2022-02-21 18:42:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ComptimeType {
|
|
|
|
|
pub:
|
|
|
|
|
kind ComptimeTypeKind
|
|
|
|
|
pos token.Pos
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn (cty ComptimeType) str() string {
|
|
|
|
|
return match cty.kind {
|
2023-03-23 02:02:42 +03:00
|
|
|
|
.map_ { '\$map' }
|
|
|
|
|
.int { '\$int' }
|
|
|
|
|
.float { '\$float' }
|
|
|
|
|
.struct_ { '\$struct' }
|
|
|
|
|
.iface { '\$interface' }
|
|
|
|
|
.array { '\$array' }
|
|
|
|
|
.sum_type { '\$sumtype' }
|
|
|
|
|
.enum_ { '\$enum' }
|
|
|
|
|
.alias { '\$alias' }
|
|
|
|
|
.function { '\$function' }
|
|
|
|
|
.option { '\$option' }
|
2022-02-21 18:42:54 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-22 12:14:46 +03:00
|
|
|
|
pub type EmptyExpr = u8
|
2021-03-31 11:13:15 +03:00
|
|
|
|
|
|
|
|
|
pub struct EmptyStmt {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-03-31 11:13:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 01:57:09 +03:00
|
|
|
|
pub struct EmptyNode {
|
2022-07-22 12:14:46 +03:00
|
|
|
|
pub:
|
|
|
|
|
pos token.Pos
|
2021-04-02 01:57:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 14:29:15 +03:00
|
|
|
|
pub const (
|
|
|
|
|
empty_expr = Expr(EmptyExpr(0))
|
|
|
|
|
empty_stmt = Stmt(EmptyStmt{})
|
|
|
|
|
empty_node = Node(EmptyNode{})
|
|
|
|
|
)
|
2021-04-02 01:57:09 +03:00
|
|
|
|
|
2020-08-02 14:06:44 +03:00
|
|
|
|
// `{stmts}` or `unsafe {stmts}`
|
2020-03-24 17:44:17 +03:00
|
|
|
|
pub struct Block {
|
|
|
|
|
pub:
|
2020-08-02 14:06:44 +03:00
|
|
|
|
is_unsafe bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2023-07-03 23:10:00 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
stmts []Stmt
|
2020-03-24 17:44:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 18:13:12 +03:00
|
|
|
|
// | IncDecStmt k
|
2019-12-28 16:11:05 +03:00
|
|
|
|
// Stand-alone expression in a statement list.
|
|
|
|
|
pub struct ExprStmt {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-07-17 20:13:22 +03:00
|
|
|
|
comments []Comment
|
2020-05-21 23:35:43 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
expr Expr
|
2021-04-10 17:57:18 +03:00
|
|
|
|
is_expr bool
|
|
|
|
|
typ Type
|
2019-12-28 16:11:05 +03:00
|
|
|
|
}
|
2019-12-22 04:34:37 +03:00
|
|
|
|
|
2019-12-26 13:21:41 +03:00
|
|
|
|
pub struct IntegerLiteral {
|
2019-12-26 05:40:18 +03:00
|
|
|
|
pub:
|
2020-03-17 04:49:15 +03:00
|
|
|
|
val string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2019-12-26 05:40:18 +03:00
|
|
|
|
}
|
2019-12-24 20:54:43 +03:00
|
|
|
|
|
2019-12-27 12:03:29 +03:00
|
|
|
|
pub struct FloatLiteral {
|
|
|
|
|
pub:
|
|
|
|
|
val string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2019-12-27 12:03:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-24 20:54:43 +03:00
|
|
|
|
pub struct StringLiteral {
|
|
|
|
|
pub:
|
2020-05-19 18:12:47 +03:00
|
|
|
|
val string
|
|
|
|
|
is_raw bool
|
2021-04-02 01:57:09 +03:00
|
|
|
|
language Language
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2019-12-24 20:54:43 +03:00
|
|
|
|
}
|
2019-12-22 04:34:37 +03:00
|
|
|
|
|
2020-03-21 09:01:06 +03:00
|
|
|
|
// 'name: $name'
|
|
|
|
|
pub struct StringInterLiteral {
|
|
|
|
|
pub:
|
|
|
|
|
vals []string
|
2020-06-16 11:41:51 +03:00
|
|
|
|
fwidths []int
|
|
|
|
|
precisions []int
|
|
|
|
|
pluss []bool
|
|
|
|
|
fills []bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
fmt_poss []token.Pos
|
|
|
|
|
pos token.Pos
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-02-11 16:52:33 +03:00
|
|
|
|
exprs []Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
expr_types []Type
|
2022-04-15 15:30:37 +03:00
|
|
|
|
fmts []u8
|
2020-06-16 11:41:51 +03:00
|
|
|
|
need_fmts []bool // an explicit non-default fmt required, e.g. `x`
|
2020-03-21 09:01:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 11:54:15 +03:00
|
|
|
|
pub struct CharLiteral {
|
|
|
|
|
pub:
|
|
|
|
|
val string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-02-04 11:54:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 10:51:55 +03:00
|
|
|
|
pub struct BoolLiteral {
|
|
|
|
|
pub:
|
|
|
|
|
val bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2019-12-29 10:51:55 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 22:59:54 +03:00
|
|
|
|
pub struct Nil {
|
|
|
|
|
pub:
|
|
|
|
|
pos token.Pos
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-14 08:48:25 +03:00
|
|
|
|
pub enum GenericKindField {
|
|
|
|
|
unknown
|
|
|
|
|
name
|
|
|
|
|
typ
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-02 22:09:15 +03:00
|
|
|
|
// `foo.bar`
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-01-02 22:09:15 +03:00
|
|
|
|
pub struct SelectorExpr {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-01-12 06:38:43 +03:00
|
|
|
|
field_name string
|
|
|
|
|
is_mut bool // is used for the case `if mut ident.selector is MyType {`, it indicates if the root ident is mutable
|
2022-01-26 13:36:28 +03:00
|
|
|
|
mut_pos token.Pos
|
2021-01-12 06:38:43 +03:00
|
|
|
|
next_token token.Kind
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-05-16 21:29:47 +03:00
|
|
|
|
expr Expr // expr.field_name
|
|
|
|
|
expr_type Type // type of `Foo` in `Foo.bar`
|
|
|
|
|
typ Type // type of the entire thing (`Foo.bar`)
|
|
|
|
|
name_type Type // T in `T.name` or typeof in `typeof(expr).name`
|
2022-11-17 08:51:50 +03:00
|
|
|
|
or_block OrExpr
|
2022-05-16 21:29:47 +03:00
|
|
|
|
gkind_field GenericKindField // `T.name` => ast.GenericKindField.name, `T.typ` => ast.GenericKindField.typ, or .unknown
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2022-05-16 21:29:47 +03:00
|
|
|
|
from_embed_types []Type // holds the type of the embed that the method is called from
|
|
|
|
|
has_hidden_receiver bool
|
2020-01-02 22:09:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 02:59:39 +03:00
|
|
|
|
// root_ident returns the origin ident where the selector started.
|
2021-04-09 19:06:40 +03:00
|
|
|
|
pub fn (e &SelectorExpr) root_ident() ?Ident {
|
2020-12-10 02:59:39 +03:00
|
|
|
|
mut root := e.expr
|
2021-09-13 04:08:58 +03:00
|
|
|
|
for mut root is SelectorExpr {
|
|
|
|
|
root = root.expr
|
2020-12-10 02:59:39 +03:00
|
|
|
|
}
|
2022-03-02 17:01:20 +03:00
|
|
|
|
if mut root is Ident {
|
|
|
|
|
return root
|
2021-04-09 19:06:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return none
|
2020-12-10 02:59:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-28 13:02:06 +03:00
|
|
|
|
// module declaration
|
2019-12-28 11:15:32 +03:00
|
|
|
|
pub struct Module {
|
|
|
|
|
pub:
|
2021-01-20 08:04:59 +03:00
|
|
|
|
name string // encoding.base64
|
|
|
|
|
short_name string // base64
|
2021-04-02 01:57:09 +03:00
|
|
|
|
attrs []Attr
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
name_pos token.Pos // `name` in import name
|
|
|
|
|
is_skipped bool // module main can be skipped in single file programs
|
2019-12-28 11:15:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-04-05 03:08:10 +03:00
|
|
|
|
pub struct StructField {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
type_pos token.Pos
|
2023-01-09 09:36:45 +03:00
|
|
|
|
option_pos token.Pos
|
2020-06-23 19:01:56 +03:00
|
|
|
|
comments []Comment
|
2022-05-02 01:59:17 +03:00
|
|
|
|
i int
|
2020-04-12 13:35:54 +03:00
|
|
|
|
has_default_expr bool
|
2021-04-02 01:57:09 +03:00
|
|
|
|
attrs []Attr
|
|
|
|
|
is_pub bool
|
|
|
|
|
default_val string
|
|
|
|
|
is_mut bool
|
|
|
|
|
is_global bool
|
2021-11-04 10:31:40 +03:00
|
|
|
|
is_volatile bool
|
2022-05-26 00:44:18 +03:00
|
|
|
|
is_deprecated bool
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2023-04-18 14:07:21 +03:00
|
|
|
|
is_recursive bool
|
2021-06-21 07:10:10 +03:00
|
|
|
|
default_expr Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
default_expr_typ Type
|
|
|
|
|
name string
|
|
|
|
|
typ Type
|
2022-11-20 12:18:14 +03:00
|
|
|
|
unaliased_typ Type
|
2022-07-07 16:09:58 +03:00
|
|
|
|
anon_struct_decl StructDecl // only if the field is an anonymous struct
|
2020-04-05 03:08:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-21 16:00:21 +03:00
|
|
|
|
pub fn (f &StructField) equals(o &StructField) bool {
|
|
|
|
|
// TODO: f.is_mut == o.is_mut was removed here to allow read only access
|
|
|
|
|
// to (mut/not mut), but otherwise equal fields; some other new checks are needed:
|
|
|
|
|
// - if node is declared mut, and we mutate node.stmts, all stmts fields must be mutable
|
|
|
|
|
// - same goes for pub and global, if we call the field from another module
|
|
|
|
|
return f.name == o.name && f.typ == o.typ && f.is_pub == o.is_pub && f.is_global == o.is_global
|
2020-02-03 09:02:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// const field in const declaration group
|
2020-04-04 06:14:40 +03:00
|
|
|
|
pub struct ConstField {
|
2020-02-03 09:02:54 +03:00
|
|
|
|
pub:
|
2021-12-15 15:34:49 +03:00
|
|
|
|
mod string
|
|
|
|
|
name string
|
|
|
|
|
is_pub bool
|
2023-06-18 22:36:17 +03:00
|
|
|
|
is_markused bool // an explicit `[markused]` tag; the const will NOT be removed by `-skip-unused`, no matter what
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-04-11 17:27:41 +03:00
|
|
|
|
expr Expr // the value expr of field; everything after `=`
|
|
|
|
|
typ Type // the type of the const field, it can be any type in V
|
|
|
|
|
comments []Comment // comments before current const field
|
|
|
|
|
end_comments []Comment // comments that after const field
|
2021-07-18 19:41:39 +03:00
|
|
|
|
// the comptime_expr_value field is filled by the checker, when it has enough
|
|
|
|
|
// info to evaluate the constant at compile time
|
|
|
|
|
comptime_expr_value ComptTimeConstValue = empty_comptime_const_expr()
|
2020-04-04 06:14:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// const declaration
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-04-04 06:14:40 +03:00
|
|
|
|
pub struct ConstDecl {
|
|
|
|
|
pub:
|
2021-01-12 06:38:43 +03:00
|
|
|
|
is_pub bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-12-15 15:34:49 +03:00
|
|
|
|
attrs []Attr // tags like `[markused]`, valid for all the consts in the list
|
2020-04-27 23:53:26 +03:00
|
|
|
|
pub mut:
|
2020-12-28 14:52:04 +03:00
|
|
|
|
fields []ConstField // all the const fields in the `const (...)` block
|
2021-01-03 23:10:25 +03:00
|
|
|
|
end_comments []Comment // comments that after last const field
|
2020-12-30 04:15:44 +03:00
|
|
|
|
is_block bool // const() block
|
2019-12-30 08:16:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-30 08:16:59 +03:00
|
|
|
|
pub struct StructDecl {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-04-22 18:21:01 +03:00
|
|
|
|
name string
|
|
|
|
|
generic_types []Type
|
|
|
|
|
is_pub bool
|
2021-01-17 07:39:44 +03:00
|
|
|
|
// _pos fields for vfmt
|
2020-06-23 19:01:56 +03:00
|
|
|
|
mut_pos int // mut:
|
|
|
|
|
pub_pos int // pub:
|
|
|
|
|
pub_mut_pos int // pub mut:
|
2021-02-05 18:46:43 +03:00
|
|
|
|
global_pos int // __global:
|
2021-01-17 07:39:44 +03:00
|
|
|
|
module_pos int // module:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
language Language
|
2020-06-23 19:01:56 +03:00
|
|
|
|
is_union bool
|
2021-04-02 01:57:09 +03:00
|
|
|
|
attrs []Attr
|
2020-06-23 19:01:56 +03:00
|
|
|
|
end_comments []Comment
|
2020-12-23 21:12:49 +03:00
|
|
|
|
embeds []Embed
|
2020-10-30 09:09:26 +03:00
|
|
|
|
pub mut:
|
2021-01-12 06:38:43 +03:00
|
|
|
|
fields []StructField
|
2020-10-30 09:09:26 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 21:12:49 +03:00
|
|
|
|
pub struct Embed {
|
|
|
|
|
pub:
|
2021-05-08 13:32:29 +03:00
|
|
|
|
typ Type
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-05-08 13:32:29 +03:00
|
|
|
|
comments []Comment
|
2019-12-30 08:16:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 03:00:47 +03:00
|
|
|
|
pub struct InterfaceEmbedding {
|
|
|
|
|
pub:
|
|
|
|
|
name string
|
|
|
|
|
typ Type
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-05-02 03:00:47 +03:00
|
|
|
|
comments []Comment
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-03-31 20:59:38 +03:00
|
|
|
|
pub struct InterfaceDecl {
|
2020-04-05 13:31:39 +03:00
|
|
|
|
pub:
|
2021-07-15 08:29:13 +03:00
|
|
|
|
name string
|
|
|
|
|
typ Type
|
2022-01-26 13:36:28 +03:00
|
|
|
|
name_pos token.Pos
|
2021-07-15 08:29:13 +03:00
|
|
|
|
language Language
|
|
|
|
|
field_names []string
|
|
|
|
|
is_pub bool
|
|
|
|
|
mut_pos int // mut:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-07-15 08:29:13 +03:00
|
|
|
|
pre_comments []Comment
|
|
|
|
|
generic_types []Type
|
2021-11-17 12:41:33 +03:00
|
|
|
|
attrs []Attr
|
2021-05-02 03:00:47 +03:00
|
|
|
|
pub mut:
|
2022-02-15 12:17:39 +03:00
|
|
|
|
methods []FnDecl
|
|
|
|
|
fields []StructField
|
|
|
|
|
embeds []InterfaceEmbedding
|
|
|
|
|
are_embeds_expanded bool
|
2020-03-31 20:59:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-21 13:48:53 +03:00
|
|
|
|
// `field1: val1`
|
2020-04-17 03:38:39 +03:00
|
|
|
|
pub struct StructInitField {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
name_pos token.Pos
|
2020-10-14 22:48:49 +03:00
|
|
|
|
comments []Comment
|
2020-12-09 12:11:22 +03:00
|
|
|
|
next_comments []Comment
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-02-21 13:48:53 +03:00
|
|
|
|
expr Expr // `val1`
|
|
|
|
|
name string // 'field1'
|
|
|
|
|
typ Type // the type of this field
|
2021-04-02 01:57:09 +03:00
|
|
|
|
expected_type Type
|
2021-04-02 17:26:37 +03:00
|
|
|
|
parent_type Type
|
2020-04-17 03:38:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-21 13:48:53 +03:00
|
|
|
|
// `s := Foo{
|
|
|
|
|
// ...a
|
|
|
|
|
// field1: 'hello'
|
|
|
|
|
// }`
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-30 08:16:59 +03:00
|
|
|
|
pub struct StructInit {
|
|
|
|
|
pub:
|
2022-02-09 15:06:45 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
name_pos token.Pos
|
2022-07-10 12:00:17 +03:00
|
|
|
|
no_keys bool // `Foo{val1, val2}`
|
|
|
|
|
is_short_syntax bool // `foo(field1: val1, field2: val2)`
|
|
|
|
|
is_anon bool // `x: struct{ foo: bar }`
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2021-02-02 16:42:00 +03:00
|
|
|
|
unresolved bool
|
2021-01-04 22:01:35 +03:00
|
|
|
|
pre_comments []Comment
|
2022-02-21 13:48:53 +03:00
|
|
|
|
typ_str string // 'Foo'
|
|
|
|
|
typ Type // the type of this struct
|
|
|
|
|
update_expr Expr // `a` in `...a`
|
2021-04-02 01:57:09 +03:00
|
|
|
|
update_expr_type Type
|
2023-01-03 11:21:32 +03:00
|
|
|
|
update_expr_pos token.Pos
|
2021-01-04 22:01:35 +03:00
|
|
|
|
update_expr_comments []Comment
|
2022-02-12 08:16:51 +03:00
|
|
|
|
is_update_embed bool
|
2022-02-21 13:48:53 +03:00
|
|
|
|
has_update_expr bool // has `...a`
|
2023-06-22 16:41:08 +03:00
|
|
|
|
init_fields []StructInitField
|
2022-02-04 15:24:38 +03:00
|
|
|
|
generic_types []Type
|
2019-12-30 08:16:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-10 12:00:17 +03:00
|
|
|
|
pub enum StructInitKind {
|
|
|
|
|
normal
|
|
|
|
|
short_syntax
|
|
|
|
|
anon
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-28 11:15:32 +03:00
|
|
|
|
// import statement
|
|
|
|
|
pub struct Import {
|
|
|
|
|
pub:
|
2021-01-09 07:36:38 +03:00
|
|
|
|
mod string // the module name of the import
|
|
|
|
|
alias string // the `x` in `import xxx as x`
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
mod_pos token.Pos
|
|
|
|
|
alias_pos token.Pos
|
|
|
|
|
syms_pos token.Pos
|
2020-07-18 22:34:38 +03:00
|
|
|
|
pub mut:
|
2021-02-08 20:48:48 +03:00
|
|
|
|
syms []ImportSymbol // the list of symbols in `import {symbol1, symbol2}`
|
|
|
|
|
comments []Comment
|
|
|
|
|
next_comments []Comment
|
2020-07-18 22:34:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// import symbol,for import {symbol} syntax
|
2020-07-18 22:34:38 +03:00
|
|
|
|
pub struct ImportSymbol {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-08-04 21:10:22 +03:00
|
|
|
|
name string
|
2019-12-28 11:15:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// anonymous function
|
2020-04-17 22:59:19 +03:00
|
|
|
|
pub struct AnonFn {
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2021-08-10 21:27:15 +03:00
|
|
|
|
decl FnDecl
|
|
|
|
|
inherited_vars []Param
|
|
|
|
|
typ Type // the type of anonymous fn. Both .typ and .decl.name are auto generated
|
2023-03-31 18:08:42 +03:00
|
|
|
|
has_gen map[string]bool // has been generated
|
2020-04-17 22:59:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// function or method declaration
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-27 15:57:49 +03:00
|
|
|
|
pub struct FnDecl {
|
|
|
|
|
pub:
|
2023-06-27 01:23:24 +03:00
|
|
|
|
name string // 'math.bits.normalize'
|
|
|
|
|
short_name string // 'normalize'
|
|
|
|
|
mod string // 'math.bits'
|
|
|
|
|
is_deprecated bool
|
|
|
|
|
is_pub bool
|
|
|
|
|
is_variadic bool
|
|
|
|
|
is_anon bool
|
|
|
|
|
is_noreturn bool // true, when [noreturn] is used on a fn
|
|
|
|
|
is_manualfree bool // true, when [manualfree] is used on a fn
|
|
|
|
|
is_main bool // true for `fn main()`
|
|
|
|
|
is_test bool // true for `fn test_abcde() {}`, false for `fn test_abc(x int) {}`, or for fns that do not start with test_
|
|
|
|
|
is_conditional bool // true for `[if abc] fn abc(){}`
|
|
|
|
|
is_exported bool // true for `[export: 'exact_C_name']`
|
|
|
|
|
is_keep_alive bool // passed memory must not be freed (by GC) before function returns
|
|
|
|
|
is_unsafe bool // true, when [unsafe] is used on a fn
|
|
|
|
|
is_markused bool // true, when an explicit `[markused]` tag was put on a fn; `-skip-unused` will not remove that fn
|
|
|
|
|
is_file_translated bool // true, when the file it resides in is `[translated]`
|
|
|
|
|
receiver StructField // TODO this is not a struct field
|
|
|
|
|
receiver_pos token.Pos // `(u User)` in `fn (u User) name()` position
|
|
|
|
|
is_method bool
|
|
|
|
|
is_static_type_method bool // true for `fn Foo.bar() {}`
|
|
|
|
|
method_type_pos token.Pos // `User` in ` fn (u User)` position
|
|
|
|
|
method_idx int
|
|
|
|
|
rec_mut bool // is receiver mutable
|
|
|
|
|
rec_share ShareType
|
|
|
|
|
language Language // V, C, JS
|
|
|
|
|
file_mode Language // whether *the file*, where a function was a '.c.v', '.js.v' etc.
|
|
|
|
|
no_body bool // just a definition `fn C.malloc()`
|
|
|
|
|
is_builtin bool // this function is defined in builtin/strconv
|
|
|
|
|
body_pos token.Pos // function bodys position
|
|
|
|
|
file string
|
|
|
|
|
generic_names []string
|
|
|
|
|
is_direct_arr bool // direct array access
|
|
|
|
|
attrs []Attr
|
|
|
|
|
ctdefine_idx int = -1 // the index in fn.attrs of `[if xyz]`, when such attribute exists
|
2020-04-27 23:53:26 +03:00
|
|
|
|
pub mut:
|
2022-04-28 12:31:30 +03:00
|
|
|
|
idx int // index in an external container; can be used to refer to the function in a more efficient way, just by its integer index
|
2021-08-03 03:17:22 +03:00
|
|
|
|
params []Param
|
|
|
|
|
stmts []Stmt
|
|
|
|
|
defer_stmts []DeferStmt
|
|
|
|
|
return_type Type
|
2022-01-26 13:36:28 +03:00
|
|
|
|
return_type_pos token.Pos // `string` in `fn (u User) name() string` position
|
2021-08-03 03:17:22 +03:00
|
|
|
|
has_return bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
should_be_skipped bool // true, when -skip-unused could not find any usages of that function, starting from main + other known used functions
|
2021-12-22 17:16:10 +03:00
|
|
|
|
ninstances int // 0 for generic functions with no concrete instances
|
2021-12-15 15:34:49 +03:00
|
|
|
|
has_await bool // 'true' if this function uses JS.await
|
2023-04-15 14:29:15 +03:00
|
|
|
|
|
2021-12-05 14:33:53 +03:00
|
|
|
|
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
|
2022-02-25 16:36:48 +03:00
|
|
|
|
end_comments []Comment // comments *after* header declarations. E.g.: `fn C.C_func(x int) int // Comment`
|
|
|
|
|
next_comments []Comment // comments that are one line after the decl; used for InterfaceDecl
|
2023-04-15 14:29:15 +03:00
|
|
|
|
|
2022-09-15 07:59:31 +03:00
|
|
|
|
source_file &File = unsafe { nil }
|
|
|
|
|
scope &Scope = unsafe { nil }
|
2021-06-17 11:38:42 +03:00
|
|
|
|
label_names []string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos // function declaration position
|
2019-12-29 09:24:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 16:58:34 +03:00
|
|
|
|
pub fn (f &FnDecl) new_method_with_receiver_type(new_type Type) FnDecl {
|
|
|
|
|
unsafe {
|
|
|
|
|
mut new_method := f
|
|
|
|
|
new_method.params = f.params.clone()
|
|
|
|
|
for i in 1 .. new_method.params.len {
|
|
|
|
|
if new_method.params[i].typ == new_method.params[0].typ {
|
|
|
|
|
new_method.params[i].typ = new_type
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new_method.params[0].typ = new_type
|
|
|
|
|
return *new_method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[minify]
|
|
|
|
|
pub struct Fn {
|
|
|
|
|
pub:
|
2023-06-27 01:23:24 +03:00
|
|
|
|
is_variadic bool
|
|
|
|
|
language Language
|
|
|
|
|
is_pub bool
|
|
|
|
|
is_ctor_new bool // `[use_new] fn JS.Array.prototype.constructor()`
|
|
|
|
|
is_deprecated bool // `[deprecated] fn abc(){}`
|
|
|
|
|
is_noreturn bool // `[noreturn] fn abc(){}`
|
|
|
|
|
is_unsafe bool // `[unsafe] fn abc(){}`
|
|
|
|
|
is_placeholder bool
|
|
|
|
|
is_main bool // `fn main(){}`
|
|
|
|
|
is_test bool // `fn test_abc(){}`
|
|
|
|
|
is_keep_alive bool // passed memory must not be freed (by GC) before function returns
|
|
|
|
|
is_method bool // true for `fn (x T) name()`, and for interface declarations (which are also for methods)
|
|
|
|
|
is_static_type_method bool // true for `fn Foo.bar() {}`
|
|
|
|
|
no_body bool // a pure declaration like `fn abc(x int)`; used in .vh files, C./JS. fns.
|
|
|
|
|
is_file_translated bool // true, when the file it resides in is `[translated]`
|
|
|
|
|
mod string
|
|
|
|
|
file string
|
|
|
|
|
file_mode Language
|
|
|
|
|
pos token.Pos
|
|
|
|
|
return_type_pos token.Pos
|
2023-04-07 16:58:34 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
return_type Type
|
|
|
|
|
receiver_type Type // != 0, when .is_method == true
|
|
|
|
|
name string
|
|
|
|
|
params []Param
|
|
|
|
|
source_fn voidptr // set in the checker, while processing fn declarations // TODO get rid of voidptr
|
|
|
|
|
usages int
|
|
|
|
|
generic_names []string
|
|
|
|
|
dep_names []string // globals or consts dependent names
|
|
|
|
|
attrs []Attr // all fn attributes
|
|
|
|
|
is_conditional bool // true for `[if abc]fn(){}`
|
|
|
|
|
ctdefine_idx int // the index of the attribute, containing the compile time define [if mytag]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn (f &Fn) method_equals(o &Fn) bool {
|
|
|
|
|
return f.params[1..].equals(o.params[1..]) && f.return_type == o.return_type
|
|
|
|
|
&& f.is_variadic == o.is_variadic && f.language == o.language
|
|
|
|
|
&& f.generic_names == o.generic_names && f.is_pub == o.is_pub && f.mod == o.mod
|
|
|
|
|
&& f.name == o.name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[minify]
|
|
|
|
|
pub struct Param {
|
|
|
|
|
pub:
|
|
|
|
|
pos token.Pos
|
|
|
|
|
name string
|
|
|
|
|
is_mut bool
|
2023-05-09 00:22:22 +03:00
|
|
|
|
is_shared bool
|
|
|
|
|
is_atomic bool
|
2023-04-07 16:58:34 +03:00
|
|
|
|
is_auto_rec bool
|
|
|
|
|
type_pos token.Pos
|
|
|
|
|
is_hidden bool // interface first arg
|
|
|
|
|
pub mut:
|
|
|
|
|
typ Type
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-09 00:22:22 +03:00
|
|
|
|
pub fn (p &Param) specifier() string {
|
|
|
|
|
if p.is_shared {
|
|
|
|
|
return 'shared'
|
|
|
|
|
} else if p.is_atomic {
|
|
|
|
|
return 'atomic'
|
|
|
|
|
} else if p.is_mut {
|
|
|
|
|
return 'mut'
|
|
|
|
|
} else {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 16:58:34 +03:00
|
|
|
|
pub fn (f &Fn) new_method_with_receiver_type(new_type Type) Fn {
|
|
|
|
|
unsafe {
|
|
|
|
|
mut new_method := f
|
|
|
|
|
new_method.params = f.params.clone()
|
|
|
|
|
for i in 1 .. new_method.params.len {
|
|
|
|
|
if new_method.params[i].typ == new_method.params[0].typ {
|
|
|
|
|
new_method.params[i].typ = new_type
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new_method.params[0].typ = new_type
|
|
|
|
|
|
|
|
|
|
return *new_method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn (p &Param) equals(o &Param) bool {
|
|
|
|
|
return p.name == o.name && p.is_mut == o.is_mut && p.typ == o.typ && p.is_hidden == o.is_hidden
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn (p []Param) equals(o []Param) bool {
|
|
|
|
|
if p.len != o.len {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
for i in 0 .. p.len {
|
|
|
|
|
if !p[i].equals(o[i]) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 02:09:00 +03:00
|
|
|
|
// break, continue
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-04 10:29:50 +03:00
|
|
|
|
pub struct BranchStmt {
|
|
|
|
|
pub:
|
2020-12-06 10:02:36 +03:00
|
|
|
|
kind token.Kind
|
|
|
|
|
label string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-02-04 10:29:50 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// function or method call expr
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-29 09:24:17 +03:00
|
|
|
|
pub struct CallExpr {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
name_pos token.Pos
|
2021-03-30 10:43:17 +03:00
|
|
|
|
mod string
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2020-11-14 14:59:03 +03:00
|
|
|
|
name string // left.name()
|
2020-04-27 23:53:26 +03:00
|
|
|
|
is_method bool
|
2020-07-13 21:04:16 +03:00
|
|
|
|
is_field bool // temp hack, remove ASAP when re-impl CallExpr / Selector (joe)
|
2022-11-15 20:51:57 +03:00
|
|
|
|
is_fn_var bool // fn variable, `a := fn() {}`, then: `a()`
|
|
|
|
|
is_fn_a_const bool // fn const, `const c = abc`, where `abc` is a function, then: `c()`
|
2021-04-09 13:13:49 +03:00
|
|
|
|
is_keep_alive bool // GC must not free arguments before fn returns
|
2021-07-04 20:24:19 +03:00
|
|
|
|
is_noreturn bool // whether the function/method is marked as [noreturn]
|
2021-11-17 12:41:33 +03:00
|
|
|
|
is_ctor_new bool // if JS ctor calls requires `new` before call, marked as `[use_new]` in V
|
2023-01-26 18:47:38 +03:00
|
|
|
|
is_file_translated bool // true, when the file it resides in is `[translated]`
|
2020-04-09 16:33:46 +03:00
|
|
|
|
args []CallArg
|
2021-04-02 01:57:09 +03:00
|
|
|
|
expected_arg_types []Type
|
2022-12-26 19:44:18 +03:00
|
|
|
|
comptime_ret_val bool
|
2021-04-02 01:57:09 +03:00
|
|
|
|
language Language
|
2020-04-09 16:33:46 +03:00
|
|
|
|
or_block OrExpr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
left Expr // `user` in `user.register()`
|
|
|
|
|
left_type Type // type of `user`
|
|
|
|
|
receiver_type Type // User
|
|
|
|
|
return_type Type
|
2022-11-15 20:51:57 +03:00
|
|
|
|
fn_var_type Type // the fn type, when `is_fn_a_const` or `is_fn_var` is true
|
|
|
|
|
const_name string // the fully qualified name of the const, i.e. `main.c`, given `const c = abc`, and callexpr: `c()`
|
2021-12-15 15:34:49 +03:00
|
|
|
|
should_be_skipped bool // true for calls to `[if someflag?]` functions, when there is no `-d someflag`
|
2021-04-24 09:44:15 +03:00
|
|
|
|
concrete_types []Type // concrete types, e.g. <int, string>
|
2022-01-26 13:36:28 +03:00
|
|
|
|
concrete_list_pos token.Pos
|
2022-02-11 23:00:13 +03:00
|
|
|
|
raw_concrete_types []Type
|
2020-10-22 04:51:25 +03:00
|
|
|
|
free_receiver bool // true if the receiver expression needs to be freed
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2021-12-04 15:51:42 +03:00
|
|
|
|
from_embed_types []Type // holds the type of the embed that the method is called from
|
2021-01-10 00:47:33 +03:00
|
|
|
|
comments []Comment
|
2020-03-14 13:11:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-05 13:00:35 +03:00
|
|
|
|
/*
|
|
|
|
|
pub struct AutofreeArgVar {
|
|
|
|
|
name string
|
|
|
|
|
idx int
|
|
|
|
|
}
|
|
|
|
|
*/
|
2023-04-15 14:29:15 +03:00
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// function call argument: `f(callarg)`
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-03-14 13:11:43 +03:00
|
|
|
|
pub struct CallArg {
|
|
|
|
|
pub:
|
2021-01-12 06:38:43 +03:00
|
|
|
|
is_mut bool
|
2021-04-02 01:57:09 +03:00
|
|
|
|
share ShareType
|
2021-01-12 06:38:43 +03:00
|
|
|
|
comments []Comment
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2021-06-21 07:10:10 +03:00
|
|
|
|
expr Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2020-11-09 16:24:46 +03:00
|
|
|
|
is_tmp_autofree bool // this tells cgen that a tmp variable has to be used for the arg expression in order to free it after the call
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-09-05 13:00:35 +03:00
|
|
|
|
// tmp_name string // for autofree
|
2019-12-27 15:57:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// function return statement
|
2019-12-27 15:57:49 +03:00
|
|
|
|
pub struct Return {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-07-17 20:13:22 +03:00
|
|
|
|
comments []Comment
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2021-06-21 07:10:10 +03:00
|
|
|
|
exprs []Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
types []Type
|
2019-12-27 15:57:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-14 14:49:29 +03:00
|
|
|
|
pub enum ComptimeVarKind {
|
|
|
|
|
no_comptime // it is not a comptime var
|
|
|
|
|
key_var // map key from `for k,v in t.$(field.name)`
|
|
|
|
|
value_var // map value from `for k,v in t.$(field.name)`
|
|
|
|
|
field_var // comptime field var `a := t.$(field.name)`
|
2023-04-10 10:42:49 +03:00
|
|
|
|
generic_param // generic fn parameter
|
2023-03-14 14:49:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-03-10 14:01:37 +03:00
|
|
|
|
pub struct Var {
|
2019-12-24 20:54:43 +03:00
|
|
|
|
pub:
|
2020-10-29 03:09:38 +03:00
|
|
|
|
name string
|
2021-04-02 01:57:09 +03:00
|
|
|
|
share ShareType
|
2020-10-29 03:09:38 +03:00
|
|
|
|
is_mut bool
|
|
|
|
|
is_autofree_tmp bool
|
|
|
|
|
is_arg bool // fn args should not be autofreed
|
2021-02-12 03:03:11 +03:00
|
|
|
|
is_auto_deref bool
|
2021-08-10 21:27:15 +03:00
|
|
|
|
is_inherited bool
|
2022-08-26 13:37:10 +03:00
|
|
|
|
has_inherited bool
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-03-13 17:33:50 +03:00
|
|
|
|
expr Expr
|
2021-04-09 11:00:05 +03:00
|
|
|
|
typ Type
|
|
|
|
|
orig_type Type // original sumtype type; 0 if it's not a sumtype
|
|
|
|
|
smartcasts []Type // nested sum types require nested smart casting, for that a list of types is needed
|
2021-01-21 23:31:25 +03:00
|
|
|
|
// TODO: move this to a real docs site later
|
|
|
|
|
// 10 <- original type (orig_type)
|
2021-04-09 11:00:05 +03:00
|
|
|
|
// [11, 12, 13] <- cast order (smartcasts)
|
2021-01-21 23:31:25 +03:00
|
|
|
|
// 12 <- the current casted type (typ)
|
2023-03-14 14:49:29 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
is_used bool // whether the local variable was used in other expressions
|
|
|
|
|
is_changed bool // to detect mutable vars that are never changed
|
|
|
|
|
ct_type_var ComptimeVarKind // comptime variable type
|
2020-12-05 22:52:50 +03:00
|
|
|
|
// (for setting the position after the or block for autofree)
|
2021-04-25 21:40:38 +03:00
|
|
|
|
is_or bool // `x := foo() or { ... }`
|
|
|
|
|
is_tmp bool // for tmp for loop vars, so that autofree can skip them
|
2023-06-18 22:36:17 +03:00
|
|
|
|
is_auto_heap bool // value whose address goes out of scope
|
2021-04-25 21:40:38 +03:00
|
|
|
|
is_stack_obj bool // may be pointer to stack value (`mut` or `&` arg and not [heap] struct)
|
2019-12-24 20:54:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 11:18:15 +03:00
|
|
|
|
// used for smartcasting only
|
|
|
|
|
// struct fields change type in scopes
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-11-11 11:18:15 +03:00
|
|
|
|
pub struct ScopeStructField {
|
|
|
|
|
pub:
|
2021-04-09 11:00:05 +03:00
|
|
|
|
struct_type Type // type of struct
|
|
|
|
|
name string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-04-09 11:00:05 +03:00
|
|
|
|
typ Type
|
|
|
|
|
smartcasts []Type // nested sum types require nested smart casting, for that a list of types is needed
|
|
|
|
|
orig_type Type // original sumtype type; 0 if it's not a sumtype
|
2021-01-21 23:31:25 +03:00
|
|
|
|
// TODO: move this to a real docs site later
|
|
|
|
|
// 10 <- original type (orig_type)
|
2021-04-09 11:00:05 +03:00
|
|
|
|
// [11, 12, 13] <- cast order (smartcasts)
|
2021-01-21 23:31:25 +03:00
|
|
|
|
// 12 <- the current casted type (typ)
|
2020-11-11 11:18:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-10-03 08:03:44 +03:00
|
|
|
|
pub struct GlobalField {
|
2020-02-03 09:02:54 +03:00
|
|
|
|
pub:
|
2021-12-15 15:34:49 +03:00
|
|
|
|
name string
|
|
|
|
|
has_expr bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
typ_pos token.Pos
|
2023-06-18 22:36:17 +03:00
|
|
|
|
is_markused bool // an explicit `[markused]` tag; the global will NOT be removed by `-skip-unused`
|
2022-04-15 02:39:38 +03:00
|
|
|
|
is_volatile bool
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2021-07-28 08:11:55 +03:00
|
|
|
|
expr Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2020-10-03 08:03:44 +03:00
|
|
|
|
comments []Comment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct GlobalDecl {
|
|
|
|
|
pub:
|
2021-07-29 10:57:31 +03:00
|
|
|
|
mod string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-12-15 15:34:49 +03:00
|
|
|
|
is_block bool // __global() block
|
|
|
|
|
attrs []Attr // tags like `[markused]`, valid for all the globals in the list
|
2020-10-03 08:03:44 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
fields []GlobalField
|
|
|
|
|
end_comments []Comment
|
2020-02-03 09:02:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2021-01-14 17:20:11 +03:00
|
|
|
|
pub struct EmbeddedFile {
|
|
|
|
|
pub:
|
2021-12-04 20:43:19 +03:00
|
|
|
|
compression_type string
|
|
|
|
|
pub mut:
|
2022-11-10 05:09:51 +03:00
|
|
|
|
rpath string // used in the source code, as an ID/key to the embed
|
|
|
|
|
apath string // absolute path during compilation to the resource
|
2021-12-04 20:43:19 +03:00
|
|
|
|
// these are set by gen_embed_file_init in v/gen/c/embed
|
|
|
|
|
is_compressed bool
|
2022-04-15 15:30:37 +03:00
|
|
|
|
bytes []u8
|
2021-12-04 20:43:19 +03:00
|
|
|
|
len int
|
2021-01-14 17:20:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 01:57:09 +03:00
|
|
|
|
// Each V source file is represented by one File structure.
|
|
|
|
|
// When the V compiler runs, the parser will fill an []File.
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// That array is then passed to V's checker.
|
2021-05-22 18:59:17 +03:00
|
|
|
|
[heap]
|
2019-12-30 14:10:46 +03:00
|
|
|
|
pub struct File {
|
2019-12-24 20:54:43 +03:00
|
|
|
|
pub:
|
2022-02-06 01:16:02 +03:00
|
|
|
|
nr_lines int // number of source code lines in the file (including newlines and comments)
|
|
|
|
|
nr_bytes int // number of processed source code bytes
|
|
|
|
|
mod Module // the module of the source file (from `module xyz` at the top)
|
2022-09-15 07:59:31 +03:00
|
|
|
|
global_scope &Scope = unsafe { nil }
|
2022-02-06 01:16:02 +03:00
|
|
|
|
is_test bool // true for _test.v files
|
|
|
|
|
is_generated bool // true for `[generated] module xyz` files; turn off notices
|
|
|
|
|
is_translated bool // true for `[translated] module xyz` files; turn off some checks
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-04-28 12:31:30 +03:00
|
|
|
|
idx int // index in an external container; can be used to refer to the file in a more efficient way, just by its integer index
|
2021-05-22 18:59:17 +03:00
|
|
|
|
path string // absolute path of the source file - '/projects/v/file.v'
|
|
|
|
|
path_base string // file name - 'file.v' (useful for tracing)
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2021-01-14 17:20:11 +03:00
|
|
|
|
stmts []Stmt // all the statements in the source file
|
|
|
|
|
imports []Import // all the imports
|
2023-06-18 22:36:17 +03:00
|
|
|
|
auto_imports []string // imports that were implicitly added
|
2021-01-14 17:20:11 +03:00
|
|
|
|
embedded_files []EmbeddedFile // list of files to embed in the binary
|
2020-12-28 14:52:04 +03:00
|
|
|
|
imported_symbols map[string]string // used for `import {symbol}`, it maps symbol => module.symbol
|
2021-01-03 23:10:25 +03:00
|
|
|
|
errors []errors.Error // all the checker errors in the file
|
2021-03-22 20:43:06 +03:00
|
|
|
|
warnings []errors.Warning // all the checker warnings in the file
|
|
|
|
|
notices []errors.Notice // all the checker notices in the file
|
2020-12-07 20:13:03 +03:00
|
|
|
|
generic_fns []&FnDecl
|
2021-04-01 09:58:33 +03:00
|
|
|
|
global_labels []string // from `asm { .globl labelname }`
|
2023-04-06 00:44:52 +03:00
|
|
|
|
template_paths []string // all the .html/.md files that were processed with $tmpl
|
2020-02-17 14:25:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 10:24:16 +03:00
|
|
|
|
[unsafe]
|
|
|
|
|
pub fn (f &File) free() {
|
|
|
|
|
unsafe {
|
|
|
|
|
f.path.free()
|
|
|
|
|
f.path_base.free()
|
|
|
|
|
f.scope.free()
|
|
|
|
|
f.stmts.free()
|
|
|
|
|
f.imports.free()
|
|
|
|
|
f.auto_imports.free()
|
|
|
|
|
f.embedded_files.free()
|
|
|
|
|
f.imported_symbols.free()
|
|
|
|
|
f.errors.free()
|
|
|
|
|
f.warnings.free()
|
|
|
|
|
f.notices.free()
|
|
|
|
|
f.global_labels.free()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 18:10:46 +03:00
|
|
|
|
pub struct IdentFn {
|
2020-02-17 14:25:18 +03:00
|
|
|
|
pub mut:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2020-01-19 01:26:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 19:10:31 +03:00
|
|
|
|
// TODO: (joe) remove completely, use ident.obj
|
|
|
|
|
// instead which points to the scope object
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-01-19 01:26:14 +03:00
|
|
|
|
pub struct IdentVar {
|
2020-02-06 15:57:35 +03:00
|
|
|
|
pub mut:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2020-03-13 07:57:51 +03:00
|
|
|
|
is_mut bool
|
|
|
|
|
is_static bool
|
2021-09-22 13:06:30 +03:00
|
|
|
|
is_volatile bool
|
2023-01-09 09:36:45 +03:00
|
|
|
|
is_option bool
|
2021-04-02 01:57:09 +03:00
|
|
|
|
share ShareType
|
2020-01-19 01:26:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 14:09:40 +03:00
|
|
|
|
pub type IdentInfo = IdentFn | IdentVar
|
2020-01-19 01:26:14 +03:00
|
|
|
|
|
|
|
|
|
pub enum IdentKind {
|
2020-02-17 14:25:18 +03:00
|
|
|
|
unresolved
|
2020-01-19 01:26:14 +03:00
|
|
|
|
blank_ident
|
|
|
|
|
variable
|
2020-02-03 09:02:54 +03:00
|
|
|
|
constant
|
2020-04-04 06:14:40 +03:00
|
|
|
|
global
|
2020-02-17 14:25:18 +03:00
|
|
|
|
function
|
2019-12-24 20:54:43 +03:00
|
|
|
|
}
|
2019-12-28 16:11:05 +03:00
|
|
|
|
|
2019-12-22 04:34:37 +03:00
|
|
|
|
// A single identifier
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-28 16:11:05 +03:00
|
|
|
|
pub struct Ident {
|
|
|
|
|
pub:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
language Language
|
2019-12-31 12:53:30 +03:00
|
|
|
|
tok_kind token.Kind
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
mut_pos token.Pos
|
2021-05-31 14:43:44 +03:00
|
|
|
|
comptime bool
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2023-05-07 20:53:56 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
|
|
|
|
obj ScopeObject
|
|
|
|
|
mod string
|
|
|
|
|
name string
|
|
|
|
|
kind IdentKind
|
|
|
|
|
info IdentInfo
|
|
|
|
|
is_mut bool // if mut *token* is before name. Use `is_mut()` to lookup mut variable
|
|
|
|
|
or_expr OrExpr
|
|
|
|
|
concrete_types []Type
|
2022-03-24 21:43:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-04 19:10:22 +03:00
|
|
|
|
pub fn (i &Ident) is_auto_heap() bool {
|
|
|
|
|
match i.obj {
|
|
|
|
|
Var {
|
|
|
|
|
return i.obj.is_auto_heap
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 21:43:25 +03:00
|
|
|
|
pub fn (i &Ident) is_mut() bool {
|
|
|
|
|
match i.obj {
|
|
|
|
|
Var {
|
|
|
|
|
return i.obj.is_mut
|
|
|
|
|
}
|
|
|
|
|
ConstField {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
AsmRegister, GlobalField {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-22 04:34:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 16:49:14 +03:00
|
|
|
|
pub fn (i &Ident) var_info() IdentVar {
|
2022-03-13 10:53:29 +03:00
|
|
|
|
match i.info {
|
2020-02-06 19:38:02 +03:00
|
|
|
|
IdentVar {
|
2020-11-24 15:58:29 +03:00
|
|
|
|
return i.info
|
2020-02-06 19:38:02 +03:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
panic('Ident.var_info(): info is not IdentVar variant')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 04:13:10 +03:00
|
|
|
|
// left op right
|
|
|
|
|
// See: token.Kind.is_infix
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-01-22 23:34:38 +03:00
|
|
|
|
pub struct InfixExpr {
|
2019-12-22 04:34:37 +03:00
|
|
|
|
pub:
|
2021-03-12 18:09:01 +03:00
|
|
|
|
op token.Kind
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-03-12 18:09:01 +03:00
|
|
|
|
is_stmt bool
|
2020-10-21 22:58:40 +03:00
|
|
|
|
pub mut:
|
2023-01-29 22:06:05 +03:00
|
|
|
|
left Expr
|
|
|
|
|
right Expr
|
|
|
|
|
left_type Type
|
|
|
|
|
right_type Type
|
|
|
|
|
promoted_type Type = void_type
|
|
|
|
|
auto_locked string
|
|
|
|
|
or_block OrExpr
|
2023-04-15 14:29:15 +03:00
|
|
|
|
|
2021-11-29 03:48:49 +03:00
|
|
|
|
ct_left_value_evaled bool
|
|
|
|
|
ct_left_value ComptTimeConstValue = empty_comptime_const_expr()
|
|
|
|
|
ct_right_value_evaled bool
|
|
|
|
|
ct_right_value ComptTimeConstValue = empty_comptime_const_expr()
|
2023-04-15 14:29:15 +03:00
|
|
|
|
|
2023-03-12 02:07:13 +03:00
|
|
|
|
before_op_comments []Comment
|
|
|
|
|
after_op_comments []Comment
|
2019-12-22 04:34:37 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 04:13:10 +03:00
|
|
|
|
// ++, --
|
2020-01-06 18:13:12 +03:00
|
|
|
|
pub struct PostfixExpr {
|
|
|
|
|
pub:
|
2022-06-18 13:30:33 +03:00
|
|
|
|
op token.Kind
|
|
|
|
|
pos token.Pos
|
|
|
|
|
is_c2v_prefix bool // for `--x` (`x--$`), only for translated code until c2v can handle it
|
2020-07-13 15:01:32 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
expr Expr
|
2023-03-01 00:58:53 +03:00
|
|
|
|
typ Type
|
2020-07-14 19:52:28 +03:00
|
|
|
|
auto_locked string
|
2020-01-06 18:13:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-29 04:13:10 +03:00
|
|
|
|
// See: token.Kind.is_prefix
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-01-06 18:13:12 +03:00
|
|
|
|
pub struct PrefixExpr {
|
|
|
|
|
pub:
|
2021-03-03 11:10:38 +03:00
|
|
|
|
op token.Kind
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-08-18 00:35:36 +03:00
|
|
|
|
pub mut:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
right_type Type
|
2021-03-03 11:10:38 +03:00
|
|
|
|
right Expr
|
2020-08-23 03:12:05 +03:00
|
|
|
|
or_block OrExpr
|
2021-03-03 11:10:38 +03:00
|
|
|
|
is_option bool // IfGuard
|
2020-01-06 18:13:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-01-07 14:14:10 +03:00
|
|
|
|
pub struct IndexExpr {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
index Expr // [0], RangeExpr [start..end] or map[key]
|
|
|
|
|
or_expr OrExpr
|
2021-02-16 16:08:01 +03:00
|
|
|
|
left Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
left_type Type // array, map, fixed array
|
2020-04-09 16:33:46 +03:00
|
|
|
|
is_setter bool
|
2021-02-16 16:08:01 +03:00
|
|
|
|
is_map bool
|
|
|
|
|
is_array bool
|
|
|
|
|
is_farray bool
|
2021-03-03 11:10:38 +03:00
|
|
|
|
is_option bool // IfGuard
|
2021-12-11 22:55:46 +03:00
|
|
|
|
is_direct bool // Set if the underlying memory can be safely accessed
|
2021-12-22 16:34:02 +03:00
|
|
|
|
is_gated bool // #[] gated array
|
2020-01-07 14:14:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-28 21:16:04 +03:00
|
|
|
|
pub struct IfExpr {
|
2019-12-29 10:51:55 +03:00
|
|
|
|
pub:
|
2020-09-18 01:58:54 +03:00
|
|
|
|
is_comptime bool
|
2020-07-20 17:48:33 +03:00
|
|
|
|
tok_kind token.Kind
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-07-20 17:48:33 +03:00
|
|
|
|
post_comments []Comment
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
left Expr // `a` in `a := if ...`
|
2021-01-12 06:38:43 +03:00
|
|
|
|
branches []IfBranch // includes all `else if` branches
|
|
|
|
|
is_expr bool
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2021-01-12 06:38:43 +03:00
|
|
|
|
has_else bool
|
2021-05-11 09:30:01 +03:00
|
|
|
|
// implements bool // comptime $if implements interface
|
2020-03-20 16:39:56 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct IfBranch {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
body_pos token.Pos
|
2021-01-12 06:38:43 +03:00
|
|
|
|
comments []Comment
|
2020-07-08 16:17:28 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
cond Expr
|
2021-07-09 18:17:04 +03:00
|
|
|
|
pkg_exist bool
|
|
|
|
|
stmts []Stmt
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2020-02-03 09:02:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-12 13:58:33 +03:00
|
|
|
|
pub struct UnsafeExpr {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2022-01-20 09:40:16 +03:00
|
|
|
|
pub mut:
|
2020-09-22 06:28:29 +03:00
|
|
|
|
expr Expr
|
2020-07-12 13:58:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-04 13:44:25 +03:00
|
|
|
|
pub struct LockExpr {
|
|
|
|
|
pub:
|
2021-02-03 17:16:52 +03:00
|
|
|
|
is_rlock []bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-07-04 13:44:25 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
stmts []Stmt
|
2021-05-15 04:34:27 +03:00
|
|
|
|
lockeds []Expr // `x`, `y.z` in `lock x, y.z {`
|
|
|
|
|
comments []Comment
|
|
|
|
|
is_expr bool
|
|
|
|
|
typ Type
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2020-07-04 13:44:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-05 12:00:11 +03:00
|
|
|
|
pub struct MatchExpr {
|
|
|
|
|
pub:
|
2021-01-12 06:38:43 +03:00
|
|
|
|
tok_kind token.Kind
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-01-30 13:57:57 +03:00
|
|
|
|
comments []Comment // comments before the first branch
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
cond Expr
|
|
|
|
|
branches []MatchBranch
|
2020-11-25 14:09:40 +03:00
|
|
|
|
is_expr bool // returns a value
|
2021-04-02 01:57:09 +03:00
|
|
|
|
return_type Type
|
|
|
|
|
cond_type Type // type of `x` in `match x {`
|
|
|
|
|
expected_type Type // for debugging only
|
2020-11-25 14:09:40 +03:00
|
|
|
|
is_sum_type bool
|
2020-02-05 12:00:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-04 13:59:45 +03:00
|
|
|
|
pub struct MatchBranch {
|
|
|
|
|
pub:
|
2020-11-11 23:53:21 +03:00
|
|
|
|
ecmnts [][]Comment // inline comments for each left side expr
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-07-03 16:10:39 +03:00
|
|
|
|
is_else bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
post_comments []Comment // comments below ´... }´
|
|
|
|
|
branch_pos token.Pos // for checker errors about invalid branches
|
2020-12-12 11:01:12 +03:00
|
|
|
|
pub mut:
|
2021-10-14 02:15:52 +03:00
|
|
|
|
stmts []Stmt // right side
|
2021-06-21 07:10:10 +03:00
|
|
|
|
exprs []Expr // left side
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2020-03-04 13:59:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-16 16:34:57 +03:00
|
|
|
|
pub struct SelectExpr {
|
|
|
|
|
pub:
|
|
|
|
|
branches []SelectBranch
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-09-19 03:14:35 +03:00
|
|
|
|
has_exception bool
|
2020-09-16 16:34:57 +03:00
|
|
|
|
pub mut:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
is_expr bool // returns a value
|
|
|
|
|
expected_type Type // for debugging only
|
2020-09-16 16:34:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-09-16 16:34:57 +03:00
|
|
|
|
pub struct SelectBranch {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-09-16 16:34:57 +03:00
|
|
|
|
comment Comment // comment above `select {`
|
|
|
|
|
is_else bool
|
|
|
|
|
is_timeout bool
|
|
|
|
|
post_comments []Comment
|
2022-01-20 09:40:16 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
stmt Stmt // `a := <-ch` or `ch <- a`
|
|
|
|
|
stmts []Stmt // right side
|
2020-09-16 16:34:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 09:29:43 +03:00
|
|
|
|
pub enum ComptimeForKind {
|
2020-07-25 01:02:44 +03:00
|
|
|
|
methods
|
|
|
|
|
fields
|
2021-04-25 18:29:26 +03:00
|
|
|
|
attributes
|
2023-03-12 13:46:54 +03:00
|
|
|
|
values
|
2020-07-25 01:02:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 09:29:43 +03:00
|
|
|
|
pub struct ComptimeFor {
|
2020-07-03 16:10:39 +03:00
|
|
|
|
pub:
|
|
|
|
|
val_var string
|
2021-11-17 09:29:43 +03:00
|
|
|
|
kind ComptimeForKind
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
typ_pos token.Pos
|
2020-07-03 16:10:39 +03:00
|
|
|
|
pub mut:
|
2023-07-03 23:10:00 +03:00
|
|
|
|
stmts []Stmt
|
|
|
|
|
typ Type
|
2020-07-03 16:10:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 08:16:59 +03:00
|
|
|
|
pub struct ForStmt {
|
|
|
|
|
pub:
|
2022-10-03 10:45:11 +03:00
|
|
|
|
is_inf bool // `for {}`
|
|
|
|
|
pos token.Pos
|
|
|
|
|
comments []Comment
|
2020-11-20 14:23:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
cond Expr
|
|
|
|
|
stmts []Stmt
|
2021-01-12 06:38:43 +03:00
|
|
|
|
label string // `label: for {`
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2020-01-07 02:14:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-01-07 02:14:19 +03:00
|
|
|
|
pub struct ForInStmt {
|
|
|
|
|
pub:
|
2020-10-14 14:23:58 +03:00
|
|
|
|
key_var string
|
|
|
|
|
val_var string
|
|
|
|
|
is_range bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2022-10-03 10:45:11 +03:00
|
|
|
|
comments []Comment
|
2020-10-13 17:27:24 +03:00
|
|
|
|
val_is_mut bool // `for mut val in vals {` means that modifying `val` will modify the array
|
2020-10-14 14:23:58 +03:00
|
|
|
|
// and the array cannot be indexed inside the loop
|
2020-10-15 23:12:59 +03:00
|
|
|
|
pub mut:
|
2022-09-08 13:36:40 +03:00
|
|
|
|
val_is_ref bool // `for val in &arr {` means that value of `val` will be the reference of the value in `arr`
|
|
|
|
|
cond Expr
|
|
|
|
|
key_type Type
|
|
|
|
|
val_type Type
|
|
|
|
|
cond_type Type
|
2023-07-05 17:02:22 +03:00
|
|
|
|
high Expr // `10` in `for i in 0..10 {`
|
2022-09-08 13:36:40 +03:00
|
|
|
|
high_type Type
|
|
|
|
|
kind Kind // array/map/string
|
|
|
|
|
label string // `label: for {`
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2023-07-03 23:10:00 +03:00
|
|
|
|
stmts []Stmt
|
2020-01-07 02:14:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ForCStmt {
|
|
|
|
|
pub:
|
2020-03-11 04:44:30 +03:00
|
|
|
|
has_init bool
|
2020-04-10 10:00:14 +03:00
|
|
|
|
has_cond bool
|
|
|
|
|
has_inc bool
|
2021-02-24 15:58:45 +03:00
|
|
|
|
is_multi bool // for a,b := 0,1; a < 10; a,b = a+b, a {...}
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2022-10-03 10:45:11 +03:00
|
|
|
|
comments []Comment
|
2020-11-20 14:23:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
init Stmt // i := 0;
|
|
|
|
|
cond Expr // i < 10;
|
|
|
|
|
inc Stmt // i++; i += 2
|
|
|
|
|
stmts []Stmt
|
2021-01-12 06:38:43 +03:00
|
|
|
|
label string // `label: for {`
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2019-12-30 08:16:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-23 15:30:51 +03:00
|
|
|
|
// #include, #define etc
|
2020-02-04 11:54:15 +03:00
|
|
|
|
pub struct HashStmt {
|
|
|
|
|
pub:
|
2021-01-23 12:39:12 +03:00
|
|
|
|
mod string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-01-23 12:39:12 +03:00
|
|
|
|
source_file string
|
2020-08-28 09:24:04 +03:00
|
|
|
|
pub mut:
|
2021-07-23 15:30:51 +03:00
|
|
|
|
val string // example: 'include <openssl/rand.h> # please install openssl // comment'
|
|
|
|
|
kind string // : 'include'
|
|
|
|
|
main string // : '<openssl/rand.h>'
|
|
|
|
|
msg string // : 'please install openssl'
|
|
|
|
|
ct_conds []Expr // *all* comptime conditions, that must be true, for the hash to be processed
|
|
|
|
|
// ct_conds is filled by the checker, based on the current nesting of `$if cond1 {}` blocks
|
2020-02-04 11:54:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 06:54:51 +03:00
|
|
|
|
/*
|
|
|
|
|
// filter(), map(), sort()
|
2020-02-10 16:42:57 +03:00
|
|
|
|
pub struct Lambda {
|
|
|
|
|
pub:
|
|
|
|
|
name string
|
|
|
|
|
}
|
2020-08-12 06:54:51 +03:00
|
|
|
|
*/
|
2023-04-15 14:29:15 +03:00
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// variable assign statement
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-28 21:16:04 +03:00
|
|
|
|
pub struct AssignStmt {
|
|
|
|
|
pub:
|
2021-01-12 06:38:43 +03:00
|
|
|
|
op token.Kind // include: =,:=,+=,-=,*=,/= and so on; for a list of all the assign operators, see vlib/token/token.v
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-01-12 06:38:43 +03:00
|
|
|
|
comments []Comment
|
|
|
|
|
end_comments []Comment
|
2020-04-27 23:53:26 +03:00
|
|
|
|
pub mut:
|
2021-01-30 13:55:10 +03:00
|
|
|
|
right []Expr
|
2020-06-16 14:20:16 +03:00
|
|
|
|
left []Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
left_types []Type
|
|
|
|
|
right_types []Type
|
2020-05-27 04:20:22 +03:00
|
|
|
|
is_static bool // for translated code only
|
2021-09-22 13:06:30 +03:00
|
|
|
|
is_volatile bool // for disabling variable access optimisations (needed for hardware drivers)
|
2020-06-16 14:20:16 +03:00
|
|
|
|
is_simple bool // `x+=2` in `for x:=1; ; x+=2`
|
2020-05-26 19:00:51 +03:00
|
|
|
|
has_cross_var bool
|
2019-12-28 21:16:04 +03:00
|
|
|
|
}
|
2020-02-06 19:38:02 +03:00
|
|
|
|
|
2021-06-19 17:07:07 +03:00
|
|
|
|
// `expr as Ident`
|
2020-03-02 21:00:33 +03:00
|
|
|
|
pub struct AsCast {
|
|
|
|
|
pub:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
typ Type // to type
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
expr Expr // from expr: `expr` in `expr as Ident`
|
2021-06-19 17:07:07 +03:00
|
|
|
|
expr_type Type // from type
|
2020-03-02 21:00:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 05:52:32 +03:00
|
|
|
|
// An enum value, like OS.macos or .macos
|
2020-02-11 01:19:50 +03:00
|
|
|
|
pub struct EnumVal {
|
2020-02-10 22:33:34 +03:00
|
|
|
|
pub:
|
2020-02-25 17:02:34 +03:00
|
|
|
|
enum_name string
|
|
|
|
|
val string
|
2020-03-15 02:46:08 +03:00
|
|
|
|
mod string // for full path `mod_Enum_val`
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2020-02-11 01:19:50 +03:00
|
|
|
|
}
|
2020-02-10 22:33:34 +03:00
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// enum field in enum declaration
|
2020-04-09 20:23:49 +03:00
|
|
|
|
pub struct EnumField {
|
2020-05-18 19:06:09 +03:00
|
|
|
|
pub:
|
2020-12-25 22:41:59 +03:00
|
|
|
|
name string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-12-28 14:52:04 +03:00
|
|
|
|
comments []Comment // comment after Enumfield in the same line
|
|
|
|
|
next_comments []Comment // comments between current EnumField and next EnumField
|
2021-01-03 23:10:25 +03:00
|
|
|
|
has_expr bool // true, when .expr has a value
|
2023-05-13 02:08:30 +03:00
|
|
|
|
attrs []Attr
|
2021-12-03 07:45:37 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
expr Expr // the value of current EnumField; 123 in `ename = 123`
|
2020-04-09 20:23:49 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:52:04 +03:00
|
|
|
|
// enum declaration
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-11 01:19:50 +03:00
|
|
|
|
pub struct EnumDecl {
|
|
|
|
|
pub:
|
2020-07-10 17:43:02 +03:00
|
|
|
|
name string
|
|
|
|
|
is_pub bool
|
2021-04-02 01:57:09 +03:00
|
|
|
|
is_flag bool // true when the enum has [flag] tag,for bit field enum
|
|
|
|
|
is_multi_allowed bool // true when the enum has [_allow_multiple_values] tag
|
|
|
|
|
comments []Comment // comments before the first EnumField
|
|
|
|
|
fields []EnumField // all the enum fields
|
|
|
|
|
attrs []Attr // attributes of enum declaration
|
2022-10-29 06:32:20 +03:00
|
|
|
|
typ Type // the default is `int`; can be changed by `enum Big as u64 { a = 5 }`
|
2023-01-25 22:59:28 +03:00
|
|
|
|
typ_pos token.Pos
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-02-11 01:19:50 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-07 19:37:55 +03:00
|
|
|
|
pub struct AliasTypeDecl {
|
|
|
|
|
pub:
|
2020-03-08 00:37:03 +03:00
|
|
|
|
name string
|
|
|
|
|
is_pub bool
|
2023-01-18 02:34:43 +03:00
|
|
|
|
typ Type
|
2021-04-02 01:57:09 +03:00
|
|
|
|
parent_type Type
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
type_pos token.Pos
|
2020-11-20 12:51:50 +03:00
|
|
|
|
comments []Comment
|
2020-03-07 19:37:55 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 18:26:40 +03:00
|
|
|
|
// SumTypeDecl is the ast node for `type MySumType = string | int`
|
2020-11-25 14:09:40 +03:00
|
|
|
|
pub struct SumTypeDecl {
|
2020-11-11 11:18:15 +03:00
|
|
|
|
pub:
|
2021-07-15 08:29:13 +03:00
|
|
|
|
name string
|
|
|
|
|
is_pub bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2022-05-12 11:57:57 +03:00
|
|
|
|
name_pos token.Pos
|
2021-07-15 08:29:13 +03:00
|
|
|
|
typ Type
|
|
|
|
|
generic_types []Type
|
2022-01-08 17:35:10 +03:00
|
|
|
|
attrs []Attr // attributes of type declaration
|
2020-11-11 11:18:15 +03:00
|
|
|
|
pub mut:
|
2021-04-29 09:04:02 +03:00
|
|
|
|
variants []TypeNode
|
2020-11-11 11:18:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-11 18:10:46 +03:00
|
|
|
|
pub struct FnTypeDecl {
|
|
|
|
|
pub:
|
2023-03-30 14:30:10 +03:00
|
|
|
|
name string
|
|
|
|
|
is_pub bool
|
|
|
|
|
typ Type
|
|
|
|
|
pos token.Pos
|
|
|
|
|
type_pos token.Pos
|
|
|
|
|
comments []Comment
|
|
|
|
|
generic_types []Type
|
|
|
|
|
attrs []Attr // attributes of type declaration
|
2020-03-11 18:10:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 16:33:46 +03:00
|
|
|
|
// TODO: handle this differently
|
|
|
|
|
// v1 excludes non current os ifdefs so
|
|
|
|
|
// the defer's never get added in the first place
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-18 00:50:04 +03:00
|
|
|
|
pub struct DeferStmt {
|
2020-02-11 12:26:46 +03:00
|
|
|
|
pub:
|
2023-07-03 23:10:00 +03:00
|
|
|
|
pos token.Pos
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2023-07-03 23:10:00 +03:00
|
|
|
|
stmts []Stmt
|
2021-05-31 14:43:44 +03:00
|
|
|
|
defer_vars []Ident
|
|
|
|
|
ifdef string
|
|
|
|
|
idx_in_fn int = -1 // index in FnDecl.defer_stmts
|
2020-02-11 12:26:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 16:41:19 +03:00
|
|
|
|
// `(3+4)`
|
|
|
|
|
pub struct ParExpr {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2022-01-20 09:40:16 +03:00
|
|
|
|
pub mut:
|
2020-02-28 16:41:19 +03:00
|
|
|
|
expr Expr
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2021-01-15 15:45:26 +03:00
|
|
|
|
pub struct GoExpr {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-01-15 15:45:26 +03:00
|
|
|
|
pub mut:
|
2021-04-12 00:56:25 +03:00
|
|
|
|
call_expr CallExpr
|
|
|
|
|
is_expr bool
|
2020-03-16 10:33:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-28 00:33:46 +03:00
|
|
|
|
[minify]
|
|
|
|
|
pub struct SpawnExpr {
|
|
|
|
|
pub:
|
|
|
|
|
pos token.Pos
|
|
|
|
|
pub mut:
|
|
|
|
|
call_expr CallExpr
|
|
|
|
|
is_expr bool
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 00:50:04 +03:00
|
|
|
|
pub struct GotoLabel {
|
2020-02-17 16:15:42 +03:00
|
|
|
|
pub:
|
2020-02-18 00:50:04 +03:00
|
|
|
|
name string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2022-10-22 19:26:38 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
is_used bool
|
2020-02-17 16:15:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct GotoStmt {
|
|
|
|
|
pub:
|
2020-02-18 00:50:04 +03:00
|
|
|
|
name string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-02-17 16:15:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2019-12-30 11:38:12 +03:00
|
|
|
|
pub struct ArrayInit {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos // `[]` in []Type{} position
|
|
|
|
|
elem_type_pos token.Pos // `Type` in []Type{} position
|
|
|
|
|
ecmnts [][]Comment // optional iembed comments after each expr
|
2021-02-21 21:18:19 +03:00
|
|
|
|
pre_cmnts []Comment
|
2021-01-12 06:38:43 +03:00
|
|
|
|
is_fixed bool
|
2021-01-14 05:51:13 +03:00
|
|
|
|
has_val bool // fixed size literal `[expr, expr]!`
|
2021-01-12 06:38:43 +03:00
|
|
|
|
mod string
|
|
|
|
|
has_len bool
|
|
|
|
|
has_cap bool
|
|
|
|
|
has_default bool
|
2023-03-08 22:51:45 +03:00
|
|
|
|
has_index bool // true if temp variable index is used
|
2020-12-01 13:20:27 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
exprs []Expr // `[expr, expr]` or `[expr]Type{}` for fixed array
|
|
|
|
|
len_expr Expr // len: expr
|
|
|
|
|
cap_expr Expr // cap: expr
|
|
|
|
|
default_expr Expr // init: expr
|
2022-01-15 10:59:38 +03:00
|
|
|
|
expr_types []Type // [Dog, Cat] // also used for interface_types
|
|
|
|
|
elem_type Type // element type
|
|
|
|
|
default_type Type // default value type
|
|
|
|
|
typ Type // array type
|
2019-12-30 11:38:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 18:14:08 +03:00
|
|
|
|
pub struct ArrayDecompose {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-12-29 18:14:08 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
expr Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
expr_type Type
|
|
|
|
|
arg_type Type
|
2020-12-29 18:14:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 22:18:42 +03:00
|
|
|
|
pub struct ChanInit {
|
|
|
|
|
pub:
|
2022-06-28 08:30:02 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
elem_type_pos token.Pos
|
|
|
|
|
has_cap bool
|
2020-08-14 22:18:42 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
cap_expr Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
|
|
|
|
elem_type Type
|
2020-08-14 22:18:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-22 16:13:19 +03:00
|
|
|
|
pub struct MapInit {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-02-22 14:04:48 +03:00
|
|
|
|
comments [][]Comment // comments after key-value pairs
|
|
|
|
|
pre_cmnts []Comment // comments before the first key-value pair
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
keys []Expr
|
|
|
|
|
vals []Expr
|
2022-01-27 10:44:34 +03:00
|
|
|
|
val_types []Type
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
|
|
|
|
key_type Type
|
|
|
|
|
value_type Type
|
2020-02-22 16:13:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 16:31:54 +03:00
|
|
|
|
// s[10..20]
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-02 16:31:54 +03:00
|
|
|
|
pub struct RangeExpr {
|
|
|
|
|
pub:
|
2020-03-07 00:24:39 +03:00
|
|
|
|
has_high bool
|
|
|
|
|
has_low bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-12-22 16:34:02 +03:00
|
|
|
|
is_gated bool // #[] gated array
|
2022-01-20 09:40:16 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
low Expr
|
|
|
|
|
high Expr
|
2022-11-26 09:56:00 +03:00
|
|
|
|
typ Type // filled in by checker; the type of `0...1` is `int` for example, while `a`...`z` is `rune` etc
|
2020-02-02 16:31:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-10 16:43:17 +03:00
|
|
|
|
pub struct CastExpr {
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
arg Expr // `n` in `string(buf, n)`
|
2021-07-18 19:41:39 +03:00
|
|
|
|
typ Type // `string`
|
|
|
|
|
expr Expr // `buf` in `string(buf, n)` and `&Type(buf)`
|
|
|
|
|
typname string // `&Type` in `&Type(buf)`
|
|
|
|
|
expr_type Type // `byteptr`, the type of the `buf` expression
|
|
|
|
|
has_arg bool // true for `string(buf, n)`, false for `&Type(buf)`
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-02-10 16:43:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2021-03-17 03:43:17 +03:00
|
|
|
|
pub struct AsmStmt {
|
|
|
|
|
pub:
|
2021-06-23 14:20:07 +03:00
|
|
|
|
arch pref.Arch
|
|
|
|
|
is_basic bool
|
|
|
|
|
is_volatile bool
|
|
|
|
|
is_goto bool
|
|
|
|
|
clobbered []AsmClobbered
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-03-17 03:43:17 +03:00
|
|
|
|
pub mut:
|
2021-04-01 09:58:33 +03:00
|
|
|
|
templates []AsmTemplate
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2021-04-01 09:58:33 +03:00
|
|
|
|
output []AsmIO
|
|
|
|
|
input []AsmIO
|
|
|
|
|
global_labels []string // labels defined in assembly block, exported with `.globl`
|
|
|
|
|
local_labels []string // local to the assembly block
|
2021-03-17 03:43:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2021-03-17 03:43:17 +03:00
|
|
|
|
pub struct AsmTemplate {
|
|
|
|
|
pub mut:
|
|
|
|
|
name string
|
|
|
|
|
is_label bool // `example_label:`
|
|
|
|
|
is_directive bool // .globl assembly_function
|
|
|
|
|
args []AsmArg
|
|
|
|
|
comments []Comment
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-03-17 03:43:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 09:58:33 +03:00
|
|
|
|
// [eax+5] | j | displacement literal (e.g. 123 in [rax + 123] ) | eax | true | `a` | 0.594 | 123 | label_name
|
2021-09-10 20:56:55 +03:00
|
|
|
|
pub type AsmArg = AsmAddressing
|
|
|
|
|
| AsmAlias
|
|
|
|
|
| AsmDisp
|
|
|
|
|
| AsmRegister
|
|
|
|
|
| BoolLiteral
|
|
|
|
|
| CharLiteral
|
|
|
|
|
| FloatLiteral
|
|
|
|
|
| IntegerLiteral
|
|
|
|
|
| string
|
2021-03-17 03:43:17 +03:00
|
|
|
|
|
|
|
|
|
pub struct AsmRegister {
|
2021-04-15 02:30:23 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
name string // eax or r12d etc.
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2021-03-17 03:43:17 +03:00
|
|
|
|
size int
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 09:58:33 +03:00
|
|
|
|
pub struct AsmDisp {
|
|
|
|
|
pub:
|
|
|
|
|
val string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-04-01 09:58:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 03:43:17 +03:00
|
|
|
|
pub struct AsmAlias {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-04-15 02:30:23 +03:00
|
|
|
|
pub mut:
|
2021-03-17 03:43:17 +03:00
|
|
|
|
name string // a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct AsmAddressing {
|
|
|
|
|
pub:
|
2021-04-02 17:26:37 +03:00
|
|
|
|
scale int = -1 // 1, 2, 4, or 8 literal
|
2021-04-01 09:58:33 +03:00
|
|
|
|
mode AddressingMode
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-03-17 03:43:17 +03:00
|
|
|
|
pub mut:
|
2021-10-05 18:57:15 +03:00
|
|
|
|
segment string // fs:
|
2021-04-01 09:58:33 +03:00
|
|
|
|
displacement AsmArg // 8, 16 or 32 bit literal value
|
|
|
|
|
base AsmArg // gpr
|
|
|
|
|
index AsmArg // gpr
|
2021-03-17 03:43:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-18 22:36:17 +03:00
|
|
|
|
// addressing modes:
|
2021-03-17 03:43:17 +03:00
|
|
|
|
pub enum AddressingMode {
|
|
|
|
|
invalid
|
|
|
|
|
displacement // displacement
|
|
|
|
|
base // base
|
|
|
|
|
base_plus_displacement // base + displacement
|
|
|
|
|
index_times_scale_plus_displacement // (index ∗ scale) + displacement
|
|
|
|
|
base_plus_index_plus_displacement // base + (index ∗ scale) + displacement
|
|
|
|
|
base_plus_index_times_scale_plus_displacement // base + index + displacement
|
|
|
|
|
rip_plus_displacement // rip + displacement
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct AsmClobbered {
|
|
|
|
|
pub mut:
|
2021-04-01 09:58:33 +03:00
|
|
|
|
reg AsmRegister
|
2021-03-17 03:43:17 +03:00
|
|
|
|
comments []Comment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// : [alias_a] '=r' (a) // this is a comment
|
|
|
|
|
pub struct AsmIO {
|
|
|
|
|
pub:
|
|
|
|
|
alias string // [alias_a]
|
2021-05-14 12:01:15 +03:00
|
|
|
|
constraint string // '=r' TODO: allow all backends to easily use this with a struct
|
2021-03-17 03:43:17 +03:00
|
|
|
|
comments []Comment // // this is a comment
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2023-07-05 17:02:22 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
expr Expr // (a)
|
2021-03-17 03:43:17 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const (
|
|
|
|
|
// reference: https://en.wikipedia.org/wiki/X86#/media/File:Table_of_x86_Registers_svg.svg
|
|
|
|
|
// map register size -> register name
|
2021-08-04 12:44:41 +03:00
|
|
|
|
x86_no_number_register_list = {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
8: ['al', 'ah', 'bl', 'bh', 'cl', 'ch', 'dl', 'dh', 'bpl', 'sil', 'dil', 'spl']
|
|
|
|
|
16: ['ax', 'bx', 'cx', 'dx', 'bp', 'si', 'di', 'sp', /* segment registers */ 'cs', 'ss',
|
|
|
|
|
'ds', 'es', 'fs', 'gs', 'flags', 'ip', /* task registers */ 'gdtr', 'idtr', 'tr', 'ldtr',
|
|
|
|
|
// CSR register 'msw', /* FP core registers */ 'cw', 'sw', 'tw', 'fp_ip', 'fp_dp',
|
|
|
|
|
'fp_cs', 'fp_ds', 'fp_opc']
|
|
|
|
|
32: [
|
|
|
|
|
'eax',
|
|
|
|
|
'ebx',
|
|
|
|
|
'ecx',
|
|
|
|
|
'edx',
|
|
|
|
|
'ebp',
|
|
|
|
|
'esi',
|
|
|
|
|
'edi',
|
|
|
|
|
'esp',
|
|
|
|
|
'eflags',
|
|
|
|
|
'eip', /* CSR register */
|
|
|
|
|
'mxcsr' /* 32-bit FP core registers 'fp_dp', 'fp_ip' (TODO: why are there duplicates?) */,
|
|
|
|
|
]
|
|
|
|
|
64: ['rax', 'rbx', 'rcx', 'rdx', 'rbp', 'rsi', 'rdi', 'rsp', 'rflags', 'rip']
|
|
|
|
|
}
|
|
|
|
|
// no comments because maps do not support comments
|
|
|
|
|
// r#*: gp registers added in 64-bit extensions, can only be from 8-15 actually
|
2023-06-18 22:36:17 +03:00
|
|
|
|
// *mm#: vector/simd registers
|
2021-03-17 03:43:17 +03:00
|
|
|
|
// st#: floating point numbers
|
|
|
|
|
// cr#: control/status registers
|
|
|
|
|
// dr#: debug registers
|
2021-08-04 12:44:41 +03:00
|
|
|
|
x86_with_number_register_list = {
|
|
|
|
|
8: {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'r#b': 16
|
|
|
|
|
}
|
2021-08-04 12:44:41 +03:00
|
|
|
|
16: {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'r#w': 16
|
|
|
|
|
}
|
2021-08-04 12:44:41 +03:00
|
|
|
|
32: {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'r#d': 16
|
|
|
|
|
}
|
2021-08-04 12:44:41 +03:00
|
|
|
|
64: {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'r#': 16
|
|
|
|
|
'mm#': 16
|
|
|
|
|
'cr#': 16
|
|
|
|
|
'dr#': 16
|
|
|
|
|
}
|
2021-08-04 12:44:41 +03:00
|
|
|
|
80: {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'st#': 16
|
|
|
|
|
}
|
2021-08-04 12:44:41 +03:00
|
|
|
|
128: {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'xmm#': 32
|
|
|
|
|
}
|
2021-08-04 12:44:41 +03:00
|
|
|
|
256: {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'ymm#': 32
|
|
|
|
|
}
|
2021-08-04 12:44:41 +03:00
|
|
|
|
512: {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'zmm#': 32
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TODO: saved priviled registers for arm
|
2021-04-01 09:58:33 +03:00
|
|
|
|
pub const (
|
2021-03-17 03:43:17 +03:00
|
|
|
|
arm_no_number_register_list = ['fp' /* aka r11 */, /* not instruction pointer: */ 'ip' /* aka r12 */,
|
|
|
|
|
'sp' /* aka r13 */, 'lr' /* aka r14 */, /* this is instruction pointer ('program counter'): */
|
|
|
|
|
'pc' /* aka r15 */,
|
|
|
|
|
] // 'cpsr' and 'apsr' are special flags registers, but cannot be referred to directly
|
2021-08-04 12:44:41 +03:00
|
|
|
|
arm_with_number_register_list = {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'r#': 16
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2021-04-01 09:58:33 +03:00
|
|
|
|
pub const (
|
2021-03-17 03:43:17 +03:00
|
|
|
|
riscv_no_number_register_list = ['zero', 'ra', 'sp', 'gp', 'tp']
|
2021-08-04 12:44:41 +03:00
|
|
|
|
riscv_with_number_register_list = {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
'x#': 32
|
|
|
|
|
't#': 3
|
|
|
|
|
's#': 12
|
|
|
|
|
'a#': 8
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2023-02-06 17:39:03 +03:00
|
|
|
|
// `assert a == 0, 'a is zero'`
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-26 17:51:05 +03:00
|
|
|
|
pub struct AssertStmt {
|
|
|
|
|
pub:
|
2022-08-03 01:14:01 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
extra_pos token.Pos
|
2020-10-21 22:58:40 +03:00
|
|
|
|
pub mut:
|
2023-02-06 17:39:03 +03:00
|
|
|
|
expr Expr // `a == 0`
|
|
|
|
|
extra Expr // `'a is zero'`
|
2021-04-13 13:07:57 +03:00
|
|
|
|
is_used bool // asserts are used in _test.v files, as well as in non -prod builds of all files
|
2020-02-26 17:51:05 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 15:36:33 +03:00
|
|
|
|
pub struct IfGuardVar {
|
|
|
|
|
pub mut:
|
|
|
|
|
name string
|
|
|
|
|
is_mut bool
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2022-01-25 15:36:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// `if x := opt() {`
|
2020-02-28 17:36:41 +03:00
|
|
|
|
pub struct IfGuardExpr {
|
2020-02-27 20:02:40 +03:00
|
|
|
|
pub:
|
2022-01-25 15:36:33 +03:00
|
|
|
|
vars []IfGuardVar
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2023-02-06 17:39:03 +03:00
|
|
|
|
expr Expr // `opt()`
|
|
|
|
|
expr_type Type // type of `opt()`
|
2020-02-27 20:02:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 09:51:15 +03:00
|
|
|
|
pub enum OrKind {
|
|
|
|
|
absent
|
|
|
|
|
block
|
2022-04-30 01:59:14 +03:00
|
|
|
|
propagate_option
|
|
|
|
|
propagate_result
|
2020-05-23 09:51:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 17:36:41 +03:00
|
|
|
|
// `or { ... }`
|
|
|
|
|
pub struct OrExpr {
|
|
|
|
|
pub:
|
2023-07-03 23:10:00 +03:00
|
|
|
|
kind OrKind
|
|
|
|
|
pos token.Pos
|
|
|
|
|
pub mut:
|
2020-05-23 09:51:15 +03:00
|
|
|
|
stmts []Stmt
|
2020-02-28 17:36:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 04:00:20 +03:00
|
|
|
|
/*
|
2020-09-12 17:40:52 +03:00
|
|
|
|
// `or { ... }`
|
|
|
|
|
pub struct OrExpr2 {
|
|
|
|
|
pub:
|
|
|
|
|
call_expr CallExpr
|
|
|
|
|
stmts []Stmt // inside `or { }`
|
|
|
|
|
kind OrKind
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-09-12 17:40:52 +03:00
|
|
|
|
}
|
2020-09-13 04:00:20 +03:00
|
|
|
|
*/
|
2021-02-08 18:03:05 +03:00
|
|
|
|
|
|
|
|
|
// deprecated
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-02-18 19:29:47 +03:00
|
|
|
|
pub struct Assoc {
|
|
|
|
|
pub:
|
2020-03-01 15:07:51 +03:00
|
|
|
|
var_name string
|
|
|
|
|
fields []string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
exprs []Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
typ Type
|
2022-09-15 07:59:31 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2020-02-18 19:29:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 20:13:34 +03:00
|
|
|
|
pub struct SizeOf {
|
|
|
|
|
pub:
|
2022-12-15 20:21:52 +03:00
|
|
|
|
guessed_type bool // a legacy `sizeof( GuessedType )` => a deprecation notice, suggesting `v fmt -w .` => `sizeof[ Type ]()`
|
|
|
|
|
is_type bool
|
|
|
|
|
pos token.Pos
|
2021-01-13 08:13:39 +03:00
|
|
|
|
pub mut:
|
2022-12-15 20:21:52 +03:00
|
|
|
|
expr Expr // checker uses this to set typ, when !is_type
|
2022-01-20 09:40:16 +03:00
|
|
|
|
typ Type
|
2020-02-18 20:13:34 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-13 06:26:13 +03:00
|
|
|
|
pub struct IsRefType {
|
|
|
|
|
pub:
|
2022-12-15 20:21:52 +03:00
|
|
|
|
guessed_type bool // a legacy `isreftype( GuessedType )` => a deprecation notice, suggesting `v fmt -w .` => `isreftype[ Type ]()`
|
|
|
|
|
is_type bool
|
|
|
|
|
pos token.Pos
|
2021-06-13 06:26:13 +03:00
|
|
|
|
pub mut:
|
2022-12-15 20:21:52 +03:00
|
|
|
|
expr Expr // checker uses this to set typ, when !is_type
|
2022-01-20 09:40:16 +03:00
|
|
|
|
typ Type
|
2021-06-13 06:26:13 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2021-01-30 14:57:09 +03:00
|
|
|
|
pub struct OffsetOf {
|
|
|
|
|
pub:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
struct_type Type
|
2021-01-30 14:57:09 +03:00
|
|
|
|
field string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-01-30 14:57:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 17:36:18 +03:00
|
|
|
|
pub struct Likely {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-06-09 18:08:31 +03:00
|
|
|
|
is_likely bool // false for _unlikely_
|
2022-01-20 09:40:16 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
expr Expr
|
2020-06-09 17:36:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-03-19 14:15:39 +03:00
|
|
|
|
pub struct TypeOf {
|
|
|
|
|
pub:
|
2022-12-07 12:26:27 +03:00
|
|
|
|
is_type bool
|
|
|
|
|
pos token.Pos
|
2020-05-09 16:16:48 +03:00
|
|
|
|
pub mut:
|
2022-12-15 20:21:52 +03:00
|
|
|
|
expr Expr // checker uses this to set typ, when !is_type
|
2022-12-07 12:26:27 +03:00
|
|
|
|
typ Type
|
2020-03-19 14:15:39 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2021-03-06 20:09:28 +03:00
|
|
|
|
pub struct DumpExpr {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-03-06 20:09:28 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
expr Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
expr_type Type
|
2021-03-06 20:09:28 +03:00
|
|
|
|
cname string // filled in the checker
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-05 03:08:10 +03:00
|
|
|
|
pub struct Comment {
|
2020-02-18 22:20:15 +03:00
|
|
|
|
pub:
|
2021-06-18 15:47:26 +03:00
|
|
|
|
text string
|
|
|
|
|
is_multi bool // true only for /* comment */, that use many lines
|
|
|
|
|
is_inline bool // true for all /* comment */ comments
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-02-18 22:20:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-01 16:57:54 +03:00
|
|
|
|
pub struct ConcatExpr {
|
|
|
|
|
pub:
|
2021-01-12 06:38:43 +03:00
|
|
|
|
vals []Expr
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-05-16 00:14:53 +03:00
|
|
|
|
pub mut:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
return_type Type
|
2020-03-01 16:57:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 11:12:32 +03:00
|
|
|
|
// @FN, @STRUCT, @MOD etc. See full list in token.valid_at_tokens
|
|
|
|
|
pub struct AtExpr {
|
|
|
|
|
pub:
|
|
|
|
|
name string
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-11-05 11:12:32 +03:00
|
|
|
|
kind token.AtKind
|
|
|
|
|
pub mut:
|
2021-01-12 06:38:43 +03:00
|
|
|
|
val string
|
2020-11-05 11:12:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2021-01-05 17:11:43 +03:00
|
|
|
|
pub struct ComptimeSelector {
|
|
|
|
|
pub:
|
|
|
|
|
has_parens bool // if $() is used, for vfmt
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-01-05 17:11:43 +03:00
|
|
|
|
pub mut:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
left Expr
|
|
|
|
|
left_type Type
|
|
|
|
|
field_expr Expr
|
|
|
|
|
typ Type
|
2021-01-05 17:11:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 01:59:17 +03:00
|
|
|
|
[minify]
|
2020-05-25 06:32:33 +03:00
|
|
|
|
pub struct ComptimeCall {
|
2020-06-06 11:05:26 +03:00
|
|
|
|
pub:
|
2023-04-15 14:29:15 +03:00
|
|
|
|
pos token.Pos
|
|
|
|
|
has_parens bool // if $() is used, for vfmt
|
|
|
|
|
method_name string
|
|
|
|
|
method_pos token.Pos
|
|
|
|
|
scope &Scope = unsafe { nil }
|
|
|
|
|
is_vweb bool
|
|
|
|
|
is_embed bool
|
|
|
|
|
is_env bool
|
|
|
|
|
env_pos token.Pos
|
2021-07-09 18:17:04 +03:00
|
|
|
|
is_pkgconfig bool
|
2020-06-06 11:05:26 +03:00
|
|
|
|
pub mut:
|
2023-07-02 09:41:04 +03:00
|
|
|
|
vweb_tmpl File
|
2023-07-05 17:02:22 +03:00
|
|
|
|
left Expr
|
2021-12-12 20:42:40 +03:00
|
|
|
|
left_type Type
|
2021-04-02 01:57:09 +03:00
|
|
|
|
result_type Type
|
2021-01-31 20:22:42 +03:00
|
|
|
|
env_value string
|
2022-11-10 05:09:51 +03:00
|
|
|
|
args_var string
|
2021-03-11 16:04:34 +03:00
|
|
|
|
args []CallArg
|
2021-12-04 20:43:19 +03:00
|
|
|
|
embed_file EmbeddedFile
|
2023-07-03 23:10:00 +03:00
|
|
|
|
or_block OrExpr
|
2020-05-25 06:32:33 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 21:54:36 +03:00
|
|
|
|
pub struct None {
|
|
|
|
|
pub:
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2020-06-16 13:14:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 15:32:14 +03:00
|
|
|
|
pub enum SqlStmtKind {
|
|
|
|
|
insert
|
|
|
|
|
update
|
|
|
|
|
delete
|
2021-04-07 16:27:02 +03:00
|
|
|
|
create
|
2021-04-12 00:57:25 +03:00
|
|
|
|
drop
|
2020-06-24 15:32:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct SqlStmt {
|
2021-04-27 15:28:57 +03:00
|
|
|
|
pub:
|
2023-07-05 17:02:22 +03:00
|
|
|
|
pos token.Pos
|
2021-04-27 15:28:57 +03:00
|
|
|
|
pub mut:
|
2023-01-13 18:02:32 +03:00
|
|
|
|
lines []SqlStmtLine
|
2023-07-05 17:02:22 +03:00
|
|
|
|
db_expr Expr // `db` in `sql db {`
|
|
|
|
|
or_expr OrExpr
|
2023-01-13 18:02:32 +03:00
|
|
|
|
db_expr_type Type // the type of the `db` in `sql db {`
|
2021-04-27 15:28:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct SqlStmtLine {
|
2020-06-19 17:43:32 +03:00
|
|
|
|
pub:
|
2023-07-05 17:02:22 +03:00
|
|
|
|
kind SqlStmtKind
|
|
|
|
|
pos token.Pos
|
2023-04-04 08:23:06 +03:00
|
|
|
|
// is_generated indicates a statement is generated by ORM for complex queries with related tables.
|
|
|
|
|
is_generated bool
|
2023-01-30 12:26:10 +03:00
|
|
|
|
scope &Scope = unsafe { nil }
|
2020-06-25 15:43:07 +03:00
|
|
|
|
pub mut:
|
2021-07-23 12:33:55 +03:00
|
|
|
|
object_var_name string // `user`
|
|
|
|
|
updated_columns []string // for `update set x=y`
|
|
|
|
|
table_expr TypeNode
|
|
|
|
|
fields []StructField
|
|
|
|
|
sub_structs map[int]SqlStmtLine
|
2023-07-05 17:02:22 +03:00
|
|
|
|
where_expr Expr
|
|
|
|
|
update_exprs []Expr // for `update`
|
2020-06-19 17:43:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 13:14:22 +03:00
|
|
|
|
pub struct SqlExpr {
|
2020-06-17 01:59:33 +03:00
|
|
|
|
pub:
|
2022-01-20 09:40:16 +03:00
|
|
|
|
is_count bool
|
|
|
|
|
has_where bool
|
|
|
|
|
has_order bool
|
|
|
|
|
has_limit bool
|
|
|
|
|
has_offset bool
|
|
|
|
|
has_desc bool
|
|
|
|
|
is_array bool
|
2023-04-04 08:23:06 +03:00
|
|
|
|
// is_generated indicates a statement is generated by ORM for complex queries with related tables.
|
|
|
|
|
is_generated bool
|
|
|
|
|
pos token.Pos
|
2022-01-20 09:40:16 +03:00
|
|
|
|
pub mut:
|
2022-08-31 14:43:20 +03:00
|
|
|
|
typ Type
|
2020-06-27 17:19:12 +03:00
|
|
|
|
db_expr Expr // `db` in `sql db {`
|
2022-01-20 09:40:16 +03:00
|
|
|
|
where_expr Expr
|
2020-07-02 20:29:22 +03:00
|
|
|
|
order_expr Expr
|
2020-06-27 17:19:12 +03:00
|
|
|
|
limit_expr Expr
|
2022-01-20 09:40:16 +03:00
|
|
|
|
offset_expr Expr
|
2021-04-02 01:57:09 +03:00
|
|
|
|
table_expr TypeNode
|
|
|
|
|
fields []StructField
|
2021-02-04 22:28:33 +03:00
|
|
|
|
sub_structs map[int]SqlExpr
|
2023-07-03 23:10:00 +03:00
|
|
|
|
or_expr OrExpr
|
2020-02-19 21:54:36 +03:00
|
|
|
|
}
|
2020-03-18 10:41:49 +03:00
|
|
|
|
|
2021-03-30 10:33:29 +03:00
|
|
|
|
pub struct NodeError {
|
|
|
|
|
pub:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
idx int // index for referencing the related File error
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pos token.Pos
|
2021-03-30 10:33:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 03:19:23 +03:00
|
|
|
|
[inline]
|
2020-06-16 14:20:16 +03:00
|
|
|
|
pub fn (expr Expr) is_blank_ident() bool {
|
2022-03-16 10:30:37 +03:00
|
|
|
|
if expr is Ident {
|
|
|
|
|
return expr.kind == .blank_ident
|
2020-03-18 03:19:23 +03:00
|
|
|
|
}
|
2022-03-16 10:30:37 +03:00
|
|
|
|
return false
|
2020-03-18 03:19:23 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pub fn (expr Expr) pos() token.Pos {
|
2020-04-17 03:38:39 +03:00
|
|
|
|
// all uncommented have to be implemented
|
2022-03-06 20:01:22 +03:00
|
|
|
|
// Note: please do not print here. the language server will hang
|
2023-06-18 22:36:17 +03:00
|
|
|
|
// as it uses STDIO primarily to communicate ~Ned
|
2020-11-25 14:09:40 +03:00
|
|
|
|
match expr {
|
2020-07-07 18:10:39 +03:00
|
|
|
|
AnonFn {
|
|
|
|
|
return expr.decl.pos
|
|
|
|
|
}
|
2021-08-10 21:27:15 +03:00
|
|
|
|
CTempVar, EmptyExpr {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
// println('compiler bug, unhandled EmptyExpr pos()')
|
|
|
|
|
return token.Pos{}
|
2021-03-31 11:13:15 +03:00
|
|
|
|
}
|
2021-04-07 16:26:10 +03:00
|
|
|
|
NodeError, ArrayDecompose, ArrayInit, AsCast, Assoc, AtExpr, BoolLiteral, CallExpr,
|
|
|
|
|
CastExpr, ChanInit, CharLiteral, ConcatExpr, Comment, ComptimeCall, ComptimeSelector,
|
2023-05-28 00:33:46 +03:00
|
|
|
|
EnumVal, DumpExpr, FloatLiteral, GoExpr, SpawnExpr, Ident, IfExpr, IntegerLiteral,
|
|
|
|
|
IsRefType, Likely, LockExpr, MapInit, MatchExpr, None, OffsetOf, OrExpr, ParExpr,
|
|
|
|
|
PostfixExpr, PrefixExpr, RangeExpr, SelectExpr, SelectorExpr, SizeOf, SqlExpr,
|
|
|
|
|
StringInterLiteral, StringLiteral, StructInit, TypeNode, TypeOf, UnsafeExpr, ComptimeType,
|
|
|
|
|
Nil {
|
2021-04-06 16:16:19 +03:00
|
|
|
|
return expr.pos
|
|
|
|
|
}
|
|
|
|
|
IndexExpr {
|
|
|
|
|
if expr.or_expr.kind != .absent {
|
|
|
|
|
return expr.or_expr.pos
|
|
|
|
|
}
|
2020-12-29 18:14:08 +03:00
|
|
|
|
return expr.pos
|
|
|
|
|
}
|
2020-11-04 14:34:12 +03:00
|
|
|
|
IfGuardExpr {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
return expr.expr.pos()
|
2020-11-04 14:34:12 +03:00
|
|
|
|
}
|
2020-04-17 03:38:39 +03:00
|
|
|
|
InfixExpr {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
left_pos := expr.left.pos()
|
|
|
|
|
right_pos := expr.right.pos()
|
|
|
|
|
return token.Pos{
|
2020-06-19 12:46:08 +03:00
|
|
|
|
line_nr: expr.pos.line_nr
|
2020-04-17 03:38:39 +03:00
|
|
|
|
pos: left_pos.pos
|
|
|
|
|
len: right_pos.pos - left_pos.pos + right_pos.len
|
2021-03-23 08:23:46 +03:00
|
|
|
|
col: left_pos.col
|
2021-01-19 16:49:40 +03:00
|
|
|
|
last_line: right_pos.last_line
|
2020-04-17 03:38:39 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-04 14:34:12 +03:00
|
|
|
|
// Please, do NOT use else{} here.
|
|
|
|
|
// This match is exhaustive *on purpose*, to help force
|
|
|
|
|
// maintaining/implementing proper .pos fields.
|
2020-04-17 03:38:39 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-29 13:31:18 +03:00
|
|
|
|
|
2020-08-17 22:10:47 +03:00
|
|
|
|
pub fn (expr Expr) is_lvalue() bool {
|
2023-04-15 14:29:15 +03:00
|
|
|
|
return match expr {
|
|
|
|
|
Ident, CTempVar { true }
|
|
|
|
|
IndexExpr { expr.left.is_lvalue() }
|
|
|
|
|
SelectorExpr { expr.expr.is_lvalue() }
|
|
|
|
|
ParExpr { expr.expr.is_lvalue() } // for var := &{...(*pointer_var)}
|
|
|
|
|
PrefixExpr { expr.right.is_lvalue() }
|
|
|
|
|
ComptimeSelector { expr.field_expr.is_lvalue() }
|
|
|
|
|
else { false }
|
2020-08-17 22:10:47 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-19 19:18:36 +03:00
|
|
|
|
pub fn (expr Expr) is_expr() bool {
|
2023-04-15 14:29:15 +03:00
|
|
|
|
return match expr {
|
|
|
|
|
IfExpr, LockExpr, MatchExpr, SelectExpr { expr.is_expr }
|
|
|
|
|
else { true }
|
2020-09-19 19:18:36 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 11:56:11 +03:00
|
|
|
|
pub fn (expr Expr) get_pure_type() Type {
|
|
|
|
|
match expr {
|
|
|
|
|
BoolLiteral { return bool_type }
|
|
|
|
|
CharLiteral { return char_type }
|
|
|
|
|
FloatLiteral { return f64_type }
|
|
|
|
|
StringLiteral { return string_type }
|
|
|
|
|
IntegerLiteral { return i64_type }
|
|
|
|
|
else { return void_type }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-03 21:02:36 +03:00
|
|
|
|
pub fn (expr Expr) is_pure_literal() bool {
|
2020-12-11 06:46:06 +03:00
|
|
|
|
return match expr {
|
2022-06-03 21:02:36 +03:00
|
|
|
|
BoolLiteral, CharLiteral, FloatLiteral, StringLiteral, IntegerLiteral { true }
|
2020-12-11 06:46:06 +03:00
|
|
|
|
else { false }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 13:15:36 +03:00
|
|
|
|
pub fn (expr Expr) is_auto_deref_var() bool {
|
2021-02-20 21:50:43 +03:00
|
|
|
|
match expr {
|
|
|
|
|
Ident {
|
|
|
|
|
if expr.obj is Var {
|
|
|
|
|
if expr.obj.is_auto_deref {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PrefixExpr {
|
2021-02-21 13:15:36 +03:00
|
|
|
|
if expr.op == .amp && expr.right.is_auto_deref_var() {
|
2021-02-20 21:50:43 +03:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-15 04:34:27 +03:00
|
|
|
|
// returns if an expression can be used in `lock x, y.z {`
|
|
|
|
|
pub fn (e &Expr) is_lockable() bool {
|
2023-04-15 14:29:15 +03:00
|
|
|
|
return match e {
|
|
|
|
|
Ident { true }
|
|
|
|
|
SelectorExpr { e.expr.is_lockable() }
|
|
|
|
|
else { false }
|
2021-05-15 04:34:27 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 22:58:40 +03:00
|
|
|
|
// CTempVar is used in cgen only, to hold nodes for temporary variables
|
|
|
|
|
pub struct CTempVar {
|
|
|
|
|
pub:
|
2021-04-02 01:57:09 +03:00
|
|
|
|
name string // the name of the C temporary variable; used by g.expr(x)
|
|
|
|
|
typ Type // the type of the original expression
|
|
|
|
|
is_ptr bool // whether the type is a pointer
|
2022-01-20 09:40:16 +03:00
|
|
|
|
pub mut:
|
|
|
|
|
orig Expr // the original expression, which produced the C temp variable; used by x.str()
|
2020-10-21 22:58:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 13:36:28 +03:00
|
|
|
|
pub fn (node Node) pos() token.Pos {
|
2021-01-09 07:36:38 +03:00
|
|
|
|
match node {
|
2021-03-31 11:13:15 +03:00
|
|
|
|
NodeError {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
return token.Pos{}
|
2021-03-31 11:13:15 +03:00
|
|
|
|
}
|
2021-04-02 01:57:09 +03:00
|
|
|
|
EmptyNode {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
return token.Pos{}
|
2021-04-02 01:57:09 +03:00
|
|
|
|
}
|
2021-01-09 07:36:38 +03:00
|
|
|
|
Stmt {
|
2021-03-11 15:50:02 +03:00
|
|
|
|
mut pos := node.pos
|
2021-01-09 07:36:38 +03:00
|
|
|
|
if node is Import {
|
|
|
|
|
for sym in node.syms {
|
|
|
|
|
pos = pos.extend(sym.pos)
|
|
|
|
|
}
|
2021-04-09 14:51:25 +03:00
|
|
|
|
} else if node is TypeDecl {
|
|
|
|
|
match node {
|
|
|
|
|
FnTypeDecl, AliasTypeDecl {
|
|
|
|
|
pos = pos.extend(node.type_pos)
|
|
|
|
|
}
|
|
|
|
|
SumTypeDecl {
|
|
|
|
|
for variant in node.variants {
|
|
|
|
|
pos = pos.extend(variant.pos)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-09 07:36:38 +03:00
|
|
|
|
}
|
2021-04-06 16:16:19 +03:00
|
|
|
|
if node is AssignStmt {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
return pos.extend(node.right.last().pos())
|
2021-04-06 16:16:19 +03:00
|
|
|
|
}
|
|
|
|
|
if node is AssertStmt {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
return pos.extend(node.expr.pos())
|
2021-04-06 16:16:19 +03:00
|
|
|
|
}
|
2021-01-09 07:36:38 +03:00
|
|
|
|
return pos
|
|
|
|
|
}
|
|
|
|
|
Expr {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
return node.pos()
|
2021-01-09 07:36:38 +03:00
|
|
|
|
}
|
|
|
|
|
StructField {
|
|
|
|
|
return node.pos.extend(node.type_pos)
|
|
|
|
|
}
|
2021-04-29 09:04:02 +03:00
|
|
|
|
MatchBranch, SelectBranch, EnumField, ConstField, StructInitField, GlobalField, CallArg {
|
2021-01-09 07:36:38 +03:00
|
|
|
|
return node.pos
|
|
|
|
|
}
|
2021-04-09 14:51:25 +03:00
|
|
|
|
Param {
|
|
|
|
|
return node.pos.extend(node.type_pos)
|
|
|
|
|
}
|
2021-01-09 07:36:38 +03:00
|
|
|
|
IfBranch {
|
|
|
|
|
return node.pos.extend(node.body_pos)
|
|
|
|
|
}
|
|
|
|
|
ScopeObject {
|
|
|
|
|
match node {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
ConstField, GlobalField, Var {
|
|
|
|
|
return node.pos
|
|
|
|
|
}
|
|
|
|
|
AsmRegister {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
return token.Pos{
|
2021-03-17 03:43:17 +03:00
|
|
|
|
len: -1
|
|
|
|
|
line_nr: -1
|
|
|
|
|
pos: -1
|
|
|
|
|
last_line: -1
|
2021-03-23 08:23:46 +03:00
|
|
|
|
col: -1
|
2021-03-17 03:43:17 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-09 07:36:38 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
File {
|
2022-01-26 13:36:28 +03:00
|
|
|
|
mut pos := token.Pos{}
|
2021-01-09 07:36:38 +03:00
|
|
|
|
if node.stmts.len > 0 {
|
2021-03-11 15:50:02 +03:00
|
|
|
|
first_pos := node.stmts.first().pos
|
|
|
|
|
last_pos := node.stmts.last().pos
|
2021-01-09 07:36:38 +03:00
|
|
|
|
pos = first_pos.extend_with_last_line(last_pos, last_pos.line_nr)
|
|
|
|
|
}
|
|
|
|
|
return pos
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn (node Node) children() []Node {
|
|
|
|
|
mut children := []Node{}
|
|
|
|
|
if node is Expr {
|
|
|
|
|
match node {
|
|
|
|
|
StringInterLiteral, Assoc, ArrayInit {
|
|
|
|
|
return node.exprs.map(Node(it))
|
|
|
|
|
}
|
2021-01-19 08:16:42 +03:00
|
|
|
|
SelectorExpr, PostfixExpr, UnsafeExpr, AsCast, ParExpr, IfGuardExpr, SizeOf, Likely,
|
|
|
|
|
TypeOf, ArrayDecompose {
|
2021-01-09 07:36:38 +03:00
|
|
|
|
children << node.expr
|
|
|
|
|
}
|
|
|
|
|
LockExpr, OrExpr {
|
|
|
|
|
return node.stmts.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
StructInit {
|
2023-06-22 16:41:08 +03:00
|
|
|
|
return node.init_fields.map(Node(it))
|
2021-01-09 07:36:38 +03:00
|
|
|
|
}
|
|
|
|
|
AnonFn {
|
|
|
|
|
children << Stmt(node.decl)
|
|
|
|
|
}
|
|
|
|
|
CallExpr {
|
|
|
|
|
children << node.left
|
2021-03-30 10:43:17 +03:00
|
|
|
|
children << node.args.map(Node(it))
|
2021-01-09 07:36:38 +03:00
|
|
|
|
children << Expr(node.or_block)
|
|
|
|
|
}
|
|
|
|
|
InfixExpr {
|
|
|
|
|
children << node.left
|
|
|
|
|
children << node.right
|
|
|
|
|
}
|
|
|
|
|
PrefixExpr {
|
|
|
|
|
children << node.right
|
|
|
|
|
}
|
|
|
|
|
IndexExpr {
|
|
|
|
|
children << node.left
|
|
|
|
|
children << node.index
|
|
|
|
|
}
|
|
|
|
|
IfExpr {
|
|
|
|
|
children << node.left
|
|
|
|
|
children << node.branches.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
MatchExpr {
|
|
|
|
|
children << node.cond
|
|
|
|
|
children << node.branches.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
SelectExpr {
|
|
|
|
|
return node.branches.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
ChanInit {
|
|
|
|
|
children << node.cap_expr
|
|
|
|
|
}
|
|
|
|
|
MapInit {
|
|
|
|
|
children << node.keys.map(Node(it))
|
|
|
|
|
children << node.vals.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
RangeExpr {
|
|
|
|
|
children << node.low
|
|
|
|
|
children << node.high
|
|
|
|
|
}
|
|
|
|
|
CastExpr {
|
|
|
|
|
children << node.expr
|
|
|
|
|
children << node.arg
|
|
|
|
|
}
|
|
|
|
|
ConcatExpr {
|
|
|
|
|
return node.vals.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
ComptimeCall, ComptimeSelector {
|
|
|
|
|
children << node.left
|
|
|
|
|
}
|
|
|
|
|
else {}
|
|
|
|
|
}
|
|
|
|
|
} else if node is Stmt {
|
|
|
|
|
match node {
|
2021-11-17 09:29:43 +03:00
|
|
|
|
Block, DeferStmt, ForCStmt, ForInStmt, ForStmt, ComptimeFor {
|
2021-01-09 07:36:38 +03:00
|
|
|
|
return node.stmts.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
ExprStmt, AssertStmt {
|
|
|
|
|
children << node.expr
|
|
|
|
|
}
|
|
|
|
|
InterfaceDecl {
|
2021-04-05 18:14:21 +03:00
|
|
|
|
children << node.methods.map(Node(Stmt(it)))
|
|
|
|
|
children << node.fields.map(Node(it))
|
2021-01-09 07:36:38 +03:00
|
|
|
|
}
|
|
|
|
|
AssignStmt {
|
|
|
|
|
children << node.left.map(Node(it))
|
|
|
|
|
children << node.right.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
Return {
|
|
|
|
|
return node.exprs.map(Node(it))
|
|
|
|
|
}
|
2022-03-06 20:01:22 +03:00
|
|
|
|
// Note: these four decl nodes cannot be merged as one branch
|
2021-01-09 07:36:38 +03:00
|
|
|
|
StructDecl {
|
|
|
|
|
return node.fields.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
GlobalDecl {
|
|
|
|
|
return node.fields.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
ConstDecl {
|
|
|
|
|
return node.fields.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
EnumDecl {
|
|
|
|
|
return node.fields.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
FnDecl {
|
|
|
|
|
if node.is_method {
|
|
|
|
|
children << Node(node.receiver)
|
|
|
|
|
}
|
|
|
|
|
children << node.params.map(Node(it))
|
|
|
|
|
children << node.stmts.map(Node(it))
|
|
|
|
|
}
|
2021-04-09 14:51:25 +03:00
|
|
|
|
TypeDecl {
|
|
|
|
|
if node is SumTypeDecl {
|
2021-04-29 09:04:02 +03:00
|
|
|
|
children << node.variants.map(Node(Expr(it)))
|
2021-04-09 14:51:25 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-09 07:36:38 +03:00
|
|
|
|
else {}
|
|
|
|
|
}
|
|
|
|
|
} else if node is ScopeObject {
|
|
|
|
|
match node {
|
|
|
|
|
GlobalField, ConstField, Var { children << node.expr }
|
2021-03-17 03:43:17 +03:00
|
|
|
|
AsmRegister {}
|
2021-01-09 07:36:38 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
match node {
|
2021-04-02 17:26:37 +03:00
|
|
|
|
GlobalField, ConstField, EnumField, StructInitField, CallArg {
|
2021-01-09 07:36:38 +03:00
|
|
|
|
children << node.expr
|
|
|
|
|
}
|
|
|
|
|
SelectBranch {
|
|
|
|
|
children << node.stmt
|
|
|
|
|
children << node.stmts.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
IfBranch, File {
|
|
|
|
|
return node.stmts.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
MatchBranch {
|
|
|
|
|
children << node.stmts.map(Node(it))
|
|
|
|
|
children << node.exprs.map(Node(it))
|
|
|
|
|
}
|
|
|
|
|
else {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return children
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-16 16:08:01 +03:00
|
|
|
|
// helper for dealing with `m[k1][k2][k3][k3] = value`
|
|
|
|
|
pub fn (mut lx IndexExpr) recursive_mapset_is_setter(val bool) {
|
|
|
|
|
lx.is_setter = val
|
|
|
|
|
if mut lx.left is IndexExpr {
|
|
|
|
|
if lx.left.is_map {
|
|
|
|
|
lx.left.recursive_mapset_is_setter(val)
|
|
|
|
|
}
|
2022-04-28 17:37:19 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn (mut lx IndexExpr) recursive_arraymap_set_is_setter() {
|
|
|
|
|
lx.is_setter = true
|
|
|
|
|
if mut lx.left is IndexExpr {
|
|
|
|
|
lx.left.recursive_arraymap_set_is_setter()
|
2022-04-28 13:20:56 +03:00
|
|
|
|
} else if mut lx.left is SelectorExpr {
|
|
|
|
|
if mut lx.left.expr is IndexExpr {
|
2022-04-28 17:37:19 +03:00
|
|
|
|
lx.left.expr.recursive_arraymap_set_is_setter()
|
2022-04-28 13:20:56 +03:00
|
|
|
|
}
|
2021-02-16 16:08:01 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-17 03:43:17 +03:00
|
|
|
|
|
2021-08-10 10:29:44 +03:00
|
|
|
|
// return all the registers for the given architecture
|
2021-04-02 01:57:09 +03:00
|
|
|
|
pub fn all_registers(mut t Table, arch pref.Arch) map[string]ScopeObject {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
mut res := map[string]ScopeObject{}
|
|
|
|
|
match arch {
|
|
|
|
|
.amd64, .i386 {
|
|
|
|
|
for bit_size, array in ast.x86_no_number_register_list {
|
|
|
|
|
for name in array {
|
|
|
|
|
res[name] = AsmRegister{
|
|
|
|
|
name: name
|
|
|
|
|
typ: t.bitsize_to_type(bit_size)
|
|
|
|
|
size: bit_size
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for bit_size, array in ast.x86_with_number_register_list {
|
|
|
|
|
for name, max_num in array {
|
|
|
|
|
for i in 0 .. max_num {
|
|
|
|
|
hash_index := name.index('#') or {
|
2021-04-02 01:57:09 +03:00
|
|
|
|
panic('all_registers: no hashtag found')
|
2021-03-17 03:43:17 +03:00
|
|
|
|
}
|
2022-11-15 16:53:13 +03:00
|
|
|
|
assembled_name := '${name[..hash_index]}${i}${name[hash_index + 1..]}'
|
2021-03-17 03:43:17 +03:00
|
|
|
|
res[assembled_name] = AsmRegister{
|
|
|
|
|
name: assembled_name
|
|
|
|
|
typ: t.bitsize_to_type(bit_size)
|
|
|
|
|
size: bit_size
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-26 19:01:42 +03:00
|
|
|
|
.arm32 {
|
|
|
|
|
arm32 := gen_all_registers(mut t, ast.arm_no_number_register_list, ast.arm_with_number_register_list,
|
2021-03-17 03:43:17 +03:00
|
|
|
|
32)
|
2021-04-26 19:01:42 +03:00
|
|
|
|
for k, v in arm32 {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
res[k] = v
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-26 19:01:42 +03:00
|
|
|
|
.arm64 {
|
|
|
|
|
arm64 := gen_all_registers(mut t, ast.arm_no_number_register_list, ast.arm_with_number_register_list,
|
2021-03-17 03:43:17 +03:00
|
|
|
|
64)
|
2021-04-26 19:01:42 +03:00
|
|
|
|
for k, v in arm64 {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
res[k] = v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.rv32 {
|
|
|
|
|
rv32 := gen_all_registers(mut t, ast.riscv_no_number_register_list, ast.riscv_with_number_register_list,
|
|
|
|
|
32)
|
|
|
|
|
for k, v in rv32 {
|
|
|
|
|
res[k] = v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.rv64 {
|
|
|
|
|
rv64 := gen_all_registers(mut t, ast.riscv_no_number_register_list, ast.riscv_with_number_register_list,
|
|
|
|
|
64)
|
|
|
|
|
for k, v in rv64 {
|
|
|
|
|
res[k] = v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { // TODO
|
2021-04-02 01:57:09 +03:00
|
|
|
|
panic('all_registers: unhandled arch')
|
2021-03-17 03:43:17 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only for arm and riscv because x86 has different sized registers
|
2021-04-02 01:57:09 +03:00
|
|
|
|
fn gen_all_registers(mut t Table, without_numbers []string, with_numbers map[string]int, bit_size int) map[string]ScopeObject {
|
2021-03-17 03:43:17 +03:00
|
|
|
|
mut res := map[string]ScopeObject{}
|
|
|
|
|
for name in without_numbers {
|
|
|
|
|
res[name] = AsmRegister{
|
|
|
|
|
name: name
|
|
|
|
|
typ: t.bitsize_to_type(bit_size)
|
|
|
|
|
size: bit_size
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for name, max_num in with_numbers {
|
|
|
|
|
for i in 0 .. max_num {
|
2021-04-02 01:57:09 +03:00
|
|
|
|
hash_index := name.index('#') or { panic('all_registers: no hashtag found') }
|
2022-11-15 16:53:13 +03:00
|
|
|
|
assembled_name := '${name[..hash_index]}${i}${name[hash_index + 1..]}'
|
2021-03-17 03:43:17 +03:00
|
|
|
|
res[assembled_name] = AsmRegister{
|
|
|
|
|
name: assembled_name
|
|
|
|
|
typ: t.bitsize_to_type(bit_size)
|
|
|
|
|
size: bit_size
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res
|
|
|
|
|
}
|
2021-07-30 19:20:45 +03:00
|
|
|
|
|
|
|
|
|
// is `expr` a literal, i.e. it does not depend on any other declarations (C compile time constant)
|
|
|
|
|
pub fn (expr Expr) is_literal() bool {
|
|
|
|
|
match expr {
|
2022-10-08 19:27:30 +03:00
|
|
|
|
BoolLiteral, CharLiteral, FloatLiteral, IntegerLiteral, StringLiteral, StringInterLiteral {
|
2021-07-30 19:20:45 +03:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
PrefixExpr {
|
|
|
|
|
return expr.right.is_literal()
|
|
|
|
|
}
|
|
|
|
|
InfixExpr {
|
|
|
|
|
return expr.left.is_literal() && expr.right.is_literal()
|
|
|
|
|
}
|
|
|
|
|
ParExpr {
|
|
|
|
|
return expr.expr.is_literal()
|
|
|
|
|
}
|
|
|
|
|
CastExpr {
|
2023-06-17 14:10:06 +03:00
|
|
|
|
return !expr.has_arg && expr.expr.is_literal() && (expr.typ.is_any_kind_of_pointer()
|
2022-07-06 13:32:30 +03:00
|
|
|
|
|| expr.typ in [i8_type, i16_type, int_type, i64_type, u8_type, u16_type, u32_type, u64_type, f32_type, f64_type, char_type, bool_type, rune_type])
|
2021-07-30 19:20:45 +03:00
|
|
|
|
}
|
|
|
|
|
SizeOf, IsRefType {
|
|
|
|
|
return expr.is_type || expr.expr.is_literal()
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-07 17:02:37 +03:00
|
|
|
|
|
2023-01-05 20:53:37 +03:00
|
|
|
|
pub fn (e Expr) is_nil() bool {
|
|
|
|
|
if e is Nil {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if e is UnsafeExpr {
|
|
|
|
|
if e.expr is Nil {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-07 17:02:37 +03:00
|
|
|
|
pub fn type_can_start_with_token(tok &token.Token) bool {
|
|
|
|
|
match tok.kind {
|
|
|
|
|
.name {
|
|
|
|
|
return (tok.lit.len > 0 && tok.lit[0].is_capital())
|
2022-07-29 23:01:30 +03:00
|
|
|
|
|| builtin_type_names_matcher.matches(tok.lit)
|
2021-11-07 17:02:37 +03:00
|
|
|
|
}
|
|
|
|
|
// Note: return type (T1, T2) should be handled elsewhere
|
|
|
|
|
.amp, .key_fn, .lsbr, .question {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
else {}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|