Skip to content

Commit

Permalink
Merge pull request #4887 from yebblies/idgenx
Browse files Browse the repository at this point in the history
Generate both id.c and id.d from idgen.d, in preperation for switch
  • Loading branch information
yebblies committed Aug 16, 2015
2 parents 5de6640 + 56d9744 commit 2d050ca
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
{
// Look for special class names

if (id == Id::__sizeof || id == Id::__xalignof || id == Id::mangleof)
if (id == Id::__sizeof || id == Id::__xalignof || id == Id::_mangleof)
error("illegal class name");

// BUG: What if this is the wrong TypeInfo, i.e. it is nested?
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ void Dsymbol::addMember(Scope *sc, ScopeDsymbol *sds)
}
if (sds->isAggregateDeclaration() || sds->isEnumDeclaration())
{
if (ident == Id::__sizeof || ident == Id::__xalignof || ident == Id::mangleof)
if (ident == Id::__sizeof || ident == Id::__xalignof || ident == Id::_mangleof)
error(".%s property cannot be redefined", ident->toChars());
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -2756,7 +2756,7 @@ Expression *Expression::toBoolean(Scope *sc)
/* Don't really need to check for opCast first, but by doing so we
* get better error messages if it isn't there.
*/
Dsymbol *fd = search_function(ad, Id::cast);
Dsymbol *fd = search_function(ad, Id::_cast);
if (fd)
{
e = new CastExp(loc, e, Type::tbool);
Expand Down Expand Up @@ -7137,7 +7137,7 @@ Expression *DotIdExp::semanticX(Scope *sc)
if (Expression *ex = unaSemantic(sc))
return ex;

if (ident == Id::mangleof)
if (ident == Id::_mangleof)
{
// symbol.mangleof
Dsymbol *ds;
Expand Down Expand Up @@ -7448,9 +7448,9 @@ Expression *DotIdExp::semanticY(Scope *sc, int flag)
return new ErrorExp();
}
else if (t1b->ty == Tpointer && e1->type->ty != Tenum &&
ident != Id::init && ident != Id::__sizeof &&
ident != Id::_init && ident != Id::__sizeof &&
ident != Id::__xalignof && ident != Id::offsetof &&
ident != Id::mangleof && ident != Id::stringof)
ident != Id::_mangleof && ident != Id::stringof)
{
Type *t1bn = t1b->nextOf();
if (flag)
Expand Down Expand Up @@ -13606,8 +13606,8 @@ Expression *EqualExp::semantic(Scope *sc)
{
if (needOpEquals(sd))
{
this->e1 = new DotIdExp(loc, e1, Id::tupleof);
this->e2 = new DotIdExp(loc, e2, Id::tupleof);
this->e1 = new DotIdExp(loc, e1, Id::_tupleof);
this->e2 = new DotIdExp(loc, e2, Id::_tupleof);
e = this;
}
else
Expand Down
61 changes: 54 additions & 7 deletions src/idgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Msgtable[] msgtable =
{ "max" },
{ "min" },
{ "This", "this" },
{ "super" },
{ "_super", "super" },
{ "ctor", "__ctor" },
{ "dtor", "__dtor" },
{ "__xdtor", "__xdtor" },
Expand All @@ -50,12 +50,12 @@ Msgtable[] msgtable =
{ "unitTest", "__unitTest" },
{ "require", "__require" },
{ "ensure", "__ensure" },
{ "init" },
{ "_init", "init" },
{ "__sizeof", "sizeof" },
{ "__xalignof", "alignof" },
{ "mangleof" },
{ "_mangleof", "mangleof" },
{ "stringof" },
{ "tupleof" },
{ "_tupleof", "tupleof" },
{ "length" },
{ "remove" },
{ "ptr" },
Expand Down Expand Up @@ -221,7 +221,7 @@ Msgtable[] msgtable =
{ "slice", "opSlice" },
{ "sliceass", "opSliceAssign" },
{ "call", "opCall" },
{ "cast", "opCast" },
{ "_cast", "opCast" },
{ "opIn" },
{ "opIn_r" },
{ "opStar" },
Expand Down Expand Up @@ -375,7 +375,7 @@ Msgtable[] msgtable =
int main()
{
{
auto fp = fopen("id.h","w");
auto fp = fopen("id.h","wb");
if (!fp)
{
printf("can't open id.h\n");
Expand Down Expand Up @@ -403,7 +403,7 @@ int main()
}

{
auto fp = fopen("id.c","w");
auto fp = fopen("id.c","wb");
if (!fp)
{
printf("can't open id.c\n");
Expand Down Expand Up @@ -442,5 +442,52 @@ int main()
fclose(fp);
}

{
auto fp = fopen("id.d","wb");
if (!fp)
{
printf("can't open id.d\n");
exit(EXIT_FAILURE);
}

fprintf(fp, "// File generated by idgen.d\n");
fprintf(fp, "\n");
fprintf(fp, "module ddmd.id;\n");
fprintf(fp, "\n");
fprintf(fp, "import ddmd.identifier, ddmd.tokens;\n");
fprintf(fp, "\n");
fprintf(fp, "struct Id\n");
fprintf(fp, "{\n");

foreach(e; msgtable)
{
auto id = e.ident;
auto p = e.name;

if (!p)
p = id;
fprintf(fp, " extern (C++) static __gshared Identifier %s;\n", id);
}

fprintf(fp, "\n");
fprintf(fp, " extern (C++) static void initialize()\n");
fprintf(fp, " {\n");

foreach(e; msgtable)
{
auto id = e.ident;
auto p = e.name;

if (!p)
p = id;
fprintf(fp," %s = Identifier.idPool(\"%s\");\n", id, p);
}

fprintf(fp, " }\n");
fprintf(fp, "}\n");

fclose(fp);
}

return EXIT_SUCCESS;
}
15 changes: 1 addition & 14 deletions src/magicport.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"interpret.c", "ctfeexpr.c", "traits.c", "builtin.c", "clone.c",
"arrayop.c", "aliasthis.h", "aliasthis.c", "json.h", "json.c",
"unittests.c", "imphint.c", "argtypes.c", "apply.c", "sapply.c", "sideeffect.c",
"ctfe.h", "canthrow.c", "target.c", "target.h", "id.c", "id.h",
"ctfe.h", "canthrow.c", "target.c", "target.h",
"impcnvtab.c", "visitor.h", "lib.h", "nogc.c", "nspace.h", "nspace.c",
"errors.c", "errors.h",
"tokens.c", "tokens.h",
Expand Down Expand Up @@ -1762,19 +1762,6 @@
"function skipspace"
]
},
{
"module" : "id",
"package" : "",
"imports" :
[
"identifier",
"tokens"
],
"members" :
[
"struct Id"
]
},
{
"module" : "identifier",
"package" : "",
Expand Down
34 changes: 17 additions & 17 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ Expression *Type::getProperty(Loc loc, Identifier *ident, int flag)
{
e = new IntegerExp(loc, alignsize(), Type::tsize_t);
}
else if (ident == Id::init)
else if (ident == Id::_init)
{
Type *tb = toBasetype();
e = defaultInitLiteral(loc);
Expand All @@ -2097,7 +2097,7 @@ Expression *Type::getProperty(Loc loc, Identifier *ident, int flag)
se->sinit = toInitializer(se->sd);
}
}
else if (ident == Id::mangleof)
else if (ident == Id::_mangleof)
{
if (!deco)
{
Expand Down Expand Up @@ -2176,7 +2176,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident, int flag)
return e;
}
}
else if (ident == Id::init)
else if (ident == Id::_init)
{
Type *tb = toBasetype();
e = defaultInitLiteral(e->loc);
Expand Down Expand Up @@ -2228,8 +2228,8 @@ Expression *Type::noMember(Scope *sc, Expression *e, Identifier *ident, int flag

if (ident != Id::__sizeof &&
ident != Id::__xalignof &&
ident != Id::init &&
ident != Id::mangleof &&
ident != Id::_init &&
ident != Id::_mangleof &&
ident != Id::stringof &&
ident != Id::offsetof)
{
Expand Down Expand Up @@ -3592,7 +3592,7 @@ Expression *TypeVector::dotExp(Scope *sc, Expression *e, Identifier *ident, int
e->type = basetype;
return e;
}
if (ident == Id::init || ident == Id::offsetof || ident == Id::stringof)
if (ident == Id::_init || ident == Id::offsetof || ident == Id::stringof)
{
// init should return a new VectorExp (Bugzilla 12776)
// offsetof does not work on a cast expression, so use e directly
Expand Down Expand Up @@ -6756,7 +6756,7 @@ void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsy
{
//printf("TypeIdentifier::resolve(sc = %p, idents = '%s')\n", sc, toChars());

if ((ident->equals(Id::super) || ident->equals(Id::This)) && !hasThis(sc))
if ((ident->equals(Id::_super) || ident->equals(Id::This)) && !hasThis(sc))
{
AggregateDeclaration *ad = sc->getStructClassScope();
if (ad)
Expand All @@ -6766,7 +6766,7 @@ void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsy
{
if (ident->equals(Id::This))
ident = cd->ident;
else if (cd->baseClass && ident->equals(Id::super))
else if (cd->baseClass && ident->equals(Id::_super))
ident = cd->baseClass->ident;
}
else
Expand Down Expand Up @@ -7342,7 +7342,7 @@ Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident, int fl
printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e->toChars(), ident->toChars(), toChars());
#endif
// Bugzilla 14010
if (ident == Id::mangleof)
if (ident == Id::_mangleof)
return getProperty(e->loc, ident, flag);

if (sym->scope)
Expand All @@ -7364,7 +7364,7 @@ Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident, int fl
{
if (ident == Id::max ||
ident == Id::min ||
ident == Id::init)
ident == Id::_init)
{
return getProperty(e->loc, ident, flag);
}
Expand All @@ -7381,7 +7381,7 @@ Expression *TypeEnum::getProperty(Loc loc, Identifier *ident, int flag)
{
return sym->getMaxMinValue(loc, ident);
}
else if (ident == Id::init)
else if (ident == Id::_init)
{
e = defaultInitLiteral(loc);
}
Expand All @@ -7392,7 +7392,7 @@ Expression *TypeEnum::getProperty(Loc loc, Identifier *ident, int flag)
Scope sc;
e = e->semantic(&sc);
}
else if (ident == Id::mangleof)
else if (ident == Id::_mangleof)
{
e = Type::getProperty(loc, ident, flag);
}
Expand Down Expand Up @@ -7574,7 +7574,7 @@ Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident, int
printf("TypeStruct::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars());
#endif
// Bugzilla 14010
if (ident == Id::mangleof)
if (ident == Id::_mangleof)
return getProperty(e->loc, ident, flag);

if (!sym->members)
Expand All @@ -7585,7 +7585,7 @@ Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident, int

/* If e.tupleof
*/
if (ident == Id::tupleof)
if (ident == Id::_tupleof)
{
/* Create a TupleExp out of the fields of the struct e:
* (e.field0, e.field1, e.field2, ...)
Expand Down Expand Up @@ -8134,12 +8134,12 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident, int f
}

// Bugzilla 12543
if (ident == Id::__sizeof || ident == Id::__xalignof || ident == Id::mangleof)
if (ident == Id::__sizeof || ident == Id::__xalignof || ident == Id::_mangleof)
{
return Type::getProperty(e->loc, ident, 0);
}

if (ident == Id::tupleof)
if (ident == Id::_tupleof)
{
/* Create a TupleExp
*/
Expand Down Expand Up @@ -8790,7 +8790,7 @@ Expression *TypeTuple::getProperty(Loc loc, Identifier *ident, int flag)
{
e = new IntegerExp(loc, arguments->dim, Type::tsize_t);
}
else if (ident == Id::init)
else if (ident == Id::_init)
{
e = defaultInitLiteral(loc);
}
Expand Down
4 changes: 2 additions & 2 deletions src/opover.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static Identifier *opId(Expression *e)
void visit(UAddExp *e) { id = Id::uadd; }
void visit(NegExp *e) { id = Id::neg; }
void visit(ComExp *e) { id = Id::com; }
void visit(CastExp *e) { id = Id::cast; }
void visit(CastExp *e) { id = Id::_cast; }
void visit(InExp *e) { id = Id::opIn; }
void visit(PostExp *e) { id = (e->op == TOKplusplus) ? Id::postinc : Id::postdec; }
void visit(AddExp *e) { id = Id::add; }
Expand Down Expand Up @@ -536,7 +536,7 @@ Expression *op_overload(Expression *e, Scope *sc)
/* Rewrite as:
* e1.opCast!(T)();
*/
fd = search_function(ad, Id::cast);
fd = search_function(ad, Id::_cast);
if (fd)
{
#if 1 // Backwards compatibility with D1 if opCast is a function, not a template
Expand Down
6 changes: 3 additions & 3 deletions src/posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ $(optabgen_output) : optabgen

######## idgen generates some source

idgen_output = id.h id.c
idgen_output = id.h id.c id.d
$(idgen_output) : idgen

idgen: idgen.d $(HOST_DC)
Expand Down Expand Up @@ -609,7 +609,7 @@ GENSRC=access.d aggregate.d aliasthis.d apply.d \
cppmangle.d ctfeexpr.d declaration.d \
delegatize.d doc.d dsymbol.d \
denum.d expression.d func.d \
hdrgen.d id.d identifier.d imphint.d \
hdrgen.d identifier.d imphint.d \
dimport.d dinifile.d inline.d init.d \
dinterpret.d json.d lexer.d link.d \
dmacro.d dmangle.d mars.d \
Expand All @@ -629,7 +629,7 @@ MANUALSRC= \
entity.d backend.d \
$(ROOT)/array.d $(ROOT)/longdouble.d \
$(ROOT)/rootobject.d $(ROOT)/port.d \
$(ROOT)/rmem.d
$(ROOT)/rmem.d id.d

ifeq ($(D_OBJC),1)
GENSRC += objc.d
Expand Down

0 comments on commit 2d050ca

Please sign in to comment.