Added support for unions as a step towards lowering ADTs in the next pass to be written.

This commit is contained in:
Nathan Braswell
2016-06-15 22:26:03 -07:00
parent d44293a48b
commit 4de7dd1210
8 changed files with 55 additions and 13 deletions

View File

@@ -190,8 +190,10 @@ obj identifier (Object) {
return name == other.name && type == other.type && enclosing_scope == other.enclosing_scope
}
}
fun ast_type_def_ptr(name: string): *ast_node {
var to_ret.construct(name): type_def
fun ast_type_def_ptr(name: ref string): *ast_node
return ast_type_def_ptr(name, false)
fun ast_type_def_ptr(name: ref string, is_union: bool): *ast_node {
var to_ret.construct(name, is_union): type_def
var ptr = new<ast_node>()
ptr->copy_construct(&ast_node::type_def(to_ret))
return ptr
@@ -205,12 +207,14 @@ fun is_type_def(node: *ast_node): bool {
obj type_def (Object) {
var scope: map<string, vector<*ast_node>>
var name: string
var is_union: bool
var self_type: *type
var variables: vector<*ast_node>
var methods: vector<*ast_node>
fun construct(nameIn: string): *type_def {
fun construct(nameIn: ref string, is_unionIn: bool): *type_def {
scope.construct()
name.copy_construct(&nameIn)
is_union = is_unionIn
self_type = null<type>()
variables.construct()
methods.construct()
@@ -220,6 +224,7 @@ obj type_def (Object) {
self_type = old->self_type
scope.copy_construct(&old->scope)
name.copy_construct(&old->name)
is_union = old->is_union
variables.copy_construct(&old->variables)
methods.copy_construct(&old->methods)
}
@@ -234,7 +239,7 @@ obj type_def (Object) {
copy_construct(&other)
}
fun operator==(other: ref type_def): bool {
return name == other.name && self_type == other.self_type && variables == other.variables && methods == other.methods
return name == other.name && is_union == other.is_union && self_type == other.self_type && variables == other.variables && methods == other.methods
}
}
fun ast_adt_def_ptr(name: string): *ast_node {
@@ -1128,7 +1133,7 @@ fun get_ast_name(node: *ast_node): string {
ast_node::translation_unit(backing) return string("translation_unit: ") + backing.name
ast_node::import(backing) return string("import: ") + backing.name + "; [" + backing.imported.reduce(fun(name: string, acc: string): string return acc + " " + name;, string()) + " ]"
ast_node::identifier(backing) return string("identifier: ") + backing.name + ": " + backing.type->to_string()
ast_node::type_def(backing) return string("type_def: ") + backing.name
ast_node::type_def(backing) return string("type_def: ") + backing.name + " union?:" + backing.is_union
ast_node::adt_def(backing) return string("adt_def: ") + backing.name
ast_node::function(backing) {
if (backing.is_extern)