当前位置: 首页>>代码示例>>C++>>正文


C++ VarDeclaration::toParent方法代码示例

本文整理汇总了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;
}
开发者ID:D-Programming-microD,项目名称:GDC,代码行数:78,代码来源:inline.c


注:本文中的VarDeclaration::toParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。