From 36ec04c00fa540fcee0f2cff1f7b81dd8a98101a Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Thu, 17 Apr 2025 18:44:58 +0000
Subject: [PATCH] some refactor

---
 src/Parser/ParsedExpression.hpp |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/src/Parser/ParsedExpression.hpp b/src/Parser/ParsedExpression.hpp
index 3f74478..54cce5d 100644
--- a/src/Parser/ParsedExpression.hpp
+++ b/src/Parser/ParsedExpression.hpp
@@ -4,6 +4,7 @@
 #include <memory>
 #include <string>
 
+#include "Symbols/SymbolContainer.hpp"
 #include "Symbols/Value.hpp"
 
 namespace Parser {
@@ -59,6 +60,46 @@
         expr->rhs  = std::move(operand);
         return expr;
     }
+
+    Symbols::Variables::Type getType() const {
+        switch (kind) {
+            case Kind::Literal:
+                return value.getType();
+                break;
+
+            case Kind::Variable:
+                {
+                    const auto ns     = Symbols::SymbolContainer::instance()->currentScopeName() + ".variables";
+                    auto       symbol = Symbols::SymbolContainer::instance()->get(ns, name);
+                    if (!symbol) {
+                        throw std::runtime_error("Unknown variable: " + name + " in namespace: " + ns +
+                                                 " File: " + __FILE__ + ":" + std::to_string(__LINE__));
+                    }
+                    return symbol->getValue().getType();
+                }
+
+            case Kind::Binary:
+                {
+                    auto lhsType = lhs->value.getType();
+                    //auto rhsType = rhs->value.getType();
+                    return lhsType;  // Bináris kifejezésnél a típusok azonosak, tehát a bal oldali típust visszaadhatjuk
+                }
+
+            case Kind::Unary:
+                {
+                    //auto operandType = op.
+                    if (op == "!") {
+                        return Symbols::Variables::Type::BOOLEAN;  // Mivel a '!' operátor bool típust vár
+                    }
+                    break;
+                }
+
+            default:
+                throw std::runtime_error("Unknown expression kind");
+        }
+
+        throw std::runtime_error("Could not determine type for expression");
+    }
 };
 
 }  // namespace Parser

--
Gitblit v1.9.3