本文整理汇总了C++中VarDeclaration::toParent方法的典型用法代码示例。如果您正苦于以下问题:C++ VarDeclaration::toParent方法的具体用法?C++ VarDeclaration::toParent怎么用?C++ VarDeclaration::toParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VarDeclaration
的用法示例。
在下文中一共展示了VarDeclaration::toParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
Expression *VarExp::doInline(InlineDoState *ids)
{
//printf("VarExp::doInline(%s)\n", toChars());
for (size_t i = 0; i < ids->from.dim; i++)
{
if (var == ids->from[i])
{
VarExp *ve = (VarExp *)copy();
ve->var = (Declaration *)ids->to[i];
return ve;
}
}
if (ids->fd && var == ids->fd->vthis)
{
VarExp *ve = new VarExp(loc, ids->vthis);
ve->type = type;
return ve;
}
/* Inlining context pointer access for nested referenced variables.
* For example:
* auto fun() {
* int i = 40;
* auto foo() {
* int g = 2;
* struct Result {
* auto bar() { return i + g; }
* }
* return Result();
* }
* return foo();
* }
* auto t = fun();
* 'i' and 'g' are nested referenced variables in Result.bar(), so:
* auto x = t.bar();
* should be inlined to:
* auto x = *(t.vthis.vthis + i->voffset) + *(t.vthis + g->voffset)
*/
VarDeclaration *v = var->isVarDeclaration();
if (v && v->nestedrefs.dim && ids->vthis)
{
Dsymbol *s = ids->fd;
FuncDeclaration *fdv = v->toParent()->isFuncDeclaration();
assert(fdv);
Expression *ve = new VarExp(loc, ids->vthis);
ve->type = ids->vthis->type;
while (s != fdv)
{
FuncDeclaration *f = s->isFuncDeclaration();
if (AggregateDeclaration *ad = s->isThis())
{
assert(ad->vthis);
ve = new DotVarExp(loc, ve, ad->vthis);
ve->type = ad->vthis->type;
s = ad->toParent2();
}
else if (f && f->isNested())
{
assert(f->vthis);
if (f->hasNestedFrameRefs())
{
ve = new DotVarExp(loc, ve, f->vthis);
ve->type = f->vthis->type;
}
s = f->toParent2();
}
else
assert(0);
assert(s);
}
ve = new DotVarExp(loc, ve, v);
ve->type = v->type;
//printf("\t==> ve = %s, type = %s\n", ve->toChars(), ve->type->toChars());
return ve;
}
return this;
}