Init const copy construction

This commit is contained in:
drmortalwombat 2023-07-02 20:48:46 +02:00
parent ef0a79b8f0
commit 6c7347310b
4 changed files with 95 additions and 72 deletions

View File

@ -75,6 +75,11 @@ inline const char * string::tocstr(void) const
return cstr;
}
inline unsigned string::size(void) const
{
return strlen(cstr);
}
string string::operator+(const string & s)
{
return string(cstr, s.cstr);
@ -145,3 +150,13 @@ inline bool string::operator>=(const char * s) const
{
return strcmp(cstr, s) >= 0;
}
inline char & string::operator[](unsigned t)
{
return cstr[t];
}
inline char string::operator[](unsigned t) const
{
return cstr[t];
}

View File

@ -13,6 +13,8 @@ public:
string(const char * s1, const char * s2);
~string(void);
unsigned size(void) const;
string & operator=(const string & s);
string & operator=(const char * s);
@ -37,6 +39,9 @@ public:
bool operator>=(const string & s) const;
bool operator>=(const char * s) const;
char & operator[](unsigned t);
char operator[](unsigned t) const;
const char * tocstr(void) const;
};

View File

@ -1073,7 +1073,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* pro
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)
{
@ -2991,7 +2994,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
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)
{
@ -3018,7 +3023,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
#endif
}
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))
{

View File

@ -2660,12 +2660,6 @@ void Parser::ParseVariableInit(Declaration* ndec)
else
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;
if (fcons)
@ -2727,11 +2721,12 @@ void Parser::ParseVariableInit(Declaration* ndec)
ndec->mValue = nexp;
}
else
else if (pexp && pexp->mType != EX_LIST && ndec->mBase->CanAssign(pexp->mDecType))
{
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)