Fixing member functions with includes

This commit is contained in:
drmortalwombat 2023-06-27 08:12:20 +02:00
parent 0b1b4a7d9b
commit 8f39d736d5
7 changed files with 496 additions and 337 deletions

View File

@ -148,9 +148,13 @@ void Expression::Dump(int ident) const
break; break;
case EX_CONSTANT: case EX_CONSTANT:
printf("CONST"); printf("CONST");
if (mDecValue->mIdent)
printf(" '%s'", mDecValue->mIdent->mString);
break; break;
case EX_VARIABLE: case EX_VARIABLE:
printf("VAR"); printf("VAR");
if (mDecValue->mIdent)
printf(" '%s'", mDecValue->mIdent->mString);
break; break;
case EX_ASSIGNMENT: case EX_ASSIGNMENT:
printf("ASSIGN<%s>", TokenNames[mToken]); printf("ASSIGN<%s>", TokenNames[mToken]);
@ -778,7 +782,7 @@ Declaration::Declaration(const Location& loc, DecType type)
: mLocation(loc), mEndLocation(loc), mType(type), mScope(nullptr), mData(nullptr), mIdent(nullptr), mQualIdent(nullptr), : mLocation(loc), mEndLocation(loc), mType(type), mScope(nullptr), mData(nullptr), mIdent(nullptr), mQualIdent(nullptr),
mSize(0), mOffset(0), mFlags(0), mComplexity(0), mLocalSize(0), mSize(0), mOffset(0), mFlags(0), mComplexity(0), mLocalSize(0),
mBase(nullptr), mParams(nullptr), mValue(nullptr), mNext(nullptr), mPrev(nullptr), mConst(nullptr), mBase(nullptr), mParams(nullptr), mValue(nullptr), mNext(nullptr), mPrev(nullptr), mConst(nullptr),
mConstructor(nullptr), mDestructor(nullptr), mCopyConstructor(nullptr), mCopyAssignment(nullptr), mDefaultConstructor(nullptr), mDestructor(nullptr), mCopyConstructor(nullptr), mCopyAssignment(nullptr),
mVectorConstructor(nullptr), mVectorDestructor(nullptr), mVectorCopyConstructor(nullptr), mVectorCopyAssignment(nullptr), mVectorConstructor(nullptr), mVectorDestructor(nullptr), mVectorCopyConstructor(nullptr), mVectorCopyAssignment(nullptr),
mVarIndex(-1), mLinkerObject(nullptr), mCallers(nullptr), mCalled(nullptr), mAlignment(1), mVarIndex(-1), mLinkerObject(nullptr), mCallers(nullptr), mCalled(nullptr), mAlignment(1),
mInteger(0), mNumber(0), mMinValue(-0x80000000LL), mMaxValue(0x7fffffffLL), mFastCallBase(0), mFastCallSize(0), mStride(0), mStripe(1), mInteger(0), mNumber(0), mMinValue(-0x80000000LL), mMaxValue(0x7fffffffLL), mFastCallBase(0), mFastCallSize(0), mStride(0), mStripe(1),
@ -1207,11 +1211,18 @@ bool Declaration::IsNumericType(void) const
return mType == DT_TYPE_INTEGER || mType == DT_TYPE_BOOL || mType == DT_TYPE_FLOAT || mType == DT_TYPE_ENUM; return mType == DT_TYPE_INTEGER || mType == DT_TYPE_BOOL || mType == DT_TYPE_FLOAT || mType == DT_TYPE_ENUM;
} }
bool Declaration::IsSimpleType(void) const bool Declaration::IsSimpleType(void) const
{ {
return mType == DT_TYPE_INTEGER || mType == DT_TYPE_BOOL || mType == DT_TYPE_FLOAT || mType == DT_TYPE_ENUM || mType == DT_TYPE_POINTER; return mType == DT_TYPE_INTEGER || mType == DT_TYPE_BOOL || mType == DT_TYPE_FLOAT || mType == DT_TYPE_ENUM || mType == DT_TYPE_POINTER;
} }
void Declaration::SetDefined(void)
{
mFlags |= DTF_DEFINED;
if (mConst)
mConst->mFlags |= DTF_DEFINED;
}
Declaration* TheVoidTypeDeclaration, * TheConstVoidTypeDeclaration, * TheSignedIntTypeDeclaration, * TheUnsignedIntTypeDeclaration, * TheConstCharTypeDeclaration, * TheCharTypeDeclaration, * TheSignedCharTypeDeclaration, * TheUnsignedCharTypeDeclaration; Declaration* TheVoidTypeDeclaration, * TheConstVoidTypeDeclaration, * TheSignedIntTypeDeclaration, * TheUnsignedIntTypeDeclaration, * TheConstCharTypeDeclaration, * TheCharTypeDeclaration, * TheSignedCharTypeDeclaration, * TheUnsignedCharTypeDeclaration;
Declaration* TheBoolTypeDeclaration, * TheFloatTypeDeclaration, * TheConstVoidPointerTypeDeclaration, * TheVoidPointerTypeDeclaration, * TheSignedLongTypeDeclaration, * TheUnsignedLongTypeDeclaration; Declaration* TheBoolTypeDeclaration, * TheFloatTypeDeclaration, * TheConstVoidPointerTypeDeclaration, * TheVoidPointerTypeDeclaration, * TheSignedLongTypeDeclaration, * TheUnsignedLongTypeDeclaration;

View File

@ -94,8 +94,6 @@ static const uint64 DTF_FPARAM_CONST = (1ULL << 40);
static const uint64 DTF_FPARAM_NOCONST = (1ULL << 41); static const uint64 DTF_FPARAM_NOCONST = (1ULL << 41);
static const uint64 DTF_FUNC_THIS = (1ULL << 42); static const uint64 DTF_FUNC_THIS = (1ULL << 42);
static const uint64 DTF_FUNC_CONSTRUCTOR = (1ULL << 43);
static const uint64 DTF_FUNC_DESTRUCTOR = (1ULL << 44);
static const uint64 DTF_VAR_ALIASING = (1ULL << 48); static const uint64 DTF_VAR_ALIASING = (1ULL << 48);
@ -223,7 +221,7 @@ public:
DecType mType; DecType mType;
Token mToken; Token mToken;
Declaration * mBase, * mParams, * mNext, * mPrev, * mConst; Declaration * mBase, * mParams, * mNext, * mPrev, * mConst;
Declaration * mConstructor, * mDestructor, * mCopyConstructor, * mCopyAssignment; Declaration * mDefaultConstructor, * mDestructor, * mCopyConstructor, * mCopyAssignment;
Declaration * mVectorConstructor, * mVectorDestructor, * mVectorCopyConstructor, * mVectorCopyAssignment; Declaration * mVectorConstructor, * mVectorDestructor, * mVectorCopyConstructor, * mVectorCopyAssignment;
Expression* mValue; Expression* mValue;
@ -251,6 +249,8 @@ public:
bool IsNumericType(void) const; bool IsNumericType(void) const;
bool IsSimpleType(void) const; bool IsSimpleType(void) const;
void SetDefined(void);
Declaration* ToConstType(void); Declaration* ToConstType(void);
Declaration* ToStriped(int stripe); Declaration* ToStriped(int stripe);
Declaration* ToStriped(Errors* errors); Declaration* ToStriped(Errors* errors);

View File

@ -12026,10 +12026,7 @@ void InterCodeBasicBlock::InnerLoopOptimization(const NumberSet& aliasedParams)
block->mInstructions[j++] = ins; block->mInstructions[j++] = ins;
} }
} }
#ifdef _DEBUG
if (j != block->mInstructions.Size())
printf("Moved %d %d\n", mIndex, block->mInstructions.Size() - j);
#endif
block->mInstructions.SetSize(j); block->mInstructions.SetSize(j);
} }
#endif #endif

View File

@ -1854,7 +1854,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
} }
return vr; return vl;
case EX_INDEX: case EX_INDEX:
{ {
@ -2761,6 +2761,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
} }
Declaration * decResult = nullptr; Declaration * decResult = nullptr;
GrowingArray<InterInstruction*> defins(nullptr);
if (ftype->mBase->mType == DT_TYPE_STRUCT) if (ftype->mBase->mType == DT_TYPE_STRUCT)
{ {
@ -2816,7 +2817,11 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
wins->mSrc[1].mType = IT_POINTER; wins->mSrc[1].mType = IT_POINTER;
wins->mSrc[1].mTemp = ains->mDst.mTemp; wins->mSrc[1].mTemp = ains->mDst.mTemp;
wins->mSrc[1].mOperandSize = 2; wins->mSrc[1].mOperandSize = 2;
block->Append(wins);
if (ftype->mFlags & DTF_FASTCALL)
defins.Push(wins);
else
block->Append(wins);
atotal = 2; atotal = 2;
} }
@ -2826,8 +2831,6 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
else else
proc->CallsFunctionPointer(); proc->CallsFunctionPointer();
GrowingArray<InterInstruction*> defins(nullptr);
Declaration* pdec = ftype->mParams; Declaration* pdec = ftype->mParams;
Expression* pex = exp->mRight; Expression* pex = exp->mRight;
while (pex) while (pex)
@ -4326,7 +4329,7 @@ InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod
InterCodeProcedure* proc = new InterCodeProcedure(mod, dec->mLocation, dec->mQualIdent, mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_BYTE_CODE)); InterCodeProcedure* proc = new InterCodeProcedure(mod, dec->mLocation, dec->mQualIdent, mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_BYTE_CODE));
#if 0 #if 0
if (proc->mIdent && !strcmp(proc->mIdent->mString, "test_retparam_value")) if (proc->mIdent && !strcmp(proc->mIdent->mString, "test_member"))
exp->Dump(0); exp->Dump(0);
#endif #endif
#if 0 #if 0

File diff suppressed because it is too large Load Diff

View File

@ -49,6 +49,7 @@ protected:
void AddDefaultConstructors(Declaration* pthis); void AddDefaultConstructors(Declaration* pthis);
void ParseVariableInit(Declaration* ndec); void ParseVariableInit(Declaration* ndec);
void AddMemberFunction(Declaration* dec, Declaration* mdec);
Expression * AddFunctionCallRefReturned(Expression * exp); Expression * AddFunctionCallRefReturned(Expression * exp);
Expression* CleanupExpression(Expression* exp); Expression* CleanupExpression(Expression* exp);

View File

@ -1397,13 +1397,33 @@ void Scanner::NextRawToken(void)
else if ((mCompilerOptions & COPT_CPLUSPLUS) && !strcmp(tkident, "operator")) else if ((mCompilerOptions & COPT_CPLUSPLUS) && !strcmp(tkident, "operator"))
{ {
NextRawToken(); NextRawToken();
if (mToken == TK_ASSIGN) switch (mToken)
{ {
mToken = TK_IDENT; case TK_ASSIGN:
mTokenIdent = Ident::Unique("operator="); mTokenIdent = Ident::Unique("operator=");
} break;
else
case TK_ADD:
mTokenIdent = Ident::Unique("operator+");
break;
case TK_SUB:
mTokenIdent = Ident::Unique("operator-");
break;
case TK_MUL:
mTokenIdent = Ident::Unique("operator*");
break;
case TK_DIV:
mTokenIdent = Ident::Unique("operator/");
break;
case TK_MOD:
mTokenIdent = Ident::Unique("operator%");
break;
default:
mErrors->Error(mLocation, EERR_INVALID_OPERATOR, "Invalid operator token"); mErrors->Error(mLocation, EERR_INVALID_OPERATOR, "Invalid operator token");
}
mToken = TK_IDENT;
} }
else else
{ {