Shorter AST names
This commit is contained in:
@@ -42,7 +42,7 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
match(*node) {
|
||||
ast_node::type_def(backing) all_type_defs.add(node)
|
||||
ast_node::function(backing) if (backing.body_statement && !is_code_block(backing.body_statement)) {
|
||||
backing.body_statement = ast_code_block_ptr(backing.body_statement)
|
||||
backing.body_statement = _code_block(backing.body_statement)
|
||||
add_to_scope("~enclosing_scope", node, backing.body_statement)
|
||||
if (!is_code_block(backing.body_statement))
|
||||
error("BUT EXTRA WHY")
|
||||
@@ -51,55 +51,55 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
}
|
||||
ast_node::if_statement(backing) {
|
||||
if (!is_code_block(backing.then_part)) {
|
||||
backing.then_part = ast_code_block_ptr(backing.then_part)
|
||||
backing.then_part = _code_block(backing.then_part)
|
||||
add_to_scope("~enclosing_scope", node, backing.then_part)
|
||||
}
|
||||
if (backing.else_part && !is_code_block(backing.else_part)) {
|
||||
backing.else_part = ast_code_block_ptr(backing.else_part)
|
||||
backing.else_part = _code_block(backing.else_part)
|
||||
add_to_scope("~enclosing_scope", node, backing.else_part)
|
||||
}
|
||||
}
|
||||
// no need for case because it's already been lowered
|
||||
ast_node::while_loop(backing) {
|
||||
if (!is_code_block(backing.statement)) {
|
||||
backing.statement = ast_code_block_ptr(backing.statement)
|
||||
backing.statement = _code_block(backing.statement)
|
||||
add_to_scope("~enclosing_scope", node, backing.statement)
|
||||
}
|
||||
var condition = backing.condition
|
||||
backing.condition = ast_value_ptr(str("true"), type_ptr(base_type::boolean()))
|
||||
backing.condition = _value(str("true"), type_ptr(base_type::boolean()))
|
||||
// objects do not coerce to booleans, so it should be ok for this not to be a ref
|
||||
var condition_ident = ast_identifier_ptr("condition_temp", get_ast_type(condition), backing.statement)
|
||||
backing.statement->code_block.children.add(0, ast_declaration_statement_ptr(condition_ident, condition))
|
||||
var condition_if = ast_if_statement_ptr(make_operator_call("!", vec(condition_ident)))
|
||||
condition_if->if_statement.then_part = ast_branching_statement_ptr(branching_type::break_stmt())
|
||||
var condition_ident = _ident("condition_temp", get_ast_type(condition), backing.statement)
|
||||
backing.statement->code_block.children.add(0, _declaration(condition_ident, condition))
|
||||
var condition_if = _if(make_operator_call("!", vec(condition_ident)))
|
||||
condition_if->if_statement.then_part = _branch(branching_type::break_stmt())
|
||||
backing.statement->code_block.children.add(1, condition_if)
|
||||
}
|
||||
ast_node::for_loop(backing) {
|
||||
if (!is_code_block(backing.body)) {
|
||||
backing.body = ast_code_block_ptr(backing.body)
|
||||
backing.body = _code_block(backing.body)
|
||||
add_to_scope("~enclosing_scope", node, backing.body)
|
||||
}
|
||||
add_before_in(backing.init, node, parent_chain->top())
|
||||
backing.init = null<ast_node>()
|
||||
// the do_update goes in the block above the for
|
||||
var update_ident = ast_identifier_ptr("do_update", type_ptr(base_type::boolean()), parent_chain->top())
|
||||
add_before_in(ast_declaration_statement_ptr(update_ident, ast_value_ptr(str("false"), type_ptr(base_type::boolean()))),
|
||||
var update_ident = _ident("do_update", type_ptr(base_type::boolean()), parent_chain->top())
|
||||
add_before_in(_declaration(update_ident, _value(str("false"), type_ptr(base_type::boolean()))),
|
||||
node, parent_chain->top())
|
||||
var update_if = ast_if_statement_ptr(update_ident)
|
||||
var update_if = _if(update_ident)
|
||||
add_to_scope("~enclosing_scope", backing.body, update_if)
|
||||
update_if->if_statement.then_part = ast_code_block_ptr(backing.update)
|
||||
update_if->if_statement.then_part = _code_block(backing.update)
|
||||
add_to_scope("~enclosing_scope", update_if, update_if->if_statement.then_part)
|
||||
backing.update = null<ast_node>()
|
||||
backing.body->code_block.children.add(0, update_if)
|
||||
backing.body->code_block.children.add(1, ast_assignment_statement_ptr(update_ident, ast_value_ptr(str("true"), type_ptr(base_type::boolean()))))
|
||||
backing.body->code_block.children.add(1, _assign(update_ident, _value(str("true"), type_ptr(base_type::boolean()))))
|
||||
|
||||
var condition = backing.condition
|
||||
backing.condition = ast_value_ptr(str("true"), type_ptr(base_type::boolean()))
|
||||
backing.condition = _value(str("true"), type_ptr(base_type::boolean()))
|
||||
// objects do not coerce to booleans, so it should be ok for this not to be a ref
|
||||
var condition_ident = ast_identifier_ptr("condition_temp", get_ast_type(condition), backing.body)
|
||||
backing.body->code_block.children.add(2, ast_declaration_statement_ptr(condition_ident, condition))
|
||||
var condition_if = ast_if_statement_ptr(make_operator_call("!", vec(condition_ident)))
|
||||
condition_if->if_statement.then_part = ast_branching_statement_ptr(branching_type::break_stmt())
|
||||
var condition_ident = _ident("condition_temp", get_ast_type(condition), backing.body)
|
||||
backing.body->code_block.children.add(2, _declaration(condition_ident, condition))
|
||||
var condition_if = _if(make_operator_call("!", vec(condition_ident)))
|
||||
condition_if->if_statement.then_part = _branch(branching_type::break_stmt())
|
||||
backing.body->code_block.children.add(3, condition_if)
|
||||
}
|
||||
}
|
||||
@@ -144,15 +144,15 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
}
|
||||
if (func_name == "||" || func_name == "&&") {
|
||||
var enclosing_block_idx = parent_chain->index_from_top_satisfying(fun(i: *ast_node): bool return is_code_block(i);)
|
||||
var short_circuit_result = ast_identifier_ptr("short_circut_result", type_ptr(base_type::boolean()), parent_chain->from_top(enclosing_block_idx))
|
||||
var short_circuit_declaration = ast_declaration_statement_ptr(short_circuit_result, backing.parameters[0])
|
||||
var short_circuit_result = _ident("short_circut_result", type_ptr(base_type::boolean()), parent_chain->from_top(enclosing_block_idx))
|
||||
var short_circuit_declaration = _declaration(short_circuit_result, backing.parameters[0])
|
||||
var condition = short_circuit_result
|
||||
if (func_name == "||")
|
||||
condition = make_operator_call("!", vec(condition))
|
||||
var short_circuit_if = ast_if_statement_ptr(condition)
|
||||
var short_circuit_if = _if(condition)
|
||||
add_to_scope("~enclosing_scope", parent_chain->from_top(enclosing_block_idx), short_circuit_if)
|
||||
// how to get proper parent scoping working for this part
|
||||
short_circuit_if->if_statement.then_part = ast_code_block_ptr(ast_assignment_statement_ptr(short_circuit_result, backing.parameters[1]))
|
||||
short_circuit_if->if_statement.then_part = _code_block(_assign(short_circuit_result, backing.parameters[1]))
|
||||
add_to_scope("~enclosing_scope", short_circuit_if, short_circuit_if->if_statement.then_part)
|
||||
add_before_in(short_circuit_declaration, parent_chain->from_top(enclosing_block_idx-1), parent_chain->from_top(enclosing_block_idx))
|
||||
add_before_in(short_circuit_if, parent_chain->from_top(enclosing_block_idx-1), parent_chain->from_top(enclosing_block_idx))
|
||||
@@ -203,10 +203,10 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
in_function_param_type = get_ast_type(param)->clone_without_ref()
|
||||
var param_type = get_ast_type(param)
|
||||
if (!in_function_param_type->is_ref && param_type->indirection == 0 && (param_type->is_object() && has_method(param_type->type_def, "copy_construct", vec(param_type->clone_with_indirection(1))))) {
|
||||
var temp_ident = ast_identifier_ptr("temporary_param_boom", param_type->clone_without_ref(), replace_in)
|
||||
var temp_ident = _ident("temporary_param_boom", param_type->clone_without_ref(), replace_in)
|
||||
add_to_scope("temporary_param_boom", temp_ident, replace_in)
|
||||
add_to_scope("~enclosing_scope", replace_in, temp_ident)
|
||||
var declaration = ast_declaration_statement_ptr(temp_ident, null<ast_node>())
|
||||
var declaration = _declaration(temp_ident, null<ast_node>())
|
||||
var copy_in = make_method_call(temp_ident, "copy_construct", vec(make_operator_call("&", vec(param))))
|
||||
add_before_in(declaration, replace_before, replace_in)
|
||||
add_before_in(copy_in, replace_before, replace_in)
|
||||
@@ -215,13 +215,13 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
}
|
||||
var func_return_type = func_type->return_type
|
||||
if (!func_return_type->is_ref && func_return_type->indirection == 0 && func_return_type->is_object()) {
|
||||
var temp_return = ast_identifier_ptr("temporary_return_boomchaka", func_return_type, replace_in)
|
||||
var temp_return = _ident("temporary_return_boomchaka", func_return_type, replace_in)
|
||||
add_to_scope("temporary_return_boomchaka", temp_return, replace_in)
|
||||
add_to_scope("~enclosing_scope", replace_in, temp_return)
|
||||
var declaration = ast_declaration_statement_ptr(temp_return, node)
|
||||
var declaration = _declaration(temp_return, node)
|
||||
add_before_in(declaration, replace_before, replace_in)
|
||||
if (has_method(func_return_type->type_def, "destruct", vec<*type>())) {
|
||||
add_before_in(ast_defer_statement_ptr(make_method_call(temp_return, "destruct", vec<*ast_node>())),
|
||||
add_before_in(_defer(make_method_call(temp_return, "destruct", vec<*ast_node>())),
|
||||
replace_before, replace_in)
|
||||
}
|
||||
replace_with_in(node, temp_return, parent_chain)
|
||||
@@ -242,7 +242,7 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
if (!is_code_block(backing.body_statement))
|
||||
error("BUT WHY")
|
||||
backing.body_statement->code_block.children.add(order++,
|
||||
ast_defer_statement_ptr(make_method_call(param, "destruct", vec<*ast_node>())))
|
||||
_defer(make_method_call(param, "destruct", vec<*ast_node>())))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -252,10 +252,10 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
return;
|
||||
if (!ident_type->is_ref && ident_type->indirection == 0 && ident_type->is_object()) {
|
||||
if (backing.expression && has_method(ident_type->type_def, "copy_construct", vec(get_ast_type(backing.expression)->clone_with_increased_indirection()))) {
|
||||
var temp_cpy_ctst = ast_identifier_ptr("temp_declaration_copy_construct", get_ast_type(backing.expression)->clone_without_ref(), parent_chain->top())
|
||||
var temp_cpy_ctst = _ident("temp_declaration_copy_construct", get_ast_type(backing.expression)->clone_without_ref(), parent_chain->top())
|
||||
add_to_scope("temp_declaration_copy_construct", temp_cpy_ctst, parent_chain->top())
|
||||
add_to_scope("~enclosing_scope", parent_chain->top(), temp_cpy_ctst)
|
||||
var declaration = ast_declaration_statement_ptr(temp_cpy_ctst, backing.expression)
|
||||
var declaration = _declaration(temp_cpy_ctst, backing.expression)
|
||||
add_after_in(make_method_call(backing.identifier, "copy_construct", vec(make_operator_call("&", vec(temp_cpy_ctst)))),
|
||||
node, parent_chain->top())
|
||||
// do second so the order's right
|
||||
@@ -264,7 +264,7 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
backing.expression = null<ast_node>()
|
||||
}
|
||||
if (has_method(ident_type->type_def, "destruct", vec<*type>())) {
|
||||
add_after_in(ast_defer_statement_ptr(make_method_call(backing.identifier, "destruct", vec<*ast_node>())),
|
||||
add_after_in(_defer(make_method_call(backing.identifier, "destruct", vec<*ast_node>())),
|
||||
node, parent_chain->top())
|
||||
}
|
||||
}
|
||||
@@ -284,10 +284,10 @@ fun obj_lower(name_ast_map: *map<str, pair<*tree<symbol>,*ast_node>>, ast_to_syn
|
||||
if (return_value) {
|
||||
if (get_ast_type(enclosing_function)->return_type->is_ref)
|
||||
return_value = make_operator_call("&", vec(return_value))
|
||||
var temp_return = ast_identifier_ptr("temp_boom_return", get_ast_type(return_value)->clone_without_ref(), block)
|
||||
var temp_return = _ident("temp_boom_return", get_ast_type(return_value)->clone_without_ref(), block)
|
||||
add_to_scope("temp_boom_return", temp_return, block)
|
||||
add_to_scope("~enclosing_scope", block, temp_return)
|
||||
var declaration_statement = ast_declaration_statement_ptr(temp_return, null<ast_node>())
|
||||
var declaration_statement = _declaration(temp_return, null<ast_node>())
|
||||
var assign_statement = assign_or_copy_construct_statement(temp_return, return_value)
|
||||
add_before_in(declaration_statement, node, block)
|
||||
add_before_in(assign_statement, node, block)
|
||||
|
||||
Reference in New Issue
Block a user