Exemple #1
0
void FunctionScope::init(AnalysisResultConstPtr ar) {
    m_dynamicInvoke = false;

    if (isNamed("__autoload")) {
        setVolatile();
    }

    // FileScope's flags are from parser, but VariableTable has more flags
    // coming from type inference phase. So we are tranferring these flags
    // just for better modularization between FileScope and VariableTable.
    if (m_attribute & FileScope::ContainsDynamicVariable) {
        m_variables->setAttribute(VariableTable::ContainsDynamicVariable);
    }
    if (m_attribute & FileScope::ContainsLDynamicVariable) {
        m_variables->setAttribute(VariableTable::ContainsLDynamicVariable);
    }
    if (m_attribute & FileScope::ContainsExtract) {
        m_variables->setAttribute(VariableTable::ContainsExtract);
    }
    if (m_attribute & FileScope::ContainsAssert) {
        m_variables->setAttribute(VariableTable::ContainsAssert);
    }
    if (m_attribute & FileScope::ContainsCompact) {
        m_variables->setAttribute(VariableTable::ContainsCompact);
    }
    if (m_attribute & FileScope::ContainsUnset) {
        m_variables->setAttribute(VariableTable::ContainsUnset);
    }
    if (m_attribute & FileScope::ContainsGetDefinedVars) {
        m_variables->setAttribute(VariableTable::ContainsGetDefinedVars);
    }

    if (m_stmt && Option::AllVolatile && !m_pseudoMain && !m_method) {
        m_volatile = true;
    }

    if (!m_method && Option::DynamicInvokeFunctions.find(m_scopeName) !=
            Option::DynamicInvokeFunctions.end()) {
        setDynamicInvoke();
    }
    if (m_modifiers) {
        m_virtual = m_modifiers->isAbstract();
    }

    if (m_stmt) {
        MethodStatementPtr stmt = dynamic_pointer_cast<MethodStatement>(m_stmt);
        StatementListPtr stmts = stmt->getStmts();
        if (stmts) {
            for (int i = 0; i < stmts->getCount(); i++) {
                StatementPtr stmt = (*stmts)[i];
                stmt->setFileLevel();
                if (stmt->is(Statement::KindOfExpStatement)) {
                    ExpStatementPtr expStmt = dynamic_pointer_cast<ExpStatement>(stmt);
                    ExpressionPtr exp = expStmt->getExpression();
                    exp->setTopLevel();
                }
            }
        }
    }
}
void StatementList::outputPHP(CodeGenerator &cg, AnalysisResultPtr ar) {
  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr stmt = m_stmts[i];

    switch (cg.getContext()) {
    case CodeGenerator::NoContext:
      stmt->outputPHP(cg, ar);
      break;
    case CodeGenerator::PhpDeclaration:
      if (stmt->is(Statement::KindOfFunctionStatement) ||
          stmt->is(Statement::KindOfClassStatement) ||
          stmt->is(Statement::KindOfInterfaceStatement)) {
        cg.setContext(CodeGenerator::PhpImplementation);
        stmt->outputPHP(cg, ar);
        cg.setContext(CodeGenerator::PhpDeclaration);
      }
      break;
    case CodeGenerator::PhpImplementation:
      if (!stmt->is(Statement::KindOfFunctionStatement) &&
          !stmt->is(Statement::KindOfClassStatement) &&
          !stmt->is(Statement::KindOfInterfaceStatement)) {
        stmt->outputPHP(cg, ar);
      }
      break;
    default:
      ASSERT(false);
    }
  }
}
void StatementList::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) {
  FunctionScopePtr func = getFunctionScope();

  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr stmt = m_stmts[i];
    stmt->outputCPP(cg, ar);
    if (stmt->is(Statement::KindOfMethodStatement)) {
      MethodStatementPtr methodStmt =
        dynamic_pointer_cast<MethodStatement>(stmt);
      std::string methodName = methodStmt->getName();
      if (methodName == "offsetget") {
        ClassScopePtr cls = getClassScope();
        std::string arrayAccess("arrayaccess");
        if (cls->derivesFrom(ar, arrayAccess, false, false)) {
          FunctionScopePtr funcScope = methodStmt->getFunctionScope();
          std::string name = funcScope->getName();
          funcScope->setName("__offsetget_lval");
          methodStmt->setName("__offsetget_lval");
          methodStmt->outputCPP(cg, ar);
          funcScope->setName(name);
          methodStmt->setName("offsetget");
        }
      }
    }
  }
}
void MethodStatement::inferTypes(AnalysisResultPtr ar) {
  FunctionScopePtr funcScope = m_funcScope.lock();
  if (ar->getPhase() == AnalysisResult::FirstInference && m_stmt) {
    if (m_stmt->hasRetExp() ||
        funcScope->inPseudoMain() ||
        funcScope->getReturnType()) {
      bool lastIsReturn = false;
      if (m_stmt->getCount()) {
        StatementPtr lastStmt = (*m_stmt)[m_stmt->getCount()-1];
        if (lastStmt->is(Statement::KindOfReturnStatement)) {
          lastIsReturn = true;
        }
      }
      if (!lastIsReturn &&
          !(funcScope->inPseudoMain() && !Option::GenerateCPPMain)) {
        ExpressionPtr constant =
          funcScope->inPseudoMain() ? CONSTANT("true") : CONSTANT("null");
        ReturnStatementPtr returnStmt =
          ReturnStatementPtr(new ReturnStatement(getLocation(),
            Statement::KindOfReturnStatement, constant));
        m_stmt->addElement(returnStmt);
      }
    }
  }
  ar->pushScope(funcScope);
  if (m_params) {
    m_params->inferAndCheck(ar, NEW_TYPE(Any), false);
  }
  if (m_stmt) {
    m_stmt->inferTypes(ar);
  }
  ar->popScope();
}
void MethodStatement::inferFunctionTypes(AnalysisResultPtr ar) {
  FunctionScopeRawPtr funcScope = getFunctionScope();
  bool pseudoMain = funcScope->inPseudoMain();

  if (m_stmt && funcScope->isFirstPass()) {
    if (m_stmt->hasRetExp() ||
        pseudoMain ||
        funcScope->getReturnType()) {
      bool lastIsReturn = false;
      if (m_stmt->getCount()) {
        StatementPtr lastStmt = (*m_stmt)[m_stmt->getCount()-1];
        if (lastStmt->is(Statement::KindOfReturnStatement)) {
          lastIsReturn = true;
        }
      }
      if (!lastIsReturn && (!pseudoMain || Option::GenerateCPPMain)) {
        ExpressionPtr constant =
          makeConstant(ar, funcScope->inPseudoMain() ? "true" : "null");
        ReturnStatementPtr returnStmt =
          ReturnStatementPtr(new ReturnStatement(getScope(), getLocation(),
            Statement::KindOfReturnStatement, constant));
        m_stmt->addElement(returnStmt);
      }
    }
  }

  if (m_params) {
    m_params->inferAndCheck(ar, Type::Any, false);
  }
  if (m_stmt) {
    m_stmt->inferTypes(ar);
  }
}
Exemple #6
0
bool AnalysisResult::checkClassPresent(ConstructPtr cs,
                                       const std::string &name) const {
  if (name == "self" || name == "parent") return true;
  std::string lowerName = toLower(name);
  if (ClassScopePtr currentCls = cs->getClassScope()) {
    if (lowerName == currentCls->getName() ||
        currentCls->derivesFrom(shared_from_this(), lowerName,
                                true, false)) {
      return true;
    }
  }
  if (FileScopePtr currentFile = cs->getFileScope()) {
    StatementList &stmts = *currentFile->getStmt();
    for (int i = stmts.getCount(); i--; ) {
      StatementPtr s = stmts[i];
      if (s && s->is(Statement::KindOfClassStatement)) {
        ClassScopePtr scope =
          static_pointer_cast<ClassStatement>(s)->getClassScope();
        if (lowerName == scope->getName()) {
          return true;
        }
        if (scope->derivesFrom(shared_from_this(), lowerName,
                               true, false)) {
          return true;
        }
      }
    }
  }
  return false;
}
void	PartTable::repo(long projectid, long partno, long repoid) {
	std::string	query(	"update part set repoid = ? "
				"where project = ? and partno = ?");
	StatementPtr	stmt = database()->statement(query);
	FieldValueFactory	factory;
	stmt->bind(0, factory.get((int)repoid));
	stmt->bind(1, factory.get((int)projectid));
	stmt->bind(2, factory.get((int)partno));
	stmt->execute();
}
void StatementList::analyzeProgramImpl(AnalysisResultPtr ar) {
  m_included = true;
  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr stmt = m_stmts[i];

    // effect testing
    if (ar->isFirstPass() && !stmt->hasEffect() &&
        !stmt->is(Statement::KindOfStatementList)) {
      ar->getCodeError()->record(shared_from_this(),
                                 CodeError::StatementHasNoEffect, stmt);
    }

    // changing AUTOLOAD to includes
    if (ar->getPhase() == AnalysisResult::AnalyzeInclude &&
        stmt->is(Statement::KindOfExpStatement)) {
      ExpStatementPtr expStmt = dynamic_pointer_cast<ExpStatement>(stmt);
      if (stmt->isFileLevel()) {
        expStmt->analyzeAutoload(ar);
      }
      expStmt->analyzeShortCircuit(ar);
    }

    bool scopeStmt = stmt->is(Statement::KindOfFunctionStatement) ||
      stmt->is(Statement::KindOfClassStatement) ||
      stmt->is(Statement::KindOfInterfaceStatement);
    if (ar->getPhase() != AnalysisResult::AnalyzeTopLevel || !scopeStmt) {
      /* Recurse when analyzing include/all OR when not a scope */
      stmt->analyzeProgram(ar);
    }
  }
}
void StatementList::analyzeProgramImpl(AnalysisResultPtr ar) {
  m_included = true;
  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr stmt = m_stmts[i];

    // effect testing
    if (ar->getPhase() == AnalysisResult::AnalyzeAll) {
      if (!stmt->hasEffect() && !stmt->hasDecl() &&
          !stmt->is(Statement::KindOfStatementList)) {
        Compiler::Error(Compiler::StatementHasNoEffect, stmt);
      }

      if (stmt->is(Statement::KindOfExpStatement)) {
        static_pointer_cast<ExpStatement>(stmt)->analyzeShortCircuit(ar);
      }
    }

    bool scopeStmt = stmt->is(Statement::KindOfFunctionStatement) ||
      stmt->is(Statement::KindOfClassStatement) ||
      stmt->is(Statement::KindOfInterfaceStatement);
    if (ar->getPhase() != AnalysisResult::AnalyzeTopLevel || !scopeStmt) {
      /* Recurse when analyzing include/all OR when not a scope */
      stmt->analyzeProgram(ar);
    }
  }
}
Exemple #10
0
void CodeGenerator::printStatementVector(StatementPtr s) {
  if (s == nullptr) {
    printf("V:9:\"HH\\Vector\":0:{}");
  } else 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("}");
  }
}
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());
  }
}
Exemple #12
0
void deleteVal(ConnectionPtr & conn, const char * b)
{
	string insert("delete from dpak where col2=");
	insert += string("'") + string(b) + string("'");
	try
	{
		StatementPtr stmt = conn->createStatement();
		int rows = stmt->executeUpdate(insert.c_str());
		cerr << "Number of rows delete: " << rows << endl;
	}catch(BaseException & e){
		cerr << "BaseException: " << e.getMessage() << endl;
	}
}
Exemple #13
0
void Dictionary::build(StatementPtr stmt) {
  for (int i = 0, n = stmt->getKidCount(); i < n; i++) {
    if (ConstructPtr kid = stmt->getNthKid(i)) {
      if (StatementPtr s = boost::dynamic_pointer_cast<Statement>(kid)) {
        if (FunctionWalker::SkipRecurse(s)) continue;
        build(s);
      } else {
        ExpressionPtr e = boost::dynamic_pointer_cast<Expression>(kid);
        build(e);
      }
    }
  }
}
Exemple #14
0
void Parser::onTry(Token *out, Token *tryStmt, Token *className, Token *var,
                   Token *catchStmt, Token *catches) {
  StatementPtr stmtList;
  if (catches->stmt) {
    stmtList = catches->stmt;
  } else {
    stmtList = NEW_STMT0(StatementList);
  }
  stmtList->insertElement(NEW_STMT(CatchStatement, className->text(),
                                   var->text(), catchStmt->stmt));
  out->stmt = NEW_STMT(TryStatement, tryStmt->stmt,
                       dynamic_pointer_cast<StatementList>(stmtList));
}
void UnaryOpExpression::analyzeProgram(AnalysisResultPtr ar) {
  if (ar->getPhase() == AnalysisResult::AnalyzeFinal && m_op == '@') {
    StatementPtr stmt = ar->getStatementForSilencer();
    ASSERT(stmt);
    m_silencer = stmt->requireSilencers(1);
  }
  if (m_exp) m_exp->analyzeProgram(ar);
  if (ar->getPhase() == AnalysisResult::AnalyzeFinal && m_op == '@') {
    StatementPtr stmt = ar->getStatementForSilencer();
    ASSERT(stmt);
    stmt->endRequireSilencers(m_silencer);
  }
}
Exemple #16
0
void FileScope::setFileLevel(StatementListPtr stmtList) {
  for (int i = 0; i < stmtList->getCount(); i++) {
    StatementPtr stmt = (*stmtList)[i];
    stmt->setFileLevel();
    if (stmt->is(Statement::KindOfExpStatement)) {
      ExpStatementPtr expStmt = dynamic_pointer_cast<ExpStatement>(stmt);
      ExpressionPtr exp = expStmt->getExpression();
      exp->setFileLevel();
    }
    if (stmt->is(Statement::KindOfStatementList)) {
      setFileLevel(dynamic_pointer_cast<StatementList>(stmt));
    }
  }
}
Exemple #17
0
void selectAll(ConnectionPtr & conn)
{
	StatementPtr stmt = conn->createStatement();
	ResultSetPtr res = stmt->executeQuery("select * from dpak");
	while(res->next())
	{
		int i;
		for(i=0; i< res->numColumns(); i++)
		{
			cerr << res->getString(i) << "|";
		}
		cerr << endl;
	}
}
Exemple #18
0
void StatementList::analyzeProgram(AnalysisResultPtr ar) {
  m_included = true;
  for (unsigned int i = 0; i < m_stmts.size(); i++) {
    StatementPtr stmt = m_stmts[i];

    // effect testing
    if (ar->getPhase() == AnalysisResult::AnalyzeAll) {
      if (!stmt->hasEffect() && !stmt->hasDecl() &&
          !stmt->is(Statement::KindOfStatementList)) {
        Compiler::Error(Compiler::StatementHasNoEffect, stmt);
      }
    }

    stmt->analyzeProgram(ar);
  }
}
std::shared_ptr<StatementList> CIRTreeLinearizatior::Linearize(StatementPtr statement) {
    collectStmList = false;
    statement->Accept(this);
    collectStmList = true;
    currSEQ->Accept(this);
    return currStmList;
}
Exemple #20
0
    CodeNodePtr findInterpolatable(StatementPtr stmt) {
        if (CodeNodePtr e = stmt->getExpression()) {
            if (CodeNodePtr f = findInterpolatable(e)) {
                return f;
            }
        }

        StatementList children = stmt->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            if (CodeNodePtr f = findInterpolatable(children[i])) {
                return f;
            }
        }

        return CodeNodePtr();        
    }
void	UpdateSpec::bind(StatementPtr& stmt) const {
	int	index = 0;
	UpdateSpec::const_iterator	i;
	for (i = begin(); i != end(); i++, index++) {
		stmt->bind(index, i->second);
	}
}
ExpressionPtr StatementList::getEffectiveImpl(AnalysisResultConstPtr 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 = CONSTANT("null");
      } else if (!e->isScalar()) {
        break;
      }
      return e;
    }
    if (m_stmts[i]->hasImpl()) break;
  }
  return ExpressionPtr();
}
Exemple #23
0
void deleteVal(ConnectionPtr & conn, int a)
{
	char col1_val[10];
	memset(col1_val, 0, 10);
	snprintf(col1_val, 10, "%li", a);

	string insert("delete from dpak where col1=");
	insert += col1_val;
	try
	{
		StatementPtr stmt = conn->createStatement();
		int rows = stmt->executeUpdate(insert.c_str());
		cerr << "Number of rows delete: " << rows << endl;
	}catch(BaseException & e){
		cerr << "BaseException: " << e.getMessage() << endl;
	}
}
Exemple #24
0
    static void doCountReferences(
        StatementPtr statement,
        ReferenceMap& refs,
        ReferencePath path
    ) {
        assert(statement);
        path.push_back(statement);

        if (CodeNodePtr e = statement->getExpression()) {
            countReferences(e, refs, path);
        }
        
        StatementList children = statement->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            doCountReferences(children[i], refs, path);
        }
    }
CodeGeneration::CCode CIRTreeCodeGenerator::Generate(StatementPtr ptr, const std::vector<Temp::CTempPtr>& args) {
    code.clear();
    code.emplace_back(new OPER("// define args operator", {}, args));
    isStartLabel = true;
    argsOnStack = &args;
    ptr->Accept(this);
    return std::move(code);
}
Exemple #26
0
    void replace(StatementPtr st, CodeNodePtr node, CodeNodePtr with) {
        assert(st);
        assert(node);
        assert(with);

        if (CodeNodePtr e = st->getExpression()) {
            if (e == node) {
                st->setExpression(with);
            } else {
                replace(e, node, with);
            }
        }

        StatementList children = st->getChildren();
        for (size_t i = 0; i < children.size(); ++i) {
            replace(children[i], node, with);
        }       
    }
Exemple #27
0
void updateVal(ConnectionPtr & conn, int a, const char* b)
{
	char col1_val[10];
	memset(col1_val, 0, 10);
	snprintf(col1_val, 10, "%li", a);

	string insert("update dpak set col2=");
	insert += string("'") + string(b) + string("'");
	insert += string("where col1=");
	insert += col1_val;
	try
	{
		StatementPtr stmt = conn->createStatement();
		int rows = stmt->executeUpdate(insert.c_str());
		cerr << "Number of rows updated: " << rows << endl;
	}catch(BaseException & e){
		cerr << "BaseException: " << e.getMessage() << endl;
	}
}
Exemple #28
0
void MethodStatement::inferFunctionTypes(AnalysisResultPtr ar) {
  IMPLEMENT_INFER_AND_CHECK_ASSERT(getFunctionScope());

  FunctionScopeRawPtr funcScope = getFunctionScope();
  bool pseudoMain = funcScope->inPseudoMain();

  if (m_stmt && funcScope->isFirstPass() && !funcScope->isGenerator()) {
    if (pseudoMain ||
        funcScope->getReturnType() ||
        m_stmt->hasRetExp()) {
      bool lastIsReturn = false;
      if (m_stmt->getCount()) {
        StatementPtr lastStmt = (*m_stmt)[m_stmt->getCount()-1];
        if (lastStmt->is(Statement::KindOfReturnStatement)) {
          lastIsReturn = true;
        }
      }
      if (!lastIsReturn) {
        ExpressionPtr constant =
          makeScalarExpression(ar, funcScope->inPseudoMain() ?
                               Variant(1) :
                               Variant(Variant::NullInit()));
        ReturnStatementPtr returnStmt =
          ReturnStatementPtr(
            new ReturnStatement(getScope(), getLocation(), constant));
        m_stmt->addElement(returnStmt);
      }
    }
  }

  if (m_params) {
    m_params->inferAndCheck(ar, Type::Any, false);
  }

  if (m_stmt) {
    m_stmt->inferTypes(ar);
  }

  if (funcScope->isGenerator()) {
    funcScope->setReturnType(ar,
      Type::GetType(Type::KindOfObject, "Continuation"));
  }
}
void UnaryOpExpression::analyzeProgram(AnalysisResultPtr ar) {
    if (ar->getPhase() == AnalysisResult::AnalyzeFinal && m_op == '@') {
        StatementPtr stmt = ar->getStatementForSilencer();
        ASSERT(stmt);
        m_silencer = stmt->requireSilencers(1);
    }
    if (ar->isFirstPass()) {
        ConstructPtr self = shared_from_this();
        if (m_op == T_INCLUDE || m_op == T_REQUIRE) {
            ar->getCodeError()->record(self, CodeError::UseInclude, self);
        }
    }
    if (m_exp) m_exp->analyzeProgram(ar);
    if (ar->getPhase() == AnalysisResult::AnalyzeFinal && m_op == '@') {
        StatementPtr stmt = ar->getStatementForSilencer();
        ASSERT(stmt);
        stmt->endRequireSilencers(m_silencer);
    }
}
Exemple #30
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();
  }
}