Init const copy construction
This commit is contained in:
parent
ef0a79b8f0
commit
6c7347310b
|
@ -75,6 +75,11 @@ inline const char * string::tocstr(void) const
|
||||||
return cstr;
|
return cstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline unsigned string::size(void) const
|
||||||
|
{
|
||||||
|
return strlen(cstr);
|
||||||
|
}
|
||||||
|
|
||||||
string string::operator+(const string & s)
|
string string::operator+(const string & s)
|
||||||
{
|
{
|
||||||
return string(cstr, s.cstr);
|
return string(cstr, s.cstr);
|
||||||
|
@ -145,3 +150,13 @@ inline bool string::operator>=(const char * s) const
|
||||||
{
|
{
|
||||||
return strcmp(cstr, s) >= 0;
|
return strcmp(cstr, s) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline char & string::operator[](unsigned t)
|
||||||
|
{
|
||||||
|
return cstr[t];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline char string::operator[](unsigned t) const
|
||||||
|
{
|
||||||
|
return cstr[t];
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ public:
|
||||||
string(const char * s1, const char * s2);
|
string(const char * s1, const char * s2);
|
||||||
~string(void);
|
~string(void);
|
||||||
|
|
||||||
|
unsigned size(void) const;
|
||||||
|
|
||||||
string & operator=(const string & s);
|
string & operator=(const string & s);
|
||||||
string & operator=(const char * s);
|
string & operator=(const char * s);
|
||||||
|
|
||||||
|
@ -37,6 +39,9 @@ public:
|
||||||
bool operator>=(const string & s) const;
|
bool operator>=(const string & s) const;
|
||||||
bool operator>=(const char * s) const;
|
bool operator>=(const char * s) const;
|
||||||
|
|
||||||
|
char & operator[](unsigned t);
|
||||||
|
char operator[](unsigned t) const;
|
||||||
|
|
||||||
const char * tocstr(void) const;
|
const char * tocstr(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1073,7 +1073,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* pro
|
||||||
|
|
||||||
block->Append(ins);
|
block->Append(ins);
|
||||||
|
|
||||||
return ExValue(rdec->mBase, ins->mDst.mTemp, 1);
|
ExValue rv(rdec->mBase, ins->mDst.mTemp, 1);
|
||||||
|
if (ins->mDst.mType != DT_TYPE_REFERENCE)
|
||||||
|
rv = Dereference(proc, exp, block, rv);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
else if (lrexp)
|
else if (lrexp)
|
||||||
{
|
{
|
||||||
|
@ -2991,7 +2994,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
||||||
pex = nullptr;
|
pex = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExValue vp(pdec ? pdec->mBase : TheSignedIntTypeDeclaration, ains->mDst.mTemp, 1);
|
Declaration* ptype = pdec ? pdec->mBase : texp->mDecType;
|
||||||
|
|
||||||
|
ExValue vp(ptype ? ptype : TheSignedIntTypeDeclaration, ains->mDst.mTemp, 1);
|
||||||
|
|
||||||
if (pdec && pdec->mBase->mType == DT_TYPE_REFERENCE && texp->mType == EX_CALL)
|
if (pdec && pdec->mBase->mType == DT_TYPE_REFERENCE && texp->mType == EX_CALL)
|
||||||
{
|
{
|
||||||
|
@ -3018,7 +3023,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
vr = TranslateExpression(procType, proc, block, texp, destack, breakBlock, continueBlock, inlineMapper, &vp);
|
if (ptype && (ptype->mType == DT_TYPE_STRUCT || ptype->mType == DT_TYPE_UNION))
|
||||||
|
vr = TranslateExpression(procType, proc, block, texp, destack, breakBlock, continueBlock, inlineMapper, &vp);
|
||||||
|
else
|
||||||
|
vr = TranslateExpression(procType, proc, block, texp, destack, breakBlock, continueBlock, inlineMapper, nullptr);
|
||||||
|
|
||||||
if (!(pdec && pdec->mBase->mType == DT_TYPE_REFERENCE) && (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION))
|
if (!(pdec && pdec->mBase->mType == DT_TYPE_REFERENCE) && (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION))
|
||||||
{
|
{
|
||||||
|
|
|
@ -2660,78 +2660,73 @@ void Parser::ParseVariableInit(Declaration* ndec)
|
||||||
else
|
else
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
|
|
||||||
if (pexp && pexp->mType != EX_LIST && ndec->mBase->CanAssign(pexp->mDecType))
|
Declaration* fcons = ndec->mBase->mScope ? ndec->mBase->mScope->Lookup(ndec->mBase->mIdent) : nullptr;
|
||||||
|
|
||||||
|
if (fcons)
|
||||||
|
{
|
||||||
|
Declaration* mtype = ndec->mBase->ToMutableType();
|
||||||
|
|
||||||
|
Expression* vexp = new Expression(mScanner->mLocation, EX_VARIABLE);
|
||||||
|
vexp->mDecType = mtype;
|
||||||
|
vexp->mDecValue = ndec;
|
||||||
|
|
||||||
|
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
|
cexp->mDecValue = fcons;
|
||||||
|
cexp->mDecType = cexp->mDecValue->mBase;
|
||||||
|
|
||||||
|
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
fexp->mLeft = cexp;
|
||||||
|
fexp->mRight = pexp;
|
||||||
|
|
||||||
|
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 = mtype;
|
||||||
|
texp->mDecType->mSize = 2;
|
||||||
|
|
||||||
|
if (fexp->mRight)
|
||||||
|
{
|
||||||
|
Expression* lexp = new Expression(mScanner->mLocation, EX_LIST);
|
||||||
|
lexp->mLeft = texp;
|
||||||
|
lexp->mRight = fexp->mRight;
|
||||||
|
fexp->mRight = lexp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fexp->mRight = texp;
|
||||||
|
|
||||||
|
ResolveOverloadCall(cexp, fexp->mRight);
|
||||||
|
|
||||||
|
Expression* dexp = nullptr;
|
||||||
|
if (ndec->mBase->mDestructor)
|
||||||
|
{
|
||||||
|
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||||
|
cexp->mDecValue = ndec->mBase->mDestructor;
|
||||||
|
cexp->mDecType = cexp->mDecValue->mBase;
|
||||||
|
|
||||||
|
dexp = new Expression(mScanner->mLocation, EX_CALL);
|
||||||
|
dexp->mLeft = cexp;
|
||||||
|
dexp->mRight = texp;
|
||||||
|
}
|
||||||
|
|
||||||
|
Expression* nexp = new Expression(mScanner->mLocation, EX_CONSTRUCT);
|
||||||
|
|
||||||
|
nexp->mLeft = new Expression(mScanner->mLocation, EX_LIST);
|
||||||
|
nexp->mLeft->mLeft = fexp;
|
||||||
|
nexp->mLeft->mRight = dexp;
|
||||||
|
|
||||||
|
nexp->mRight = vexp;
|
||||||
|
nexp->mDecType = vexp->mDecType;
|
||||||
|
|
||||||
|
ndec->mValue = nexp;
|
||||||
|
}
|
||||||
|
else if (pexp && pexp->mType != EX_LIST && ndec->mBase->CanAssign(pexp->mDecType))
|
||||||
{
|
{
|
||||||
ndec->mValue = pexp;
|
ndec->mValue = pexp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
mErrors->Error(pexp->mLocation, EERR_INCOMPATIBLE_TYPES, "Can not initialize variable with expression", ndec->mIdent);
|
||||||
Declaration* fcons = ndec->mBase->mScope ? ndec->mBase->mScope->Lookup(ndec->mBase->mIdent) : nullptr;
|
|
||||||
|
|
||||||
if (fcons)
|
|
||||||
{
|
|
||||||
Declaration* mtype = ndec->mBase->ToMutableType();
|
|
||||||
|
|
||||||
Expression* vexp = new Expression(mScanner->mLocation, EX_VARIABLE);
|
|
||||||
vexp->mDecType = mtype;
|
|
||||||
vexp->mDecValue = ndec;
|
|
||||||
|
|
||||||
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
|
||||||
cexp->mDecValue = fcons;
|
|
||||||
cexp->mDecType = cexp->mDecValue->mBase;
|
|
||||||
|
|
||||||
Expression* fexp = new Expression(mScanner->mLocation, EX_CALL);
|
|
||||||
fexp->mLeft = cexp;
|
|
||||||
fexp->mRight = pexp;
|
|
||||||
|
|
||||||
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 = mtype;
|
|
||||||
texp->mDecType->mSize = 2;
|
|
||||||
|
|
||||||
if (fexp->mRight)
|
|
||||||
{
|
|
||||||
Expression* lexp = new Expression(mScanner->mLocation, EX_LIST);
|
|
||||||
lexp->mLeft = texp;
|
|
||||||
lexp->mRight = fexp->mRight;
|
|
||||||
fexp->mRight = lexp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fexp->mRight = texp;
|
|
||||||
|
|
||||||
ResolveOverloadCall(cexp, fexp->mRight);
|
|
||||||
|
|
||||||
Expression* dexp = nullptr;
|
|
||||||
if (ndec->mBase->mDestructor)
|
|
||||||
{
|
|
||||||
Expression* cexp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
|
||||||
cexp->mDecValue = ndec->mBase->mDestructor;
|
|
||||||
cexp->mDecType = cexp->mDecValue->mBase;
|
|
||||||
|
|
||||||
dexp = new Expression(mScanner->mLocation, EX_CALL);
|
|
||||||
dexp->mLeft = cexp;
|
|
||||||
dexp->mRight = texp;
|
|
||||||
}
|
|
||||||
|
|
||||||
Expression* nexp = new Expression(mScanner->mLocation, EX_CONSTRUCT);
|
|
||||||
|
|
||||||
nexp->mLeft = new Expression(mScanner->mLocation, EX_LIST);
|
|
||||||
nexp->mLeft->mLeft = fexp;
|
|
||||||
nexp->mLeft->mRight = dexp;
|
|
||||||
|
|
||||||
nexp->mRight = vexp;
|
|
||||||
nexp->mDecType = vexp->mDecType;
|
|
||||||
|
|
||||||
ndec->mValue = nexp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue