Skip to content

Commit

Permalink
Merge pull request #4038 from 9rnsr/remove_typedef
Browse files Browse the repository at this point in the history
Remove internals for typedef declaration
  • Loading branch information
WalterBright committed Oct 5, 2014
2 parents f8265ae + 08a4a3d commit 4b29161
Show file tree
Hide file tree
Showing 31 changed files with 19 additions and 812 deletions.
5 changes: 0 additions & 5 deletions src/argtypes.c
Expand Up @@ -476,11 +476,6 @@ TypeTuple *toArgTypes(Type *t)
t->toBasetype()->accept(this);
}

void visit(TypeTypedef *t)
{
t->sym->basetype->accept(this);
}

void visit(TypeClass *)
{
result = new TypeTuple(Type::tvoidptr);
Expand Down
7 changes: 0 additions & 7 deletions src/class.c
Expand Up @@ -106,13 +106,6 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
Type::typeinfostruct = this;
}

if (id == Id::TypeInfo_Typedef)
{
if (!inObject)
error("%s", msg);
Type::typeinfotypedef = this;
}

if (id == Id::TypeInfo_Pointer)
{
if (!inObject)
Expand Down
5 changes: 0 additions & 5 deletions src/cppmangle.c
Expand Up @@ -781,11 +781,6 @@ class CppMangleVisitor : public Visitor
store(t);
}

void visit(TypeTypedef *t)
{
visit((Type *)t);
}

void visit(TypeClass *t)
{
if (substitute(t)) return;
Expand Down
129 changes: 0 additions & 129 deletions src/declaration.c
Expand Up @@ -276,104 +276,6 @@ bool TupleDeclaration::needThis()
}


/********************************* TypedefDeclaration ****************************/

TypedefDeclaration::TypedefDeclaration(Loc loc, Identifier *id, Type *basetype, Initializer *init)
: Declaration(id)
{
this->type = new TypeTypedef(this);
this->basetype = basetype->toBasetype();
this->init = init;
this->loc = loc;
this->sinit = NULL;
}

Dsymbol *TypedefDeclaration::syntaxCopy(Dsymbol *s)
{
assert(!s);
return new TypedefDeclaration(loc, ident,
basetype->syntaxCopy(),
init ? init->syntaxCopy() : NULL);
}

void TypedefDeclaration::semantic(Scope *sc)
{
//printf("TypedefDeclaration::semantic(%s) sem = %d\n", toChars(), sem);
if (sem == SemanticStart)
{
sem = SemanticIn;
parent = sc->parent;
unsigned int errors = global.errors;
Type *savedbasetype = basetype;
basetype = basetype->semantic(loc, sc);
if (errors != global.errors)
{
basetype = savedbasetype;
sem = SemanticStart;
return;
}
sem = SemanticDone;
type = type->addStorageClass(storage_class);
Type *savedtype = type;
type = type->semantic(loc, sc);
if (sc->parent->isFuncDeclaration() && init)
semantic2(sc);
if (errors != global.errors)
{
basetype = savedbasetype;
type = savedtype;
sem = SemanticStart;
return;
}
storage_class |= sc->stc & STCdeprecated;
userAttribDecl = sc->userAttribDecl;
}
else if (sem == SemanticIn)
{
error("circular definition");
basetype = Type::terror;
errors = true;
}
}

void TypedefDeclaration::semantic2(Scope *sc)
{
//printf("TypedefDeclaration::semantic2(%s) sem = %d\n", toChars(), sem);
if (sem == SemanticDone)
{
sem = Semantic2Done;
basetype->alignment(); // used to detect circular typedef declarations
if (init)
{
Initializer *savedinit = init;
unsigned int errors = global.errors;
init = init->semantic(sc, basetype, INITinterpret);
if (errors != global.errors || init->isErrorInitializer())
{
init = savedinit;
return;
}

ExpInitializer *ie = init->isExpInitializer();
if (ie)
{
if (ie->exp->type == basetype)
ie->exp->type = type;
}
}
}
}

const char *TypedefDeclaration::kind()
{
return "typedef";
}

Type *TypedefDeclaration::getType()
{
return type;
}

/********************************* AliasDeclaration ****************************/

AliasDeclaration::AliasDeclaration(Loc loc, Identifier *id, Type *type)
Expand Down Expand Up @@ -1381,20 +1283,6 @@ void VarDeclaration::semantic(Scope *sc)
init = new ExpInitializer(loc, e);
goto Ldtor;
}
else if (type->ty == Ttypedef)
{
TypeTypedef *td = (TypeTypedef *)type;
if (td->sym->init)
{
init = td->sym->init;
ExpInitializer *ie = init->isExpInitializer();
if (ie)
// Make copy so we can modify it
init = new ExpInitializer(ie->loc, ie->exp);
}
else
init = getExpInitializer();
}
else if (type->baseElemOf()->ty == Tvoid)
{
error("%s does not have a default initializer", type->toChars());
Expand Down Expand Up @@ -2331,23 +2219,6 @@ TypeInfoInterfaceDeclaration *TypeInfoInterfaceDeclaration::create(Type *tinfo)
return new TypeInfoInterfaceDeclaration(tinfo);
}

/***************************** TypeInfoTypedefDeclaration *********************/

TypeInfoTypedefDeclaration::TypeInfoTypedefDeclaration(Type *tinfo)
: TypeInfoDeclaration(tinfo, 0)
{
if (!Type::typeinfotypedef)
{
ObjectNotFound(Id::TypeInfo_Typedef);
}
type = Type::typeinfotypedef->type;
}

TypeInfoTypedefDeclaration *TypeInfoTypedefDeclaration::create(Type *tinfo)
{
return new TypeInfoTypedefDeclaration(tinfo);
}

/***************************** TypeInfoPointerDeclaration *********************/

TypeInfoPointerDeclaration::TypeInfoPointerDeclaration(Type *tinfo)
Expand Down
33 changes: 0 additions & 33 deletions src/declaration.h
Expand Up @@ -187,30 +187,6 @@ class TupleDeclaration : public Declaration

/**************************************************************/

class TypedefDeclaration : public Declaration
{
public:
Type *basetype;
Initializer *init;

TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init);
Dsymbol *syntaxCopy(Dsymbol *);
void semantic(Scope *sc);
void semantic2(Scope *sc);
const char *kind();
Type *getType();

void toObjFile(bool multiobj); // compile to .obj file

TypedefDeclaration *isTypedefDeclaration() { return this; }

Symbol *sinit;
Symbol *toInitializer();
void accept(Visitor *v) { v->visit(this); }
};

/**************************************************************/

class AliasDeclaration : public Declaration
{
public:
Expand Down Expand Up @@ -383,15 +359,6 @@ class TypeInfoInterfaceDeclaration : public TypeInfoDeclaration
void accept(Visitor *v) { v->visit(this); }
};

class TypeInfoTypedefDeclaration : public TypeInfoDeclaration
{
public:
TypeInfoTypedefDeclaration(Type *tinfo);
static TypeInfoTypedefDeclaration *create(Type *tinfo);

void accept(Visitor *v) { v->visit(this); }
};

class TypeInfoPointerDeclaration : public TypeInfoDeclaration
{
public:
Expand Down
14 changes: 0 additions & 14 deletions src/doc.c
Expand Up @@ -1179,20 +1179,6 @@ void toDocBuffer(Dsymbol *s, OutBuffer *buf, Scope *sc)
}
}

void visit(TypedefDeclaration *d)
{
if (d->ident)
{
if (d->isDeprecated())
buf->writestring("deprecated ");

emitProtection(buf, d->protection);
buf->writestring("typedef ");
buf->writestring(d->toChars());
buf->writestring(";\n");
}
}

void visit(FuncDeclaration *fd)
{
//printf("FuncDeclaration::toDocbuffer() %s\n", fd->toChars());
Expand Down
2 changes: 0 additions & 2 deletions src/dsymbol.h
Expand Up @@ -30,7 +30,6 @@ class Declaration;
class ThisDeclaration;
class TypeInfoDeclaration;
class TupleDeclaration;
class TypedefDeclaration;
class AliasDeclaration;
class AggregateDeclaration;
class EnumDeclaration;
Expand Down Expand Up @@ -256,7 +255,6 @@ class Dsymbol : public RootObject
virtual ThisDeclaration *isThisDeclaration() { return NULL; }
virtual TypeInfoDeclaration *isTypeInfoDeclaration() { return NULL; }
virtual TupleDeclaration *isTupleDeclaration() { return NULL; }
virtual TypedefDeclaration *isTypedefDeclaration() { return NULL; }
virtual AliasDeclaration *isAliasDeclaration() { return NULL; }
virtual AggregateDeclaration *isAggregateDeclaration() { return NULL; }
virtual FuncDeclaration *isFuncDeclaration() { return NULL; }
Expand Down
4 changes: 0 additions & 4 deletions src/e2ir.c
Expand Up @@ -4818,10 +4818,6 @@ elem *toElem(Expression *e, IRState *irs)
}
}
}
else if (TypedefDeclaration *tyd = s->isTypedefDeclaration())
{
irs->deferToObj->push(tyd);
}
else if (EnumDeclaration *ed = s->isEnumDeclaration())
{
irs->deferToObj->push(ed);
Expand Down
6 changes: 1 addition & 5 deletions src/expression.c
Expand Up @@ -5700,7 +5700,6 @@ Expression *DeclarationExp::semantic(Scope *sc)
{
// Bugzilla 11720 - include Dataseg variables
if ((s->isFuncDeclaration() ||
s->isTypedefDeclaration() ||
s->isAggregateDeclaration() ||
s->isEnumDeclaration() ||
v && v->isDataseg()) &&
Expand Down Expand Up @@ -5933,10 +5932,7 @@ Expression *IsExp::semantic(Scope *sc)
switch (tok2)
{
case TOKtypedef:
if (targ->ty != Ttypedef)
goto Lno;
tded = ((TypeTypedef *)targ)->sym->basetype;
break;
goto Lno;

case TOKstruct:
if (targ->ty != Tstruct)
Expand Down
1 change: 0 additions & 1 deletion src/glue.c
Expand Up @@ -1400,7 +1400,6 @@ unsigned totym(Type *tx)
break;

case Tenum:
case Ttypedef:
t = totym(tx->toBasetype());
break;

Expand Down
16 changes: 0 additions & 16 deletions src/gluestub.c
Expand Up @@ -57,11 +57,6 @@ Symbol *AggregateDeclaration::toInitializer()
return NULL;
}

Symbol *TypedefDeclaration::toInitializer()
{
return NULL;
}

Symbol *EnumDeclaration::toInitializer()
{
return NULL;
Expand Down Expand Up @@ -138,11 +133,6 @@ void VarDeclaration::toObjFile(bool multiobj)
assert(0);
}

void TypedefDeclaration::toObjFile(bool multiobj)
{
assert(0);
}

void EnumDeclaration::toObjFile(bool multiobj)
{
assert(0);
Expand Down Expand Up @@ -239,12 +229,6 @@ TypeInfoDeclaration *Type::getTypeInfoDeclaration()
return NULL;
}

TypeInfoDeclaration *TypeTypedef::getTypeInfoDeclaration()
{
assert(0);
return NULL;
}

TypeInfoDeclaration *TypePointer::getTypeInfoDeclaration()
{
assert(0);
Expand Down
27 changes: 0 additions & 27 deletions src/hdrgen.c
Expand Up @@ -983,12 +983,6 @@ class PrettyPrintVisitor : public Visitor
buf->writestring(t->sym->toChars());
}

void visit(TypeTypedef *t)
{
//printf("TypeTypedef::toCBuffer2() '%s'\n", t->sym->toChars());
buf->writestring(t->sym->toChars());
}

void visit(TypeStruct *t)
{
TemplateInstance *ti = t->sym->parent->isTemplateInstance();
Expand Down Expand Up @@ -1649,19 +1643,6 @@ class PrettyPrintVisitor : public Visitor
}
}

void visit(TypedefDeclaration *d)
{
buf->writestring("typedef ");
typeToBuffer(d->basetype, d->ident);
if (d->init)
{
buf->writestring(" = ");
d->init->accept(this);
}
buf->writeByte(';');
buf->writenl();
}

void visit(AliasDeclaration *d)
{
buf->writestring("alias ");
Expand Down Expand Up @@ -2050,14 +2031,6 @@ class PrettyPrintVisitor : public Visitor
goto L1;
}

case Ttypedef:
{
TypeTypedef *tt = (TypeTypedef *)t;
buf->printf("cast(%s)", tt->sym->toChars());
t = tt->sym->basetype;
goto L1;
}

case Twchar: // BUG: need to cast(wchar)
case Tdchar: // BUG: need to cast(dchar)
if ((uinteger_t)v > 0xFF)
Expand Down

0 comments on commit 4b29161

Please sign in to comment.