|
|
|
|
@@ -160,7 +160,9 @@ obj ast_transformation (Object) {
|
|
|
|
|
fun fourth_pass(parse_tree: *tree<symbol>, translation_unit: *ast_node) {
|
|
|
|
|
println(string("Fourth Pass for ") + translation_unit->translation_unit.name)
|
|
|
|
|
}
|
|
|
|
|
fun transform_type(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *type {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun transform_type(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *type {
|
|
|
|
|
// check for references and step down
|
|
|
|
|
// always get to pre-reffed level
|
|
|
|
|
var real_node = get_node("pre_reffed", node)
|
|
|
|
|
@@ -199,11 +201,9 @@ obj ast_transformation (Object) {
|
|
|
|
|
println("No objects in lookup, returning none")
|
|
|
|
|
return type_ptr(base_type::none(), indirection)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*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 return transform(node, scope, search_type::none())
|
|
|
|
|
|
|
|
|
|
fun transform(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform(node: *tree<symbol>, scope: *ast_node): *ast_node return transform(node, scope, search_type::none())
|
|
|
|
|
fun transform(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
|
|
|
|
var name = node->data.name
|
|
|
|
|
if (name == "identifier" || name == "scoped_identifier") {
|
|
|
|
|
return transform_identifier(node, scope, searching_for)
|
|
|
|
|
@@ -249,11 +249,11 @@ obj ast_transformation (Object) {
|
|
|
|
|
}
|
|
|
|
|
print("FAILED TO TRANSFORM: "); print(name + ": "); println(concat_symbol_tree(node))
|
|
|
|
|
return null<ast_node>()
|
|
|
|
|
}
|
|
|
|
|
fun transform_all(nodes: vector<*tree<symbol>>, scope: *ast_node): vector<*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 transform_identifier(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_identifier(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
|
|
|
|
// first, we check for and generate this
|
|
|
|
|
var name = concat_symbol_tree(node)
|
|
|
|
|
if (name == "this") {
|
|
|
|
|
@@ -266,8 +266,8 @@ obj ast_transformation (Object) {
|
|
|
|
|
}
|
|
|
|
|
println("FAILED SEARCH FOR")
|
|
|
|
|
return null<ast_node>()
|
|
|
|
|
}
|
|
|
|
|
fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_value(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
var value_str = concat_symbol_tree(node)
|
|
|
|
|
var value_type = null<type>()
|
|
|
|
|
if (value_str[0] == '"')
|
|
|
|
|
@@ -289,31 +289,27 @@ obj ast_transformation (Object) {
|
|
|
|
|
value_type = type_ptr(base_type::integer())
|
|
|
|
|
}
|
|
|
|
|
return ast_value_ptr(value_str, value_type)
|
|
|
|
|
}
|
|
|
|
|
fun transform_code_block(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_code_block(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
fun transform_if_comp(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_if_comp(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
var new_if_comp = ast_if_comp_ptr()
|
|
|
|
|
new_if_comp->if_comp.wanted_generator = concat_symbol_tree(get_node("identifier", node))
|
|
|
|
|
new_if_comp->if_comp.statement = transform_statement(get_node("statement", node), scope)
|
|
|
|
|
return new_if_comp
|
|
|
|
|
}
|
|
|
|
|
fun transform_simple_passthrough(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_simple_passthrough(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
var new_passthrough = ast_simple_passthrough_ptr()
|
|
|
|
|
// setup passthrough params and string
|
|
|
|
|
new_passthrough->simple_passthrough.passthrough_str = concat_symbol_tree(get_node("triple_quoted_string", node)).slice(3,-4)
|
|
|
|
|
return new_passthrough
|
|
|
|
|
}
|
|
|
|
|
fun transform_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
var new_statement = ast_statement_ptr()
|
|
|
|
|
new_statement->statement.child = transform(node->children[0], scope)
|
|
|
|
|
return new_statement
|
|
|
|
|
}
|
|
|
|
|
fun transform_declaration_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_statement(node: *tree<symbol>, scope: *ast_node): *ast_node return ast_statement_ptr(transform(node->children[0], scope));
|
|
|
|
|
fun transform_declaration_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
// this might have an init position method call
|
|
|
|
|
var identifiers = get_nodes("identifier", node)
|
|
|
|
|
var name = concat_symbol_tree(identifiers[0])
|
|
|
|
|
@@ -335,17 +331,31 @@ obj ast_transformation (Object) {
|
|
|
|
|
if (identifiers.size == 2) {
|
|
|
|
|
var method = transform(identifiers[1], ident_type->type_def)
|
|
|
|
|
var parameters = get_nodes("parameter", node).map(fun(child: *tree<symbol>): *ast_node return transform(get_node("boolean_expression", child), scope);)
|
|
|
|
|
var method_access = ast_function_call_ptr(get_builtin_function(string("."), vector(ident_type, get_ast_type(method))), vector(identifier, method))
|
|
|
|
|
declaration->declaration_statement.init_method_call = ast_function_call_ptr(method_access, parameters)
|
|
|
|
|
declaration->declaration_statement.init_method_call = make_method_call(identifier, method, parameters)
|
|
|
|
|
}
|
|
|
|
|
add_to_scope(name, identifier, scope)
|
|
|
|
|
return declaration
|
|
|
|
|
}
|
|
|
|
|
fun transform_assignment_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun has_method(object: *ast_node, name: *char, parameter_types: vector<*type>): bool return has_method(object, string(name), parameter_types);
|
|
|
|
|
fun has_method(object: *ast_node, name: string, parameter_types: vector<*type>): bool {
|
|
|
|
|
return function_lookup(name, object, parameter_types) || false
|
|
|
|
|
}
|
|
|
|
|
fun make_method_call(object_ident: *ast_node, name: *char, parameters: vector<*ast_node>): *ast_node return make_method_call(object_ident, string(name), parameters);
|
|
|
|
|
fun make_method_call(object_ident: *ast_node, name: string, parameters: vector<*ast_node>): *ast_node {
|
|
|
|
|
var method = function_lookup(name, get_ast_type(object_ident)->type_def, parameters.map(fun(param: *ast_node): *type return get_ast_type(param);))
|
|
|
|
|
print("Here is the Method: ")
|
|
|
|
|
println(method)
|
|
|
|
|
return make_method_call(object_ident, method, parameters)
|
|
|
|
|
}
|
|
|
|
|
fun make_method_call(object_ident: *ast_node, method: *ast_node, parameters: vector<*ast_node>): *ast_node {
|
|
|
|
|
var method_access = ast_function_call_ptr(get_builtin_function(string("."), vector(get_ast_type(object_ident), get_ast_type(method))), vector(object_ident, method))
|
|
|
|
|
return ast_function_call_ptr(method_access, parameters)
|
|
|
|
|
}
|
|
|
|
|
fun transform_assignment_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
var assignment = ast_assignment_statement_ptr(transform(get_node("factor", node), scope), transform(get_node("boolean_expression", node), scope))
|
|
|
|
|
return assignment
|
|
|
|
|
}
|
|
|
|
|
fun transform_if_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_if_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
var if_statement = ast_if_statement_ptr(transform_expression(get_node("boolean_expression", node), scope))
|
|
|
|
|
// one variable declarations might be in a code_block-less if statement
|
|
|
|
|
add_to_scope("~enclosing_scope", scope, if_statement)
|
|
|
|
|
@@ -355,14 +365,14 @@ obj ast_transformation (Object) {
|
|
|
|
|
if (statements.size == 2)
|
|
|
|
|
if_statement->if_statement.else_part = statements[1]
|
|
|
|
|
return if_statement
|
|
|
|
|
}
|
|
|
|
|
fun transform_while_loop(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_while_loop(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
var while_loop = ast_while_loop_ptr(transform_expression(get_node("boolean_expression", node), scope))
|
|
|
|
|
add_to_scope("~enclosing_scope", scope, while_loop)
|
|
|
|
|
while_loop->while_loop.statement = transform(get_node("statement", node), while_loop)
|
|
|
|
|
return while_loop
|
|
|
|
|
}
|
|
|
|
|
fun transform_for_loop(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_for_loop(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
var for_loop = ast_for_loop_ptr()
|
|
|
|
|
add_to_scope("~enclosing_scope", scope, for_loop)
|
|
|
|
|
var statements = get_nodes("statement", node)
|
|
|
|
|
@@ -371,19 +381,19 @@ obj ast_transformation (Object) {
|
|
|
|
|
for_loop->for_loop.update = transform(statements[1], for_loop)
|
|
|
|
|
for_loop->for_loop.body = transform(statements[2], for_loop)
|
|
|
|
|
return for_loop
|
|
|
|
|
}
|
|
|
|
|
fun transform_return_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_return_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
return ast_return_statement_ptr(transform(node->children[0], scope))
|
|
|
|
|
}
|
|
|
|
|
fun transform_branching_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_branching_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
if (node->data.name == "break_statement")
|
|
|
|
|
return ast_branching_statement_ptr(branching_type::break_stmt())
|
|
|
|
|
return ast_branching_statement_ptr(branching_type::continue_stmt())
|
|
|
|
|
}
|
|
|
|
|
fun transform_defer_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_defer_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
return ast_defer_statement_ptr(transform(node->children[0], scope))
|
|
|
|
|
}
|
|
|
|
|
fun transform_function_call(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_function_call(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
|
|
|
|
// don't bother with a full transform for parameters with their own function, just get the boolean expression and transform it
|
|
|
|
|
var parameters = get_nodes("parameter", node).map(fun(child: *tree<symbol>): *ast_node return transform(get_node("boolean_expression", child), scope);)
|
|
|
|
|
var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);)
|
|
|
|
|
@@ -393,9 +403,9 @@ obj ast_transformation (Object) {
|
|
|
|
|
/*print("function call parameters ")*/
|
|
|
|
|
/*f->function_call.parameters.for_each(fun(param: *ast_node) print(param);)*/
|
|
|
|
|
return f
|
|
|
|
|
}
|
|
|
|
|
fun transform_expression(node: *tree<symbol>, scope: *ast_node): *ast_node return transform_expression(node, scope, search_type::none())
|
|
|
|
|
fun transform_expression(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun transform_expression(node: *tree<symbol>, scope: *ast_node): *ast_node return transform_expression(node, scope, search_type::none())
|
|
|
|
|
fun transform_expression(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
|
|
|
|
// figure out what the expression is, handle overloads, or you know
|
|
|
|
|
// ignore everything and do a passthrough
|
|
|
|
|
var func_name = string()
|
|
|
|
|
@@ -427,13 +437,13 @@ obj ast_transformation (Object) {
|
|
|
|
|
}
|
|
|
|
|
var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);)
|
|
|
|
|
return ast_function_call_ptr(get_builtin_function(func_name, parameter_types), parameters)
|
|
|
|
|
}
|
|
|
|
|
fun get_builtin_function(name: string, param_types: vector<*type>): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun get_builtin_function(name: string, param_types: vector<*type>): *ast_node {
|
|
|
|
|
if (name == "." || name == "->")
|
|
|
|
|
return ast_function_ptr(name, type_ptr(param_types, param_types[1]), vector<*ast_node>())
|
|
|
|
|
return ast_function_ptr(name, type_ptr(param_types, param_types[0]), vector<*ast_node>())
|
|
|
|
|
}
|
|
|
|
|
fun function_lookup(name: string, scope: *ast_node, param_types: vector<*type>): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun function_lookup(name: string, scope: *ast_node, param_types: vector<*type>): *ast_node {
|
|
|
|
|
println(string("doing function lookup for: ") + name)
|
|
|
|
|
var param_string = string()
|
|
|
|
|
param_types.for_each(fun(t: *type) param_string += t->to_string() + ", ";)
|
|
|
|
|
@@ -460,8 +470,8 @@ obj ast_transformation (Object) {
|
|
|
|
|
}
|
|
|
|
|
println(string("function lookup failed for ") + name)
|
|
|
|
|
return null<ast_node>()
|
|
|
|
|
}
|
|
|
|
|
fun identifier_lookup(name: string, scope: *ast_node): *ast_node {
|
|
|
|
|
}
|
|
|
|
|
fun identifier_lookup(name: string, scope: *ast_node): *ast_node {
|
|
|
|
|
println(string("doing identifier lookup for: ") + name)
|
|
|
|
|
var results = scope_lookup(name, scope)
|
|
|
|
|
if (!results.size) {
|
|
|
|
|
@@ -469,13 +479,13 @@ obj ast_transformation (Object) {
|
|
|
|
|
return null<ast_node>()
|
|
|
|
|
}
|
|
|
|
|
return results[0]
|
|
|
|
|
}
|
|
|
|
|
fun scope_lookup(name: string, scope: *ast_node): vector<*ast_node> {
|
|
|
|
|
}
|
|
|
|
|
fun scope_lookup(name: string, scope: *ast_node): vector<*ast_node> {
|
|
|
|
|
println("*****Doing a name lookup for*****")
|
|
|
|
|
println(name)
|
|
|
|
|
return scope_lookup_helper(name, scope)
|
|
|
|
|
}
|
|
|
|
|
fun scope_lookup_helper(name: string, scope: *ast_node): vector<*ast_node> {
|
|
|
|
|
}
|
|
|
|
|
fun scope_lookup_helper(name: string, scope: *ast_node): vector<*ast_node> {
|
|
|
|
|
// need to do properly scopded lookups
|
|
|
|
|
// prevent re-checking the same one...
|
|
|
|
|
print("scope is: ")
|
|
|
|
|
@@ -497,7 +507,6 @@ obj ast_transformation (Object) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return results
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun concat_symbol_tree(node: *tree<symbol>): string {
|
|
|
|
|
|