From 95eba647bc9728914c01fe6ddf3364c43e4a89de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Ferr=C3=A0s?= Date: Sun, 24 Nov 2024 20:43:13 +0100 Subject: [PATCH] Refactor ast node tree generation --- server/internal/lsp/ast/ast.go | 605 ++---------------- server/internal/lsp/ast/ast_builder.go | 38 +- server/internal/lsp/ast/ast_declaration.go | 135 ++++ server/internal/lsp/ast/ast_expression.go | 307 +++++++++ server/internal/lsp/ast/ast_statement.go | 161 +++++ server/internal/lsp/ast/ast_visitors.go | 56 +- server/internal/lsp/ast/convert.go | 478 +++++++------- server/internal/lsp/ast/convert_ct.go | 40 +- .../lsp/ast/convert_declarations_test.go | 408 ++++++------ .../lsp/ast/convert_expression_test.go | 510 ++++++++------- server/internal/lsp/ast/convert_rules.go | 2 +- server/internal/lsp/ast/convert_rules_exec.go | 210 +++--- server/internal/lsp/ast/convert_statement.go | 232 ++++--- .../lsp/ast/convert_statement_test.go | 547 ++++++++-------- server/internal/lsp/ast/json_visitor.go | 12 +- server/internal/lsp/ast2/ast_test.go | 42 ++ server/internal/lsp/stdlib/v055.go | 18 +- server/internal/lsp/stdlib/v060.go | 18 +- server/internal/lsp/stdlib/v061.go | 16 +- 19 files changed, 2064 insertions(+), 1771 deletions(-) create mode 100644 server/internal/lsp/ast/ast_declaration.go create mode 100644 server/internal/lsp/ast/ast_expression.go create mode 100644 server/internal/lsp/ast/ast_statement.go create mode 100644 server/internal/lsp/ast2/ast_test.go diff --git a/server/internal/lsp/ast/ast.go b/server/internal/lsp/ast/ast.go index 6a6a1d0..6f30606 100644 --- a/server/internal/lsp/ast/ast.go +++ b/server/internal/lsp/ast/ast.go @@ -5,619 +5,134 @@ import ( sitter "github.com/smacker/go-tree-sitter" ) -type Position struct { - Line, Column uint -} +// This package is heavily inspired by the official go/ast.go package. +// Some comment descriptions might be literal copy-pastes where they apply. const ( ResolveStatusPending = iota ResolveStatusDone ) -type NodeType int - -const ( - TypeFile = iota - TypeModule - TypeIdentifier - TypeTypeInfo - TypeDefDecl - TypeVariableDecl - TypeEnumDecl - TypeEnumProperty - TypeEnumMember - TypeStructDecl - TypeStructMemberDecl - TypeFaultDecl - TypeFaultMemberDecl - TypeConstDecl - TypeInterfaceDecl - TypeMacroDecl - TypeFunctionDecl - TypeFunctionSignature - TypeFunctionParameter - TypeLambdaDecl - TypeLambdaExpr - TypeAssignmentStatement - TypeBinaryExpr - TypeTernaryExpr - TypeElvisOrElseExpr - TypeOptionalExpr - TypeUnaryExpr - TypeUpdateExpr - TypeSubscriptExpr - TypeCastExpr - TypeRethrowExpr - TypeCallExpr - TypeTrailingGenericExpr - TypeInlineTypeWithInitExpr - TypeInitializerList - TypeReturnStatement - TypeCompoundStatement - TypeContinueStatement - TypeBreakStatement - TypeSwitchStatement - TypeSwitchCaseStatement - TypeSwitchCaseRangeExpr - TypeNextCaseStatement - TypeIfStatement - TypeElseStatement - TypeForStatement - TypeForeachStatement - TypeWhileStatement - TypeDoStatement - TypeDeferStatement - TypeAssertStatement - TypeFunctionCallExpr +type Position struct { + Line, Column uint +} - TypeIntegerLiteral -) +// ---------------------------------------------------------------------------- +// Interfaces +// +// There are 3 main classes of nodes: +// - Expressions and types nodes +// - Statement nodes +// - Declaration nodes +// +// All nodes contain position information marking the beginning and end of the +// corresponding source text segment. -type ASTNode interface { - TypeNode() NodeType +type Node interface { StartPosition() Position EndPosition() Position } -type ASTBaseNode struct { - StartPos, EndPos Position - Attributes []string - Kind NodeType +type Expression interface { + Node + exprNode() } -func (n ASTBaseNode) TypeNode() NodeType { - return n.Kind +type Declaration interface { + Node + declNode() } -func (n ASTBaseNode) StartPosition() Position { - return n.StartPos +type Statement interface { + Node + stmtNode() } -func (n ASTBaseNode) EndPosition() Position { - return n.EndPos + +// NodeAttributes is a struct that contains the common information all +// AST Nodes contains, like position or other attributes +type NodeAttributes struct { + StartPos, EndPos Position + Attributes []string } -func (n *ASTBaseNode) SetPos(start sitter.Point, end sitter.Point) { +func (n NodeAttributes) StartPosition() Position { return n.StartPos } +func (n NodeAttributes) EndPosition() Position { return n.EndPos } + +func ChangeNodePosition(n *NodeAttributes, start sitter.Point, end sitter.Point) { n.StartPos = Position{Line: uint(start.Row), Column: uint(start.Column)} n.EndPos = Position{Line: uint(end.Row), Column: uint(end.Column)} -} +} /* +func (n *NodeAttributes) SetPos(start sitter.Point, end sitter.Point) { + n.StartPos = Position{Line: uint(start.Row), Column: uint(start.Column)} + n.EndPos = Position{Line: uint(end.Row), Column: uint(end.Column)} +}*/ type File struct { - ASTBaseNode + NodeAttributes Name string Modules []Module } type Module struct { - ASTBaseNode + NodeAttributes Name string GenericParameters []string - Functions []Declaration - Macros []Declaration - Declarations []Declaration - Variables []VariableDecl - Imports []Import + Declarations []Declaration // Top level declarations + Imports []*Import // Imports in this file } type Import struct { - ASTBaseNode + NodeAttributes Path string } -type Declaration interface { - ASTNode -} - -type VariableDecl struct { - ASTBaseNode - Names []Identifier - Type TypeInfo - Initializer Expression -} - -type ConstDecl struct { - ASTBaseNode - Names []Identifier - Type option.Option[TypeInfo] - Initializer Expression -} - -type EnumDecl struct { - ASTBaseNode - Name string - BaseType TypeInfo - Properties []EnumProperty - Members []EnumMember -} +func (*Import) stmtNode() {} type EnumProperty struct { - ASTBaseNode + NodeAttributes Type TypeInfo - Name Identifier + Name Ident } type EnumMember struct { - ASTBaseNode - Name Identifier + NodeAttributes + Name Ident Value CompositeLiteral } type PropertyValue struct { - ASTBaseNode + NodeAttributes Name string Value Expression } -const ( - StructTypeNormal = iota - StructTypeUnion - StructTypeBitStruct -) - -type StructType int - -type StructDecl struct { - ASTBaseNode - Name string - BackingType option.Option[TypeInfo] - Members []StructMemberDecl - StructType StructType - Implements []string -} - type StructMemberDecl struct { - ASTBaseNode - Names []Identifier + NodeAttributes + Names []Ident Type TypeInfo BitRange option.Option[[2]uint] IsInlined bool } -type FaultDecl struct { - ASTBaseNode - Name Identifier - BackingType option.Option[TypeInfo] - Members []FaultMember -} - type FaultMember struct { - ASTBaseNode - Name Identifier -} - -type DefDecl struct { - ASTBaseNode - Name Identifier - resolvesTo string - resolvesToType option.Option[TypeInfo] -} - -type MacroDecl struct { - ASTBaseNode - Signature MacroSignature - Body Block + NodeAttributes + Name Ident } type MacroSignature struct { - Name Identifier - Parameters []FunctionParameter -} - -type LambdaDeclaration struct { - ASTBaseNode - Parameters []FunctionParameter - ReturnType option.Option[TypeInfo] - Body Expression -} - -type FunctionDecl struct { - ASTBaseNode - ParentTypeId option.Option[Identifier] - Signature FunctionSignature - Body ASTNode -} - -type FunctionSignature struct { - ASTBaseNode - Name Identifier + Name Ident Parameters []FunctionParameter - ReturnType TypeInfo } type FunctionParameter struct { - ASTBaseNode - Name Identifier + NodeAttributes + Name Ident Type TypeInfo } +// Block TODO document what this represents type Block struct { - ASTBaseNode + NodeAttributes Declarations []Declaration Statements []Expression } - -type FunctionCall struct { - ASTBaseNode - Identifier Expression - GenericArguments option.Option[[]Expression] - Arguments []Arg - TrailingBlock option.Option[CompoundStatement] -} - -type InterfaceDecl struct { - ASTBaseNode - Name Identifier - Methods []FunctionSignature -} - -type TypeInfo struct { - ASTBaseNode - ResolveStatus int - Identifier Identifier - Pointer uint - Optional bool - BuiltIn bool - Static bool - Reference bool - TLocal bool - Generics []TypeInfo -} - -type Identifier struct { - ASTBaseNode - Name string - Path string -} - -// Used only as a temporal container. -// It is decomposed and its info extracted to build other ast nodes. -type TrailingGenericsExpr struct { - ASTBaseNode - Identifier Identifier - GenericArguments []Expression -} - -type Literal struct { - ASTBaseNode - Value string -} -type IntegerLiteral struct { - ASTBaseNode - Value string -} -type RealLiteral struct { - ASTBaseNode - Value string -} - -type BoolLiteral struct { - ASTBaseNode - Value bool -} -type CompositeLiteral struct { - ASTBaseNode - Values []Expression -} - -type InitializerList struct { - ASTBaseNode - Args []Expression -} - -const ( - PathTypeIndexed = iota - PathTypeField - PathTypeRange -) - -type Path struct { - ASTBaseNode - PathType int - Path string - PathStart string - PathEnd string - FieldName string -} - -type Arg interface { - ASTNode -} -type ArgParamPathSet struct { - ASTBaseNode - Path string - Expr Expression -} - -type ArgFieldSet struct { - ASTBaseNode - FieldName string - Expr Expression -} - -func (arg *ArgFieldSet) SetExpr(expr Expression) { - arg.Expr = expr -} - -type IndexAccess struct { - ASTBaseNode - Array Expression - Index string -} - -// TODO Replace by RangeIndex -type RangeAccess struct { - ASTBaseNode - Array Expression - RangeStart uint - RangeEnd uint -} - -type FieldAccess struct { - ASTBaseNode - Object Expression - Field Expression -} - -type CompoundStatement struct { - ASTBaseNode - Statements []Expression -} - -type ReturnStatement struct { - ASTBaseNode - Return option.Option[Expression] -} - -type Statement interface { - ASTNode -} - -type ExpressionStatement struct { - ASTBaseNode - Expr Expression -} - -type AssignmentStatement struct { - ASTBaseNode - Left Expression - Right Expression - Operator string -} - -type ContinueStatement struct { - ASTBaseNode - Label option.Option[string] -} - -type BreakStatement struct { - ASTBaseNode - Label option.Option[string] -} - -type SwitchStatement struct { - ASTBaseNode - Label option.Option[string] - Condition Expression - Cases []SwitchCase - Default []Statement -} - -type SwitchCase struct { - ASTBaseNode - Value Expression - Statements []Statement -} - -type SwitchCaseRange struct { - ASTBaseNode - Start Expression - End Expression -} - -type Nextcase struct { - ASTBaseNode - Label option.Option[string] - Value Expression -} - -type IfStatement struct { - ASTBaseNode - Label option.Option[string] - Condition []Expression - Statement Statement - Else ElseStatement -} - -type ElseStatement struct { - ASTBaseNode - Statement Statement -} - -type ForStatement struct { - ASTBaseNode - Label option.Option[string] - Initializer []Expression - Condition Expression - Update []Expression - Body Statement -} - -type ForeachStatement struct { - ASTBaseNode - Value ForeachValue - Index ForeachValue - Collection Expression - Body Statement -} - -type ForeachValue struct { - Type TypeInfo - Identifier Identifier -} - -type WhileStatement struct { - ASTBaseNode - Condition []Expression - Body Statement -} - -type DoStatement struct { - ASTBaseNode - Condition Expression - Body Statement -} - -type DeferStatement struct { - ASTBaseNode - Statement Statement -} - -type AssertStatement struct { - ASTBaseNode - Assertions []Expression -} - -type TernaryExpression struct { - ASTBaseNode - Condition Expression - Consequence Expression - Alternative Expression -} - -type UpdateExpression struct { - ASTBaseNode - Operator string - Argument Expression -} - -type SubscriptExpression struct { - ASTBaseNode - Argument Expression - Index Expression // Index can be another expression: - // - IntegerLiteral - // - RangeIndex - // - Identifier - // - CallExpression - // - ... -} -type RangeIndex struct { - ASTBaseNode - - Start option.Option[uint] - End option.Option[uint] -} - -type Expression interface { - ASTNode -} - -/* -* -assignment_expr, -$.ternary_expr, -$.lambda_expr, -$.elvis_orelse_expr, -$.suffix_expr, -$.binary_expr, -$.unary_expr, -$.cast_expr, -$.rethrow_expr, -$.trailing_generic_expr, -$.update_expr, -$.call_expr, -$.subscript_expr, -$.initializer_list, -$._base_expr - - 'true', - 'false', - 'null', - $.builtin, - $.integer_literal, - $.real_literal, - $.char_literal, - $.string_literal, - $.raw_string_literal, - $.string_expr, - $.bytes_expr, - - $._ident_expr, - $._local_ident_expr, - - $.initializer_list, - seq($.type, $.initializer_list), - - $.module_ident_expr, - $.field_expr, - $.type_access_expr, - $.paren_expr, - $.expr_block, - - '$vacount', - seq($._ct_call, '(', $.flat_path, ')'), - seq($._ct_arg, '(', $._expr, ')'), - seq($._ct_analyse, '(', $.comma_decl_or_expr, ')'), - seq('$feature', '(', $.const_ident, ')'), - seq('$and', '(', $.comma_decl_or_expr, ')'), - seq('$or', '(', $.comma_decl_or_expr, ')'), - seq('$assignable', '(', $._expr, ',', $.type, ')'), - seq('$embed', '(', commaSep($._constant_expr), ')'), - - seq($.lambda_declaration, $.compound_stmt), -*/ -type UnaryExpression struct { - ASTBaseNode - Operator string - Argument Expression -} - -// BinaryExpression representa una expresión binaria (como suma, resta, etc.) -type BinaryExpression struct { - ASTBaseNode - Left ASTNode - Operator string - Right ASTNode -} - -type OptionalExpression struct { - ASTBaseNode - Argument Expression - Operator string -} - -type CastExpression struct { - ASTBaseNode - Type TypeInfo - Argument Expression -} - -type RethrowExpression struct { - ASTBaseNode - Operator string - Argument Expression -} - -type InlineTypeWithInitizlization struct { - ASTBaseNode - Type TypeInfo - InitializerList InitializerList -} diff --git a/server/internal/lsp/ast/ast_builder.go b/server/internal/lsp/ast/ast_builder.go index 4d6e2b2..03cc9e9 100644 --- a/server/internal/lsp/ast/ast_builder.go +++ b/server/internal/lsp/ast/ast_builder.go @@ -9,22 +9,22 @@ import ( // ASTBaseNodeBuilder // -- type ASTBaseNodeBuilder struct { - bn ASTBaseNode + bn NodeAttributes } -func NewBaseNodeBuilder(kind NodeType) *ASTBaseNodeBuilder { +func NewBaseNodeBuilder() *ASTBaseNodeBuilder { return &ASTBaseNodeBuilder{ - bn: ASTBaseNode{Kind: kind}, + bn: NodeAttributes{}, } } -func NewBaseNodeFromSitterNode(kind NodeType, node *sitter.Node) ASTBaseNode { - builder := NewBaseNodeBuilder(kind). +func NewBaseNodeFromSitterNode(node *sitter.Node) NodeAttributes { + builder := NewBaseNodeBuilder(). WithSitterPos(node) return builder.Build() } -func (d *ASTBaseNodeBuilder) Build() ASTBaseNode { +func (d *ASTBaseNodeBuilder) Build() NodeAttributes { return d.bn } @@ -55,14 +55,14 @@ func (d *ASTBaseNodeBuilder) WithStartEnd(startRow uint, startCol uint, endRow u // IdentifierBuilder // -- type IdentifierBuilder struct { - bi Identifier + bi *Ident bn ASTBaseNodeBuilder } func NewIdentifierBuilder() *IdentifierBuilder { return &IdentifierBuilder{ - bi: Identifier{}, - bn: *NewBaseNodeBuilder(TypeIdentifier), + bi: &Ident{}, + bn: *NewBaseNodeBuilder(), } } @@ -71,7 +71,7 @@ func (i *IdentifierBuilder) WithName(name string) *IdentifierBuilder { return i } func (i *IdentifierBuilder) WithPath(path string) *IdentifierBuilder { - i.bi.Path = path + i.bi.ModulePath = path return i } @@ -85,11 +85,11 @@ func (i *IdentifierBuilder) WithStartEnd(startRow uint, startCol uint, endRow ui return i } -func (i *IdentifierBuilder) Build() Identifier { +func (i *IdentifierBuilder) Build() Ident { ident := i.bi - ident.ASTBaseNode = i.bn.Build() + ident.NodeAttributes = i.bn.Build() - return ident + return *ident } // -- @@ -102,7 +102,7 @@ type TypeInfoBuilder struct { func NewTypeInfoBuilder() *TypeInfoBuilder { return &TypeInfoBuilder{ t: TypeInfo{ - ASTBaseNode: ASTBaseNode{Kind: TypeTypeInfo}, + NodeAttributes: NodeAttributes{}, }, } } @@ -149,7 +149,7 @@ func (b *TypeInfoBuilder) WithName(name string) *TypeInfoBuilder { } func (b *TypeInfoBuilder) WithPath(path string) *TypeInfoBuilder { - b.t.Identifier.Path = path + b.t.Identifier.ModulePath = path return b } @@ -161,8 +161,8 @@ func (b *TypeInfoBuilder) WithNameStartEnd(startRow uint, startCol uint, endRow } func (b *TypeInfoBuilder) WithStartEnd(startRow uint, startCol uint, endRow uint, endCol uint) *TypeInfoBuilder { - b.t.ASTBaseNode.StartPos = Position{startRow, startCol} - b.t.ASTBaseNode.EndPos = Position{endRow, endCol} + b.t.NodeAttributes.StartPos = Position{startRow, startCol} + b.t.NodeAttributes.EndPos = Position{endRow, endCol} return b } @@ -181,7 +181,7 @@ type DefDeclBuilder struct { func NewDefDeclBuilder() *DefDeclBuilder { return &DefDeclBuilder{ d: DefDecl{}, - a: *NewBaseNodeBuilder(TypeDefDecl), + a: *NewBaseNodeBuilder(), } } @@ -213,7 +213,7 @@ func (b *DefDeclBuilder) WithIdentifierSitterPos(node *sitter.Node) *DefDeclBuil func (b *DefDeclBuilder) Build() DefDecl { def := b.d - def.ASTBaseNode = b.a.Build() + def.NodeAttributes = b.a.Build() return def } diff --git a/server/internal/lsp/ast/ast_declaration.go b/server/internal/lsp/ast/ast_declaration.go new file mode 100644 index 0000000..84761be --- /dev/null +++ b/server/internal/lsp/ast/ast_declaration.go @@ -0,0 +1,135 @@ +package ast + +import ( + "github.com/pherrymason/c3-lsp/pkg/option" + "go/token" +) + +// ---------------------------------------------------------------------------- +// Declarations + +type ( + // The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec. + Spec interface { + Node + specNode() + } + + ImportSpec struct { + NodeAttributes + Path string + } + + ValueSpec struct { + Names []*Ident + Type Expression // value type, or nil + Values []Expression // initial values, or nil + } + + // TypeSpec represents declarations of types like aliases, definition of types + // or parametrized types (generics) + TypeSpec struct { + Name *Ident // type name + TypeParams []Expression // type parameters; or nil + Assign token.Pos // position of '=', if any + Type Expression // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes + } +) + +func (*ImportSpec) specNode() {} +func (*ValueSpec) specNode() {} + +const ( + StructTypeNormal = iota + StructTypeUnion + StructTypeBitStruct +) + +type StructType int + +type ( + // VariableDecl + // Deprecated use GenDecl with Token as token.VAR + VariableDecl struct { + NodeAttributes + Names []Ident + Type TypeInfo + Initializer Expression + } + + // ConstDecl + // Deprecated use GenDecl with Token as token.CONST + ConstDecl struct { + NodeAttributes + Names []Ident + Type option.Option[TypeInfo] + Initializer Expression + } + + GenDecl struct { + NodeAttributes + Token token.Token + Specs []Spec + } + + EnumDecl struct { + NodeAttributes + Name string + BaseType TypeInfo + Properties []EnumProperty + Members []EnumMember + } + + FaultDecl struct { + NodeAttributes + Name Ident + BackingType option.Option[TypeInfo] + Members []FaultMember + } + + MacroDecl struct { + NodeAttributes + Signature MacroSignature + Body Block + } + + DefDecl struct { + NodeAttributes + Name Ident + resolvesTo string + resolvesToType option.Option[TypeInfo] + } + + StructDecl struct { + NodeAttributes + Name string + BackingType option.Option[TypeInfo] + Members []StructMemberDecl + StructType StructType + Implements []string + } + + FunctionDecl struct { + NodeAttributes + ParentTypeId option.Option[Ident] + Signature FunctionSignature + Body Node + } + + InterfaceDecl struct { + NodeAttributes + Name Ident + Methods []FunctionSignature + } +) + +func (v *VariableDecl) declNode() {} +func (v *ConstDecl) declNode() {} +func (v *EnumDecl) declNode() {} +func (v *FaultDecl) declNode() {} +func (v *StructDecl) declNode() {} +func (v *DefDecl) declNode() {} +func (v *MacroDecl) declNode() {} + +func (v *FunctionDecl) declNode() {} +func (v *InterfaceDecl) declNode() {} diff --git a/server/internal/lsp/ast/ast_expression.go b/server/internal/lsp/ast/ast_expression.go new file mode 100644 index 0000000..1cf5921 --- /dev/null +++ b/server/internal/lsp/ast/ast_expression.go @@ -0,0 +1,307 @@ +package ast + +import ( + "github.com/pherrymason/c3-lsp/pkg/option" + "go/token" +) + +// ------------------------------------------------------------------------- +// Expressions and types + +// Field : A Field represents a Field declaration list in a struct type, ¿TODO? +// FieldList : A FieldList represents a list of Fields enclosed by parenthesis, curly +// braces or square braces, ¿TODO? + +// An expression is represented by a tree consisting of one +// or more of the following concrete expression nodes. +type ( + Ident struct { + NodeAttributes + Name string // Identifier name + ModulePath string // Module path. Some identifiers, specify module path. + } + Path struct { + NodeAttributes + PathType int + Path string + PathStart string + PathEnd string + FieldName string + } + + SelectorExpr struct { + NodeAttributes + X Expression + Sel Ident + } + + // Ellipsis TODO + + // Literal + // Deprecated use BasicLit + Literal struct { + NodeAttributes + Value string + } + + // IntegerLiteral + // Deprecated use BasicLit + IntegerLiteral struct { + NodeAttributes + Value string + } + + // RealLiteral + // Deprecated use BasicLit + RealLiteral struct { + NodeAttributes + Value string + } + + // BoolLiteral + // Deprecated use BasicLit + BoolLiteral struct { + NodeAttributes + Value bool + } + + BasicLit struct { + NodeAttributes + Kind token.Token // token.INT, token.FLOAT, token.IMAG, token.CHAR, or token.STRING + Value string // literal string + } + + CompositeLiteral struct { + NodeAttributes + Elements []Expression // list of composite elements + } + + IndexAccessExpr struct { + NodeAttributes + Array Expression + Index string + } + + // RangeAccessExpr TODO Replace by RangeIndexExpr + RangeAccessExpr struct { + NodeAttributes + Array Expression + RangeStart uint + RangeEnd uint + } + + // RangeIndexExpr TODO document this node + RangeIndexExpr struct { + NodeAttributes + + Start option.Option[uint] + End option.Option[uint] + } + + // SubscriptExpression TODO document this node + SubscriptExpression struct { + NodeAttributes + Argument Expression + Index Expression // Index can be another expression: + // - IntegerLiteral + // - RangeIndexExpr + // - Ident + // - CallExpression + // - ... + } + + // FieldAccessExpr TODO document this node + FieldAccessExpr struct { + NodeAttributes + Object Expression + Field Expression + } + + // A FunctionCall node represents an expression followed by an argument list. + FunctionCall struct { + NodeAttributes + Identifier Expression + GenericArguments option.Option[[]Expression] + Arguments []Expression + TrailingBlock option.Option[*CompoundStmt] + } + + LambdaDeclarationExpr struct { + NodeAttributes + Parameters []FunctionParameter + ReturnType option.Option[TypeInfo] + Body Statement + } + + // A UnaryExpression + UnaryExpression struct { + NodeAttributes + Operator string + Argument Expression + } + + // BinaryExpression represents a binary expression (like sum, subtract, etc.) + BinaryExpression struct { + NodeAttributes + Left Node + Operator string + Right Node + } + + OptionalExpression struct { + NodeAttributes + Argument Expression + Operator string + } + + CastExpression struct { + NodeAttributes + Type TypeInfo + Argument Expression + } + + RethrowExpression struct { + NodeAttributes + Operator string + Argument Expression + } + + TernaryExpression struct { + NodeAttributes + Condition Expression + Consequence Expression + Alternative Expression + } + + UpdateExpression struct { + NodeAttributes + Operator string + Argument Expression + } + + // InlineTypeWithInitialization + // TODO I thing this is a Statement + InlineTypeWithInitialization struct { + NodeAttributes + Type TypeInfo + InitializerList *InitializerList + } + + // InitializerList + // TODO I thing this is a Statement + InitializerList struct { + NodeAttributes + Args []Expression + } + + ArgParamPathSet struct { + NodeAttributes + Path string + Expr Expression + } + + ArgFieldSet struct { + NodeAttributes + FieldName string + Expr Expression + } +) + +const ( + PathTypeIndexed = iota + PathTypeField + PathTypeRange +) + +func (arg *ArgFieldSet) SetExpr(expr Expression) { + arg.Expr = expr +} + +// A type is represented by a tree consisting of one +// or more of the following type-specific expression nodes. +type ( + TypeInfo struct { + NodeAttributes + ResolveStatus int + Identifier Ident + Pointer uint + Optional bool + BuiltIn bool + Static bool + Reference bool + TLocal bool + Generics []TypeInfo + } + + ArrayType struct { + NodeAttributes + Len Expression // length of the array + Elt Expression // element type + } + + bStructType struct { + NodeAttributes + Fields []Expression + } + + /* + FuncType struct { + NodeAttributes + Params []Expression + Result []Expression + } + */ + FunctionSignature struct { + NodeAttributes + Name Ident + Parameters []FunctionParameter + ReturnType TypeInfo + } + + InterfaceType struct { + NodeAttributes + Methods []Expression + } + + // TrailingGenericsExpr Used only as a temporal container. + // It is decomposed and its info extracted to build other ast nodes. + TrailingGenericsExpr struct { + NodeAttributes + Identifier Ident + GenericArguments []Expression + } +) + +func (*ArgFieldSet) exprNode() {} +func (*ArgParamPathSet) exprNode() {} +func (Ident) exprNode() {} +func (SelectorExpr) exprNode() {} +func (Path) exprNode() {} +func (e *BasicLit) exprNode() {} +func (l *Literal) exprNode() {} +func (l *IntegerLiteral) exprNode() {} +func (l *RealLiteral) exprNode() {} +func (l *BoolLiteral) exprNode() {} +func (l *CompositeLiteral) exprNode() {} +func (l *IndexAccessExpr) exprNode() {} +func (l *RangeAccessExpr) exprNode() {} +func (l *RangeIndexExpr) exprNode() {} +func (l *SubscriptExpression) exprNode() {} +func (l *FieldAccessExpr) exprNode() {} +func (l *FunctionCall) exprNode() {} +func (v *LambdaDeclarationExpr) exprNode() {} +func (l *UnaryExpression) exprNode() {} +func (l *BinaryExpression) exprNode() {} +func (l *OptionalExpression) exprNode() {} +func (l *CastExpression) exprNode() {} +func (l *RethrowExpression) exprNode() {} +func (l *TernaryExpression) exprNode() {} +func (l *UpdateExpression) exprNode() {} + +func (TypeInfo) exprNode() {} +func (*InitializerList) exprNode() {} +func (*InlineTypeWithInitialization) exprNode() {} +func (l *ArrayType) exprNode() {} +func (l *bStructType) exprNode() {} +func (l *InterfaceType) exprNode() {} +func (l *TrailingGenericsExpr) exprNode() {} diff --git a/server/internal/lsp/ast/ast_statement.go b/server/internal/lsp/ast/ast_statement.go new file mode 100644 index 0000000..09656a0 --- /dev/null +++ b/server/internal/lsp/ast/ast_statement.go @@ -0,0 +1,161 @@ +package ast + +import "github.com/pherrymason/c3-lsp/pkg/option" + +// ---------------------------------------------------------------------------- +// Statements + +// A statement is represented by a tree consisting of one +// or more of the following concrete statement nodes. +type ( + // An ExpressionStmt represents (stand-alone) expression + // in a statement list. + ExpressionStmt struct { + NodeAttributes + Expr Expression + } + + // A BlockStmt represents a braced statement list + BlockStmt struct { + NodeAttributes + List []Statement + } + + // A CompoundStmt TODO What's the difference with BlockStmt? + CompoundStmt struct { + NodeAttributes + Statements []Statement + } + + // DeclarationStmt represents a declaration in a statement list + DeclarationStmt struct { + NodeAttributes + Decl Declaration + } + + IfStmt struct { + NodeAttributes + Label option.Option[string] + Condition []Expression + Statement Statement + Else ElseStatement + } + + ElseStatement struct { + NodeAttributes + Statement Statement + } + + ReturnStatement struct { + NodeAttributes + Return option.Option[Expression] + } + + AssignmentStatement struct { + NodeAttributes + Left Expression + Right Expression + Operator string + } + + ContinueStatement struct { + NodeAttributes + Label option.Option[string] + } + + BreakStatement struct { + NodeAttributes + Label option.Option[string] + } + + SwitchStatement struct { + NodeAttributes + Label option.Option[string] + Condition Expression + Cases []SwitchCase + Default []Statement + } + + SwitchCase struct { + NodeAttributes + Value Statement + Statements []Statement + } + + SwitchCaseRange struct { + NodeAttributes + Start Expression + End Expression + } + + Nextcase struct { + NodeAttributes + Label option.Option[string] + Value Expression + } + + ForStatement struct { + NodeAttributes + Label option.Option[string] + Initializer []Statement + Condition Expression + Update []Statement + Body Statement + } + + ForeachStatement struct { + NodeAttributes + Value ForeachValue + Index ForeachValue + Collection Expression + Body Statement + } + + ForeachValue struct { + Type TypeInfo + Identifier Ident + } + + WhileStatement struct { + NodeAttributes + Condition []Expression + Body Statement + } + + DoStatement struct { + NodeAttributes + Condition Expression + Body Statement + } + + DeferStatement struct { + NodeAttributes + Statement Statement + } + + AssertStatement struct { + NodeAttributes + Assertions []Expression + } +) + +func (e *ExpressionStmt) stmtNode() {} +func (e *BlockStmt) stmtNode() {} +func (e *CompoundStmt) stmtNode() {} +func (e *DeclarationStmt) stmtNode() {} +func (e *IfStmt) stmtNode() {} +func (e *ElseStatement) stmtNode() {} +func (e *ReturnStatement) stmtNode() {} +func (e *AssignmentStatement) stmtNode() {} +func (e *ContinueStatement) stmtNode() {} +func (e *BreakStatement) stmtNode() {} +func (e *SwitchStatement) stmtNode() {} +func (e *SwitchCase) stmtNode() {} +func (e *SwitchCaseRange) stmtNode() {} +func (e *Nextcase) stmtNode() {} +func (e *ForStatement) stmtNode() {} +func (e *ForeachStatement) stmtNode() {} +func (e *WhileStatement) stmtNode() {} +func (e *DoStatement) stmtNode() {} +func (e *DeferStatement) stmtNode() {} +func (e *AssertStatement) stmtNode() {} diff --git a/server/internal/lsp/ast/ast_visitors.go b/server/internal/lsp/ast/ast_visitors.go index a402c5a..db80532 100644 --- a/server/internal/lsp/ast/ast_visitors.go +++ b/server/internal/lsp/ast/ast_visitors.go @@ -15,16 +15,16 @@ type ASTVisitor interface { VisitFaultDecl(node *FaultDecl) VisitDefDecl(node *DefDecl) VisitMacroDecl(node *MacroDecl) - VisitLambdaDeclaration(node *LambdaDeclaration) + VisitLambdaDeclaration(node *LambdaDeclarationExpr) VisitFunctionDecl(node *FunctionDecl) VisitFunctionParameter(node *FunctionParameter) VisitFunctionCall(node *FunctionCall) VisitInterfaceDecl(node *InterfaceDecl) - VisitCompounStatement(node *CompoundStatement) + VisitCompounStatement(node *CompoundStmt) VisitType(node *TypeInfo) - VisitIdentifier(node *Identifier) + VisitIdentifier(node *Ident) VisitBinaryExpression(node *BinaryExpression) - VisitIfStatement(node *IfStatement) + VisitIfStatement(node *IfStmt) VisitIntegerLiteral(node *IntegerLiteral) } @@ -34,44 +34,34 @@ type VisitableNode interface { // ---------------------------------------- -func Visit(node ASTNode, v ASTVisitor) { - switch node.TypeNode() { - case TypeFile: +func Visit(node Node, v ASTVisitor) { + switch node.(type) { + case *File: v.VisitFile(node.(*File)) - case TypeModule: + case *Module: v.VisitModule(node.(*Module)) - case TypeVariableDecl: + case *VariableDecl: v.VisitVariableDeclaration(node.(*VariableDecl)) - case TypeFunctionDecl: - n := node.(FunctionDecl) - v.VisitFunctionDecl(&n) + case *FunctionDecl: + n := node.(*FunctionDecl) + v.VisitFunctionDecl(n) - case TypeFunctionParameter: - n := node.(FunctionParameter) - v.VisitFunctionParameter(&n) + case *FunctionParameter: + n := node.(*FunctionParameter) + v.VisitFunctionParameter(n) - case TypeLambdaDecl: - v.VisitLambdaDeclaration(node.(*LambdaDeclaration)) + case *LambdaDeclarationExpr: + v.VisitLambdaDeclaration(node.(*LambdaDeclarationExpr)) - case TypeCompoundStatement: - var arg *CompoundStatement - switch node.(type) { - case CompoundStatement: - n := node.(CompoundStatement) - arg = &n - case *CompoundStatement: - arg = node.(*CompoundStatement) - } - v.VisitCompounStatement(arg) + case *CompoundStmt: + v.VisitCompounStatement(node.(*CompoundStmt)) - case TypeTypeInfo: - n := node.(*TypeInfo) - v.VisitType(n) + case *TypeInfo: + v.VisitType(node.(*TypeInfo)) - case TypeIntegerLiteral: - n := node.(IntegerLiteral) - v.VisitIntegerLiteral(&n) + case *IntegerLiteral: + v.VisitIntegerLiteral(node.(*IntegerLiteral)) default: log.Print("type not found") } diff --git a/server/internal/lsp/ast/convert.go b/server/internal/lsp/ast/convert.go index 686ce91..94a464d 100644 --- a/server/internal/lsp/ast/convert.go +++ b/server/internal/lsp/ast/convert.go @@ -25,8 +25,8 @@ func ConvertToAST(cstNode *sitter.Node, sourceCode string, fileName string) File //fmt.Print(cstNode) if cstNode.Type() == "source_file" { prg = File{ - Name: fileName, - ASTBaseNode: NewBaseNodeBuilder(TypeFile).WithSitterPos(cstNode).Build(), + Name: fileName, + NodeAttributes: NewBaseNodeBuilder().WithSitterPos(cstNode).Build(), } } @@ -38,8 +38,8 @@ func ConvertToAST(cstNode *sitter.Node, sourceCode string, fileName string) File anonymousModule = true prg.Modules = append(prg.Modules, Module{ - ASTBaseNode: NewBaseNodeBuilder(TypeModule).WithStartEnd(uint(node.StartPoint().Row), uint(node.StartPoint().Column), 0, 0).Build(), - Name: symbols.NormalizeModuleName(fileName), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(uint(node.StartPoint().Row), uint(node.StartPoint().Column), 0, 0).Build(), + Name: symbols.NormalizeModuleName(fileName), }, ) parsedModules = len(prg.Modules) @@ -54,13 +54,13 @@ func ConvertToAST(cstNode *sitter.Node, sourceCode string, fileName string) File case "module": if anonymousModule { anonymousModule = false - lastMod.ASTBaseNode.EndPos = Position{uint(node.StartPoint().Row), uint(node.StartPoint().Column)} + lastMod.NodeAttributes.EndPos = Position{uint(node.StartPoint().Row), uint(node.StartPoint().Column)} } prg.Modules = append(prg.Modules, convert_module(node, source)) case "import_declaration": - lastMod.Imports = append(lastMod.Imports, convert_imports(node, source).(Import)) + lastMod.Imports = append(lastMod.Imports, convert_imports(node, source).(*Import)) case "global_declaration": variable := convert_global_declaration(node, source) @@ -85,13 +85,13 @@ func ConvertToAST(cstNode *sitter.Node, sourceCode string, fileName string) File lastMod.Declarations = append(lastMod.Declarations, convert_def_declaration(node, source)) case "func_definition", "func_declaration": - lastMod.Functions = append(lastMod.Functions, convert_function_declaration(node, source)) + lastMod.Declarations = append(lastMod.Declarations, convert_function_declaration(node, source)) case "interface_declaration": lastMod.Declarations = append(lastMod.Declarations, convert_interface_declaration(node, source)) case "macro_declaration": - lastMod.Macros = append(lastMod.Macros, convert_macro_declaration(node, source)) + lastMod.Declarations = append(lastMod.Declarations, convert_macro_declaration(node, source)) } } @@ -100,15 +100,17 @@ func ConvertToAST(cstNode *sitter.Node, sourceCode string, fileName string) File func convertSourceFile(node *sitter.Node, source []byte) File { file := File{} - file.SetPos(node.StartPoint(), node.EndPoint()) + //file.SetPos(node.StartPoint(), node.EndPoint()) + ChangeNodePosition(&file.NodeAttributes, node.StartPoint(), node.EndPoint()) return file } func convert_module(node *sitter.Node, source []byte) Module { - module := Module{ASTBaseNode: NewBaseNodeBuilder(TypeModule).Build()} + module := Module{NodeAttributes: NewBaseNodeBuilder().Build()} module.Name = node.ChildByFieldName("path").Content(source) - module.SetPos(node.StartPoint(), node.EndPoint()) + //module.SetPos(node.StartPoint(), node.EndPoint()) + ChangeNodePosition(&module.NodeAttributes, node.StartPoint(), node.EndPoint()) for i := 0; i < int(node.ChildCount()); i++ { child := node.Child(i) @@ -132,8 +134,8 @@ func convert_module(node *sitter.Node, source []byte) Module { return module } -func convert_imports(node *sitter.Node, source []byte) Expression { - imports := Import{ +func convert_imports(node *sitter.Node, source []byte) Statement { + imports := &Import{ Path: node.ChildByFieldName("path").Content(source), } @@ -142,8 +144,8 @@ func convert_imports(node *sitter.Node, source []byte) Expression { func convert_global_declaration(node *sitter.Node, source []byte) VariableDecl { variable := VariableDecl{ - Names: []Identifier{}, - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl). + Names: []Ident{}, + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(node.StartPoint(), node.EndPoint()). Build(), } @@ -153,12 +155,12 @@ func convert_global_declaration(node *sitter.Node, source []byte) VariableDecl { //debugNode(n, source) switch n.Type() { case "type": - variable.Type = convert_type(n, source).(TypeInfo) + variable.Type = convert_type(n, source) case "ident": variable.Names = append( variable.Names, - convert_ident(n, source).(Identifier), + convert_ident(n, source).(Ident), ) case ";": @@ -169,7 +171,7 @@ func convert_global_declaration(node *sitter.Node, source []byte) VariableDecl { if sub.Type() == "ident" { variable.Names = append( variable.Names, - convert_ident(sub, source).(Identifier), + convert_ident(sub, source).(Ident), ) } } @@ -186,16 +188,16 @@ func convert_global_declaration(node *sitter.Node, source []byte) VariableDecl { right := node.ChildByFieldName("right") if right != nil { - variable.Initializer = convert_expression(right, source) + variable.Initializer = convert_expression(right, source).(Expression) } return variable } -func convert_enum_declaration(node *sitter.Node, sourceCode []byte) Expression { - enumDecl := EnumDecl{ +func convert_enum_declaration(node *sitter.Node, sourceCode []byte) Declaration { + enumDecl := &EnumDecl{ Name: node.ChildByFieldName("name").Content(sourceCode), - ASTBaseNode: NewBaseNodeBuilder(TypeEnumDecl). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(node.StartPoint(), node.EndPoint()). Build(), } @@ -204,29 +206,24 @@ func convert_enum_declaration(node *sitter.Node, sourceCode []byte) Expression { n := node.Child(i) switch n.Type() { case "enum_spec": - enumDecl.BaseType = convert_type(n.Child(1), sourceCode).(TypeInfo) + enumDecl.BaseType = convert_type(n.Child(1), sourceCode) if n.ChildCount() >= 3 { param_list := n.Child(2) for p := 0; p < int(param_list.ChildCount()); p++ { paramNode := param_list.Child(p) if paramNode.Type() == "enum_param_declaration" { + convertType := convert_type(paramNode.Child(0), sourceCode) enumDecl.Properties = append( enumDecl.Properties, EnumProperty{ - ASTBaseNode: NewBaseNodeBuilder(TypeEnumProperty). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(paramNode.StartPoint(), paramNode.EndPoint()). Build(), Name: NewIdentifierBuilder(). WithName(paramNode.Child(1).Content(sourceCode)). WithSitterPos(paramNode). Build(), - /*Identifier{ - Name: paramNode.Child(1).Content(sourceCode), - ASTBaseNode: NewBaseNodeBuilder(). - WithSitterPosRange(paramNode.Child(1).StartPoint(), paramNode.Child(1).EndPoint()). - Build(), - },*/ - Type: convert_type(paramNode.Child(0), sourceCode).(TypeInfo), + Type: convertType, }, ) } @@ -246,7 +243,7 @@ func convert_enum_declaration(node *sitter.Node, sourceCode []byte) Expression { for a := 0; a < int(args.ChildCount()); a++ { arg := args.Child(a) if arg.Type() == "arg" { - compositeLiteral.Values = append(compositeLiteral.Values, + compositeLiteral.Elements = append(compositeLiteral.Elements, convert_literal(arg.Child(0), sourceCode), ) } @@ -260,14 +257,8 @@ func convert_enum_declaration(node *sitter.Node, sourceCode []byte) Expression { WithName(name.Content(sourceCode)). WithSitterPos(name). Build(), - /*Identifier{ - Name: name.Content(sourceCode), - ASTBaseNode: NewBaseNodeBuilder(). - WithSitterPosRange(name.StartPoint(), name.EndPoint()). - Build(), - },*/ Value: compositeLiteral, - ASTBaseNode: NewBaseNodeBuilder(TypeEnumProperty). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(enumeratorNode.StartPoint(), enumeratorNode.EndPoint()). Build(), }, @@ -280,9 +271,9 @@ func convert_enum_declaration(node *sitter.Node, sourceCode []byte) Expression { return enumDecl } -func convert_struct_declaration(node *sitter.Node, sourceCode []byte) Expression { +func convert_struct_declaration(node *sitter.Node, sourceCode []byte) Declaration { structDecl := StructDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeStructDecl). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(node.StartPoint(), node.EndPoint()). Build(), StructType: StructTypeNormal, @@ -322,7 +313,7 @@ func convert_struct_declaration(node *sitter.Node, sourceCode []byte) Expression fieldType := TypeInfo{} member := StructMemberDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeStructMemberDecl). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(memberNode.StartPoint(), memberNode.EndPoint()). Build(), } @@ -333,13 +324,13 @@ func convert_struct_declaration(node *sitter.Node, sourceCode []byte) Expression switch n.Type() { case "type": - fieldType = convert_type(n, sourceCode).(TypeInfo) + fieldType = convert_type(n, sourceCode) member.Type = fieldType case "identifier_list": for j := 0; j < int(n.ChildCount()); j++ { member.Names = append( member.Names, - convert_ident(n.Child(j), sourceCode).(Identifier), + convert_ident(n.Child(j), sourceCode).(Ident), ) } case "attributes": @@ -355,7 +346,7 @@ func convert_struct_declaration(node *sitter.Node, sourceCode []byte) Expression case "ident": member.Names = append(member.Names, - convert_ident(n, sourceCode).(Identifier), + convert_ident(n, sourceCode).(Ident), ) } } @@ -365,13 +356,13 @@ func convert_struct_declaration(node *sitter.Node, sourceCode []byte) Expression } } - return structDecl + return &structDecl } -func convert_bitstruct_declaration(node *sitter.Node, sourceCode []byte) Expression { +func convert_bitstruct_declaration(node *sitter.Node, sourceCode []byte) Declaration { structDecl := StructDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeStructDecl).WithSitterPosRange(node.StartPoint(), node.EndPoint()).Build(), - StructType: StructTypeBitStruct, + NodeAttributes: NewBaseNodeBuilder().WithSitterPosRange(node.StartPoint(), node.EndPoint()).Build(), + StructType: StructTypeBitStruct, } for i := 0; i < int(node.ChildCount()); i++ { @@ -392,14 +383,14 @@ func convert_bitstruct_declaration(node *sitter.Node, sourceCode []byte) Express // TODO attributes case "type": - structDecl.BackingType = option.Some(convert_type(child, sourceCode).(TypeInfo)) + structDecl.BackingType = option.Some(convert_type(child, sourceCode)) case "bitstruct_body": structDecl.Members = convert_bitstruct_members(child, sourceCode) } } - return structDecl + return &structDecl } func convert_bitstruct_members(node *sitter.Node, source []byte) []StructMemberDecl { @@ -409,7 +400,7 @@ func convert_bitstruct_members(node *sitter.Node, source []byte) []StructMemberD //debugNode(bdefnode, source) bType := bdefnode.Type() member := StructMemberDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeStructMemberDecl). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(bdefnode.StartPoint(), bdefnode.EndPoint()). Build(), } @@ -421,11 +412,11 @@ func convert_bitstruct_members(node *sitter.Node, source []byte) []StructMemberD switch xNode.Type() { case "base_type": // Note: here we consciously pass bdefnode because typeNodeToType expects a child node of base_type. If we send xNode it will not find it. - member.Type = convert_type(bdefnode, source).(TypeInfo) + member.Type = convert_type(bdefnode, source) case "ident": member.Names = append( member.Names, - convert_ident(xNode, source).(Identifier), + convert_ident(xNode, source).(Ident), ) } } @@ -457,7 +448,7 @@ func convert_bitstruct_members(node *sitter.Node, source []byte) []StructMemberD return members } -func convert_fault_declaration(node *sitter.Node, sourceCode []byte) Expression { +func convert_fault_declaration(node *sitter.Node, sourceCode []byte) Declaration { // TODO parse attributes baseType := option.None[TypeInfo]() // TODO Parse type! @@ -477,7 +468,7 @@ func convert_fault_declaration(node *sitter.Node, sourceCode []byte) Expression WithName(constantNode.Content(sourceCode)). WithSitterPos(constantNode). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFaultMemberDecl). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(constantNode.StartPoint(), constantNode.EndPoint()). Build(), }, @@ -488,14 +479,14 @@ func convert_fault_declaration(node *sitter.Node, sourceCode []byte) Expression } nameNode := node.ChildByFieldName("name") - fault := FaultDecl{ + fault := &FaultDecl{ Name: NewIdentifierBuilder(). WithName(nameNode.Content(sourceCode)). WithSitterPos(nameNode). Build(), BackingType: baseType, Members: constants, - ASTBaseNode: NewBaseNodeBuilder(TypeFaultDecl). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPos(node). Build(), } @@ -503,10 +494,10 @@ func convert_fault_declaration(node *sitter.Node, sourceCode []byte) Expression return fault } -func convert_const_declaration(node *sitter.Node, source []byte) Expression { - constant := ConstDecl{ - Names: []Identifier{}, - ASTBaseNode: NewBaseNodeBuilder(TypeConstDecl). +func convert_const_declaration(node *sitter.Node, source []byte) Declaration { + constant := &ConstDecl{ + Names: []Ident{}, + NodeAttributes: NewBaseNodeBuilder(). WithSitterPos(node). Build(), } @@ -521,7 +512,7 @@ func convert_const_declaration(node *sitter.Node, source []byte) Expression { n := node.Child(i) switch n.Type() { case "type": - constant.Type = option.Some(convert_type(n, source).(TypeInfo)) + constant.Type = option.Some(convert_type(n, source)) case "const_ident": idNode = n @@ -540,7 +531,7 @@ func convert_const_declaration(node *sitter.Node, source []byte) Expression { right := node.ChildByFieldName("right") if right != nil { - constant.Initializer = convert_expression(right, source) + constant.Initializer = convert_expression(right, source).(Expression) } return constant @@ -555,7 +546,7 @@ define_declaration [13, 0] - [13, 15] base_type [13, 11] - [13, 14] base_type_name [13, 11] - [13, 14] */ -func convert_def_declaration(node *sitter.Node, sourceCode []byte) Expression { +func convert_def_declaration(node *sitter.Node, sourceCode []byte) Declaration { defBuilder := NewDefDeclBuilder(). WithSitterPos(node) @@ -570,7 +561,7 @@ func convert_def_declaration(node *sitter.Node, sourceCode []byte) Expression { var _type TypeInfo if n.Child(0).Type() == "type" { // Might contain module path - _type = convert_type(n.Child(0), sourceCode).(TypeInfo) + _type = convert_type(n.Child(0), sourceCode) defBuilder.WithResolvesToType(_type) } else if n.Child(0).Type() == "func_typedef" { // TODO Parse full info of this func typedefinition @@ -579,12 +570,13 @@ func convert_def_declaration(node *sitter.Node, sourceCode []byte) Expression { } } - return defBuilder.Build() + def := defBuilder.Build() + return &def } -func convert_interface_declaration(node *sitter.Node, sourceCode []byte) Expression { +func convert_interface_declaration(node *sitter.Node, sourceCode []byte) Declaration { // TODO parse attributes - methods := []FunctionSignature{} + var methods []FunctionSignature for i := 0; i < int(node.ChildCount()); i++ { n := node.Child(i) switch n.Type() { @@ -600,19 +592,19 @@ func convert_interface_declaration(node *sitter.Node, sourceCode []byte) Express } nameNode := node.ChildByFieldName("name") - _interface := InterfaceDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeInterfaceDecl).WithSitterPos(node).Build(), - Name: NewIdentifierBuilder().WithName(nameNode.Content(sourceCode)).WithSitterPos(nameNode).Build(), - Methods: methods, + _interface := &InterfaceDecl{ + NodeAttributes: NewBaseNodeBuilder().WithSitterPos(node).Build(), + Name: NewIdentifierBuilder().WithName(nameNode.Content(sourceCode)).WithSitterPos(nameNode).Build(), + Methods: methods, } return _interface } -func convert_macro_declaration(node *sitter.Node, sourceCode []byte) Expression { +func convert_macro_declaration(node *sitter.Node, sourceCode []byte) Declaration { var nameNode *sitter.Node - parameters := []FunctionParameter{} + var parameters []FunctionParameter nodeParameters := node.Child(2) if nodeParameters.ChildCount() > 2 { for i := uint32(0); i < nodeParameters.ChildCount(); i++ { @@ -623,14 +615,14 @@ func convert_macro_declaration(node *sitter.Node, sourceCode []byte) Expression parameters = append( parameters, - convert_function_parameter(argNode, option.None[Identifier](), sourceCode), + convert_function_parameter(argNode, option.None[Ident](), sourceCode), ) } } nameNode = node.Child(1).ChildByFieldName("name") - macro := MacroDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeMacroDecl).WithSitterPos(node).Build(), + macro := &MacroDecl{ + NodeAttributes: NewBaseNodeBuilder().WithSitterPos(node).Build(), Signature: MacroSignature{ Name: NewIdentifierBuilder(). WithName(nameNode.Content(sourceCode)). @@ -675,15 +667,17 @@ func convert_ident(node *sitter.Node, source []byte) Expression { Build() } -func convert_type(node *sitter.Node, sourceCode []byte) Expression { +func convert_type(node *sitter.Node, sourceCode []byte) TypeInfo { return extTypeNodeToType(node, sourceCode) } -func convert_var_decl(node *sitter.Node, source []byte) Expression { +func convert_var_decl(node *sitter.Node, source []byte) Declaration { //for i := 0; i < int(node.ChildCount()); i++ { //} - return ASTBaseNode{} + decl := &VariableDecl{} + + return decl } func extTypeNodeToType( @@ -692,7 +686,7 @@ func extTypeNodeToType( ) TypeInfo { typeInfo := TypeInfo{ Optional: false, - ASTBaseNode: NewBaseNodeBuilder(TypeTypeInfo). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(node.StartPoint(), node.EndPoint()). Build(), Pointer: uint(0), @@ -703,7 +697,7 @@ func extTypeNodeToType( //fmt.Println(n.Type(), n.Content(sourceCode)) switch n.Type() { case "base_type": - typeInfo.ASTBaseNode = NewBaseNodeBuilder(TypeTypeInfo). + typeInfo.NodeAttributes = NewBaseNodeBuilder(). WithSitterPosRange(n.StartPoint(), n.EndPoint()). Build() @@ -727,7 +721,7 @@ func extTypeNodeToType( for g := 0; g < int(bn.ChildCount()); g++ { gn := bn.Child(g) if gn.Type() == "type" { - gType := convert_type(gn, sourceCode).(TypeInfo) + gType := convert_type(gn, sourceCode) typeInfo.Generics = append(typeInfo.Generics, gType) } } @@ -756,18 +750,8 @@ func extTypeNodeToType( return typeInfo } -func inArray(needle string, haystack []string) bool { - for _, item := range haystack { - if item == needle { - return true - } - } - - return false -} - -func convert_function_declaration(node *sitter.Node, source []byte) Expression { - var typeIdentifier option.Option[Identifier] +func convert_function_declaration(node *sitter.Node, source []byte) Declaration { + var typeIdentifier option.Option[Ident] funcHeader := node.Child(1) //debugNode(funcHeader, source) @@ -780,7 +764,7 @@ func convert_function_declaration(node *sitter.Node, source []byte) Expression { signature := convert_function_signature(node, source) bodyNode := node.ChildByFieldName("body") - var body Expression + var body Node if bodyNode != nil { n := bodyNode.Child(0) // options @@ -793,11 +777,11 @@ func convert_function_declaration(node *sitter.Node, source []byte) Expression { } } - funcDecl := FunctionDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionDecl).WithSitterPos(node).Build(), - ParentTypeId: typeIdentifier, - Signature: signature, - Body: body, + funcDecl := &FunctionDecl{ + NodeAttributes: NewBaseNodeBuilder().WithSitterPos(node).Build(), + ParentTypeId: typeIdentifier, + Signature: signature, + Body: body, } /* @@ -814,7 +798,7 @@ func convert_function_declaration(node *sitter.Node, source []byte) Expression { } func convert_function_signature(node *sitter.Node, sourceCode []byte) FunctionSignature { - var typeIdentifier option.Option[Identifier] + var typeIdentifier option.Option[Ident] funcHeader := node.Child(1) nameNode := funcHeader.ChildByFieldName("name") @@ -830,9 +814,9 @@ func convert_function_signature(node *sitter.Node, sourceCode []byte) FunctionSi WithName(nameNode.Content(sourceCode)). WithSitterPos(nameNode). Build(), - ReturnType: convert_type(funcHeader.ChildByFieldName("return_type"), sourceCode).(TypeInfo), + ReturnType: convert_type(funcHeader.ChildByFieldName("return_type"), sourceCode), Parameters: convert_function_parameter_list(node.Child(2), typeIdentifier, sourceCode), - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionSignature). + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(node.StartPoint(), node.EndPoint()). Build(), } @@ -840,14 +824,14 @@ func convert_function_signature(node *sitter.Node, sourceCode []byte) FunctionSi return signatureDecl } -func convert_function_parameter_list(node *sitter.Node, typeIdentifier option.Option[Identifier], source []byte) []FunctionParameter { +func convert_function_parameter_list(node *sitter.Node, typeIdentifier option.Option[Ident], source []byte) []FunctionParameter { if node.Type() != "fn_parameter_list" { panic( fmt.Sprintf("Wrong node provided: Expected fn_parameter_list, provided %s", node.Type()), ) } - parameters := []FunctionParameter{} + var parameters []FunctionParameter if node.ChildCount() > 2 { for i := 0; i < int(node.ChildCount()); i++ { argNode := node.Child(i) @@ -885,8 +869,8 @@ func convert_function_parameter_list(node *sitter.Node, typeIdentifier option.Op seq($.ct_ident, '...'), // 2 ), */ -func convert_function_parameter(argNode *sitter.Node, methodIdentifier option.Option[Identifier], sourceCode []byte) FunctionParameter { - var identifier Identifier +func convert_function_parameter(argNode *sitter.Node, methodIdentifier option.Option[Ident], sourceCode []byte) FunctionParameter { + var identifier Ident var argType TypeInfo ampersandFound := false @@ -898,7 +882,7 @@ func convert_function_parameter(argNode *sitter.Node, methodIdentifier option.Op ampersandFound = true case "type": - argType = convert_type(n, sourceCode).(TypeInfo) + argType = convert_type(n, sourceCode) case "ident": identifier = NewIdentifierBuilder(). WithName(n.Content(sourceCode)). @@ -917,17 +901,17 @@ func convert_function_parameter(argNode *sitter.Node, methodIdentifier option.Op WithName(methodIdentifier.Get().Name). WithSitterPos(n). Build(), - Pointer: pointer, - ASTBaseNode: NewBaseNodeBuilder(TypeTypeInfo).WithSitterPos(argNode).Build(), + Pointer: pointer, + NodeAttributes: NewBaseNodeBuilder().WithSitterPos(argNode).Build(), } } } } variable := FunctionParameter{ - Name: identifier, - Type: argType, - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter).WithSitterPos(argNode).Build(), + Name: identifier, + Type: argType, + NodeAttributes: NewBaseNodeBuilder().WithSitterPos(argNode).Build(), } return variable @@ -935,33 +919,33 @@ func convert_function_parameter(argNode *sitter.Node, methodIdentifier option.Op func convert_lambda_declaration(node *sitter.Node, source []byte) Expression { rType := option.None[TypeInfo]() - parameters := []FunctionParameter{} + var parameters []FunctionParameter for i := 0; i < int(node.ChildCount()); i++ { n := node.Child(i) switch n.Type() { case "type", "optional_type": - r := convert_type(n, source).(TypeInfo) + r := convert_type(n, source) rType = option.Some[TypeInfo](r) case "fn_parameter_list": - parameters = convert_function_parameter_list(n, option.None[Identifier](), source) + parameters = convert_function_parameter_list(n, option.None[Ident](), source) case "attributes": // TODO } } - return LambdaDeclaration{ - ASTBaseNode: NewBaseNodeBuilder(TypeLambdaDecl).WithSitterPos(node).Build(), - ReturnType: rType, - Parameters: parameters, + return &LambdaDeclarationExpr{ + NodeAttributes: NewBaseNodeBuilder().WithSitterPos(node).Build(), + ReturnType: rType, + Parameters: parameters, } } func convert_lambda_declaration_with_body(node *sitter.Node, source []byte) Expression { expression := convert_lambda_declaration(node, source) - lambda := expression.(LambdaDeclaration) - lambda.Body = convert_compound_stmt(node.NextSibling(), source).(CompoundStatement) + lambda := expression.(*LambdaDeclarationExpr) + lambda.Body = convert_compound_stmt(node.NextSibling(), source).(*CompoundStmt) return lambda } @@ -969,15 +953,16 @@ func convert_lambda_declaration_with_body(node *sitter.Node, source []byte) Expr func convert_lambda_expr(node *sitter.Node, source []byte) Expression { expr := convert_lambda_declaration(node.Child(0), source) - lambda := expr.(LambdaDeclaration) + lambda := expr.(*LambdaDeclarationExpr) bodyNode := node.Child(1).ChildByFieldName("body") - lambda.ASTBaseNode.EndPos.Column = uint(bodyNode.EndPoint().Column) - lambda.ASTBaseNode.EndPos.Line = uint(bodyNode.EndPoint().Row) - lambda.Body = ReturnStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeLambdaExpr).WithSitterPos(bodyNode).Build(), - Return: option.Some(convert_expression(bodyNode, source)), + lambda.NodeAttributes.EndPos.Column = uint(bodyNode.EndPoint().Column) + lambda.NodeAttributes.EndPos.Line = uint(bodyNode.EndPoint().Row) + expression := convert_expression(bodyNode, source).(Expression) + lambda.Body = &ReturnStatement{ + NodeAttributes: NewBaseNodeBuilder().WithSitterPos(bodyNode).Build(), + Return: option.Some(expression), } return lambda @@ -1003,7 +988,7 @@ $._base_expr, func convert_expression(node *sitter.Node, source []byte) Expression { //fmt.Print("convert_expression:\n") //debugNode(node, source) - return anyOf("_expr", []NodeRule{ + converted := anyOf("_expr", []NodeRule{ NodeOfType("assignment_expr"), NodeOfType("ternary_expr"), NodeChildWithSequenceOf([]NodeRule{ @@ -1022,14 +1007,23 @@ func convert_expression(node *sitter.Node, source []byte) Expression { NodeOfType("subscript_expr"), NodeOfType("initializer_list"), NodeTryConversionFunc("_base_expr"), - }, node, source, false) + }, node, source, true) + + return converted.(Expression) +} + +func convert_expr_stmt(node *sitter.Node, source []byte) Statement { + expr := convert_expression(node, source) + + return &ExpressionStmt{ + Expr: expr, + } } func convert_base_expression(node *sitter.Node, source []byte) Expression { - var expression Expression //debugNode(node, source) - return anyOf("_base_expr", []NodeRule{ + found := anyOf("_base_expr", []NodeRule{ NodeOfType("string_literal"), NodeOfType("char_literal"), NodeOfType("raw_string_literal"), @@ -1093,12 +1087,14 @@ func convert_base_expression(node *sitter.Node, source []byte) Expression { NodeOfType("lambda_declaration"), NodeOfType("compound_stmt"), }, "..lambda_declaration_with_body.."), - }, node, source, false) + }, node, source, true) - return expression + return found.(Expression) } -func convert_assignment_expr(node *sitter.Node, source []byte) Expression { +// convert_assignment_expr +// TODO Naming does not match with return type +func convert_assignment_expr(node *sitter.Node, source []byte) Statement { leftNode := node.ChildByFieldName("left") rightNode := node.ChildByFieldName("right") var left Expression @@ -1114,11 +1110,11 @@ func convert_assignment_expr(node *sitter.Node, source []byte) Expression { operator = node.ChildByFieldName("operator").Content(source) } - return AssignmentStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeAssignmentStatement, node), - Left: left, - Right: right, - Operator: operator, + return &AssignmentStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Left: left, + Right: right, + Operator: operator, } } @@ -1127,11 +1123,11 @@ func convert_binary_expr(node *sitter.Node, source []byte) Expression { operator := node.ChildByFieldName("operator").Content(source) right := convert_expression(node.ChildByFieldName("right"), source) - return BinaryExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeBinaryExpr, node), - Left: left, - Operator: operator, - Right: right, + return &BinaryExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Left: left, + Operator: operator, + Right: right, } } @@ -1154,22 +1150,44 @@ func convert_ternary_expr(node *sitter.Node, source []byte) Expression { } condition := anyOf("ternary_expr", expected, node.ChildByFieldName("condition"), source, false) - return TernaryExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeTernaryExpr, node), - Condition: condition, - Consequence: convert_expression(node.ChildByFieldName("consequence"), source), - Alternative: convert_expression(node.ChildByFieldName("alternative"), source), + return &TernaryExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Condition: condition.(Expression), + Consequence: convert_expression(node.ChildByFieldName("consequence"), source), + Alternative: convert_expression(node.ChildByFieldName("alternative"), source), + } +} + +func convert_field_expr(node *sitter.Node, source []byte) Expression { + argument := node.ChildByFieldName("argument") + var argumentNode Expression + if argument.Type() == "ident" { + argumentNode = NewIdentifierBuilder(). + WithName(argument.Content(source)). + WithSitterPos(argument). + Build() + } else { + + } + field := node.ChildByFieldName("field") + + return &SelectorExpr{ + X: argumentNode, + Sel: NewIdentifierBuilder(). + WithName(field.Content(source)). + WithSitterPos(field). + Build(), } } func convert_elvis_orelse_expr(node *sitter.Node, source []byte) Expression { conditionNode := node.ChildByFieldName("condition") - return TernaryExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeElvisOrElseExpr, node), - Condition: convert_expression(conditionNode, source), - Consequence: convert_ident(conditionNode, source), - Alternative: convert_expression(node.ChildByFieldName("alternative"), source), + return &TernaryExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Condition: convert_expression(conditionNode, source), + Consequence: convert_ident(conditionNode, source), + Alternative: convert_expression(node.ChildByFieldName("alternative"), source), } } @@ -1181,26 +1199,26 @@ func convert_optional_expr(node *sitter.Node, source []byte) Expression { } argumentNode := node.ChildByFieldName("argument") - return OptionalExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeOptionalExpr, node), - Operator: operator, - Argument: convert_expression(argumentNode, source), + return &OptionalExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Operator: operator, + Argument: convert_expression(argumentNode, source), } } func convert_unary_expr(node *sitter.Node, source []byte) Expression { - return UnaryExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeUnaryExpr, node), - Operator: node.ChildByFieldName("operator").Content(source), - Argument: convert_expression(node.ChildByFieldName("argument"), source), + return &UnaryExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Operator: node.ChildByFieldName("operator").Content(source), + Argument: convert_expression(node.ChildByFieldName("argument"), source), } } func convert_update_expr(node *sitter.Node, source []byte) Expression { - return UpdateExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeUpdateExpr, node), - Operator: node.ChildByFieldName("operator").Content(source), - Argument: convert_expression(node.ChildByFieldName("argument"), source), + return &UpdateExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Operator: node.ChildByFieldName("operator").Content(source), + Argument: convert_expression(node.ChildByFieldName("argument"), source), } } @@ -1216,33 +1234,33 @@ func convert_subscript_expr(node *sitter.Node, source []byte) Expression { } } - return SubscriptExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeSubscriptExpr, node), - Index: index, - Argument: convert_expression(node.ChildByFieldName("argument"), source), + return &SubscriptExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Index: index, + Argument: convert_expression(node.ChildByFieldName("argument"), source), } } func convert_cast_expr(node *sitter.Node, source []byte) Expression { - return CastExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeCastExpr, node), - Type: convert_type(node.ChildByFieldName("type"), source).(TypeInfo), - Argument: convert_expression(node.ChildByFieldName("value"), source), + return &CastExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Type: convert_type(node.ChildByFieldName("type"), source), + Argument: convert_expression(node.ChildByFieldName("value"), source), } } func convert_rethrow_expr(node *sitter.Node, source []byte) Expression { - return RethrowExpression{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeRethrowExpr, node), - Operator: node.ChildByFieldName("operator").Content(source), - Argument: convert_expression(node.ChildByFieldName("argument"), source), + return &RethrowExpression{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Operator: node.ChildByFieldName("operator").Content(source), + Argument: convert_expression(node.ChildByFieldName("argument"), source), } } func convert_call_expr(node *sitter.Node, source []byte) Expression { invocationNode := node.ChildByFieldName("arguments") - args := []Arg{} + var args []Expression for i := 0; i < int(invocationNode.ChildCount()); i++ { n := invocationNode.Child(i) if n.Type() == "arg" { @@ -1251,25 +1269,27 @@ func convert_call_expr(node *sitter.Node, source []byte) Expression { } trailingNode := node.ChildByFieldName("trailing") - compoundStmt := option.None[CompoundStatement]() + compoundStmt := option.None[*CompoundStmt]() if trailingNode != nil { - compoundStmt = option.Some(convert_compound_stmt(trailingNode, source).(CompoundStatement)) + compoundStmt = option.Some(convert_compound_stmt(trailingNode, source).(*CompoundStmt)) } expr := convert_expression(node.ChildByFieldName("function"), source) var identifier Expression genericArguments := option.None[[]Expression]() switch expr.(type) { - case Identifier: - identifier = expr - case TrailingGenericsExpr: - identifier = expr.(TrailingGenericsExpr).Identifier - ga := expr.(TrailingGenericsExpr).GenericArguments + case *SelectorExpr: + identifier = expr.(*SelectorExpr) + case *Ident: + identifier = expr.(Ident) + case *TrailingGenericsExpr: + identifier = expr.(*TrailingGenericsExpr).Identifier + ga := expr.(*TrailingGenericsExpr).GenericArguments genericArguments = option.Some(ga) } - return FunctionCall{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeCallExpr, node), + return &FunctionCall{ + NodeAttributes: NewBaseNodeFromSitterNode(node), Identifier: identifier, GenericArguments: genericArguments, Arguments: args, @@ -1289,15 +1309,15 @@ func convert_trailing_generic_expr(node *sitter.Node, source []byte) Expression operator := convert_generic_arguments(node.ChildByFieldName("operator"), source) - return TrailingGenericsExpr{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeTrailingGenericExpr, node), - Identifier: expr.(Identifier), + return &TrailingGenericsExpr{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Identifier: *(expr.(*Ident)), GenericArguments: operator, } } func convert_generic_arguments(node *sitter.Node, source []byte) []Expression { - args := []Expression{} + var args []Expression for i := 0; i < int(node.ChildCount()); i++ { n := node.Child(i) @@ -1317,20 +1337,20 @@ func convert_generic_arguments(node *sitter.Node, source []byte) []Expression { func convert_type_with_initializer_list(node *sitter.Node, source []byte) Expression { baseExpr := convert_base_expression(node.NextNamedSibling(), source) - initList, ok := baseExpr.(InitializerList) + initList, ok := baseExpr.(*InitializerList) if !ok { - initList = InitializerList{} + initList = &InitializerList{} } - expression := InlineTypeWithInitizlization{ - ASTBaseNode: NewBaseNodeBuilder(TypeInlineTypeWithInitExpr). + expression := &InlineTypeWithInitialization{ + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd( uint(node.StartPoint().Row), uint(node.StartPoint().Column), - initList.ASTBaseNode.EndPos.Line, - initList.ASTBaseNode.EndPos.Column, + initList.NodeAttributes.EndPos.Line, + initList.NodeAttributes.EndPos.Column, ).Build(), - Type: convert_type(node, source).(TypeInfo), + Type: convert_type(node, source), InitializerList: initList, } @@ -1349,17 +1369,17 @@ func convert_literal(node *sitter.Node, sourceCode []byte) Expression { //fmt.Printf("Converting literal %s\n", node.Type()) switch node.Type() { case "string_literal", "char_literal", "raw_string_literal", "bytes_literal": - literal = Literal{Value: node.Content(sourceCode)} + literal = &Literal{Value: node.Content(sourceCode)} case "integer_literal": - literal = IntegerLiteral{ASTBaseNode: ASTBaseNode{Kind: TypeIntegerLiteral}, Value: node.Content(sourceCode)} + literal = &IntegerLiteral{NodeAttributes: NodeAttributes{}, Value: node.Content(sourceCode)} case "real_literal": - literal = RealLiteral{Value: node.Content(sourceCode)} + literal = &RealLiteral{Value: node.Content(sourceCode)} case "false": - literal = BoolLiteral{Value: false} + literal = &BoolLiteral{Value: false} case "true": - literal = BoolLiteral{Value: true} + literal = &BoolLiteral{Value: true} case "null": - literal = Literal{Value: "null"} + literal = &Literal{Value: "null"} default: panic(fmt.Sprintf("Literal type not supported: %s\n", node.Type())) } @@ -1368,12 +1388,12 @@ func convert_literal(node *sitter.Node, sourceCode []byte) Expression { } func convert_as_literal(node *sitter.Node, source []byte) Expression { - return Literal{Value: node.Content(source)} + return &Literal{Value: node.Content(source)} } func convert_initializer_list(node *sitter.Node, source []byte) Expression { - initList := InitializerList{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeInitializerList, node), + initList := &InitializerList{ + NodeAttributes: NewBaseNodeFromSitterNode(node), } for i := 0; i < int(node.ChildCount()); i++ { n := node.Child(i) @@ -1385,7 +1405,7 @@ func convert_initializer_list(node *sitter.Node, source []byte) Expression { return initList } -func convert_arg(node *sitter.Node, source []byte) Arg { +func convert_arg(node *sitter.Node, source []byte) Expression { childCount := int(node.ChildCount()) if is_literal(node.Child(0)) { @@ -1395,7 +1415,7 @@ func convert_arg(node *sitter.Node, source []byte) Arg { switch node.Child(0).Type() { case "param_path": param_path := node.Child(0) - var arg Arg + var arg Expression param_path_element := param_path.Child(0) argType := 0 @@ -1411,11 +1431,11 @@ func convert_arg(node *sitter.Node, source []byte) Arg { } if argType == 1 { - arg = ArgFieldSet{ + arg = &ArgFieldSet{ FieldName: param_path_element.Child(1).Content(source), } } else { - arg = ArgParamPathSet{ + arg = &ArgParamPathSet{ Path: node.Child(0).Content(source), } } @@ -1431,10 +1451,10 @@ func convert_arg(node *sitter.Node, source []byte) Arg { } switch v := arg.(type) { - case ArgParamPathSet: + case *ArgParamPathSet: v.Expr = expr arg = v - case ArgFieldSet: + case *ArgFieldSet: v.Expr = expr arg = v } @@ -1444,7 +1464,7 @@ func convert_arg(node *sitter.Node, source []byte) Arg { case "type": return Expression(convert_type(node.Child(0), source)) case "$vasplat": - return Literal{Value: node.Content(source)} + return &Literal{Value: node.Content(source)} case "...": return Expression(convert_expression(node.Child(1), source)) default: @@ -1513,17 +1533,17 @@ func convert_flat_path(node *sitter.Node, source []byte) Expression { path := convert_param_path(next, source) switch path.PathType { case PathTypeIndexed: - return IndexAccess{ + return &IndexAccessExpr{ Array: base_expr, Index: path.Path, } case PathTypeField: - return FieldAccess{ + return &FieldAccessExpr{ Object: base_expr, Field: path, } case PathTypeRange: - return RangeAccess{ + return &RangeAccessExpr{ Array: base_expr, RangeStart: utils.StringToUint(path.PathStart), RangeEnd: utils.StringToUint(path.PathEnd), @@ -1547,18 +1567,18 @@ func convert_range_expr(node *sitter.Node, source []byte) Expression { right = option.Some(utils.StringToUint(rightNode.Content(source))) } - return RangeIndex{ + return &RangeIndexExpr{ Start: left, End: right, } } -func cast_expressions_to_args(expressions []Expression) []Arg { - var args []Arg +func cast_expressions_to_args(expressions []Expression) []Expression { + var args []Expression for _, expr := range expressions { // Realiza una conversión de tipo de Expression a Arg - if arg, ok := expr.(Arg); ok { + if arg, ok := expr.(Expression); ok { args = append(args, arg) } else { // Si algún elemento no puede convertirse, retornamos un error @@ -1571,8 +1591,8 @@ func cast_expressions_to_args(expressions []Expression) []Arg { type NodeConverterSeparated func(node *sitter.Node, source []byte) (Expression, int) -func convert_token_separated(node *sitter.Node, separator string, source []byte, convert_func NodeConverter) []Expression { - expressions := []Expression{} +func convert_token_separated(node *sitter.Node, separator string, source []byte, convert_func NodeConverter) []Node { + var nodes []Node for i := 0; i < int(node.ChildCount()); i++ { n := node.Child(i) @@ -1582,12 +1602,12 @@ func convert_token_separated(node *sitter.Node, separator string, source []byte, expr := convert_func(n, source) if expr != nil { - expressions = append(expressions, expr) + nodes = append(nodes, expr) } //i += advance } - return expressions + return nodes } func convert_dummy(node *sitter.Node, source []byte) Expression { diff --git a/server/internal/lsp/ast/convert_ct.go b/server/internal/lsp/ast/convert_ct.go index 3aafd74..3fcb2e6 100644 --- a/server/internal/lsp/ast/convert_ct.go +++ b/server/internal/lsp/ast/convert_ct.go @@ -5,7 +5,7 @@ import ( ) func convert_ct_type_ident(node *sitter.Node, source []byte) Expression { - return Literal{Value: node.Content(source)} + return &Literal{Value: node.Content(source)} } /* @@ -31,15 +31,15 @@ func convert_compile_time_call(node *sitter.Node, source []byte) Expression { flatPath := node.NextNamedSibling() endNode = flatPath.NextSibling() - funcCall := FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr). + funcCall := &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(node.StartPoint(), endNode.EndPoint()). Build(), Identifier: NewIdentifierBuilder(). WithName(node.Content(source)). WithSitterPos(node). Build(), - Arguments: []Arg{convert_flat_path(flatPath, source)}, + Arguments: []Expression{convert_flat_path(flatPath, source)}, } return funcCall @@ -61,15 +61,15 @@ func convert_compile_time_arg(node *sitter.Node, source []byte) Expression { expr := convert_expression(insideParenths, source) - funcCall := FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr). + funcCall := &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(node.StartPoint(), endNode.EndPoint()). Build(), Identifier: NewIdentifierBuilder(). WithName(node.Content(source)). WithSitterPos(node). Build(), - Arguments: []Arg{expr}, + Arguments: []Expression{expr.(Expression)}, } return funcCall @@ -107,16 +107,16 @@ func convert_compile_time_analyse(node *sitter.Node, source []byte) Expression { //expressions := convert_token_separated(decl_or_expr_node, ",", source, convert_decl_or_expr) - funcCall := FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr). + funcCall := &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder(). WithSitterPosRange(node.StartPoint(), decl_or_expr_node.NextSibling().EndPoint()). Build(), Identifier: NewIdentifierBuilder(). WithName(node.Content(source)). WithSitterPos(node). Build(), - Arguments: []Arg{ - convert_expression(decl_or_expr_node, source), + Arguments: []Expression{ + convert_expression(decl_or_expr_node, source).(Expression), }, } @@ -125,26 +125,32 @@ func convert_compile_time_analyse(node *sitter.Node, source []byte) Expression { func convert_compile_time_call_unk(node *sitter.Node, source []byte) Expression { next := node.NextNamedSibling() - return FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithSitterPosRange(node.StartPoint(), next.EndPoint()).Build(), + _args := convert_token_separated(next, ",", source, cv_expr_fn(convert_expression)) + var args []Expression + for _, a := range _args { + args = append(args, a.(Expression)) + } + + return &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithSitterPosRange(node.StartPoint(), next.EndPoint()).Build(), Identifier: NewIdentifierBuilder(). WithName(node.Content(source)). WithSitterPos(node). Build(), Arguments: cast_expressions_to_args( - convert_token_separated(next, ",", source, convert_expression), + args, ), } } func convert_feature(node *sitter.Node, source []byte) Expression { next := node.NextNamedSibling() - return FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithSitterPosRange(node.StartPoint(), next.EndPoint()).Build(), + return &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithSitterPosRange(node.StartPoint(), next.EndPoint()).Build(), Identifier: NewIdentifierBuilder(). WithName(node.Content(source)). WithSitterPos(node). Build(), - Arguments: []Arg{convert_base_expression(next, source)}, + Arguments: []Expression{convert_base_expression(next, source)}, } } diff --git a/server/internal/lsp/ast/convert_declarations_test.go b/server/internal/lsp/ast/convert_declarations_test.go index 7bd7ab2..c60b004 100644 --- a/server/internal/lsp/ast/convert_declarations_test.go +++ b/server/internal/lsp/ast/convert_declarations_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/assert" ) -func aWithPos(kind NodeType, startRow uint, startCol uint, endRow uint, endCol uint) ASTBaseNode { - return NewBaseNodeBuilder(kind). +func aWithPos(startRow uint, startCol uint, endRow uint, endCol uint) NodeAttributes { + return NewBaseNodeBuilder(). WithStartEnd(startRow, startCol, endRow, endCol). Build() } @@ -19,12 +19,12 @@ func TestConvertToAST_module(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") expectedAst := File{ - ASTBaseNode: NewBaseNodeBuilder(TypeFile).WithStartEnd(0, 0, 0, 11).Build(), - Name: "file.c3", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(0, 0, 0, 11).Build(), + Name: "file.c3", Modules: []Module{ { - Name: "foo", - ASTBaseNode: NewBaseNodeBuilder(TypeModule).WithStartEnd(0, 0, 0, 11).Build(), + Name: "foo", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(0, 0, 0, 11).Build(), }, }, } @@ -40,27 +40,27 @@ func TestConvertToAST_module_implicit(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "path/file/xxx.c3") expected := Module{ - Name: "path_file_xxx", - ASTBaseNode: NewBaseNodeBuilder(TypeModule).WithStartEnd(1, 1, 2, 1).Build(), + Name: "path_file_xxx", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 1, 2, 1).Build(), Declarations: []Declaration{ - VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(1, 1, 1, 18).Build(), - Names: []Identifier{ + &VariableDecl{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 1, 1, 18).Build(), + Names: []Ident{ NewIdentifierBuilder().WithName("variable").WithStartEnd(1, 5, 1, 13).Build(), }, Type: NewTypeInfoBuilder().IsBuiltin(). WithName("int"). WithNameStartEnd(1, 1, 1, 4). WithStartEnd(1, 1, 1, 4).Build(), - Initializer: IntegerLiteral{Value: "0"}, + Initializer: &IntegerLiteral{Value: "0"}, }, }, } assert.Equal(t, expected, ast.Modules[0]) expected = Module{ - Name: "foo", - ASTBaseNode: NewBaseNodeBuilder(TypeModule).WithStartEnd(2, 1, 2, 12).Build(), + Name: "foo", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 1, 2, 12).Build(), } assert.Equal(t, expected, ast.Modules[1]) } @@ -75,14 +75,14 @@ func TestConvertToAST_module_with_generics(t *testing.T) { { Name: "foo", GenericParameters: []string{"Type"}, - ASTBaseNode: ASTBaseNode{ + NodeAttributes: NodeAttributes{ Attributes: nil, StartPos: Position{0, 0}, EndPos: Position{0, 19}, }, }, }, - ASTBaseNode: ASTBaseNode{ + NodeAttributes: NodeAttributes{ Attributes: nil, StartPos: Position{0, 0}, EndPos: Position{0, 19}, @@ -103,14 +103,14 @@ func TestConvertToAST_module_with_attributes(t *testing.T) { { Name: "foo", GenericParameters: nil, - ASTBaseNode: ASTBaseNode{ + NodeAttributes: NodeAttributes{ Attributes: []string{"@private"}, StartPos: Position{0, 0}, EndPos: Position{0, 20}, }, }, }, - ASTBaseNode: ASTBaseNode{ + NodeAttributes: NodeAttributes{ Attributes: nil, StartPos: Position{0, 0}, EndPos: Position{0, 20}, @@ -142,13 +142,13 @@ func TestConvertToAST_global_variables(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") expectedHello := VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 1, 1, 15). Build(), - Names: []Identifier{ + Names: []Ident{ { Name: "hello", - ASTBaseNode: NewBaseNodeBuilder(TypeIdentifier). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 5, 1, 10). Build(), }, @@ -156,37 +156,37 @@ func TestConvertToAST_global_variables(t *testing.T) { Type: TypeInfo{ Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(1, 1, 1, 4).Build(), BuiltIn: true, - ASTBaseNode: NewBaseNodeBuilder(TypeTypeInfo). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 1, 1, 4). Build(), }, - Initializer: IntegerLiteral{Value: "3"}, + Initializer: &IntegerLiteral{Value: "3"}, } - assert.Equal(t, expectedHello, ast.Modules[0].Variables[0]) + assert.Equal(t, expectedHello, ast.Modules[0].Declarations[0]) expectedAnimals := VariableDecl{ - ASTBaseNode: aWithPos(TypeVariableDecl, 2, 1, 2, 24), - Names: []Identifier{ + NodeAttributes: aWithPos(2, 1, 2, 24), + Names: []Ident{ { - Name: "dog", - ASTBaseNode: aWithPos(TypeIdentifier, 2, 5, 2, 8), + Name: "dog", + NodeAttributes: aWithPos(2, 5, 2, 8), }, { - Name: "cat", - ASTBaseNode: aWithPos(TypeIdentifier, 2, 10, 2, 13), + Name: "cat", + NodeAttributes: aWithPos(2, 10, 2, 13), }, { - Name: "elephant", - ASTBaseNode: aWithPos(TypeIdentifier, 2, 15, 2, 23), + Name: "elephant", + NodeAttributes: aWithPos(2, 15, 2, 23), }, }, Type: TypeInfo{ - Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(2, 1, 2, 4).Build(), - BuiltIn: true, - ASTBaseNode: aWithPos(TypeTypeInfo, 2, 1, 2, 4), + Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(2, 1, 2, 4).Build(), + BuiltIn: true, + NodeAttributes: aWithPos(2, 1, 2, 4), }, } - assert.Equal(t, expectedAnimals, ast.Modules[0].Variables[1]) + assert.Equal(t, expectedAnimals, ast.Modules[0].Declarations[1]) } func TestConvertToAST_enum_decl(t *testing.T) { @@ -200,40 +200,40 @@ func TestConvertToAST_enum_decl(t *testing.T) { row := uint(1) expected := EnumDecl{ Name: "Colors", - ASTBaseNode: NewBaseNodeBuilder(TypeEnumDecl). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 1, 1, 33). Build(), Members: []EnumMember{ { - Name: Identifier{ + Name: Ident{ Name: "RED", - ASTBaseNode: NewBaseNodeBuilder(TypeIdentifier). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 15, 1, 18). Build(), }, - ASTBaseNode: NewBaseNodeBuilder(TypeEnumProperty). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 15, 1, 18). Build(), }, { - Name: Identifier{ + Name: Ident{ Name: "BLUE", - ASTBaseNode: NewBaseNodeBuilder(TypeIdentifier). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 20, 1, 24). Build(), }, - ASTBaseNode: NewBaseNodeBuilder(TypeEnumProperty). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 20, 1, 24). Build(), }, { - Name: Identifier{ + Name: Ident{ Name: "GREEN", - ASTBaseNode: NewBaseNodeBuilder(TypeIdentifier). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 26, 1, 31). Build(), }, - ASTBaseNode: NewBaseNodeBuilder(TypeEnumProperty). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 26, 1, 31). Build(), }, @@ -246,33 +246,33 @@ func TestConvertToAST_enum_decl(t *testing.T) { expected = EnumDecl{ Name: "TypedColors", BaseType: TypeInfo{ - Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(2, 18, 2, 21).Build(), - BuiltIn: true, - Optional: false, - ASTBaseNode: aWithPos(TypeTypeInfo, row, 18, row, 21), + Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(2, 18, 2, 21).Build(), + BuiltIn: true, + Optional: false, + NodeAttributes: aWithPos(row, 18, row, 21), }, - ASTBaseNode: aWithPos(TypeEnumDecl, row, 1, row, 42), + NodeAttributes: aWithPos(row, 1, row, 42), Members: []EnumMember{ { - Name: Identifier{ - Name: "RED", - ASTBaseNode: aWithPos(TypeIdentifier, row, 24, row, 27), + Name: Ident{ + Name: "RED", + NodeAttributes: aWithPos(row, 24, row, 27), }, - ASTBaseNode: aWithPos(TypeEnumProperty, row, 24, row, 27), + NodeAttributes: aWithPos(row, 24, row, 27), }, { - Name: Identifier{ - Name: "BLUE", - ASTBaseNode: aWithPos(TypeIdentifier, row, 29, row, 33), + Name: Ident{ + Name: "BLUE", + NodeAttributes: aWithPos(row, 29, row, 33), }, - ASTBaseNode: aWithPos(TypeEnumProperty, row, 29, row, 33), + NodeAttributes: aWithPos(row, 29, row, 33), }, { - Name: Identifier{ - Name: "GREEN", - ASTBaseNode: aWithPos(TypeIdentifier, row, 35, row, 40), + Name: Ident{ + Name: "GREEN", + NodeAttributes: aWithPos(row, 35, row, 40), }, - ASTBaseNode: aWithPos(TypeEnumProperty, row, 35, row, 40), + NodeAttributes: aWithPos(row, 35, row, 40), }, }, } @@ -293,81 +293,81 @@ func TestConvertToAST_enum_decl_with_associated_params(t *testing.T) { expected := EnumDecl{ Name: "State", BaseType: TypeInfo{ - Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(1, 14, 1, 17).Build(), - BuiltIn: true, - Optional: false, - ASTBaseNode: aWithPos(TypeTypeInfo, row, 14, row, 17), + Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(1, 14, 1, 17).Build(), + BuiltIn: true, + Optional: false, + NodeAttributes: aWithPos(row, 14, row, 17), }, Properties: []EnumProperty{ { - Name: Identifier{ - Name: "desc", - ASTBaseNode: aWithPos(TypeIdentifier, row, 26, row, 30), + Name: Ident{ + Name: "desc", + NodeAttributes: aWithPos(row, 26, row, 30), }, Type: TypeInfo{ - Identifier: NewIdentifierBuilder().WithName("String").WithStartEnd(1, 19, 1, 25).Build(), - BuiltIn: false, - Optional: false, - ASTBaseNode: aWithPos(TypeEnumProperty, row, 19, row, 25), + Identifier: NewIdentifierBuilder().WithName("String").WithStartEnd(1, 19, 1, 25).Build(), + BuiltIn: false, + Optional: false, + NodeAttributes: aWithPos(row, 19, row, 25), }, - ASTBaseNode: aWithPos(TypeEnumProperty, row, 19, row, 30), + NodeAttributes: aWithPos(row, 19, row, 30), }, { - Name: Identifier{ - Name: "active", - ASTBaseNode: aWithPos(TypeIdentifier, row, 37, row, 43), + Name: Ident{ + Name: "active", + NodeAttributes: aWithPos(row, 37, row, 43), }, Type: TypeInfo{ - Identifier: NewIdentifierBuilder().WithName("bool").WithStartEnd(1, 32, 1, 36).Build(), - BuiltIn: true, - Optional: false, - ASTBaseNode: aWithPos(TypeTypeInfo, row, 32, row, 36), + Identifier: NewIdentifierBuilder().WithName("bool").WithStartEnd(1, 32, 1, 36).Build(), + BuiltIn: true, + Optional: false, + NodeAttributes: aWithPos(row, 32, row, 36), }, - ASTBaseNode: aWithPos(TypeEnumProperty, row, 32, row, 43), + NodeAttributes: aWithPos(row, 32, row, 43), }, { - Name: Identifier{ - Name: "ke", - ASTBaseNode: aWithPos(TypeIdentifier, row, 50, row, 52), + Name: Ident{ + Name: "ke", + NodeAttributes: aWithPos(row, 50, row, 52), }, Type: TypeInfo{ - Identifier: NewIdentifierBuilder().WithName("char").WithStartEnd(1, 45, 1, 49).Build(), - BuiltIn: true, - Optional: false, - ASTBaseNode: aWithPos(TypeTypeInfo, row, 45, row, 49), + Identifier: NewIdentifierBuilder().WithName("char").WithStartEnd(1, 45, 1, 49).Build(), + BuiltIn: true, + Optional: false, + NodeAttributes: aWithPos(row, 45, row, 49), }, - ASTBaseNode: aWithPos(TypeEnumProperty, row, 45, row, 52), + NodeAttributes: aWithPos(row, 45, row, 52), }, }, - ASTBaseNode: aWithPos(TypeEnumDecl, row, 1, row+3, 2), + NodeAttributes: aWithPos(row, 1, row+3, 2), Members: []EnumMember{ { - Name: Identifier{ - Name: "PENDING", - ASTBaseNode: aWithPos(TypeIdentifier, row+1, 2, row+1, 9), + Name: Ident{ + Name: "PENDING", + NodeAttributes: aWithPos(row+1, 2, row+1, 9), }, Value: CompositeLiteral{ - Values: []Expression{ - Literal{Value: "\"pending start\""}, - BoolLiteral{Value: false}, - Literal{Value: "'c'"}, + Elements: []Expression{ + &Literal{Value: "\"pending start\""}, + &BoolLiteral{Value: false}, + &Literal{Value: "'c'"}, }, }, - ASTBaseNode: aWithPos(TypeEnumMember, row+1, 2, row+1, 41), + NodeAttributes: aWithPos(row+1, 2, row+1, 41), }, { - Name: Identifier{ - Name: "RUNNING", - ASTBaseNode: aWithPos(TypeIdentifier, row+2, 2, row+2, 9), + Name: Ident{ + Name: "RUNNING", + NodeAttributes: aWithPos(row+2, 2, row+2, 9), }, Value: CompositeLiteral{ - Values: []Expression{ - Literal{Value: "\"running\""}, - BoolLiteral{Value: true}, - Literal{Value: "'e'"}, + Elements: []Expression{ + &Literal{Value: "\"running\""}, + &BoolLiteral{Value: true}, + &Literal{Value: "'e'"}, }, }, - ASTBaseNode: aWithPos(TypeEnumMember, row+2, 2, row+2, 34), + NodeAttributes: aWithPos(row+2, 2, row+2, 34), }, }, } @@ -385,52 +385,52 @@ func TestConvertToAST_struct_decl(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") expected := StructDecl{ - ASTBaseNode: aWithPos(TypeStructDecl, 1, 1, 5, 2), - Name: "MyStruct", - StructType: StructTypeNormal, + NodeAttributes: aWithPos(1, 1, 5, 2), + Name: "MyStruct", + StructType: StructTypeNormal, Members: []StructMemberDecl{ { - ASTBaseNode: aWithPos(TypeStructMemberDecl, 2, 2, 2, 11), - Names: []Identifier{ + NodeAttributes: aWithPos(2, 2, 2, 11), + Names: []Ident{ { - ASTBaseNode: aWithPos(TypeIdentifier, 2, 6, 2, 10), - Name: "data", + NodeAttributes: aWithPos(2, 6, 2, 10), + Name: "data", }, }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 2, 2, 2, 5), - Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(2, 2, 2, 5).Build(), - BuiltIn: true, + NodeAttributes: aWithPos(2, 2, 2, 5), + Identifier: NewIdentifierBuilder().WithName("int").WithStartEnd(2, 2, 2, 5).Build(), + BuiltIn: true, }, }, { - ASTBaseNode: aWithPos(TypeStructMemberDecl, 3, 2, 3, 11), - Names: []Identifier{ + NodeAttributes: aWithPos(3, 2, 3, 11), + Names: []Ident{ { - ASTBaseNode: aWithPos(TypeIdentifier, 3, 7, 3, 10), - Name: "key", + NodeAttributes: aWithPos(3, 7, 3, 10), + Name: "key", }, }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 3, 2, 3, 6), - Identifier: NewIdentifierBuilder().WithName("char").WithStartEnd(3, 2, 3, 6).Build(), - BuiltIn: true, + NodeAttributes: aWithPos(3, 2, 3, 6), + Identifier: NewIdentifierBuilder().WithName("char").WithStartEnd(3, 2, 3, 6).Build(), + BuiltIn: true, }, }, { - ASTBaseNode: aWithPos(TypeStructMemberDecl, 4, 2, 4, 24), - Names: []Identifier{ + NodeAttributes: aWithPos(4, 2, 4, 24), + Names: []Ident{ { - ASTBaseNode: aWithPos(TypeIdentifier, 4, 17, 4, 23), - Name: "camera", + NodeAttributes: aWithPos(4, 17, 4, 23), + Name: "camera", }, }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 4, 2, 4, 16), - Identifier: Identifier{ - Path: "raylib", - Name: "Camera", - ASTBaseNode: aWithPos(TypeIdentifier, 4, 2, 4, 16), + NodeAttributes: aWithPos(4, 2, 4, 16), + Identifier: Ident{ + ModulePath: "raylib", + Name: "Camera", + NodeAttributes: aWithPos(4, 2, 4, 16), }, BuiltIn: false, }, @@ -453,7 +453,7 @@ func TestConvertToAST_struct_decl_with_interface(t *testing.T) { expected := []string{"MyInterface", "MySecondInterface"} - structDecl := ast.Modules[0].Declarations[0].(StructDecl) + structDecl := ast.Modules[0].Declarations[0].(*StructDecl) assert.Equal(t, expected, structDecl.Implements) } @@ -471,22 +471,22 @@ func TestConvertToAST_struct_decl_with_anonymous_bitstructs(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - structDecl := ast.Modules[0].Declarations[1].(StructDecl) + structDecl := ast.Modules[0].Declarations[1].(*StructDecl) assert.Equal(t, 5, len(structDecl.Members)) assert.Equal( t, StructMemberDecl{ - ASTBaseNode: aWithPos(TypeStructMemberDecl, 4, 3, 4, 25), - Names: []Identifier{ + NodeAttributes: aWithPos(4, 3, 4, 25), + Names: []Ident{ NewIdentifierBuilder(). WithName("bc"). WithStartEnd(4, 14, 4, 16). Build(), }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 4, 3, 4, 13), + NodeAttributes: aWithPos(4, 3, 4, 13), Identifier: NewIdentifierBuilder(). WithName("Register16"). WithStartEnd(4, 3, 4, 13). @@ -500,15 +500,15 @@ func TestConvertToAST_struct_decl_with_anonymous_bitstructs(t *testing.T) { assert.Equal( t, StructMemberDecl{ - ASTBaseNode: aWithPos(TypeStructMemberDecl, 5, 3, 5, 22), - Names: []Identifier{ + NodeAttributes: aWithPos(5, 3, 5, 22), + Names: []Ident{ NewIdentifierBuilder(). WithName("b"). WithStartEnd(5, 12, 5, 13). Build(), }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 5, 3, 5, 11), + NodeAttributes: aWithPos(5, 3, 5, 11), Identifier: NewIdentifierBuilder(). WithName("Register"). WithStartEnd(5, 3, 5, 11). @@ -522,15 +522,15 @@ func TestConvertToAST_struct_decl_with_anonymous_bitstructs(t *testing.T) { assert.Equal( t, StructMemberDecl{ - ASTBaseNode: aWithPos(TypeStructMemberDecl, 6, 3, 6, 21), - Names: []Identifier{ + NodeAttributes: aWithPos(6, 3, 6, 21), + Names: []Ident{ NewIdentifierBuilder(). WithName("c"). WithStartEnd(6, 12, 6, 13). Build(), }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 6, 3, 6, 11), + NodeAttributes: aWithPos(6, 3, 6, 11), Identifier: NewIdentifierBuilder(). WithName("Register"). WithStartEnd(6, 3, 6, 11). @@ -544,15 +544,15 @@ func TestConvertToAST_struct_decl_with_anonymous_bitstructs(t *testing.T) { assert.Equal( t, StructMemberDecl{ - ASTBaseNode: aWithPos(TypeStructMemberDecl, 8, 2, 8, 16), - Names: []Identifier{ + NodeAttributes: aWithPos(8, 2, 8, 16), + Names: []Ident{ NewIdentifierBuilder(). WithName("sp"). WithStartEnd(8, 13, 8, 15). Build(), }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 8, 2, 8, 12), + NodeAttributes: aWithPos(8, 2, 8, 12), Identifier: NewIdentifierBuilder(). WithName("Register16"). WithStartEnd(8, 2, 8, 12). @@ -565,15 +565,15 @@ func TestConvertToAST_struct_decl_with_anonymous_bitstructs(t *testing.T) { assert.Equal( t, StructMemberDecl{ - ASTBaseNode: aWithPos(TypeStructMemberDecl, 9, 2, 9, 16), - Names: []Identifier{ + NodeAttributes: aWithPos(9, 2, 9, 16), + Names: []Ident{ NewIdentifierBuilder(). WithName("pc"). WithStartEnd(9, 13, 9, 15). Build(), }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 9, 2, 9, 12), + NodeAttributes: aWithPos(9, 2, 9, 12), Identifier: NewIdentifierBuilder(). WithName("Register16"). WithStartEnd(9, 2, 9, 12). @@ -596,7 +596,7 @@ func TestConvertToAST_struct_decl_with_inline_substructs(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - structDecl := ast.Modules[0].Declarations[1].(StructDecl) + structDecl := ast.Modules[0].Declarations[1].(*StructDecl) assert.Equal(t, true, structDecl.Members[0].IsInlined) } @@ -609,7 +609,7 @@ func TestConvertToAST_union_decl(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - unionDecl := ast.Modules[0].Declarations[0].(StructDecl) + unionDecl := ast.Modules[0].Declarations[0].(*StructDecl) assert.Equal(t, StructTypeUnion, int(unionDecl.StructType)) } @@ -624,14 +624,14 @@ func TestConvertToAST_bitstruct_decl(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - bitstructDecl := ast.Modules[0].Declarations[0].(StructDecl) + bitstructDecl := ast.Modules[0].Declarations[0].(*StructDecl) assert.Equal(t, StructTypeBitStruct, int(bitstructDecl.StructType)) assert.Equal(t, true, bitstructDecl.BackingType.IsSome()) expectedType := TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 1, 32, 1, 36), - BuiltIn: true, + NodeAttributes: aWithPos(1, 32, 1, 36), + BuiltIn: true, Identifier: NewIdentifierBuilder(). WithName("uint"). WithStartEnd(1, 32, 1, 36). @@ -641,16 +641,16 @@ func TestConvertToAST_bitstruct_decl(t *testing.T) { assert.Equal(t, []string{"AnInterface"}, bitstructDecl.Implements) expect := StructMemberDecl{ - ASTBaseNode: aWithPos(TypeStructMemberDecl, 3, 2, 3, 19), - Names: []Identifier{ + NodeAttributes: aWithPos(3, 2, 3, 19), + Names: []Ident{ NewIdentifierBuilder(). WithName("a"). WithStartEnd(3, 9, 3, 10). Build(), }, Type: TypeInfo{ - ASTBaseNode: aWithPos(TypeTypeInfo, 3, 2, 3, 8), - BuiltIn: true, + NodeAttributes: aWithPos(3, 2, 3, 8), + BuiltIn: true, Identifier: NewIdentifierBuilder(). WithName("ushort"). WithStartEnd(3, 2, 3, 8). @@ -670,7 +670,7 @@ func TestConvertToAST_fault_decl(t *testing.T) { };` ast := ConvertToAST(GetCST(source), source, "file.c3") - faultDecl := ast.Modules[0].Declarations[0].(FaultDecl) + faultDecl := ast.Modules[0].Declarations[0].(*FaultDecl) assert.Equal( t, @@ -680,8 +680,8 @@ func TestConvertToAST_fault_decl(t *testing.T) { Build(), faultDecl.Name, ) - assert.Equal(t, Position{1, 1}, faultDecl.ASTBaseNode.StartPos) - assert.Equal(t, Position{5, 2}, faultDecl.ASTBaseNode.EndPos) + assert.Equal(t, Position{1, 1}, faultDecl.NodeAttributes.StartPos) + assert.Equal(t, Position{5, 2}, faultDecl.NodeAttributes.EndPos) assert.Equal(t, false, faultDecl.BackingType.IsSome()) assert.Equal(t, 2, len(faultDecl.Members)) @@ -692,7 +692,7 @@ func TestConvertToAST_fault_decl(t *testing.T) { WithName("IO_ERROR"). WithStartEnd(3, 3, 3, 11). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFaultMemberDecl). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(3, 3, 3, 11). Build(), }, @@ -705,7 +705,7 @@ func TestConvertToAST_fault_decl(t *testing.T) { WithName("PARSE_ERROR"). WithStartEnd(4, 3, 4, 14). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFaultMemberDecl). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(4, 3, 4, 14). Build(), }, @@ -725,8 +725,8 @@ func TestConvertToAST_def_decl(t *testing.T) { assert.Equal(t, DefDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeDefDecl).WithStartEnd(1, 1, 1, 16).Build(), - Name: NewIdentifierBuilder().WithName("Kilo").WithStartEnd(1, 5, 1, 9).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 1, 1, 16).Build(), + Name: NewIdentifierBuilder().WithName("Kilo").WithStartEnd(1, 5, 1, 9).Build(), resolvesToType: option.Some( NewTypeInfoBuilder(). WithName("int").WithNameStartEnd(1, 12, 1, 15). @@ -738,8 +738,8 @@ func TestConvertToAST_def_decl(t *testing.T) { assert.Equal(t, DefDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeDefDecl).WithStartEnd(2, 1, 2, 21).Build(), - Name: NewIdentifierBuilder().WithName("KiloPtr").WithStartEnd(2, 5, 2, 12).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 1, 2, 21).Build(), + Name: NewIdentifierBuilder().WithName("KiloPtr").WithStartEnd(2, 5, 2, 12).Build(), resolvesToType: option.Some( NewTypeInfoBuilder(). WithName("Kilo").WithNameStartEnd(2, 15, 2, 19). @@ -753,8 +753,8 @@ func TestConvertToAST_def_decl(t *testing.T) { row = 4 assert.Equal(t, DefDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeDefDecl).WithStartEnd(row, 1, row, 40).Build(), - Name: NewIdentifierBuilder().WithName("MyMap").WithStartEnd(row, 5, row, 10).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(row, 1, row, 40).Build(), + Name: NewIdentifierBuilder().WithName("MyMap").WithStartEnd(row, 5, row, 10).Build(), resolvesToType: option.Some( NewTypeInfoBuilder(). WithName("HashMap").WithNameStartEnd(row, 13, row, 20). @@ -765,12 +765,12 @@ func TestConvertToAST_def_decl(t *testing.T) { ), }, ast.Modules[0].Declarations[3]) - // Def with Identifier path + // Def with Ident path row = 5 assert.Equal(t, DefDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeDefDecl).WithStartEnd(row, 1, row, 29).Build(), - Name: NewIdentifierBuilder().WithName("Camera").WithStartEnd(row, 5, row, 11).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(row, 1, row, 29).Build(), + Name: NewIdentifierBuilder().WithName("Camera").WithStartEnd(row, 5, row, 11).Build(), resolvesToType: option.Some( NewTypeInfoBuilder(). WithPath("raylib"). @@ -789,17 +789,17 @@ func TestConvertToAST_function_declaration(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - fnDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, Position{1, 1}, fnDecl.ASTBaseNode.StartPos) - assert.Equal(t, Position{3, 2}, fnDecl.ASTBaseNode.EndPos) + fnDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, Position{1, 1}, fnDecl.NodeAttributes.StartPos) + assert.Equal(t, Position{3, 2}, fnDecl.NodeAttributes.EndPos) assert.Equal(t, "test", fnDecl.Signature.Name.Name, "Function name") - assert.Equal(t, Position{1, 9}, fnDecl.Signature.Name.ASTBaseNode.StartPos) - assert.Equal(t, Position{1, 13}, fnDecl.Signature.Name.ASTBaseNode.EndPos) + assert.Equal(t, Position{1, 9}, fnDecl.Signature.Name.NodeAttributes.StartPos) + assert.Equal(t, Position{1, 13}, fnDecl.Signature.Name.NodeAttributes.EndPos) assert.Equal(t, "void", fnDecl.Signature.ReturnType.Identifier.Name, "Return type") - assert.Equal(t, Position{1, 4}, fnDecl.Signature.ReturnType.ASTBaseNode.StartPos) - assert.Equal(t, Position{1, 8}, fnDecl.Signature.ReturnType.ASTBaseNode.EndPos) + assert.Equal(t, Position{1, 4}, fnDecl.Signature.ReturnType.NodeAttributes.StartPos) + assert.Equal(t, Position{1, 8}, fnDecl.Signature.ReturnType.NodeAttributes.EndPos) } func TestConvertToAST_function_declaration_one_line(t *testing.T) { @@ -807,11 +807,11 @@ func TestConvertToAST_function_declaration_one_line(t *testing.T) { fn void init_window(int width, int height, char* title) @extern("InitWindow");` ast := ConvertToAST(GetCST(source), source, "file.c3") - fnDecl := ast.Modules[0].Functions[0].(FunctionDecl) + fnDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) assert.Equal(t, "init_window", fnDecl.Signature.Name.Name, "Function name") - assert.Equal(t, Position{1, 1}, fnDecl.ASTBaseNode.StartPos) - assert.Equal(t, Position{1, 79}, fnDecl.ASTBaseNode.EndPos) + assert.Equal(t, Position{1, 1}, fnDecl.NodeAttributes.StartPos) + assert.Equal(t, Position{1, 79}, fnDecl.NodeAttributes.EndPos) } func TestConvertToAST_Function_returning_optional_type_declaration(t *testing.T) { @@ -821,7 +821,7 @@ func TestConvertToAST_Function_returning_optional_type_declaration(t *testing.T) }` ast := ConvertToAST(GetCST(source), source, "file.c3") - fnDecl := ast.Modules[0].Functions[0].(FunctionDecl) + fnDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) assert.Equal(t, "usz", fnDecl.Signature.ReturnType.Identifier.Name, "Return type") assert.Equal(t, true, fnDecl.Signature.ReturnType.Optional, "Return type should be optional") @@ -834,7 +834,7 @@ func TestConvertToAST_function_with_arguments_declaration(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - fnDecl := ast.Modules[0].Functions[0].(FunctionDecl) + fnDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) assert.Equal(t, 3, len(fnDecl.Signature.Parameters)) assert.Equal(t, @@ -845,7 +845,7 @@ func TestConvertToAST_function_with_arguments_declaration(t *testing.T) { IsBuiltin(). WithStartEnd(1, 14, 1, 17). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 14, 1, 24).Build(), }, fnDecl.Signature.Parameters[0], @@ -858,7 +858,7 @@ func TestConvertToAST_function_with_arguments_declaration(t *testing.T) { IsBuiltin(). WithStartEnd(1, 26, 1, 30). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 26, 1, 33).Build(), }, fnDecl.Signature.Parameters[1], @@ -872,7 +872,7 @@ func TestConvertToAST_function_with_arguments_declaration(t *testing.T) { IsPointer(). WithStartEnd(1, 35, 1, 38). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 35, 1, 47).Build(), }, fnDecl.Signature.Parameters[2], @@ -886,20 +886,20 @@ func TestConvertToAST_method_declaration(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - methodDecl := ast.Modules[0].Functions[0].(FunctionDecl) + methodDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) - assert.Equal(t, Position{1, 1}, methodDecl.ASTBaseNode.StartPos) - assert.Equal(t, Position{3, 2}, methodDecl.ASTBaseNode.EndPos) + assert.Equal(t, Position{1, 1}, methodDecl.NodeAttributes.StartPos) + assert.Equal(t, Position{3, 2}, methodDecl.NodeAttributes.EndPos) assert.Equal(t, true, methodDecl.ParentTypeId.IsSome(), "Function is flagged as method") assert.Equal(t, "method", methodDecl.Signature.Name.Name, "Function name") - assert.Equal(t, Position{1, 23}, methodDecl.Signature.Name.ASTBaseNode.StartPos) - assert.Equal(t, Position{1, 29}, methodDecl.Signature.Name.ASTBaseNode.EndPos) + assert.Equal(t, Position{1, 23}, methodDecl.Signature.Name.NodeAttributes.StartPos) + assert.Equal(t, Position{1, 29}, methodDecl.Signature.Name.NodeAttributes.EndPos) assert.Equal(t, "Object", methodDecl.Signature.ReturnType.Identifier.Name, "Return type") assert.Equal(t, uint(1), methodDecl.Signature.ReturnType.Pointer, "Return type is pointer") - assert.Equal(t, Position{1, 4}, methodDecl.Signature.ReturnType.ASTBaseNode.StartPos) - assert.Equal(t, Position{1, 10}, methodDecl.Signature.ReturnType.ASTBaseNode.EndPos) + assert.Equal(t, Position{1, 4}, methodDecl.Signature.ReturnType.NodeAttributes.StartPos) + assert.Equal(t, Position{1, 10}, methodDecl.Signature.ReturnType.NodeAttributes.EndPos) assert.Equal(t, 2, len(methodDecl.Signature.Parameters)) assert.Equal(t, @@ -909,7 +909,7 @@ func TestConvertToAST_method_declaration(t *testing.T) { WithName("UserStruct").WithNameStartEnd(1, 30, 1, 34). WithStartEnd(1, 30, 1, 34). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 30, 1, 34).Build(), }, methodDecl.Signature.Parameters[0], @@ -923,7 +923,7 @@ func TestConvertToAST_method_declaration(t *testing.T) { IsPointer(). WithStartEnd(1, 36, 1, 39). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 36, 1, 48).Build(), }, methodDecl.Signature.Parameters[1], @@ -936,7 +936,7 @@ func TestConvertToAST_method_declaration_mutable(t *testing.T) { return 1; }` ast := ConvertToAST(GetCST(source), source, "file.c3") - methodDecl := ast.Modules[0].Functions[0].(FunctionDecl) + methodDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) assert.Equal(t, FunctionParameter{ @@ -946,7 +946,7 @@ func TestConvertToAST_method_declaration_mutable(t *testing.T) { WithStartEnd(1, 30, 1, 35). IsPointer(). Build(), - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter). + NodeAttributes: NewBaseNodeBuilder(). WithStartEnd(1, 30, 1, 35).Build(), }, methodDecl.Signature.Parameters[0], @@ -961,7 +961,7 @@ func TestConvertToAST_interface_decl(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - interfaceDecl := ast.Modules[0].Declarations[0].(InterfaceDecl) + interfaceDecl := ast.Modules[0].Declarations[0].(*InterfaceDecl) assert.Equal(t, 2, len(interfaceDecl.Methods)) } @@ -973,7 +973,7 @@ func TestConvertToAST_macro_decl(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - macroDecl := ast.Modules[0].Macros[0].(MacroDecl) + macroDecl := ast.Modules[0].Declarations[0].(*MacroDecl) assert.Equal(t, Position{1, 1}, macroDecl.StartPos) assert.Equal(t, Position{3, 2}, macroDecl.EndPos) @@ -986,8 +986,8 @@ func TestConvertToAST_macro_decl(t *testing.T) { assert.Equal( t, FunctionParameter{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter).WithStartEnd(1, 9, 1, 10).Build(), - Name: NewIdentifierBuilder().WithName("x").WithStartEnd(1, 9, 1, 10).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 9, 1, 10).Build(), + Name: NewIdentifierBuilder().WithName("x").WithStartEnd(1, 9, 1, 10).Build(), }, macroDecl.Signature.Parameters[0], ) diff --git a/server/internal/lsp/ast/convert_expression_test.go b/server/internal/lsp/ast/convert_expression_test.go index 6abbbee..ed0ae6e 100644 --- a/server/internal/lsp/ast/convert_expression_test.go +++ b/server/internal/lsp/ast/convert_expression_test.go @@ -16,63 +16,63 @@ func TestConvertToAST_declaration_with_assignment(t *testing.T) { cases := []struct { skip bool literal string - expected ASTNode + expected Node }{ { literal: "1", - expected: IntegerLiteral{Value: "1"}, + expected: &IntegerLiteral{Value: "1"}, }, { literal: "1.1", - expected: RealLiteral{Value: "1.1"}, + expected: &RealLiteral{Value: "1.1"}, }, { literal: "false", - expected: BoolLiteral{Value: false}, + expected: &BoolLiteral{Value: false}, }, { literal: "true", - expected: BoolLiteral{Value: true}, + expected: &BoolLiteral{Value: true}, }, { literal: "null", - expected: Literal{Value: "null"}, + expected: &Literal{Value: "null"}, }, { literal: "\"hello\"", - expected: Literal{Value: "\"hello\""}, + expected: &Literal{Value: "\"hello\""}, }, { literal: "`hello`", - expected: Literal{Value: "`hello`"}, + expected: &Literal{Value: "`hello`"}, }, { literal: "x'FF'", - expected: Literal{Value: "x'FF'"}, + expected: &Literal{Value: "x'FF'"}, }, { literal: "x\"FF\"", - expected: Literal{Value: "x\"FF\""}, + expected: &Literal{Value: "x\"FF\""}, }, { literal: "x`FF`", - expected: Literal{Value: "x`FF`"}, + expected: &Literal{Value: "x`FF`"}, }, { literal: "b64'FF'", - expected: Literal{Value: "b64'FF'"}, + expected: &Literal{Value: "b64'FF'"}, }, { literal: "b64\"FF\"", - expected: Literal{Value: "b64\"FF\""}, + expected: &Literal{Value: "b64\"FF\""}, }, { literal: "b64`FF`", - expected: Literal{Value: "b64`FF`"}, + expected: &Literal{Value: "b64`FF`"}, }, { literal: "$$builtin", - expected: Literal{Value: "$$builtin"}, + expected: &Literal{Value: "$$builtin"}, }, // _ident_expr // - const_ident @@ -105,28 +105,28 @@ func TestConvertToAST_declaration_with_assignment(t *testing.T) { }, { literal: "&anotherVariable", - expected: UnaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUnaryExpr).WithStartEnd(2, 13, 2, 29).Build(), - Operator: "&", - Argument: NewIdentifierBuilder().WithName("anotherVariable").WithStartEnd(2, 14, 2, 29).Build(), + expected: &UnaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 29).Build(), + Operator: "&", + Argument: NewIdentifierBuilder().WithName("anotherVariable").WithStartEnd(2, 14, 2, 29).Build(), }, }, // seq($.type, $.initializer_list), { literal: "Type{1,2}", - expected: InlineTypeWithInitizlization{ - ASTBaseNode: NewBaseNodeBuilder(TypeInlineTypeWithInitExpr).WithStartEnd(2, 13, 2, 22).Build(), + expected: &InlineTypeWithInitialization{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 22).Build(), Type: NewTypeInfoBuilder(). WithName("Type"). WithNameStartEnd(2, 13, 2, 17). WithStartEnd(2, 13, 2, 17). Build(), - InitializerList: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 17, 2, 22).Build(), + InitializerList: &InitializerList{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 17, 2, 22).Build(), Args: []Expression{ - IntegerLiteral{Value: "1"}, - IntegerLiteral{Value: "2"}, + &IntegerLiteral{Value: "1"}, + &IntegerLiteral{Value: "2"}, }, }, }, @@ -135,7 +135,7 @@ func TestConvertToAST_declaration_with_assignment(t *testing.T) { // $vacount { literal: "$vacount", - expected: Literal{Value: "$vacount"}, + expected: &Literal{Value: "$vacount"}, }, } @@ -150,7 +150,7 @@ func TestConvertToAST_declaration_with_assignment(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - assert.Equal(t, tt.expected, ast.Modules[0].Variables[0].Initializer) + assert.Equal(t, tt.expected, ast.Modules[0].Declarations[0].(*VariableDecl).Initializer) }) } } @@ -158,20 +158,20 @@ func TestConvertToAST_declaration_with_assignment(t *testing.T) { func TestConvertToAST_declaration_with_initializer_list_assingment(t *testing.T) { cases := []struct { literal string - expected ASTNode + expected Node }{ { literal: "{[0] = 1, [2] = 2}", expected: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 13, 2, 13+18).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 13+18).Build(), Args: []Expression{ - ArgParamPathSet{ + &ArgParamPathSet{ Path: "[0]", - Expr: IntegerLiteral{Value: "1"}, + Expr: &IntegerLiteral{Value: "1"}, }, - ArgParamPathSet{ + &ArgParamPathSet{ Path: "[2]", - Expr: IntegerLiteral{Value: "2"}, + Expr: &IntegerLiteral{Value: "2"}, }, }, }, @@ -179,9 +179,9 @@ func TestConvertToAST_declaration_with_initializer_list_assingment(t *testing.T) { literal: "{[0] = Type}", expected: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 13, 2, 13+12).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 13+12).Build(), Args: []Expression{ - ArgParamPathSet{ + &ArgParamPathSet{ Path: "[0]", Expr: NewTypeInfoBuilder(). WithStartEnd(2, 13+7, 2, 13+11). @@ -195,11 +195,11 @@ func TestConvertToAST_declaration_with_initializer_list_assingment(t *testing.T) { literal: "{[0..2] = 2}", expected: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 13, 2, 25).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 25).Build(), Args: []Expression{ - ArgParamPathSet{ + &ArgParamPathSet{ Path: "[0..2]", - Expr: IntegerLiteral{Value: "2"}, + Expr: &IntegerLiteral{Value: "2"}, }, }, }, @@ -207,12 +207,12 @@ func TestConvertToAST_declaration_with_initializer_list_assingment(t *testing.T) { literal: "{.a = 1}", expected: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 13, 2, 13+8).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 13+8).Build(), Args: []Expression{ - ArgFieldSet{ + &ArgFieldSet{ //ASTNodeBase: NewBaseNodeBuilder().WithStartEnd(2, 13+2, 2, 13+3).Build(), FieldName: "a", - Expr: IntegerLiteral{Value: "1"}, + Expr: &IntegerLiteral{Value: "1"}, }, }, }, @@ -220,7 +220,7 @@ func TestConvertToAST_declaration_with_initializer_list_assingment(t *testing.T) { literal: "{Type}", expected: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 13, 2, 13+6).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 13+6).Build(), Args: []Expression{ NewTypeInfoBuilder(). WithStartEnd(2, 13+1, 2, 13+5). @@ -233,25 +233,25 @@ func TestConvertToAST_declaration_with_initializer_list_assingment(t *testing.T) { literal: "{$vasplat()}", expected: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 13, 2, 25).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 25).Build(), Args: []Expression{ - Literal{Value: "$vasplat()"}, + &Literal{Value: "$vasplat()"}, }, }, }, { literal: "{$vasplat(0..1)}", expected: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 13, 2, 29).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 29).Build(), Args: []Expression{ - Literal{Value: "$vasplat(0..1)"}, + &Literal{Value: "$vasplat(0..1)"}, }, }, }, { literal: "{...id}", expected: InitializerList{ - ASTBaseNode: NewBaseNodeBuilder(TypeInitializerList).WithStartEnd(2, 13, 2, 20).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 13, 2, 20).Build(), Args: []Expression{ NewIdentifierBuilder(). WithName("id"). @@ -289,7 +289,7 @@ func TestConvertToAST_declaration_with_initializer_list_assingment(t *testing.T) ast := ConvertToAST(GetCST(source), source, "file.c3") - assert.Equal(t, tt.expected, ast.Modules[0].Variables[0].Initializer) + assert.Equal(t, tt.expected, ast.Modules[0].Declarations[0].(*VariableDecl).Initializer) }) } } @@ -328,14 +328,47 @@ func TestConvertToAST_function_statements_call_with_arguments(t *testing.T) { } func TestConvertToAST_function_statements_call_chain(t *testing.T) { - t.Skip("TODO") - source := ` + cases := []struct { + skip bool + input string + expected *FunctionCall + }{ + { + skip: false, + input: "object.call(1);", + expected: &FunctionCall{ + NodeAttributes: NodeAttributes{ + StartPos: Position{Line: 3, Column: 2}, + EndPos: Position{Line: 3, Column: 16}, + }, + Identifier: &SelectorExpr{ + X: Ident{Name: "object"}, + Sel: Ident{Name: "call"}, + }, + Arguments: []Expression{ + &IntegerLiteral{Value: "1"}, + }, + }, + }, + } + + for i, tt := range cases { + if tt.skip { + continue + } + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + source := ` module foo; fn void main() { - object.call(1).call2(3); - }` + ` + tt.input + ` + }` - ConvertToAST(GetCST(source), source, "file.c3") + ast := ConvertToAST(GetCST(source), source, "file.c3") + call := ast.Modules[0].Declarations[0].(*FunctionDecl).Body.(*CompoundStmt).Statements[0].(*ExpressionStmt).Expr.(*FunctionCall) + + assert.Equal(t, tt.expected, call) + }) + } } func TestConvertToAST_compile_time_call(t *testing.T) { @@ -361,20 +394,20 @@ func TestConvertToAST_compile_time_call(t *testing.T) { { input: "$(10)", // literal ArgumentTypeName: "IntegerLiteral", - Argument: IntegerLiteral{Value: "10"}, + Argument: &IntegerLiteral{Value: "10"}, }, { input: "$(a[5])", - ArgumentTypeName: "IndexAccess", - Argument: IndexAccess{ + ArgumentTypeName: "IndexAccessExpr", + Argument: &IndexAccessExpr{ Array: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 10, 1, 11).Build(), Index: "[5]", }, }, { input: "$(a[5..6])", - ArgumentTypeName: "RangeAccess", - Argument: RangeAccess{ + ArgumentTypeName: "RangeAccessExpr", + Argument: &RangeAccessExpr{ Array: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 10, 1, 11).Build(), RangeStart: 5, RangeEnd: 6, @@ -407,24 +440,24 @@ func TestConvertToAST_compile_time_call(t *testing.T) { source := `module foo; int x = ` + input + `;` ast := ConvertToAST(GetCST(source), source, "file.c3") - initializer := ast.Modules[0].Variables[0].Initializer.(FunctionCall) + initializer := ast.Modules[0].Declarations[0].(*VariableDecl).Initializer.(*FunctionCall) - assert.Equal(t, method, initializer.Identifier.(Identifier).Name) + assert.Equal(t, method, initializer.Identifier.(Ident).Name) arg := initializer.Arguments[0] switch arg.(type) { - case Literal: + case *Literal: if tt.ArgumentTypeName != "Literal" { t.Errorf("Expected argument must be Literal. It was %s", tt.ArgumentTypeName) } - e := tt.Argument.(Literal) - assert.Equal(t, e.Value, arg.(Literal).Value) - case IntegerLiteral: + e := tt.Argument.(*Literal) + assert.Equal(t, e.Value, arg.(*Literal).Value) + case *IntegerLiteral: if tt.ArgumentTypeName != "IntegerLiteral" { t.Errorf("Expected argument must be IntegerLiteral. It was %s", tt.ArgumentTypeName) } - e := tt.Argument.(IntegerLiteral) - assert.Equal(t, e.Value, arg.(IntegerLiteral).Value) + e := tt.Argument.(*IntegerLiteral) + assert.Equal(t, e.Value, arg.(*IntegerLiteral).Value) case TypeInfo: if tt.ArgumentTypeName != "TypeInfo" { @@ -433,21 +466,21 @@ func TestConvertToAST_compile_time_call(t *testing.T) { e := tt.Argument.(TypeInfo) assert.Equal(t, e.Identifier.Name, arg.(TypeInfo).Identifier.Name) - case IndexAccess: - if tt.ArgumentTypeName != "IndexAccess" { - t.Errorf("Expected argument must be IndexAccess. It was %s", tt.ArgumentTypeName) + case *IndexAccessExpr: + if tt.ArgumentTypeName != "IndexAccessExpr" { + t.Errorf("Expected argument must be IndexAccessExpr. It was %s", tt.ArgumentTypeName) } - e := tt.Argument.(IndexAccess) - assert.Equal(t, e.Array.(Identifier).Name, arg.(IndexAccess).Array.(Identifier).Name) + e := tt.Argument.(*IndexAccessExpr) + assert.Equal(t, e.Array.(Ident).Name, arg.(*IndexAccessExpr).Array.(Ident).Name) - case RangeAccess: - if tt.ArgumentTypeName != "RangeAccess" { - t.Errorf("Expected argument must be RangeAccess. It was %s", tt.ArgumentTypeName) + case *RangeAccessExpr: + if tt.ArgumentTypeName != "RangeAccessExpr" { + t.Errorf("Expected argument must be RangeAccessExpr. It was %s", tt.ArgumentTypeName) } - e := tt.Argument.(RangeAccess) - assert.Equal(t, e.Array.(Identifier).Name, arg.(RangeAccess).Array.(Identifier).Name) - assert.Equal(t, e.RangeStart, arg.(RangeAccess).RangeStart) - assert.Equal(t, e.RangeEnd, arg.(RangeAccess).RangeEnd) + e := tt.Argument.(*RangeAccessExpr) + assert.Equal(t, e.Array.(Ident).Name, arg.(*RangeAccessExpr).Array.(Ident).Name) + assert.Equal(t, e.RangeStart, arg.(*RangeAccessExpr).RangeStart) + assert.Equal(t, e.RangeEnd, arg.(*RangeAccessExpr).RangeEnd) default: t.Errorf("Expected argument wrong type.") @@ -477,12 +510,12 @@ func TestConvertToAST_compile_time_argument_call(t *testing.T) { int x = ` + method + `(id);` ast := ConvertToAST(GetCST(source), source, "file.c3") - initializer := ast.Modules[0].Variables[0].Initializer.(FunctionCall) + initializer := ast.Modules[0].Declarations[0].(*VariableDecl).Initializer.(*FunctionCall) assert.Equal(t, FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(1, 12, 1, 16+length).Build(), - Identifier: NewIdentifierBuilder().WithName(method).WithStartEnd(1, 12, 1, 12+length).Build(), - Arguments: []Arg{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 12, 1, 16+length).Build(), + Identifier: NewIdentifierBuilder().WithName(method).WithStartEnd(1, 12, 1, 12+length).Build(), + Arguments: []Expression{ NewIdentifierBuilder().WithName("id").WithStartEnd(1, 12+length+1, 1, 14+length+1).Build(), }, }, initializer) @@ -499,9 +532,9 @@ func TestConvertToAST_compile_time_analyse(t *testing.T) { { input: "$eval(id)", expected: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(1, 12, 1, 21).Build(), - Identifier: NewIdentifierBuilder().WithName("$eval").WithStartEnd(1, 12, 1, 17).Build(), - Arguments: []Arg{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 12, 1, 21).Build(), + Identifier: NewIdentifierBuilder().WithName("$eval").WithStartEnd(1, 12, 1, 17).Build(), + Arguments: []Expression{ NewIdentifierBuilder().WithName("id").WithStartEnd(1, 18, 1, 20).Build(), }, }, @@ -512,7 +545,7 @@ func TestConvertToAST_compile_time_analyse(t *testing.T) { input: "$and(id)", expected: FunctionCall{ ASTNodeBase: NewBaseNodeBuilder().WithStartEnd(1, 12, 1, 19).Build(), - Identifier: NewIdentifierBuilder().WithName("$and").WithStartEnd(1, 12, 1, 16).Build(), + Ident: NewIdentifierBuilder().WithName("$and").WithStartEnd(1, 12, 1, 16).Build(), Arguments: []Arg{ NewIdentifierBuilder().WithName("id").WithStartEnd(1, 17, 1, 19).Build(), }, @@ -541,7 +574,7 @@ func TestConvertToAST_compile_time_analyse(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - assert.Equal(t, tt.expected, ast.Modules[0].Variables[0].Initializer.(FunctionCall)) + assert.Equal(t, tt.expected, ast.Modules[0].Declarations[0].(*VariableDecl).Initializer.(*FunctionCall)) }) } } @@ -550,12 +583,12 @@ func TestConvertToAST_lambda_declaration(t *testing.T) { cases := []struct { skip bool input string - expected LambdaDeclaration + expected LambdaDeclarationExpr }{ { input: "int i = fn int (int a, int b){};", - expected: LambdaDeclaration{ - ASTBaseNode: NewBaseNodeBuilder(TypeLambdaDecl).WithStartEnd(1, 8, 1, 29).Build(), + expected: LambdaDeclarationExpr{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 8, 1, 29).Build(), ReturnType: option.Some[TypeInfo](NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). @@ -564,8 +597,8 @@ func TestConvertToAST_lambda_declaration(t *testing.T) { Build()), Parameters: []FunctionParameter{ { - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter).WithStartEnd(1, 16, 1, 21).Build(), - Name: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 20, 1, 21).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 16, 1, 21).Build(), + Name: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 20, 1, 21).Build(), Type: NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). @@ -574,8 +607,8 @@ func TestConvertToAST_lambda_declaration(t *testing.T) { Build(), }, { - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionParameter).WithStartEnd(1, 23, 1, 28).Build(), - Name: NewIdentifierBuilder().WithName("b").WithStartEnd(1, 27, 1, 28).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 23, 1, 28).Build(), + Name: NewIdentifierBuilder().WithName("b").WithStartEnd(1, 27, 1, 28).Build(), Type: NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). @@ -584,21 +617,21 @@ func TestConvertToAST_lambda_declaration(t *testing.T) { Build(), }, }, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(1, 29, 1, 31).Build(), - Statements: []Expression{}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 29, 1, 31).Build(), + Statements: []Statement{}, }, }, }, { input: "int i = fn (){};", - expected: LambdaDeclaration{ - ASTBaseNode: NewBaseNodeBuilder(TypeLambdaDecl).WithStartEnd(1, 8, 1, 13).Build(), - Parameters: []FunctionParameter{}, - ReturnType: option.None[TypeInfo](), - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(1, 13, 1, 15).Build(), - Statements: []Expression{}, + expected: LambdaDeclarationExpr{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 8, 1, 13).Build(), + Parameters: []FunctionParameter{}, + ReturnType: option.None[TypeInfo](), + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 13, 1, 15).Build(), + Statements: []Statement{}, }, }, }, @@ -617,7 +650,7 @@ func TestConvertToAST_lambda_declaration(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - assert.Equal(t, tt.expected, ast.Modules[0].Variables[0].Initializer.(LambdaDeclaration)) + assert.Equal(t, tt.expected, ast.Modules[0].Declarations[0].(*VariableDecl).Initializer.(*LambdaDeclarationExpr)) }) } } @@ -631,17 +664,17 @@ func TestConvertToAST_assignment_expr(t *testing.T) { { input: "i = 10;", expected: AssignmentStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeAssignmentStatement).WithStartEnd(1, 19, 1, 19+6).Build(), - Left: NewIdentifierBuilder().WithName("i").WithStartEnd(1, 19, 1, 20).Build(), - Right: IntegerLiteral{Value: "10"}, - Operator: "=", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 19, 1, 19+6).Build(), + Left: NewIdentifierBuilder().WithName("i").WithStartEnd(1, 19, 1, 20).Build(), + Right: &IntegerLiteral{Value: "10"}, + Operator: "=", }, }, { input: "$CompileTimeType = Type;", expected: AssignmentStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeAssignmentStatement).WithStartEnd(1, 19, 1, 19+23).Build(), - Left: Literal{Value: "$CompileTimeType"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 19, 1, 19+23).Build(), + Left: &Literal{Value: "$CompileTimeType"}, Right: NewTypeInfoBuilder(). WithName("Type"). WithNameStartEnd(1, 38, 1, 42). @@ -665,8 +698,8 @@ func TestConvertToAST_assignment_expr(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - cmp_stmts := ast.Modules[0].Functions[0].(FunctionDecl).Body.(CompoundStatement) - assert.Equal(t, tt.expected, cmp_stmts.Statements[0].(AssignmentStatement)) + cmp_stmts := ast.Modules[0].Declarations[0].(*FunctionDecl).Body.(CompoundStmt) + assert.Equal(t, tt.expected, cmp_stmts.Statements[0].(*AssignmentStatement)) }) } } @@ -680,12 +713,12 @@ func TestConvertToAST_ternary_expr(t *testing.T) { { input: "i > 10 ? a:b;", expected: TernaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeTernaryExpr).WithStartEnd(1, 19, 1, 19+12).Build(), - Condition: BinaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeBinaryExpr).WithStartEnd(1, 19, 1, 25).Build(), - Left: NewIdentifierBuilder().WithName("i").WithStartEnd(1, 19, 1, 20).Build(), - Operator: ">", - Right: IntegerLiteral{Value: "10"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 19, 1, 19+12).Build(), + Condition: &BinaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 19, 1, 25).Build(), + Left: NewIdentifierBuilder().WithName("i").WithStartEnd(1, 19, 1, 20).Build(), + Operator: ">", + Right: IntegerLiteral{Value: "10"}, }, Consequence: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 19+9, 1, 19+10).Build(), Alternative: NewIdentifierBuilder().WithName("b").WithStartEnd(1, 19+11, 1, 19+12).Build(), @@ -706,8 +739,8 @@ func TestConvertToAST_ternary_expr(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - cmp_stmts := ast.Modules[0].Functions[0].(FunctionDecl).Body.(CompoundStatement) - assert.Equal(t, tt.expected, cmp_stmts.Statements[0].(TernaryExpression)) + cmp_stmts := ast.Modules[0].Declarations[0].(*FunctionDecl).Body.(CompoundStmt) + assert.Equal(t, tt.expected, cmp_stmts.Statements[0].(*ExpressionStmt).Expr) //TernaryExpression }) } } @@ -718,8 +751,9 @@ func TestConvertToAST_lambda_expr(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - expected := LambdaDeclaration{ - ASTBaseNode: NewBaseNodeBuilder(TypeLambdaDecl).WithStartEnd(1, 9, 1, 24).Build(), + literal := IntegerLiteral{Value: "10"} + expected := LambdaDeclarationExpr{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 9, 1, 24).Build(), ReturnType: option.Some(NewTypeInfoBuilder(). WithStartEnd(1, 12, 1, 15). WithName("int"). @@ -728,13 +762,13 @@ func TestConvertToAST_lambda_expr(t *testing.T) { Build(), ), Parameters: []FunctionParameter{}, - Body: ReturnStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeReturnStatement).WithStartEnd(1, 22, 1, 24).Build(), - Return: option.Some(Expression(IntegerLiteral{Value: "10"})), + Body: &ReturnStatement{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 22, 1, 24).Build(), + Return: option.Some[Expression](&literal), }, } - lambda := ast.Modules[0].Variables[0].Initializer.(LambdaDeclaration) + lambda := ast.Modules[0].Declarations[0].(*VariableDecl).Initializer.(*LambdaDeclarationExpr) assert.Equal(t, expected, lambda) } @@ -749,20 +783,20 @@ func TestConvertToAST_elvis_or_else_expr(t *testing.T) { source: `module foo; int i = condition ?: 10;`, expected: TernaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeTernaryExpr).WithStartEnd(1, 11, 1, 26).Build(), - Condition: NewIdentifierBuilder().WithName("condition").WithStartEnd(1, 11, 1, 20).Build(), - Consequence: NewIdentifierBuilder().WithName("condition").WithStartEnd(1, 11, 1, 20).Build(), - Alternative: IntegerLiteral{Value: "10"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 26).Build(), + Condition: NewIdentifierBuilder().WithName("condition").WithStartEnd(1, 11, 1, 20).Build(), + Consequence: NewIdentifierBuilder().WithName("condition").WithStartEnd(1, 11, 1, 20).Build(), + Alternative: &IntegerLiteral{Value: "10"}, }, }, { source: `module foo; int i = condition ?? 10;`, expected: TernaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeTernaryExpr).WithStartEnd(1, 11, 1, 26).Build(), - Condition: NewIdentifierBuilder().WithName("condition").WithStartEnd(1, 11, 1, 20).Build(), - Consequence: NewIdentifierBuilder().WithName("condition").WithStartEnd(1, 11, 1, 20).Build(), - Alternative: IntegerLiteral{Value: "10"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 26).Build(), + Condition: NewIdentifierBuilder().WithName("condition").WithStartEnd(1, 11, 1, 20).Build(), + Consequence: NewIdentifierBuilder().WithName("condition").WithStartEnd(1, 11, 1, 20).Build(), + Alternative: &IntegerLiteral{Value: "10"}, }, }, } @@ -777,7 +811,7 @@ func TestConvertToAST_elvis_or_else_expr(t *testing.T) { func(t *testing.T) { ast := ConvertToAST(GetCST(tt.source), tt.source, "file.c3") - assert.Equal(t, tt.expected, ast.Modules[0].Variables[0].Initializer.(TernaryExpression)) + assert.Equal(t, tt.expected, ast.Modules[0].Declarations[0].(*VariableDecl).Initializer.(*TernaryExpression)) }) } } @@ -792,13 +826,13 @@ func TestConvertToAST_optional_expr(t *testing.T) { source: `module foo; int b = a + b?;`, expected: OptionalExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeOptionalExpr).WithStartEnd(1, 11, 1, 17).Build(), - Operator: "?", - Argument: BinaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeBinaryExpr).WithStartEnd(1, 11, 1, 16).Build(), - Left: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 11, 1, 12).Build(), - Right: NewIdentifierBuilder().WithName("b").WithStartEnd(1, 15, 1, 16).Build(), - Operator: "+", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 17).Build(), + Operator: "?", + Argument: &BinaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 16).Build(), + Left: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 11, 1, 12).Build(), + Right: NewIdentifierBuilder().WithName("b").WithStartEnd(1, 15, 1, 16).Build(), + Operator: "+", }, }, }, @@ -806,13 +840,13 @@ func TestConvertToAST_optional_expr(t *testing.T) { source: `module foo; int b = a + b?!;`, expected: OptionalExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeOptionalExpr).WithStartEnd(1, 11, 1, 18).Build(), - Operator: "?!", - Argument: BinaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeBinaryExpr).WithStartEnd(1, 11, 1, 16).Build(), - Left: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 11, 1, 12).Build(), - Right: NewIdentifierBuilder().WithName("b").WithStartEnd(1, 15, 1, 16).Build(), - Operator: "+", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 18).Build(), + Operator: "?!", + Argument: &BinaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 16).Build(), + Left: NewIdentifierBuilder().WithName("a").WithStartEnd(1, 11, 1, 12).Build(), + Right: NewIdentifierBuilder().WithName("b").WithStartEnd(1, 15, 1, 16).Build(), + Operator: "+", }, }, }, @@ -828,7 +862,7 @@ func TestConvertToAST_optional_expr(t *testing.T) { func(t *testing.T) { ast := ConvertToAST(GetCST(tt.source), tt.source, "file.c3") - assert.Equal(t, tt.expected, ast.Modules[0].Variables[0].Initializer.(OptionalExpression)) + assert.Equal(t, tt.expected, ast.Modules[0].Declarations[0].(*VariableDecl).Initializer.(*OptionalExpression)) }) } } @@ -844,15 +878,15 @@ func TestConvertToAST_unary_expr(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - stmt := ast.Modules[0].Functions[0].(FunctionDecl).Body.(CompoundStatement).Statements[0] + stmt := ast.Modules[0].Declarations[0].(*FunctionDecl).Body.(CompoundStmt).Statements[0] assert.Equal(t, UnaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUnaryExpr).WithStartEnd(2, 2, 2, 5).Build(), - Operator: "++", - Argument: NewIdentifierBuilder().WithName("b").WithStartEnd(2, 4, 2, 5).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 2, 2, 5).Build(), + Operator: "++", + Argument: NewIdentifierBuilder().WithName("b").WithStartEnd(2, 4, 2, 5).Build(), }, - stmt.(UnaryExpression), + stmt.(*ExpressionStmt).Expr, ) } @@ -863,11 +897,11 @@ func TestConvertToAST_cast_expr(t *testing.T) { }` ast := ConvertToAST(GetCST(source), source, "file.c3") - stmt := ast.Modules[0].Functions[0].(FunctionDecl).Body.(CompoundStatement).Statements[0] + stmt := ast.Modules[0].Declarations[0].(*FunctionDecl).Body.(CompoundStmt).Statements[0] assert.Equal(t, CastExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeCastExpr).WithStartEnd(2, 2, 2, 8).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 2, 2, 8).Build(), Type: NewTypeInfoBuilder(). WithName("int"). WithNameStartEnd(2, 3, 2, 6). @@ -876,7 +910,7 @@ func TestConvertToAST_cast_expr(t *testing.T) { Build(), Argument: NewIdentifierBuilder().WithName("b").WithStartEnd(2, 7, 2, 8).Build(), }, - stmt.(CastExpression), + stmt.(*ExpressionStmt).Expr, //CastExpression), ) } @@ -891,12 +925,12 @@ func TestConvertToAST_rethrow_expr(t *testing.T) { source: `module foo; int b = foo_may_error()!;`, expected: RethrowExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeRethrowExpr).WithStartEnd(1, 11, 1, 27).Build(), - Operator: "!", - Argument: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(1, 11, 1, 26).Build(), - Identifier: NewIdentifierBuilder().WithName("foo_may_error").WithStartEnd(1, 11, 1, 24).Build(), - Arguments: []Arg{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 27).Build(), + Operator: "!", + Argument: &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 26).Build(), + Identifier: NewIdentifierBuilder().WithName("foo_may_error").WithStartEnd(1, 11, 1, 24).Build(), + Arguments: []Expression{}, }, }, }, @@ -904,12 +938,12 @@ func TestConvertToAST_rethrow_expr(t *testing.T) { source: `module foo; int b = foo_may_error()!!;`, expected: RethrowExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeRethrowExpr).WithStartEnd(1, 11, 1, 28).Build(), - Operator: "!!", - Argument: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(1, 11, 1, 26).Build(), - Identifier: NewIdentifierBuilder().WithName("foo_may_error").WithStartEnd(1, 11, 1, 24).Build(), - Arguments: []Arg{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 28).Build(), + Operator: "!!", + Argument: &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 11, 1, 26).Build(), + Identifier: NewIdentifierBuilder().WithName("foo_may_error").WithStartEnd(1, 11, 1, 24).Build(), + Arguments: []Expression{}, }, }, }, @@ -925,7 +959,7 @@ func TestConvertToAST_rethrow_expr(t *testing.T) { func(t *testing.T) { ast := ConvertToAST(GetCST(tt.source), tt.source, "file.c3") - assert.Equal(t, tt.expected, ast.Modules[0].Variables[0].Initializer.(RethrowExpression)) + assert.Equal(t, tt.expected, ast.Modules[0].Declarations[0].(*VariableDecl).Initializer.(*RethrowExpression)) }) } } @@ -942,9 +976,9 @@ func TestConvertToAST_call_expr(t *testing.T) { simple(); }`, expected: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(2, 4, 2, 12).Build(), - Identifier: NewIdentifierBuilder().WithName("simple").WithStartEnd(2, 4, 2, 10).Build(), - Arguments: []Arg{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 12).Build(), + Identifier: NewIdentifierBuilder().WithName("simple").WithStartEnd(2, 4, 2, 10).Build(), + Arguments: []Expression{}, }, }, { @@ -953,9 +987,9 @@ func TestConvertToAST_call_expr(t *testing.T) { simple(a, b); }`, expected: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(2, 4, 2, 16).Build(), - Identifier: NewIdentifierBuilder().WithName("simple").WithStartEnd(2, 4, 2, 10).Build(), - Arguments: []Arg{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 16).Build(), + Identifier: NewIdentifierBuilder().WithName("simple").WithStartEnd(2, 4, 2, 10).Build(), + Arguments: []Expression{ NewIdentifierBuilder().WithName("a").WithStartEnd(2, 11, 2, 12).Build(), NewIdentifierBuilder().WithName("b").WithStartEnd(2, 14, 2, 15).Build(), }, @@ -969,9 +1003,9 @@ func TestConvertToAST_call_expr(t *testing.T) { simple(a, b) @attributes; }`, expected: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(2, 4, 2, 16).Build(), - Identifier: NewIdentifierBuilder().WithName("simple").WithStartEnd(2, 4, 2, 10).Build(), - Arguments: []Arg{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 16).Build(), + Identifier: NewIdentifierBuilder().WithName("simple").WithStartEnd(2, 4, 2, 10).Build(), + Arguments: []Expression{ NewIdentifierBuilder().WithName("a").WithStartEnd(2, 11, 2, 12).Build(), NewIdentifierBuilder().WithName("b").WithStartEnd(2, 14, 2, 15).Build(), }, @@ -988,21 +1022,21 @@ func TestConvertToAST_call_expr(t *testing.T) { }; }`, expected: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(2, 4, 5, 5).Build(), - Identifier: NewIdentifierBuilder().WithName("$simple").WithStartEnd(2, 4, 2, 11).Build(), - Arguments: []Arg{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 5, 5).Build(), + Identifier: NewIdentifierBuilder().WithName("$simple").WithStartEnd(2, 4, 2, 11).Build(), + Arguments: []Expression{ NewIdentifierBuilder().WithName("a").WithStartEnd(2, 12, 2, 13).Build(), NewIdentifierBuilder().WithName("b").WithStartEnd(2, 15, 2, 16).Build(), }, TrailingBlock: option.Some( - CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 4, 5, 5).Build(), - Statements: []Expression{ - AssignmentStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeAssertStatement).WithStartEnd(4, 8, 4, 13).Build(), - Left: NewIdentifierBuilder().WithName("a").WithStartEnd(4, 8, 4, 9).Build(), - Right: IntegerLiteral{Value: "1"}, - Operator: "=", + &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 4, 5, 5).Build(), + Statements: []Statement{ + &AssignmentStatement{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 8, 4, 13).Build(), + Left: NewIdentifierBuilder().WithName("a").WithStartEnd(4, 8, 4, 9).Build(), + Right: &IntegerLiteral{Value: "1"}, + Operator: "=", }, }, }, @@ -1021,8 +1055,8 @@ func TestConvertToAST_call_expr(t *testing.T) { func(t *testing.T) { ast := ConvertToAST(GetCST(tt.source), tt.source, "file.c3") - mainFnc := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, mainFnc.Body.(CompoundStatement).Statements[0].(FunctionCall)) + mainFnc := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, mainFnc.Body.(CompoundStmt).Statements[0].(*ExpressionStmt).Expr) //FunctionCall)) }) } } @@ -1039,22 +1073,22 @@ func TestConvertToAST_trailing_generic_expr(t *testing.T) { test()(1.0, &g); }`, expected: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(2, 4, 2, 32).Build(), - Identifier: Identifier{ - ASTBaseNode: NewBaseNodeBuilder(TypeIdentifier).WithStartEnd(2, 4, 2, 8).Build(), - Name: "test", - Path: "", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 32).Build(), + Identifier: Ident{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 8).Build(), + Name: "test", + ModulePath: "", }, GenericArguments: option.Some([]Expression{ NewTypeInfoBuilder().WithName("int").IsBuiltin().WithNameStartEnd(2, 10, 2, 13).WithStartEnd(2, 10, 2, 13).Build(), NewTypeInfoBuilder().WithName("double").IsBuiltin().WithNameStartEnd(2, 15, 2, 21).WithStartEnd(2, 15, 2, 21).Build(), }), - Arguments: []Arg{ - RealLiteral{Value: "1.0"}, - UnaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUnaryExpr).WithStartEnd(2, 29, 2, 31).Build(), - Operator: "&", - Argument: NewIdentifierBuilder().WithName("g").WithStartEnd(2, 30, 2, 31).Build(), + Arguments: []Expression{ + &RealLiteral{Value: "1.0"}, + &UnaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 29, 2, 31).Build(), + Operator: "&", + Argument: NewIdentifierBuilder().WithName("g").WithStartEnd(2, 30, 2, 31).Build(), }, }, }, @@ -1065,7 +1099,7 @@ func TestConvertToAST_trailing_generic_expr(t *testing.T) { foo_test::test()(1.0, &g); }`, expected: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(2, 4, 2, 42).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 42).Build(), Identifier: NewIdentifierBuilder(). WithName("test"). WithPath("foo_test"). @@ -1075,12 +1109,12 @@ func TestConvertToAST_trailing_generic_expr(t *testing.T) { NewTypeInfoBuilder().WithName("int").IsBuiltin().WithNameStartEnd(2, 20, 2, 23).WithStartEnd(2, 20, 2, 23).Build(), NewTypeInfoBuilder().WithName("double").IsBuiltin().WithNameStartEnd(2, 25, 2, 31).WithStartEnd(2, 25, 2, 31).Build(), }), - Arguments: []Arg{ - RealLiteral{Value: "1.0"}, - UnaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUnaryExpr).WithStartEnd(2, 39, 2, 41).Build(), - Operator: "&", - Argument: NewIdentifierBuilder().WithName("g").WithStartEnd(2, 40, 2, 41).Build(), + Arguments: []Expression{ + &RealLiteral{Value: "1.0"}, + &UnaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 39, 2, 41).Build(), + Operator: "&", + Argument: NewIdentifierBuilder().WithName("g").WithStartEnd(2, 40, 2, 41).Build(), }, }, }, @@ -1100,7 +1134,7 @@ func TestConvertToAST_trailing_generic_expr(t *testing.T) { assert.Equal( t, tt.expected, - ast.Modules[0].Functions[0].(FunctionDecl).Body.(CompoundStatement).Statements[0].(FunctionCall), + ast.Modules[0].Declarations[0].(*FunctionDecl).Body.(CompoundStmt).Statements[0].(*ExpressionStmt).Expr, //FunctionCall), ) }, ) @@ -1119,11 +1153,11 @@ func TestConvertToAST_update_expr(t *testing.T) { a++; }`, expected: UpdateExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUpdateExpr).WithStartEnd(2, 4, 2, 7).Build(), - Operator: "++", - Argument: Identifier{ - ASTBaseNode: NewBaseNodeBuilder(TypeIdentifier).WithStartEnd(2, 4, 2, 5).Build(), - Name: "a", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 7).Build(), + Operator: "++", + Argument: Ident{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 5).Build(), + Name: "a", }, }, }, @@ -1133,8 +1167,8 @@ func TestConvertToAST_update_expr(t *testing.T) { a--; }`, expected: UpdateExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUpdateExpr).WithStartEnd(2, 4, 2, 7).Build(), - Operator: "--", + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 7).Build(), + Operator: "--", Argument: NewIdentifierBuilder(). WithName("a"). WithStartEnd(2, 4, 2, 5). @@ -1156,7 +1190,7 @@ func TestConvertToAST_update_expr(t *testing.T) { assert.Equal( t, tt.expected, - ast.Modules[0].Functions[0].(FunctionDecl).Body.(CompoundStatement).Statements[0].(UpdateExpression), + ast.Modules[0].Declarations[0].(*FunctionDecl).Body.(CompoundStmt).Statements[0].(*ExpressionStmt).Expr, //(UpdateExpression), ) }, ) @@ -1175,9 +1209,9 @@ func TestConvertToAST_subscript_expr(t *testing.T) { a[0]; }`, expected: SubscriptExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeSubscriptExpr).WithStartEnd(2, 4, 2, 8).Build(), - Argument: NewIdentifierBuilder().WithName("a").WithStartEnd(2, 4, 2, 5).Build(), - Index: IntegerLiteral{Value: "0"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 8).Build(), + Argument: NewIdentifierBuilder().WithName("a").WithStartEnd(2, 4, 2, 5).Build(), + Index: &IntegerLiteral{Value: "0"}, }, }, { @@ -1186,10 +1220,10 @@ func TestConvertToAST_subscript_expr(t *testing.T) { a[0..2]; }`, expected: SubscriptExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeSubscriptExpr).WithStartEnd(2, 5, 2, 12).Build(), - Argument: NewIdentifierBuilder().WithName("a").WithStartEnd(2, 5, 2, 6).Build(), - Index: RangeIndex{ - //ASTBaseNode: NewBaseNodeBuilder().WithStartEnd(2, 6, 2, 9).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 5, 2, 12).Build(), + Argument: NewIdentifierBuilder().WithName("a").WithStartEnd(2, 5, 2, 6).Build(), + Index: &RangeIndexExpr{ + //NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 6, 2, 9).Build(), Start: option.Some(uint(0)), End: option.Some(uint(2)), }, @@ -1201,9 +1235,9 @@ func TestConvertToAST_subscript_expr(t *testing.T) { a[id]; }`, expected: SubscriptExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeSubscriptExpr).WithStartEnd(2, 4, 2, 9).Build(), - Argument: NewIdentifierBuilder().WithName("a").WithStartEnd(2, 4, 2, 5).Build(), - Index: NewIdentifierBuilder().WithName("id").WithStartEnd(2, 6, 2, 8).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 9).Build(), + Argument: NewIdentifierBuilder().WithName("a").WithStartEnd(2, 4, 2, 5).Build(), + Index: NewIdentifierBuilder().WithName("id").WithStartEnd(2, 6, 2, 8).Build(), }, }, { @@ -1212,12 +1246,12 @@ func TestConvertToAST_subscript_expr(t *testing.T) { a[call()]; }`, expected: SubscriptExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeSubscriptExpr).WithStartEnd(2, 4, 2, 13).Build(), - Argument: NewIdentifierBuilder().WithName("a").WithStartEnd(2, 4, 2, 5).Build(), - Index: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(2, 6, 2, 12).Build(), - Identifier: NewIdentifierBuilder().WithName("call").WithStartEnd(2, 6, 2, 10).Build(), - Arguments: []Arg{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 4, 2, 13).Build(), + Argument: NewIdentifierBuilder().WithName("a").WithStartEnd(2, 4, 2, 5).Build(), + Index: &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 6, 2, 12).Build(), + Identifier: NewIdentifierBuilder().WithName("call").WithStartEnd(2, 6, 2, 10).Build(), + Arguments: []Expression{}, }, }, }, @@ -1236,7 +1270,7 @@ func TestConvertToAST_subscript_expr(t *testing.T) { assert.Equal( t, tt.expected, - ast.Modules[0].Functions[0].(FunctionDecl).Body.(CompoundStatement).Statements[0].(SubscriptExpression), + ast.Modules[0].Declarations[0].(*FunctionDecl).Body.(CompoundStmt).Statements[0].(*ExpressionStmt).Expr, //SubscriptExpression), ) }, ) diff --git a/server/internal/lsp/ast/convert_rules.go b/server/internal/lsp/ast/convert_rules.go index 852b635..e9d9ce4 100644 --- a/server/internal/lsp/ast/convert_rules.go +++ b/server/internal/lsp/ast/convert_rules.go @@ -137,7 +137,7 @@ func (t TryConversionFunc) Validate(node *sitter.Node, source []byte) bool { expr = nil } }() - expr = conversion.convert(node, source) + expr = conversion.convert(node, source).(Expression) }() return expr != nil diff --git a/server/internal/lsp/ast/convert_rules_exec.go b/server/internal/lsp/ast/convert_rules_exec.go index d7d513d..d73d4bf 100644 --- a/server/internal/lsp/ast/convert_rules_exec.go +++ b/server/internal/lsp/ast/convert_rules_exec.go @@ -2,17 +2,18 @@ package ast import ( "errors" + "fmt" sitter "github.com/smacker/go-tree-sitter" ) -type NodeConverter func(node *sitter.Node, source []byte) Expression +type NodeConverter func(node *sitter.Node, source []byte) Node type ConversionInfo struct { method NodeConverter goChild bool } -func (c ConversionInfo) convert(node *sitter.Node, source []byte) Expression { +func (c ConversionInfo) convert(node *sitter.Node, source []byte) Node { n := node if c.goChild { n = node.Child(0) @@ -21,98 +22,124 @@ func (c ConversionInfo) convert(node *sitter.Node, source []byte) Expression { return c.method(n, source) } +type StatementConverter func(node *sitter.Node, source []byte) Statement +type ExpressionConverter func(node *sitter.Node, source []byte) Expression +type DeclarationConverter func(node *sitter.Node, source []byte) Declaration + +func cv_stmt_fn(fn StatementConverter) NodeConverter { + return func(node *sitter.Node, source []byte) Node { + return fn(node, source).(Node) + } +} + +func cv_expr_fn(fn ExpressionConverter) NodeConverter { + return func(node *sitter.Node, source []byte) Node { + return fn(node, source).(Node) + } +} + +func cv_decl_fn(fn DeclarationConverter) NodeConverter { + return func(node *sitter.Node, source []byte) Node { + return fn(node, source).(Node) + } +} + func nodeTypeConverterMap(nodeType string) (ConversionInfo, error) { funcMap := map[string]ConversionInfo{ - "assignment_expr": {method: convert_assignment_expr}, - "assert_stmt": {method: convert_assert_stmt}, - "at_ident": {method: convert_ident}, - "binary_expr": {method: convert_binary_expr}, - "break_stmt": {method: convert_break_stmt}, - "bytes_expr": {method: convert_bytes_expr}, - "builtin": {method: convert_as_literal}, - "call_expr": {method: convert_call_expr}, - "continue_stmt": {method: convert_continue_stmt}, - "cast_expr": {method: convert_cast_expr}, - "const_ident": {method: convert_ident}, - "compound_stmt": {method: convert_compound_stmt}, - "ct_ident": {method: convert_ident}, - "declaration_stmt": {method: convert_declaration_stmt}, - "defer_stmt": {method: convert_defer_stmt}, - "do_stmt": {method: convert_do_stmt}, - "split_declaration_stmt": {method: convert_split_declaration_stmt}, - "elvis_orelse_expr": {method: convert_elvis_orelse_expr}, - "expr_stmt": {method: convert_expression, goChild: true}, - "for_stmt": {method: convert_for_stmt}, - "foreach_stmt": {method: convert_foreach_stmt}, - "hash_ident": {method: convert_ident}, - "ident": {method: convert_ident}, - "if_stmt": {method: convert_if_stmt}, - "initializer_list": {method: convert_initializer_list}, - - "lambda_declaration": {method: convert_lambda_declaration}, - "lambda_expr": {method: convert_lambda_expr}, - "local_decl_after_type": {method: convert_local_declaration_after_type}, - "module_ident_expr": {method: convert_module_ident_expr}, - "nextcase_stmt": {method: convert_nextcase_stmt}, - "optional_expr": {method: convert_optional_expr}, - "rethrow_expr": {method: convert_rethrow_expr}, - "return_stmt": {method: convert_return_stmt}, + "assignment_expr": {method: cv_stmt_fn(convert_assignment_expr)}, + "assert_stmt": {method: cv_stmt_fn(convert_assert_stmt)}, + "at_ident": {method: cv_expr_fn(convert_ident)}, + "binary_expr": {method: cv_expr_fn(convert_binary_expr)}, + "break_stmt": {method: cv_stmt_fn(convert_break_stmt)}, + "bytes_expr": {method: cv_expr_fn(convert_bytes_expr)}, + "builtin": {method: cv_expr_fn(convert_as_literal)}, + "call_expr": {method: cv_expr_fn(convert_call_expr)}, + "continue_stmt": {method: cv_stmt_fn(convert_continue_stmt)}, + "cast_expr": {method: cv_expr_fn(convert_cast_expr)}, + "const_ident": {method: cv_expr_fn(convert_ident)}, + "compound_stmt": {method: cv_stmt_fn(convert_compound_stmt)}, + "ct_ident": {method: cv_expr_fn(convert_ident)}, + "declaration_stmt": {method: cv_decl_fn(convert_declaration_stmt)}, + "defer_stmt": {method: cv_stmt_fn(convert_defer_stmt)}, + "do_stmt": {method: cv_stmt_fn(convert_do_stmt)}, + "split_declaration_stmt": {method: cv_decl_fn(convert_split_declaration_stmt)}, + "elvis_orelse_expr": {method: cv_expr_fn(convert_elvis_orelse_expr)}, + "expr_stmt": {method: cv_stmt_fn(convert_expr_stmt), goChild: true}, + "for_stmt": {method: cv_stmt_fn(convert_for_stmt)}, + "foreach_stmt": {method: cv_stmt_fn(convert_foreach_stmt)}, + "hash_ident": {method: cv_expr_fn(convert_ident)}, + "ident": {method: cv_expr_fn(convert_ident)}, + "if_stmt": {method: cv_stmt_fn(convert_if_stmt)}, + "initializer_list": {method: cv_expr_fn(convert_initializer_list)}, + + "lambda_declaration": {method: cv_expr_fn(convert_lambda_declaration)}, + "lambda_expr": {method: cv_expr_fn(convert_lambda_expr)}, + "local_decl_after_type": {method: cv_decl_fn(convert_local_declaration_after_type)}, + "module_ident_expr": {method: cv_expr_fn(convert_module_ident_expr)}, + "nextcase_stmt": {method: cv_stmt_fn(convert_nextcase_stmt)}, + "optional_expr": {method: cv_expr_fn(convert_optional_expr)}, + "rethrow_expr": {method: cv_expr_fn(convert_rethrow_expr)}, + "return_stmt": {method: cv_stmt_fn(convert_return_stmt)}, //"suffix_expr": convert_dummy, - "subscript_expr": {method: convert_subscript_expr}, - "switch_stmt": {method: convert_switch_stmt}, - "ternary_expr": {method: convert_ternary_expr}, - "trailing_generic_expr": {method: convert_trailing_generic_expr}, - "type": {method: convert_type}, - "unary_expr": {method: convert_unary_expr}, - "update_expr": {method: convert_update_expr}, - "var_stmt": {method: convert_var_decl, goChild: true}, - "while_stmt": {method: convert_while_stmt}, + "subscript_expr": {method: cv_expr_fn(convert_subscript_expr)}, + "switch_stmt": {method: cv_stmt_fn(convert_switch_stmt)}, + "ternary_expr": {method: cv_expr_fn(convert_ternary_expr)}, + "trailing_generic_expr": {method: cv_expr_fn(convert_trailing_generic_expr)}, + "type": {method: func(node *sitter.Node, source []byte) Node { + n := convert_type(node, source) + return n + }}, + "unary_expr": {method: cv_expr_fn(convert_unary_expr)}, + "update_expr": {method: cv_expr_fn(convert_update_expr)}, + "var_stmt": {method: cv_decl_fn(convert_var_decl), goChild: true}, + "while_stmt": {method: cv_stmt_fn(convert_while_stmt)}, + "field_expr": {method: cv_expr_fn(convert_field_expr)}, // Builtins ---------------- - "$vacount": {method: convert_as_literal}, - "$feature": {method: convert_feature}, - - "$alignof": {method: convert_compile_time_call}, - "$extnameof": {method: convert_compile_time_call}, - "$nameof": {method: convert_compile_time_call}, - "$offsetof": {method: convert_compile_time_call}, - "$qnameof": {method: convert_compile_time_call}, - - "$vaconst": {method: convert_compile_time_arg}, - "$vaarg": {method: convert_compile_time_arg}, - "$varef": {method: convert_compile_time_arg}, - "$vaexpr": {method: convert_compile_time_arg}, - - "$eval": {method: convert_compile_time_analyse}, - "$is_const": {method: convert_compile_time_analyse}, - "$sizeof": {method: convert_compile_time_analyse}, - "$stringify": {method: convert_compile_time_analyse}, - - "$and": {method: convert_compile_time_call_unk}, - "$append": {method: convert_compile_time_call_unk}, - "$concat": {method: convert_compile_time_call_unk}, - "$defined": {method: convert_compile_time_call_unk}, - "$embed": {method: convert_compile_time_call_unk}, - "$or": {method: convert_compile_time_call_unk}, - - "_expr": {method: convert_expression}, - "_base_expr": {method: convert_base_expression}, - "_statement": {method: convert_statement}, + "$vacount": {method: cv_expr_fn(convert_as_literal)}, + "$feature": {method: cv_expr_fn(convert_feature)}, + + "$alignof": {method: cv_expr_fn(convert_compile_time_call)}, + "$extnameof": {method: cv_expr_fn(convert_compile_time_call)}, + "$nameof": {method: cv_expr_fn(convert_compile_time_call)}, + "$offsetof": {method: cv_expr_fn(convert_compile_time_call)}, + "$qnameof": {method: cv_expr_fn(convert_compile_time_call)}, + + "$vaconst": {method: cv_expr_fn(convert_compile_time_arg)}, + "$vaarg": {method: cv_expr_fn(convert_compile_time_arg)}, + "$varef": {method: cv_expr_fn(convert_compile_time_arg)}, + "$vaexpr": {method: cv_expr_fn(convert_compile_time_arg)}, + + "$eval": {method: cv_expr_fn(convert_compile_time_analyse)}, + "$is_const": {method: cv_expr_fn(convert_compile_time_analyse)}, + "$sizeof": {method: cv_expr_fn(convert_compile_time_analyse)}, + "$stringify": {method: cv_expr_fn(convert_compile_time_analyse)}, + + "$and": {method: cv_expr_fn(convert_compile_time_call_unk)}, + "$append": {method: cv_expr_fn(convert_compile_time_call_unk)}, + "$concat": {method: cv_expr_fn(convert_compile_time_call_unk)}, + "$defined": {method: cv_expr_fn(convert_compile_time_call_unk)}, + "$embed": {method: cv_expr_fn(convert_compile_time_call_unk)}, + "$or": {method: cv_expr_fn(convert_compile_time_call_unk)}, + + "_expr": {method: cv_expr_fn(convert_expression)}, + "_base_expr": {method: cv_expr_fn(convert_base_expression)}, + "_statement": {method: cv_stmt_fn(convert_statement)}, // Literals - "string_literal": {method: convert_literal}, - "char_literal": {method: convert_literal}, - "raw_string_literal": {method: convert_literal}, - "integer_literal": {method: convert_literal}, - "real_literal": {method: convert_literal}, - "bytes_literal": {method: convert_literal}, - "true": {method: convert_literal}, - "false": {method: convert_literal}, - "null": {method: convert_literal}, + "string_literal": {method: cv_expr_fn(convert_literal)}, + "char_literal": {method: cv_expr_fn(convert_literal)}, + "raw_string_literal": {method: cv_expr_fn(convert_literal)}, + "integer_literal": {method: cv_expr_fn(convert_literal)}, + "real_literal": {method: cv_expr_fn(convert_literal)}, + "bytes_literal": {method: cv_expr_fn(convert_literal)}, + "true": {method: cv_expr_fn(convert_literal)}, + "false": {method: cv_expr_fn(convert_literal)}, + "null": {method: cv_expr_fn(convert_literal)}, // Custom ones ---------------- - "..type_with_initializer_list..": {method: convert_type_with_initializer_list}, - "..lambda_declaration_with_body..": {method: convert_lambda_declaration_with_body}, + "..type_with_initializer_list..": {method: cv_expr_fn(convert_type_with_initializer_list)}, + "..lambda_declaration_with_body..": {method: cv_expr_fn(convert_lambda_declaration_with_body)}, } if function, exists := funcMap[nodeType]; exists { @@ -123,7 +150,7 @@ func nodeTypeConverterMap(nodeType string) (ConversionInfo, error) { //panic(fmt.Sprintf("La función %s no existe\n", nodeType)) } -func anyOf(name string, rules []NodeRule, node *sitter.Node, source []byte, debug bool) Expression { +func anyOf(name string, rules []NodeRule, node *sitter.Node, source []byte, debug bool) Node { //fmt.Printf("anyOf: ") if debug { debugNode(node, source, "AnyOf["+name+"]") @@ -134,6 +161,9 @@ func anyOf(name string, rules []NodeRule, node *sitter.Node, source []byte, debu for _, rule := range rules { if rule.Validate(node, source) { + if debug { + fmt.Printf("Converted selected %s\n", rule.Type()) + } conversion, err := nodeTypeConverterMap(rule.Type()) if err != nil { continue @@ -149,14 +179,14 @@ func anyOf(name string, rules []NodeRule, node *sitter.Node, source []byte, debu return nil } -func commaSep(convert NodeConverter, node *sitter.Node, source []byte) []Expression { - expressions := []Expression{} +func commaSep(convert NodeConverter, node *sitter.Node, source []byte) []Node { + var nodes []Node for { debugNode(node, source, "commaSep") condition := convert(node, source) if condition != nil { - expressions = append(expressions, condition) + nodes = append(nodes, condition) } else { break } @@ -178,5 +208,5 @@ func commaSep(convert NodeConverter, node *sitter.Node, source []byte) []Express } } - return expressions + return nodes } diff --git a/server/internal/lsp/ast/convert_statement.go b/server/internal/lsp/ast/convert_statement.go index 0ccd8ae..85f9dd3 100644 --- a/server/internal/lsp/ast/convert_statement.go +++ b/server/internal/lsp/ast/convert_statement.go @@ -7,8 +7,8 @@ import ( sitter "github.com/smacker/go-tree-sitter" ) -func convert_statement(node *sitter.Node, source []byte) Expression { - return anyOf("statement", []NodeRule{ +func convert_statement(node *sitter.Node, source []byte) Statement { + dd := anyOf("statement", []NodeRule{ NodeOfType("compound_stmt"), NodeOfType("expr_stmt"), NodeOfType("declaration_stmt"), @@ -32,13 +32,15 @@ func convert_statement(node *sitter.Node, source []byte) Expression { NodeOfType("ct_switch_stmt"), NodeOfType("ct_foreach_stmt"), NodeOfType("ct_for_stmt"), - }, node, source, false) + }, node, source, true) + + return dd.(Statement) } -func convert_compound_stmt(node *sitter.Node, source []byte) Expression { - cmpStatement := CompoundStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeCompoundStatement, node), - Statements: []Expression{}, +func convert_compound_stmt(node *sitter.Node, source []byte) Statement { + cmpStatement := &CompoundStmt{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Statements: []Statement{}, } for i := 0; i < int(node.ChildCount()); i++ { n := node.Child(i) @@ -53,25 +55,25 @@ func convert_compound_stmt(node *sitter.Node, source []byte) Expression { return cmpStatement } -func convert_return_stmt(node *sitter.Node, source []byte) Expression { +func convert_return_stmt(node *sitter.Node, source []byte) Statement { expr := option.None[Expression]() argNode := node.Child(0).NextSibling() if argNode.Type() != ";" { - expr = option.Some(convert_expression(argNode, source)) + expr = option.Some(convert_expression(argNode, source).(Expression)) } - return ReturnStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeReturnStatement, node), - Return: expr, + return &ReturnStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Return: expr, } } -func convert_split_declaration_stmt(node *sitter.Node, source []byte) Expression { +func convert_split_declaration_stmt(node *sitter.Node, source []byte) Declaration { return convert_declaration_stmt(node.Parent(), source) } -func convert_declaration_stmt(node *sitter.Node, source []byte) Expression { +func convert_declaration_stmt(node *sitter.Node, source []byte) Declaration { if node.Type() == "const_declaration" { return convert_const_declaration(node, source) } @@ -79,7 +81,7 @@ func convert_declaration_stmt(node *sitter.Node, source []byte) Expression { isStatic := false isTlocal := false varDecl := VariableDecl{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeVariableDecl, node), + NodeAttributes: NewBaseNodeFromSitterNode(node), } end := false for i := 0; i < int(node.ChildCount()) && !end; i++ { @@ -95,7 +97,7 @@ func convert_declaration_stmt(node *sitter.Node, source []byte) Expression { } case "type": - varDecl.Type = convert_type(n, source).(TypeInfo) + varDecl.Type = convert_type(n, source) varDecl.Type.Static = isStatic varDecl.Type.TLocal = isTlocal @@ -108,16 +110,16 @@ func convert_declaration_stmt(node *sitter.Node, source []byte) Expression { right := n.ChildByFieldName("right") if right != nil { - varDecl.Initializer = convert_expression(right, source) + varDecl.Initializer = convert_expression(right, source).(Expression) } end = true } } - return varDecl + return &varDecl } -func convert_continue_stmt(node *sitter.Node, source []byte) Expression { +func convert_continue_stmt(node *sitter.Node, source []byte) Statement { label := option.None[string]() for i := 0; i < int(node.ChildCount()); i++ { n := node.Child(i) @@ -126,13 +128,13 @@ func convert_continue_stmt(node *sitter.Node, source []byte) Expression { } } - return ContinueStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeContinueStatement, node), - Label: label, + return &ContinueStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Label: label, } } -func convert_break_stmt(node *sitter.Node, source []byte) Expression { +func convert_break_stmt(node *sitter.Node, source []byte) Statement { label := option.None[string]() for i := 0; i < int(node.ChildCount()); i++ { n := node.Child(i) @@ -141,15 +143,15 @@ func convert_break_stmt(node *sitter.Node, source []byte) Expression { } } - return BreakStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeBreakStatement, node), - Label: label, + return &BreakStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Label: label, } } -func convert_switch_stmt(node *sitter.Node, source []byte) Expression { +func convert_switch_stmt(node *sitter.Node, source []byte) Statement { label := option.None[string]() - cases := []SwitchCase{} + var cases []SwitchCase var defaultStatement []Statement body := node.ChildByFieldName("body") @@ -157,22 +159,27 @@ func convert_switch_stmt(node *sitter.Node, source []byte) Expression { n := body.Child(i) if n.Type() == "case_stmt" { conditionNode := n.ChildByFieldName("value") - var caseValue Expression + var caseValue Statement if conditionNode.Type() == "case_range" { - caseValue = SwitchCaseRange{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeSwitchCaseRangeExpr, conditionNode), - Start: convert_expression(conditionNode.Child(0), source), - End: convert_expression(conditionNode.Child(2), source), + caseValue = &SwitchCaseRange{ + NodeAttributes: NewBaseNodeFromSitterNode(conditionNode), + Start: convert_expression(conditionNode.Child(0), source).(Expression), + End: convert_expression(conditionNode.Child(2), source).(Expression), } } else if conditionNode.Type() == "type" { - caseValue = convert_type(conditionNode, source) + caseValue = &ExpressionStmt{ + Expr: convert_type(conditionNode, source), + } } else { - caseValue = convert_expression(conditionNode, source) + caseValue = &ExpressionStmt{ + Expr: convert_expression(conditionNode, source).(Expression), + } + } colon := conditionNode.NextSibling() ns := colon.NextSibling() - statements := []Statement{} + var statements []Statement for { if ns == nil { break @@ -182,9 +189,9 @@ func convert_switch_stmt(node *sitter.Node, source []byte) Expression { } cases = append(cases, SwitchCase{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeSwitchStatement, n), - Value: caseValue, - Statements: statements, + NodeAttributes: NewBaseNodeFromSitterNode(n), + Value: caseValue, + Statements: statements, }) } else { for d := 0; d < int(n.ChildCount()); d++ { @@ -196,18 +203,18 @@ func convert_switch_stmt(node *sitter.Node, source []byte) Expression { } } - return SwitchStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeSwitchStatement, node), - Label: label, - Condition: convert_expression(node.ChildByFieldName("condition"), source), - Cases: cases, - Default: defaultStatement, + return &SwitchStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Label: label, + Condition: convert_expression(node.ChildByFieldName("condition"), source).(Expression), + Cases: cases, + Default: defaultStatement, } } -func convert_nextcase_stmt(node *sitter.Node, source []byte) Expression { +func convert_nextcase_stmt(node *sitter.Node, source []byte) Statement { label := option.None[string]() - var value Expression + var value Node targetNode := node.ChildByFieldName("target") if targetNode != nil { value = anyOf("nextcase_stmt", []NodeRule{ @@ -224,20 +231,20 @@ func convert_nextcase_stmt(node *sitter.Node, source []byte) Expression { } } - return Nextcase{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeNextCaseStatement, node), - Label: label, - Value: value, + return &Nextcase{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Label: label, + Value: value.(Expression), } } -func convert_if_stmt(node *sitter.Node, source []byte) Expression { +func convert_if_stmt(node *sitter.Node, source []byte) Statement { conditions := convert_paren_conditions(node.ChildByFieldName("condition"), source) //fmt.Printf("%s", reflect.TypeOf(conditions).String()) - stmt := IfStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeIfStatement, node), - Label: option.None[string](), - Condition: conditions, + stmt := &IfStmt{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Label: option.None[string](), + Condition: conditions, } for i := 0; i < int(node.ChildCount()); i++ { @@ -248,14 +255,14 @@ func convert_if_stmt(node *sitter.Node, source []byte) Expression { case "else_part": elseStmt := convert_statement(n.Child(1), source) switch elseStmt.(type) { - case CompoundStatement: - if len(elseStmt.(CompoundStatement).Statements) == 0 { + case *CompoundStmt: + if len(elseStmt.(*CompoundStmt).Statements) == 0 { elseStmt = nil } } stmt.Else = ElseStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeElseStatement, n), - Statement: elseStmt, + NodeAttributes: NewBaseNodeFromSitterNode(n), + Statement: elseStmt, } } } @@ -263,8 +270,8 @@ func convert_if_stmt(node *sitter.Node, source []byte) Expression { ifBody := node.ChildByFieldName("body") bodyStmt := convert_statement(ifBody, source) switch bodyStmt.(type) { - case CompoundStatement: - if len(bodyStmt.(CompoundStatement).Statements) == 0 { + case *CompoundStmt: + if len(bodyStmt.(*CompoundStmt).Statements) == 0 { bodyStmt = nil } } @@ -297,13 +304,16 @@ func convert_conditions(node *sitter.Node, source []byte) []Expression { } else { // Option 3: // (decl_or_expr),* + optional(, try_unwrap | catch_unwrap) - conditions = commaSep(convert_decl_or_expression, node, source) + nodes := commaSep(convert_decl_or_expression, node, source) + for _, n := range nodes { + conditions = append(conditions, n.(Expression)) + } } return conditions } -func convert_local_declaration_after_type(node *sitter.Node, source []byte) Expression { +func convert_local_declaration_after_type(node *sitter.Node, source []byte) Declaration { var init Expression if node.Child(1).Type() == "attributes" { @@ -312,12 +322,12 @@ func convert_local_declaration_after_type(node *sitter.Node, source []byte) Expr right := node.ChildByFieldName("right") if right != nil { - init = convert_expression(right, source) + init = convert_expression(right, source).(Expression) } - varDecl := VariableDecl{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeVariableDecl, node), - Names: []Identifier{ + varDecl := &VariableDecl{ + NodeAttributes: NewBaseNodeFromSitterNode(node), + Names: []Ident{ NewIdentifierBuilder(). WithName(node.ChildByFieldName("name").Content(source)). WithSitterPos(node.ChildByFieldName("name")). @@ -329,9 +339,9 @@ func convert_local_declaration_after_type(node *sitter.Node, source []byte) Expr return varDecl } -func convert_for_stmt(node *sitter.Node, source []byte) Expression { - forStmt := ForStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeForStatement, node), +func convert_for_stmt(node *sitter.Node, source []byte) Statement { + forStmt := &ForStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), } for i := 0; i < int(node.ChildCount()); i++ { @@ -360,22 +370,43 @@ func convert_for_stmt(node *sitter.Node, source []byte) Expression { return forStmt } -func convert_comma_decl_or_expression(node *sitter.Node, source []byte) []Expression { - return commaSep(convert_decl_or_expression, node.Child(0), source) +func convert_comma_decl_or_expression(node *sitter.Node, source []byte) []Statement { + nodes := commaSep(convert_decl_or_expression, node.Child(0), source) + + stmts := []Statement{} + for _, n := range nodes { + stmts = append(stmts, n.(Statement)) + } + return stmts } // This takes anon nodes -func convert_decl_or_expression(node *sitter.Node, source []byte) Expression { - return anyOf("decl_or_expression", []NodeRule{ +func convert_decl_or_expression(node *sitter.Node, source []byte) Node { + found := anyOf("decl_or_expression", []NodeRule{ NodeOfType("var_decl"), NodeSiblingsWithSequenceOf([]NodeRule{ NodeOfType("type"), NodeOfType("local_decl_after_type"), }, "split_declaration_stmt"), NodeAnonymous("_expr"), }, node, source, true) + + switch found.(type) { + case Expression: + return &ExpressionStmt{ + Expr: found.(Expression), + } + + case Declaration: + return &DeclarationStmt{ + Decl: found.(Declaration), + } + + default: + panic("Did not find type") + } } -func convert_foreach_stmt(node *sitter.Node, source []byte) Expression { +func convert_foreach_stmt(node *sitter.Node, source []byte) Statement { /* foreach_stmt: $ => seq( choice('foreach', 'foreach_r'), @@ -397,8 +428,8 @@ func convert_foreach_stmt(node *sitter.Node, source []byte) Expression { seq(optional($._type_or_optional_type), optional('&'), $.ident), ), */ - stmt := ForeachStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeForeachStatement, node), + stmt := &ForeachStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), } foreachVar := ForeachValue{} @@ -420,7 +451,7 @@ func convert_foreach_stmt(node *sitter.Node, source []byte) Expression { case ")", "(": default: - stmt.Collection = convert_expression(cn, source) + stmt.Collection = convert_expression(cn, source).(Expression) } } } @@ -442,23 +473,23 @@ func convert_foreach_var(node *sitter.Node, source []byte) ForeachValue { n := node.Child(i) switch n.Type() { case "type": - value.Type = convert_type(n, source).(TypeInfo) + value.Type = convert_type(n, source) case "&": // ?? value.Type.Reference = true case "ident": - value.Identifier = convert_ident(n, source).(Identifier) + value.Identifier = convert_ident(n, source).(Ident) } } return value } -func convert_while_stmt(node *sitter.Node, source []byte) Expression { - stmt := WhileStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeWhileStatement, node), +func convert_while_stmt(node *sitter.Node, source []byte) Statement { + stmt := &WhileStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), } for i := 0; i < int(node.ChildCount()); i++ { @@ -477,9 +508,9 @@ func convert_while_stmt(node *sitter.Node, source []byte) Expression { return stmt } -func convert_do_stmt(node *sitter.Node, source []byte) Expression { - stmt := DoStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeDoStatement, node), +func convert_do_stmt(node *sitter.Node, source []byte) Statement { + stmt := &DoStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), } for i := 0; i < int(node.ChildCount()); i++ { @@ -488,16 +519,16 @@ func convert_do_stmt(node *sitter.Node, source []byte) Expression { case "compound_stmt": stmt.Body = convert_statement(n, source) case "paren_expr": - stmt.Condition = convert_expression(n.Child(1), source) + stmt.Condition = convert_expression(n.Child(1), source).(Expression) } } return stmt } -func convert_defer_stmt(node *sitter.Node, source []byte) Expression { - stmt := DeferStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeDeferStatement, node), +func convert_defer_stmt(node *sitter.Node, source []byte) Statement { + stmt := &DeferStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), } stmt.Statement = convert_statement( @@ -508,12 +539,19 @@ func convert_defer_stmt(node *sitter.Node, source []byte) Expression { return stmt } -func convert_assert_stmt(node *sitter.Node, source []byte) Expression { - stmt := AssertStatement{ - ASTBaseNode: NewBaseNodeFromSitterNode(TypeAssertStatement, node), +func convert_assert_stmt(node *sitter.Node, source []byte) Statement { + stmt := &AssertStatement{ + NodeAttributes: NewBaseNodeFromSitterNode(node), } - - stmt.Assertions = commaSep(convert_expression, node.Child(2), source) - + /* + nodes := commaSep( + convert_expression, + node.Child(2), + source, + ) + for _, node := range nodes { + stmt.Assertions = append(stmt.Assertions, node.(Expression)) + } + */ return stmt } diff --git a/server/internal/lsp/ast/convert_statement_test.go b/server/internal/lsp/ast/convert_statement_test.go index 83a465d..1c0ab41 100644 --- a/server/internal/lsp/ast/convert_statement_test.go +++ b/server/internal/lsp/ast/convert_statement_test.go @@ -12,13 +12,13 @@ func TestConvertToAST_declaration_stmt_constant(t *testing.T) { cases := []struct { skip bool input string - expected ASTNode + expected Node }{ { input: "const int I;", expected: ConstDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeConstDecl).WithStartEnd(1, 3, 1, 15).Build(), - Names: []Identifier{NewIdentifierBuilder().WithName("I").WithStartEnd(1, 13, 1, 14).Build()}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 3, 1, 15).Build(), + Names: []Ident{NewIdentifierBuilder().WithName("I").WithStartEnd(1, 13, 1, 14).Build()}, Type: option.Some(NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). @@ -30,23 +30,23 @@ func TestConvertToAST_declaration_stmt_constant(t *testing.T) { { input: "const int I = 1;", // With initialization expected: ConstDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeConstDecl).WithStartEnd(1, 3, 1, 19).Build(), - Names: []Identifier{NewIdentifierBuilder().WithName("I").WithStartEnd(1, 13, 1, 14).Build()}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 3, 1, 19).Build(), + Names: []Ident{NewIdentifierBuilder().WithName("I").WithStartEnd(1, 13, 1, 14).Build()}, Type: option.Some(NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). WithStartEnd(1, 9, 1, 12). WithNameStartEnd(1, 9, 1, 12). Build()), - Initializer: IntegerLiteral{Value: "1"}, + Initializer: &IntegerLiteral{Value: "1"}, }, }, { input: "const I;", // Without type expected: ConstDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeConstDecl).WithStartEnd(1, 3, 1, 11).Build(), - Names: []Identifier{NewIdentifierBuilder().WithName("I").WithStartEnd(1, 9, 1, 10).Build()}, - Type: option.None[TypeInfo](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(1, 3, 1, 11).Build(), + Names: []Ident{NewIdentifierBuilder().WithName("I").WithStartEnd(1, 9, 1, 10).Build()}, + Type: option.None[TypeInfo](), }, }, } @@ -61,7 +61,7 @@ func TestConvertToAST_declaration_stmt_constant(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - varDecl := ast.Modules[0].Declarations[0].(ConstDecl) + varDecl := ast.Modules[0].Declarations[0].(*ConstDecl) assert.Equal(t, tt.expected, varDecl) }) } @@ -71,13 +71,13 @@ func TestConvertToAST_declaration_stmt_local_variable(t *testing.T) { cases := []struct { skip bool input string - expected ASTNode + expected Node }{ { input: "int i;", expected: VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(2, 3, 2, 9).Build(), - Names: []Identifier{NewIdentifierBuilder().WithName("i").WithStartEnd(2, 7, 2, 8).Build()}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 9).Build(), + Names: []Ident{NewIdentifierBuilder().WithName("i").WithStartEnd(2, 7, 2, 8).Build()}, Type: NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). @@ -89,22 +89,22 @@ func TestConvertToAST_declaration_stmt_local_variable(t *testing.T) { { input: "int i = 1;", // With initialization expected: VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(2, 3, 2, 13).Build(), - Names: []Identifier{NewIdentifierBuilder().WithName("i").WithStartEnd(2, 7, 2, 8).Build()}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 13).Build(), + Names: []Ident{NewIdentifierBuilder().WithName("i").WithStartEnd(2, 7, 2, 8).Build()}, Type: NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). WithStartEnd(2, 3, 2, 6). WithNameStartEnd(2, 3, 2, 6). Build(), - Initializer: IntegerLiteral{Value: "1"}, + Initializer: &IntegerLiteral{Value: "1"}, }, }, { input: "static int i = 1;", // With initialization expected: VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(2, 3, 2, 20).Build(), - Names: []Identifier{NewIdentifierBuilder().WithName("i").WithStartEnd(2, 14, 2, 15).Build()}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 20).Build(), + Names: []Ident{NewIdentifierBuilder().WithName("i").WithStartEnd(2, 14, 2, 15).Build()}, Type: NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). @@ -112,7 +112,7 @@ func TestConvertToAST_declaration_stmt_local_variable(t *testing.T) { WithStartEnd(2, 10, 2, 13). WithNameStartEnd(2, 10, 2, 13). Build(), - Initializer: IntegerLiteral{Value: "1"}, + Initializer: &IntegerLiteral{Value: "1"}, }, }, } @@ -129,8 +129,8 @@ func TestConvertToAST_declaration_stmt_local_variable(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(VariableDecl)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*DeclarationStmt).Decl) //(VariableDecl)) }) } } @@ -144,15 +144,15 @@ func TestConvertToAST_continue_stmt(t *testing.T) { { input: "continue;", expected: ContinueStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeContinueStatement).WithStartEnd(2, 3, 2, 12).Build(), - Label: option.None[string](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 12).Build(), + Label: option.None[string](), }, }, { input: "continue FOO;", // With label expected: ContinueStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeContinueStatement).WithStartEnd(2, 3, 2, 16).Build(), - Label: option.Some("FOO"), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 16).Build(), + Label: option.Some("FOO"), }, }, } @@ -169,8 +169,8 @@ func TestConvertToAST_continue_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(ContinueStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*ContinueStatement)) }) } } @@ -184,15 +184,15 @@ func TestConvertToAST_break_stmt(t *testing.T) { { input: "break;", expected: BreakStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeBreakStatement).WithStartEnd(2, 3, 2, 9).Build(), - Label: option.None[string](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 9).Build(), + Label: option.None[string](), }, }, { input: "break FOO;", // With label expected: BreakStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeBreakStatement).WithStartEnd(2, 3, 2, 13).Build(), - Label: option.Some("FOO"), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 13).Build(), + Label: option.Some("FOO"), }, }, } @@ -209,8 +209,8 @@ func TestConvertToAST_break_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(BreakStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*BreakStatement)) }) } } @@ -232,26 +232,30 @@ func TestConvertToAST_switch_stmt(t *testing.T) { chirp; }`, expected: SwitchStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeSwitchStatement).WithStartEnd(3, 3, 10, 4).Build(), - Label: option.None[string](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 10, 4).Build(), + Label: option.None[string](), Cases: []SwitchCase{ { - ASTBaseNode: NewBaseNodeBuilder(TypeSwitchStatement).WithStartEnd(4, 4, 5, 11).Build(), - Value: IntegerLiteral{Value: "1"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 4, 5, 11).Build(), + Value: &ExpressionStmt{ + Expr: &IntegerLiteral{Value: "1"}, + }, Statements: []Statement{ - NewIdentifierBuilder().WithName("hello").WithStartEnd(5, 5, 5, 10).Build(), + &ExpressionStmt{ + Expr: NewIdentifierBuilder().WithName("hello").WithStartEnd(5, 5, 5, 10).Build(), + }, }, }, { - ASTBaseNode: NewBaseNodeBuilder(TypeSwitchStatement).WithStartEnd(6, 4, 7, 9).Build(), - Value: IntegerLiteral{Value: "2"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(6, 4, 7, 9).Build(), + Value: &ExpressionStmt{Expr: &IntegerLiteral{Value: "2"}}, Statements: []Statement{ - NewIdentifierBuilder().WithName("bye").WithStartEnd(7, 5, 7, 8).Build(), + &ExpressionStmt{Expr: NewIdentifierBuilder().WithName("bye").WithStartEnd(7, 5, 7, 8).Build()}, }, }, }, Default: []Statement{ - NewIdentifierBuilder().WithName("chirp").WithStartEnd(9, 5, 9, 10).Build(), + &ExpressionStmt{Expr: NewIdentifierBuilder().WithName("chirp").WithStartEnd(9, 5, 9, 10).Build()}, }, }, }, @@ -262,19 +266,20 @@ func TestConvertToAST_switch_stmt(t *testing.T) { hello; }`, expected: SwitchStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeSwitchStatement).WithStartEnd(3, 3, 6, 4).Build(), - Label: option.None[string](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 6, 4).Build(), + Label: option.None[string](), Cases: []SwitchCase{ { - ASTBaseNode: NewBaseNodeBuilder(TypeSwitchCaseStatement).WithStartEnd(4, 4, 5, 11).Build(), - Value: NewTypeInfoBuilder(). + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 4, 5, 11).Build(), + Value: &ExpressionStmt{Expr: NewTypeInfoBuilder(). WithName("int"). IsBuiltin(). WithNameStartEnd(4, 9, 4, 12). WithStartEnd(4, 9, 4, 12). Build(), + }, Statements: []Statement{ - NewIdentifierBuilder().WithName("hello").WithStartEnd(5, 5, 5, 10).Build(), + &ExpressionStmt{Expr: NewIdentifierBuilder().WithName("hello").WithStartEnd(5, 5, 5, 10).Build()}, }, }, }, @@ -287,18 +292,18 @@ func TestConvertToAST_switch_stmt(t *testing.T) { hello; }`, expected: SwitchStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeSwitchStatement).WithStartEnd(3, 3, 6, 4).Build(), - Label: option.None[string](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 6, 4).Build(), + Label: option.None[string](), Cases: []SwitchCase{ { - ASTBaseNode: NewBaseNodeBuilder(TypeSwitchCaseStatement).WithStartEnd(4, 4, 5, 11).Build(), - Value: SwitchCaseRange{ - ASTBaseNode: NewBaseNodeBuilder(TypeSwitchCaseRangeExpr).WithStartEnd(4, 9, 4, 14).Build(), - Start: IntegerLiteral{Value: "1"}, - End: IntegerLiteral{Value: "10"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 4, 5, 11).Build(), + Value: &SwitchCaseRange{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 9, 4, 14).Build(), + Start: &IntegerLiteral{Value: "1"}, + End: &IntegerLiteral{Value: "10"}, }, Statements: []Statement{ - NewIdentifierBuilder().WithName("hello").WithStartEnd(5, 5, 5, 10).Build(), + &ExpressionStmt{Expr: NewIdentifierBuilder().WithName("hello").WithStartEnd(5, 5, 5, 10).Build()}, }, }, }, @@ -318,8 +323,8 @@ func TestConvertToAST_switch_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(SwitchStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*SwitchStatement)) }) } } @@ -333,43 +338,43 @@ func TestConvertToAST_nextcase(t *testing.T) { { input: `nextcase;`, expected: Nextcase{ - ASTBaseNode: NewBaseNodeBuilder(TypeNextCaseStatement).WithStartEnd(2, 3, 2, 12).Build(), - Label: option.None[string](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 12).Build(), + Label: option.None[string](), }, }, { input: `nextcase 3;`, expected: Nextcase{ - ASTBaseNode: NewBaseNodeBuilder(TypeNextCaseStatement).WithStartEnd(2, 3, 2, 14).Build(), - Label: option.None[string](), - Value: IntegerLiteral{Value: "3"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 14).Build(), + Label: option.None[string](), + Value: &IntegerLiteral{Value: "3"}, }, }, { input: `nextcase LABEL:3;`, expected: Nextcase{ - ASTBaseNode: NewBaseNodeBuilder(TypeNextCaseStatement).WithStartEnd(2, 3, 2, 20).Build(), - Label: option.Some("LABEL"), - Value: IntegerLiteral{Value: "3"}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 20).Build(), + Label: option.Some("LABEL"), + Value: &IntegerLiteral{Value: "3"}, }, }, { input: `nextcase rand();`, expected: Nextcase{ - ASTBaseNode: NewBaseNodeBuilder(TypeNextCaseStatement).WithStartEnd(2, 3, 2, 19).Build(), - Label: option.None[string](), - Value: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(2, 12, 2, 18).Build(), - Identifier: NewIdentifierBuilder().WithName("rand").WithStartEnd(2, 12, 2, 16).Build(), - Arguments: []Arg{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 19).Build(), + Label: option.None[string](), + Value: &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 12, 2, 18).Build(), + Identifier: NewIdentifierBuilder().WithName("rand").WithStartEnd(2, 12, 2, 16).Build(), + Arguments: []Expression{}, }, }, }, { input: `nextcase default;`, expected: Nextcase{ - ASTBaseNode: NewBaseNodeBuilder(TypeNextCaseStatement).WithStartEnd(2, 3, 2, 20).Build(), - Label: option.None[string](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(2, 3, 2, 20).Build(), + Label: option.None[string](), }, }, } @@ -386,8 +391,8 @@ func TestConvertToAST_nextcase(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(Nextcase)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*Nextcase)) }) } } @@ -396,31 +401,31 @@ func TestConvertToAST_if_stmt(t *testing.T) { cases := []struct { skip bool input string - expected IfStatement + expected IfStmt }{ { //skip: true, input: ` if (true) {}`, - expected: IfStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeIfStatement).WithStartEnd(3, 3, 3, 15).Build(), - Label: option.None[string](), - Condition: []Expression{BoolLiteral{Value: true}}, + expected: IfStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 15).Build(), + Label: option.None[string](), + Condition: []Expression{&BoolLiteral{Value: true}}, }, }, { skip: true, input: ` if (c > 0) {}`, - expected: IfStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeIfStatement).WithStartEnd(3, 3, 3, 16).Build(), - Label: option.None[string](), + expected: IfStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 16).Build(), + Label: option.None[string](), Condition: []Expression{ - BinaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeBinaryExpr).WithStartEnd(3, 7, 3, 12).Build(), - Left: NewIdentifierBuilder().WithName("c").WithStartEnd(3, 7, 3, 8).Build(), - Operator: ">", - Right: IntegerLiteral{Value: "0"}, + &BinaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 7, 3, 12).Build(), + Left: NewIdentifierBuilder().WithName("c").WithStartEnd(3, 7, 3, 8).Build(), + Operator: ">", + Right: IntegerLiteral{Value: "0"}, }, }, }, @@ -429,21 +434,21 @@ func TestConvertToAST_if_stmt(t *testing.T) { skip: true, input: ` if (c > 0, c < 10) {}`, - expected: IfStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeIfStatement).WithStartEnd(3, 3, 3, 24).Build(), - Label: option.None[string](), + expected: IfStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 24).Build(), + Label: option.None[string](), Condition: []Expression{ - BinaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeBinaryExpr).WithStartEnd(3, 7, 3, 12).Build(), - Left: NewIdentifierBuilder().WithName("c").WithStartEnd(3, 7, 3, 8).Build(), - Operator: ">", - Right: IntegerLiteral{Value: "0"}, + &BinaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 7, 3, 12).Build(), + Left: NewIdentifierBuilder().WithName("c").WithStartEnd(3, 7, 3, 8).Build(), + Operator: ">", + Right: IntegerLiteral{Value: "0"}, }, - BinaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeBinaryExpr).WithStartEnd(3, 14, 3, 20).Build(), - Left: NewIdentifierBuilder().WithName("c").WithStartEnd(3, 14, 3, 15).Build(), - Operator: "<", - Right: IntegerLiteral{Value: "10"}, + &BinaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 14, 3, 20).Build(), + Left: NewIdentifierBuilder().WithName("c").WithStartEnd(3, 14, 3, 15).Build(), + Operator: "<", + Right: IntegerLiteral{Value: "10"}, }, }, }, @@ -453,14 +458,14 @@ func TestConvertToAST_if_stmt(t *testing.T) { input: ` if (value) {} else {}`, - expected: IfStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeIfStatement).WithStartEnd(3, 3, 4, 10).Build(), - Label: option.None[string](), + expected: IfStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 4, 10).Build(), + Label: option.None[string](), Condition: []Expression{ NewIdentifierBuilder().WithName("value").WithStartEnd(3, 7, 3, 12).Build(), }, Else: ElseStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeElseStatement).WithStartEnd(4, 3, 4, 10).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 3, 4, 10).Build(), }, }, }, @@ -468,17 +473,17 @@ func TestConvertToAST_if_stmt(t *testing.T) { input: ` if (value){} else if (value2){}`, - expected: IfStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeIfStatement).WithStartEnd(3, 3, 4, 21).Build(), - Label: option.None[string](), + expected: IfStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 4, 21).Build(), + Label: option.None[string](), Condition: []Expression{ NewIdentifierBuilder().WithName("value").WithStartEnd(3, 7, 3, 12).Build(), }, Else: ElseStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeElseStatement).WithStartEnd(4, 3, 4, 21).Build(), - Statement: IfStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeIfStatement).WithStartEnd(4, 8, 4, 21).Build(), - Label: option.None[string](), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 3, 4, 21).Build(), + Statement: &IfStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 8, 4, 21).Build(), + Label: option.None[string](), Condition: []Expression{ NewIdentifierBuilder().WithName("value2").WithStartEnd(4, 12, 4, 18).Build(), }, @@ -493,9 +498,9 @@ func TestConvertToAST_if_stmt(t *testing.T) { if FOO: (i > 0) { }`, - expected: IfStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeIfStatement).WithStartEnd(3, 3, 5, 4).Build(), - Label: option.Some("FOO"), + expected: IfStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 5, 4).Build(), + Label: option.Some("FOO"), }, }, } @@ -512,8 +517,8 @@ func TestConvertToAST_if_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(IfStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*IfStmt)) }) } } @@ -529,12 +534,12 @@ func TestConvertToAST_for_stmt(t *testing.T) { input: ` for (int i=0; i<10; i++) {}`, expected: ForStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeForStatement).WithStartEnd(3, 3, 3, 30).Build(), - Label: option.None[string](), - Initializer: []Expression{ - VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(3, 8, 3, 15).Build(), - Names: []Identifier{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 30).Build(), + Label: option.None[string](), + Initializer: []Statement{ + &DeclarationStmt{Decl: &VariableDecl{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 8, 3, 15).Build(), + Names: []Ident{ NewIdentifierBuilder(). WithName("i"). WithStartEnd(3, 12, 3, 13). @@ -546,27 +551,29 @@ func TestConvertToAST_for_stmt(t *testing.T) { WithNameStartEnd(3, 8, 3, 11). IsBuiltin(). Build(), - Initializer: IntegerLiteral{ + Initializer: &IntegerLiteral{ Value: "0", }, }, + }, }, - Condition: BinaryExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeBinaryExpr).WithStartEnd(3, 17, 3, 21).Build(), - Left: NewIdentifierBuilder().WithName("i").WithStartEnd(3, 17, 3, 18).Build(), - Right: IntegerLiteral{Value: "10"}, - Operator: "<", + Condition: &BinaryExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 17, 3, 21).Build(), + Left: NewIdentifierBuilder().WithName("i").WithStartEnd(3, 17, 3, 18).Build(), + Right: IntegerLiteral{Value: "10"}, + Operator: "<", }, - Update: []Expression{ - UpdateExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUpdateExpr).WithStartEnd(3, 23, 3, 26).Build(), - Operator: "++", - Argument: NewIdentifierBuilder().WithName("i").WithStartEnd(3, 23, 3, 24).Build(), + Update: []Statement{ + &ExpressionStmt{Expr: &UpdateExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 23, 3, 26).Build(), + Operator: "++", + Argument: NewIdentifierBuilder().WithName("i").WithStartEnd(3, 23, 3, 24).Build(), + }, }, }, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 28, 3, 30).Build(), - Statements: []Expression{}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 28, 3, 30).Build(), + Statements: []Statement{}, }, }, }, @@ -575,12 +582,12 @@ func TestConvertToAST_for_stmt(t *testing.T) { input: ` for (int i=0, j=0; true; i++) {}`, expected: ForStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeForStatement).WithStartEnd(3, 3, 3, 35).Build(), - Label: option.None[string](), - Initializer: []Expression{ - VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(3, 8, 3, 20).Build(), - Names: []Identifier{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 35).Build(), + Label: option.None[string](), + Initializer: []Statement{ + &DeclarationStmt{Decl: &VariableDecl{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 8, 3, 20).Build(), + Names: []Ident{ NewIdentifierBuilder(). WithName("i"). WithStartEnd(3, 12, 3, 13). @@ -592,31 +599,33 @@ func TestConvertToAST_for_stmt(t *testing.T) { WithNameStartEnd(3, 8, 3, 11). IsBuiltin(). Build(), - Initializer: IntegerLiteral{ + Initializer: &IntegerLiteral{ Value: "0", }, }, - AssignmentStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeAssignmentStatement).WithStartEnd(3, 17, 3, 20).Build(), + }, + &AssignmentStatement{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 17, 3, 20).Build(), Left: NewIdentifierBuilder(). WithName("j"). WithStartEnd(3, 17, 3, 18). Build(), - Right: IntegerLiteral{Value: "0"}, + Right: &IntegerLiteral{Value: "0"}, Operator: "=", }, }, - Condition: BoolLiteral{Value: true}, - Update: []Expression{ - UpdateExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUpdateExpr).WithStartEnd(3, 28, 3, 31).Build(), - Operator: "++", - Argument: NewIdentifierBuilder().WithName("i").WithStartEnd(3, 28, 3, 29).Build(), + Condition: &BoolLiteral{Value: true}, + Update: []Statement{ + &ExpressionStmt{Expr: &UpdateExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 28, 3, 31).Build(), + Operator: "++", + Argument: NewIdentifierBuilder().WithName("i").WithStartEnd(3, 28, 3, 29).Build(), + }, }, }, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 33, 3, 35).Build(), - Statements: []Expression{}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 33, 3, 35).Build(), + Statements: []Statement{}, }, }, }, @@ -625,12 +634,12 @@ func TestConvertToAST_for_stmt(t *testing.T) { input: ` for (int i=0; foo(); i++) {}`, expected: ForStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeForStatement).WithStartEnd(3, 3, 3, 31).Build(), - Label: option.None[string](), - Initializer: []Expression{ - VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(3, 8, 3, 15).Build(), - Names: []Identifier{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 31).Build(), + Label: option.None[string](), + Initializer: []Statement{ + &DeclarationStmt{Decl: &VariableDecl{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 8, 3, 15).Build(), + Names: []Ident{ NewIdentifierBuilder(). WithName("i"). WithStartEnd(3, 12, 3, 13). @@ -642,26 +651,26 @@ func TestConvertToAST_for_stmt(t *testing.T) { WithNameStartEnd(3, 8, 3, 11). IsBuiltin(). Build(), - Initializer: IntegerLiteral{ - Value: "0", - }, + Initializer: &IntegerLiteral{Value: "0"}, + }, }, }, - Condition: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(3, 17, 3, 22).Build(), - Identifier: NewIdentifierBuilder().WithName("foo").WithStartEnd(3, 17, 3, 20).Build(), - Arguments: []Arg{}, + Condition: &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 17, 3, 22).Build(), + Identifier: NewIdentifierBuilder().WithName("foo").WithStartEnd(3, 17, 3, 20).Build(), + Arguments: []Expression{}, }, - Update: []Expression{ - UpdateExpression{ - ASTBaseNode: NewBaseNodeBuilder(TypeUpdateExpr).WithStartEnd(3, 24, 3, 27).Build(), - Operator: "++", - Argument: NewIdentifierBuilder().WithName("i").WithStartEnd(3, 24, 3, 25).Build(), + Update: []Statement{ + &ExpressionStmt{Expr: &UpdateExpression{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 24, 3, 27).Build(), + Operator: "++", + Argument: NewIdentifierBuilder().WithName("i").WithStartEnd(3, 24, 3, 25).Build(), + }, }, }, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 29, 3, 31).Build(), - Statements: []Expression{}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 29, 3, 31).Build(), + Statements: []Statement{}, }, }, }, @@ -673,23 +682,24 @@ func TestConvertToAST_for_stmt(t *testing.T) { int i = 0; }`, expected: ForStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeForStatement).WithStartEnd(3, 3, 5, 4).Build(), - Label: option.None[string](), - Initializer: nil, - Condition: nil, - Update: nil, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 12, 5, 4).Build(), - Statements: []Expression{ - VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(4, 4, 4, 14).Build(), - Names: []Identifier{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 5, 4).Build(), + Label: option.None[string](), + Initializer: nil, + Condition: nil, + Update: nil, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 12, 5, 4).Build(), + Statements: []Statement{ + &DeclarationStmt{Decl: &VariableDecl{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 4, 4, 14).Build(), + Names: []Ident{ NewIdentifierBuilder().WithName("i").WithStartEnd(4, 8, 4, 9).Build(), }, Type: NewTypeInfoBuilder().WithName("int").IsBuiltin(). WithStartEnd(4, 4, 4, 7). WithNameStartEnd(4, 4, 4, 7).Build(), - Initializer: IntegerLiteral{Value: "0"}, + Initializer: &IntegerLiteral{Value: "0"}, + }, }, }, }, @@ -709,8 +719,8 @@ func TestConvertToAST_for_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(ForStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*ForStatement)) }) } } @@ -726,15 +736,15 @@ func TestConvertToAST_foreach_stmt(t *testing.T) { input: ` foreach (int x : a) {}`, expected: ForeachStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeForeachStatement).WithStartEnd(3, 3, 3, 25).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 25).Build(), Value: ForeachValue{ Type: NewTypeInfoBuilder().WithName("int").IsBuiltin().WithNameStartEnd(3, 12, 3, 15).WithStartEnd(3, 12, 3, 15).Build(), Identifier: NewIdentifierBuilder().WithName("x").WithStartEnd(3, 16, 3, 17).Build(), }, Collection: NewIdentifierBuilder().WithName("a").WithStartEnd(3, 20, 3, 21).Build(), - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 23, 3, 25).Build(), - Statements: []Expression{}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 23, 3, 25).Build(), + Statements: []Statement{}, }, }, }, @@ -743,15 +753,15 @@ func TestConvertToAST_foreach_stmt(t *testing.T) { input: ` foreach (int &x : a) {}`, expected: ForeachStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeForeachStatement).WithStartEnd(3, 3, 3, 26).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 26).Build(), Value: ForeachValue{ Type: NewTypeInfoBuilder().WithName("int").IsBuiltin().IsReference().WithNameStartEnd(3, 12, 3, 15).WithStartEnd(3, 12, 3, 15).Build(), Identifier: NewIdentifierBuilder().WithName("x").WithStartEnd(3, 17, 3, 18).Build(), }, Collection: NewIdentifierBuilder().WithName("a").WithStartEnd(3, 21, 3, 22).Build(), - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 24, 3, 26).Build(), - Statements: []Expression{}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 24, 3, 26).Build(), + Statements: []Statement{}, }, }, }, @@ -760,7 +770,7 @@ func TestConvertToAST_foreach_stmt(t *testing.T) { input: ` foreach (int idx, char value : a) {}`, expected: ForeachStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeForeachStatement).WithStartEnd(3, 3, 3, 39).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 39).Build(), Index: ForeachValue{ Type: NewTypeInfoBuilder().WithName("int").IsBuiltin().WithNameStartEnd(3, 12, 3, 15).WithStartEnd(3, 12, 3, 15).Build(), @@ -771,9 +781,9 @@ func TestConvertToAST_foreach_stmt(t *testing.T) { Identifier: NewIdentifierBuilder().WithName("value").WithStartEnd(3, 26, 3, 31).Build(), }, Collection: NewIdentifierBuilder().WithName("a").WithStartEnd(3, 34, 3, 35).Build(), - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 37, 3, 39).Build(), - Statements: []Expression{}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 37, 3, 39).Build(), + Statements: []Statement{}, }, }, }, @@ -784,24 +794,25 @@ func TestConvertToAST_foreach_stmt(t *testing.T) { int i; }`, expected: ForeachStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeForeachStatement).WithStartEnd(3, 3, 5, 4).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 5, 4).Build(), Value: ForeachValue{ Type: NewTypeInfoBuilder().WithName("int").IsBuiltin().WithNameStartEnd(3, 12, 3, 15).WithStartEnd(3, 12, 3, 15).Build(), Identifier: NewIdentifierBuilder().WithName("x").WithStartEnd(3, 16, 3, 17).Build(), }, Collection: NewIdentifierBuilder().WithName("a").WithStartEnd(3, 20, 3, 21).Build(), - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 23, 5, 4).Build(), - Statements: []Expression{ - VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(4, 4, 4, 10).Build(), - Names: []Identifier{ + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 23, 5, 4).Build(), + Statements: []Statement{ + &DeclarationStmt{Decl: &VariableDecl{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 4, 4, 10).Build(), + Names: []Ident{ NewIdentifierBuilder().WithName("i").WithStartEnd(4, 8, 4, 9).Build(), }, Type: NewTypeInfoBuilder().WithName("int").IsBuiltin(). WithStartEnd(4, 4, 4, 7). WithNameStartEnd(4, 4, 4, 7).Build(), }, + }, }, }, }, @@ -820,8 +831,8 @@ func TestConvertToAST_foreach_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(ForeachStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*ForeachStatement)) }) } } @@ -837,13 +848,13 @@ func TestConvertToAST_while_stmt(t *testing.T) { input: ` while (true) {}`, expected: WhileStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeWhileStatement).WithStartEnd(3, 3, 3, 18).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 18).Build(), Condition: []Expression{ - BoolLiteral{Value: true}, + &BoolLiteral{Value: true}, }, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 16, 3, 18).Build(), - Statements: []Expression{}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 16, 3, 18).Build(), + Statements: []Statement{}, }, }, }, @@ -854,22 +865,23 @@ func TestConvertToAST_while_stmt(t *testing.T) { int i; }`, expected: WhileStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeWhileStatement).WithStartEnd(3, 3, 5, 4).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 5, 4).Build(), Condition: []Expression{ - BoolLiteral{Value: true}, + &BoolLiteral{Value: true}, }, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 16, 5, 4).Build(), - Statements: []Expression{ - VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(4, 4, 4, 10).Build(), - Names: []Identifier{ + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 16, 5, 4).Build(), + Statements: []Statement{ + &DeclarationStmt{Decl: &VariableDecl{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 4, 4, 10).Build(), + Names: []Ident{ NewIdentifierBuilder().WithName("i").WithStartEnd(4, 8, 4, 9).Build(), }, Type: NewTypeInfoBuilder().WithName("int").IsBuiltin(). WithStartEnd(4, 4, 4, 7). WithNameStartEnd(4, 4, 4, 7).Build(), }, + }, }, }, }, @@ -888,8 +900,8 @@ func TestConvertToAST_while_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(WhileStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*WhileStatement)) }) } } @@ -905,11 +917,11 @@ func TestConvertToAST_do_stmt(t *testing.T) { input: ` do {};`, expected: DoStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeDoStatement).WithStartEnd(3, 3, 3, 9).Build(), - Condition: nil, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 6, 3, 8).Build(), - Statements: []Expression{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 9).Build(), + Condition: nil, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 6, 3, 8).Build(), + Statements: []Statement{}, }, }, }, @@ -918,11 +930,11 @@ func TestConvertToAST_do_stmt(t *testing.T) { input: ` do {} while(true);`, expected: DoStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeDoStatement).WithStartEnd(3, 3, 3, 21).Build(), - Condition: BoolLiteral{Value: true}, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 6, 3, 8).Build(), - Statements: []Expression{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 21).Build(), + Condition: &BoolLiteral{Value: true}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 6, 3, 8).Build(), + Statements: []Statement{}, }, }, }, @@ -933,20 +945,21 @@ func TestConvertToAST_do_stmt(t *testing.T) { int i; } while(true);`, expected: DoStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeDoStatement).WithStartEnd(3, 3, 5, 17).Build(), - Condition: BoolLiteral{Value: true}, - Body: CompoundStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeCompoundStatement).WithStartEnd(3, 6, 5, 4).Build(), - Statements: []Expression{ - VariableDecl{ - ASTBaseNode: NewBaseNodeBuilder(TypeVariableDecl).WithStartEnd(4, 4, 4, 10).Build(), - Names: []Identifier{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 5, 17).Build(), + Condition: &BoolLiteral{Value: true}, + Body: &CompoundStmt{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 6, 5, 4).Build(), + Statements: []Statement{ + &DeclarationStmt{Decl: &VariableDecl{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(4, 4, 4, 10).Build(), + Names: []Ident{ NewIdentifierBuilder().WithName("i").WithStartEnd(4, 8, 4, 9).Build(), }, Type: NewTypeInfoBuilder().WithName("int").IsBuiltin(). WithStartEnd(4, 4, 4, 7). WithNameStartEnd(4, 4, 4, 7).Build(), }, + }, }, }, }, @@ -965,8 +978,8 @@ func TestConvertToAST_do_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(DoStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*DoStatement)) }) } } @@ -982,11 +995,12 @@ func TestConvertToAST_defer_stmt(t *testing.T) { input: ` defer foo();`, expected: DeferStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeDeferStatement).WithStartEnd(3, 3, 3, 15).Build(), - Statement: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(3, 9, 3, 14).Build(), - Identifier: NewIdentifierBuilder().WithName("foo").WithStartEnd(3, 9, 3, 12).Build(), - Arguments: []Arg{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 15).Build(), + Statement: &ExpressionStmt{Expr: &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 9, 3, 14).Build(), + Identifier: NewIdentifierBuilder().WithName("foo").WithStartEnd(3, 9, 3, 12).Build(), + Arguments: []Expression{}, + }, }, }, }, @@ -995,11 +1009,12 @@ func TestConvertToAST_defer_stmt(t *testing.T) { input: ` defer try foo();`, expected: DeferStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeDeferStatement).WithStartEnd(3, 3, 3, 19).Build(), - Statement: FunctionCall{ - ASTBaseNode: NewBaseNodeBuilder(TypeFunctionCallExpr).WithStartEnd(3, 13, 3, 18).Build(), - Identifier: NewIdentifierBuilder().WithName("foo").WithStartEnd(3, 13, 3, 16).Build(), - Arguments: []Arg{}, + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 19).Build(), + Statement: &ExpressionStmt{Expr: &FunctionCall{ + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 13, 3, 18).Build(), + Identifier: NewIdentifierBuilder().WithName("foo").WithStartEnd(3, 13, 3, 16).Build(), + Arguments: []Expression{}, + }, }, }, }, @@ -1017,8 +1032,8 @@ func TestConvertToAST_defer_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(DeferStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*DeferStatement)) }) } } @@ -1034,9 +1049,9 @@ func TestConvertToAST_assert_stmt(t *testing.T) { input: ` assert(true);`, expected: AssertStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeAssertStatement).WithStartEnd(3, 3, 3, 16).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 16).Build(), Assertions: []Expression{ - BoolLiteral{Value: true}, + &BoolLiteral{Value: true}, }, }, }, @@ -1045,10 +1060,10 @@ func TestConvertToAST_assert_stmt(t *testing.T) { input: ` assert(true,1);`, expected: AssertStatement{ - ASTBaseNode: NewBaseNodeBuilder(TypeAssertStatement).WithStartEnd(3, 3, 3, 18).Build(), + NodeAttributes: NewBaseNodeBuilder().WithStartEnd(3, 3, 3, 18).Build(), Assertions: []Expression{ - BoolLiteral{Value: true}, - IntegerLiteral{Value: "1"}, + &BoolLiteral{Value: true}, + &IntegerLiteral{Value: "1"}, }, }, }, @@ -1066,8 +1081,8 @@ func TestConvertToAST_assert_stmt(t *testing.T) { ast := ConvertToAST(GetCST(source), source, "file.c3") - funcDecl := ast.Modules[0].Functions[0].(FunctionDecl) - assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStatement).Statements[0].(AssertStatement)) + funcDecl := ast.Modules[0].Declarations[0].(*FunctionDecl) + assert.Equal(t, tt.expected, funcDecl.Body.(CompoundStmt).Statements[0].(*AssertStatement)) }) } } diff --git a/server/internal/lsp/ast/json_visitor.go b/server/internal/lsp/ast/json_visitor.go index 93077f0..97e443a 100644 --- a/server/internal/lsp/ast/json_visitor.go +++ b/server/internal/lsp/ast/json_visitor.go @@ -8,7 +8,7 @@ type JSONVisitor struct { Result map[string]interface{} } -func serialize_pos(node ASTNode) map[string]interface{} { +func serialize_pos(node Node) map[string]interface{} { return map[string]interface{}{ "start": []uint{node.StartPosition().Line, node.StartPosition().Column}, "end": []uint{node.EndPosition().Line, node.EndPosition().Column}, @@ -44,7 +44,7 @@ func (v *JSONVisitor) VisitModule(node *Module) { functionsV := JSONVisitor{} functions := []interface{}{} - for _, fun := range node.Functions { + for _, fun := range node.Declarations { Visit(fun, &functionsV) if functionsV.Result != nil { functions = append(functions, functionsV.Result) @@ -111,7 +111,7 @@ func (v *JSONVisitor) VisitMacroDecl(node *MacroDecl) { } -func (v *JSONVisitor) VisitLambdaDeclaration(node *LambdaDeclaration) { +func (v *JSONVisitor) VisitLambdaDeclaration(node *LambdaDeclarationExpr) { } @@ -160,7 +160,7 @@ func (v *JSONVisitor) VisitInterfaceDecl(node *InterfaceDecl) { } -func (v *JSONVisitor) VisitCompounStatement(node *CompoundStatement) { +func (v *JSONVisitor) VisitCompounStatement(node *CompoundStmt) { visitor := JSONVisitor{} statements := []JSONObject{} for _, s := range node.Statements { @@ -191,7 +191,7 @@ func VisitType(node *TypeInfo) JSONObject { } } -func (v *JSONVisitor) VisitIdentifier(node *Identifier) { +func (v *JSONVisitor) VisitIdentifier(node *Ident) { } @@ -199,7 +199,7 @@ func (v *JSONVisitor) VisitBinaryExpression(node *BinaryExpression) { } -func (v *JSONVisitor) VisitIfStatement(node *IfStatement) { +func (v *JSONVisitor) VisitIfStatement(node *IfStmt) { } diff --git a/server/internal/lsp/ast2/ast_test.go b/server/internal/lsp/ast2/ast_test.go new file mode 100644 index 0000000..34957db --- /dev/null +++ b/server/internal/lsp/ast2/ast_test.go @@ -0,0 +1,42 @@ +package ast2 + +import ( + "fmt" + "go/token" + "testing" +) + +func Test_walk(t *testing.T) { + file := &File{ + Name: Ident{0, "main.c3"}, + Decls: []Decl{ + &VarDecl{Name: Ident{0, "x"}, Values: []Expr{ + &BasicLit{ + ValuePos: 2, + Kind: token.INT, + Value: "2", + }, + }}, + }, + } + + if file.FileStart == 0 { + + } + Walky(file) +} + +func Walky(n Node) { + switch n.(type) { + case *File: + fmt.Println("Is a file") + for _, decls := range n.(*File).Decls { + Walky(decls) + } + + case *VarDecl: + fmt.Println("It's a vardecl") + default: + fmt.Println("I dont know") + } +} diff --git a/server/internal/lsp/stdlib/v055.go b/server/internal/lsp/stdlib/v055.go index dece7d2..eeb737d 100644 --- a/server/internal/lsp/stdlib/v055.go +++ b/server/internal/lsp/stdlib/v055.go @@ -363,7 +363,7 @@ func Load_v055_stdlib() symbolstable.UnitModules { // Define module std::io::file module = moduleCollection["std::io::file"] - module.AddFunction(symbols.NewFunctionBuilder("open", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("open_path", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("from_handle", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("file", "CFile", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_size", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("reopen", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("seek", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("offset", "isz", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("seek_mode", "Seek", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write_byte", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("close", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("eof", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read_byte", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_buffer", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_new", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_temp", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("flush", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("open", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("open_path", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("from_handle", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("file", "CFile", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_size", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("reopen", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("seek", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("offset", "isz", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("seek_mode", "Seek", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write_byte", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("close", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("eof", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read_byte", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_buffer", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_new", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_temp", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("flush", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io module = moduleCollection["std::io"] @@ -379,7 +379,7 @@ func Load_v055_stdlib() symbolstable.UnitModules { // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_chdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_chdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] @@ -399,27 +399,27 @@ func Load_v055_stdlib() symbolstable.UnitModules { // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_mkdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_mkdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_rmdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_rmdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("Path", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("Path", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::path module = moduleCollection["std::io::path"] - module.AddVariable(symbols.NewVariableBuilder("DEFAULT_PATH_ENV", "PathEnv", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_POSIX", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_WIN32", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_POSIX", "bool[256]", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_WIN32", "bool[256]", "std::io::path", &docId).Build()).AddStruct(symbols.NewStructBuilder("Path", "std::io::path", &docId).WithStructMember("path_string", "String", "std::io::path", &docId).WithStructMember("env", "PathEnv", "std::io::path", &docId).WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathList", "std::io::path", &docId).WithResolvesTo("").WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathWalker", "std::io::path", &docId).WithResolvesTo("fn bool! (Path, bool is_dir, void*)").WithoutSourceCode().Build()).AddEnum(symbols.NewEnumBuilder("MkdirPermissions", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("NORMAL", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_ONLY", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_AND_ADMIN", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddEnum(symbols.NewEnumBuilder("PathEnv", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("WIN32", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("POSIX", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddFault(symbols.NewFaultBuilder("PathResult", "", "std::io::path", &docId).WithConstant(symbols.NewFaultConstantBuilder("INVALID_PATH", &docId).Build()).WithConstant(symbols.NewFaultConstantBuilder("NO_PARENT", &docId).Build()).Build()).AddFunction(symbols.NewFunctionBuilder("getcwd", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_dir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("file_size", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("exists", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tgetcwd", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("chdir", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_directory", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_posix_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_win32_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("ls", symbols.NewTypeFromString("PathList", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("mkdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("recursive", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmtree", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_new", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_win32_wstring", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "WString", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_windows", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_posix", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("equals", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("p2", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("append", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tappend", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("start_of_base_name", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_absolute", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("absolute", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("basename", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("dirname", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("extension", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name_len", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("parent", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("normalize", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path_str", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("as_zstr", symbols.NewTypeFromString("ZString", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("root_directory", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("walk", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("w", "PathWalker", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("data", "void", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("str_view", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("has_suffix", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("str", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_format", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("formatter", "Formatter", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_new_string", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_win32_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddVariable(symbols.NewVariableBuilder("DEFAULT_PATH_ENV", "PathEnv", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_POSIX", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_WIN32", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_POSIX", "bool[256]", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_WIN32", "bool[256]", "std::io::path", &docId).Build()).AddStruct(symbols.NewStructBuilder("ModulePath", "std::io::path", &docId).WithStructMember("path_string", "String", "std::io::path", &docId).WithStructMember("env", "PathEnv", "std::io::path", &docId).WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathList", "std::io::path", &docId).WithResolvesTo("").WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathWalker", "std::io::path", &docId).WithResolvesTo("fn bool! (ModulePath, bool is_dir, void*)").WithoutSourceCode().Build()).AddEnum(symbols.NewEnumBuilder("MkdirPermissions", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("NORMAL", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_ONLY", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_AND_ADMIN", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddEnum(symbols.NewEnumBuilder("PathEnv", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("WIN32", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("POSIX", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddFault(symbols.NewFaultBuilder("PathResult", "", "std::io::path", &docId).WithConstant(symbols.NewFaultConstantBuilder("INVALID_PATH", &docId).Build()).WithConstant(symbols.NewFaultConstantBuilder("NO_PARENT", &docId).Build()).Build()).AddFunction(symbols.NewFunctionBuilder("getcwd", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_dir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("file_size", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("exists", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tgetcwd", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("chdir", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_posix_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_win32_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("ls", symbols.NewTypeFromString("PathList", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("mkdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("recursive", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmtree", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_new", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_win32_wstring", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "WString", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_windows", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_posix", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("equals", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("p2", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("append", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tappend", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("start_of_base_name", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_absolute", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("absolute", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("basename", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("dirname", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("extension", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name_len", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("parent", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("normalize", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path_str", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("as_zstr", symbols.NewTypeFromString("ZString", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("root_directory", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("walk", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("w", "PathWalker", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("data", "void", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("str_view", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("has_suffix", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("str", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_format", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("formatter", "Formatter", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_new_string", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_win32_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io module = moduleCollection["std::io"] @@ -683,7 +683,7 @@ func Load_v055_stdlib() symbolstable.UnitModules { // Define module std::os::env module = moduleCollection["std::os::env"] - module.AddFunction(symbols.NewFunctionBuilder("get_var", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_var_temp", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("set_var", symbols.NewTypeFromString("bool", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("value", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("overwrite", "bool", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_home_dir", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("using", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_config_dir", symbols.NewTypeFromString("Path", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("clear_var", symbols.NewTypeFromString("bool", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("executable_path", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("get_var", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_var_temp", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("set_var", symbols.NewTypeFromString("bool", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("value", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("overwrite", "bool", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_home_dir", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("using", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_config_dir", symbols.NewTypeFromString("ModulePath", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("clear_var", symbols.NewTypeFromString("bool", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("executable_path", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()) // Define module std::os::linux module = moduleCollection["std::os::linux"] diff --git a/server/internal/lsp/stdlib/v060.go b/server/internal/lsp/stdlib/v060.go index 620acac..272a86f 100644 --- a/server/internal/lsp/stdlib/v060.go +++ b/server/internal/lsp/stdlib/v060.go @@ -363,7 +363,7 @@ func Load_v060_stdlib() symbolstable.UnitModules { // Define module std::io::file module = moduleCollection["std::io::file"] - module.AddFunction(symbols.NewFunctionBuilder("open", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("open_path", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("from_handle", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("file", "CFile", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_size", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("reopen", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("seek", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("offset", "isz", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("seek_mode", "Seek", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write_byte", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("close", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("eof", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read_byte", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_buffer", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_new", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_temp", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("flush", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("open", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("open_path", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("from_handle", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("file", "CFile", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_size", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("reopen", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("seek", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("offset", "isz", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("seek_mode", "Seek", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write_byte", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("close", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("eof", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read_byte", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_buffer", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_new", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_temp", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("flush", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io module = moduleCollection["std::io"] @@ -379,7 +379,7 @@ func Load_v060_stdlib() symbolstable.UnitModules { // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_chdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_chdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] @@ -399,27 +399,27 @@ func Load_v060_stdlib() symbolstable.UnitModules { // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_mkdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_mkdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_rmdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_rmdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("Path", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("Path", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::path module = moduleCollection["std::io::path"] - module.AddVariable(symbols.NewVariableBuilder("DEFAULT_PATH_ENV", "PathEnv", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_POSIX", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_WIN32", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_POSIX", "bool[256]", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_WIN32", "bool[256]", "std::io::path", &docId).Build()).AddStruct(symbols.NewStructBuilder("Path", "std::io::path", &docId).WithStructMember("path_string", "String", "std::io::path", &docId).WithStructMember("env", "PathEnv", "std::io::path", &docId).WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathList", "std::io::path", &docId).WithResolvesTo("").WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathWalker", "std::io::path", &docId).WithResolvesTo("fn bool! (Path, bool is_dir, void*)").WithoutSourceCode().Build()).AddEnum(symbols.NewEnumBuilder("MkdirPermissions", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("NORMAL", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_ONLY", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_AND_ADMIN", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddEnum(symbols.NewEnumBuilder("PathEnv", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("WIN32", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("POSIX", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddFault(symbols.NewFaultBuilder("PathResult", "", "std::io::path", &docId).WithConstant(symbols.NewFaultConstantBuilder("INVALID_PATH", &docId).Build()).WithConstant(symbols.NewFaultConstantBuilder("NO_PARENT", &docId).Build()).Build()).AddFunction(symbols.NewFunctionBuilder("getcwd", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_dir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("file_size", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("exists", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tgetcwd", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("chdir", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_directory", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_posix_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_win32_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("ls", symbols.NewTypeFromString("PathList", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("mkdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("recursive", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmtree", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_new", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_win32_wstring", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "WString", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_windows", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_posix", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("equals", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("p2", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("append", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tappend", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("start_of_base_name", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_absolute", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("absolute", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("basename", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("dirname", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("extension", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name_len", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("parent", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("normalize", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path_str", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("as_zstr", symbols.NewTypeFromString("ZString", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("root_directory", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("walk", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("w", "PathWalker", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("data", "void", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("str_view", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("has_suffix", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("str", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free_with_allocator", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_format", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("formatter", "Formatter", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_new_string", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_win32_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddVariable(symbols.NewVariableBuilder("DEFAULT_PATH_ENV", "PathEnv", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_POSIX", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_WIN32", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_POSIX", "bool[256]", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_WIN32", "bool[256]", "std::io::path", &docId).Build()).AddStruct(symbols.NewStructBuilder("ModulePath", "std::io::path", &docId).WithStructMember("path_string", "String", "std::io::path", &docId).WithStructMember("env", "PathEnv", "std::io::path", &docId).WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathList", "std::io::path", &docId).WithResolvesTo("").WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathWalker", "std::io::path", &docId).WithResolvesTo("fn bool! (ModulePath, bool is_dir, void*)").WithoutSourceCode().Build()).AddEnum(symbols.NewEnumBuilder("MkdirPermissions", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("NORMAL", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_ONLY", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_AND_ADMIN", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddEnum(symbols.NewEnumBuilder("PathEnv", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("WIN32", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("POSIX", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddFault(symbols.NewFaultBuilder("PathResult", "", "std::io::path", &docId).WithConstant(symbols.NewFaultConstantBuilder("INVALID_PATH", &docId).Build()).WithConstant(symbols.NewFaultConstantBuilder("NO_PARENT", &docId).Build()).Build()).AddFunction(symbols.NewFunctionBuilder("getcwd", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_dir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("file_size", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("exists", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tgetcwd", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("chdir", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_posix_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_win32_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("ls", symbols.NewTypeFromString("PathList", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("mkdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("recursive", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmtree", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_new", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_win32_wstring", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "WString", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_windows", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_posix", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("equals", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("p2", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("append", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tappend", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("start_of_base_name", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_absolute", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("absolute", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("basename", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("dirname", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("extension", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name_len", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("parent", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("normalize", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path_str", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("as_zstr", symbols.NewTypeFromString("ZString", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("root_directory", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("walk", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("w", "PathWalker", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("data", "void", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("str_view", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("has_suffix", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("str", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free_with_allocator", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_format", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("formatter", "Formatter", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_new_string", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_win32_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io module = moduleCollection["std::io"] @@ -683,7 +683,7 @@ func Load_v060_stdlib() symbolstable.UnitModules { // Define module std::os::env module = moduleCollection["std::os::env"] - module.AddFunction(symbols.NewFunctionBuilder("get_var", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_var_temp", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("set_var", symbols.NewTypeFromString("bool", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("value", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("overwrite", "bool", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_home_dir", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("using", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_config_dir", symbols.NewTypeFromString("Path", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("clear_var", symbols.NewTypeFromString("bool", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("executable_path", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("get_var", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_var_temp", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("set_var", symbols.NewTypeFromString("bool", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("value", "String", "std::os::env", &docId).Build()).WithArgument(symbols.NewVariableBuilder("overwrite", "bool", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_home_dir", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("using", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_config_dir", symbols.NewTypeFromString("ModulePath", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("clear_var", symbols.NewTypeFromString("bool", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("name", "String", "std::os::env", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("executable_path", symbols.NewTypeFromString("String", "std::os::env"), "std::os::env", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::os::env", &docId).Build()).WithoutSourceCode().Build()) // Define module std::os::linux module = moduleCollection["std::os::linux"] diff --git a/server/internal/lsp/stdlib/v061.go b/server/internal/lsp/stdlib/v061.go index 943c638..dc5c9bd 100644 --- a/server/internal/lsp/stdlib/v061.go +++ b/server/internal/lsp/stdlib/v061.go @@ -365,7 +365,7 @@ func Load_v061_stdlib() symbolstable.UnitModules { // Define module std::io::file module = moduleCollection["std::io::file"] - module.AddFunction(symbols.NewFunctionBuilder("open", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("open_path", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("from_handle", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("file", "CFile", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_size", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("reopen", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("seek", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("offset", "isz", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("seek_mode", "Seek", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write_byte", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("close", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("eof", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read_byte", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_buffer", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_new", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_temp", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("flush", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("open", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("open_path", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("from_handle", symbols.NewTypeFromString("File", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("file", "CFile", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("get_size", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("reopen", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mode", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("seek", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("offset", "isz", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("seek_mode", "Seek", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write_byte", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("close", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("eof", symbols.NewTypeFromString("bool", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("write", symbols.NewTypeFromString("usz", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("read_byte", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_buffer", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("buffer", "char", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_new", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("load_temp", symbols.NewTypeFromString("char", "std::io::file"), "std::io::file", &docId).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::file", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("flush", symbols.NewTypeFromString("void", "std::io::file"), "std::io::file", &docId).WithTypeIdentifier("File").WithArgument(symbols.NewVariableBuilder("self", "File", "std::io::file", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io module = moduleCollection["std::io"] @@ -381,7 +381,7 @@ func Load_v061_stdlib() symbolstable.UnitModules { // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_chdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_chdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] @@ -401,27 +401,27 @@ func Load_v061_stdlib() symbolstable.UnitModules { // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_ls", symbols.NewTypeFromString("PathList", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_mkdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_mkdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_rmdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_rmdir", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_rmtree", symbols.NewTypeFromString("void", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::os", &docId).Build()).WithoutSourceCode().Build()) // Define module std::io::os module = moduleCollection["std::io::os"] - module.AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("Path", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("Path", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("native_temp_directory", symbols.NewTypeFromString("", "std::io::os"), "std::io::os", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::os", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io::path module = moduleCollection["std::io::path"] - module.AddVariable(symbols.NewVariableBuilder("DEFAULT_PATH_ENV", "PathEnv", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_POSIX", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_WIN32", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_POSIX", "bool[256]", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_WIN32", "bool[256]", "std::io::path", &docId).Build()).AddStruct(symbols.NewStructBuilder("Path", "std::io::path", &docId).WithStructMember("path_string", "String", "std::io::path", &docId).WithStructMember("env", "PathEnv", "std::io::path", &docId).WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathList", "std::io::path", &docId).WithResolvesTo("").WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathWalker", "std::io::path", &docId).WithResolvesTo("fn bool! (Path, bool is_dir, void*)").WithoutSourceCode().Build()).AddEnum(symbols.NewEnumBuilder("MkdirPermissions", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("NORMAL", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_ONLY", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_AND_ADMIN", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddEnum(symbols.NewEnumBuilder("PathEnv", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("WIN32", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("POSIX", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddFault(symbols.NewFaultBuilder("PathResult", "", "std::io::path", &docId).WithConstant(symbols.NewFaultConstantBuilder("INVALID_PATH", &docId).Build()).WithConstant(symbols.NewFaultConstantBuilder("NO_PARENT", &docId).Build()).Build()).AddFunction(symbols.NewFunctionBuilder("getcwd", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_dir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("file_size", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("exists", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tgetcwd", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("chdir", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_directory", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_posix_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_win32_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("ls", symbols.NewTypeFromString("PathList", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("dir", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("mkdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("recursive", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmtree", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_new", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_win32_wstring", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "WString", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_windows", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_posix", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("equals", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("p2", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("append", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tappend", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("start_of_base_name", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_absolute", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("absolute", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("basename", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("dirname", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("extension", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name_len", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("parent", symbols.NewTypeFromString("Path", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("normalize", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path_str", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("as_zstr", symbols.NewTypeFromString("ZString", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("root_directory", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("walk", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("w", "PathWalker", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("data", "void", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("str_view", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("has_suffix", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("str", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free_with_allocator", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_format", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("formatter", "Formatter", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_new_string", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_win32_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()) + module.AddVariable(symbols.NewVariableBuilder("DEFAULT_PATH_ENV", "PathEnv", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_POSIX", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("PREFERRED_SEPARATOR_WIN32", "char", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_POSIX", "bool[256]", "std::io::path", &docId).Build()).AddVariable(symbols.NewVariableBuilder("RESERVED_PATH_CHAR_WIN32", "bool[256]", "std::io::path", &docId).Build()).AddStruct(symbols.NewStructBuilder("ModulePath", "std::io::path", &docId).WithStructMember("path_string", "String", "std::io::path", &docId).WithStructMember("env", "PathEnv", "std::io::path", &docId).WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathList", "std::io::path", &docId).WithResolvesTo("").WithoutSourceCode().Build()).AddDef(symbols.NewDefBuilder("PathWalker", "std::io::path", &docId).WithResolvesTo("fn bool! (ModulePath, bool is_dir, void*)").WithoutSourceCode().Build()).AddEnum(symbols.NewEnumBuilder("MkdirPermissions", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("NORMAL", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_ONLY", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("USER_AND_ADMIN", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddEnum(symbols.NewEnumBuilder("PathEnv", "", "std::io::path", &docId).WithEnumerator(symbols.NewEnumeratorBuilder("WIN32", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).WithEnumerator(symbols.NewEnumeratorBuilder("POSIX", &docId).WithAssociativeValues([]symbols.Variable{}).Build()).Build()).AddFault(symbols.NewFaultBuilder("PathResult", "", "std::io::path", &docId).WithConstant(symbols.NewFaultConstantBuilder("INVALID_PATH", &docId).Build()).WithConstant(symbols.NewFaultConstantBuilder("NO_PARENT", &docId).Build()).Build()).AddFunction(symbols.NewFunctionBuilder("getcwd", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_dir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_file", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("file_size", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("exists", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tgetcwd", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("chdir", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_directory", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("delete", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_posix_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_win32_separator", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("ls", symbols.NewTypeFromString("PathList", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("dir", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_dirs", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("no_symlinks", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("mask", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("mkdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("recursive", "bool", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("permissions", "MkdirPermissions", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmdir", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("rmtree", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("temp_new", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_win32_wstring", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "WString", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_windows", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("new_posix", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("equals", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("p2", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("append", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("tappend", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("filename", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("start_of_base_name", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_absolute", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("absolute", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("basename", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("dirname", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("extension", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("ModulePath").WithArgument(symbols.NewVariableBuilder("self", "ModulePath", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("volume_name_len", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("parent", symbols.NewTypeFromString("ModulePath", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("normalize", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("path_str", "String", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("as_zstr", symbols.NewTypeFromString("ZString", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("root_directory", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("walk", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("w", "PathWalker", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("data", "void", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("str_view", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("has_suffix", symbols.NewTypeFromString("bool", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("str", "String", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free_with_allocator", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("free", symbols.NewTypeFromString("void", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_format", symbols.NewTypeFromString("usz", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("formatter", "Formatter", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("to_new_string", symbols.NewTypeFromString("String", "std::io::path"), "std::io::path", &docId).WithTypeIdentifier("Path").WithArgument(symbols.NewVariableBuilder("self", "Path", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("allocator", "Allocator", "std::io::path", &docId).Build()).WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_win32_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()).AddFunction(symbols.NewFunctionBuilder("is_reserved_path_char", symbols.NewTypeFromString("", "std::io::path"), "std::io::path", &docId).WithArgument(symbols.NewVariableBuilder("c", "char", "std::io::path", &docId).Build()).WithArgument(symbols.NewVariableBuilder("path_env", "PathEnv", "std::io::path", &docId).Build()).IsMacro().WithoutSourceCode().Build()) // Define module std::io module = moduleCollection["std::io"]