Ejemplo n.º 1
0
ExpressionPtr FunctionCall::postOptimize(AnalysisResultPtr ar) {
  if (m_class) ar->postOptimize(m_class);
  ar->postOptimize(m_nameExp);
  ar->postOptimize(m_params);
  optimizeArgArray(ar);
  return ExpressionPtr();
}
Ejemplo n.º 2
0
StatementPtr ForEachStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_array);
  ar->postOptimize(m_name);
  ar->postOptimize(m_value);
  ar->postOptimize(m_stmt);
  return StatementPtr();
}
Ejemplo n.º 3
0
StatementPtr WhileStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_condition);
  if (m_stmt) {
    ar->getScope()->incLoopNestedLevel();
    ar->postOptimize(m_stmt);
    ar->getScope()->decLoopNestedLevel();
  }
  return StatementPtr();
}
Ejemplo n.º 4
0
StatementPtr InterfaceStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_base);
  if (m_stmt) {
    ClassScopePtr classScope = m_classScope.lock();
    ar->pushScope(classScope);
    ar->postOptimize(m_stmt);
    ar->popScope();
  }
  return StatementPtr();
}
Ejemplo n.º 5
0
StatementPtr ForStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_exp1);
  ar->postOptimize(m_exp2);
  ar->postOptimize(m_exp3);
  if (m_stmt) {
    ar->getScope()->incLoopNestedLevel();
    ar->postOptimize(m_stmt);
    ar->getScope()->decLoopNestedLevel();
  }
  return StatementPtr();
}
Ejemplo n.º 6
0
ExpressionPtr UnaryOpExpression::postOptimize(AnalysisResultPtr ar) {
  bool insideScalarArray = ar->getInsideScalarArray();

  if (m_op == T_ARRAY &&
      (getContext() & (RefValue|LValue)) == 0) {
    if (m_exp) {
      ExpressionListPtr pairs = dynamic_pointer_cast<ExpressionList>(m_exp);
      if (pairs && pairs->isScalarArrayPairs()) {
        m_arrayId = ar->registerScalarArray(m_exp);
        ar->setInsideScalarArray(true);
      }
    } else {
      m_arrayId = ar->registerScalarArray(m_exp); // empty array
    }
  }

  ar->postOptimize(m_exp);
  if (m_op == T_PRINT && m_exp->is(KindOfEncapsListExpression) &&
      !m_exp->hasEffect()) {
    EncapsListExpressionPtr e = static_pointer_cast<EncapsListExpression>
      (m_exp);
    e->stripConcat();
  }

  ar->setInsideScalarArray(insideScalarArray);

  if (m_op == T_UNSET_CAST && !hasEffect()) {
    return CONSTANT("null");
  } else if (m_op == T_UNSET && m_exp->is(KindOfExpressionList) &&
             !static_pointer_cast<ExpressionList>(m_exp)->getCount()) {
    return CONSTANT("null");
  }

  return ExpressionPtr();
}
Ejemplo n.º 7
0
ExpressionPtr ExpressionList::postOptimize(AnalysisResultPtr ar) {
  for (unsigned int i = 0; i < m_exps.size(); i++) {
    ar->postOptimize(m_exps[i]);
  }
  return optimize(ar) ? static_pointer_cast<Expression>(shared_from_this())
                      : ExpressionPtr();
}
Ejemplo n.º 8
0
ExpressionPtr BinaryOpExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_exp1);
  ar->postOptimize(m_exp2);
  ExpressionPtr optExp = simplifyArithmetic(ar);
  if (optExp) return optExp;
  if (isShortCircuitOperator()) return simplifyLogical(ar);
  return ExpressionPtr();
}
Ejemplo n.º 9
0
ExpressionPtr AssignmentExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_variable);
  ar->postOptimize(m_value);
  if (m_variable->is(Expression::KindOfSimpleVariable)) {
    SimpleVariablePtr var =
      dynamic_pointer_cast<SimpleVariable>(m_variable);
    const std::string &name = var->getName();
    VariableTablePtr variables = ar->getScope()->getVariables();
    if (variables->checkUnused(name)) {
      variables->addUnused(name);
      if (m_value->getContainedEffects() != getContainedEffects()) {
        s_effectsTag++;
      }
      return m_value;
    }
  }
  return ExpressionPtr();
}
Ejemplo n.º 10
0
StatementPtr MethodStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_modifiers);
  ar->postOptimize(m_params);
  FunctionScopePtr funcScope = m_funcScope.lock();
  ar->pushScope(funcScope);
  if (ar->getPhase() != AnalysisResult::AnalyzeInclude &&
      (AliasManager::doLocalCopyProp() ||
       AliasManager::doStringOpts())) {
    bool flag;
    do {
      AliasManager am;
      MethodStatementPtr self =
        static_pointer_cast<MethodStatement>(shared_from_this());
      flag = am.optimize(ar, self);
      ar->postOptimize(m_stmt);
    } while (flag);
  } else {
    ar->postOptimize(m_stmt);
  }
  ar->popScope();
  return StatementPtr();
}
Ejemplo n.º 11
0
ExpressionPtr AssignmentExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_variable);
  ar->postOptimize(m_value);
  if (m_variable->is(Expression::KindOfSimpleVariable)) {
    SimpleVariablePtr var =
      dynamic_pointer_cast<SimpleVariable>(m_variable);
    const std::string &name = var->getName();
    VariableTablePtr variables = ar->getScope()->getVariables();
    if (!variables->isPseudoMainTable() &&
        !variables->getAttribute(VariableTable::ContainsDynamicVariable) &&
        !variables->isReferenced(name) &&
        variables->isLocal(name)) {
      variables->addUnused(name);
      if (m_value->isScalar()) {
        m_value->setExpectedType(m_expectedType);
        return m_value;
      } else {
        return makeIdCall(ar);
      }
    }
  }
  return ExpressionPtr();
}
Ejemplo n.º 12
0
StatementPtr StatementList::postOptimize(AnalysisResultPtr ar) {
  bool changed = false;
  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr &s = m_stmts[i];
    ar->postOptimize(s);
    if (AliasManager::doDeadCodeElim() &&
        s->is(KindOfExpStatement) && !s->hasEffect()) {
      removeElement(i--);
      changed = true;
      continue;
    }
  }
  return changed ? static_pointer_cast<Statement>(shared_from_this())
                 : StatementPtr();
}
Ejemplo n.º 13
0
ExpressionPtr IncludeExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_exp);
  if (!m_include.empty()) {
    FileScopePtr fs = ar->findFileScope(m_include, false);
    if (fs) {
      if (!Option::KeepStatementsWithNoEffect && !fs->hasImpl(ar)) {
        return ScalarExpressionPtr
          (new ScalarExpression(getLocation(),
                                Expression::KindOfScalarExpression,
                                1));
      }
      m_exp.reset();
    }
  }
  return ExpressionPtr();
}
Ejemplo n.º 14
0
StatementPtr StatementList::postOptimize(AnalysisResultPtr ar) {
  bool changed = false;
  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr &s = m_stmts[i];
    ar->postOptimize(s);
    if (s->is(KindOfExpStatement) && !s->hasEffect()) {
      if (Option::EliminateDeadCode ||
          static_pointer_cast<ExpStatement>(s)->getExpression()->isScalar()) {
        removeElement(i--);
        changed = true;
        continue;
      }
    }
  }
  return changed ? static_pointer_cast<Statement>(shared_from_this())
                 : StatementPtr();
}
Ejemplo n.º 15
0
ExpressionPtr UnaryOpExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_exp);
  if (m_op == T_PRINT && m_exp->is(KindOfEncapsListExpression) &&
      !m_exp->hasEffect()) {
    EncapsListExpressionPtr e = static_pointer_cast<EncapsListExpression>
      (m_exp);
    e->stripConcat();
  }

  if (m_op == T_UNSET_CAST && !hasEffect()) {
    return CONSTANT("null");
  } else if (m_op == T_UNSET && m_exp->is(KindOfExpressionList) &&
             !static_pointer_cast<ExpressionList>(m_exp)->getCount()) {
    return CONSTANT("null");
  }

  return ExpressionPtr();
}
Ejemplo n.º 16
0
ExpressionPtr IncludeExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_exp);
  if (!m_include.empty()) {
    if (!m_depsSet) {
      analyzeInclude(ar, m_include);
      m_depsSet = true;
    }
    FileScopePtr fs = ar->findFileScope(m_include, false);
    if (fs) {
      if (!Option::KeepStatementsWithNoEffect) {
        if (ExpressionPtr rep = fs->getEffectiveImpl(ar)) {
          recomputeEffects();
          return rep;
        }
      }
      m_exp.reset();
    }
  }
  return ExpressionPtr();
}
Ejemplo n.º 17
0
ExpressionPtr UnaryOpExpression::postOptimize(AnalysisResultPtr ar) {
    bool insideScalarArray = ar->getInsideScalarArray();

    if (m_op == T_ARRAY &&
            (getContext() & (RefValue|LValue)) == 0) {
        if (m_exp) {
            ExpressionListPtr pairs = dynamic_pointer_cast<ExpressionList>(m_exp);
            if (pairs && pairs->isScalarArrayPairs()) {
                m_arrayId = ar->registerScalarArray(m_exp);
                ar->setInsideScalarArray(true);
            }
        } else {
            m_arrayId = ar->registerScalarArray(m_exp); // empty array
        }
    }

    ar->postOptimize(m_exp);

    ar->setInsideScalarArray(insideScalarArray);
    return ExpressionPtr();
}
Ejemplo n.º 18
0
StatementPtr IfBranchStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_condition);
  ar->postOptimize(m_stmt);
  return StatementPtr();
}
Ejemplo n.º 19
0
ExpressionPtr ListAssignment::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_variables);
  ar->postOptimize(m_array);
  return ExpressionPtr();
}
Ejemplo n.º 20
0
StatementPtr StaticStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_exp);
  return StatementPtr();
}
Ejemplo n.º 21
0
ExpressionPtr DynamicVariable::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_exp);
  return ExpressionPtr();
}
Ejemplo n.º 22
0
StatementPtr ClassVariable::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_modifiers);
  ar->postOptimize(m_declaration);
  return StatementPtr();
}
Ejemplo n.º 23
0
StatementPtr CatchStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_stmt);
  return StatementPtr();
}
Ejemplo n.º 24
0
ExpressionPtr AssignmentExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_variable);
  ar->postOptimize(m_value);
  return optimize(ar);
}
Ejemplo n.º 25
0
StatementPtr ExpStatement::postOptimize(AnalysisResultPtr ar) {
  m_exp = m_exp->unneeded(ar);
  ar->postOptimize(m_exp);
  return StatementPtr();
}
Ejemplo n.º 26
0
StatementPtr EchoStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_exp);
  m_exp->stripConcat();
  return StatementPtr();
}
ExpressionPtr ObjectPropertyExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_object);
  ar->postOptimize(m_property);
  return ExpressionPtr();
}
ExpressionPtr ObjectMethodExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_object);
  return FunctionCall::postOptimize(ar);
}
ExpressionPtr ArrayElementExpression::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_variable);
  ar->postOptimize(m_offset);
  return ExpressionPtr();
}
Ejemplo n.º 30
0
StatementPtr BlockStatement::postOptimize(AnalysisResultPtr ar) {
  ar->postOptimize(m_stmts);
  return StatementPtr();
}