void DependencyGraph::add(KindOf kindOf, const std::string &program,
                          const std::string &parent, StatementPtr stmt) {
  ASSERT(kindOf == KindOfProgramMaxInclude ||
         kindOf == KindOfProgramMinInclude ||
         kindOf == KindOfProgramUserFunction ||
         kindOf == KindOfProgramUserClass);
  add(kindOf, program, program, ConstructPtr(), parent, ConstructPtr());
  if ((kindOf == KindOfProgramUserFunction ||
       kindOf == KindOfProgramUserClass) && *stmt->getLocation()->file) {
    add(KindOfProgramMinInclude, program, program, ConstructPtr(),
        stmt->getLocation()->file, ConstructPtr());
  }
}
Beispiel #2
0
  void execute() {
    std::sort(m_rootEntries.begin(), m_rootEntries.end(), reCmp);

    for (int i = 0; i < m_size; i++) {
      RootEntry &re = m_rootEntries[i];
      if (!re.second) break;
      const AstWalkerState &s = re.first[re.first.size() - 1];
      StatementPtr sp(dynamic_pointer_cast<Statement>(s.cp));
      assert(sp);
      StatementListPtr sl;
      int ix;
      if (sp->is(Statement::KindOfStatementList)) {
        sl = static_pointer_cast<StatementList>(sp);
        ix = (s.index - 1) / 2;
      } else {
        assert(sp->is(Statement::KindOfBlockStatement));
        sl = static_pointer_cast<BlockStatement>(sp)->getStmts();
        if (!sl) continue;
        ix = 0;
      }
      ExpressionPtr e = m_dict.get(re.second);
      assert(e && e->is(Expression::KindOfSimpleVariable));
      SimpleVariablePtr sv(static_pointer_cast<SimpleVariable>(e));
      Symbol *sym = sv->getSymbol();
      bool inGen = sv->getFunctionScope()->isGenerator();
      if (!sym || sym->isGlobal() || sym->isStatic() || sym->isParameter() ||
          sym->isClosureVar() || sv->isThis() || inGen) {
        continue;
      }

      sym->setShrinkWrapped();
      e = e->clone();
      e->clearContext();
      e->recomputeEffects();
      e->setContext(Expression::Declaration);
      StatementPtr sub = (*sl)[ix];
      e->setLocation(sub->getLocation());
      e->setBlockScope(sub->getScope());
      ExpStatementPtr exp(
          new ExpStatement(sub->getScope(), sub->getLocation(), e));
      sl->insertElement(exp, ix);
    }
  }
ExpressionPtr StatementList::getEffectiveImpl(AnalysisResultPtr ar) const {
  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr s = m_stmts[i];
    if (s->is(KindOfReturnStatement)) {
      ExpressionPtr e = static_pointer_cast<ReturnStatement>(s)->getRetExp();
      if (!e) {
        e = Expression::MakeConstant(ar, s->getLocation(), "null");
      } else if (!e->isScalar()) {
        break;
      }
      return e;
    }
    if (m_stmts[i]->hasImpl()) break;
  }
  return ExpressionPtr();
}
Beispiel #4
0
void CodeGenerator::printAsBlock(StatementPtr s) {
  if (s->is(Statement::KindOfBlockStatement)) {
    s->outputCodeModel(*this);
  } else {
    printObjectHeader("BlockStatement", 2);
    printPropertyHeader("statements");
    if (s->is(Statement::KindOfStatementList)) {
      auto sl = static_pointer_cast<StatementList>(s);
      printStatementVector(sl);
    } else {
      printf("V:9:\"HH\\Vector\":1:{");
      s->outputCodeModel(*this);
      printf("}");
    }
    printPropertyHeader("sourceLocation");
    printLocation(s->getLocation());
    printObjectFooter();
  }
}
Beispiel #5
0
void CodeGenerator::printAsBlock(StatementPtr s, bool isEnclosed) {
  if (s != nullptr && s->is(Statement::KindOfBlockStatement)) {
    s->outputCodeModel(*this);
  } else {
    auto numProps = s == nullptr ? 0 : 2;
    if (isEnclosed) numProps++;
    printObjectHeader("BlockStatement", numProps);
    if (s != nullptr) {
      printPropertyHeader("statements");
      printStatementVector(s);
      printPropertyHeader("sourceLocation");
      printLocation(s->getLocation());
    }
    if (isEnclosed) {
      printPropertyHeader("isEnclosed");
      printBool(true);
    }
    printObjectFooter();
  }
}