Fixing member functions with includes
This commit is contained in:
parent
0b1b4a7d9b
commit
8f39d736d5
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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,6 +2817,10 @@ 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;
|
||||||
|
|
||||||
|
if (ftype->mFlags & DTF_FASTCALL)
|
||||||
|
defins.Push(wins);
|
||||||
|
else
|
||||||
block->Append(wins);
|
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
|
||||||
|
|
|
@ -28,6 +28,34 @@ Parser::~Parser(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Parser::AddMemberFunction(Declaration* dec, Declaration* mdec)
|
||||||
|
{
|
||||||
|
Declaration* gdec = mCompilationUnits->mScope->Insert(mdec->mQualIdent, mdec);
|
||||||
|
if (gdec)
|
||||||
|
{
|
||||||
|
if (gdec->mType == DT_CONST_FUNCTION)
|
||||||
|
{
|
||||||
|
Declaration* pcdec = nullptr;
|
||||||
|
Declaration* pdec = gdec;
|
||||||
|
|
||||||
|
while (pdec && !mdec->mBase->IsSameParams(pdec->mBase))
|
||||||
|
{
|
||||||
|
pcdec = pdec;
|
||||||
|
pdec = pdec->mNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pdec)
|
||||||
|
pcdec->mNext = mdec;
|
||||||
|
|
||||||
|
dec->mScope->Insert(mdec->mIdent, gdec);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mErrors->Error(mdec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate struct member declaration", mdec->mIdent);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
dec->mScope->Insert(mdec->mIdent, mdec);
|
||||||
|
}
|
||||||
|
|
||||||
Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt)
|
Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt)
|
||||||
{
|
{
|
||||||
const Ident* structName = nullptr;
|
const Ident* structName = nullptr;
|
||||||
|
@ -118,36 +146,10 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt)
|
||||||
if (mCompilerOptions & COPT_NATIVE)
|
if (mCompilerOptions & COPT_NATIVE)
|
||||||
mdec->mFlags |= DTF_NATIVE;
|
mdec->mFlags |= DTF_NATIVE;
|
||||||
|
|
||||||
if (!(mdec->mFlags & (DTF_FUNC_CONSTRUCTOR | DTF_FUNC_DESTRUCTOR)))
|
|
||||||
{
|
|
||||||
Declaration* pdec = dec->mScope->Insert(mdec->mIdent, mdec);
|
|
||||||
|
|
||||||
if (pdec)
|
|
||||||
{
|
|
||||||
if (pdec->mType == DT_CONST_FUNCTION)
|
|
||||||
{
|
|
||||||
Declaration* pcdec = nullptr;
|
|
||||||
|
|
||||||
while (pdec && !mdec->mBase->IsSameParams(pdec->mBase))
|
|
||||||
{
|
|
||||||
pcdec = pdec;
|
|
||||||
pdec = pdec->mNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pdec)
|
|
||||||
pcdec->mNext = mdec;
|
|
||||||
else
|
|
||||||
mErrors->Error(mdec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate struct member declaration", mdec->mIdent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
mErrors->Error(mdec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate struct member declaration", mdec->mIdent);
|
|
||||||
}
|
|
||||||
else if (mCompilationUnits->mScope->Insert(mdec->mQualIdent, mdec))
|
|
||||||
mErrors->Error(mdec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate struct member declaration", mdec->mIdent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(mdec->mFlags & DTF_DEFINED))
|
if (!(mdec->mFlags & DTF_DEFINED))
|
||||||
ConsumeToken(TK_SEMICOLON);
|
ConsumeToken(TK_SEMICOLON);
|
||||||
|
|
||||||
|
AddMemberFunction(dec, mdec);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -201,13 +203,14 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt)
|
||||||
else
|
else
|
||||||
dec->mParams = nullptr;
|
dec->mParams = nullptr;
|
||||||
|
|
||||||
dec->mFlags |= DTF_DEFINED;
|
dec->SetDefined();
|
||||||
|
|
||||||
if (mCompilerOptions & COPT_CPLUSPLUS)
|
if ((mCompilerOptions & COPT_CPLUSPLUS) && dec->mType == DT_TYPE_STRUCT && dec->mIdent)
|
||||||
{
|
{
|
||||||
AddDefaultConstructors(pthis);
|
AddDefaultConstructors(pthis);
|
||||||
|
|
||||||
Declaration* cdec = pthis->mBase->mConstructor;
|
// Lookup constructors, have same name as class
|
||||||
|
Declaration* cdec = dec->mScope->Lookup(dec->mIdent);
|
||||||
while (cdec)
|
while (cdec)
|
||||||
{
|
{
|
||||||
if (cdec->mFlags & DTF_DEFINED)
|
if (cdec->mFlags & DTF_DEFINED)
|
||||||
|
@ -346,6 +349,10 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint64 flags)
|
||||||
dec = ndec;
|
dec = ndec;
|
||||||
}
|
}
|
||||||
else if (dec->mType == DT_TYPE_STRUCT && (flags & ~dec->mFlags))
|
else if (dec->mType == DT_TYPE_STRUCT && (flags & ~dec->mFlags))
|
||||||
|
{
|
||||||
|
if ((flags & ~dec->mFlags) == DTF_CONST)
|
||||||
|
dec = dec->ToConstType();
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Declaration* ndec = new Declaration(dec->mLocation, dec->mType);
|
Declaration* ndec = new Declaration(dec->mLocation, dec->mType);
|
||||||
ndec->mFlags = dec->mFlags | flags;
|
ndec->mFlags = dec->mFlags | flags;
|
||||||
|
@ -357,6 +364,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint64 flags)
|
||||||
ndec->mQualIdent = dec->mQualIdent;
|
ndec->mQualIdent = dec->mQualIdent;
|
||||||
dec = ndec;
|
dec = ndec;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
}
|
}
|
||||||
else if (!dec)
|
else if (!dec)
|
||||||
|
@ -1158,10 +1166,12 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
||||||
|
|
||||||
Expression* Parser::BuildMemberInitializer(Expression* vexp)
|
Expression* Parser::BuildMemberInitializer(Expression* vexp)
|
||||||
{
|
{
|
||||||
if (vexp->mDecType->mType == DT_TYPE_STRUCT && vexp->mDecType->mConstructor)
|
Declaration* fcons = (vexp->mDecType->mType == DT_TYPE_STRUCT && vexp->mDecType->mScope) ? vexp->mDecType->mScope->Lookup(vexp->mDecType->mIdent) : nullptr;
|
||||||
|
|
||||||
|
if (fcons)
|
||||||
{
|
{
|
||||||
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
cexp->mDecValue = vexp->mDecType->mConstructor;
|
cexp->mDecValue = fcons;
|
||||||
cexp->mDecType = cexp->mDecValue->mBase;
|
cexp->mDecType = cexp->mDecValue->mBase;
|
||||||
|
|
||||||
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
@ -1249,7 +1259,7 @@ void Parser::PrependMemberConstructor(Declaration* pthis, Declaration* cfunc)
|
||||||
while (bdec->mType == DT_TYPE_ARRAY)
|
while (bdec->mType == DT_TYPE_ARRAY)
|
||||||
bdec = bdec->mBase;
|
bdec = bdec->mBase;
|
||||||
|
|
||||||
if (bdec->mType == DT_TYPE_STRUCT && bdec->mConstructor)
|
if (bdec->mType == DT_TYPE_STRUCT && bdec->mDefaultConstructor)
|
||||||
{
|
{
|
||||||
Expression* qexp = new Expression(pthis->mLocation, EX_QUALIFY);
|
Expression* qexp = new Expression(pthis->mLocation, EX_QUALIFY);
|
||||||
qexp->mLeft = thisexp;
|
qexp->mLeft = thisexp;
|
||||||
|
@ -1269,9 +1279,7 @@ void Parser::PrependMemberConstructor(Declaration* pthis, Declaration* cfunc)
|
||||||
pexp->mDecType->mBase = bdec;
|
pexp->mDecType->mBase = bdec;
|
||||||
pexp->mDecType->mSize = 2;
|
pexp->mDecType->mSize = 2;
|
||||||
|
|
||||||
Declaration* mdec = bdec->mConstructor;
|
Declaration* mdec = bdec->mDefaultConstructor;
|
||||||
while (mdec && mdec->mBase->mParams->mNext)
|
|
||||||
mdec = mdec->mNext;
|
|
||||||
|
|
||||||
Expression* cexp = new Expression(pthis->mLocation, EX_CONSTANT);
|
Expression* cexp = new Expression(pthis->mLocation, EX_CONSTANT);
|
||||||
if (mdec)
|
if (mdec)
|
||||||
|
@ -1385,6 +1393,44 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
{
|
{
|
||||||
bool simpleDestructor = true, simpleAssignment = true;
|
bool simpleDestructor = true, simpleAssignment = true;
|
||||||
|
|
||||||
|
char dname[100];
|
||||||
|
strcpy_s(dname, "~");
|
||||||
|
strcat_s(dname, pthis->mBase->mIdent->mString);
|
||||||
|
|
||||||
|
const Ident * dtorident = Ident::Unique(dname);
|
||||||
|
|
||||||
|
// Extract constructor and destructor from scope
|
||||||
|
|
||||||
|
Declaration* cdec = pthis->mBase->mScope->Lookup(pthis->mBase->mIdent);
|
||||||
|
while (cdec)
|
||||||
|
{
|
||||||
|
Declaration* ctdec = cdec->mBase;
|
||||||
|
Declaration* tparam = ctdec->mParams->mNext;
|
||||||
|
|
||||||
|
if (!tparam)
|
||||||
|
pthis->mBase->mDefaultConstructor = cdec;
|
||||||
|
else if (!tparam->mNext && tparam->mBase->mType == DT_TYPE_REFERENCE && pthis->mBase->IsConstSame(tparam->mBase->mBase))
|
||||||
|
pthis->mBase->mCopyConstructor = cdec;
|
||||||
|
|
||||||
|
cdec = cdec->mNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
Declaration* ddec = pthis->mBase->mScope->Lookup(dtorident);
|
||||||
|
if (ddec)
|
||||||
|
pthis->mBase->mDestructor = ddec;
|
||||||
|
|
||||||
|
Declaration* adec = pthis->mBase->mScope->Lookup(Ident::Unique("operator="));
|
||||||
|
while (adec)
|
||||||
|
{
|
||||||
|
Declaration* atdec = adec->mBase;
|
||||||
|
Declaration* tparam = atdec->mParams->mNext;
|
||||||
|
|
||||||
|
if (!tparam->mNext && tparam->mBase->mType == DT_TYPE_REFERENCE && pthis->mBase->IsConstSame(tparam->mBase->mBase))
|
||||||
|
pthis->mBase->mCopyAssignment = adec;
|
||||||
|
|
||||||
|
adec = adec->mNext;
|
||||||
|
}
|
||||||
|
|
||||||
Declaration* dec = pthis->mBase->mParams;
|
Declaration* dec = pthis->mBase->mParams;
|
||||||
while (dec)
|
while (dec)
|
||||||
{
|
{
|
||||||
|
@ -1423,7 +1469,6 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_DESTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
|
|
||||||
|
@ -1432,10 +1477,7 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
|
|
||||||
pthis->mBase->mDestructor = cdec;
|
pthis->mBase->mDestructor = cdec;
|
||||||
|
|
||||||
char dname[100];
|
cdec->mIdent = dtorident;
|
||||||
strcpy_s(dname, "~");
|
|
||||||
strcat_s(dname, pthis->mBase->mIdent->mString);
|
|
||||||
cdec->mIdent = Ident::Unique(dname);
|
|
||||||
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
||||||
|
|
||||||
cdec->mCompilerOptions = mCompilerOptions;
|
cdec->mCompilerOptions = mCompilerOptions;
|
||||||
|
@ -1449,7 +1491,7 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mValue = new Expression(mScanner->mLocation, EX_VOID);
|
cdec->mValue = new Expression(mScanner->mLocation, EX_VOID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pthis->mBase->mConstructor)
|
if (!pthis->mBase->mDefaultConstructor)
|
||||||
{
|
{
|
||||||
Declaration* ctdec = new Declaration(mScanner->mLocation, DT_TYPE_FUNCTION);
|
Declaration* ctdec = new Declaration(mScanner->mLocation, DT_TYPE_FUNCTION);
|
||||||
ctdec->mSize = 0;
|
ctdec->mSize = 0;
|
||||||
|
@ -1463,18 +1505,19 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_CONSTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
|
|
||||||
if (mCompilerOptions & COPT_NATIVE)
|
if (mCompilerOptions & COPT_NATIVE)
|
||||||
cdec->mFlags |= DTF_NATIVE;
|
cdec->mFlags |= DTF_NATIVE;
|
||||||
|
|
||||||
pthis->mBase->mConstructor = cdec;
|
pthis->mBase->mDefaultConstructor = cdec;
|
||||||
|
|
||||||
cdec->mIdent = pthis->mBase->mIdent;
|
cdec->mIdent = pthis->mBase->mIdent;
|
||||||
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
||||||
|
|
||||||
|
AddMemberFunction(pthis->mBase, cdec);
|
||||||
|
|
||||||
cdec->mCompilerOptions = mCompilerOptions;
|
cdec->mCompilerOptions = mCompilerOptions;
|
||||||
cdec->mBase->mCompilerOptions = mCompilerOptions;
|
cdec->mBase->mCompilerOptions = mCompilerOptions;
|
||||||
|
|
||||||
|
@ -1511,7 +1554,6 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_CONSTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
|
|
||||||
|
@ -1519,12 +1561,12 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mFlags |= DTF_NATIVE;
|
cdec->mFlags |= DTF_NATIVE;
|
||||||
|
|
||||||
pthis->mBase->mCopyConstructor = cdec;
|
pthis->mBase->mCopyConstructor = cdec;
|
||||||
cdec->mNext = pthis->mBase->mConstructor;
|
|
||||||
pthis->mBase->mConstructor = cdec;
|
|
||||||
|
|
||||||
cdec->mIdent = pthis->mBase->mIdent;
|
cdec->mIdent = pthis->mBase->mIdent;
|
||||||
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
||||||
|
|
||||||
|
AddMemberFunction(pthis->mBase, cdec);
|
||||||
|
|
||||||
cdec->mCompilerOptions = mCompilerOptions;
|
cdec->mCompilerOptions = mCompilerOptions;
|
||||||
cdec->mBase->mCompilerOptions = mCompilerOptions;
|
cdec->mBase->mCompilerOptions = mCompilerOptions;
|
||||||
|
|
||||||
|
@ -1680,7 +1722,6 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_CONSTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
|
|
||||||
|
@ -1691,16 +1732,12 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
||||||
|
|
||||||
pthis->mBase->mCopyAssignment = cdec;
|
pthis->mBase->mCopyAssignment = cdec;
|
||||||
Declaration* pdec = pthis->mBase->mScope->Insert(cdec->mIdent, cdec);
|
|
||||||
if (pdec)
|
|
||||||
{
|
|
||||||
cdec->mNext = pdec->mNext;
|
|
||||||
pdec->mNext = cdec;
|
|
||||||
}
|
|
||||||
|
|
||||||
cdec->mCompilerOptions = mCompilerOptions;
|
cdec->mCompilerOptions = mCompilerOptions;
|
||||||
cdec->mBase->mCompilerOptions = mCompilerOptions;
|
cdec->mBase->mCompilerOptions = mCompilerOptions;
|
||||||
|
|
||||||
|
AddMemberFunction(pthis->mBase, cdec);
|
||||||
|
|
||||||
cdec->mVarIndex = -1;
|
cdec->mVarIndex = -1;
|
||||||
|
|
||||||
Expression* pthisexp = new Expression(pthis->mLocation, EX_VARIABLE);
|
Expression* pthisexp = new Expression(pthis->mLocation, EX_VARIABLE);
|
||||||
|
@ -1828,11 +1865,7 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Declaration* dcons = pthis->mBase->mConstructor;
|
if (pthis->mBase->mDefaultConstructor && !pthis->mBase->mVectorConstructor)
|
||||||
while (dcons && dcons->mBase->mParams->mNext)
|
|
||||||
dcons = dcons->mNext;
|
|
||||||
|
|
||||||
if (dcons && !pthis->mBase->mVectorConstructor)
|
|
||||||
{
|
{
|
||||||
Declaration* ctdec = new Declaration(mScanner->mLocation, DT_TYPE_FUNCTION);
|
Declaration* ctdec = new Declaration(mScanner->mLocation, DT_TYPE_FUNCTION);
|
||||||
ctdec->mSize = 0;
|
ctdec->mSize = 0;
|
||||||
|
@ -1857,7 +1890,6 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_CONSTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
|
|
||||||
|
@ -1894,7 +1926,7 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
dexp->mLeft = aexp;
|
dexp->mLeft = aexp;
|
||||||
|
|
||||||
Expression* fexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
Expression* fexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
fexp->mDecValue = dcons;
|
fexp->mDecValue = pthis->mBase->mDefaultConstructor;
|
||||||
fexp->mDecType = fexp->mDecValue->mBase;
|
fexp->mDecType = fexp->mDecValue->mBase;
|
||||||
|
|
||||||
Expression*cexp = new Expression(mScanner->mLocation, EX_CALL);
|
Expression*cexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
@ -1935,7 +1967,6 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_CONSTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
|
|
||||||
|
@ -2025,7 +2056,6 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_CONSTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
|
|
||||||
|
@ -2127,7 +2157,6 @@ void Parser::AddDefaultConstructors(Declaration* pthis)
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_CONSTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
|
|
||||||
|
@ -2223,7 +2252,7 @@ void Parser::AppendMemberDestructor(Declaration* pthis)
|
||||||
while (bdec->mType == DT_TYPE_ARRAY)
|
while (bdec->mType == DT_TYPE_ARRAY)
|
||||||
bdec = bdec->mBase;
|
bdec = bdec->mBase;
|
||||||
|
|
||||||
if (bdec->mType == DT_TYPE_STRUCT && bdec->mConstructor)
|
if (bdec->mType == DT_TYPE_STRUCT && bdec->mDestructor)
|
||||||
{
|
{
|
||||||
Expression* qexp = new Expression(pthis->mLocation, EX_QUALIFY);
|
Expression* qexp = new Expression(pthis->mLocation, EX_QUALIFY);
|
||||||
qexp->mLeft = thisexp;
|
qexp->mLeft = thisexp;
|
||||||
|
@ -2295,7 +2324,11 @@ void Parser::PrependThisArgument(Declaration* fdec, Declaration* pthis)
|
||||||
{
|
{
|
||||||
Declaration* adec = new Declaration(fdec->mLocation, DT_ARGUMENT);
|
Declaration* adec = new Declaration(fdec->mLocation, DT_ARGUMENT);
|
||||||
|
|
||||||
|
if (fdec->mBase->mType == DT_TYPE_STRUCT)
|
||||||
|
adec->mVarIndex = 2;
|
||||||
|
else
|
||||||
adec->mVarIndex = 0;
|
adec->mVarIndex = 0;
|
||||||
|
|
||||||
adec->mOffset = 0;
|
adec->mOffset = 0;
|
||||||
adec->mBase = pthis;
|
adec->mBase = pthis;
|
||||||
adec->mSize = adec->mBase->mSize;
|
adec->mSize = adec->mBase->mSize;
|
||||||
|
@ -2351,7 +2384,58 @@ Expression* Parser::AddFunctionCallRefReturned(Expression* exp)
|
||||||
{
|
{
|
||||||
Expression* lexp = nullptr, * rexp = nullptr;
|
Expression* lexp = nullptr, * rexp = nullptr;
|
||||||
|
|
||||||
if (exp->mType == EX_CALL)
|
if (exp->mType == EX_PREFIX && exp->mToken == TK_BINARY_AND && exp->mLeft->mType == EX_CALL)
|
||||||
|
{
|
||||||
|
lexp = AddFunctionCallRefReturned(exp->mLeft);
|
||||||
|
|
||||||
|
// Returning a value object for pass by address
|
||||||
|
// add a temporary variable
|
||||||
|
|
||||||
|
int nindex = mLocalIndex++;
|
||||||
|
|
||||||
|
Declaration* rtdec = exp->mLeft->mDecType;
|
||||||
|
|
||||||
|
Declaration* vdec = new Declaration(exp->mLocation, DT_VARIABLE);
|
||||||
|
|
||||||
|
vdec->mVarIndex = nindex;
|
||||||
|
vdec->mBase = rtdec;
|
||||||
|
vdec->mSize = rtdec->mSize;
|
||||||
|
|
||||||
|
Expression* vexp = new Expression(exp->mLocation, EX_VARIABLE);
|
||||||
|
vexp->mDecType = rtdec;
|
||||||
|
vexp->mDecValue = vdec;
|
||||||
|
|
||||||
|
Expression * pex = new Expression(exp->mLocation, EX_INITIALIZATION);
|
||||||
|
pex->mToken = TK_ASSIGN;
|
||||||
|
pex->mLeft = vexp;
|
||||||
|
pex->mRight = exp->mLeft;
|
||||||
|
pex->mDecValue = nullptr;
|
||||||
|
pex->mDecType = vdec->mBase;
|
||||||
|
|
||||||
|
exp->mLeft = pex;
|
||||||
|
|
||||||
|
if (rtdec->mDestructor)
|
||||||
|
{
|
||||||
|
Expression* texp = new Expression(mScanner->mLocation, EX_PREFIX);
|
||||||
|
texp->mToken = TK_BINARY_AND;
|
||||||
|
texp->mLeft = vexp;
|
||||||
|
texp->mDecType = new Declaration(mScanner->mLocation, DT_TYPE_POINTER);
|
||||||
|
texp->mDecType->mFlags |= DTF_CONST | DTF_DEFINED;
|
||||||
|
texp->mDecType->mBase = vdec->mBase;
|
||||||
|
texp->mDecType->mSize = 2;
|
||||||
|
|
||||||
|
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
|
cexp->mDecValue = rtdec->mDestructor;
|
||||||
|
cexp->mDecType = cexp->mDecValue->mBase;
|
||||||
|
|
||||||
|
Expression* dexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
dexp->mLeft = cexp;
|
||||||
|
dexp->mRight = texp;
|
||||||
|
|
||||||
|
rexp = ConcatExpression(rexp, dexp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (exp->mType == EX_CALL)
|
||||||
{
|
{
|
||||||
lexp = AddFunctionCallRefReturned(exp->mLeft);
|
lexp = AddFunctionCallRefReturned(exp->mLeft);
|
||||||
if (exp->mRight)
|
if (exp->mRight)
|
||||||
|
@ -2453,14 +2537,18 @@ void Parser::ParseVariableInit(Declaration* ndec)
|
||||||
{
|
{
|
||||||
ndec->mValue = pexp;
|
ndec->mValue = pexp;
|
||||||
}
|
}
|
||||||
else if (ndec->mBase->mConstructor)
|
else
|
||||||
|
{
|
||||||
|
Declaration* fcons = ndec->mBase->mScope ? ndec->mBase->mScope->Lookup(ndec->mBase->mIdent) : nullptr;
|
||||||
|
|
||||||
|
if (fcons)
|
||||||
{
|
{
|
||||||
Expression* vexp = new Expression(mScanner->mLocation, EX_VARIABLE);
|
Expression* vexp = new Expression(mScanner->mLocation, EX_VARIABLE);
|
||||||
vexp->mDecType = ndec->mBase;
|
vexp->mDecType = ndec->mBase;
|
||||||
vexp->mDecValue = ndec;
|
vexp->mDecValue = ndec;
|
||||||
|
|
||||||
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
cexp->mDecValue = ndec->mBase->mConstructor;
|
cexp->mDecValue = fcons;
|
||||||
cexp->mDecType = cexp->mDecValue->mBase;
|
cexp->mDecType = cexp->mDecValue->mBase;
|
||||||
|
|
||||||
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
@ -2515,6 +2603,7 @@ void Parser::ParseVariableInit(Declaration* ndec)
|
||||||
ndec->mValue = pexp;
|
ndec->mValue = pexp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool expression, Declaration* pthis)
|
Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool expression, Declaration* pthis)
|
||||||
{
|
{
|
||||||
|
@ -2658,7 +2747,6 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_DESTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
cdec->mBase->mFlags |= typeFlags;
|
cdec->mBase->mFlags |= typeFlags;
|
||||||
|
@ -2666,11 +2754,6 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
if (mCompilerOptions & COPT_NATIVE)
|
if (mCompilerOptions & COPT_NATIVE)
|
||||||
cdec->mFlags |= DTF_NATIVE;
|
cdec->mFlags |= DTF_NATIVE;
|
||||||
|
|
||||||
if (pthis->mBase->mDestructor)
|
|
||||||
mErrors->Error(ctdec->mLocation, EERR_DUPLICATE_DEFINITION, "Duplicate destrcutor definition");
|
|
||||||
else
|
|
||||||
pthis->mBase->mDestructor = cdec;
|
|
||||||
|
|
||||||
char dname[100];
|
char dname[100];
|
||||||
strcpy_s(dname, "~");
|
strcpy_s(dname, "~");
|
||||||
strcat_s(dname, pthis->mBase->mIdent->mString);
|
strcat_s(dname, pthis->mBase->mIdent->mString);
|
||||||
|
@ -2706,16 +2789,11 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
|
|
||||||
Declaration* cdec = new Declaration(ctdec->mLocation, DT_CONST_FUNCTION);
|
Declaration* cdec = new Declaration(ctdec->mLocation, DT_CONST_FUNCTION);
|
||||||
|
|
||||||
if (ctdec->mParams && !ctdec->mParams->mNext && ctdec->mParams->mBase->mType == DT_TYPE_REFERENCE &&
|
|
||||||
pthis->mBase->IsConstSame(ctdec->mParams->mBase->mBase))
|
|
||||||
pthis->mBase->mCopyConstructor = cdec;
|
|
||||||
|
|
||||||
PrependThisArgument(ctdec, pthis);
|
PrependThisArgument(ctdec, pthis);
|
||||||
|
|
||||||
cdec->mBase = ctdec;
|
cdec->mBase = ctdec;
|
||||||
|
|
||||||
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
cdec->mFlags |= cdec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE);
|
||||||
cdec->mFlags |= DTF_FUNC_CONSTRUCTOR;
|
|
||||||
|
|
||||||
cdec->mSection = mCodeSection;
|
cdec->mSection = mCodeSection;
|
||||||
cdec->mBase->mFlags |= typeFlags;
|
cdec->mBase->mFlags |= typeFlags;
|
||||||
|
@ -2723,7 +2801,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
if (mCompilerOptions & COPT_NATIVE)
|
if (mCompilerOptions & COPT_NATIVE)
|
||||||
cdec->mFlags |= DTF_NATIVE;
|
cdec->mFlags |= DTF_NATIVE;
|
||||||
|
|
||||||
Declaration* pdec = pthis->mBase->mConstructor;
|
Declaration* pdec = pthis->mBase->mScope ? pthis->mBase->mScope->Lookup(pthis->mBase->mIdent) : nullptr;
|
||||||
if (pdec)
|
if (pdec)
|
||||||
{
|
{
|
||||||
while (pdec && !cdec->mBase->IsSameParams(pdec->mBase))
|
while (pdec && !cdec->mBase->IsSameParams(pdec->mBase))
|
||||||
|
@ -2756,11 +2834,6 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
|
|
||||||
cdec = pdec;
|
cdec = pdec;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
cdec->mNext = pthis->mBase->mConstructor;
|
|
||||||
pthis->mBase->mConstructor = cdec;
|
|
||||||
}
|
|
||||||
|
|
||||||
cdec->mIdent = pthis->mBase->mIdent;
|
cdec->mIdent = pthis->mBase->mIdent;
|
||||||
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
cdec->mQualIdent = pthis->mBase->mScope->Mangle(cdec->mIdent);
|
||||||
|
@ -2805,7 +2878,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
|
|
||||||
PrependThisArgument(ctdec, bthis);
|
PrependThisArgument(ctdec, bthis);
|
||||||
|
|
||||||
Declaration* cdec = bdec->mConstructor;
|
Declaration* cdec = bdec->mScope->Lookup(bdec->mIdent);
|
||||||
if (cdec)
|
if (cdec)
|
||||||
{
|
{
|
||||||
while (cdec && !cdec->mBase->IsSameParams(ctdec))
|
while (cdec && !cdec->mBase->IsSameParams(ctdec))
|
||||||
|
@ -2887,7 +2960,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
AppendMemberDestructor(bthis);
|
AppendMemberDestructor(bthis);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mErrors->Error(ctdec->mLocation, EERR_DUPLICATE_DEFINITION, "Desctructor not declared", bdec->mIdent);
|
mErrors->Error(ctdec->mLocation, EERR_DUPLICATE_DEFINITION, "Destructor not declared", bdec->mIdent);
|
||||||
|
|
||||||
return bdec->mDestructor;
|
return bdec->mDestructor;
|
||||||
}
|
}
|
||||||
|
@ -2935,13 +3008,6 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
{
|
{
|
||||||
if (ndec->mBase->mType == DT_TYPE_FUNCTION && pthis)
|
if (ndec->mBase->mType == DT_TYPE_FUNCTION && pthis)
|
||||||
{
|
{
|
||||||
if (ndec->mIdent == Ident::Unique("operator="))
|
|
||||||
{
|
|
||||||
if (ndec->mBase->mParams && ndec->mBase->mParams->mBase->mType == DT_TYPE_REFERENCE && ndec->mBase->mParams->mBase->mBase->IsConstSame(pthis->mBase))
|
|
||||||
{
|
|
||||||
pthis->mBase->mCopyAssignment = ndec;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PrependThisArgument(ndec->mBase, pthis);
|
PrependThisArgument(ndec->mBase, pthis);
|
||||||
|
|
||||||
|
@ -3108,7 +3174,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
else
|
else
|
||||||
rdec = ndec;
|
rdec = ndec;
|
||||||
ldec = ndec;
|
ldec = ndec;
|
||||||
ndec->mNext = nullptr;
|
// ndec->mNext = nullptr;
|
||||||
|
|
||||||
if (mScanner->mToken == TK_ASSIGN)
|
if (mScanner->mToken == TK_ASSIGN)
|
||||||
{
|
{
|
||||||
|
@ -3146,13 +3212,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
while (bdec && bdec->mType == DT_TYPE_ARRAY)
|
while (bdec && bdec->mType == DT_TYPE_ARRAY)
|
||||||
bdec = bdec->mBase;
|
bdec = bdec->mBase;
|
||||||
|
|
||||||
if (bdec && bdec->mConstructor)
|
if (bdec && bdec->mDefaultConstructor)
|
||||||
{
|
|
||||||
Declaration* cdec = bdec->mConstructor;
|
|
||||||
while (cdec && cdec->mBase->mParams->mNext)
|
|
||||||
cdec = cdec->mNext;
|
|
||||||
|
|
||||||
if (cdec)
|
|
||||||
{
|
{
|
||||||
Expression* vexp = new Expression(ndec->mLocation, EX_VARIABLE);
|
Expression* vexp = new Expression(ndec->mLocation, EX_VARIABLE);
|
||||||
vexp->mDecType = ndec->mBase;
|
vexp->mDecType = ndec->mBase;
|
||||||
|
@ -3169,7 +3229,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
if (bdec->mSize == ndec->mBase->mSize)
|
if (bdec->mSize == ndec->mBase->mSize)
|
||||||
{
|
{
|
||||||
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
cexp->mDecValue = cdec;
|
cexp->mDecValue = bdec->mDefaultConstructor;
|
||||||
cexp->mDecType = cexp->mDecValue->mBase;
|
cexp->mDecType = cexp->mDecValue->mBase;
|
||||||
|
|
||||||
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
@ -3245,10 +3305,9 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
|
||||||
ndec->mValue = nexp;
|
ndec->mValue = nexp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (bdec && bdec->mDestructor)
|
||||||
mErrors->Error(ndec->mLocation, EERR_NO_DEFAULT_CONSTRUCTOR, "No default constructor for class", ndec->mBase->mIdent);
|
mErrors->Error(ndec->mLocation, EERR_NO_DEFAULT_CONSTRUCTOR, "No default constructor for class", ndec->mBase->mIdent);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (storageFlags & DTF_EXPORT)
|
if (storageFlags & DTF_EXPORT)
|
||||||
{
|
{
|
||||||
|
@ -3938,7 +3997,9 @@ int Parser::OverloadDistance(Declaration* fdec, Expression* pexp)
|
||||||
else
|
else
|
||||||
return NOOVERLOAD;
|
return NOOVERLOAD;
|
||||||
}
|
}
|
||||||
else if (ptype->IsSubType(ex->mDecType))
|
else if (ptype->mType == DT_TYPE_POINTER && etype->mType == DT_TYPE_ARRAY && ptype->mBase->IsSame(etype->mBase))
|
||||||
|
dist += 1;
|
||||||
|
else if (ptype->IsSubType(etype))
|
||||||
dist += 256;
|
dist += 256;
|
||||||
else
|
else
|
||||||
return NOOVERLOAD;
|
return NOOVERLOAD;
|
||||||
|
@ -4040,7 +4101,10 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
// Simple copy
|
// Simple copy
|
||||||
exp = pexp;
|
exp = pexp;
|
||||||
}
|
}
|
||||||
else if (exp->mDecType->mConstructor)
|
else
|
||||||
|
{
|
||||||
|
Declaration* fcons = exp->mDecType->mScope ? exp->mDecType->mScope->Lookup(exp->mDecType->mIdent) : nullptr;
|
||||||
|
if (fcons)
|
||||||
{
|
{
|
||||||
Declaration* tdec = new Declaration(mScanner->mLocation, DT_VARIABLE);
|
Declaration* tdec = new Declaration(mScanner->mLocation, DT_VARIABLE);
|
||||||
|
|
||||||
|
@ -4054,7 +4118,7 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
vexp->mDecValue = tdec;
|
vexp->mDecValue = tdec;
|
||||||
|
|
||||||
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
cexp->mDecValue = exp->mDecType->mConstructor;
|
cexp->mDecValue = fcons;
|
||||||
cexp->mDecType = cexp->mDecValue->mBase;
|
cexp->mDecType = cexp->mDecValue->mBase;
|
||||||
|
|
||||||
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
@ -4083,10 +4147,10 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
ResolveOverloadCall(cexp, fexp->mRight);
|
ResolveOverloadCall(cexp, fexp->mRight);
|
||||||
|
|
||||||
Expression* dexp = nullptr;
|
Expression* dexp = nullptr;
|
||||||
if (exp->mDecType->mBase->mDestructor)
|
if (exp->mDecType->mDestructor)
|
||||||
{
|
{
|
||||||
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
cexp->mDecValue = exp->mDecType->mBase->mDestructor;
|
cexp->mDecValue = exp->mDecType->mDestructor;
|
||||||
cexp->mDecType = cexp->mDecValue->mBase;
|
cexp->mDecType = cexp->mDecValue->mBase;
|
||||||
|
|
||||||
dexp = new Expression(mScanner->mLocation, EX_CALL);
|
dexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
@ -4114,6 +4178,7 @@ Expression* Parser::ParsePostfixExpression(bool lhs)
|
||||||
exp = nexp->ConstantFold(mErrors);
|
exp = nexp->ConstantFold(mErrors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (exp->mDecType->mType == DT_TYPE_POINTER && exp->mDecType->mBase->mType == DT_TYPE_FUNCTION)
|
if (exp->mDecType->mType == DT_TYPE_POINTER && exp->mDecType->mBase->mType == DT_TYPE_FUNCTION)
|
||||||
|
@ -4348,7 +4413,9 @@ Expression* Parser::ParseAddExpression(bool lhs)
|
||||||
else
|
else
|
||||||
nexp->mDecType = exp->mDecType;
|
nexp->mDecType = exp->mDecType;
|
||||||
|
|
||||||
exp = nexp->ConstantFold(mErrors);
|
exp = CheckOperatorOverload(nexp);
|
||||||
|
|
||||||
|
exp = exp->ConstantFold(mErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
return exp;
|
return exp;
|
||||||
|
@ -4567,6 +4634,66 @@ Expression* Parser::CheckOperatorOverload(Expression* exp)
|
||||||
ResolveOverloadCall(nexp->mLeft, nexp->mRight);
|
ResolveOverloadCall(nexp->mLeft, nexp->mRight);
|
||||||
nexp->mDecType = nexp->mLeft->mDecType->mBase;
|
nexp->mDecType = nexp->mLeft->mDecType->mBase;
|
||||||
|
|
||||||
|
exp = nexp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (exp->mType == EX_BINARY)
|
||||||
|
{
|
||||||
|
const Ident* opident = nullptr;
|
||||||
|
switch (exp->mToken)
|
||||||
|
{
|
||||||
|
case TK_ADD:
|
||||||
|
opident = Ident::Unique("operator+");
|
||||||
|
break;
|
||||||
|
case TK_SUB:
|
||||||
|
opident = Ident::Unique("operator+");
|
||||||
|
break;
|
||||||
|
case TK_MUL:
|
||||||
|
opident = Ident::Unique("operator+");
|
||||||
|
break;
|
||||||
|
case TK_DIV:
|
||||||
|
opident = Ident::Unique("operator+");
|
||||||
|
break;
|
||||||
|
case TK_MOD:
|
||||||
|
opident = Ident::Unique("operator%");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opident)
|
||||||
|
{
|
||||||
|
Declaration* tdec = exp->mLeft->mDecType;
|
||||||
|
if (tdec->mType == DT_TYPE_STRUCT)
|
||||||
|
{
|
||||||
|
Declaration* mdec = tdec->mScope->Lookup(opident);
|
||||||
|
if (mdec)
|
||||||
|
{
|
||||||
|
Expression* nexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
|
||||||
|
nexp->mLeft = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
|
nexp->mLeft->mDecType = mdec->mBase;
|
||||||
|
nexp->mLeft->mDecValue = mdec;
|
||||||
|
|
||||||
|
nexp->mDecType = mdec->mBase;
|
||||||
|
nexp->mRight = exp->mRight;
|
||||||
|
|
||||||
|
Expression* texp = new Expression(nexp->mLocation, EX_PREFIX);
|
||||||
|
texp->mToken = TK_BINARY_AND;
|
||||||
|
texp->mLeft = exp->mLeft;
|
||||||
|
texp->mDecType = new Declaration(nexp->mLocation, DT_TYPE_POINTER);
|
||||||
|
texp->mDecType->mFlags |= DTF_CONST | DTF_DEFINED;
|
||||||
|
texp->mDecType->mBase = exp->mDecType;
|
||||||
|
texp->mDecType->mSize = 2;
|
||||||
|
|
||||||
|
Expression* lexp = new Expression(nexp->mLocation, EX_LIST);
|
||||||
|
lexp->mLeft = texp;
|
||||||
|
lexp->mRight = nexp->mRight;
|
||||||
|
nexp->mRight = lexp;
|
||||||
|
|
||||||
|
ResolveOverloadCall(nexp->mLeft, nexp->mRight);
|
||||||
|
nexp->mDecType = nexp->mLeft->mDecType->mBase;
|
||||||
|
|
||||||
exp = nexp;
|
exp = nexp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -1397,14 +1397,34 @@ 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
|
||||||
{
|
{
|
||||||
mToken = TK_IDENT;
|
mToken = TK_IDENT;
|
||||||
|
|
Loading…
Reference in New Issue