// CPPParserSymExpr.cpp: Creation of expressions for the grammar
#include "CPPParserSym.h"
#include "CPPSymTable.h"
#include "CPPExpr.h"
CPPExprRefI
CPPParserSym::MakeExprBinary(
CPPExprRefI lhs,
CPPExprRefI rhs,
ANTLRTokenType opToken
)
{
return new CPPExprBinary(lhs, rhs, opToken);
}
CPPExprRefI
CPPParserSym::MakeExprUnary(
CPPExprRefI rhs,
ANTLRTokenType opToken
)
{
return new CPPExprUnary(rhs, opToken);
}
CPPExprRefI
CPPParserSym::MakeExprConditional(
CPPExprRefI condition,
CPPExprRefI lhs,
CPPExprRefI rhs
)
{
return new CPPExprConditional(condition, lhs, rhs);
}
CPPExprRefI
CPPParserSym::MakeExprLiteral(
ANTLRTokenType tokType,
const JLStr& tokText
)
{
return new CPPExprLiteral(tokType, tokText);
}
CPPExprRefI
CPPParserSym::MakeExprSizeofExpr(
CPPExprRefI expr
)
{
return new CPPExprSizeofExpr(expr);
}
CPPExprRefI
CPPParserSym::MakeExprSizeofType(
CPPTypeRefI type
)
{
return new CPPExprSizeofType(type);
}
CPPExprRefI
CPPParserSym::MakeExprId(
CPPDeclRefI decl
)
{
return new CPPExprId(decl);
}
CPPExprRefI
CPPParserSym::MakeExprNewCast(
ANTLRTokenType castTokenType,
CPPTypeRefI castType,
CPPExprRefI expr
)
{
CPPExprCast::CastFlavor castFlavor;
switch (castTokenType)
{
case TOK_CONST_CAST:
castFlavor = CPPExprCast::Const;
break;
case TOK_DYNAMIC_CAST:
castFlavor = CPPExprCast::Dynamic;
break;
case TOK_REINTERPRET_CAST:
castFlavor = CPPExprCast::Reinterpret;
break;
case TOK_STATIC_CAST:
castFlavor = CPPExprCast::Static;
break;
default:
assert(0);
break;
}
return new CPPExprCast(castFlavor, castType, expr);
}
CPPExprRefI
CPPParserSym::MakeExprTraditionalCast(
CPPTypeRefI castType,
CPPExprRefI expr
)
{
return new CPPExprCast(CPPExprCast::Traditional, castType, expr);
}
CPPExprRefI
CPPParserSym::MakeExprFunctionLikeCast(
CPPTypeRefI castType,
CPPExprRefI expr
)
{
return new CPPExprCast(CPPExprCast::FunctionLike, castType, expr);
}
CPPExprRefI
CPPParserSym::MakeExprNew(
CPPExprRefI placementExpr,
CPPTypeRefI rawType,
CPPExprRefI arraySizeExpr,
CPPExprRefI initExpr,
const ANTLRTokenPtr& errTok
)
{
CPPTypeRefI arrayType;
// Determine the array type, which is the same as the raw type
// when the arraySizeExpr is nil
if (arraySizeExpr.get() == 0)
{
arrayType = rawType;
} else {
arrayType = symTable->LookupArrayOfType(rawType, CPPExprRefI(), errTok);
}
return new CPPExprNew(placementExpr, rawType, arrayType, arraySizeExpr, initExpr);
}
CPPExprRefI
CPPParserSym::MakeExprDelete(
CPPExprRefI exprToDelete,
bool deleteArray
)
{
return new CPPExprDelete(exprToDelete, deleteArray);
}
CPPExprRefI
CPPParserSym::MakeExprFunctionCall(
CPPExprRefI exprFunction,
CPPExprRefI exprArgList
)
{
return new CPPExprFunctionCall(exprFunction, exprArgList);
}
CPPExprRefI
CPPParserSym::MakeExprPostop(
CPPExprRefI exprLhs,
ANTLRTokenType tt
)
{
return new CPPExprPostop(exprLhs, tt);
}
CPPExprRefI
CPPParserSym::MakeExprThis()
{
return new CPPExprThis();
}
CPPExprRefI
CPPParserSym::MakeExprArraySubscript(
CPPExprRefI lhs,
CPPExprRefI exprSubscript
)
{
return new CPPExprArraySubscript(lhs, exprSubscript);
}