本文整理汇总了C++中VarDeclaration类的典型用法代码示例。如果您正苦于以下问题:C++ VarDeclaration类的具体用法?C++ VarDeclaration怎么用?C++ VarDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VarDeclaration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: if
Expression *scanVar(Dsymbol *s, InlineScanState *iss)
{
//printf("scanVar(%s %s)\n", s->kind(), s->toPrettyChars());
VarDeclaration *vd = s->isVarDeclaration();
if (vd)
{
TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
if (td)
{
for (size_t i = 0; i < td->objects->dim; i++)
{
DsymbolExp *se = (DsymbolExp *)(*td->objects)[i];
assert(se->op == TOKdsymbol);
scanVar(se->s, iss); // TODO
}
}
else if (vd->init)
{
if (ExpInitializer *ie = vd->init->isExpInitializer())
{
Expression *e = ie->exp->inlineScan(iss);
if (vd->init != ie) // DeclareExp with vd appears in e
return e;
ie->exp = e;
}
}
}
else
{
s->inlineScan();
}
return NULL;
}
开发者ID:D-Programming-microD,项目名称:GDC,代码行数:33,代码来源:inline.c
示例2: isPOD
/***************************************
* Return true if struct is POD (Plain Old Data).
* This is defined as:
* not nested
* no postblits, constructors, destructors, or assignment operators
* no fields with with any of those
* The idea being these are compatible with C structs.
*
* Note that D struct constructors can mean POD, since there is always default
* construction with no ctor, but that interferes with OPstrpar which wants it
* on the stack in memory, not in registers.
*/
bool StructDeclaration::isPOD()
{
if (enclosing || cpctor || postblit || ctor || dtor)
return false;
/* Recursively check any fields have a constructor.
* We should cache the results of this.
*/
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->isField());
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
while (tv->ty == Tsarray)
{ TypeSArray *ta = (TypeSArray *)tv;
tv = tv->nextOf()->toBasetype();
}
if (tv->ty == Tstruct)
{ TypeStruct *ts = (TypeStruct *)tv;
StructDeclaration *sd = ts->sym;
if (!sd->isPOD())
return false;
}
}
return true;
}
开发者ID:duralog,项目名称:ldc,代码行数:41,代码来源:struct.c
示例3: visit
void visit(DeclarationExp *e)
{
VarDeclaration *v = e->declaration->isVarDeclaration();
if (v)
{
result = v->checkNestedReference(sc, Loc());
if (result)
return;
/* Some expressions cause the frontend to create a temporary.
* For example, structs with cpctors replace the original
* expression e with:
* __cpcttmp = __cpcttmp.cpctor(e);
*
* In this instance, we need to ensure that the original
* expression e does not have any nested references by
* checking the declaration initializer too.
*/
if (v->_init && v->_init->isExpInitializer())
{
Expression *ie = initializerToExpression(v->_init);
result = lambdaCheckForNestedRef(ie, sc);
}
}
}
开发者ID:Lucretia,项目名称:gcc,代码行数:25,代码来源:delegatize.c
示例4: visit
void visit(IndexExp *e)
{
if (e->e1->op == TOKvar)
{
VarDeclaration *v = ((VarExp *)e->e1)->var->isVarDeclaration();
if (v && v->toParent2() == sc->func)
{
Type *tb = v->type->toBasetype();
if (tb->ty == Tarray || tb->ty == Tsarray)
{
if (v->storage_class & STCvariadic)
{
error(e->loc, "escaping reference to the payload of variadic parameter %s", v);
return;
}
}
}
}
Type *tb = e->e1->type->toBasetype();
if (tb->ty == Tsarray)
{
e->e1->accept(this);
}
}
开发者ID:nrTQgc,项目名称:ldc,代码行数:25,代码来源:escape.c
示例5: scanForNestedRef
void VarExp::scanForNestedRef(Scope *sc)
{
//printf("VarExp::scanForNestedRef(%s)\n", toChars());
VarDeclaration *v = var->isVarDeclaration();
if (v)
v->checkNestedReference(sc, 0);
}
开发者ID:Geod24,项目名称:dnet,代码行数:7,代码来源:delegatize.c
示例6: assert
Expression *DeclarationExp::doInline(InlineDoState *ids)
{ DeclarationExp *de = (DeclarationExp *)copy();
VarDeclaration *vd;
//printf("DeclarationExp::doInline(%s)\n", toChars());
vd = declaration->isVarDeclaration();
if (vd)
{
#if 0
// Need to figure this out before inlining can work for tuples
TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
if (td)
{
for (size_t i = 0; i < td->objects->dim; i++)
{ DsymbolExp *se = (DsymbolExp *)td->objects->data[i];
assert(se->op == TOKdsymbol);
se->s;
}
return st->objects->dim;
}
#endif
if (vd->isStatic() || vd->isConst())
;
else
{
VarDeclaration *vto;
vto = new VarDeclaration(vd->loc, vd->type, vd->ident, vd->init);
*vto = *vd;
vto->parent = ids->parent;
#if IN_DMD
vto->csym = NULL;
vto->isym = NULL;
#endif
ids->from.push(vd);
ids->to.push(vto);
if (vd->init)
{
if (vd->init->isVoidInitializer())
{
vto->init = new VoidInitializer(vd->init->loc);
}
else
{
ExpInitializer *ie = vd->init->isExpInitializer();
assert(ie);
vto->init = new ExpInitializer(ie->loc, ie->exp->doInline(ids));
}
}
de->declaration = (Dsymbol *) (void *)vto;
}
}
/* This needs work, like DeclarationExp::toElem(), if we are
* to handle TemplateMixin's. For now, we just don't inline them.
*/
return de;
}
开发者ID:alekseysidorov,项目名称:ldc,代码行数:59,代码来源:inline.c
示例7: expressionInlineCost
int DeclarationExp::inlineCost3(InlineCostState *ics)
{ int cost = 0;
VarDeclaration *vd;
//printf("DeclarationExp::inlineCost3()\n");
vd = declaration->isVarDeclaration();
if (vd)
{
TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
if (td)
{
#if 1
return COST_MAX; // finish DeclarationExp::doInline
#else
for (size_t i = 0; i < td->objects->dim; i++)
{ Object *o = (*td->objects)[i];
if (o->dyncast() != DYNCAST_EXPRESSION)
return COST_MAX;
Expression *eo = (Expression *)o;
if (eo->op != TOKdsymbol)
return COST_MAX;
}
return td->objects->dim;
#endif
}
if (!ics->hdrscan && vd->isDataseg())
return COST_MAX;
cost += 1;
#if DMDV2
if (vd->edtor) // if destructor required
return COST_MAX; // needs work to make this work
#endif
// Scan initializer (vd->init)
if (vd->init)
{
ExpInitializer *ie = vd->init->isExpInitializer();
if (ie)
{
cost += expressionInlineCost(ie->exp, ics);
}
}
}
// These can contain functions, which when copied, get output twice.
if (declaration->isStructDeclaration() ||
declaration->isClassDeclaration() ||
declaration->isFuncDeclaration() ||
declaration->isTypedefDeclaration() ||
#if DMDV2
declaration->isAttribDeclaration() ||
#endif
declaration->isTemplateMixin())
return COST_MAX;
//printf("DeclarationExp::inlineCost3('%s')\n", toChars());
return cost;
}
开发者ID:NilsBossung,项目名称:dmd,代码行数:59,代码来源:inline.c
示例8: toDt
void StructDeclaration::toDt(dt_t **pdt)
{
unsigned offset;
unsigned i;
dt_t *dt;
//printf("StructDeclaration::toDt(), this='%s'\n", toChars());
offset = 0;
// Note equivalence of this loop to class's
for (i = 0; i < fields.dim; i++)
{
VarDeclaration *v = (VarDeclaration *)fields.data[i];
//printf("\tfield '%s' voffset %d, offset = %d\n", v->toChars(), v->offset, offset);
dt = NULL;
int sz;
if (v->storage_class & STCref)
{
sz = PTRSIZE;
if (v->offset >= offset)
dtnzeros(&dt, sz);
}
else
{
sz = v->type->size();
Initializer *init = v->init;
if (init)
{ //printf("\t\thas initializer %s\n", init->toChars());
ExpInitializer *ei = init->isExpInitializer();
Type *tb = v->type->toBasetype();
if (ei && tb->ty == Tsarray)
((TypeSArray *)tb)->toDtElem(&dt, ei->exp);
else
dt = init->toDt();
}
else if (v->offset >= offset)
v->type->toDt(&dt);
}
if (dt)
{
if (v->offset < offset)
error("overlapping initialization for struct %s.%s", toChars(), v->toChars());
else
{
if (offset < v->offset)
dtnzeros(pdt, v->offset - offset);
dtcat(pdt, dt);
offset = v->offset + sz;
}
}
}
if (offset < structsize)
dtnzeros(pdt, structsize - offset);
dt_optimize(*pdt);
}
开发者ID:torarin,项目名称:dmd,代码行数:58,代码来源:todt.c
示例9: inlineCost
int DeclarationExp::inlineCost(InlineCostState *ics)
{ int cost = 0;
VarDeclaration *vd;
//printf("DeclarationExp::inlineCost()\n");
vd = declaration->isVarDeclaration();
if (vd)
{
TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
if (td)
{
#if 1
return COST_MAX; // finish DeclarationExp::doInline
#else
for (size_t i = 0; i < td->objects->dim; i++)
{ Object *o = (*td->objects)[i];
if (o->dyncast() != DYNCAST_EXPRESSION)
return COST_MAX;
Expression *eo = (Expression *)o;
if (eo->op != TOKdsymbol)
return COST_MAX;
}
return td->objects->dim;
#endif
}
// This breaks on LDC too, since nested static variables have internal
// linkage and thus can't be referenced from other objects.
if (!ics->hdrscan && vd->isDataseg())
return COST_MAX;
cost += 1;
// Scan initializer (vd->init)
if (vd->init)
{
ExpInitializer *ie = vd->init->isExpInitializer();
if (ie)
{
cost += ie->exp->inlineCost(ics);
}
}
}
// These can contain functions, which when copied, get output twice.
// These break on LDC too, since nested static variables and functions have
// internal linkage and thus can't be referenced from other objects.
if (declaration->isStructDeclaration() ||
declaration->isClassDeclaration() ||
declaration->isFuncDeclaration() ||
declaration->isTypedefDeclaration() ||
declaration->isTemplateMixin())
return COST_MAX;
//printf("DeclarationExp::inlineCost('%s')\n", toChars());
return cost;
}
开发者ID:alekseysidorov,项目名称:ldc,代码行数:56,代码来源:inline.c
示例10: check
void check(Loc loc, Declaration *d)
{
assert(d);
VarDeclaration *v = d->isVarDeclaration();
if (v && v->toParent2() == sc->func)
{
if (v->isDataseg())
return;
if ((v->storage_class & (STCref | STCout)) == 0)
{
error(loc, "escaping reference to local variable %s", v);
return;
}
if (global.params.useDIP25 &&
(v->storage_class & (STCref | STCout)) && !(v->storage_class & (STCreturn | STCforeach)))
{
if (sc->func->flags & FUNCFLAGreturnInprocess)
{
//printf("inferring 'return' for variable '%s'\n", v->toChars());
v->storage_class |= STCreturn;
if (v == sc->func->vthis)
{
TypeFunction *tf = (TypeFunction *)sc->func->type;
if (tf->ty == Tfunction)
{
//printf("'this' too\n");
tf->isreturn = true;
}
}
}
else if (sc->module && sc->module->isRoot())
{
//printf("escaping reference to local ref variable %s\n", v->toChars());
//printf("storage class = x%llx\n", v->storage_class);
error(loc, "escaping reference to local ref variable %s", v);
}
return;
}
if (v->storage_class & STCref &&
v->storage_class & (STCforeach | STCtemp) &&
v->init)
{
// (ref v = ex; ex)
if (ExpInitializer *ez = v->init->isExpInitializer())
{
assert(ez->exp && ez->exp->op == TOKconstruct);
Expression *ex = ((ConstructExp *)ez->exp)->e2;
ex->accept(this);
return;
}
}
}
}
开发者ID:nrTQgc,项目名称:ldc,代码行数:55,代码来源:escape.c
示例11: isNested
/***************************************
* Fit elements[] to the corresponding type of field[].
* Input:
* loc
* sc
* elements The explicit arguments that given to construct object.
* stype The constructed object type.
* Returns false if any errors occur.
* Otherwise, returns true and elements[] are rewritten for the output.
*/
bool StructDeclaration::fit(Loc loc, Scope *sc, Expressions *elements, Type *stype)
{
if (!elements)
return true;
size_t nfields = fields.dim - isNested();
size_t offset = 0;
for (size_t i = 0; i < elements->dim; i++)
{
Expression *e = (*elements)[i];
if (!e)
continue;
e = resolveProperties(sc, e);
if (i >= nfields)
{
if (i == fields.dim - 1 && isNested() && e->op == TOKnull)
{
// CTFE sometimes creates null as hidden pointer; we'll allow this.
continue;
}
::error(loc, "more initializers than fields (%d) of %s", nfields, toChars());
return false;
}
VarDeclaration *v = fields[i];
if (v->offset < offset)
{
::error(loc, "overlapping initialization for %s", v->toChars());
return false;
}
offset = (unsigned)(v->offset + v->type->size());
Type *telem = v->type;
if (stype)
telem = telem->addMod(stype->mod);
Type *origType = telem;
while (!e->implicitConvTo(telem) && telem->toBasetype()->ty == Tsarray)
{
/* Static array initialization, as in:
* T[3][5] = e;
*/
telem = telem->toBasetype()->nextOf();
}
if (!e->implicitConvTo(telem))
telem = origType; // restore type for better diagnostic
e = e->implicitCastTo(sc, telem);
if (e->op == TOKerror)
return false;
(*elements)[i] = e->isLvalue() ? callCpCtor(sc, e) : valueNoDtor(e);
}
return true;
}
开发者ID:hariomrana,项目名称:dmd,代码行数:65,代码来源:struct.c
示例12: scanVar
void scanVar(Dsymbol *s, InlineScanState *iss)
{
VarDeclaration *vd = s->isVarDeclaration();
if (vd)
{
TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
if (td)
{
for (size_t i = 0; i < td->objects->dim; i++)
{ DsymbolExp *se = (DsymbolExp *)td->objects->tdata()[i];
assert(se->op == TOKdsymbol);
scanVar(se->s, iss);
}
}
else
{
// Scan initializer (vd->init)
if (vd->init)
{
ExpInitializer *ie = vd->init->isExpInitializer();
if (ie)
{
#if DMDV2
if (vd->type)
{ Type *tb = vd->type->toBasetype();
if (tb->ty == Tstruct)
{ StructDeclaration *sd = ((TypeStruct *)tb)->sym;
if (sd->cpctor)
{ /* The problem here is that if the initializer is a
* function call that returns a struct S with a cpctor:
* S s = foo();
* the postblit is done by the return statement in foo()
* in s2ir.c, the intermediate code generator.
* But, if foo() is inlined and now the code looks like:
* S s = x;
* the postblit is not there, because such assignments
* are rewritten as s.cpctor(&x) by the front end.
* So, the inlining won't get the postblit called.
* Work around by not inlining these cases.
* A proper fix would be to move all the postblit
* additions to the front end.
*/
return;
}
}
}
#endif
ie->exp = ie->exp->inlineScan(iss);
}
}
}
}
}
开发者ID:NilsBossung,项目名称:dmd,代码行数:54,代码来源:inline.c
示例13: needOpEquals
int StructDeclaration::needOpEquals()
{
#define X 0
if (X) printf("StructDeclaration::needOpEquals() %s\n", toChars());
if (hasIdentityEquals)
goto Lneed;
#if 0
if (isUnionDeclaration())
goto Ldontneed;
#endif
/* If any of the fields has an opEquals, then we
* need it too.
*/
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->isField());
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
#if 0
if (tv->isfloating())
goto Lneed;
if (tv->ty == Tarray)
goto Lneed;
if (tv->ty == Tclass)
goto Lneed;
#endif
while (tv->ty == Tsarray)
{ TypeSArray *ta = (TypeSArray *)tv;
tv = tv->nextOf()->toBasetype();
}
if (tv->ty == Tstruct)
{ TypeStruct *ts = (TypeStruct *)tv;
StructDeclaration *sd = ts->sym;
if (sd->needOpEquals())
goto Lneed;
}
}
Ldontneed:
if (X) printf("\tdontneed\n");
return 0;
Lneed:
if (X) printf("\tneed\n");
return 1;
#undef X
}
开发者ID:Ingrater,项目名称:dmd,代码行数:52,代码来源:clone.c
示例14: visit
void visit(DeclarationExp *e)
{
//printf("DeclarationExp::inlineCost3()\n");
VarDeclaration *vd = e->declaration->isVarDeclaration();
if (vd)
{
TupleDeclaration *td = vd->toAlias()->isTupleDeclaration();
if (td)
{
cost = COST_MAX; // finish DeclarationExp::doInline
return;
}
if (!hdrscan && vd->isDataseg())
{
cost = COST_MAX;
return;
}
if (vd->edtor)
{
// if destructor required
// needs work to make this work
cost = COST_MAX;
return;
}
// Scan initializer (vd->init)
if (vd->_init)
{
ExpInitializer *ie = vd->_init->isExpInitializer();
if (ie)
{
expressionInlineCost(ie->exp);
}
}
cost += 1;
}
// These can contain functions, which when copied, get output twice.
if (e->declaration->isStructDeclaration() ||
e->declaration->isClassDeclaration() ||
e->declaration->isFuncDeclaration() ||
e->declaration->isAttribDeclaration() ||
e->declaration->isTemplateMixin())
{
cost = COST_MAX;
return;
}
//printf("DeclarationExp::inlineCost3('%s')\n", toChars());
}
开发者ID:quickfur,项目名称:GDC,代码行数:51,代码来源:inlinecost.c
示例15: func
/* Returns:
* 0 this member doesn't need further processing to determine struct size
* 1 this member does
*/
static int func(Dsymbol *s, void *param)
{ SV *psv = (SV *)param;
VarDeclaration *v = s->isVarDeclaration();
if (v)
{
if (v->scope)
v->semantic(NULL);
if (v->storage_class & (STCstatic | STCextern | STCtls | STCgshared | STCmanifest | STCctfe | STCtemplateparameter))
return 0;
if (v->isField() && v->sem >= SemanticDone)
return 0;
return 1;
}
return 0;
}
开发者ID:duralog,项目名称:ldc,代码行数:19,代码来源:struct.c
示例16:
Expression *fromConstInitializer(Expression *e1)
{
//printf("fromConstInitializer(%s)\n", e1->toChars());
if (e1->op == TOKvar)
{ VarExp *ve = (VarExp *)e1;
VarDeclaration *v = ve->var->isVarDeclaration();
if (v && !v->originalType && v->scope) // semantic() not yet run
v->semantic (v->scope);
if (v && v->isConst() && v->init)
{ Expression *ei = v->init->toExpression();
if (ei && ei->type)
e1 = ei;
}
}
return e1;
}
开发者ID:smunix,项目名称:ldc,代码行数:16,代码来源:optimize.c
示例17: AddBaseFields
void ldc::DIBuilder::AddBaseFields(ClassDeclaration *sd, llvm::DIFile file,
std::vector<llvm::Value*> &elems)
{
if (sd->baseClass)
{
AddBaseFields(sd->baseClass, file, elems);
}
ArrayIter<VarDeclaration> it(sd->fields);
size_t narr = sd->fields.dim;
elems.reserve(narr);
for (; !it.done(); it.next())
{
VarDeclaration* vd = it.get();
elems.push_back(CreateMemberType(vd->loc.linnum, vd->type, file, vd->toChars(), vd->offset));
}
}
开发者ID:Safety0ff,项目名称:ldc,代码行数:17,代码来源:dibuilder.cpp
示例18: visit
void visit(ExpStatement *stmt) override {
IF_LOG Logger::println("ExpStatement::toNakedIR(): %s",
stmt->loc.toChars());
LOG_SCOPE;
// This happens only if there is a ; at the end:
// asm { naked; ... };
// Is this a legal AST?
if (!stmt->exp) {
return;
}
// only expstmt supported in declarations
if (!stmt->exp || stmt->exp->op != TOKdeclaration) {
visit(static_cast<Statement *>(stmt));
return;
}
DeclarationExp *d = static_cast<DeclarationExp *>(stmt->exp);
VarDeclaration *vd = d->declaration->isVarDeclaration();
FuncDeclaration *fd = d->declaration->isFuncDeclaration();
EnumDeclaration *ed = d->declaration->isEnumDeclaration();
// and only static variable/function declaration
// no locals or nested stuffies!
if (!vd && !fd && !ed) {
visit(static_cast<Statement *>(stmt));
return;
}
if (vd && !(vd->storage_class & (STCstatic | STCmanifest))) {
error(vd->loc, "non-static variable `%s` not allowed in naked function",
vd->toChars());
return;
}
if (fd && !fd->isStatic()) {
error(fd->loc,
"non-static nested function `%s` not allowed in naked function",
fd->toChars());
return;
}
// enum decls should always be safe
// make sure the symbols gets processed
// TODO: codegen() here is likely incorrect
Declaration_codegen(d->declaration, irs);
}
开发者ID:ldc-developers,项目名称:ldc,代码行数:46,代码来源:naked.cpp
示例19: visit
void visit(DeclarationExp *e)
{
// Note that, walkPostorder does not support DeclarationExp today.
VarDeclaration *v = e->declaration->isVarDeclaration();
if (v && !(v->storage_class & STCmanifest) && !v->isDataseg() && v->init)
{
if (v->init->isVoidInitializer())
{
}
else
{
ExpInitializer *ei = v->init->isExpInitializer();
assert(ei);
doCond(ei->exp);
}
}
}
开发者ID:SungSingSong,项目名称:dmd,代码行数:17,代码来源:nogc.c
示例20: needOpAssign
int StructDeclaration::needOpAssign()
{
#define X 0
if (X) printf("StructDeclaration::needOpAssign() %s\n", toChars());
if (hasIdentityAssign)
goto Lneed; // because has identity==elaborate opAssign
if (dtor || postblit)
goto Lneed;
/* If any of the fields need an opAssign, then we
* need it too.
*/
for (size_t i = 0; i < fields.dim; i++)
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->isField());
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
while (tv->ty == Tsarray)
{ TypeSArray *ta = (TypeSArray *)tv;
tv = tv->nextOf()->toBasetype();
}
if (tv->ty == Tstruct)
{ TypeStruct *ts = (TypeStruct *)tv;
StructDeclaration *sd = ts->sym;
if (sd->needOpAssign())
goto Lneed;
}
}
Ldontneed:
if (X) printf("\tdontneed\n");
return 0;
Lneed:
if (X) printf("\tneed\n");
return 1;
#undef X
}
开发者ID:Ingrater,项目名称:dmd,代码行数:42,代码来源:clone.c
注:本文中的VarDeclaration类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论