Files
kraken/stdlib/c_line_control.krak

41 lines
1.4 KiB
Plaintext

import symbol:*
import tree:*
import vector:*
import map:*
import util:*
import string:*
import mem:*
import io:*
import ast_nodes:*
import ast_transformation:*
import pass_common:*
fun get_line(node: *tree<symbol>, name: string): *ast_node {
var to_ret = ast_simple_passthrough_ptr()
to_ret->simple_passthrough.passthrough_str = string("\n#line ") + get_first_terminal(node)->data.position + " \"" + name + "\"\n"
return to_ret
}
fun c_line_control(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_syntax: *map<*ast_node, *tree<symbol>>) {
var first = true
name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree<symbol>,*ast_node>) {
var helper_after = fun(node: *ast_node, parent_chain: *stack<*ast_node>) {}
var helper = fun(node: *ast_node, parent_chain: *stack<*ast_node>) {
match(*node) {
ast_node::statement(backing) {
if (is_code_block(parent_chain->top()) && ast_to_syntax->contains_key(node)) {
/*println(string("adding ") + get_ast_name(node) + " to " + get_ast_name(parent))*/
add_before_in(get_line(ast_to_syntax->get(node), name), node, parent_chain->top())
}
}
}
}
if (first)
run_on_tree(helper, helper_after, syntax_ast_pair.second)
first = false
})
}