Fix no inline for overloaded operators
This commit is contained in:
parent
9de7caa68d
commit
4a87e4d97b
|
@ -1023,6 +1023,9 @@ ConstexprInterpreter::Value ConstexprInterpreter::EvalUnary(Expression* exp, con
|
|||
break;
|
||||
case TK_MUL:
|
||||
return vl.GetPtr();
|
||||
case TK_SIZEOF:
|
||||
v.PutInt(vl.mDecType->mSize);
|
||||
break;
|
||||
default:
|
||||
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible operator", TokenNames[exp->mToken]);
|
||||
}
|
||||
|
|
|
@ -649,6 +649,19 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio
|
|||
|
||||
return this;
|
||||
}
|
||||
else if (mType == EX_PREFIX && mToken == TK_SIZEOF)
|
||||
{
|
||||
if (mLeft->mDecType->mFlags & DTF_DEFINED)
|
||||
{
|
||||
Expression* ex = new Expression(mLocation, EX_CONSTANT);
|
||||
Declaration* dec = new Declaration(mLocation, DT_CONST_INTEGER);
|
||||
dec->mBase = TheSignedIntTypeDeclaration;
|
||||
dec->mInteger = mLeft->mDecType->mSize;
|
||||
ex->mDecValue = dec;
|
||||
ex->mDecType = dec->mBase;
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
else if (mType == EX_PREFIX && mLeft->mType == EX_CONSTANT)
|
||||
{
|
||||
|
||||
|
|
|
@ -899,6 +899,10 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo
|
|||
{
|
||||
return TheUnsignedCharTypeDeclaration;
|
||||
}
|
||||
else if (exp->mToken == TK_SIZEOF)
|
||||
{
|
||||
return TheUnsignedIntTypeDeclaration;
|
||||
}
|
||||
else
|
||||
{
|
||||
procDec->mComplexity += 10 * exp->mLeft->mDecType->mSize;
|
||||
|
|
|
@ -23226,7 +23226,7 @@ void InterCodeProcedure::Close(void)
|
|||
{
|
||||
GrowingTypeArray tstack(IT_NONE);
|
||||
|
||||
CheckFunc = !strcmp(mIdent->mString, "equipment_navigate");
|
||||
CheckFunc = !strcmp(mIdent->mString, "reuref<struct Node>::(cast)");
|
||||
CheckCase = false;
|
||||
|
||||
mEntryBlock = mBlocks[0];
|
||||
|
|
|
@ -3439,6 +3439,18 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
mErrors->Error(exp->mLocation, ERRR_CANNOT_FIND_BANK_OF_EXPRESSION, "Cannot find bank of expressiohn");
|
||||
} break;
|
||||
|
||||
case TK_SIZEOF:
|
||||
{
|
||||
ins->mCode = IC_CONSTANT;
|
||||
ins->mNumOperands = 0;
|
||||
ins->mConst.mType = IT_INT16;
|
||||
ins->mConst.mIntConst = exp->mLeft->mDecType->mSize;
|
||||
ins->mDst.mType = IT_INT16;
|
||||
ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType);
|
||||
block->Append(ins);
|
||||
return ExValue(TheUnsignedIntTypeDeclaration, ins->mDst.mTemp, vl.mReference - 1);
|
||||
}
|
||||
|
||||
case TK_NEW:
|
||||
{
|
||||
ins->mCode = IC_MALLOC;
|
||||
|
@ -5628,6 +5640,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
|
||||
return ExValue(TheVoidTypeDeclaration);
|
||||
}
|
||||
case EX_TYPE:
|
||||
return ExValue(exp->mDecType);
|
||||
|
||||
default:
|
||||
mErrors->Error(exp->mLocation, EERR_UNIMPLEMENTED, "Unimplemented expression");
|
||||
return ExValue(TheVoidTypeDeclaration);
|
||||
|
|
|
@ -4786,6 +4786,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
|||
|
||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||
ctdec->mFlags |= storageFlags & (DTF_REQUEST_INLINE | DTF_CONSTEXPR | DTF_VIRTUAL);
|
||||
cdec->mFlags |= storageFlags & (DTF_PREVENT_INLINE);
|
||||
|
||||
cdec->mSection = mCodeSection;
|
||||
cdec->mBase->mFlags |= typeFlags;
|
||||
|
@ -4836,6 +4837,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
|||
|
||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||
ctdec->mFlags |= storageFlags & (DTF_REQUEST_INLINE | DTF_CONSTEXPR | DTF_VIRTUAL);
|
||||
cdec->mFlags |= storageFlags & (DTF_PREVENT_INLINE);
|
||||
|
||||
cdec->mSection = mCodeSection;
|
||||
cdec->mBase->mFlags |= typeFlags;
|
||||
|
@ -4880,7 +4882,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
|||
cdec->mBase = ctdec;
|
||||
|
||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||
cdec->mFlags |= storageFlags & (DTF_INLINE | DTF_CONSTEXPR);
|
||||
cdec->mFlags |= storageFlags & (DTF_INLINE | DTF_CONSTEXPR | DTF_PREVENT_INLINE);
|
||||
|
||||
cdec->mSection = mCodeSection;
|
||||
cdec->mBase->mFlags |= typeFlags;
|
||||
|
@ -6785,6 +6787,10 @@ Expression* Parser::ParseSimpleExpression(bool lhs, bool tid)
|
|||
dec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
|
||||
dec->mBase = TheSignedIntTypeDeclaration;
|
||||
|
||||
exp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||
exp->mDecValue = dec;
|
||||
exp->mDecType = dec->mBase;
|
||||
|
||||
if (ConsumeTokenIf(TK_ELLIPSIS))
|
||||
{
|
||||
rexp = ParseParenthesisExpression();
|
||||
|
@ -6805,14 +6811,24 @@ Expression* Parser::ParseSimpleExpression(bool lhs, bool tid)
|
|||
else
|
||||
{
|
||||
rexp = ParseParenthesisExpression();
|
||||
Declaration* btype;
|
||||
if (rexp->mDecType->IsReference())
|
||||
dec->mInteger = rexp->mDecType->mBase->mSize;
|
||||
btype = rexp->mDecType->mBase;
|
||||
else
|
||||
dec->mInteger = rexp->mDecType->mSize;
|
||||
btype = rexp->mDecType;
|
||||
|
||||
if (btype->mFlags & DTF_DEFINED)
|
||||
dec->mInteger = btype->mSize;
|
||||
else
|
||||
{
|
||||
exp->mType = EX_PREFIX;
|
||||
exp->mToken = TK_SIZEOF;
|
||||
exp->mLeft = new Expression(mScanner->mLocation, EX_TYPE);
|
||||
exp->mLeft->mDecType = btype;
|
||||
exp->mLeft->mDecValue = nullptr;
|
||||
}
|
||||
}
|
||||
exp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||
exp->mDecValue = dec;
|
||||
exp->mDecType = dec->mBase;
|
||||
|
||||
break;
|
||||
|
||||
case TK_OPEN_PARENTHESIS:
|
||||
|
|
Loading…
Reference in New Issue