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


C++ Binary::getSubExp2方法代码示例

本文整理汇总了C++中Binary::getSubExp2方法的典型用法代码示例。如果您正苦于以下问题:C++ Binary::getSubExp2方法的具体用法?C++ Binary::getSubExp2怎么用?C++ Binary::getSubExp2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Binary的用法示例。


在下文中一共展示了Binary::getSubExp2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Binary

std::list<Statement *> *RTLInstDict::transformPostVars(std::list<Statement *> *rts, bool optimise)
{
    std::list<Statement *>::iterator rt;

    // Map from var (could be any expression really) to details
    std::map<Exp *, transPost, lessExpStar> vars;
    int tmpcount = 1;  // For making temp names unique
    // Exp *matchParam(1, idParam);  // ? Was never used anyway

#ifdef DEBUG_POSTVAR
    std::cout << "Transforming from:\n";
    for (Exp_CIT p = rts->begin(); p != rts->end(); p++) {
        std::cout << setw(8) << " ";
        (*p)->print(std::cout);
        std::cout << "\n";
    }
#endif

    // First pass: Scan for post-variables and usages of their referents
    for (rt = rts->begin(); rt != rts->end(); rt++) {
        // ss appears to be a list of expressions to be searched
        // It is either the LHS and RHS of an assignment, or it's the parameters of a flag call
        Binary *ss;
        if ((*rt)->isAssign()) {
            Exp *lhs = ((Assign *)*rt)->getLeft();
            Exp *rhs = ((Assign *)*rt)->getRight();

            // Look for assignments to post-variables
            if (lhs && lhs->isPostVar()) {
                if (vars.find(lhs) == vars.end()) {
                    // Add a record in the map for this postvar
                    transPost &el = vars[lhs];
                    el.used = false;
                    el.type = ((Assign *)*rt)->getType();

                    // Constuct a temporary. We should probably be smarter and actually check that it's not otherwise
                    // used here.
                    std::string tmpname = el.type->getTempName() + (tmpcount++) + "post" ;
                    el.tmp = Location::tempOf(new Const(tmpname.c_str()));

                    // Keep a copy of the referrent. For example, if the lhs is r[0]', base is r[0]
                    el.base = lhs->getSubExp1();
                    el.post = lhs;  // The whole post-var, e.g. r[0]'
                    el.isNew = true;

                    // The emulator generator sets optimise false
                    // I think this forces always generating the temps (MVE)
                    if (!optimise) {
                        el.used = true;
                        el.isNew = false;
                    }

                }
            }
            // For an assignment, the two expressions to search are the left and right hand sides (could just put the
            // whole assignment on, I suppose)
            ss = new Binary(opList,
                            lhs->clone(),
                            new Binary(opList,
                                       rhs->clone(),
                                       new Terminal(opNil)));
        } else if ((*rt)->isFlagAssgn()) {
            // An opFlagCall is assumed to be a Binary with a string and an opList of parameters
            ss = (Binary *)((Binary *)*rt)->getSubExp2();
        } else
            ss = NULL;

        /* Look for usages of post-variables' referents
         * Trickier than you'd think, as we need to make sure to skip over the post-variables themselves. ie match
         * r[0] but not r[0]'
         * Note: back with SemStrs, we could use a match expression which was a wildcard prepended to the base
         * expression; this would match either the base (r[0]) or the post-var (r[0]').
         * Can't really use this with Exps, so we search twice; once for the base, and once for the post, and if we
         * get more with the former, then we have a use of the base (consider r[0] + r[0]')
         */
        for (std::map<Exp *, transPost, lessExpStar>::iterator sr = vars.begin(); sr != vars.end(); sr++) {
            if (sr->second.isNew) {
                // Make sure we don't match a var in its defining statement
                sr->second.isNew = false;
                continue;
            }
            Binary *cur;
            for (cur = ss; !cur->isNil(); cur = (Binary *)cur->getSubExp2()) {
                if (sr->second.used)
                    break;  // Don't bother; already know it's used
                Exp *s = cur->getSubExp1();
                if (!s) continue;
                if (*s == *sr->second.base) {
                    sr->second.used = true;
                    break;
                }
                std::list<Exp *> res1, res2;
                s->searchAll(sr->second.base, res1);
                s->searchAll(sr->second.post, res2);
                // Each match of a post will also match the base.
                // But if there is a bare (non-post) use of the base, there will be a result in res1 that is not in res2
                if (res1.size() > res2.size())
                    sr->second.used = true;
            }
        }
//.........这里部分代码省略.........
开发者ID:pmatos,项目名称:boomerang,代码行数:101,代码来源:sslinst.cpp


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