Add variadic sizeof...
This commit is contained in:
parent
06ebf85d9d
commit
c674fc9a8b
|
@ -1069,15 +1069,15 @@ const Ident* Declaration::MangleIdent(void)
|
|||
}
|
||||
else if (mType == DT_TYPE_REFERENCE)
|
||||
{
|
||||
mMangleIdent = mBase->MangleIdent()->PreMangle("&");
|
||||
mMangleIdent = mBase->MangleIdent()->Mangle("&");
|
||||
}
|
||||
else if (mType == DT_TYPE_RVALUEREF)
|
||||
{
|
||||
mMangleIdent = mBase->MangleIdent()->PreMangle("&&");
|
||||
mMangleIdent = mBase->MangleIdent()->Mangle("&&");
|
||||
}
|
||||
else if (mType == DT_TYPE_POINTER)
|
||||
{
|
||||
mMangleIdent = mBase->MangleIdent()->PreMangle("*");
|
||||
mMangleIdent = mBase->MangleIdent()->Mangle("*");
|
||||
}
|
||||
else if (mType == DT_TYPE_ARRAY)
|
||||
{
|
||||
|
@ -1121,11 +1121,7 @@ const Ident* Declaration::MangleIdent(void)
|
|||
Declaration* dec = mBase;
|
||||
while (dec)
|
||||
{
|
||||
const Ident* id;
|
||||
if (dec->mBase)
|
||||
id = dec->mBase->MangleIdent();
|
||||
else
|
||||
id = dec->MangleIdent();
|
||||
const Ident* id = dec->MangleIdent();
|
||||
|
||||
if (id)
|
||||
{
|
||||
|
|
|
@ -1851,11 +1851,19 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
var->mIdent = dec->mQualIdent;
|
||||
var->mOffset = 0;
|
||||
var->mSize = dec->mSize;
|
||||
if ((dec->mFlags & DTF_VAR_ALIASING) || dec->mBase->mType == DT_TYPE_ARRAY)
|
||||
var->mAliased = true;
|
||||
var->mLinkerObject = mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_DATA, dec->mAlignment);
|
||||
dec->mLinkerObject = var->mLinkerObject;
|
||||
|
||||
if (dec->mBase->mFlags & DTF_CONST)
|
||||
var->mLinkerObject->mFlags |= LOBJF_CONST;
|
||||
else if ((dec->mFlags & DTF_VAR_ALIASING) || dec->mBase->mType == DT_TYPE_ARRAY)
|
||||
var->mAliased = true;
|
||||
var->mLinkerObject->AddData(dec->mData, dec->mSize);
|
||||
|
||||
LinkerObject* aobj = mLinker->FindSame(var->mLinkerObject);
|
||||
if (aobj)
|
||||
var->mLinkerObject = aobj;
|
||||
|
||||
dec->mLinkerObject = var->mLinkerObject;
|
||||
proc->mModule->mGlobalVars.Push(var);
|
||||
}
|
||||
|
||||
|
@ -4989,7 +4997,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, dec->mAlignment));
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
if (proc->mIdent && !strcmp(proc->mIdent->mString, "main"))
|
||||
exp->Dump(0);
|
||||
#endif
|
||||
|
|
|
@ -274,6 +274,38 @@ LinkerObject* Linker::FindObjectByAddr(int bank, int addr)
|
|||
return FindObjectByAddr(addr);
|
||||
}
|
||||
|
||||
LinkerObject* Linker::FindSame(LinkerObject* obj)
|
||||
{
|
||||
for (int i = 0; i < mObjects.Size(); i++)
|
||||
{
|
||||
LinkerObject* lobj = mObjects[i];
|
||||
if (lobj != obj && obj->IsSameConst(lobj))
|
||||
return lobj;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool LinkerObject::IsSameConst(const LinkerObject* obj) const
|
||||
{
|
||||
if ((mFlags & LOBJF_CONST) && mFlags == obj->mFlags &&
|
||||
mSection == obj->mSection && mSize == obj->mSize && mAlignment == obj->mAlignment &&
|
||||
mReferences.Size() == obj->mReferences.Size())
|
||||
{
|
||||
for (int i = 0; i < mSize; i++)
|
||||
if (mData[i] != obj->mData[i])
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < mReferences.Size(); i++)
|
||||
if (mReferences[i] != obj->mReferences[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
LinkerObject * Linker::AddObject(const Location& location, const Ident* ident, LinkerSection * section, LinkerObjectType type, int alignment)
|
||||
{
|
||||
LinkerObject* obj = new LinkerObject;
|
||||
|
|
|
@ -213,6 +213,8 @@ public:
|
|||
void MoveToSection(LinkerSection* section);
|
||||
|
||||
void MarkRelevant(void);
|
||||
|
||||
bool IsSameConst(const LinkerObject* obj) const;
|
||||
};
|
||||
|
||||
class LinkerOverlay
|
||||
|
@ -246,6 +248,7 @@ public:
|
|||
bool IsSectionPlaced(LinkerSection* section);
|
||||
|
||||
LinkerObject * AddObject(const Location & location, const Ident* ident, LinkerSection * section, LinkerObjectType type, int alignment = 1);
|
||||
LinkerObject* FindSame(LinkerObject* obj);
|
||||
|
||||
LinkerOverlay* AddOverlay(const Location& location, const Ident* ident, int bank);
|
||||
|
||||
|
|
|
@ -3415,7 +3415,7 @@ Expression* Parser::AddFunctionCallRefReturned(Expression* exp)
|
|||
else if ((pdec->mBase->mType == DT_TYPE_REFERENCE || pdec->mBase->mType == DT_TYPE_RVALUEREF) && pex->mType == EX_CONSTANT)
|
||||
{
|
||||
// A simple constant is passed by const ref
|
||||
if (pex->mDecValue->mType == DT_CONST_INTEGER || pex->mDecValue->mType == DT_CONST_FLOAT || pex->mDecValue->mType == DT_CONST_POINTER)
|
||||
if (pex->mDecValue->mType == DT_CONST_INTEGER || pex->mDecValue->mType == DT_CONST_FLOAT || pex->mDecValue->mType == DT_CONST_POINTER || pex->mDecValue->mType == DT_CONST_ADDRESS)
|
||||
{
|
||||
int nindex = mLocalIndex++;
|
||||
|
||||
|
@ -5076,7 +5076,7 @@ Expression* Parser::ParseSimpleExpression(bool lhs)
|
|||
dec->mBase = new Declaration(mScanner->mLocation, DT_TYPE_ARRAY);
|
||||
dec->mBase->mSize = dec->mSize;
|
||||
dec->mBase->mBase = TheConstCharTypeDeclaration;
|
||||
dec->mBase->mFlags |= DTF_DEFINED;
|
||||
dec->mBase->mFlags |= DTF_DEFINED | DTF_CONST;
|
||||
uint8* d = new uint8[size + 1];
|
||||
dec->mData = d;
|
||||
|
||||
|
@ -5343,10 +5343,32 @@ Expression* Parser::ParseSimpleExpression(bool lhs)
|
|||
break;
|
||||
case TK_SIZEOF:
|
||||
mScanner->NextToken();
|
||||
rexp = ParseParenthesisExpression();
|
||||
|
||||
dec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER);
|
||||
dec->mBase = TheSignedIntTypeDeclaration;
|
||||
dec->mInteger = rexp->mDecType->mSize;
|
||||
|
||||
if (ConsumeTokenIf(TK_ELLIPSIS))
|
||||
{
|
||||
rexp = ParseParenthesisExpression();
|
||||
if (rexp->mType == EX_PACK)
|
||||
{
|
||||
int n = 0;
|
||||
Declaration* vdec = rexp->mDecValue->mParams;
|
||||
while (vdec)
|
||||
{
|
||||
n++;
|
||||
vdec = vdec->mNext;
|
||||
}
|
||||
dec->mInteger = n;
|
||||
}
|
||||
else
|
||||
mErrors->Error(mScanner->mLocation, EERR_INVALID_PACK_USAGE, "variadic pack expected");
|
||||
}
|
||||
else
|
||||
{
|
||||
rexp = ParseParenthesisExpression();
|
||||
dec->mInteger = rexp->mDecType->mSize;
|
||||
}
|
||||
exp = new Expression(mScanner->mLocation, EX_CONSTANT);
|
||||
exp->mDecValue = dec;
|
||||
exp->mDecType = dec->mBase;
|
||||
|
|
Loading…
Reference in New Issue