13. Boost package for the AST

The AST boost module implements collection of helper macros and functions to accompany AST.

All functions and symbols are in “ast_boost” module, use require to get access to it.

require daslib/ast_boost

13.1. Type aliases

AnnotationDeclarationPtr = smart_ptr<AnnotationDeclaration>

Alias for smart_ptr<AnnotationDeclaration>

bitfield DebugExpressionFlags
Fields
  • refCount (0x1) - Which things to print in debug_expression.

13.2. Function annotations

macro

MacroMacro function annotation.

tag_function

TagFunctionAnnotation function annotation.

13.3. Variant macros

better_rtti_in_expr

This macro is used to implement is type, as type and ?as type runtime checks for the Expression class and its subclasses.

13.4. Structure macros

function_macro

Turns AstFunctionAnnotation into a macro with the specified name.

block_macro

Turns AstBlockAnnotation into a macro with the specified name.

structure_macro

Turns AstStructureAnnotation into a macro with the specified name.

enumeration_macro

Turns AstEnumerationAnnotation into a macro with the specified name.

contract

Turns AstFunctionAnnotation into a contract macro with the specified name.

reader_macro

Turns AstReaderMacro into a macro with the specified name.

comment_reader

Turns AstCommentReader into a macro with the specified name.

call_macro

Turns AstCallMacro into a macro with the specified name.

typeinfo_macro

Turns AstTypeInfoMacro into a macro with the specified name.

variant_macro

Turns AstVariantMacro into a macro with the specified name.

for_loop_macro

Turns AstForLoopMacro into a macro with the specified name.

capture_macro

Turns AstCaptureMacro into a macro with the specified name.

type_macro

Turns AstTypeMacro into a macro with the specified name.

simulate_macro

Turns AstSimulateMacro into a macro with the specified name.

tag_structure

This macro implements [tag_structure] annotation, which allows to add tag (name) to a specific structure.

tag_function_macro

This macro implements [tag_function_macro] annotation, which allows to add an AstFunctionAnnotation to any function with a specific [tag_function(name)] tag.

infer_macro

Turns AstPassMacro into a macro with the specified ‘name’, which is called during the infer pass.

dirty_infer_macro

Turns AstPassMacro into a macro with the specified ‘name’, which is called during the dirty infer pass.

optimization_macro

Turns AstPassMacro into a macro with the specified ‘name’, which is called during the optimization pass.

lint_macro

Turns AstPassMacro into a macro with the specified ‘name’, which is called during the lint pass.

global_lint_macro

Turns AstPassMacro into a macro with the specified ‘name’, which is called during the global lint pass.

13.5. Classes

MacroMacro : AstFunctionAnnotation

This macro implements [macro] function annotation.

MacroMacro.apply(func: FunctionPtr; group: ModuleGroup; args: AnnotationArgumentList; errors: das_string) : bool()

Implementation details of a function annotation macro.

Arguments
TagFunctionAnnotation : AstFunctionAnnotation

This annotation is used for tagging specific funcstion.

TagFunctionAnnotation.apply(func: FunctionPtr; group: ModuleGroup; args: AnnotationArgumentList; errors: das_string) : bool()

Implementation details of a function annotation macro.

Arguments
TagStructureAnnotation : AstStructureAnnotation

This annotation is used for tagging specific structure.

TagStructureAnnotation.apply(str: StructurePtr; group: ModuleGroup; args: AnnotationArgumentList; errors: das_string) : bool()

Implementation details of a function annotation macro.

Arguments
SetupAnyAnnotation : AstStructureAnnotation

This is base class for any annotation or macro setup.

Fields
  • annotation_function_call : string = “” - Function call name, which is used to setup any annotation.

  • name : string - Name of the annotation to setup.

SetupAnyAnnotation.apply(st: StructurePtr; group: ModuleGroup; args: AnnotationArgumentList; errors: das_string) : bool()

Implementation details for setting up any type of annotation in the ast_boost module.

Arguments
SetupAnyAnnotation.setup_call(st: StructurePtr; cll: smart_ptr<ExprCall>)

Implementation details for how the call is set up for any annotation.

Arguments
SetupFunctionAnnotation : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_function_annotation” - This is base class for function annotation setup.

SetupBlockAnnotation : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_block_annotation” - This is base class for block annotation setup.

SetupStructureAnnotation : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_structure_annotation” - This is base class for structure annotation setup.

SetupEnumerationAnnotation : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_enumeration_annotation” - [enumration_macro] implementation.

SetupContractAnnotation : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_contract_annotation” - This is base class for contract annotation setup.

SetupReaderMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_reader_macro” - [reader_macro] implementation.

SetupCommentReader : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_comment_reader” - [comment_reader] implementation.

SetupVariantMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_variant_macro” - [variant_macro] implementation.

SetupForLoopMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_for_loop_macro” - [for_loop_macro] implementation.

SetupCaptureMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_capture_macro” - [capture_macro] implementation.

SetupTypeMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_type_macro” - This is base class for type macro setup.

SetupSimulateMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_simulate_macro” - This is base class for a simulate macro.

SetupCallMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_call_macro” - [call_macro] implementation.

SetupTypeInfoMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_typeinfo_macro” - [typeinfo_macro] implementation.

SetupInferMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_infer_macro” - [infer_macro] implementation.

SetupDirtyInferMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_dirty_infer_macro” - [dirty_infer_macro] implementation.

SetupLintMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_lint_macro” - [lint_macro] implementation.

SetupGlobalLintMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_global_lint_macro” - [global_lint_macro] implementation.

SetupOptimizationMacro : SetupAnyAnnotation
Fields
  • annotation_function_call : string = “add_new_optimization_macro” - [optimization_macro] implementation.

TagFunctionMacro : SetupAnyAnnotation

[tag_function_macro] implementation.

Fields
  • annotation_function_call : string = “setup_tag_annotation” - Name of the function call, which setups up the annotation.

  • tag : string - Name of the tag.

TagFunctionMacro.apply(st: StructurePtr; group: ModuleGroup; args: AnnotationArgumentList; errors: das_string) : bool()

Implementation details for setting up tag function annotation in the ast_boost module.

Arguments
TagFunctionMacro.setup_call(st: StructurePtr; cll: smart_ptr<ExprCall>)

Implementation details for how the call is set up for tag function annotation.

Arguments
BetterRttiVisitor : AstVariantMacro

Implements expr is type and expr as type checks, using RTTI.

BetterRttiVisitor.visitExprIsVariant(prog: ProgramPtr; mod: Module?; expr: smart_ptr<ExprIsVariant>) : ExpressionPtr()

For Expr* replaces ‘is’ with check of __rtti, and returns true if it matches.

Arguments
BetterRttiVisitor.visitExprAsVariant(prog: ProgramPtr; mod: Module?; expr: smart_ptr<ExprAsVariant>) : ExpressionPtr()

For Expr* replaced ‘as’ with cast, which checks __rtti.

Arguments
BetterRttiVisitor.visitExprSafeAsVariant(prog: ProgramPtr; mod: Module?; expr: smart_ptr<ExprSafeAsVariant>) : ExpressionPtr()

For Expr* replaces ‘as’ with cast, which checks __rtti. :Arguments: * prog : ProgramPtr

13.6. Containers

emplace_new(vec: dasvector`smart_ptr`Expression; ptr: smart_ptr<Expression>)

Emplaces newly created object into the container without memory leak (i.e. correct ptr_ref_count).

Arguments
  • vec : vector<smart_ptr<Expression>>

  • ptr : smart_ptr< Expression >

emplace_new(vec: dasvector`smart_ptr`TypeDecl; ptr: smart_ptr<TypeDecl>)

Emplaces newly created object into the container without memory leak (i.e. correct ptr_ref_count).

Arguments
  • vec : vector<smart_ptr<TypeDecl>>

  • ptr : smart_ptr< TypeDecl >

emplace_new(vec: dasvector`smart_ptr`Variable; ptr: smart_ptr<Variable>)

Emplaces newly created object into the container without memory leak (i.e. correct ptr_ref_count).

Arguments
  • vec : vector<smart_ptr<Variable>>

  • ptr : smart_ptr< Variable >

emplace_new(vec: MakeStruct; ptr: smart_ptr<MakeFieldDecl>)

Emplaces newly created object into the container without memory leak (i.e. correct ptr_ref_count).

Arguments

13.7. Textual descriptions of the objects

describe(list: AnnotationArgumentList) : string()

Returns textual description of the object.

Arguments
describe(ann: AnnotationDeclaration) : string()

Returns textual description of the object.

Arguments
describe(list: AnnotationList) : string()

Returns textual description of the object.

Arguments
describe(vvar: VariablePtr) : string()

Returns textual description of the object.

Arguments
debug_expression(expr: ExpressionPtr; deFlags: DebugExpressionFlags = bitfield(0x0)) : string()

Gives hierarchical lisp-like textual representation of expression with all its subexpressions.

Arguments
debug_expression(expr: Expression?) : string()

Gives hierarchical lisp-like textual representation of expression with all its subexpressions.

Arguments
describe(expr: Expression?) : string()

Returns textual description of the object.

Arguments
describe_bitfield(bf: auto; merger: string = "") : auto()

Returns textual description of the bitfield.

Arguments
  • bf : auto

  • merger : string

describe_function_short(func: smart_ptr<Function>|Function?) : auto()

Gives short (name, arguments with types, result type) description of the function.

Arguments

13.8. Queries

isVectorType(typ: Type) : bool()

Returns true if type is vector type, i.e. int2, float3, and such, including range and urange.

Arguments
isExpression(t: TypeDeclPtr; top: bool = true) : bool()

Returns true if given object is derived from ast::Expression.

Arguments
is_same_or_inherited(parent: Structure const?; child: Structure const?) : bool()

Returns true if child is the same class as parent, or is inherited from the parent.

Arguments
is_class_method(cinfo: StructurePtr; finfo: TypeDeclPtr) : bool()

Returns true if field is a class method.

Arguments
find_arg(argn: string; args: AnnotationArgumentList) : RttiValue()

Warning

This function is deprecated.

Find argument in annotation argument list.

Arguments
find_arg(args: AnnotationArgumentList; argn: string) : RttiValue()

Find argument in annotation argument list.

Arguments
find_unique_function(mod: Module?; name: string; canfail: bool = false) : smart_ptr<Function>()

Returns unique function of that specific name, or null if there is none or more than one.

Arguments
  • mod : Module ?

  • name : string

  • canfail : bool

find_unique_generic(mod: Module?; name: string; canfail: bool = false) : smart_ptr<Function>()

Returns unique generic function of that specific name, or null if there is none or more than one.

Arguments
  • mod : Module ?

  • name : string

  • canfail : bool

find_annotation(mod_name: string; ann_name: string) : Annotation const?()

Finds annotation in the module.

Arguments
  • mod_name : string

  • ann_name : string

get_for_source_index(expr: smart_ptr<ExprFor>; svar: VariablePtr) : int()

Find index of the for loop source variable.

Arguments
get_for_source_index(expr: smart_ptr<ExprFor>; source: ExpressionPtr) : int()

Find index of the for loop source variable.

Arguments
isCMRES(fun: FunctionPtr) : bool()

Returns true if function returns result by copy-or-move on the stack, as oppose to through the register ABI.

Arguments
isCMRES(fun: Function?) : bool()

Returns true if function returns result by copy-or-move on the stack, as oppose to through the register ABI.

Arguments
isMakeLocal(expr: ExpressionPtr) : bool()

Returns true if Expression is inherited from ExprMakeLocal, i.e. ExprMakeArray, ExprMakeStruct, ExprMakeTuple, or ExprMakeVariant.

Arguments
isExprCallFunc(expr: ExpressionPtr) : bool()

Returns true if expression is ExprCallFunction.

Arguments
get_workhorse_types() : Type[34]()

Returns array which contains all workhorse base types.

find_argument_index(typ: TypeDeclPtr; name: string) : int()

Returns index of the specific argument name, or -1 if its not found.

Arguments
isCMRESType(blockT: TypeDeclPtr) : bool()

Returns true if type is copy-or-move on the stack, as oppose to through the register ABI.

Arguments
getVectorElementCount(bt: Type) : int()

Number of elements in the vector type, for example 3 for float3.

Arguments
getVectorElementSize(bt: Type) : int()

Size of individual element in the vector type, for example 4 in float2 and 8 in range64.

Arguments
getVectorElementType(bt: Type) : Type()

Type of individual element in the vector type, for example float in float2.

Arguments
getVectorOffset(bt: Type; ident: string) : int()

Offset of the element in the vector type, for example 4 for “y” in float2.

Arguments
  • bt : Type

  • ident : string

13.9. Annotations

append_annotation(mod_name: string; ann_name: string; args: array<tuple<argname:string;argvalue:variant<tBool:bool;tInt:int;tUInt:uint;tInt64:int64;tUInt64:uint64;tFloat:float;tDouble:double;tString:string;nothing:any>>>) : smart_ptr<AnnotationDeclaration>()

Appends function annotation to the function given its name and arguments.

Arguments
  • mod_name : string

  • ann_name : string

  • args : array<tuple<argname:string;argvalue: RttiValue >>

append_annotation(mod_name: string; ann_name: string) : smart_ptr<AnnotationDeclaration>()

Appends function annotation to the function given its name and arguments.

Arguments
  • mod_name : string

  • ann_name : string

append_annotation(func: FunctionPtr; mod_name: string; ann_name: string)

Appends function annotation to the function given its name and arguments.

Arguments
  • func : FunctionPtr

  • mod_name : string

  • ann_name : string

append_annotation(blk: smart_ptr<ExprBlock>; mod_name: string; ann_name: string)

Appends function annotation to the function given its name and arguments.

Arguments
  • blk : smart_ptr< ExprBlock >

  • mod_name : string

  • ann_name : string

append_annotation(st: smart_ptr<Structure>; mod_name: string; ann_name: string)

Appends function annotation to the function given its name and arguments.

Arguments
  • st : smart_ptr< Structure >

  • mod_name : string

  • ann_name : string

append_annotation(func: FunctionPtr; mod_name: string; ann_name: string; args: array<tuple<argname:string;argvalue:variant<tBool:bool;tInt:int;tUInt:uint;tInt64:int64;tUInt64:uint64;tFloat:float;tDouble:double;tString:string;nothing:any>>>)

Appends function annotation to the function given its name and arguments.

Arguments
  • func : FunctionPtr

  • mod_name : string

  • ann_name : string

  • args : array<tuple<argname:string;argvalue: RttiValue >>

append_annotation(blk: smart_ptr<ExprBlock>; mod_name: string; ann_name: string; args: array<tuple<argname:string;argvalue:variant<tBool:bool;tInt:int;tUInt:uint;tInt64:int64;tUInt64:uint64;tFloat:float;tDouble:double;tString:string;nothing:any>>>)

Appends function annotation to the function given its name and arguments.

Arguments
  • blk : smart_ptr< ExprBlock >

  • mod_name : string

  • ann_name : string

  • args : array<tuple<argname:string;argvalue: RttiValue >>

append_annotation(st: smart_ptr<Structure>; mod_name: string; ann_name: string; args: array<tuple<argname:string;argvalue:variant<tBool:bool;tInt:int;tUInt:uint;tInt64:int64;tUInt64:uint64;tFloat:float;tDouble:double;tString:string;nothing:any>>>)

Appends function annotation to the function given its name and arguments.

Arguments
  • st : smart_ptr< Structure >

  • mod_name : string

  • ann_name : string

  • args : array<tuple<argname:string;argvalue: RttiValue >>

add_annotation_argument(arguments: AnnotationArgumentList; argName: string; val: bool) : int()

Adds annotation argument to the argument list.

Arguments
add_annotation_argument(arguments: AnnotationArgumentList; argName: string; val: int) : int()

Adds annotation argument to the argument list.

Arguments
add_annotation_argument(arguments: AnnotationArgumentList; argName: string; val: float) : int()

Adds annotation argument to the argument list.

Arguments
add_annotation_argument(arguments: AnnotationArgumentList; argName: string; val: string) : int()

Adds annotation argument to the argument list.

Arguments
add_annotation_argument(arguments: AnnotationArgumentList; ann: AnnotationArgument) : int()

Adds annotation argument to the argument list.

Arguments

13.10. Expression generation

override_method(str: StructurePtr; name: string; funcName: string) : bool()

Override class method name with new function.

Arguments
panic_expr_as() : void?()

Function call which panics with “invalid ‘as’ expression or null pointer dereference” message.

make_static_assert_false(text: string; at: LineInfo) : smart_ptr<ExprStaticAssert>()

Creates static_assert(false,text) expression.

Arguments
convert_to_expression(value: auto& ==const; at: LineInfo) : auto()

Converts value to expression, which generates this value.

Arguments
convert_to_expression(value: auto ==const; at: LineInfo) : auto()

Converts value to expression, which generates this value.

Arguments
convert_to_expression(value: auto ==const) : auto()

Converts value to expression, which generates this value.

Arguments
  • value : auto!

convert_to_expression(value: auto ==const) : auto()

Converts value to expression, which generates this value.

Arguments
  • value : auto!

13.11. Visitors

visit_finally(blk: ExprBlock?; adapter: smart_ptr<VisitorAdapter>)

Calls visitor on the finally section of the block.

Arguments

13.12. Type generation

function_to_type(fn: FunctionPtr) : TypeDeclPtr()

Returns TypeDeclPtr of the tFunction type, based on the provided function.

Arguments

13.13. Setup

setup_call_list(name: string; at: LineInfo; subblock: block<(var fn:FunctionPtr):void>) : ExprBlock?()

Create new function which will contain collection of calls. Returns body block to where the call is to be appended.

Arguments
setup_call_list(name: string; at: LineInfo; isInit: bool = false; isPrivate: bool = true; isLateInit: bool = false) : ExprBlock?()

Create new function which will contain collection of calls. Returns body block to where the call is to be appended.

Arguments
  • name : string

  • at : LineInfo

  • isInit : bool

  • isPrivate : bool

  • isLateInit : bool

setup_macro(name: string; at: LineInfo) : ExprBlock?()

Setup macro initialization function, which will only be called during compilation of this module. Returns body block to where the macro initialization is to be appended.

Arguments
setup_tag_annotation(name: string; tag: string; classPtr: auto) : auto()

Creates annotation and applies it to all tagged functions given tag.

Arguments
  • name : string

  • tag : string

  • classPtr : auto

13.14. Uncategorized

Function?`is`BuiltInFunction(foo: Function?) : bool()

Returns true if foo is BuiltInFunction.

Arguments
Function?`as`BuiltInFunction(foo: Function?) : BuiltInFunction?()

Returns the BuiltInFunction or panics.

Arguments
Function?`is`ExternalFnBase(foo: Function?) : bool()

Returns true if foo is ExternalFnBase.

Arguments
Function?`as`ExternalFnBase(foo: Function?) : ExternalFnBase?()

Returns ExternalFnBase or panics. :Arguments: * foo : Function ?

Annotation?`is`FunctionAnnotation(foo: Annotation?) : bool()

Returns true if foo is FunctionAnnotation.

Arguments
smart_ptr<Annotation>`is`FunctionAnnotation(foo: smart_ptr<Annotation>) : bool()

Returns true if foo is FunctionAnnotation.

Arguments
Annotation?`as`FunctionAnnotation(foo: Annotation?) : FunctionAnnotation?()

Returns FunctionAnnotation or panics.

Arguments
smart_ptr<Annotation>`as`FunctionAnnotation(foo: smart_ptr<Annotation>) : FunctionAnnotation?()

Returns FunctionAnnotation or panics.

Arguments
Annotation?`is`StructureAnnotation(foo: Annotation?) : bool()

Returns true if foo is StructureAnnotation.

Arguments
smart_ptr<Annotation>`is`StructureAnnotation(foo: smart_ptr<Annotation>) : bool()

Returns true if foo is StructureAnnotation.

Arguments
Annotation?`as`StructureAnnotation(foo: Annotation?) : StructureAnnotation?()

Returns StructureAnnotation or panics.

Arguments
smart_ptr<Annotation>`as`StructureAnnotation(foo: smart_ptr<Annotation>) : StructureAnnotation?()

Returns StructureAnnotation or panics.

Arguments
walk_and_convert(data: uint8 const?; info: TypeDeclPtr; at: LineInfo) : ExpressionPtr()

Walks data and converts it to an AST which generates such data.

Arguments
auto`is`BuiltInFunction(anything: auto) : auto()

Returns true if foo is BuiltInFunction.

Arguments
  • anything : auto

auto`is`ExternalFnBase(anything: auto) : auto()

Returns true if foo is ExternalFnBase.

Arguments
  • anything : auto

auto`is`FunctionAnnotation(anything: auto) : auto()

Returns true if foo is FunctionAnnotation.

Arguments
  • anything : auto

auto`is`StructureAnnotation(anything: auto) : auto()

Returns true if foo is StructureAnnotation.

Arguments
  • anything : auto