More C++ aggregate initialization
This commit is contained in:
parent
803b868356
commit
f0b9b5cce4
|
@ -335,6 +335,9 @@ void Expression::Dump(int ident) const
|
||||||
case EX_LABEL:
|
case EX_LABEL:
|
||||||
printf("LABEL %s", mDecValue->mIdent->mString);
|
printf("LABEL %s", mDecValue->mIdent->mString);
|
||||||
break;
|
break;
|
||||||
|
case EX_AGGREGATE:
|
||||||
|
printf("AGGREGATE");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,8 @@ enum ExpressionType
|
||||||
EX_PACK,
|
EX_PACK,
|
||||||
EX_PACK_TYPE,
|
EX_PACK_TYPE,
|
||||||
EX_LABEL,
|
EX_LABEL,
|
||||||
EX_GOTO
|
EX_GOTO,
|
||||||
|
EX_AGGREGATE
|
||||||
};
|
};
|
||||||
|
|
||||||
class Expression
|
class Expression
|
||||||
|
|
|
@ -1246,7 +1246,7 @@ void InterCodeGenerator::TranslateAssembler(InterCodeModule* mod, Declaration *
|
||||||
cexp = cexp->mRight;
|
cexp = cexp->mRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(offset < osize);
|
assert(offset == osize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterCodeGenerator::BuildSwitchTree(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock* block, InlineMapper * inlineMapper, ExValue v, const SwitchNodeArray& nodes, int left, int right, int vleft, int vright, InterCodeBasicBlock* dblock)
|
void InterCodeGenerator::BuildSwitchTree(InterCodeProcedure* proc, Expression* exp, InterCodeBasicBlock* block, InlineMapper * inlineMapper, ExValue v, const SwitchNodeArray& nodes, int left, int right, int vleft, int vright, InterCodeBasicBlock* dblock)
|
||||||
|
@ -5442,6 +5442,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
||||||
return ExValue(TheVoidTypeDeclaration);
|
return ExValue(TheVoidTypeDeclaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case EX_AGGREGATE:
|
||||||
|
mErrors->Error(exp->mLocation, EERR_INVALID_INITIALIZER, "Unexpected aggreate");
|
||||||
|
return ExValue(TheVoidTypeDeclaration);
|
||||||
|
|
||||||
case EX_SWITCH:
|
case EX_SWITCH:
|
||||||
{
|
{
|
||||||
DestructStack* odestack = destack;
|
DestructStack* odestack = destack;
|
||||||
|
|
|
@ -2503,7 +2503,7 @@ Expression* Parser::BuildMemberInitializer(Expression* vexp)
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
||||||
{
|
{
|
||||||
fexp->mRight = ParseListExpression(false);
|
fexp->mRight = ParseListExpression(false, fcons->mBase->mParams->mNext);
|
||||||
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -4496,6 +4496,8 @@ Expression * Parser::BuildVariableInit(Expression* vexp, Expression* pexp)
|
||||||
|
|
||||||
void Parser::ParseVariableInit(Declaration* ndec, Expression* pexp)
|
void Parser::ParseVariableInit(Declaration* ndec, Expression* pexp)
|
||||||
{
|
{
|
||||||
|
Declaration* fcons = ndec->mBase->mScope ? ndec->mBase->mScope->Lookup(ndec->mBase->mIdent->PreMangle("+"), SLEVEL_CLASS) : nullptr;
|
||||||
|
|
||||||
if (!pexp)
|
if (!pexp)
|
||||||
{
|
{
|
||||||
Token ctoken = mScanner->mToken == TK_OPEN_BRACE ? TK_CLOSE_BRACE : TK_CLOSE_PARENTHESIS;
|
Token ctoken = mScanner->mToken == TK_OPEN_BRACE ? TK_CLOSE_BRACE : TK_CLOSE_PARENTHESIS;
|
||||||
|
@ -4503,15 +4505,13 @@ void Parser::ParseVariableInit(Declaration* ndec, Expression* pexp)
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
if (mScanner->mToken != ctoken)
|
if (mScanner->mToken != ctoken)
|
||||||
{
|
{
|
||||||
pexp = ParseListExpression(false);
|
pexp = ParseListExpression(false, fcons ? fcons->mBase->mParams->mNext : nullptr);
|
||||||
ConsumeToken(ctoken);
|
ConsumeToken(ctoken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
Declaration* fcons = ndec->mBase->mScope ? ndec->mBase->mScope->Lookup(ndec->mBase->mIdent->PreMangle("+"), SLEVEL_CLASS) : nullptr;
|
|
||||||
|
|
||||||
if (ndec->mBase->mFlags & DTF_PURE_VIRTUAL)
|
if (ndec->mBase->mFlags & DTF_PURE_VIRTUAL)
|
||||||
mErrors->Error(ndec->mLocation, ERRR_INSTANTIATE_ABSTRACT_CLASS, "Cannot instantiate abstract class", ndec->mIdent);
|
mErrors->Error(ndec->mLocation, ERRR_INSTANTIATE_ABSTRACT_CLASS, "Cannot instantiate abstract class", ndec->mIdent);
|
||||||
|
|
||||||
|
@ -6616,18 +6616,25 @@ Expression* Parser::ParseSimpleExpression(bool lhs, bool tid)
|
||||||
{
|
{
|
||||||
if ((dec->mType == DT_ELEMENT || dec->mType == DT_CONST_FUNCTION) && !(dec->mFlags & DTF_STATIC))
|
if ((dec->mType == DT_ELEMENT || dec->mType == DT_CONST_FUNCTION) && !(dec->mFlags & DTF_STATIC))
|
||||||
{
|
{
|
||||||
Expression* texp = new Expression(mScanner->mLocation, EX_VARIABLE);
|
if (mThisPointer->mType == DT_TYPE_POINTER)
|
||||||
texp->mDecType = mThisPointer->mBase;
|
{
|
||||||
texp->mDecValue = mThisPointer;
|
mErrors->Error(mScanner->mLocation, ERRO_THIS_OUTSIDE_OF_METHOD, "Invalid non static member");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Expression* texp = new Expression(mScanner->mLocation, EX_VARIABLE);
|
||||||
|
texp->mDecType = mThisPointer->mBase;
|
||||||
|
texp->mDecValue = mThisPointer;
|
||||||
|
|
||||||
Expression* dexp = new Expression(mScanner->mLocation, EX_PREFIX);
|
Expression* dexp = new Expression(mScanner->mLocation, EX_PREFIX);
|
||||||
dexp->mToken = TK_MUL;
|
dexp->mToken = TK_MUL;
|
||||||
dexp->mDecType = texp->mDecType->mBase;
|
dexp->mDecType = texp->mDecType->mBase;
|
||||||
dexp->mLeft = texp;
|
dexp->mLeft = texp;
|
||||||
|
|
||||||
dexp = dexp->ConstantFold(mErrors, mDataSection);
|
dexp = dexp->ConstantFold(mErrors, mDataSection);
|
||||||
|
|
||||||
exp = ParseQualify(dexp);
|
exp = ParseQualify(dexp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
|
@ -6805,6 +6812,13 @@ Expression* Parser::ParseSimpleExpression(bool lhs, bool tid)
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TK_OPEN_BRACE:
|
||||||
|
mScanner->NextToken();
|
||||||
|
exp = new Expression(mScanner->mLocation, EX_AGGREGATE);
|
||||||
|
exp->mLeft = ParseListExpression(false);
|
||||||
|
exp->mDecType = TheConstVoidTypeDeclaration;
|
||||||
|
ConsumeToken(TK_CLOSE_BRACE);
|
||||||
|
break;
|
||||||
case TK_ASM:
|
case TK_ASM:
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
if (mScanner->mToken == TK_OPEN_BRACE)
|
if (mScanner->mToken == TK_OPEN_BRACE)
|
||||||
|
@ -6981,7 +6995,7 @@ Expression* Parser::ParseQualify(Expression* exp)
|
||||||
nexp->mRight = nullptr;
|
nexp->mRight = nullptr;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nexp->mRight = ParseListExpression(false);
|
nexp->mRight = ParseListExpression(false, mdec->mBase->mParams->mNext);
|
||||||
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7712,6 +7726,10 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
nexp->mDecType = TheVoidTypeDeclaration;
|
nexp->mDecType = TheVoidTypeDeclaration;
|
||||||
exp = nexp->ConstantFold(mErrors, mDataSection, mCompilationUnits->mLinker);
|
exp = nexp->ConstantFold(mErrors, mDataSection, mCompilationUnits->mLinker);
|
||||||
}
|
}
|
||||||
|
else if (mScanner->mToken == TK_OPEN_BRACE)
|
||||||
|
{
|
||||||
|
exp = ParseCastExpression(exp);
|
||||||
|
}
|
||||||
else if (mScanner->mToken == TK_OPEN_PARENTHESIS)
|
else if (mScanner->mToken == TK_OPEN_PARENTHESIS)
|
||||||
{
|
{
|
||||||
// Explicit constructor invocation
|
// Explicit constructor invocation
|
||||||
|
@ -7732,10 +7750,12 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
exp->mDecType = TheConstVoidTypeDeclaration;
|
exp->mDecType = TheConstVoidTypeDeclaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Declaration* fcons = exp->mDecType->mScope ? exp->mDecType->mScope->Lookup(exp->mDecType->mIdent->PreMangle("+")) : nullptr;
|
||||||
|
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
||||||
{
|
{
|
||||||
pexp = ParseListExpression(false);
|
pexp = ParseListExpression(false, fcons ? fcons->mBase->mParams->mNext : nullptr);
|
||||||
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -7748,7 +7768,6 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Declaration* fcons = exp->mDecType->mScope ? exp->mDecType->mScope->Lookup(exp->mDecType->mIdent->PreMangle("+")) : nullptr;
|
|
||||||
if (fcons)
|
if (fcons)
|
||||||
{
|
{
|
||||||
Declaration* tdec = new Declaration(mScanner->mLocation, DT_VARIABLE);
|
Declaration* tdec = new Declaration(mScanner->mLocation, DT_VARIABLE);
|
||||||
|
@ -7894,7 +7913,7 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
nexp->mLeft = exp;
|
nexp->mLeft = exp;
|
||||||
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
||||||
{
|
{
|
||||||
nexp->mRight = ParseListExpression(false);
|
nexp->mRight = ParseListExpression(false, exp->mDecType->mParams);
|
||||||
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -9555,7 +9574,7 @@ Expression* Parser::ExpandArgumentPack(Expression* exp, Declaration* dec)
|
||||||
return vex;
|
return vex;
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression* Parser::ParseListExpression(bool lhs)
|
Expression* Parser::ParseListExpression(bool lhs, Declaration* params)
|
||||||
{
|
{
|
||||||
if (ConsumeTokenIf(TK_ELLIPSIS))
|
if (ConsumeTokenIf(TK_ELLIPSIS))
|
||||||
{
|
{
|
||||||
|
@ -9606,7 +9625,17 @@ Expression* Parser::ParseListExpression(bool lhs)
|
||||||
return ParseBinaryFoldExpression(nexp);
|
return ParseBinaryFoldExpression(nexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression* exp = ParseExpression(lhs);
|
Expression* exp;
|
||||||
|
|
||||||
|
if ((mCompilerOptions & COPT_CPLUSPLUS) && mScanner->mToken == TK_OPEN_BRACE && params)
|
||||||
|
{
|
||||||
|
exp = new Expression(mScanner->mLocation, EX_TYPE);
|
||||||
|
exp->mDecType = params->mBase->NonRefBase();
|
||||||
|
exp = ParseCastExpression(exp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
exp = ParseExpression(lhs);
|
||||||
|
|
||||||
if (exp->mType == EX_PACK)
|
if (exp->mType == EX_PACK)
|
||||||
{
|
{
|
||||||
if (ConsumeTokenIf(TK_ELLIPSIS))
|
if (ConsumeTokenIf(TK_ELLIPSIS))
|
||||||
|
@ -9627,7 +9656,7 @@ Expression* Parser::ParseListExpression(bool lhs)
|
||||||
if (ConsumeTokenIf(TK_ELLIPSIS))
|
if (ConsumeTokenIf(TK_ELLIPSIS))
|
||||||
return ParseBinaryFoldExpression(nexp);
|
return ParseBinaryFoldExpression(nexp);
|
||||||
|
|
||||||
nexp->mRight = ParseListExpression(false);
|
nexp->mRight = ParseListExpression(false, params ? params->mNext : nullptr);
|
||||||
nexp->mDecType = nexp->mRight->mDecType;
|
nexp->mDecType = nexp->mRight->mDecType;
|
||||||
exp = nexp;
|
exp = nexp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ protected:
|
||||||
Expression* ParseRExpression(void);
|
Expression* ParseRExpression(void);
|
||||||
|
|
||||||
Expression* ExpandArgumentPack(Expression * exp, Declaration* dec);
|
Expression* ExpandArgumentPack(Expression * exp, Declaration* dec);
|
||||||
Expression* ParseListExpression(bool lhs);
|
Expression* ParseListExpression(bool lhs, Declaration * params = nullptr);
|
||||||
|
|
||||||
Expression* ParseParenthesisExpression(void);
|
Expression* ParseParenthesisExpression(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue