diff --git a/boot/parser.yy b/boot/parser.yy index bc06b47..e4b4f08 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -524,11 +524,11 @@ variable_declaration: identifier_definitions ":" type_expression } } variable_declarations: - variable_declaration variable_declarations + variable_declaration ";" variable_declarations { std::swap($$, $1); - $$.reserve($$.size() + $2.size()); - $$.insert(std::end($$), std::begin($2), std::end($2)); + $$.reserve($$.size() + $3.size()); + $$.insert(std::end($$), std::begin($3), std::end($3)); } | variable_declaration { std::swap($$, $1); } variable_part: diff --git a/gcc/elna-generic.cc b/gcc/elna-generic.cc index 278b24e..e5ddc54 100644 --- a/gcc/elna-generic.cc +++ b/gcc/elna-generic.cc @@ -41,14 +41,10 @@ namespace elna::gcc { if (auto reference = type.get()) { - auto looked_up = unresolved.find(reference->identifier); - if (looked_up == unresolved.cend()) + auto looked_up = symbols->lookup(reference->identifier); + if (looked_up != NULL_TREE) { - return symbols->lookup(reference->identifier); - } - else - { - return looked_up->second; + return TREE_TYPE(looked_up); } } else if (auto reference = type.get()) @@ -73,22 +69,20 @@ namespace elna::gcc } else if (auto reference = type.get()) { - return handle_symbol(reference->name, reference->reference, symbols, unresolved); + return handle_symbol(reference->name, reference, symbols, unresolved); } return error_mark_node; } - tree handle_symbol(const std::string& symbol_name, const boot::type& type, + tree handle_symbol(const std::string& symbol_name, std::shared_ptr reference, std::shared_ptr symbols, std::unordered_map& unresolved) { - auto looked_up = symbols->lookup(symbol_name); + auto looked_up = get_inner_alias(reference->reference, symbols, unresolved); + + unresolved.insert({ symbol_name, looked_up }); - if (looked_up == NULL_TREE) - { - looked_up = get_inner_alias(type, symbols, unresolved); - unresolved.insert({ symbol_name, looked_up }); - } return looked_up; + } std::deque> do_semantic_analysis(const char *path, @@ -103,7 +97,7 @@ namespace elna::gcc { for (auto& [symbol_name, symbol_info] : declaration_visitor.unresolved) { - handle_symbol(symbol_name, boot::type(symbol_info), symbols, unresolved); + handle_symbol(symbol_name, symbol_info, symbols, unresolved); } } return std::move(declaration_visitor.errors()); diff --git a/include/elna/gcc/elna-generic.h b/include/elna/gcc/elna-generic.h index 95ee7d7..14b9b0f 100644 --- a/include/elna/gcc/elna-generic.h +++ b/include/elna/gcc/elna-generic.h @@ -35,9 +35,10 @@ namespace elna::gcc std::deque> do_semantic_analysis(const char *path, std::unique_ptr& ast, std::shared_ptr info_table, std::shared_ptr symbols, std::unordered_map& unresolved); - tree handle_symbol(const std::string& symbol_name, const boot::type& type, + tree handle_symbol(const std::string& symbol_name, std::shared_ptr reference, std::shared_ptr symbols, std::unordered_map& unresolved); + class generic_visitor final : public boot::parser_visitor { tree current_expression{ NULL_TREE }; diff --git a/source.elna b/source.elna index 15cf78e..02afc8e 100644 --- a/source.elna +++ b/source.elna @@ -169,8 +169,8 @@ end proc write_i(value: Int); var - digit: Int - n: Word + digit: Int; + n: Word; buffer: [10]Char begin n := 10u; @@ -282,7 +282,7 @@ end proc read_source(filename: ^Char) -> ^SourceFile; var - result: ^SourceFile + result: ^SourceFile; file_handle: ^FILE begin file_handle := fopen(filename, "rb\0".ptr); @@ -473,9 +473,9 @@ end proc lex_string(source_code: ^SourceCode, token_content: ^StringBuffer) -> Bool; var - token_end, constructed_string: ^Char - token_length: Word - is_valid: Bool + token_end, constructed_string: ^Char; + token_length: Word; + is_valid: Bool; next_char: Char begin is_valid := true; @@ -509,7 +509,7 @@ end proc print_tokens(tokens: ^Token, tokens_size: Word); var - current_token: ^Token + current_token: ^Token; i: Word begin i := 0u; @@ -728,8 +728,8 @@ end proc tokenize(source_code: SourceCode, tokens_size: ^Word) -> ^Token; var - tokens, current_token: ^Token - first_char: Char + tokens, current_token: ^Token; + first_char: Char; token_buffer: StringBuffer begin tokens_size^ := 0u; @@ -905,8 +905,8 @@ end proc parse_command_line*(argc: Int, argv: ^^Char) -> ^CommandLine; var - parameter: ^^Char - i: Int + parameter: ^^Char; + i: Int; result: ^CommandLine begin i := 1; @@ -946,10 +946,10 @@ end proc process(argc: Int, argv: ^^Char) -> Int; var - tokens: ^Token - tokens_size: Word - source_code: SourceCode - command_line: ^CommandLine + tokens: ^Token; + tokens_size: Word; + source_code: SourceCode; + command_line: ^CommandLine; return_code: Int begin return_code := 0;