more work on the ast_transformation
This commit is contained in:
@@ -40,7 +40,6 @@ obj ast_transformation (Object) {
|
||||
translation_unit->translation_unit.children.add(type_def_node)
|
||||
add_to_scope("~enclosing_scope", translation_unit, type_def_node)
|
||||
add_to_scope(name, type_def_node, translation_unit)
|
||||
// add to scope, the reverse
|
||||
// set up type - self-referential, traits, template, etc
|
||||
} else if (child->data.name == "adt_def") {
|
||||
var name = concat_symbol_tree(get_node("identifier", child))
|
||||
@@ -48,13 +47,9 @@ obj ast_transformation (Object) {
|
||||
translation_unit->translation_unit.children.add(adt_def_node)
|
||||
add_to_scope("~enclosing_scope", translation_unit, adt_def_node)
|
||||
add_to_scope(name, adt_def_node, translation_unit)
|
||||
// add to scope, the reverse
|
||||
} else if (child->data.name == "if_comp") {
|
||||
var if_comp_node = ast_if_comp_ptr()
|
||||
var if_comp_node = transform(child, translation_unit)
|
||||
translation_unit->translation_unit.children.add(if_comp_node)
|
||||
add_to_scope("~enclosing_scope", translation_unit, if_comp_node)
|
||||
// add parent to scope?
|
||||
// do children...
|
||||
}
|
||||
})
|
||||
|
||||
@@ -62,19 +57,39 @@ obj ast_transformation (Object) {
|
||||
// this one already has all its types defined
|
||||
parse_tree->children.for_each(fun(child: *tree<symbol>) {
|
||||
if (child->data.name == "import") {
|
||||
var name = concat_symbol_tree(get_node("identifier", child))
|
||||
var import_identifier_children = get_nodes("identifier", child)
|
||||
var name = concat_symbol_tree(import_identifier_children[0])
|
||||
var import_node = ast_import_ptr(name)
|
||||
translation_unit->translation_unit.children.add(import_node)
|
||||
add_to_scope("~enclosing_scope", translation_unit, import_node)
|
||||
var outside_translation_unit = importer->import(name + ".krak")
|
||||
add_to_scope(name, outside_translation_unit, translation_unit)
|
||||
// call out to importer
|
||||
// go through what is imported - *, or individual names
|
||||
// for names undefined right now (i.e. not of a type), leave an empty vector?
|
||||
import_node->import.imported = from_vector(import_identifier_children.slice(1,-1).map(fun(ident: *tree<symbol>):string return concat_symbol_tree(ident);))
|
||||
}
|
||||
})
|
||||
return translation_unit
|
||||
}
|
||||
/*NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree<ASTData>* scope, std::vector<Type> types, bool limitToFunction, std::map<std::string, Type*> templateTypeReplacements) {*/
|
||||
fun transform(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||
var name = node->data.name
|
||||
if (name == "identifier" || name == "scoped_identifier") {
|
||||
} else if (name == "code_block") {
|
||||
var new_block = ast_code_block_ptr()
|
||||
add_to_scope("~enclosing_scope", scope, new_block)
|
||||
new_block->code_block.children = transform_all(node->children, new_block)
|
||||
return new_block
|
||||
} else if (name == "code_block") {
|
||||
var new_if_comp = ast_if_comp_ptr()
|
||||
add_to_scope("~enclosing_scope", scope, new_if_comp)
|
||||
new_if_comp->code_block.children = transform_all(node->children, new_if_comp)
|
||||
return new_if_comp
|
||||
}
|
||||
print("FAILED TO TRANSFORM: "); println(concat_symbol_tree(node))
|
||||
return null<ast_node>()
|
||||
}
|
||||
fun transform_all(nodes: vector<*tree<symbol>>, scope: *ast_node): vector<*ast_node> {
|
||||
return nodes.map(fun(node: *tree<symbol>): *ast_node return transform(node, scope);)
|
||||
}
|
||||
}
|
||||
|
||||
fun concat_symbol_tree(node: *tree<symbol>): string {
|
||||
@@ -95,6 +110,9 @@ fun get_node(lookup: string, parent: *tree<symbol>): *tree<symbol> {
|
||||
return results[0]
|
||||
return null<tree<symbol>>()
|
||||
}
|
||||
fun get_nodes(lookup: *char, parent: *tree<symbol>): vector<*tree<symbol>> {
|
||||
return get_nodes(string(lookup), parent)
|
||||
}
|
||||
fun get_nodes(lookup: string, parent: *tree<symbol>): vector<*tree<symbol>> {
|
||||
return parent->children.filter(fun(node: *tree<symbol>):bool return node->data.name == lookup;)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user