本文整理汇总了C++中EnumMember类的典型用法代码示例。如果您正苦于以下问题:C++ EnumMember类的具体用法?C++ EnumMember怎么用?C++ EnumMember使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EnumMember类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DtoType
llvm::DIType ldc::DIBuilder::CreateEnumType(Type *type)
{
llvm::Type *T = DtoType(type);
assert(type->ty == Tenum && "only enums allowed for debug info in dwarfEnumType");
TypeEnum *te = static_cast<TypeEnum *>(type);
llvm::SmallVector<llvm::Value *, 8> subscripts;
for (ArrayIter<Dsymbol> it(te->sym->members); it.more(); it.next())
{
EnumMember *em = it->isEnumMember();
llvm::StringRef Name(em->toChars());
uint64_t Val = em->value->toInteger();
llvm::Value *Subscript = DBuilder.createEnumerator(Name, Val);
subscripts.push_back(Subscript);
}
llvm::StringRef Name = te->toChars();
unsigned LineNumber = te->sym->loc.linnum;
llvm::DIFile File = CreateFile(te->sym->loc);
return DBuilder.createEnumerationType(
llvm::DICompileUnit(GetCU()),
Name,
File,
LineNumber,
getTypeBitSize(T), // size (bits)
getABITypeAlign(T)*8, // align (bits)
DBuilder.getOrCreateArray(subscripts) // subscripts
#if LDC_LLVM_VER >= 302
, CreateTypeDescription(te->sym->memtype, NULL)
#endif
);
}
示例2: DtoType
ldc::DIType ldc::DIBuilder::CreateEnumType(Type *type) {
llvm::Type *T = DtoType(type);
assert(type->ty == Tenum &&
"only enums allowed for debug info in dwarfEnumType");
TypeEnum *te = static_cast<TypeEnum *>(type);
#if LDC_LLVM_VER >= 306
llvm::SmallVector<llvm::Metadata *, 8> subscripts;
#else
llvm::SmallVector<llvm::Value *, 8> subscripts;
#endif
for (auto m : *te->sym->members) {
EnumMember *em = m->isEnumMember();
llvm::StringRef Name(em->toChars());
uint64_t Val = em->value->toInteger();
auto Subscript = DBuilder.createEnumerator(Name, Val);
subscripts.push_back(Subscript);
}
llvm::StringRef Name = te->toChars();
unsigned LineNumber = te->sym->loc.linnum;
ldc::DIFile File(CreateFile(te->sym->loc));
return DBuilder.createEnumerationType(
GetCU(), Name, File, LineNumber,
getTypeBitSize(T), // size (bits)
getABITypeAlign(T) * 8, // align (bits)
DBuilder.getOrCreateArray(subscripts), // subscripts
CreateTypeDescription(te->sym->memtype, false));
}
示例3: toCBuffer
void EnumDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writestring("enum ");
if (ident)
{ buf->writestring(ident->toChars());
buf->writeByte(' ');
}
if (memtype)
{
buf->writestring(": ");
memtype->toCBuffer(buf, NULL, hgs);
}
if (!members)
{
buf->writeByte(';');
buf->writenl();
return;
}
buf->writenl();
buf->writeByte('{');
buf->writenl();
buf->level++;
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = (*members)[i]->isEnumMember();
if (!em)
continue;
em->toCBuffer(buf, hgs);
buf->writeByte(',');
buf->writenl();
}
buf->level--;
buf->writeByte('}');
buf->writenl();
}
示例4: toCBuffer
void EnumDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{ int i;
buf->writestring("enum ");
if (ident)
{ buf->writestring(ident->toChars());
buf->writeByte(' ');
}
if (memtype)
{
buf->writestring(": ");
memtype->toCBuffer(buf, NULL, hgs);
}
if (!members)
{
buf->writeByte(';');
buf->writenl();
return;
}
buf->writenl();
buf->writeByte('{');
buf->writenl();
for (i = 0; i < members->dim; i++)
{
EnumMember *em = ((Dsymbol *)members->data[i])->isEnumMember();
if (!em)
continue;
//buf->writestring(" ");
em->toCBuffer(buf, hgs);
buf->writeByte(',');
buf->writenl();
}
buf->writeByte('}');
buf->writenl();
}
示例5: printf
void EnumDeclaration::addMember(Scope *sc, ScopeDsymbol *sds)
{
#if 0
printf("EnumDeclaration::addMember() %s\n", toChars());
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = (*members)[i]->isEnumMember();
printf(" member %s\n", em->toChars());
}
#endif
/* Anonymous enum members get added to enclosing scope.
*/
ScopeDsymbol *scopesym = isAnonymous() ? sds : this;
if (!isAnonymous())
{
ScopeDsymbol::addMember(sc, sds);
if (!symtab)
symtab = new DsymbolTable();
}
if (members)
{
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = (*members)[i]->isEnumMember();
em->ed = this;
//printf("add %s to scope %s\n", em->toChars(), scopesym->toChars());
em->addMember(sc, scopesym);
}
}
added = true;
}
示例6: assert
ldc::DIType ldc::DIBuilder::CreateEnumType(Type *type) {
assert(type->ty == Tenum);
llvm::Type *T = DtoType(type);
TypeEnum *te = static_cast<TypeEnum *>(type);
llvm::SmallVector<LLMetadata *, 8> subscripts;
for (auto m : *te->sym->members) {
EnumMember *em = m->isEnumMember();
llvm::StringRef Name(em->toChars());
uint64_t Val = em->value()->toInteger();
auto Subscript = DBuilder.createEnumerator(Name, Val);
subscripts.push_back(Subscript);
}
llvm::StringRef Name = te->toChars();
unsigned LineNumber = te->sym->loc.linnum;
ldc::DIFile File(CreateFile(te->sym));
return DBuilder.createEnumerationType(
GetCU(), Name, File, LineNumber,
getTypeAllocSize(T) * 8, // size (bits)
getABITypeAlign(T) * 8, // align (bits)
DBuilder.getOrCreateArray(subscripts), // subscripts
CreateTypeDescription(te->sym->memtype, false));
}
示例7: addMember
int EnumDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum)
{
if (!isAnonymous())
return ScopeDsymbol::addMember(sc, sd, memnum);
/* Anonymous enum members get added to enclosing scope.
*/
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = (*members)[i]->isEnumMember();
em->ed = this;
//printf("add %s\n", em->toChars());
em->addMember(sc, sd, 1);
}
return 1;
}
示例8: semantic
//.........这里部分代码省略.........
{
errors = true;
if (members)
{
for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->errors = true; // poison all the members
}
}
semanticRun = PASSsemanticdone;
return;
}
}
semanticRun = PASSsemanticdone;
if (!members) // enum ident : memtype;
return;
if (members->dim == 0)
{
error("enum %s must have at least one member", toChars());
errors = true;
return;
}
Module::dprogress++;
Scope *sce;
if (isAnonymous())
sce = sc;
else
{
sce = sc->push(this);
sce->parent = this;
}
sce = sce->startCTFE();
sce->setNoFree(); // needed for getMaxMinValue()
/* Each enum member gets the sce scope
*/
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = (*members)[i]->isEnumMember();
if (em)
em->scope = sce;
}
if (!added)
{
/* addMember() is not called when the EnumDeclaration appears as a function statement,
* so we have to do what addMember() does and install the enum members in the right symbol
* table
*/
ScopeDsymbol *scopesym = NULL;
if (isAnonymous())
{
/* Anonymous enum members get added to enclosing scope.
*/
for (Scope *sct = sce; 1; sct = sct->enclosing)
{
assert(sct);
if (sct->scopesym)
{
scopesym = sct->scopesym;
if (!sct->scopesym->symtab)
sct->scopesym->symtab = new DsymbolTable();
break;
}
}
}
else
{
// Otherwise enum members are in the EnumDeclaration's symbol table
scopesym = this;
}
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = (*members)[i]->isEnumMember();
if (em)
{
em->ed = this;
em->addMember(sc, scopesym, 1);
}
}
}
for (size_t i = 0; i < members->dim; i++)
{
EnumMember *em = (*members)[i]->isEnumMember();
if (em)
em->semantic(em->scope);
}
//printf("defaultval = %lld\n", defaultval);
//if (defaultval) printf("defaultval: %s %s\n", defaultval->toChars(), defaultval->type->toChars());
//printf("members = %s\n", members->toChars());
}
示例9: error
void EnumMember::semantic(Scope *sc)
{
//printf("EnumMember::semantic() %s\n", toChars());
if (errors || semanticRun >= PASSsemanticdone)
return;
if (semanticRun == PASSsemantic)
{
error("circular reference to enum member");
Lerrors:
errors = true;
semanticRun = PASSsemanticdone;
return;
}
assert(ed);
ed->semantic(sc);
if (ed->errors)
goto Lerrors;
if (errors || semanticRun >= PASSsemanticdone)
return;
semanticRun = PASSsemantic;
if (scope)
sc = scope;
// The first enum member is special
bool first = (this == (*ed->members)[0]);
if (type)
{
type = type->semantic(loc, sc);
assert(value); // "type id;" is not a valid enum member declaration
}
if (value)
{
Expression *e = value;
assert(e->dyncast() == DYNCAST_EXPRESSION);
e = e->semantic(sc);
e = resolveProperties(sc, e);
e = e->ctfeInterpret();
if (e->op == TOKerror)
goto Lerrors;
if (first && !ed->memtype && !ed->isAnonymous())
{
ed->memtype = e->type;
if (ed->memtype->ty == Terror)
{
ed->errors = true;
goto Lerrors;
}
if (ed->memtype->ty != Terror)
{
/* Bugzilla 11746: All of named enum members should have same type
* with the first member. If the following members were referenced
* during the first member semantic, their types should be unified.
*/
for (size_t i = 0; i < ed->members->dim; i++)
{
EnumMember *em = (*ed->members)[i]->isEnumMember();
if (!em || em == this || em->semanticRun < PASSsemanticdone || em->type)
continue;
//printf("[%d] em = %s, em->semanticRun = %d\n", i, toChars(), em->semanticRun);
Expression *e = em->value;
e = e->implicitCastTo(sc, ed->memtype);
e = e->ctfeInterpret();
e = e->castTo(sc, ed->type);
if (e->op == TOKerror)
ed->errors = true;
em->value = e;
}
if (ed->errors)
{
ed->memtype = Type::terror;
goto Lerrors;
}
}
}
if (ed->memtype && !type)
{
e = e->implicitCastTo(sc, ed->memtype);
e = e->ctfeInterpret();
// save origValue for better json output
origValue = e;
if (!ed->isAnonymous())
e = e->castTo(sc, ed->type);
}
else if (type)
{
e = e->implicitCastTo(sc, type);
e = e->ctfeInterpret();
assert(ed->isAnonymous());
// save origValue for better json output
origValue = e;
}
//.........这里部分代码省略.........
示例10: cv4_Denum
unsigned cv4_Denum(EnumDeclaration *e)
{
debtyp_t *d,*dt;
unsigned nfields,fnamelen;
unsigned len;
unsigned property;
unsigned attribute;
int i;
const char *id;
idx_t typidx;
//dbg_printf("cv4_Denum(%s)\n", e->toChars());
property = 0;
if (!e->members || !e->memtype)
property |= 0x80; // enum is forward referenced
id = e->toPrettyChars();
len = 10;
d = debtyp_alloc(len + cv_stringbytes(id));
TOWORD(d->data,LF_ENUM);
TOWORD(d->data + 4,e->memtype ? cv4_typidx(e->memtype->toCtype()) : 0);
TOWORD(d->data + 8,property);
len += cv_namestring(d->data + len,id);
d->length = 0; // so cv_debtyp() will allocate new
typidx = cv_debtyp(d);
d->length = len; // restore length
// Compute the number of fields, and the length of the fieldlist record
nfields = 0;
fnamelen = 2;
if (e->members)
{
for (i = 0; i < e->members->dim; i++)
{ EnumMember *sf = ((Dsymbol *)e->members->data[i])->isEnumMember();
dinteger_t value;
if (sf)
{
value = sf->value->toInteger();
unsigned fnamelen1 = fnamelen;
fnamelen += 4 + cv4_numericbytes(value) + cv_stringbytes(sf->toPrettyChars());
/* Optlink dies on longer ones, so just truncate
*/
if (fnamelen > 0xB000) // 0xB000 found by trial and error
{ fnamelen = fnamelen1; // back up
break; // and skip the rest
}
nfields++;
}
}
}
TOWORD(d->data + 2,nfields);
// If forward reference, then field list is 0
if (!e->members)
{
TOWORD(d->data + 6,0);
return typidx;
}
// Generate fieldlist type record
dt = debtyp_alloc(fnamelen);
TOWORD(dt->data,LF_FIELDLIST);
// And fill it in
int j = 2;
int fieldi = 0;
for (i = 0; i < e->members->dim; i++)
{ EnumMember *sf = ((Dsymbol *)e->members->data[i])->isEnumMember();
dinteger_t value;
if (sf)
{
fieldi++;
if (fieldi > nfields)
break; // chop off the rest
value = sf->value->toInteger();
TOWORD(dt->data + j,LF_ENUMERATE);
attribute = 0;
TOWORD(dt->data + j + 2,attribute);
cv4_storenumeric(dt->data + j + 4,value);
j += 4 + cv4_numericbytes(value);
j += cv_namestring(dt->data + j, sf->toPrettyChars());
// If enum is not a member of a class, output enum members as constants
// if (!isclassmember(s))
// {
// cv4_outsym(sf);
// }
}
}
assert(j == fnamelen);
TOWORD(d->data + 6,cv_debtyp(dt));
// cv4_outsym(s);
//.........这里部分代码省略.........
示例11: cv4_Denum
unsigned cv4_Denum(EnumDeclaration *e)
{
//dbg_printf("cv4_Denum(%s)\n", e->toChars());
unsigned property = 0;
if (!e->members || !e->memtype || !e->memtype->isintegral())
property |= 0x80; // enum is forward referenced or non-integer
// Compute the number of fields, and the length of the fieldlist record
unsigned nfields = 0;
unsigned fnamelen = 2;
if (!property)
{
for (size_t i = 0; i < e->members->dim; i++)
{ EnumMember *sf = (*e->members)[i]->isEnumMember();
if (sf)
{
dinteger_t value = sf->value->toInteger();
unsigned fnamelen1 = fnamelen;
// store only member's simple name
fnamelen += 4 + cv4_numericbytes(value) + cv_stringbytes(sf->toChars());
if (config.fulltypes != CV8)
{
/* Optlink dies on longer ones, so just truncate
*/
if (fnamelen > 0xB000) // 0xB000 found by trial and error
{ fnamelen = fnamelen1; // back up
break; // and skip the rest
}
}
nfields++;
}
}
}
const char *id = e->toPrettyChars();
unsigned len;
debtyp_t *d;
unsigned memtype = e->memtype ? cv4_typidx(e->memtype->toCtype()) : 0;
switch (config.fulltypes)
{
case CV8:
len = 14;
d = debtyp_alloc(len + cv_stringbytes(id));
TOWORD(d->data,LF_ENUM_V3);
TOLONG(d->data + 6,memtype);
TOWORD(d->data + 4,property);
len += cv_namestring(d->data + len,id);
break;
case CV4:
len = 10;
d = debtyp_alloc(len + cv_stringbytes(id));
TOWORD(d->data,LF_ENUM);
TOWORD(d->data + 4,memtype);
TOWORD(d->data + 8,property);
len += cv_namestring(d->data + len,id);
break;
default:
assert(0);
}
unsigned length_save = d->length;
d->length = 0; // so cv_debtyp() will allocate new
idx_t typidx = cv_debtyp(d);
d->length = length_save; // restore length
TOWORD(d->data + 2,nfields);
unsigned fieldlist = 0;
if (!property) // if forward reference, then fieldlist is 0
{
// Generate fieldlist type record
debtyp_t *dt = debtyp_alloc(fnamelen);
TOWORD(dt->data,(config.fulltypes == CV8) ? LF_FIELDLIST_V2 : LF_FIELDLIST);
// And fill it in
unsigned j = 2;
unsigned fieldi = 0;
for (size_t i = 0; i < e->members->dim; i++)
{ EnumMember *sf = (*e->members)[i]->isEnumMember();
if (sf)
{
fieldi++;
if (fieldi > nfields)
break; // chop off the rest
dinteger_t value = sf->value->toInteger();
TOWORD(dt->data + j,(config.fulltypes == CV8) ? LF_ENUMERATE_V3 : LF_ENUMERATE);
unsigned attribute = 0;
TOWORD(dt->data + j + 2,attribute);
cv4_storenumeric(dt->data + j + 4,value);
j += 4 + cv4_numericbytes(value);
// store only member's simple name
j += cv_namestring(dt->data + j, sf->toChars());
// If enum is not a member of a class, output enum members as constants
//.........这里部分代码省略.........
示例12: if
void EnumDeclaration::semantic(Scope *sc)
{
Type *t;
Scope *sce;
//printf("EnumDeclaration::semantic(sd = %p, '%s') %s\n", sc->scopesym, sc->scopesym->toChars(), toChars());
//printf("EnumDeclaration::semantic() %s\n", toChars());
if (!members) // enum ident;
return;
if (!memtype && !isAnonymous())
{ // Set memtype if we can to reduce fwd reference errors
memtype = Type::tint32; // case 1) enum ident { ... }
}
if (symtab) // if already done
{ if (!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;
}
if (sc->stc & STCdeprecated)
isdeprecated = 1;
parent = sc->parent;
/* The separate, and distinct, cases are:
* 1. enum { ... }
* 2. enum : memtype { ... }
* 3. enum ident { ... }
* 4. enum ident : memtype { ... }
*/
if (memtype)
{
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 || !sym->members || !sym->symtab || sym->scope)
{ // memtype is forward referenced, so try again later
scope = scx ? scx : new Scope(*sc);
scope->setNoFree();
scope->module->addDeferredSemantic(this);
printf("\tdeferring %s\n", toChars());
return;
}
}
#if 0 // Decided to abandon this restriction for D 2.0
if (!memtype->isintegral())
{ error("base type must be of integral type, not %s", memtype->toChars());
memtype = Type::tint32;
}
#endif
}
type = type->semantic(loc, sc);
if (isAnonymous())
sce = sc;
else
{ sce = sc->push(this);
sce->parent = this;
}
if (members->dim == 0)
error("enum %s must have at least one member", toChars());
int first = 1;
Expression *elast = NULL;
for (int 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());
if (em->type)
em->type = em->type->semantic(em->loc, sce);
e = em->value;
if (e)
{
assert(e->dyncast() == DYNCAST_EXPRESSION);
e = e->semantic(sce);
e = e->optimize(WANTvalue | WANTinterpret);
if (memtype)
{
e = e->implicitCastTo(sce, memtype);
//.........这里部分代码省略.........
示例13: if
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;
//.........这里部分代码省略.........
示例14: return
bool operator==(const EnumMember& lhs, const EnumMember& rhs)
{
return (lhs.name() == rhs.name() && lhs.declaringType() == rhs.declaringType() && lhs.type() == rhs.type());
}