Skip to content

Commit

Permalink
Semantic finer split 14 (dsymbol.d: switch to mixin for XXXstate and …
Browse files Browse the repository at this point in the history
…compilation fixes)
  • Loading branch information
Syniurge committed Sep 15, 2017
1 parent fc4ed0b commit c87c326
Showing 1 changed file with 33 additions and 72 deletions.
105 changes: 33 additions & 72 deletions src/ddmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -191,79 +191,46 @@ extern (C++) class Dsymbol : RootObject
// (only use this with ddoc)
UnitTestDeclaration ddocUnittest;

version(StringSupported)
private static extern(D) string semStates(string[] names)
{
static string semStates(string[] names)
{
string result;
uint offset;
foreach(name; names)
{
uint stateOffset = offset;
uint mask = 0x3 << offset;
offset += 2;

OutBuffer buf;
buf.printf("%u", stateOffset);
char[] s_stateOffset = buf.peekSlice();
buf.reset();
buf.printf("%u", stateOffset);
char[] s_mask = buf.peekSlice();

result ~= " @property SemState " ~ name ~ "state() { return semanticRun & mask; }\n";
result ~=" @property SemState " ~ name ~ "state(SemState value)" ~
" { return semanticRun = (semanticRun & ~" ~ mask ~ ") | (value << " ~ stateOffset ~ "); }\n";
}
return result;
}
mixin(semStates(["members"]));
}
else
{
@property SemState membersState() { return semanticRun & 0x3; }
@property SemState membersState(SemState value) { return semanticRun = (semanticRun & ~0x3) | value; }

@property SemState typeState() { return (semanticRun & (0x3<<2)) >> 2; }
@property SemState typeState(SemState value) { return semanticRun = (semanticRun & ~(0x3<<2)) | (value << 2); }

@property SemState initializerState() { return (semanticRun & (0x3<<4)) >> 4; }
@property SemState initializerState(SemState value) { return semanticRun = (semanticRun & ~(0x3<<4)) | (value << 4); }
alias bodyState = initializerState;
alias aliasState = initializerState;

@property SemState sizeState() { return (semanticRun & (0x3<<6)) >> 6; }
@property SemState sizeState(SemState value) { return semanticRun = (semanticRun & ~(0x3<<6)) | (value << 6); }
import std.conv;

This comment has been minimized.

Copy link
@ibuclaw

ibuclaw Sep 15, 2017

Member

Just as a note, I don't think the policy of rejecting phobos in the compiler has changed.

This comment has been minimized.

Copy link
@Syniurge

Syniurge Sep 15, 2017

Author Contributor

Noted, I'll add a simple int to string conversion function to replace to!string.


@property SemState baseClassState() { return (semanticRun & (0x3<<8)) >> 8; }
@property SemState baseClassState(SemState value) { return semanticRun = (semanticRun & ~(0x3<<8)) | (value << 8); }
alias includeState = baseClassState;
string result;
uint offset;
foreach(name; names)
{
uint mask = 0x3 << offset;

@property SemState tiargsState() { return (semanticRun & (0x3<<10)) >> 10; }
@property SemState tiargsState(SemState value) { return semanticRun = (semanticRun & ~(0x3<<10)) | (value << 10); }
alias fieldsState = tiargsState;
alias vtblState = tiargsState;
auto s_offset = offset.to!string;
auto s_mask = mask.to!string;

@property SemState addMemberState() { return (semanticRun & (0x3<<12)) >> 12; }
@property SemState addMemberState(SemState value) { return semanticRun = (semanticRun & ~(0x3<<12)) | (value << 12); }
result ~= " @property SemState " ~ name ~ "State()" ~
" { return cast(SemState) (semanticRun & " ~ s_mask ~ ") >>" ~ s_offset ~ "; }\n";
result ~=" @property SemState " ~ name ~ "State(SemState value)" ~
" { semanticRun = (semanticRun & ~" ~ s_mask ~ ") | (value << " ~ s_offset ~ "); return value; }\n";

@property SemState semanticState() { return (semanticRun & (0x3<<14)) >> 14; }
@property SemState semanticState(SemState value) { return semanticRun = (semanticRun & ~(0x3<<14)) | (value << 14); }
offset += 2;
}
return result;
}

mixin(semStates(["addMember", "members", "type", "initializer", "size", "baseClass", "tiargs", "semantic"]));

// vtbl?
}
alias bodyState = initializerState;
alias aliasState = initializerState;
alias includeState = baseClassState;
alias fieldsState = tiargsState;
alias vtblState = tiargsState;

final extern (D) this()
{
//printf("Dsymbol::Dsymbol(%p)\n", this);
this.semanticRun = PASSinit;
}

final extern (D) this(Identifier ident)
{
//printf("Dsymbol::Dsymbol(%p, ident)\n", this);
this.ident = ident;
this.semanticRun = PASSinit;
}

static Dsymbol create(Identifier ident)
Expand Down Expand Up @@ -813,8 +780,8 @@ extern (C++) class Dsymbol : RootObject
return null;
}
ti.tempdecl = td;
if (!ti.semanticRun)
ti.semantic(sc);
if (ti.semanticState != SemState.Done) // FWDREF FIXME should probably go
ti.semantic();
sm = ti.toAlias();
break;
}
Expand Down Expand Up @@ -1738,7 +1705,7 @@ public:
{
Dsymbol s = (*members)[i];
if (AttribDeclaration a = s.isAttribDeclaration())
result = _foreach(sc, a.include(sc, null), dg, &n);
result = _foreach(sc, a.include(null), dg, &n);
else if (TemplateMixin tm = s.isTemplateMixin())
result = _foreach(sc, tm.members, dg, &n);
else if (s.isTemplateInstance())
Expand All @@ -1764,9 +1731,7 @@ public:

Scope* newScope()
{
// always push a new scope
sc = _scope.push(this);
return sc;
return _scope.push(this);
}

uint nextMember;
Expand Down Expand Up @@ -1802,7 +1767,7 @@ public:
if (!symtab)
symtab = new DsymbolTable();

sc = newScope();
auto sc = newScope();
scope(exit) while (sc != _scope)
sc = sc.pop();

Expand Down Expand Up @@ -1831,7 +1796,7 @@ public:
void defer()
{
semanticState = SemState.Defer;
_scope._module.addDeferredSemantic(s);
_scope._module.addDeferredSemantic(this);
}

// Ungag errors when not speculative
Expand All @@ -1840,11 +1805,7 @@ public:
determineMembers();
if (membersState == SemState.Defer)
return defer();
if (membersState != SemState.Done)
{
error("member expansion failed");
return;
}
assert (membersState == SemState.Done, "member expansion failed");

if (members)
foreach (s; *members)
Expand Down Expand Up @@ -1967,7 +1928,7 @@ extern (C++) final class ArrayScopeSymbol : ScopeDsymbol
Expression e = new IntegerExp(Loc(), td.objects.dim, Type.tsize_t);
v._init = new ExpInitializer(Loc(), e);
v.storage_class |= STCtemp | STCstatic | STCconst;
v.semantic(sc);
v.semantic(); // FWDREF FIXME?
return v;
}
if (type)
Expand All @@ -1978,7 +1939,7 @@ extern (C++) final class ArrayScopeSymbol : ScopeDsymbol
Expression e = new IntegerExp(Loc(), type.arguments.dim, Type.tsize_t);
v._init = new ExpInitializer(Loc(), e);
v.storage_class |= STCtemp | STCstatic | STCconst;
v.semantic(sc);
v.semantic(); // FWDREF FIXME?
return v;
}
if (exp.op == TOKindex)
Expand Down Expand Up @@ -2117,7 +2078,7 @@ extern (C++) final class ArrayScopeSymbol : ScopeDsymbol
}
*pvar = v;
}
(*pvar).semantic(sc);
(*pvar).semantic(); // FWDREF FIXME?
return (*pvar);
}
return null;
Expand Down

0 comments on commit c87c326

Please sign in to comment.