Skip to content

Commit

Permalink
refactor type_enum
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 28, 2013
1 parent 3397ec7 commit 5ffa2eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/backend/type.c
Expand Up @@ -445,6 +445,31 @@ 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;
slist_add(s);
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

0 comments on commit 5ffa2eb

Please sign in to comment.