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


C++ CodeGenerator::findLabelId方法代码示例

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


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

示例1: outputCPPImpl

void WhileStatement::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
  int labelId = cg.createNewId(ar);
  cg.pushBreakScope(labelId);
  cg.indentBegin("{\n");

  bool e_order = m_condition->preOutputCPP(cg, ar, 0);

  cg.printf("while (");
  if (e_order) {
    cg.printf("true");
  } else {
    m_condition->outputCPP(cg, ar);
  }
  cg.indentBegin(") {\n");
  if (e_order) {
    m_condition->outputCPPBegin(cg, ar);
    cg.printf("if (!(");
    m_condition->outputCPP(cg, ar);
    cg.printf(")) break;\n");
    m_condition->outputCPPEnd(cg, ar);
  }
  cg.printf("LOOP_COUNTER_CHECK(%d);\n", labelId);
  if (m_stmt) {
    m_stmt->outputCPP(cg, ar);
  }
  if (cg.findLabelId("continue", labelId)) {
    cg.printf("continue%d:;\n", labelId, labelId);
  }
  cg.indentEnd("}\n");
  if (cg.findLabelId("break", labelId)) {
    cg.printf("break%d:;\n", labelId);
  }
  cg.indentEnd("}\n");
  cg.popBreakScope();
}
开发者ID:scottmac,项目名称:hiphop-dev,代码行数:35,代码来源:while_statement.cpp

示例2: outputCPPImpl

void ForStatement::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
  cg_indentBegin("{\n");

  int e1_order = 0;
  if (m_exp1) {
    if (m_exp1->preOutputCPP(cg, ar, 0)) {
      e1_order = 1;
    } else if (numStringBufs()) {
      e1_order = -1;
    }
  }
  bool e2_order = m_exp2 && m_exp2->preOutputCPP(cg, ar, 0);
  bool e3_order = m_exp3 && m_exp3->preOutputCPP(cg, ar, 0);

  int labelId = cg.createNewLocalId(ar);

  cg.pushBreakScope(e3_order ? labelId | CodeGenerator::InsideSwitch : labelId);

  if (e1_order) {
    m_exp1->outputCPPUnneeded(cg, ar);
    if (e1_order < 0) cg_printf(";\n");
  }
  cppDeclareBufs(cg, ar);
  cg_printf("for (");
  if (m_exp1 && !e1_order && m_exp1->hasEffect()) {
    m_exp1->outputCPPUnneeded(cg, ar);
  }
  cg_printf("; ");
  if (m_exp2 && !e2_order) m_exp2->outputCPP(cg, ar);
  cg_printf("; ");
  if (m_exp3 && !e3_order && m_exp3->hasEffect()) {
    m_exp3->outputCPPUnneeded(cg, ar);
  }
  cg_indentBegin(") {\n");
  if (e2_order) {
    m_exp2->outputCPPBegin(cg, ar);
    cg_printf("if (!(");
    m_exp2->outputCPP(cg, ar);
    cg_printf(")) break;\n");
    m_exp2->outputCPPEnd(cg, ar);
  }
  cg_printf("LOOP_COUNTER_CHECK(%d);\n", labelId);
  if (m_stmt) {
    m_stmt->outputCPP(cg, ar);
  }
  if (cg.findLabelId("continue", labelId)) {
    cg_printf("continue%d:;\n", labelId);
  }
  if (e3_order) {
    m_exp3->outputCPPUnneeded(cg, ar);
  }
  cg_indentEnd("}\n");
  if (cg.findLabelId("break", labelId)) {
    cg_printf("break%d:;\n", labelId);
  }
  cppEndBufs(cg, ar);
  cg_indentEnd("}\n");
  cg.popBreakScope();
}
开发者ID:Bittarman,项目名称:hiphop-php,代码行数:59,代码来源:for_statement.cpp

示例3: outputCPP

void DoStatement::outputCPP(CodeGenerator &cg, AnalysisResultPtr ar) {
  cg.indentBegin("{\n");
  int labelId = cg.createNewId(ar);
  cg.pushBreakScope(labelId);

  cg.indentBegin("do {\n");
  cg.printf("LOOP_COUNTER_CHECK(%d);\n", labelId);
  if (m_stmt) {
    m_stmt->outputCPP(cg, ar);
  }
  if (cg.findLabelId("continue", labelId)) {
    cg.printf("continue%d:;\n", labelId);
  }
  cg.indentEnd("} while (");
  m_condition->outputCPP(cg, ar);
  cg.printf(");\n");
  if (cg.findLabelId("break", labelId)) {
    cg.printf("break%d:;\n", labelId);
  }
  cg.indentEnd("}\n");
  cg.popBreakScope();
}
开发者ID:Neomeng,项目名称:hiphop-php,代码行数:22,代码来源:do_statement.cpp

示例4: outputCPPImpl

void DoStatement::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
  cg_indentBegin("{\n");
  bool e_order = m_condition->preOutputCPP(cg, ar, 0);

  int labelId = cg.createNewLocalId(shared_from_this());
  cg.pushBreakScope(e_order ? labelId | CodeGenerator::InsideSwitch : labelId);

  cppDeclareBufs(cg, ar);
  cg_indentBegin("do {\n");
  cg_printf("LOOP_COUNTER_CHECK(%d);\n", labelId);
  if (m_stmt) {
    m_stmt->outputCPP(cg, ar);
  }
  if (cg.findLabelId("continue", labelId)) {
    cg_printf("continue%d:;\n", labelId);
  }
  if (e_order) {
    m_condition->outputCPPBegin(cg, ar);
    cg_printf("if (!(");
    m_condition->outputCPP(cg, ar);
    cg_printf(")) break;\n");
    m_condition->outputCPPEnd(cg, ar);
  }
  cg_indentEnd("} while (");
  if (e_order) {
    cg_printf("true");
  } else {
    m_condition->outputCPP(cg, ar);
  }
  cg_printf(");\n");
  if (cg.findLabelId("break", labelId)) {
    cg_printf("break%d:;\n", labelId);
  }
  cppEndBufs(cg, ar);
  cg_indentEnd("}\n");
  cg.popBreakScope();
}
开发者ID:gavingeng,项目名称:hiphop-php,代码行数:37,代码来源:do_statement.cpp

示例5: outputCPPImpl


//.........这里部分代码省略.........
        if (seenNums.find(num) != seenNums.end()) {
          staticCases = false;
          break;
        }
        seenNums.insert(num);
      } else {
        seenDefault = true;
      }
    }
  }

  labelId |= CodeGenerator::InsideSwitch;
  if (staticCases) labelId |= CodeGenerator::StaticCases;
  cg.pushBreakScope(labelId, false);
  labelId &= ~CodeGenerator::BreakScopeBitMask;
  cg_indentBegin("{\n");

  string var;
  int varId = -1;

  if (m_exp->preOutputCPP(cg, ar, 0)) {
    varId = cg.createNewLocalId(shared_from_this());
    var = string(Option::SwitchPrefix) + lexical_cast<string>(varId);
    m_exp->getType()->outputCPPDecl(cg, ar, getScope());
    cg_printf(" %s;\n", var.c_str());

    m_exp->outputCPPBegin(cg, ar);
    cg_printf("%s = (", var.c_str());
    m_exp->outputCPP(cg, ar);
    cg_printf(");\n");
    m_exp->outputCPPEnd(cg, ar);
  }

  if (staticCases) {
    cg_printf("switch (");
    if (!var.empty()) {
      cg_printf("%s", var.c_str());
    } else {
      m_exp->outputCPP(cg, ar);
    }
    cg_printf(") {\n");
    if (m_cases) m_cases->outputCPP(cg, ar);
    cg_printf("}\n");
  } else {
    if (var.empty()) {
      varId = cg.createNewLocalId(shared_from_this());
      if (m_exp->hasContext(Expression::LValue) &&
          m_exp->is(Expression::KindOfSimpleVariable)) {
        var = getScope()->getVariables()->getVariableName(
          cg, ar, static_pointer_cast<SimpleVariable>(m_exp)->getName());
      } else {
        var = string(Option::SwitchPrefix) + lexical_cast<string>(varId);
        m_exp->getType()->outputCPPDecl(cg, ar, getScope());
        cg_printf(" %s = (", var.c_str());
        m_exp->outputCPP(cg, ar);
        cg_printf(");\n");
      }
    }

    if (m_cases && m_cases->getCount()) {
      CaseStatementPtr defaultCase;
      int defaultCaseNum = -1;
      for (int i = 0; i < m_cases->getCount(); i++) {
        CaseStatementPtr stmt =
          dynamic_pointer_cast<CaseStatement>((*m_cases)[i]);
        if (stmt->getCondition()) {
          stmt->outputCPPAsIf(cg, ar, varId, var.c_str(), i);
        } else {
          defaultCase = stmt;
          defaultCaseNum = i;
        }
      }
      if (defaultCaseNum != -1) {
        defaultCase->outputCPPAsIf(cg, ar, varId, var.c_str(), defaultCaseNum);
      } else {
        cg_printf("goto break%d;\n", labelId);
        cg.addLabelId("break", labelId);
      }
      cg_printf("\n");
      for (int i = 0; i < m_cases->getCount(); i++) {
        CaseStatementPtr stmt =
          dynamic_pointer_cast<CaseStatement>((*m_cases)[i]);
        stmt->outputCPPByNumber(cg, ar, varId,
                                !stmt->getCondition() && defaultCaseNum != i ?
                                -1 : i);
      }
    }
  }

  // Even though switch's break/continue will never goto these labels, we need
  // them for "break/continue n" inside switches.
  if (cg.findLabelId("continue", labelId)) {
    cg_printf("continue%d:;\n", labelId);
  }
  if (cg.findLabelId("break", labelId)) {
    cg_printf("break%d:;\n", labelId);
  }
  cg_indentEnd("}\n");
  cg.popBreakScope();
}
开发者ID:activeingredient,项目名称:hiphop-php,代码行数:101,代码来源:switch_statement.cpp

示例6: outputCPPImpl


//.........这里部分代码省略.........
  cg_indentBegin(") {\n");
  cg_printf("LOOP_COUNTER_CHECK(%d);\n", labelId);

  /*
    The order of evaluation here is.
    - second() (if !m_ref)
    - first() (if !m_ref && m_name is set)
    - side effects of m_name (if set)
    - side effects of m_value
    - assignment to m_value
    - assignment to m_name
    This order is observable, and we have tests to prove it.

    Optimize for the usual case, where m_name and m_value are
    simple variables.
  */

  string valueStr, nameStr;

  if (!m_ref) {
    Util::string_printf(valueStr, "%s%d.second()",
                        Option::IterPrefix, iterId);
    Util::string_printf(nameStr, "%s%d.first()",
                        Option::IterPrefix, iterId);
    if (valueSimple) {
      cg_printf("%s%d.second(", Option::IterPrefix, iterId);
      m_value->outputCPP(cg, ar);
      cg_printf(");\n");
    } else if (m_name || m_value->hasEffect()) {
      string tmp;
      Util::string_printf(tmp, "%s%d_v", Option::MapPrefix, mapId);
      cg_printf("CVarRef %s = %s;\n",
                tmp.c_str(), valueStr.c_str());
      valueStr = tmp;
    }
    if (m_name && m_name->hasEffect()) {
      string tmp;
      Util::string_printf(tmp, "%s%d_n", Option::MapPrefix, mapId);
      cg_printf("CVarRef %s = %s;\n",
                tmp.c_str(), nameStr.c_str());
      nameStr = tmp;
    }
  } else {
    Util::string_printf(valueStr, "%s%d_v", Option::MapPrefix, mapId);
    Util::string_printf(nameStr, "%s%d_n", Option::MapPrefix, mapId);
  }

  bool wrap = false;
  if (m_name) {
    if (orderName || m_value->hasEffect()) {
      cg.setInExpression(true);
      m_name->preOutputCPP(cg, ar,
                           m_value->hasEffect() ? Expression::FixOrder: 0);
      wrap = true;
    }
  }

  if (!valueSimple) {
    if (orderValue) {
      m_value->outputCPPBegin(cg, ar);
      wrap = true;
    }
    if (!AssignmentExpression::SpecialAssignment(
          cg, ar, m_value, ExpressionPtr(), valueStr.c_str(), m_ref)) {
      m_value->outputCPP(cg, ar);
      cg_printf(".assign%s(%s)", m_ref ? "Ref" : "Val", valueStr.c_str());
    }
    cg_printf(";\n");
  }

  if (m_name && (!nameSimple || !m_ref)) {
    if (orderName) {
      m_name->outputCPPBegin(cg, ar);
    }
    if (!AssignmentExpression::SpecialAssignment(
          cg, ar, m_name, ExpressionPtr(), nameStr.c_str(), m_ref)) {
      m_name->outputCPP(cg, ar);
      cg_printf(".assign%s(%s)", m_ref ? "Ref" : "Val", nameStr.c_str());
    }
    cg_printf(";\n");
  }
  if (wrap) {
    cg.wrapExpressionEnd();
    cg.setInExpression(false);
  }

  if (m_stmt) {
    m_stmt->outputCPP(cg, ar);
  }
  if (cg.findLabelId("continue", labelId)) {
    cg_printf("continue%d:;\n", labelId);
  }
  cg_indentEnd("}\n");
  if (cg.findLabelId("break", labelId)) {
    cg_printf("break%d:;\n", labelId);
  }
  cg.popBreakScope();
  cppEndBufs(cg, ar);
  cg_indentEnd("}\n");
}
开发者ID:SimplProduction,项目名称:hiphop-php,代码行数:101,代码来源:foreach_statement.cpp

示例7: outputCPPImpl


//.........这里部分代码省略.........
    } else {
      TypePtr expectedType = m_array->getExpectedType();
      // Clear m_expectedType to avoid type cast (toArray).
      m_array->setExpectedType(TypePtr());
      cg_printf(" = ");
      m_array->outputCPP(cg, ar);
      cg_printf(";\n");
      m_array->setExpectedType(expectedType);
    }
    if (wrap) {
      m_array->outputCPPEnd(cg, ar);
    }
  } else {
    passTemp = false;
  }

  cppDeclareBufs(cg, ar);
  int iterId = cg.createNewLocalId(ar);
  cg_printf("for (");
  if (m_ref) {
    cg_printf("MutableArrayIterPtr %s%d = %s%d.begin(",
              Option::IterPrefix, iterId, Option::MapPrefix, mapId);
    if (m_name) {
      cg_printf("&");
      m_name->outputCPP(cg, ar);
    } else {
      cg_printf("NULL");
    }
    cg_printf(", ");
    m_value->outputCPP(cg, ar);
    cg_printf("); %s%d->advance();", Option::IterPrefix, iterId);
  } else {
    if (passTemp) {
      cg_printf("ArrayIterPtr %s%d = %s%d.begin(",
                Option::IterPrefix, iterId,
                Option::MapPrefix, mapId);
      ClassScopePtr cls = ar->getClassScope();
      if (cls) {
        cg_printf("%sclass_name", Option::StaticPropertyPrefix);
      }
      cg_printf("); ");
      cg_printf("!%s%d->end(); %s%d->next()",
                Option::IterPrefix, iterId,
                Option::IterPrefix, iterId);
    } else {
      TypePtr actualType = m_array->getActualType();
      if (actualType && actualType->is(Type::KindOfArray)) {
        isArray = true;
        cg_printf("ArrayIter %s%d = ", Option::IterPrefix, iterId);
      } else {
        cg_printf("ArrayIterPtr %s%d = ", Option::IterPrefix, iterId);
      }
      TypePtr expectedType = m_array->getExpectedType();
      // Clear m_expectedType to avoid type cast (toArray).
      m_array->setExpectedType(TypePtr());
      m_array->outputCPP(cg, ar);
      m_array->setExpectedType(expectedType);
      cg_printf(".begin(");
      ClassScopePtr cls = ar->getClassScope();
      if (cls) {
        cg_printf("%sclass_name", Option::StaticPropertyPrefix);
      }
      cg_printf("); ");
      if (isArray) {
        cg_printf("!%s%d.end(); ", Option::IterPrefix, iterId);
        cg_printf("++%s%d", Option::IterPrefix, iterId);
      } else {
        cg_printf("!%s%d->end(); ", Option::IterPrefix, iterId);
        cg_printf("%s%d->next()", Option::IterPrefix, iterId);
      }
    }
  }
  cg_indentBegin(") {\n");
  cg_printf("LOOP_COUNTER_CHECK(%d);\n", labelId);

  if (!m_ref) {
    cg_printf(isArray ? "%s%d.second(" : "%s%d->second(",
              Option::IterPrefix, iterId);
    m_value->outputCPP(cg, ar);
    cg_printf(");\n");
    if (m_name) {
      m_name->outputCPP(cg, ar);
      cg_printf(isArray ? " = %s%d.first();\n" : " = %s%d->first();\n",
                Option::IterPrefix, iterId);
    }
  }
  if (m_stmt) {
    m_stmt->outputCPP(cg, ar);
  }
  if (cg.findLabelId("continue", labelId)) {
    cg_printf("continue%d:;\n", labelId);
  }
  cg_indentEnd("}\n");
  if (cg.findLabelId("break", labelId)) {
    cg_printf("break%d:;\n", labelId);
  }
  cg.popBreakScope();
  cppEndBufs(cg, ar);
  cg_indentEnd("}\n");
}
开发者ID:Bittarman,项目名称:hiphop-php,代码行数:101,代码来源:foreach_statement.cpp


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