abouttreesummaryrefslogcommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/toc.h11
-rw-r--r--src/typeInfo.h29
2 files changed, 22 insertions, 18 deletions
diff --git a/src/toc.h b/src/toc.h
index c58e2fc..e95ab3e 100644
--- a/src/toc.h
+++ b/src/toc.h
@@ -84,7 +84,7 @@ std::ostream & operator<< (std::ostream & out, const Type & t)
return out;
}
}
- TypeInfo ti = typeType(globalPrg, t);
+ TypeInfo ti = typeType(globalCtx, t);
if (ti.isStruct)
out << "struct ";
auto s = findStruct(t.name, t.namespacePrefixes, globalCtx);
@@ -178,13 +178,16 @@ std::ostream & operator<< (std::ostream & out, const Expr & e)
}
case ExprType::Method:
{
- TypeInfo ti = typeExpr(globalPrg, globalCtx, *e._method.expr);
+ TypeInfo ti = typeExpr(globalCtx, *e._method.expr);
out <<
vectorStr(ti.type.namespacePrefixes, "_", true) <<
ti.type.name << genericAppendix(ti.type.genericInstantiation) << "_" << e._method.methodName;
if (!e._method.genericInstantiation.empty())
out << genericAppendix(e._method.genericInstantiation);
- out << "(&" << *e._method.expr << (e._method.arguments.empty() ? "" : ", ") <<
+ out << "(";
+ if (e._method.expr->type == ExprType::Identifier)
+ out << "&";
+ out << *e._method.expr << (e._method.arguments.empty() ? "" : ", ") <<
vectorStr(e._method.arguments, ", ") << ")"; break;
}
case ExprType::Lit:
@@ -194,7 +197,7 @@ std::ostream & operator<< (std::ostream & out, const Expr & e)
else if (e._lit.type == LitType::Bool) out << e._lit._bool;
break;
case ExprType::Paren:
- out << "(" << e._paren.expr << ")"; break;
+ out << "(" << *e._paren.expr << ")"; break;
case ExprType::Dot:
out << *e._dot.expr << (e._dot.isPointer ? "->" : ".") << e._dot.identifier; break;
case ExprType::PrefixOp:
diff --git a/src/typeInfo.h b/src/typeInfo.h
index 10b4097..e813612 100644
--- a/src/typeInfo.h
+++ b/src/typeInfo.h
@@ -10,7 +10,7 @@ struct TypeInfo
#include "find.h"
-TypeInfo typeType(const Program & p, Type t)
+TypeInfo typeType(std::shared_ptr<Context> globalCtx, Type t)
{
TypeInfo result;
result.isStruct = true;
@@ -21,10 +21,11 @@ TypeInfo typeType(const Program & p, Type t)
result.isStruct = false;
}
result.type = t;
+
return result;
}
-TypeInfo typeExpr(const Program & p, std::shared_ptr<Context> globalCtx, Expr e)
+TypeInfo typeExpr(std::shared_ptr<Context> globalCtx, Expr e)
{
TypeInfo result;
@@ -35,12 +36,12 @@ TypeInfo typeExpr(const Program & p, std::shared_ptr<Context> globalCtx, Expr e)
auto f = findFunction(e._func.functionName, e._func.namespacePrefixes, globalCtx);
if (!f.has_value())
throw "Unknown function";
- result = typeType(p, std::get<0>(*f).returnType);
+ result = typeType(globalCtx, std::get<0>(*f).returnType);
break;
}
case ExprType::Method:
{
- TypeInfo tiCaller = typeExpr(p, globalCtx, *e._method.expr);
+ TypeInfo tiCaller = typeExpr(globalCtx, *e._method.expr);
if (!tiCaller.isStruct)
throw "Calling method on non-struct";
auto s = findStruct(tiCaller.type.name, tiCaller.type.namespacePrefixes, globalCtx);
@@ -49,7 +50,7 @@ TypeInfo typeExpr(const Program & p, std::shared_ptr<Context> globalCtx, Expr e)
auto m = findStructMethod(e._method.methodName, std::get<0>(*s));
if (!m.has_value())
throw "Unknown method";
- result = typeType(p, m->t.returnType);
+ result = typeType(globalCtx, m->t.returnType);
break;
}
case ExprType::Lit:
@@ -63,11 +64,11 @@ TypeInfo typeExpr(const Program & p, std::shared_ptr<Context> globalCtx, Expr e)
}
break;
case ExprType::Paren:
- result = typeExpr(p, globalCtx, *e._paren.expr);
+ result = typeExpr(globalCtx, *e._paren.expr);
break;
case ExprType::Dot:
{
- auto tiCaller = typeExpr(p, globalCtx, *e._dot.expr);
+ auto tiCaller = typeExpr(globalCtx, *e._dot.expr);
if (!tiCaller.isStruct)
throw "Accessing member of non-struct";
auto s = findStruct(tiCaller.type.name, tiCaller.type.namespacePrefixes, globalCtx);
@@ -76,24 +77,24 @@ TypeInfo typeExpr(const Program & p, std::shared_ptr<Context> globalCtx, Expr e)
auto sm = findStructMember(e._dot.identifier, std::get<0>(*s));
if (!sm.has_value())
throw "Unknown struct member";
- result = typeType(p, sm->t.type);
+ result = typeType(globalCtx, sm->t.type);
break;
}
case ExprType::PrefixOp:
- result = typeExpr(p, globalCtx, *e._prefixOp.expr);
+ result = typeExpr(globalCtx, *e._prefixOp.expr);
break;
case ExprType::PostfixOp:
- result = typeExpr(p, globalCtx, *e._postfixOp.expr);
+ result = typeExpr(globalCtx, *e._postfixOp.expr);
break;
case ExprType::BinaryOp:
- result = typeExpr(p, globalCtx, *e._binaryOp.lexpr);
+ result = typeExpr(globalCtx, *e._binaryOp.lexpr);
break;
case ExprType::TernaryOp:
- result = typeExpr(p, globalCtx, *e._ternaryOp.rexprTrue);
+ result = typeExpr(globalCtx, *e._ternaryOp.rexprTrue);
break;
case ExprType::Bracket:
{
- TypeInfo ti = typeExpr(p, globalCtx, *e._brackets.lexpr);
+ TypeInfo ti = typeExpr(globalCtx, *e._brackets.lexpr);
if (!ti.type.modifiers.empty())
{
result = ti;
@@ -109,7 +110,7 @@ TypeInfo typeExpr(const Program & p, std::shared_ptr<Context> globalCtx, Expr e)
auto v = findVariable(e._identifier.identifier, e._identifier.namespacePrefixes, globalCtx);
if (!v.has_value())
throw "Unknown variable";
- result = typeType(p, std::get<0>(*v).type);
+ result = typeType(globalCtx, std::get<0>(*v).type);
break;
}
}