Fix alias resolution with type declarations
This commit is contained in:
parent
d359056354
commit
413f23af4d
@ -524,11 +524,11 @@ variable_declaration: identifier_definitions ":" type_expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
variable_declarations:
|
variable_declarations:
|
||||||
variable_declaration variable_declarations
|
variable_declaration ";" variable_declarations
|
||||||
{
|
{
|
||||||
std::swap($$, $1);
|
std::swap($$, $1);
|
||||||
$$.reserve($$.size() + $2.size());
|
$$.reserve($$.size() + $3.size());
|
||||||
$$.insert(std::end($$), std::begin($2), std::end($2));
|
$$.insert(std::end($$), std::begin($3), std::end($3));
|
||||||
}
|
}
|
||||||
| variable_declaration { std::swap($$, $1); }
|
| variable_declaration { std::swap($$, $1); }
|
||||||
variable_part:
|
variable_part:
|
||||||
|
@ -41,14 +41,10 @@ namespace elna::gcc
|
|||||||
{
|
{
|
||||||
if (auto reference = type.get<boot::primitive_type>())
|
if (auto reference = type.get<boot::primitive_type>())
|
||||||
{
|
{
|
||||||
auto looked_up = unresolved.find(reference->identifier);
|
auto looked_up = symbols->lookup(reference->identifier);
|
||||||
if (looked_up == unresolved.cend())
|
if (looked_up != NULL_TREE)
|
||||||
{
|
{
|
||||||
return symbols->lookup(reference->identifier);
|
return TREE_TYPE(looked_up);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return looked_up->second;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (auto reference = type.get<boot::record_type>())
|
else if (auto reference = type.get<boot::record_type>())
|
||||||
@ -73,22 +69,20 @@ namespace elna::gcc
|
|||||||
}
|
}
|
||||||
else if (auto reference = type.get<boot::alias_type>())
|
else if (auto reference = type.get<boot::alias_type>())
|
||||||
{
|
{
|
||||||
return handle_symbol(reference->name, reference->reference, symbols, unresolved);
|
return handle_symbol(reference->name, reference, symbols, unresolved);
|
||||||
}
|
}
|
||||||
return error_mark_node;
|
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<boot::alias_type> reference,
|
||||||
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved)
|
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& 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;
|
return looked_up;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
|
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
|
||||||
@ -103,7 +97,7 @@ namespace elna::gcc
|
|||||||
{
|
{
|
||||||
for (auto& [symbol_name, symbol_info] : declaration_visitor.unresolved)
|
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());
|
return std::move(declaration_visitor.errors());
|
||||||
|
@ -35,9 +35,10 @@ namespace elna::gcc
|
|||||||
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
|
std::deque<std::unique_ptr<boot::error>> do_semantic_analysis(const char *path,
|
||||||
std::unique_ptr<boot::program>& ast, std::shared_ptr<boot::symbol_table> info_table,
|
std::unique_ptr<boot::program>& ast, std::shared_ptr<boot::symbol_table> info_table,
|
||||||
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
|
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
|
||||||
tree handle_symbol(const std::string& symbol_name, const boot::type& type,
|
tree handle_symbol(const std::string& symbol_name, std::shared_ptr<boot::alias_type> reference,
|
||||||
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
|
std::shared_ptr<symbol_table> symbols, std::unordered_map<std::string, tree>& unresolved);
|
||||||
|
|
||||||
|
|
||||||
class generic_visitor final : public boot::parser_visitor
|
class generic_visitor final : public boot::parser_visitor
|
||||||
{
|
{
|
||||||
tree current_expression{ NULL_TREE };
|
tree current_expression{ NULL_TREE };
|
||||||
|
30
source.elna
30
source.elna
@ -169,8 +169,8 @@ end
|
|||||||
|
|
||||||
proc write_i(value: Int);
|
proc write_i(value: Int);
|
||||||
var
|
var
|
||||||
digit: Int
|
digit: Int;
|
||||||
n: Word
|
n: Word;
|
||||||
buffer: [10]Char
|
buffer: [10]Char
|
||||||
begin
|
begin
|
||||||
n := 10u;
|
n := 10u;
|
||||||
@ -282,7 +282,7 @@ end
|
|||||||
|
|
||||||
proc read_source(filename: ^Char) -> ^SourceFile;
|
proc read_source(filename: ^Char) -> ^SourceFile;
|
||||||
var
|
var
|
||||||
result: ^SourceFile
|
result: ^SourceFile;
|
||||||
file_handle: ^FILE
|
file_handle: ^FILE
|
||||||
begin
|
begin
|
||||||
file_handle := fopen(filename, "rb\0".ptr);
|
file_handle := fopen(filename, "rb\0".ptr);
|
||||||
@ -473,9 +473,9 @@ end
|
|||||||
|
|
||||||
proc lex_string(source_code: ^SourceCode, token_content: ^StringBuffer) -> Bool;
|
proc lex_string(source_code: ^SourceCode, token_content: ^StringBuffer) -> Bool;
|
||||||
var
|
var
|
||||||
token_end, constructed_string: ^Char
|
token_end, constructed_string: ^Char;
|
||||||
token_length: Word
|
token_length: Word;
|
||||||
is_valid: Bool
|
is_valid: Bool;
|
||||||
next_char: Char
|
next_char: Char
|
||||||
begin
|
begin
|
||||||
is_valid := true;
|
is_valid := true;
|
||||||
@ -509,7 +509,7 @@ end
|
|||||||
|
|
||||||
proc print_tokens(tokens: ^Token, tokens_size: Word);
|
proc print_tokens(tokens: ^Token, tokens_size: Word);
|
||||||
var
|
var
|
||||||
current_token: ^Token
|
current_token: ^Token;
|
||||||
i: Word
|
i: Word
|
||||||
begin
|
begin
|
||||||
i := 0u;
|
i := 0u;
|
||||||
@ -728,8 +728,8 @@ end
|
|||||||
|
|
||||||
proc tokenize(source_code: SourceCode, tokens_size: ^Word) -> ^Token;
|
proc tokenize(source_code: SourceCode, tokens_size: ^Word) -> ^Token;
|
||||||
var
|
var
|
||||||
tokens, current_token: ^Token
|
tokens, current_token: ^Token;
|
||||||
first_char: Char
|
first_char: Char;
|
||||||
token_buffer: StringBuffer
|
token_buffer: StringBuffer
|
||||||
begin
|
begin
|
||||||
tokens_size^ := 0u;
|
tokens_size^ := 0u;
|
||||||
@ -905,8 +905,8 @@ end
|
|||||||
|
|
||||||
proc parse_command_line*(argc: Int, argv: ^^Char) -> ^CommandLine;
|
proc parse_command_line*(argc: Int, argv: ^^Char) -> ^CommandLine;
|
||||||
var
|
var
|
||||||
parameter: ^^Char
|
parameter: ^^Char;
|
||||||
i: Int
|
i: Int;
|
||||||
result: ^CommandLine
|
result: ^CommandLine
|
||||||
begin
|
begin
|
||||||
i := 1;
|
i := 1;
|
||||||
@ -946,10 +946,10 @@ end
|
|||||||
|
|
||||||
proc process(argc: Int, argv: ^^Char) -> Int;
|
proc process(argc: Int, argv: ^^Char) -> Int;
|
||||||
var
|
var
|
||||||
tokens: ^Token
|
tokens: ^Token;
|
||||||
tokens_size: Word
|
tokens_size: Word;
|
||||||
source_code: SourceCode
|
source_code: SourceCode;
|
||||||
command_line: ^CommandLine
|
command_line: ^CommandLine;
|
||||||
return_code: Int
|
return_code: Int
|
||||||
begin
|
begin
|
||||||
return_code := 0;
|
return_code := 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user