Add placement new and destructor call
This commit is contained in:
parent
fef6bc29bc
commit
5b7334bb17
|
@ -4648,18 +4648,31 @@ Expression* Parser::ParseQualify(Expression* exp)
|
|||
{
|
||||
Expression* nexp = new Expression(mScanner->mLocation, EX_QUALIFY);
|
||||
nexp->mLeft = exp;
|
||||
if (mScanner->mToken == TK_IDENT)
|
||||
|
||||
int moffset = 0;
|
||||
uint64 mflags = 0;
|
||||
Declaration* mdec = nullptr;
|
||||
const Ident* ident = nullptr;
|
||||
|
||||
if ((mCompilerOptions & COPT_CPLUSPLUS) && mScanner->mToken == TK_BINARY_NOT)
|
||||
{
|
||||
int moffset;
|
||||
uint64 mflags;
|
||||
Declaration* mdec = MemberLookup(dtype, mScanner->mTokenIdent, moffset, mflags);
|
||||
mScanner->NextToken();
|
||||
if (mScanner->mToken == TK_IDENT)
|
||||
ident = mScanner->mTokenIdent->PreMangle("~");
|
||||
}
|
||||
else if (mScanner->mToken == TK_IDENT)
|
||||
ident = mScanner->mTokenIdent;
|
||||
|
||||
if (ident)
|
||||
{
|
||||
mdec = MemberLookup(dtype, ident, moffset, mflags);
|
||||
|
||||
if (mdec)
|
||||
{
|
||||
if (mflags & DTF_PROTECTED)
|
||||
{
|
||||
if (!mThisPointer || mThisPointer->mBase->IsConstSame(dtype))
|
||||
mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Struct member identifier not visible", mScanner->mTokenIdent);
|
||||
mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Struct member identifier not visible", ident);
|
||||
}
|
||||
|
||||
mScanner->NextToken();
|
||||
|
@ -4730,10 +4743,10 @@ Expression* Parser::ParseQualify(Expression* exp)
|
|||
mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Struct member identifier not found", mScanner->mTokenIdent);
|
||||
mScanner->NextToken();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Struct member identifier expected");
|
||||
|
||||
}
|
||||
else
|
||||
mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Struct expected");
|
||||
|
@ -5414,35 +5427,26 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
|||
}
|
||||
|
||||
|
||||
Expression* Parser::ParsePrefixExpression(bool lhs)
|
||||
{
|
||||
if (mScanner->mToken == TK_SUB || mScanner->mToken == TK_BINARY_NOT || mScanner->mToken == TK_LOGICAL_NOT ||
|
||||
mScanner->mToken == TK_MUL || mScanner->mToken == TK_INC || mScanner->mToken == TK_DEC || mScanner->mToken == TK_BINARY_AND ||
|
||||
mScanner->mToken == TK_BANKOF || mScanner->mToken == TK_NEW || mScanner->mToken == TK_DELETE)
|
||||
Expression* Parser::ParseNewOperator(void)
|
||||
{
|
||||
Expression* nexp;
|
||||
if (mScanner->mToken == TK_LOGICAL_NOT)
|
||||
{
|
||||
mScanner->NextToken();
|
||||
nexp = ParsePrefixExpression(false);
|
||||
nexp = nexp->LogicInvertExpression();
|
||||
nexp = CheckOperatorOverload(nexp);
|
||||
|
||||
}
|
||||
else if (mScanner->mToken == TK_INC || mScanner->mToken == TK_DEC)
|
||||
{
|
||||
nexp = new Expression(mScanner->mLocation, EX_PREINCDEC);
|
||||
nexp->mToken = mScanner->mToken;
|
||||
mScanner->NextToken();
|
||||
nexp->mLeft = ParsePrefixExpression(false);;
|
||||
nexp->mDecType = nexp->mLeft->mDecType;
|
||||
nexp = CheckOperatorOverload(nexp);
|
||||
}
|
||||
else if (mScanner->mToken == TK_NEW)
|
||||
{
|
||||
nexp = new Expression(mScanner->mLocation, EX_PREFIX);
|
||||
nexp->mToken = TK_NEW;
|
||||
mScanner->NextToken();
|
||||
|
||||
bool placement = false;
|
||||
|
||||
// Check for placement new
|
||||
if (ConsumeTokenIf(TK_OPEN_PARENTHESIS))
|
||||
{
|
||||
nexp->mType = EX_TYPECAST;
|
||||
nexp->mLeft = ParseExpression(false);
|
||||
|
||||
ConsumeToken(TK_CLOSE_PARENTHESIS);
|
||||
placement = true;
|
||||
}
|
||||
|
||||
Declaration* dec = ParseBaseTypeDeclaration(0, true);
|
||||
|
||||
Declaration* sconst = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
|
||||
|
@ -5469,7 +5473,9 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
|
|||
mexp->mDecType = TheUnsignedIntTypeDeclaration;
|
||||
ConsumeToken(TK_CLOSE_BRACKET);
|
||||
|
||||
if (!placement)
|
||||
nexp->mLeft = mexp;
|
||||
|
||||
nexp->mDecType = dec->BuildPointer(mScanner->mLocation);
|
||||
|
||||
if (dec->mVectorConstructor)
|
||||
|
@ -5536,7 +5542,9 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!placement)
|
||||
nexp->mLeft = sexp;
|
||||
|
||||
nexp->mDecType = dec->BuildPointer(mScanner->mLocation);
|
||||
|
||||
if (mScanner->mToken == TK_OPEN_PARENTHESIS || dec->mDefaultConstructor)
|
||||
|
@ -5624,6 +5632,37 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nexp;
|
||||
}
|
||||
|
||||
Expression* Parser::ParsePrefixExpression(bool lhs)
|
||||
{
|
||||
if (mScanner->mToken == TK_SUB || mScanner->mToken == TK_BINARY_NOT || mScanner->mToken == TK_LOGICAL_NOT ||
|
||||
mScanner->mToken == TK_MUL || mScanner->mToken == TK_INC || mScanner->mToken == TK_DEC || mScanner->mToken == TK_BINARY_AND ||
|
||||
mScanner->mToken == TK_BANKOF || mScanner->mToken == TK_NEW || mScanner->mToken == TK_DELETE)
|
||||
{
|
||||
Expression* nexp;
|
||||
if (mScanner->mToken == TK_LOGICAL_NOT)
|
||||
{
|
||||
mScanner->NextToken();
|
||||
nexp = ParsePrefixExpression(false);
|
||||
nexp = nexp->LogicInvertExpression();
|
||||
nexp = CheckOperatorOverload(nexp);
|
||||
|
||||
}
|
||||
else if (mScanner->mToken == TK_INC || mScanner->mToken == TK_DEC)
|
||||
{
|
||||
nexp = new Expression(mScanner->mLocation, EX_PREINCDEC);
|
||||
nexp->mToken = mScanner->mToken;
|
||||
mScanner->NextToken();
|
||||
nexp->mLeft = ParsePrefixExpression(false);;
|
||||
nexp->mDecType = nexp->mLeft->mDecType;
|
||||
nexp = CheckOperatorOverload(nexp);
|
||||
}
|
||||
else if (mScanner->mToken == TK_NEW)
|
||||
{
|
||||
nexp = ParseNewOperator();
|
||||
}
|
||||
else if (mScanner->mToken == TK_DELETE)
|
||||
{
|
||||
|
|
|
@ -99,6 +99,8 @@ protected:
|
|||
Declaration* ParseTemplateExpansion(Declaration* tmpld, Declaration* expd);
|
||||
void CompleteTemplateExpansion(Declaration* tmpld);
|
||||
|
||||
Expression* ParseNewOperator(void);
|
||||
|
||||
Expression* ParseSimpleExpression(bool lhs);
|
||||
Expression* ParsePrefixExpression(bool lhs);
|
||||
Expression* ParsePostfixExpression(bool lhs);
|
||||
|
|
Loading…
Reference in New Issue