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);
|
Expression* nexp = new Expression(mScanner->mLocation, EX_QUALIFY);
|
||||||
nexp->mLeft = exp;
|
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;
|
mScanner->NextToken();
|
||||||
uint64 mflags;
|
if (mScanner->mToken == TK_IDENT)
|
||||||
Declaration* mdec = MemberLookup(dtype, mScanner->mTokenIdent, moffset, mflags);
|
ident = mScanner->mTokenIdent->PreMangle("~");
|
||||||
|
}
|
||||||
|
else if (mScanner->mToken == TK_IDENT)
|
||||||
|
ident = mScanner->mTokenIdent;
|
||||||
|
|
||||||
|
if (ident)
|
||||||
|
{
|
||||||
|
mdec = MemberLookup(dtype, ident, moffset, mflags);
|
||||||
|
|
||||||
if (mdec)
|
if (mdec)
|
||||||
{
|
{
|
||||||
if (mflags & DTF_PROTECTED)
|
if (mflags & DTF_PROTECTED)
|
||||||
{
|
{
|
||||||
if (!mThisPointer || mThisPointer->mBase->IsConstSame(dtype))
|
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();
|
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);
|
mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Struct member identifier not found", mScanner->mTokenIdent);
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Struct member identifier expected");
|
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "Struct member identifier expected");
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Struct expected");
|
mErrors->Error(mScanner->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Struct expected");
|
||||||
|
@ -5414,36 +5427,27 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Expression* Parser::ParsePrefixExpression(bool lhs)
|
Expression* Parser::ParseNewOperator(void)
|
||||||
{
|
{
|
||||||
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;
|
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 = new Expression(mScanner->mLocation, EX_PREFIX);
|
||||||
nexp->mToken = TK_NEW;
|
nexp->mToken = TK_NEW;
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
Declaration * dec = ParseBaseTypeDeclaration(0, true);
|
|
||||||
|
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);
|
Declaration* sconst = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
|
||||||
sconst->mBase = TheUnsignedIntTypeDeclaration;
|
sconst->mBase = TheUnsignedIntTypeDeclaration;
|
||||||
|
@ -5469,7 +5473,9 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
|
||||||
mexp->mDecType = TheUnsignedIntTypeDeclaration;
|
mexp->mDecType = TheUnsignedIntTypeDeclaration;
|
||||||
ConsumeToken(TK_CLOSE_BRACKET);
|
ConsumeToken(TK_CLOSE_BRACKET);
|
||||||
|
|
||||||
|
if (!placement)
|
||||||
nexp->mLeft = mexp;
|
nexp->mLeft = mexp;
|
||||||
|
|
||||||
nexp->mDecType = dec->BuildPointer(mScanner->mLocation);
|
nexp->mDecType = dec->BuildPointer(mScanner->mLocation);
|
||||||
|
|
||||||
if (dec->mVectorConstructor)
|
if (dec->mVectorConstructor)
|
||||||
|
@ -5536,7 +5542,9 @@ Expression* Parser::ParsePrefixExpression(bool lhs)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!placement)
|
||||||
nexp->mLeft = sexp;
|
nexp->mLeft = sexp;
|
||||||
|
|
||||||
nexp->mDecType = dec->BuildPointer(mScanner->mLocation);
|
nexp->mDecType = dec->BuildPointer(mScanner->mLocation);
|
||||||
|
|
||||||
if (mScanner->mToken == TK_OPEN_PARENTHESIS || dec->mDefaultConstructor)
|
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)
|
else if (mScanner->mToken == TK_DELETE)
|
||||||
{
|
{
|
||||||
|
|
|
@ -99,6 +99,8 @@ protected:
|
||||||
Declaration* ParseTemplateExpansion(Declaration* tmpld, Declaration* expd);
|
Declaration* ParseTemplateExpansion(Declaration* tmpld, Declaration* expd);
|
||||||
void CompleteTemplateExpansion(Declaration* tmpld);
|
void CompleteTemplateExpansion(Declaration* tmpld);
|
||||||
|
|
||||||
|
Expression* ParseNewOperator(void);
|
||||||
|
|
||||||
Expression* ParseSimpleExpression(bool lhs);
|
Expression* ParseSimpleExpression(bool lhs);
|
||||||
Expression* ParsePrefixExpression(bool lhs);
|
Expression* ParsePrefixExpression(bool lhs);
|
||||||
Expression* ParsePostfixExpression(bool lhs);
|
Expression* ParsePostfixExpression(bool lhs);
|
||||||
|
|
Loading…
Reference in New Issue