Skip to content

Commit

Permalink
Merge pull request #1568 from WalterBright/b40
Browse files Browse the repository at this point in the history
refactor type_enum
  • Loading branch information
WalterBright committed Jan 28, 2013
2 parents 1658755 + 54946b4 commit d219ea1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
24 changes: 24 additions & 0 deletions src/backend/type.c
Expand Up @@ -445,6 +445,30 @@ type *type_function(tym_t tyf, type **ptypes, size_t nparams, bool variadic, typ
return t;
}

/***************************************
* Create an enum type.
* Input:
* name name of enum
* tbase "base" type of enum
* Returns:
* Tcount already incremented
*/
type *type_enum(const char *name, type *tbase)
{
Symbol *s = symbol_calloc(name);
s->Sclass = SCenum;
s->Senum = (enum_t *) MEM_PH_CALLOC(sizeof(enum_t));
s->Senum->SEflags |= SENforward; // forward reference
slist_add(s);

type *t = type_allocn(TYenum, tbase);
t->Ttag = (Classsym *)s; // enum tag name
t->Tcount++;
s->Stype = t;
t->Tcount++;
return t;
}

/*****************************
* Free up data type.
*/
Expand Down
1 change: 1 addition & 0 deletions src/backend/type.h
Expand Up @@ -210,6 +210,7 @@ type *type_static_array(unsigned long long dim, type *tnext);
type *type_assoc_array(type *tkey, type *tvalue);
type *type_delegate(type *tnext);
type *type_function(tym_t tyf, type **ptypes, size_t nparams, bool variadic, type *tret);
type *type_enum(const char *name, type *tbase);


#endif
14 changes: 1 addition & 13 deletions src/toctype.c
Expand Up @@ -265,19 +265,7 @@ type *TypeEnum::toCtype()
}
else if (sym->memtype->toBasetype()->ty == Tint32)
{
Symbol *s = symbol_calloc(sym->toPrettyChars());
s->Sclass = SCenum;
s->Senum = (enum_t *) MEM_PH_CALLOC(sizeof(enum_t));
s->Senum->SEflags |= SENforward; // forward reference
slist_add(s);

t = type_alloc(TYenum);
t->Ttag = (Classsym *)s; // enum tag name
t->Tcount++;
t->Tnext = sym->memtype->toCtype();
t->Tnext->Tcount++;
s->Stype = t;
slist_add(s);
t = type_enum(sym->toPrettyChars(), sym->memtype->toCtype());
tm->ctype = t;
ctype = t;
}
Expand Down

0 comments on commit d219ea1

Please sign in to comment.