Static init of structs with base classes
This commit is contained in:
parent
adda4044ca
commit
07323b12f9
|
@ -1215,18 +1215,37 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Declaration* mdec = dtype->mParams;
|
ExpandingArray<Declaration*> path;
|
||||||
while (mdec)
|
|
||||||
|
Declaration* ttype = dtype;
|
||||||
|
while (ttype->mBase)
|
||||||
|
{
|
||||||
|
path.Push(ttype);
|
||||||
|
ttype = ttype->mBase->mBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
Declaration* mdec = ttype->mParams;
|
||||||
|
for(;;)
|
||||||
{
|
{
|
||||||
if (ConsumeTokenIf(TK_DOT))
|
if (ConsumeTokenIf(TK_DOT))
|
||||||
{
|
{
|
||||||
if (mScanner->mToken == TK_IDENT)
|
if (mScanner->mToken == TK_IDENT)
|
||||||
{
|
{
|
||||||
Declaration* ndec = dtype->mScope->Lookup(mScanner->mTokenIdent);
|
ttype = dtype;
|
||||||
|
|
||||||
|
path.SetSize(0);
|
||||||
|
Declaration* ndec = ttype->mScope->Lookup(mScanner->mTokenIdent, SLEVEL_SCOPE);
|
||||||
|
while (!ndec && ttype->mBase)
|
||||||
|
{
|
||||||
|
path.Push(ttype);
|
||||||
|
ttype = ttype->mBase->mBase;
|
||||||
|
ndec = ttype->mScope->Lookup(mScanner->mTokenIdent, SLEVEL_SCOPE);
|
||||||
|
}
|
||||||
|
|
||||||
if (ndec)
|
if (ndec)
|
||||||
mdec = ndec;
|
mdec = ndec;
|
||||||
else
|
else
|
||||||
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "Struct member not found");
|
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "Struct member not found", mScanner->mTokenIdent);
|
||||||
|
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
ConsumeToken(TK_ASSIGN);
|
ConsumeToken(TK_ASSIGN);
|
||||||
|
@ -1234,6 +1253,9 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
||||||
else
|
else
|
||||||
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "Identifier expected");
|
mErrors->Error(mScanner->mLocation, EERR_CONSTANT_INITIALIZER, "Identifier expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mdec)
|
||||||
|
break;
|
||||||
|
|
||||||
Expression* texp = ParseInitExpression(mdec->mBase);
|
Expression* texp = ParseInitExpression(mdec->mBase);
|
||||||
|
|
||||||
|
@ -1247,7 +1269,10 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
||||||
|
|
||||||
if (!ConsumeTokenIf(TK_COMMA))
|
if (!ConsumeTokenIf(TK_COMMA))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
mdec = mdec->mNext;
|
mdec = mdec->mNext;
|
||||||
|
while (!mdec && path.Size())
|
||||||
|
mdec = path.Pop()->mParams;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue