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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ptype && (ptype->mType == DT_TYPE_STRUCT || ptype->mType == DT_TYPE_UNION))
|
||||||
vr = TranslateExpression(procType, proc, block, texp, destack, breakBlock, continueBlock, inlineMapper, &vp);
|
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,12 +2660,6 @@ void Parser::ParseVariableInit(Declaration* ndec)
|
||||||
else
|
else
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
|
|
||||||
if (pexp && pexp->mType != EX_LIST && ndec->mBase->CanAssign(pexp->mDecType))
|
|
||||||
{
|
|
||||||
ndec->mValue = pexp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Declaration* fcons = ndec->mBase->mScope ? ndec->mBase->mScope->Lookup(ndec->mBase->mIdent) : nullptr;
|
Declaration* fcons = ndec->mBase->mScope ? ndec->mBase->mScope->Lookup(ndec->mBase->mIdent) : nullptr;
|
||||||
|
|
||||||
if (fcons)
|
if (fcons)
|
||||||
|
@ -2727,11 +2721,12 @@ void Parser::ParseVariableInit(Declaration* ndec)
|
||||||
|
|
||||||
ndec->mValue = nexp;
|
ndec->mValue = nexp;
|
||||||
}
|
}
|
||||||
else
|
else if (pexp && pexp->mType != EX_LIST && ndec->mBase->CanAssign(pexp->mDecType))
|
||||||
{
|
{
|
||||||
ndec->mValue = pexp;
|
ndec->mValue = pexp;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
mErrors->Error(pexp->mLocation, EERR_INCOMPATIBLE_TYPES, "Can not initialize variable with expression", ndec->mIdent);
|
||||||
}
|
}
|
||||||
|
|
||||||
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