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. Function annotations

macro

MacroMacro function annotation.

tag_function

TagFunctionAnnotation function annotation.

13.2. 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.3. 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).

SetupFunctionAnnotatoin : SetupAnyAnnotation

[function_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupBlockAnnotatoin : SetupAnyAnnotation

[block_macro] implementation.

it defines as follows

annotation_function_call : string
name : string
SetupStructureAnnotatoin : SetupAnyAnnotation

[structure_macro] implementation.

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
SetupContractAnnotatoin : SetupAnyAnnotation

[contract] implementation.

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
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.4. Containers

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

argument

argument type

vec

builtin::dasvector`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

builtin::dasvector`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

builtin::dasvector`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.5. Textual descriptions of the objects

describe(list: AnnotationArgumentList const)

describe returns string const

argument

argument type

list

rtti::AnnotationArgumentList const

Returns textuan description of the object.

describe(ann: AnnotationDeclaration const)

describe returns string

argument

argument type

ann

rtti::AnnotationDeclaration const

Returns textuan description of the object.

describe(list: AnnotationList const)

describe returns string const

argument

argument type

list

rtti::AnnotationList const

Returns textuan 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.

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.6. 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

argument

argument type

argn

string const

args

rtti::AnnotationArgumentList 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 const

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 const

argument

argument type

expr

smart_ptr< ast::ExprFor > const

source

ExpressionPtr

Find index of the for loop source variable.

13.7. Annotations

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.

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.

13.8. 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&; 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.

13.9. Setup

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

setup_call_list returns ast::ExprBlock ?

argument

argument type

name

string const

at

rtti::LineInfo const

isInit

bool const

isPrivate

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.