]> gitweb.ps.run Git - toc/blobdiff - src/typeInfo.h
add comments, fix struct/function lookup
[toc] / src / typeInfo.h
index 89fff2a1800d7ceebaed464a9c6c6cebc6314d0d..10b4097ffe486594dd9cb44e8bf0c80f7bf6e93e 100644 (file)
@@ -24,7 +24,7 @@ TypeInfo typeType(const Program & p, Type t)
   return result;\r
 }\r
 \r
-TypeInfo typeExpr(const Program & p, const std::vector<std::string> & globalNamespace, std::shared_ptr<Context> globalCtx, Expr e)\r
+TypeInfo typeExpr(const Program & p, std::shared_ptr<Context> globalCtx, Expr e)\r
 {\r
   TypeInfo result;\r
 \r
@@ -32,28 +32,24 @@ TypeInfo typeExpr(const Program & p, const std::vector<std::string> & globalName
   {\r
   case ExprType::Func:\r
   {\r
-    auto namespacePrefixes = globalNamespace;\r
-    namespacePrefixes.insert(namespacePrefixes.end(),\r
-      e._func.namespacePrefixes.begin(),\r
-      e._func.namespacePrefixes.end());\r
     auto f = findFunction(e._func.functionName, e._func.namespacePrefixes, globalCtx);\r
     if (!f.has_value())\r
       throw "Unknown function";\r
-    result = typeType(p, f.value().returnType);\r
+    result = typeType(p, std::get<0>(*f).returnType);\r
     break;\r
   }\r
   case ExprType::Method:\r
   {\r
-    TypeInfo tiCaller = typeExpr(p, globalNamespace, globalCtx, *e._method.expr);\r
+    TypeInfo tiCaller = typeExpr(p, globalCtx, *e._method.expr);\r
     if (!tiCaller.isStruct)\r
       throw "Calling method on non-struct";\r
     auto s = findStruct(tiCaller.type.name, tiCaller.type.namespacePrefixes, globalCtx);\r
     if (!s.has_value())\r
       throw "Calling method on unknown struct";\r
-    auto m = findStructMethod(e._method.methodName, s.value());\r
+    auto m = findStructMethod(e._method.methodName, std::get<0>(*s));\r
     if (!m.has_value())\r
       throw "Unknown method";\r
-    result = typeType(p, m.value().t.returnType);\r
+    result = typeType(p, m->t.returnType);\r
     break;\r
   }\r
   case ExprType::Lit:\r
@@ -67,37 +63,37 @@ TypeInfo typeExpr(const Program & p, const std::vector<std::string> & globalName
     }\r
     break;\r
   case ExprType::Paren:\r
-    result = typeExpr(p, globalNamespace, globalCtx, *e._paren.expr);\r
+    result = typeExpr(p, globalCtx, *e._paren.expr);\r
     break;\r
   case ExprType::Dot:\r
   {\r
-    auto tiCaller = typeExpr(p, globalNamespace, globalCtx, *e._dot.expr);\r
+    auto tiCaller = typeExpr(p, globalCtx, *e._dot.expr);\r
     if (!tiCaller.isStruct)\r
       throw "Accessing member of non-struct";\r
     auto s = findStruct(tiCaller.type.name, tiCaller.type.namespacePrefixes, globalCtx);\r
     if (!s.has_value())\r
       throw "Calling method on unknown struct";\r
-    auto sm = findStructMember(e._dot.identifier, s.value());\r
+    auto sm = findStructMember(e._dot.identifier, std::get<0>(*s));\r
     if (!sm.has_value())\r
       throw "Unknown struct member";\r
-    result = typeType(p, sm.value().t.type);\r
+    result = typeType(p, sm->t.type);\r
     break;\r
   }\r
   case ExprType::PrefixOp:\r
-    result = typeExpr(p, globalNamespace, globalCtx, *e._prefixOp.expr);\r
+    result = typeExpr(p, globalCtx, *e._prefixOp.expr);\r
     break;\r
   case ExprType::PostfixOp:\r
-    result = typeExpr(p, globalNamespace, globalCtx, *e._postfixOp.expr);\r
+    result = typeExpr(p, globalCtx, *e._postfixOp.expr);\r
     break;\r
   case ExprType::BinaryOp:\r
-    result = typeExpr(p, globalNamespace, globalCtx, *e._binaryOp.lexpr);\r
+    result = typeExpr(p, globalCtx, *e._binaryOp.lexpr);\r
     break;\r
   case ExprType::TernaryOp:\r
-    result = typeExpr(p, globalNamespace, globalCtx, *e._ternaryOp.rexprTrue);\r
+    result = typeExpr(p, globalCtx, *e._ternaryOp.rexprTrue);\r
     break;\r
   case ExprType::Bracket:\r
   {\r
-    TypeInfo ti = typeExpr(p, globalNamespace, globalCtx, *e._brackets.lexpr);\r
+    TypeInfo ti = typeExpr(p, globalCtx, *e._brackets.lexpr);\r
     if (!ti.type.modifiers.empty())\r
     {\r
       result = ti;\r
@@ -110,14 +106,10 @@ TypeInfo typeExpr(const Program & p, const std::vector<std::string> & globalName
   }\r
   case ExprType::Identifier:\r
   {\r
-    auto namespacePrefixes = globalNamespace;\r
-    namespacePrefixes.insert(namespacePrefixes.end(),\r
-      e._identifier.namespacePrefixes.begin(),\r
-      e._identifier.namespacePrefixes.end());\r
-    auto v = findVariable(e._identifier.identifier, namespacePrefixes, globalCtx);\r
+    auto v = findVariable(e._identifier.identifier, e._identifier.namespacePrefixes, globalCtx);\r
     if (!v.has_value())\r
       throw "Unknown variable";\r
-    result = typeType(p, v.value().type);\r
+    result = typeType(p, std::get<0>(*v).type);\r
     break;\r
   }\r
   }\r