32. Template application helpers
The templates boost module implements collection of helper macros and functions to accompany AST.
All functions and symbols are in “templates_boost” module, use require to get access to it.
require daslib/templates_boost
32.1. Structures
- Template
This structure contains collection of subsitution rules for a template.
- Fields
kaboomVar : table<string;tuple<prefix:string;suffix:string>> - variable field access replacement rules
call2name : table<string;string> - call name replacement rules
field2name : table<string;string> - field name replacement rules
var2name : table<string;string> - variable name replacement rules
var2expr : table<string;smart_ptr< Expression >> - variable expression replacement rules
var2exprList : table<string;array<smart_ptr< Expression >>> - variable expression list replacement rules
type2type : table<string;string> - type name replacement rules
type2etype : table<string; TypeDeclPtr > - type to type declaration replacement rules
struct2etype : table< Structure ?; TypeDeclPtr > - structure to type declaration replacement rules
blockArgName : table<string;string> - block argument name replacement rules
annArg : table<string;lambda<(ann: AnnotationDeclaration ):void>> - annotation argument replacement rules
blkArg : table<string;array< VariablePtr >> - block argument replacement rules
tag2expr : table<string;smart_ptr< Expression >> - tag expression replacement rules
32.2. Call macros
- qmacro_variable
This macro implements expression reification for variables.
- qmacro_expr
This macro implements first line of the expression block reification ‘qmacro_expr’
- qmacro_function
This macro implements expression reification for functions.
- qmacro_block_to_array
This macro implements expression block to array reification ‘qmacro_block_to_array’
- qmacro_template_class
This macro implements expression reification for the named expressions (function, variable, etc.)
- qmacro_method
This macro implements expression reification for class methods.
- qmacro
This macro implements expression reification ‘qmacro’
- qmacro_block
This macro implements expression block reification ‘qmacro_block’
- qmacro_type
This macro implements type declaration reification ‘qmacro_type’
32.3. Template rules
kaboomVarField (var self: Template; name: string; prefix: string; suffix: string)
replaceVariable (var self: Template; name: string; var expr: smart_ptr<Expression>)
renameVariable (var self: Template; name: string; newName: string)
renameVariable (var self: Template; name: string; newName: das_string)
replaceType (var self: Template; name: string; newName: string)
replaceBlockArgument (var self: Template; name: string; newName: string)
- kaboomVarField(self: Template; name: string; prefix: string; suffix: string)
Adds a rule to to the template to replace a variable field access with a prefix and suffix. I.e. foo.bar into prefix + bar + suffix
- Arguments
self : Template
name : string
prefix : string
suffix : string
- replaceVariable(self: Template; name: string; expr: smart_ptr<Expression>)
Adds a rule to the template to replace a variable with an expression.
- Arguments
self : Template
name : string
expr : smart_ptr< Expression >
- renameVariable(self: Template; name: string; newName: string)
Adds a rule to the template to rename a variable.
- Arguments
self : Template
name : string
newName : string
- renameVariable(self: Template; name: string; newName: das_string)
Adds a rule to the template to rename a variable.
- Arguments
self : Template
name : string
newName : das_string
- replaceType(self: Template; name: string; newName: string)
Adds a rule to the template to replace a type alias with another type alias, specified by name.
- Arguments
self : Template
name : string
newName : string
- replaceAnnotationArgument(self: Template; name: string; cb: lambda<(var ann:AnnotationDeclaration):void>)
Adds a rule to the template to replace an annotation argument with the result of a callback.
- Arguments
self : Template
name : string
cb : lambda<(ann: AnnotationDeclaration ):void>
- replaceBlockArgument(self: Template; name: string; newName: string)
Adds a rule to the template to rename a block argument.
- Arguments
self : Template
name : string
newName : string
32.4. Template application
- apply_template(rules: Template; at: LineInfo; expr: smart_ptr<Expression>; forceAt: bool = true) : ExpressionPtr()
Applies the template to the given expression. If forceAt is set, the resulting expression will have the same line info as ‘at’.
- Arguments
rules : Template
at : LineInfo
expr : smart_ptr< Expression >
forceAt : bool
- apply_template(rules: Template; at: LineInfo; typ: smart_ptr<TypeDecl>; forceAt: bool = true) : TypeDeclPtr()
Applies the template to the given expression. If forceAt is set, the resulting expression will have the same line info as ‘at’.
- apply_template(at: LineInfo; typ: smart_ptr<TypeDecl>&; blk: block<(var rules:Template):void>) : TypeDeclPtr()
Applies the template to the given type declaration. If forceAt is set, the resulting type declaration will have the same line info as ‘at’.
- apply_template(at: LineInfo; expr: smart_ptr<Expression>&; blk: block<(var rules:Template):void>) : ExpressionPtr()
Applies the template to the given expression. If forceAt is set, the resulting expression will have the same line info as ‘at’.
- Arguments
at : LineInfo
expr : smart_ptr< Expression >&
blk : block<(rules: Template ):void>
- apply_template(expr: smart_ptr<Expression>&; blk: block<(var rules:Template):void>) : ExpressionPtr()
Applies the template to the given expression.
- Arguments
expr : smart_ptr< Expression >&
blk : block<(rules: Template ):void>
32.5. Expression helpers
- remove_deref(varname: string; expr: smart_ptr<Expression>)
Removes dereferences of the variable varname from the expression. This is typically used when replacing ‘workhorse’ variable with constant.
- Arguments
varname : string
expr : smart_ptr< Expression >
32.6. Block helpers
- unquote_block(expr: ExpressionPtr) : smart_ptr<ExprBlock>()
Returns the corresponding block subexpression expression form the ExprMakeBlock.
- Arguments
expr : ExpressionPtr
- move_unquote_block(expr: ExpressionPtr) : smart_ptr<ExprBlock>()
Moves the corresponding block subexpression expression form the ExprMakeBlock.
- Arguments
expr : ExpressionPtr
32.7. Global variable helpers
add_global_var (mod: Module?; vname: string; vat: LineInfo; var value: ExpressionPtr) : bool
add_global_var (mod: Module?; vname: string; var typ: TypeDeclPtr; vat: LineInfo; priv: bool) : bool
add_global_let (mod: Module?; vname: string; vat: LineInfo; var value: ExpressionPtr) : bool
add_global_private_var (mod: Module?; vname: string; vat: LineInfo; var value: ExpressionPtr) : bool
add_global_private_let (mod: Module?; vname: string; vat: LineInfo; var value: ExpressionPtr) : bool
- add_global_var(mod: Module?; vname: string; vat: LineInfo; value: ExpressionPtr) : bool()
Adds global variable to the module, given name and initial value. Global variables type is would be inferred from the initial value. priv specifies if the variable is private to the block.
- Arguments
mod : Module ?
vname : string
vat : LineInfo
value : ExpressionPtr
- add_global_var(mod: Module?; vname: string; typ: TypeDeclPtr; vat: LineInfo; priv: bool; blk: block<(var v:VariablePtr):void>) : bool()
Add global variable to the module, given name and type. priv specifies if the variable is private to the block.
- Arguments
mod : Module ?
vname : string
typ : TypeDeclPtr
vat : LineInfo
priv : bool
blk : block<(v: VariablePtr ):void>
- add_global_var(mod: Module?; vname: string; typ: TypeDeclPtr; vat: LineInfo; priv: bool) : bool()
Add global variable to the module, given name and type.
- Arguments
mod : Module ?
vname : string
typ : TypeDeclPtr
vat : LineInfo
priv : bool
- add_global_let(mod: Module?; vname: string; vat: LineInfo; value: ExpressionPtr) : bool()
Add global variable to the module, given name and initial value. Variable type will be constant.
- Arguments
mod : Module ?
vname : string
vat : LineInfo
value : ExpressionPtr
- add_global_private_var(mod: Module?; vname: string; vat: LineInfo; value: ExpressionPtr) : bool()
Add global variable to the module, given name and initial value. It will be private.
- Arguments
mod : Module ?
vname : string
vat : LineInfo
value : ExpressionPtr
- add_global_private_let(mod: Module?; vname: string; vat: LineInfo; value: ExpressionPtr) : bool()
Add global variable to the module, given name and initial value. It will be private, and type will be constant.
- Arguments
mod : Module ?
vname : string
vat : LineInfo
value : ExpressionPtr
32.8. Hygenic names
- make_unique_private_name(prefix: string; vat: LineInfo) : string()
Generates unique private name for the variable, given prefix and line info.
The assumption is that line info is unique for the context of the unique name generation. If it is not, additional measures must be taken to ensure uniqueness of prefix.
- Arguments
prefix : string
vat : LineInfo
32.9. Uncategorized
- replaceVarTag(self: Template; name: string; expr: smart_ptr<Expression>)
Adds a rule to the template to replace a variable tag with an expression.
- Arguments
self : Template
name : string
expr : smart_ptr< Expression >
- replaceArgumentWithList(self: Template; name: string; blka: array<VariablePtr>)
Adds a rule to the template to replace a block argument with a list of variables.
- Arguments
self : Template
name : string
blka : array< VariablePtr >
- replaceVariableWithList(self: Template; name: string; expr: array<ExpressionPtr>)
Adds a rule to the template to replace a variable with an expression list.
- Arguments
self : Template
name : string
expr : array< ExpressionPtr >
- replaceVariableWithList(self: Template; name: string; expr: dasvector`smart_ptr`Expression)
Adds a rule to the template to replace a variable with an expression list.
- Arguments
self : Template
name : string
expr : vector<smart_ptr<Expression>>
- renameField(self: Template; name: string; newName: string)
Adds a rule to the template to rename any field lookup (., ?., as, is, etc)
- Arguments
self : Template
name : string
newName : string
- renameField(self: Template; name: string; newName: das_string)
Adds a rule to the template to rename any field lookup (., ?., as, is, etc)
- Arguments
self : Template
name : string
newName : das_string
- replaceStructWithTypeDecl(self: Template; pstruct: Structure?; expr: TypeDeclPtr)
Adds a rule to the template to replace a type alias with another type alias, specified by type declaration.
- Arguments
self : Template
pstruct : Structure ?
expr : TypeDeclPtr
- replaceTypeWithTypeDecl(self: Template; name: string; expr: TypeDeclPtr)
Adds a rule to the template to replace a type alias with another type alias, specified by type declaration.
- Arguments
self : Template
name : string
expr : TypeDeclPtr
- renameCall(self: Template; name: string; newName: string)
Adds a rule to the template to rename a call.
- Arguments
self : Template
name : string
newName : string
- renameCall(self: Template; name: string; newName: das_string)
Adds a rule to the template to rename a call.
- Arguments
self : Template
name : string
newName : das_string
- visit_expression(expr: ExpressionPtr; adapter: smart_ptr<VisitorAdapter>)
Visits the expression with the given visitor adapter.
- Arguments
expr : ExpressionPtr
adapter : smart_ptr< VisitorAdapter >
- make_expression_block(exprs: array<ExpressionPtr>) : smart_ptr<ExprBlock>()
Create ExprBlock and move all expressions from expr to the list of the block.
- Arguments
exprs : array< ExpressionPtr >
- make_expression_block(exprs: dasvector`smart_ptr`Expression) : smart_ptr<ExprBlock>()
Create ExprBlock and move all expressions from expr to the list of the block.
- Arguments
exprs : vector<smart_ptr<Expression>>
- add_type_ptr_ref(a: TypeDeclPtr; flags: TypeDeclFlags) : TypeDeclPtr()
Implementation details for the reification. This adds any array to the rules.
- Arguments
a : TypeDeclPtr
flags : TypeDeclFlags
- add_type_ptr_ref(st: StructurePtr; flags: TypeDeclFlags) : TypeDeclPtr()
Implementation details for the reification. This adds any array to the rules.
- Arguments
st : StructurePtr
flags : TypeDeclFlags
- add_type_ptr_ref(st: Structure?; flags: TypeDeclFlags) : TypeDeclPtr()
Implementation details for the reification. This adds any array to the rules.
- Arguments
st : Structure ?
flags : TypeDeclFlags
- add_type_ptr_ref(st: EnumerationPtr; flags: TypeDeclFlags) : TypeDeclPtr()
Implementation details for the reification. This adds any array to the rules.
- Arguments
st : EnumerationPtr
flags : TypeDeclFlags
- add_type_ptr_ref(st: Enumeration?; flags: TypeDeclFlags) : TypeDeclPtr()
Implementation details for the reification. This adds any array to the rules.
- Arguments
st : Enumeration ?
flags : TypeDeclFlags
- apply_qmacro(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void>) : ExpressionPtr()
Implementation details for the expression reificaiton. This is a generat expression reification.
- Arguments
expr : smart_ptr< Expression >
blk : block<(rules: Template ):void>
- apply_qblock(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void>) : ExpressionPtr()
Implementation details for the expression reificaiton. This is a block reification.
- Arguments
expr : smart_ptr< Expression >
blk : block<(rules: Template ):void>
- apply_qblock_to_array(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void>) : array<ExpressionPtr>()
Implementation details for the expression reificaiton. This is a block reification.
- Arguments
expr : smart_ptr< Expression >
blk : block<(rules: Template ):void>
- apply_qblock_expr(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void>) : ExpressionPtr()
Implementation details for the expression reificaiton. This is a frist line of the block as expression reification.
- Arguments
expr : smart_ptr< Expression >
blk : block<(rules: Template ):void>
- apply_qtype(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void>) : TypeDeclPtr()
Implementation details for the expression reificaiton. This is a type declaration reification.
- Arguments
expr : smart_ptr< Expression >
blk : block<(rules: Template ):void>
- expression_at(expr: ExpressionPtr; at: LineInfo) : ExpressionPtr()
Force expression location, than return it.
- Arguments
expr : ExpressionPtr
at : LineInfo
- apply_qmacro_function(fname: string; expr: smart_ptr<Expression>; blk: block<(var rules:Template):void>) : FunctionPtr()
Implementation details for reification. This is a function generation reification.
- Arguments
fname : string
expr : smart_ptr< Expression >
blk : block<(rules: Template ):void>
- apply_qmacro_method(fname: string; parent: StructurePtr; expr: smart_ptr<Expression>; blk: block<(var rules:Template):void>) : FunctionPtr()
Implementation details for reification. This is a class method function generation reification.
- Arguments
fname : string
parent : StructurePtr
expr : smart_ptr< Expression >
blk : block<(rules: Template ):void>
- apply_qmacro_variable(vname: string; expr: smart_ptr<Expression>; blk: block<(var rules:Template):void>) : VariablePtr()
Implementation details for reification. This is a variable generation reification.
- Arguments
vname : string
expr : smart_ptr< Expression >
blk : block<(rules: Template ):void>
- apply_qmacro_template_class(instance_name: string; template_type: smart_ptr<TypeDecl>; blk: block<(var rules:Template):void>) : TypeDeclPtr()
Implementation details for the expression reificaiton. This is a template class instantiation reification.
- Arguments
- add_structure_field(cls: StructurePtr; name: string; t: TypeDeclPtr; init: ExpressionPtr) : int()
Adds a field to the structure.
- Arguments
cls : StructurePtr
name : string
t : TypeDeclPtr
init : ExpressionPtr
- make_class(name: string; mod: Module?) : smart_ptr<Structure>()
Creates a class structure. Adds __rtti, __finalize fields.
- Arguments
name : string
mod : Module ?
- make_class(name: string; baseClass: StructurePtr; mod: Module?) : smart_ptr<Structure>()
Creates a class structure derived from baseClass. Adds __rtti, __finalize fields.
- Arguments
name : string
baseClass : StructurePtr
mod : Module ?
- make_class(name: string; baseClass: Structure?; mod: Module?) : smart_ptr<Structure>()
Creates a class structure derived from baseClass. Adds __rtti, __finalize fields.
- make_class_constructor(cls: StructurePtr; ctor: FunctionPtr) : smart_ptr<Function>()
Adds a class constructor from a constructor function.
- Arguments
cls : StructurePtr
ctor : FunctionPtr
- modify_to_class_member(cls: StructurePtr; fun: FunctionPtr; isExplicit: bool; Constant: bool)
Modifies function to be a member of a particular class.
- Arguments
cls : StructurePtr
fun : FunctionPtr
isExplicit : bool
Constant : bool
- add_array_ptr_ref(a: array<smart_ptr<auto(TT)>>) : array<smart_ptr<TT>>()
Implementation details for the reification. This adds any array to the rules.
- Arguments
a : array<smart_ptr<auto(TT)>>
- enum_class_type(st: auto) : auto()
return underlying type for the enumeration
- Arguments
st : auto
- add_type_ptr_ref(anything: auto(TT); flags: TypeDeclFlags) : TypeDeclPtr()
Implementation details for the reification. This adds any array to the rules.
- Arguments
anything : auto(TT)
flags : TypeDeclFlags