Add friend classes

This commit is contained in:
drmortalwombat 2023-08-20 15:06:51 +02:00
parent 4732f76bd5
commit 54296bdd71
2 changed files with 16 additions and 3 deletions

View File

@ -13,7 +13,7 @@ inline ios::~ios(void)
} }
char ios::fill(void) char ios::fill(void) const
{ {
return mFill; return mFill;
} }

View File

@ -256,6 +256,8 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt, Declaratio
{ {
mScope = oscope; mScope = oscope;
Declaration* fdec = ParseDeclaration(nullptr, true, false); Declaration* fdec = ParseDeclaration(nullptr, true, false);
if (fdec->mType == DT_ANON)
fdec = fdec->mBase;
dec->mFriends.Push(fdec); dec->mFriends.Push(fdec);
mScope = dec->mScope; mScope = dec->mScope;
} }
@ -268,8 +270,6 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt, Declaratio
Declaration* mdec = ParseDeclaration(nullptr, false, false, pthis); Declaration* mdec = ParseDeclaration(nullptr, false, false, pthis);
if (mdec) if (mdec)
{ {
mdec->mFlags |= flags & (DTF_PRIVATE | DTF_PROTECTED);
mdec->mQualIdent = dec->mScope->Mangle(mdec->mIdent); mdec->mQualIdent = dec->mScope->Mangle(mdec->mIdent);
int offset = dec->mSize; int offset = dec->mSize;
@ -278,6 +278,8 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt, Declaratio
if (mdec->mBase->mType == DT_TYPE_FUNCTION) if (mdec->mBase->mType == DT_TYPE_FUNCTION)
{ {
mdec->mFlags |= flags & (DTF_PRIVATE | DTF_PROTECTED);
if (mdec->mBase->mFlags & DTF_VIRTUAL) if (mdec->mBase->mFlags & DTF_VIRTUAL)
needVTable = true; needVTable = true;
@ -293,6 +295,8 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt, Declaratio
} }
else if ((mCompilerOptions & COPT_CPLUSPLUS) && mdec->mType == DT_ANON) else if ((mCompilerOptions & COPT_CPLUSPLUS) && mdec->mType == DT_ANON)
{ {
mdec->mFlags |= flags & (DTF_PRIVATE | DTF_PROTECTED);
ConsumeToken(TK_SEMICOLON); ConsumeToken(TK_SEMICOLON);
// anon element // anon element
} }
@ -300,6 +304,8 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt, Declaratio
{ {
while (mdec) while (mdec)
{ {
mdec->mFlags |= flags & (DTF_PRIVATE | DTF_PROTECTED);
if (!(mdec->mBase->mFlags & DTF_DEFINED)) if (!(mdec->mBase->mFlags & DTF_DEFINED))
mErrors->Error(mdec->mLocation, EERR_UNDEFINED_OBJECT, "Undefined type used in struct member declaration"); mErrors->Error(mdec->mLocation, EERR_UNDEFINED_OBJECT, "Undefined type used in struct member declaration");
@ -3915,8 +3921,13 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex
} }
if (!pdec) if (!pdec)
{
if (!pthis && (ndec->mBase->mFlags & DTF_FUNC_THIS))
mErrors->Error(ndec->mLocation, EERR_DECLARATION_DIFFERS, "Function declaration differs", ndec->mIdent);
pcdec->mNext = ndec; pcdec->mNext = ndec;
} }
}
if (pdec) if (pdec)
{ {
@ -4870,6 +4881,8 @@ Expression* Parser::ParseQualify(Expression* exp)
{ {
if (dtype->mFriends.Contains(mFunction)) if (dtype->mFriends.Contains(mFunction))
; ;
else if (mThisPointer && mThisPointer->mBase && mThisPointer->mBase->mBase && dtype->mFriends.Contains(mThisPointer->mBase->mBase->ToMutableType()))
;
else else
mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Struct member identifier not visible", ident); mErrors->Error(mScanner->mLocation, EERR_OBJECT_NOT_FOUND, "Struct member identifier not visible", ident);
} }