Object member access works now
This commit is contained in:
@@ -233,6 +233,7 @@ obj ast_transformation (Object) {
|
||||
|| name == "bool_exp" || name == "expression"
|
||||
|| name == "shiftand" || name == "term"
|
||||
|| name == "factor" || name == "unarad"
|
||||
|| name == "access_operation"
|
||||
) {
|
||||
// for now, assume passthrough and just transform underneath
|
||||
return transform_expression(node, scope)
|
||||
@@ -242,7 +243,7 @@ obj ast_transformation (Object) {
|
||||
println(string("transforming value: ") + name)
|
||||
return transform_value(node, scope)
|
||||
}
|
||||
print("FAILED TO TRANSFORM: "); println(concat_symbol_tree(node))
|
||||
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> {
|
||||
@@ -385,12 +386,24 @@ obj ast_transformation (Object) {
|
||||
}
|
||||
} else {
|
||||
func_name = concat_symbol_tree(node->children[1])
|
||||
parameters = vector(transform(node->children[0], scope), transform(node->children[2], scope))
|
||||
var first_param = transform(node->children[0], scope)
|
||||
var second_param = null<ast_node>()
|
||||
if (func_name == "." || func_name == "->") {
|
||||
println("Gonna do the internal scope thing")
|
||||
second_param = transform(node->children[2], get_ast_type(first_param)->type_def)
|
||||
} else {
|
||||
println("Gonna do regular scope thing")
|
||||
second_param = transform(node->children[2], get_ast_type(first_param)->type_def)
|
||||
second_param = transform(node->children[2], scope)
|
||||
}
|
||||
parameters = vector(first_param, second_param)
|
||||
}
|
||||
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 {
|
||||
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 {
|
||||
@@ -429,6 +442,11 @@ obj ast_transformation (Object) {
|
||||
return results[0]
|
||||
}
|
||||
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> {
|
||||
// need to do properly scopded lookups
|
||||
// prevent re-checking the same one...
|
||||
print("scope is: ")
|
||||
@@ -440,12 +458,12 @@ obj ast_transformation (Object) {
|
||||
results += get_ast_scope(scope)->get(name)
|
||||
}
|
||||
if (get_ast_scope(scope)->contains_key(string("~enclosing_scope")))
|
||||
results += scope_lookup(name, get_ast_scope(scope)->get(string("~enclosing_scope"))[0])
|
||||
results += scope_lookup_helper(name, get_ast_scope(scope)->get(string("~enclosing_scope"))[0])
|
||||
if (is_translation_unit(scope)) {
|
||||
scope->translation_unit.children.for_each(fun(child: *ast_node) {
|
||||
if (is_import(child) && child->import.imported.contains(name)) {
|
||||
println(name + " is indeed imported")
|
||||
results += scope_lookup(name, child->import.translation_unit)
|
||||
results += scope_lookup_helper(name, child->import.translation_unit)
|
||||
} else println(name + " is not imported (this time)")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user