By default, inner struct in class should take the scope of it's outer class

This commit is contained in:
ZZYZX 2017-03-04 21:30:38 +02:00 committed by Christoph Oelckers
parent 0a7aebae93
commit 6c90d05407
3 changed files with 29 additions and 2 deletions

View file

@ -44,6 +44,19 @@ int FScopeBarrier::FlagsFromSide(int side)
} }
} }
int FScopeBarrier::ObjectFlagsFromSide(int side)
{
switch (side)
{
case Side_Play:
return OF_Play;
case Side_UI:
return OF_UI;
default:
return 0;
}
}
// used for errors // used for errors
const char* FScopeBarrier::StringFromSide(int side) const char* FScopeBarrier::StringFromSide(int side)
{ {
@ -72,6 +85,14 @@ int FScopeBarrier::ChangeSideInFlags(int flags, int side)
return flags; return flags;
} }
// this modifies OF_ flags and sets the side properly.
int FScopeBarrier::ChangeSideInObjectFlags(int flags, int side)
{
flags &= ~(OF_UI | OF_Play);
flags |= ObjectFlagsFromSide(side);
return flags;
}
FScopeBarrier::FScopeBarrier() FScopeBarrier::FScopeBarrier()
{ {
sidefrom = -1; sidefrom = -1;

View file

@ -35,12 +35,15 @@ struct FScopeBarrier
// //
static int FlagsFromSide(int side); static int FlagsFromSide(int side);
static int ObjectFlagsFromSide(int side);
// used for errors // used for errors
static const char* StringFromSide(int side); static const char* StringFromSide(int side);
// this modifies VARF_ flags and sets the side properly. // this modifies VARF_ flags and sets the side properly.
static int ChangeSideInFlags(int flags, int side); static int ChangeSideInFlags(int flags, int side);
// this modifies OF_ flags and sets the side properly.
static int ChangeSideInObjectFlags(int flags, int side);
FScopeBarrier(); FScopeBarrier();
FScopeBarrier(int flags1, int flags2, const char* name); FScopeBarrier(int flags1, int flags2, const char* name);

View file

@ -501,10 +501,13 @@ void ZCCCompiler::CreateStructTypes()
Error(s->strct, "Struct %s has incompatible flags", s->NodeName().GetChars()); Error(s->strct, "Struct %s has incompatible flags", s->NodeName().GetChars());
} }
if (outer) s->Type()->ObjectFlags = FScopeBarrier::ChangeSideInObjectFlags(s->Type()->ObjectFlags, FScopeBarrier::SideFromObjectFlags(outer->ObjectFlags));
if (s->strct->Flags & ZCC_UIFlag) if (s->strct->Flags & ZCC_UIFlag)
s->Type()->ObjectFlags |= OF_UI; s->Type()->ObjectFlags = FScopeBarrier::ChangeSideInObjectFlags(s->Type()->ObjectFlags, FScopeBarrier::Side_UI);
if (s->strct->Flags & ZCC_Play) if (s->strct->Flags & ZCC_Play)
s->Type()->ObjectFlags |= OF_Play; s->Type()->ObjectFlags = FScopeBarrier::ChangeSideInObjectFlags(s->Type()->ObjectFlags, FScopeBarrier::Side_Play);
if (s->strct->Flags & ZCC_ClearScope)
s->Type()->ObjectFlags = FScopeBarrier::ChangeSideInObjectFlags(s->Type()->ObjectFlags, FScopeBarrier::Side_PlainData); // don't inherit the scope from the outer class
s->strct->Symbol = new PSymbolType(s->NodeName(), s->Type()); s->strct->Symbol = new PSymbolType(s->NodeName(), s->Type());
syms->AddSymbol(s->strct->Symbol); syms->AddSymbol(s->strct->Symbol);