本文整理汇总了C++中EnumDeclaration::toChars方法的典型用法代码示例。如果您正苦于以下问题:C++ EnumDeclaration::toChars方法的具体用法?C++ EnumDeclaration::toChars怎么用?C++ EnumDeclaration::toChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EnumDeclaration
的用法示例。
在下文中一共展示了EnumDeclaration::toChars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: semantic
void EnumDeclaration::semantic(Scope *sc)
{
uinteger_t number;
Type *t;
Scope *sce;
//printf("EnumDeclaration::semantic(sd = %p, '%s')\n", sc->scopesym, sc->scopesym->toChars());
if (!memtype)
memtype = Type::tint32;
if (symtab) // if already done
{ if (isdone || !scope)
return; // semantic() already completed
}
else
symtab = new DsymbolTable();
Scope *scx = NULL;
if (scope)
{ sc = scope;
scx = scope; // save so we don't make redundant copies
scope = NULL;
}
unsigned dprogress_save = Module::dprogress;
if (sc->stc & STCdeprecated)
isdeprecated = 1;
parent = sc->scopesym;
memtype = memtype->semantic(loc, sc);
/* Check to see if memtype is forward referenced
*/
if (memtype->ty == Tenum)
{ EnumDeclaration *sym = (EnumDeclaration *)memtype->toDsymbol(sc);
if (!sym->memtype)
{
error("base enum %s is forward referenced", sym->toChars());
memtype = Type::tint32;
}
}
if (!memtype->isintegral())
{ error("base type must be of integral type, not %s", memtype->toChars());
memtype = Type::tint32;
}
isdone = 1;
Module::dprogress++;
t = isAnonymous() ? memtype : type;
symtab = new DsymbolTable();
sce = sc->push(this);
sce->parent = this;
number = 0;
if (!members) // enum ident;
return;
if (members->dim == 0)
error("enum %s must have at least one member", toChars());
int first = 1;
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
Expression *e;
if (!em)
/* The e->semantic(sce) can insert other symbols, such as
* template instances and function literals.
*/
continue;
//printf("Enum member '%s'\n",em->toChars());
e = em->value;
if (e)
{
assert(e->dyncast() == DYNCAST_EXPRESSION);
e = e->semantic(sce);
e = e->optimize(WANTvalue);
// Need to copy it because we're going to change the type
e = e->copy();
e = e->implicitCastTo(sc, memtype);
e = e->optimize(WANTvalue);
number = e->toInteger();
e->type = t;
}
else
{ // Default is the previous number plus 1
// Check for overflow
if (!first)
{
switch (t->toBasetype()->ty)
{
case Tbool:
if (number == 2) goto Loverflow;
break;
case Tint8:
if (number == 128) goto Loverflow;
//.........这里部分代码省略.........