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<rtti::AnnotationDeclaration>

Alias for smart_ptr<AnnotationDeclaration>

DebugExpressionFlags is a bitfield

field

bit

value

refCount

0

1

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.

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. This adds macro initialization function, which will only be called during macro compilation.

MacroMacro.apply(self: AstFunctionAnnotation; func: FunctionPtr; group: ModuleGroup; args: AnnotationArgumentList const; errors: das_string)

apply returns bool

argument

argument type

self

ast::AstFunctionAnnotation

func

FunctionPtr

group

rtti::ModuleGroup

args

rtti::AnnotationArgumentList const

errors

builtin::das_string

Implements [macro] function annotation. Internally it adds macro initialiation flag, as well as wraps function block in if is_compiling_macros() condition.

TagFunctionAnnotation : AstFunctionAnnotation

This annotation is used for tagging specific funcstion.

TagFunctionAnnotation.apply(self: AstFunctionAnnotation; func: FunctionPtr; group: ModuleGroup; args: AnnotationArgumentList const; errors: das_string)

apply returns bool

argument

argument type

self

ast::AstFunctionAnnotation

func

FunctionPtr

group

rtti::ModuleGroup

args

rtti::AnnotationArgumentList const

errors

builtin::das_string

Implements [tag_function] annotaiton. Internally this just verifies if tag has a name, i.e. bool argument without value (set to true).

TagStructureAnnotation : AstStructureAnnotation

This annotation is used for tagging specific structure. This annotation is used to tag structure with a name, which can be used to identify structure in the code.

TagStructureAnnotation.apply(self: AstStructureAnnotation; st: StructurePtr; group: ModuleGroup; args: AnnotationArgumentList const; errors: das_string)

apply returns bool

argument

argument type

self

ast::AstStructureAnnotation

st

StructurePtr

group

rtti::ModuleGroup

args

rtti::AnnotationArgumentList const

errors

builtin::das_string

Implements [tag_structure] annotation. Internally this just verifies if tag has a name, i.e. bool argument without value (set to true).

SetupAnyAnnotation : AstStructureAnnotation

This is base class for any annotation or macro setup.

it defines as follows

annotation_function_call : string
name : string
SetupAnyAnnotation.apply(self: AstStructureAnnotation; st: StructurePtr; group: ModuleGroup; args: AnnotationArgumentList const; errors: das_string)

apply returns bool

argument

argument type

self

ast::AstStructureAnnotation

st

StructurePtr

group

rtti::ModuleGroup

args

rtti::AnnotationArgumentList const

errors

builtin::das_string

Implements macro registration setup. Internally this creates __setup_macros function, which is only called during this module macro compilation. For the particular macro it adds call to the annotation registration function call (which is overrideable member annotation_function_call).

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

argument

argument type

self

ast_boost::SetupAnyAnnotation

st

StructurePtr

cll

smart_ptr< ast::ExprCall >

Implements macro registration name setup. Internally this adds name parameter to the annotation registration function call (which is overridable member name).

SetupFunctionAnnotation : SetupAnyAnnotation

This is base class for function annotation setup.

it defines as follows

annotation_function_call : string
name : string
SetupBlockAnnotation : SetupAnyAnnotation

This is base class for block annotation setup.

it defines as follows

annotation_function_call : string
name : string
SetupStructureAnnotation : SetupAnyAnnotation

This is base class for structure annotation setup.

it defines as follows

annotation_function_call : string
name : string
SetupEnumerationAnnotation : SetupAnyAnnotation

[enumration_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupContractAnnotation : SetupAnyAnnotation

This is base class for contract annotation setup.

it defines as follows

annotation_function_call : string
name : string
SetupReaderMacro : SetupAnyAnnotation

[reader_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupCommentReader : SetupAnyAnnotation

[comment_reader] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupVariantMacro : SetupAnyAnnotation

[variant_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupForLoopMacro : SetupAnyAnnotation

[for_loop_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupCaptureMacro : SetupAnyAnnotation

[capture_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupSimulateMacro : SetupAnyAnnotation

This is base class for a simulate macro. Internally this just verifies if tag has a name, i.e. bool argument without value (set to true).

it defines as follows

annotation_function_call : string
name : string
SetupCallMacro : SetupAnyAnnotation

[call_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupTypeInfoMacro : SetupAnyAnnotation

[typeinfo_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupInferMacro : SetupAnyAnnotation

[infer_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupDirtyInferMacro : SetupAnyAnnotation

[dirty_infer_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupLintMacro : SetupAnyAnnotation

[lint_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupGlobalLintMacro : SetupAnyAnnotation

[global_lint_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupOptimizationMacro : SetupAnyAnnotation

[optimization_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
TagFunctionMacro : SetupAnyAnnotation

[tag_function_macro] implementation. Applies annotation to all tagged functions.

it defines as follows

annotation_function_call : string
name : string
tag : string
TagFunctionMacro.apply(self: AstStructureAnnotation; st: StructurePtr; group: ModuleGroup; args: AnnotationArgumentList const; errors: das_string)

apply returns bool

argument

argument type

self

ast::AstStructureAnnotation

st

StructurePtr

group

rtti::ModuleGroup

args

rtti::AnnotationArgumentList const

errors

builtin::das_string

Makes sure tag is defined and is a string.

TagFunctionMacro.setup_call(self: SetupAnyAnnotation; st: StructurePtr; cll: smart_ptr<ast::ExprCall>)

argument

argument type

self

ast_boost::SetupAnyAnnotation

st

StructurePtr

cll

smart_ptr< ast::ExprCall >

Attaches tag as well as name to the setup call.

BetterRttiVisitor : AstVariantMacro

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

BetterRttiVisitor.visitExprIsVariant(self: AstVariantMacro; prog: ProgramPtr; mod: rtti::Module? const; expr: smart_ptr<ast::ExprIsVariant> const)

visitExprIsVariant returns ExpressionPtr

argument

argument type

self

ast::AstVariantMacro

prog

ProgramPtr

mod

rtti::Module ? const

expr

smart_ptr< ast::ExprIsVariant > const

Implements is type.

BetterRttiVisitor.visitExprAsVariant(self: AstVariantMacro; prog: ProgramPtr; mod: rtti::Module? const; expr: smart_ptr<ast::ExprAsVariant> const)

visitExprAsVariant returns ExpressionPtr

argument

argument type

self

ast::AstVariantMacro

prog

ProgramPtr

mod

rtti::Module ? const

expr

smart_ptr< ast::ExprAsVariant > const

Implements as type.

BetterRttiVisitor.visitExprSafeAsVariant(self: AstVariantMacro; prog: ProgramPtr; mod: rtti::Module? const; expr: smart_ptr<ast::ExprSafeAsVariant> const)

visitExprSafeAsVariant returns ExpressionPtr

argument

argument type

self

ast::AstVariantMacro

prog

ProgramPtr

mod

rtti::Module ? const

expr

smart_ptr< ast::ExprSafeAsVariant > const

Implements ?as type.

13.6. Containers

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

argument

argument type

vec

vector<smart_ptr<Expression>>

ptr

smart_ptr< ast::Expression >

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

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

argument

argument type

vec

vector<smart_ptr<TypeDecl>>

ptr

smart_ptr< ast::TypeDecl >

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

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

argument

argument type

vec

vector<smart_ptr<Variable>>

ptr

smart_ptr< ast::Variable >

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

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

argument

argument type

vec

ast::MakeStruct

ptr

smart_ptr< ast::MakeFieldDecl >

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

13.7. Textual descriptions of the objects

describe(list: AnnotationArgumentList const)

describe returns string const

argument

argument type

list

rtti::AnnotationArgumentList const

Returns textual description of the object.

describe(ann: AnnotationDeclaration const)

describe returns string

argument

argument type

ann

rtti::AnnotationDeclaration const

Returns textual description of the object.

describe(list: AnnotationList const)

describe returns string const

argument

argument type

list

rtti::AnnotationList const

Returns textual description of the object.

describe(vvar: VariablePtr)

describe returns string

argument

argument type

vvar

VariablePtr

Returns textual description of the object.

describe_function_short(func: FunctionPtr)

describe_function_short returns string const

argument

argument type

func

FunctionPtr

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

debug_expression(expr: ExpressionPtr; deFlags: DebugExpressionFlags)

debug_expression returns string

argument

argument type

expr

ExpressionPtr

deFlags

DebugExpressionFlags

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

debug_expression(expr: ast::Expression? const)

debug_expression returns string

argument

argument type

expr

ast::Expression ? const

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

describe(expr: ast::Expression? const)

describe returns string

argument

argument type

expr

ast::Expression ? const

Returns textual description of the object.

describe_bitfield(bf: auto const; merger: string const)

describe_bitfield returns auto

argument

argument type

bf

auto const

merger

string const

Returns textual description of the bitfield.

13.8. Queries

isVectorType(typ: Type const)

isVectorType returns bool

argument

argument type

typ

rtti::Type const

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

isExpression(t: TypeDeclPtr; top: bool const)

isExpression returns bool

argument

argument type

t

TypeDeclPtr

top

bool const

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

is_same_or_inherited(parent: ast::Structure? const; child: ast::Structure? const)

is_same_or_inherited returns bool const

argument

argument type

parent

ast::Structure ? const

child

ast::Structure ? const

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

is_class_method(cinfo: StructurePtr; finfo: TypeDeclPtr)

is_class_method returns bool const

argument

argument type

cinfo

StructurePtr

finfo

TypeDeclPtr

Returns true if field is a class method.

find_arg(argn: string const; args: AnnotationArgumentList const)

find_arg returns RttiValue

Warning

This function is deprecated.

argument

argument type

argn

string const

args

rtti::AnnotationArgumentList const

Find argument in annotation argument list.

find_arg(args: AnnotationArgumentList const; argn: string const)

find_arg returns RttiValue

argument

argument type

args

rtti::AnnotationArgumentList const

argn

string const

Find argument in annotation argument list.

find_unique_function(mod: rtti::Module? const; name: string const; canfail: bool const)

find_unique_function returns smart_ptr< ast::Function >

argument

argument type

mod

rtti::Module ? const

name

string const

canfail

bool const

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

find_unique_generic(mod: rtti::Module? const; name: string const; canfail: bool const)

find_unique_generic returns smart_ptr< ast::Function >

argument

argument type

mod

rtti::Module ? const

name

string const

canfail

bool const

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

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

find_annotation returns rtti::Annotation const?

argument

argument type

mod_name

string const

ann_name

string const

Finds annotation in the module.

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

get_for_source_index returns int

argument

argument type

expr

smart_ptr< ast::ExprFor > const

svar

VariablePtr

Find index of the for loop source variable.

get_for_source_index(expr: smart_ptr<ast::ExprFor> const; source: ExpressionPtr)

get_for_source_index returns int

argument

argument type

expr

smart_ptr< ast::ExprFor > const

source

ExpressionPtr

Find index of the for loop source variable.

isCMRES(fun: FunctionPtr)

isCMRES returns bool

argument

argument type

fun

FunctionPtr

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

isCMRES(fun: ast::Function? const)

isCMRES returns bool

argument

argument type

fun

ast::Function ? const

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

isMakeLocal(expr: ExpressionPtr)

isMakeLocal returns bool

argument

argument type

expr

ExpressionPtr

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

get_workhorse_types()

get_workhorse_types returns rtti::Type [30]

Returns array which contains all workhorse base types.

find_argument_index(typ: TypeDeclPtr; name: string const)

find_argument_index returns int

argument

argument type

typ

TypeDeclPtr

name

string const

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

isCMRESType(blockT: TypeDeclPtr)

isCMRESType returns bool

argument

argument type

blockT

TypeDeclPtr

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

getVectorElementCount(bt: Type const)

getVectorElementCount returns int const

argument

argument type

bt

rtti::Type const

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

getVectorElementSize(bt: Type const)

getVectorElementSize returns int const

argument

argument type

bt

rtti::Type const

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

getVectorElementType(bt: Type const)

getVectorElementType returns rtti::Type const

argument

argument type

bt

rtti::Type const

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

getVectorOffset(bt: Type const; ident: string const)

getVectorOffset returns int

argument

argument type

bt

rtti::Type const

ident

string const

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

13.9. Annotations

append_annotation(mod_name: string const; ann_name: string const; 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>>> const)

append_annotation returns smart_ptr< rtti::AnnotationDeclaration >

argument

argument type

mod_name

string const

ann_name

string const

args

array<tuple<argname:string;argvalue: RttiValue >> const

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

append_annotation(mod_name: string const; ann_name: string const)

append_annotation returns smart_ptr< rtti::AnnotationDeclaration >

argument

argument type

mod_name

string const

ann_name

string const

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

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

argument

argument type

func

FunctionPtr

mod_name

string const

ann_name

string const

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

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

argument

argument type

blk

smart_ptr< ast::ExprBlock >

mod_name

string const

ann_name

string const

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

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

argument

argument type

st

smart_ptr< ast::Structure >

mod_name

string const

ann_name

string const

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

append_annotation(func: FunctionPtr; mod_name: string const; ann_name: string const; 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>>> const)

argument

argument type

func

FunctionPtr

mod_name

string const

ann_name

string const

args

array<tuple<argname:string;argvalue: RttiValue >> const

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

append_annotation(blk: smart_ptr<ast::ExprBlock>; mod_name: string const; ann_name: string const; 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>>> const)

argument

argument type

blk

smart_ptr< ast::ExprBlock >

mod_name

string const

ann_name

string const

args

array<tuple<argname:string;argvalue: RttiValue >> const

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

append_annotation(st: smart_ptr<ast::Structure>; mod_name: string const; ann_name: string const; 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>>> const)

argument

argument type

st

smart_ptr< ast::Structure >

mod_name

string const

ann_name

string const

args

array<tuple<argname:string;argvalue: RttiValue >> const

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

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

add_annotation_argument returns int const

argument

argument type

arguments

rtti::AnnotationArgumentList

argName

string const

val

bool const

Adds annotation argument to the argument list.

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

add_annotation_argument returns int const

argument

argument type

arguments

rtti::AnnotationArgumentList

argName

string const

val

int const

Adds annotation argument to the argument list.

add_annotation_argument(arguments: AnnotationArgumentList; argName: string const; val: float const)

add_annotation_argument returns int const

argument

argument type

arguments

rtti::AnnotationArgumentList

argName

string const

val

float const

Adds annotation argument to the argument list.

add_annotation_argument(arguments: AnnotationArgumentList; argName: string const; val: string const)

add_annotation_argument returns int const

argument

argument type

arguments

rtti::AnnotationArgumentList

argName

string const

val

string const

Adds annotation argument to the argument list.

add_annotation_argument(arguments: AnnotationArgumentList; ann: AnnotationArgument const)

add_annotation_argument returns int const

argument

argument type

arguments

rtti::AnnotationArgumentList

ann

rtti::AnnotationArgument const

Adds annotation argument to the argument list.

13.10. Expression generation

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

override_method returns bool

argument

argument type

str

StructurePtr

name

string const

funcName

string const

Override class method name with new function.

panic_expr_as()

panic_expr_as returns void?

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

make_static_assert_false(text: string const; at: LineInfo const)

make_static_assert_false returns smart_ptr< ast::ExprStaticAssert >

argument

argument type

text

string const

at

rtti::LineInfo const

Creates static_assert(false,text) expression.

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

convert_to_expression returns auto

argument

argument type

value

auto&!

at

rtti::LineInfo const

Converts value to expression, which generates this value.

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

convert_to_expression returns auto

argument

argument type

value

auto const!

at

rtti::LineInfo const

Converts value to expression, which generates this value.

convert_to_expression(value: auto ==const)

convert_to_expression returns auto

argument

argument type

value

auto!

Converts value to expression, which generates this value.

convert_to_expression(value: auto const ==const)

convert_to_expression returns auto

argument

argument type

value

auto const!

Converts value to expression, which generates this value.

13.11. Visitors

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

argument

argument type

blk

ast::ExprBlock ? const

adapter

smart_ptr< ast::VisitorAdapter > const

Calls visitor on the finally section of the block.

13.12. Type generation

function_to_type(fn: FunctionPtr)

function_to_type returns TypeDeclPtr

argument

argument type

fn

FunctionPtr

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

13.13. Setup

setup_call_list(name: string const; at: LineInfo const; subblock: block<(var fn:smart_ptr<ast::Function> -const):void> const)

setup_call_list returns ast::ExprBlock ?

argument

argument type

name

string const

at

rtti::LineInfo const

subblock

block<(fn: FunctionPtr ):void> const

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

setup_call_list(name: string const; at: LineInfo const; isInit: bool const; isPrivate: bool const; isLateInit: bool const)

setup_call_list returns ast::ExprBlock ?

argument

argument type

name

string const

at

rtti::LineInfo const

isInit

bool const

isPrivate

bool const

isLateInit

bool const

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

setup_macro(name: string const; at: LineInfo const)

setup_macro returns ast::ExprBlock ?

argument

argument type

name

string const

at

rtti::LineInfo const

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.

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

setup_tag_annotation returns auto

argument

argument type

name

string const

tag

string const

classPtr

auto const

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