X-Git-Url: https://gitweb.ps.run/toc/blobdiff_plain/be56e29997e17685eebf8bd7cb745183c60de7db..b9322dfb8efe37f6f88a899269bdf21015f4db9a:/src/typeInfo.h diff --git a/src/typeInfo.h b/src/typeInfo.h index 3914847..cbe421c 100644 --- a/src/typeInfo.h +++ b/src/typeInfo.h @@ -15,7 +15,8 @@ TypeInfo typeType(const Program & p, Type t) TypeInfo result; result.isStruct = true; if (t.name == "int" || t.name == "float" || t.name == "double" || - t.name == "char" || t.name == "long" || t.name == "short" || t.name == "bool") + t.name == "char" || t.name == "long" || t.name == "short" || t.name == "bool" || + t.name == "void") { result.isStruct = false; } @@ -23,7 +24,7 @@ TypeInfo typeType(const Program & p, Type t) return result; } -TypeInfo typeExpr(const Program & p, const std::vector & globalNamespace, Expr e) +TypeInfo typeExpr(const Program & p, const std::vector & globalNamespace, std::shared_ptr globalCtx, Expr e) { TypeInfo result; @@ -43,11 +44,11 @@ TypeInfo typeExpr(const Program & p, const std::vector & globalNamespace } case ExprType::Method: { - TypeInfo tiCaller = typeExpr(p, globalNamespace, *e._method.expr); + TypeInfo tiCaller = typeExpr(p, globalNamespace, globalCtx, *e._method.expr); auto m = findStructMethod(p, e._method.methodName, tiCaller); if (!m.has_value()) throw "Unknown method"; - result = typeType(p, m.value().returnType); + result = typeType(p, m.value().t.returnType); break; } case ExprType::Lit: @@ -61,32 +62,32 @@ TypeInfo typeExpr(const Program & p, const std::vector & globalNamespace } break; case ExprType::Paren: - result = typeExpr(p, globalNamespace, *e._paren.expr); + result = typeExpr(p, globalNamespace, globalCtx, *e._paren.expr); break; case ExprType::Dot: { auto sm = findStructMember(p, - typeExpr(p, globalNamespace, *e._dot.expr), e._dot.identifier); + typeExpr(p, globalNamespace, globalCtx, *e._dot.expr), e._dot.identifier); if (!sm.has_value()) throw "Unknown struct member"; - result = typeType(p, sm.value().type); + result = typeType(p, sm.value().t.type); break; } case ExprType::PrefixOp: - result = typeExpr(p, globalNamespace, *e._prefixOp.expr); + result = typeExpr(p, globalNamespace, globalCtx, *e._prefixOp.expr); break; case ExprType::PostfixOp: - result = typeExpr(p, globalNamespace, *e._postfixOp.expr); + result = typeExpr(p, globalNamespace, globalCtx, *e._postfixOp.expr); break; case ExprType::BinaryOp: - result = typeExpr(p, globalNamespace, *e._binaryOp.lexpr); + result = typeExpr(p, globalNamespace, globalCtx, *e._binaryOp.lexpr); break; case ExprType::TernaryOp: - result = typeExpr(p, globalNamespace, *e._ternaryOp.rexprTrue); + result = typeExpr(p, globalNamespace, globalCtx, *e._ternaryOp.rexprTrue); break; case ExprType::Bracket: { - TypeInfo ti = typeExpr(p, globalNamespace, *e._brackets.lexpr); + TypeInfo ti = typeExpr(p, globalNamespace, globalCtx, *e._brackets.lexpr); if (!ti.type.modifiers.empty()) { result = ti; @@ -103,7 +104,7 @@ TypeInfo typeExpr(const Program & p, const std::vector & globalNamespace namespacePrefixes.insert(namespacePrefixes.end(), e._identifier.namespacePrefixes.begin(), e._identifier.namespacePrefixes.end()); - auto v = findVariable(p, e._identifier.identifier, namespacePrefixes); + auto v = findVariable(p, e._identifier.identifier, globalCtx); if (!v.has_value()) throw "Unknown variable"; result = typeType(p, v.value().type);