Object templates starting to work, don't do methods properly yet, likely all have the same name
This commit is contained in:
@@ -18,7 +18,7 @@ adt ast_node {
|
||||
type_def: type_def,
|
||||
adt_def: adt_def,
|
||||
function: function,
|
||||
function_template: function_template,
|
||||
template: template,
|
||||
code_block: code_block,
|
||||
statement: statement,
|
||||
if_statement: if_statement,
|
||||
@@ -306,19 +306,19 @@ obj function (Object) {
|
||||
return name == name && type == other.type && parameters == other.parameters && body_statement == other.body_statement
|
||||
}
|
||||
}
|
||||
fun ast_function_template_ptr(name: string, syntax_node: *tree<symbol>, template_types: vector<string>, template_type_replacements: map<string, *type>): *ast_node {
|
||||
var to_ret.construct(name, syntax_node, template_types, template_type_replacements): function_template
|
||||
fun ast_template_ptr(name: string, syntax_node: *tree<symbol>, template_types: vector<string>, template_type_replacements: map<string, *type>, is_function: bool): *ast_node {
|
||||
var to_ret.construct(name, syntax_node, template_types, template_type_replacements, is_function): template
|
||||
var ptr = new<ast_node>()
|
||||
ptr->copy_construct(&ast_node::function_template(to_ret))
|
||||
ptr->copy_construct(&ast_node::template(to_ret))
|
||||
return ptr
|
||||
}
|
||||
fun is_function_template(node: *ast_node): bool {
|
||||
fun is_template(node: *ast_node): bool {
|
||||
match(*node) {
|
||||
ast_node::function_template(backing) return true
|
||||
ast_node::template(backing) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
obj function_template (Object) {
|
||||
obj template (Object) {
|
||||
var name: string
|
||||
var syntax_node: *tree<symbol>
|
||||
var instantiated: vector<*ast_node>
|
||||
@@ -326,7 +326,8 @@ obj function_template (Object) {
|
||||
var template_type_replacements: map<string, *type>
|
||||
var instantiated_map: map<vector<type>, *ast_node>
|
||||
var scope: map<string, vector<*ast_node>>
|
||||
fun construct(name_in: string, syntax_node_in: *tree<symbol>, template_types_in: vector<string>, template_type_replacements_in: map<string, *type>): *function_template {
|
||||
var is_function: bool
|
||||
fun construct(name_in: string, syntax_node_in: *tree<symbol>, template_types_in: vector<string>, template_type_replacements_in: map<string, *type>, is_function: bool): *template {
|
||||
name.copy_construct(&name_in)
|
||||
syntax_node = syntax_node_in
|
||||
instantiated.construct()
|
||||
@@ -334,9 +335,10 @@ obj function_template (Object) {
|
||||
template_type_replacements.copy_construct(&template_type_replacements_in)
|
||||
instantiated_map.construct()
|
||||
scope.construct()
|
||||
template::is_function = is_function
|
||||
return this
|
||||
}
|
||||
fun copy_construct(old: *function_template) {
|
||||
fun copy_construct(old: *template) {
|
||||
name.copy_construct(&old->name)
|
||||
syntax_node = old->syntax_node
|
||||
instantiated.copy_construct(&old->instantiated)
|
||||
@@ -344,6 +346,7 @@ obj function_template (Object) {
|
||||
template_type_replacements.copy_construct(&old->template_type_replacements)
|
||||
instantiated_map.copy_construct(&old->instantiated_map)
|
||||
scope.copy_construct(&old->scope)
|
||||
is_function = old->is_function
|
||||
}
|
||||
fun destruct() {
|
||||
name.destruct()
|
||||
@@ -353,14 +356,14 @@ obj function_template (Object) {
|
||||
instantiated_map.destruct()
|
||||
scope.destruct()
|
||||
}
|
||||
fun operator=(other: ref function_template) {
|
||||
fun operator=(other: ref template) {
|
||||
destruct()
|
||||
copy_construct(&other)
|
||||
}
|
||||
fun operator==(other: ref function_template): bool {
|
||||
fun operator==(other: ref template): bool {
|
||||
return name == name && syntax_node == other.syntax_node && instantiated == other.instantiated &&
|
||||
scope == other.scope && template_types == other.template_types && template_type_replacements == other.template_type_replacements &&
|
||||
instantiated_map == other.instantiated_map
|
||||
instantiated_map == other.instantiated_map && is_function == other.is_function
|
||||
}
|
||||
}
|
||||
fun ast_code_block_ptr(): *ast_node {
|
||||
@@ -949,7 +952,7 @@ fun get_ast_children(node: *ast_node): vector<*ast_node> {
|
||||
ast_node::type_def(backing) return backing.variables + backing.methods
|
||||
ast_node::adt_def(backing) return vector<*ast_node>()
|
||||
ast_node::function(backing) return backing.parameters + backing.body_statement
|
||||
ast_node::function_template(backing) return backing.instantiated
|
||||
ast_node::template(backing) return backing.instantiated
|
||||
ast_node::code_block(backing) return backing.children
|
||||
ast_node::statement(backing) return vector<*ast_node>(backing.child)
|
||||
ast_node::if_statement(backing) return vector(backing.condition, backing.then_part, backing.else_part)
|
||||
@@ -976,7 +979,7 @@ fun get_ast_name(node: *ast_node): string {
|
||||
ast_node::type_def(backing) return string("type_def: ") + backing.name
|
||||
ast_node::adt_def(backing) return string("adt_def: ") + backing.name
|
||||
ast_node::function(backing) return string("function: ") + backing.name + ": " + backing.type->to_string()
|
||||
ast_node::function_template(backing) return string("function_template: ") + backing.name
|
||||
ast_node::template(backing) return string("template: ") + backing.name
|
||||
ast_node::code_block(backing) return string("code_block")
|
||||
ast_node::statement(backing) return string("statement")
|
||||
ast_node::if_statement(backing) return string("if_statement")
|
||||
@@ -1003,7 +1006,7 @@ fun get_ast_scope(node: *ast_node): *map<string,vector<*ast_node>> {
|
||||
ast_node::type_def() return &node->type_def.scope
|
||||
ast_node::adt_def() return &node->adt_def.scope
|
||||
ast_node::function() return &node->function.scope
|
||||
ast_node::function_template() return &node->function_template.scope
|
||||
ast_node::template() return &node->template.scope
|
||||
ast_node::code_block() return &node->code_block.scope
|
||||
ast_node::statement() return &node->statement.scope
|
||||
ast_node::if_statement() return &node->if_statement.scope
|
||||
|
||||
Reference in New Issue
Block a user