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
-
Template
¶
Template fields are
kaboomVar |
table<string;tuple<prefix:string;suffix:string>> |
call2name |
table<string;string> |
field2name |
table<string;string> |
var2name |
table<string;string> |
var2expr |
table<string;smart_ptr< ast::Expression >> |
var2exprList |
table<string;array<smart_ptr< ast::Expression >>> |
type2type |
table<string;string> |
type2etype |
table<string; TypeDeclPtr > |
blockArgName |
table<string;string> |
annArg |
table<string;lambda<(ann: rtti::AnnotationDeclaration ):void>> |
blkArg |
table<string;array< VariablePtr >> |
tag2expr |
table<string;smart_ptr< ast::Expression >> |
This structure contains collection of subsitution rules for a template.
32.1. Call macros¶
-
qmacro_expr
¶
This macro implements qmacro_expr expression reification. Expected input is a block expression (ExprMakeBlock over ExprBlock). It applies reification rules to the expression, and returns first expression in the block. .. _call-macro-templates_boost-qmacro_variable:
-
qmacro_variable
¶
This macro implements qmacro_variable expression reification. Expected input is are variable name and type expression (type<…>). Result is a new VariablePtr with the matching name and type. .. _call-macro-templates_boost-qmacro_block_to_array:
-
qmacro_block_to_array
¶
This macro implements qmacro_block_to_array expression reification. Expected input is a block expression (ExprMakeBlock over ExprBlock). It applies reification rules to the expression, and returns array with contents of the ‘list’ section of the block.
-
qmacro_function
¶
This macro implements qmacro_function expression reification. Expected input is a block expression (ExprMakeBlock over ExprBlock). It applies reification rules to the expression, and returns a FunctionPtr. New function matches block signature, as well as the block body. .. _call-macro-templates_boost-qmacro:
-
qmacro
¶
This macro implements qmacro expression reification. It applies reification rules to the expression, and returns direct result of the substitution.
-
qmacro_method
¶
This macro implements expression reification for class methods.
-
qmacro_block
¶
This macro implements qmacro_block expression reification. Expected input is a block expression (ExprMakeBlock over ExprBlock). It applies reification rules to the expression, and returns unquoted ExprBlock. .. _call-macro-templates_boost-qmacro_type:
-
qmacro_type
¶
This macro implements qmacro_type expression reification. Expected input is a type expression (type<…>). Result is TypeDeclPtr of a new type matching subtype of the type expression.
32.2. Template rules¶
-
kaboomVarField
(self: Template; name: string const; prefix: string const; suffix: string const)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
prefix |
string const |
suffix |
string const |
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
-
replaceVariable
(self: Template; name: string const; expr: smart_ptr<Expression>)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
expr |
smart_ptr< ast::Expression > |
Adds a rule to the template to replace a variable with an expression.
-
renameVariable
(self: Template; name: string const; newName: string const)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
newName |
string const |
Adds a rule to the template to rename a variable.
-
renameVariable
(self: Template; name: string const; newName: das_string const)
argument |
argument type |
---|---|
self |
|
name |
string const |
newName |
builtin::das_string const |
Adds a rule to the template to rename a variable.
-
replaceType
(self: Template; name: string const; newName: string const)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
newName |
string const |
Adds a rule to the template to replace a type alias with another type alias, specified by name.
-
replaceAnnotationArgument
(self: Template; name: string const; cb: lambda<(var ann:AnnotationDeclaration):void>)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
cb |
lambda<(ann: rtti::AnnotationDeclaration ):void> |
Adds a rule to the template to replace an annotation argument with the result of a callback.
-
replaceBlockArgument
(self: Template; name: string const; newName: string const)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
newName |
string const |
Adds a rule to the template to rename a block argument.
32.3. Template application¶
-
apply_template
(rules: Template; at: LineInfo const; expr: smart_ptr<Expression>; forceAt: bool const)¶
apply_template returns ExpressionPtr
argument |
argument type |
---|---|
rules |
|
at |
rtti::LineInfo const |
expr |
smart_ptr< ast::Expression > |
forceAt |
bool const |
TODO: figure out why this is needed
-
apply_template
(at: LineInfo const; expr: smart_ptr<Expression>&; blk: block<(var rules:Template):void> const)
apply_template returns ExpressionPtr
argument |
argument type |
---|---|
at |
rtti::LineInfo const |
expr |
smart_ptr< ast::Expression >& |
blk |
block<(rules: templates_boost::Template ):void> const |
TODO: figure out why this is needed
-
apply_template
(expr: smart_ptr<Expression>&; blk: block<(var rules:Template):void> const)
apply_template returns ExpressionPtr
argument |
argument type |
---|---|
expr |
smart_ptr< ast::Expression >& |
blk |
block<(rules: templates_boost::Template ):void> const |
TODO: figure out why this is needed
32.4. Expression helpers¶
-
remove_deref
(varname: string const; expr: smart_ptr<Expression>)¶
argument |
argument type |
---|---|
varname |
string const |
expr |
smart_ptr< ast::Expression > |
Removes dereferences of the variable varname from the expression. This is typically used when replacing ‘workhorse’ variable with constant.
32.5. Block helpers¶
-
unquote_block
(expr: ExpressionPtr)¶
unquote_block returns smart_ptr< ast::ExprBlock >
argument |
argument type |
---|---|
expr |
|
Returns the corresponding block subexpression expression form the ExprMakeBlock.
-
move_unquote_block
(expr: ExpressionPtr)¶
move_unquote_block returns smart_ptr< ast::ExprBlock >
argument |
argument type |
---|---|
expr |
|
Moves the corresponding block subexpression expression form the ExprMakeBlock.
32.6. Global variable helpers¶
-
add_global_var
(mod: Module? const; vname: string const; vat: LineInfo const; value: ExpressionPtr)¶
add_global_var returns bool
argument |
argument type |
---|---|
mod |
rtti::Module ? const |
vname |
string const |
vat |
rtti::LineInfo const |
value |
|
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.
-
add_global_var
(mod: Module? const; vname: string const; typ: TypeDeclPtr; vat: LineInfo const; priv: bool const; blk: block<(var v:smart_ptr<Variable>):void> const)
add_global_var returns bool
argument |
argument type |
---|---|
mod |
rtti::Module ? const |
vname |
string const |
typ |
|
vat |
rtti::LineInfo const |
priv |
bool const |
blk |
block<(v: VariablePtr ):void> const |
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.
-
add_global_var
(mod: Module? const; vname: string const; typ: TypeDeclPtr; vat: LineInfo const; priv: bool const)
add_global_var returns bool
argument |
argument type |
---|---|
mod |
rtti::Module ? const |
vname |
string const |
typ |
|
vat |
rtti::LineInfo const |
priv |
bool const |
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.
-
add_global_let
(mod: Module? const; vname: string const; vat: LineInfo const; value: ExpressionPtr)¶
add_global_let returns bool
argument |
argument type |
---|---|
mod |
rtti::Module ? const |
vname |
string const |
vat |
rtti::LineInfo const |
value |
|
Add global variable to the module, given name and initial value. Variable type will be constant.
-
add_global_private_var
(mod: Module? const; vname: string const; vat: LineInfo const; value: ExpressionPtr)¶
add_global_private_var returns bool
argument |
argument type |
---|---|
mod |
rtti::Module ? const |
vname |
string const |
vat |
rtti::LineInfo const |
value |
|
Add global variable to the module, given name and initial value. It will be private.
-
add_global_private_let
(mod: Module? const; vname: string const; vat: LineInfo const; value: ExpressionPtr)¶
add_global_private_let returns bool
argument |
argument type |
---|---|
mod |
rtti::Module ? const |
vname |
string const |
vat |
rtti::LineInfo const |
value |
|
Add global variable to the module, given name and initial value. It will be private, and type will be constant.
32.7. Hygenic names¶
-
make_unique_private_name
(prefix: string const; vat: LineInfo const)¶
make_unique_private_name returns string
argument |
argument type |
---|---|
prefix |
string const |
vat |
rtti::LineInfo const |
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.
32.8. Uncategorized¶
-
replaceVarTag
(self: Template; name: string const; expr: smart_ptr<Expression>)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
expr |
smart_ptr< ast::Expression > |
Adds a rule to the template to replace a variable tag with an expression.
-
replaceArgumentWithList
(self: Template; name: string const; blka: array<smart_ptr<Variable>> const)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
blka |
array< VariablePtr > const |
Adds a rule to the template to replace a block argument with a list of variables.
-
replaceVariableWithList
(self: Template; name: string const; expr: array<smart_ptr<Expression>> const)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
expr |
array< ExpressionPtr > const |
Adds a rule to the template to replace a variable with an expression list.
-
replaceVariableWithList
(self: Template; name: string const; expr: dasvector`smart_ptr`Expression const)
argument |
argument type |
---|---|
self |
|
name |
string const |
expr |
vector<smart_ptr<Expression>> const |
Adds a rule to the template to replace a variable with an expression list.
-
renameField
(self: Template; name: string const; newName: string const)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
newName |
string const |
Adds a rule to the template to rename any field lookup (., ?., as, is, etc)
-
renameField
(self: Template; name: string const; newName: das_string const)
argument |
argument type |
---|---|
self |
|
name |
string const |
newName |
builtin::das_string const |
Adds a rule to the template to rename any field lookup (., ?., as, is, etc)
-
replaceTypeWithTypeDecl
(self: Template; name: string const; expr: TypeDeclPtr)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
expr |
|
Adds a rule to the template to replace a type alias with another type alias, specified by type declaration.
-
renameCall
(self: Template; name: string const; newName: string const)¶
argument |
argument type |
---|---|
self |
|
name |
string const |
newName |
string const |
Adds a rule to the template to rename a call.
-
renameCall
(self: Template; name: string const; newName: das_string const)
argument |
argument type |
---|---|
self |
|
name |
string const |
newName |
builtin::das_string const |
Adds a rule to the template to rename a call.
-
make_expression_block
(exprs: array<smart_ptr<Expression>>)¶
make_expression_block returns smart_ptr< ast::ExprBlock >
argument |
argument type |
---|---|
exprs |
array< ExpressionPtr > |
Create ExprBlock and move all expressions from expr to the list of the block.
-
make_expression_block
(exprs: dasvector`smart_ptr`Expression)
make_expression_block returns smart_ptr< ast::ExprBlock >
argument |
argument type |
---|---|
exprs |
vector<smart_ptr<Expression>> |
Create ExprBlock and move all expressions from expr to the list of the block.
-
add_type_ptr_ref
(a: TypeDeclPtr; flags: TypeDeclFlags)¶
add_type_ptr_ref returns TypeDeclPtr
argument |
argument type |
---|---|
a |
|
flags |
|
Implementation details for the reification. This adds any array to the rules.
-
add_type_ptr_ref
(st: StructurePtr; flags: TypeDeclFlags)
add_type_ptr_ref returns TypeDeclPtr
argument |
argument type |
---|---|
st |
|
flags |
|
Implementation details for the reification. This adds any array to the rules.
-
add_type_ptr_ref
(st: Structure?; flags: TypeDeclFlags)
add_type_ptr_ref returns TypeDeclPtr
argument |
argument type |
---|---|
st |
|
flags |
|
Implementation details for the reification. This adds any array to the rules.
-
add_type_ptr_ref
(st: EnumerationPtr; flags: TypeDeclFlags)
add_type_ptr_ref returns TypeDeclPtr
argument |
argument type |
---|---|
st |
|
flags |
|
Implementation details for the reification. This adds any array to the rules.
-
add_type_ptr_ref
(st: Enumeration?; flags: TypeDeclFlags)
add_type_ptr_ref returns TypeDeclPtr
argument |
argument type |
---|---|
st |
|
flags |
|
Implementation details for the reification. This adds any array to the rules.
-
apply_qmacro
(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void> const)¶
apply_qmacro returns ExpressionPtr
argument |
argument type |
---|---|
expr |
smart_ptr< ast::Expression > |
blk |
block<(rules: templates_boost::Template ):void> const |
Implementation details for the expression reificaiton. This is a generat expression reification.
-
apply_qblock
(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void> const)¶
apply_qblock returns ExpressionPtr
argument |
argument type |
---|---|
expr |
smart_ptr< ast::Expression > |
blk |
block<(rules: templates_boost::Template ):void> const |
Implementation details for the expression reificaiton. This is a block reification.
-
apply_qblock_to_array
(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void> const)¶
apply_qblock_to_array returns array< ExpressionPtr >
argument |
argument type |
---|---|
expr |
smart_ptr< ast::Expression > |
blk |
block<(rules: templates_boost::Template ):void> const |
Implementation details for the expression reificaiton. This is a block reification.
-
apply_qblock_expr
(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void> const)¶
apply_qblock_expr returns ExpressionPtr
argument |
argument type |
---|---|
expr |
smart_ptr< ast::Expression > |
blk |
block<(rules: templates_boost::Template ):void> const |
Implementation details for the expression reificaiton. This is a frist line of the block as expression reification.
-
apply_qtype
(expr: smart_ptr<Expression>; blk: block<(var rules:Template):void> const)¶
apply_qtype returns TypeDeclPtr
argument |
argument type |
---|---|
expr |
smart_ptr< ast::Expression > |
blk |
block<(rules: templates_boost::Template ):void> const |
Implementation details for the expression reificaiton. This is a type declaration reification.
-
expression_at
(expr: ExpressionPtr; at: LineInfo const)¶
expression_at returns ExpressionPtr
argument |
argument type |
---|---|
expr |
|
at |
rtti::LineInfo const |
Force expression location, than return it.
-
emplace_new
(arr: array<smart_ptr<Expression>>; expr: ExpressionPtr)¶
argument |
argument type |
---|---|
arr |
array< ExpressionPtr > |
expr |
|
Unifies emplace and emplace_new for the array<VariablePtr>
-
emplace_new
(arr: array<smart_ptr<Variable>>; expr: VariablePtr)
argument |
argument type |
---|---|
arr |
array< VariablePtr > |
expr |
|
Unifies emplace and emplace_new for the array<VariablePtr>
-
apply_qmacro_function
(fname: string const; expr: smart_ptr<Expression>; blk: block<(var rules:Template):void> const)¶
apply_qmacro_function returns FunctionPtr
argument |
argument type |
---|---|
fname |
string const |
expr |
smart_ptr< ast::Expression > |
blk |
block<(rules: templates_boost::Template ):void> const |
Implementation details for reification. This is a function generation reification.
-
apply_qmacro_method
(fname: string const; parent: StructurePtr; expr: smart_ptr<Expression>; blk: block<(var rules:Template):void> const)¶
apply_qmacro_method returns FunctionPtr
argument |
argument type |
---|---|
fname |
string const |
parent |
|
expr |
smart_ptr< ast::Expression > |
blk |
block<(rules: templates_boost::Template ):void> const |
Implementation details for reification. This is a class method function generation reification.
-
apply_qmacro_variable
(vname: string const; expr: smart_ptr<Expression>; blk: block<(var rules:Template):void> const)¶
apply_qmacro_variable returns VariablePtr
argument |
argument type |
---|---|
vname |
string const |
expr |
smart_ptr< ast::Expression > |
blk |
block<(rules: templates_boost::Template ):void> const |
Implementation details for reification. This is a variable generation reification.
-
add_structure_field
(cls: StructurePtr; name: string const; t: TypeDeclPtr; init: ExpressionPtr)¶
add_structure_field returns int const
argument |
argument type |
---|---|
cls |
|
name |
string const |
t |
|
init |
|
Adds a field to the structure.
-
make_class
(name: string const; mod: Module? const)¶
make_class returns smart_ptr< ast::Structure >
argument |
argument type |
---|---|
name |
string const |
mod |
rtti::Module ? const |
Creates a class structure. Adds __rtti, __finalize fields.
-
make_class
(name: string const; baseClass: StructurePtr; mod: Module? const)
make_class returns smart_ptr< ast::Structure >
argument |
argument type |
---|---|
name |
string const |
baseClass |
|
mod |
rtti::Module ? const |
Creates a class structure. Adds __rtti, __finalize fields.
-
make_class
(name: string const; baseClass: Structure? const; mod: Module? const)
make_class returns smart_ptr< ast::Structure >
argument |
argument type |
---|---|
name |
string const |
baseClass |
ast::Structure ? const |
mod |
rtti::Module ? const |
Creates a class structure. Adds __rtti, __finalize fields.
-
make_class_constructor
(cls: StructurePtr; ctor: FunctionPtr)¶
make_class_constructor returns smart_ptr< ast::Function >
argument |
argument type |
---|---|
cls |
|
ctor |
|
Adds a class constructor from a constructor function.
-
modify_to_class_member
(cls: StructurePtr; fun: FunctionPtr; isExplicit: bool const; Constant: bool const)¶
argument |
argument type |
---|---|
cls |
|
fun |
|
isExplicit |
bool const |
Constant |
bool const |
Modifies function to be a member of a particular class.
-
add_array_ptr_ref
(a: array<smart_ptr<auto(TT)>>)¶
add_array_ptr_ref returns array<smart_ptr<TT>>
argument |
argument type |
---|---|
a |
array<smart_ptr<auto(TT)>> |
Implementation details for the reification. This adds any array to the rules.
-
enum_class_type
(st: auto const)¶
enum_class_type returns auto
argument |
argument type |
---|---|
st |
auto const |
return underlying type for the enumeration
-
add_type_ptr_ref
(anything: auto(TT) const; flags: TypeDeclFlags)
add_type_ptr_ref returns TypeDeclPtr
argument |
argument type |
---|---|
anything |
auto(TT) const |
flags |
|
Implementation details for the reification. This adds any array to the rules.