From bef747d558295b780f6e4c7e2b115da088bed0d8 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 9 Dec 2023 12:04:43 +0100 Subject: [PATCH] Fix analysis --- src/analysis.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/analysis.cpp b/src/analysis.cpp index e3c40be..25ce0d8 100644 --- a/src/analysis.cpp +++ b/src/analysis.cpp @@ -198,23 +198,31 @@ AnalysisResult analyze(Node &ast, Memory &memory) { } } break; case NodeType::Declaration: { - Token token = get(node.children[0]); + Token type_token = get(node.children[0]); + string type_string = get(type_token.data); + + Token token = get(node.children[1]); string identifier = get(token.data); + if (memory.contains(identifier)) throw TypeError("Already defined identifier \""+identifier+"\"", token.pos); - Type type = try_string_to_type(get(token.data), token.pos); + Type type = try_string_to_type(type_string, type_token.pos); memory.declare(identifier, type); return {}; } break; case NodeType::AssignedDeclaration: { - Token token = get(node.children[0]); + Token type_token = get(node.children[0]); + string type_string = get(type_token.data); + + Token token = get(node.children[1]); string identifier = get(token.data); + if (memory.contains(identifier)) throw TypeError("Already defined identifier \""+identifier+"\"", token.pos); - Type type = try_string_to_type(get(token.data), token.pos); + Type type = try_string_to_type(type_string, type_token.pos); memory.declare(identifier, type); get_cast(type, analyze(node.children[2], memory), get_node_pos(node));