Fix analysis
This commit is contained in:
parent
5cce75f835
commit
bef747d558
@ -198,23 +198,31 @@ AnalysisResult analyze(Node &ast, Memory &memory) {
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case NodeType::Declaration: {
|
case NodeType::Declaration: {
|
||||||
Token token = get<Token>(node.children[0]);
|
Token type_token = get<Token>(node.children[0]);
|
||||||
|
string type_string = get<string>(type_token.data);
|
||||||
|
|
||||||
|
Token token = get<Token>(node.children[1]);
|
||||||
string identifier = get<string>(token.data);
|
string identifier = get<string>(token.data);
|
||||||
|
|
||||||
if (memory.contains(identifier))
|
if (memory.contains(identifier))
|
||||||
throw TypeError("Already defined identifier \""+identifier+"\"", token.pos);
|
throw TypeError("Already defined identifier \""+identifier+"\"", token.pos);
|
||||||
|
|
||||||
Type type = try_string_to_type(get<string>(token.data), token.pos);
|
Type type = try_string_to_type(type_string, type_token.pos);
|
||||||
memory.declare(identifier, type);
|
memory.declare(identifier, type);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
} break;
|
} break;
|
||||||
case NodeType::AssignedDeclaration: {
|
case NodeType::AssignedDeclaration: {
|
||||||
Token token = get<Token>(node.children[0]);
|
Token type_token = get<Token>(node.children[0]);
|
||||||
|
string type_string = get<string>(type_token.data);
|
||||||
|
|
||||||
|
Token token = get<Token>(node.children[1]);
|
||||||
string identifier = get<string>(token.data);
|
string identifier = get<string>(token.data);
|
||||||
|
|
||||||
if (memory.contains(identifier))
|
if (memory.contains(identifier))
|
||||||
throw TypeError("Already defined identifier \""+identifier+"\"", token.pos);
|
throw TypeError("Already defined identifier \""+identifier+"\"", token.pos);
|
||||||
|
|
||||||
Type type = try_string_to_type(get<string>(token.data), token.pos);
|
Type type = try_string_to_type(type_string, type_token.pos);
|
||||||
memory.declare(identifier, type);
|
memory.declare(identifier, type);
|
||||||
|
|
||||||
get_cast(type, analyze(node.children[2], memory), get_node_pos(node));
|
get_cast(type, analyze(node.children[2], memory), get_node_pos(node));
|
||||||
|
Loading…
Reference in New Issue
Block a user