void IncludeExpression::analyzeInclude(AnalysisResultPtr ar, const std::string &include) { ASSERT(ar->getPhase() == AnalysisResult::AnalyzeInclude); ConstructPtr self = shared_from_this(); FileScopePtr file = ar->findFileScope(include, true); if (!file) { ar->getCodeError()->record(self, CodeError::PHPIncludeFileNotFound, self); return; } if (include.find("compiler/") != 0 || include.find("/compiler/") == string::npos) { ar->getCodeError()->record(self, CodeError::PHPIncludeFileNotInLib, self, ConstructPtr(), include.c_str()); } if (!isFileLevel()) { // Not unsupported but potentially bad ar->getCodeError()->record(self, CodeError::UseDynamicInclude, self); } ar->getDependencyGraph()->add (DependencyGraph::KindOfProgramMaxInclude, ar->getName(), file->getName(), StatementPtr()); ar->getDependencyGraph()->addParent (DependencyGraph::KindOfProgramMinInclude, ar->getName(), file->getName(), StatementPtr()); FunctionScopePtr func = ar->getFunctionScope(); ar->getFileScope()->addIncludeDependency(ar, m_include, func && func->isInlined()); }
void IncludeExpression::analyzeInclude(AnalysisResultPtr ar, const std::string &include) { ConstructPtr self = shared_from_this(); FileScopePtr file = ar->findFileScope(include); if (!file && !include.empty()) { Compiler::Error(Compiler::PHPIncludeFileNotFound, self); return; } FunctionScopePtr func = getFunctionScope(); getFileScope()->addIncludeDependency(ar, m_include, func && func->isInlined()); if (func && file->getPseudoMain()) { file->getPseudoMain()->addUse(func, BlockScope::UseKindInclude); } }
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(); }
void IncludeExpression::outputCPPImpl(CodeGenerator &cg, AnalysisResultPtr ar) { bool linemap = outputLineMap(cg, ar, true); // Includes aren't really supported in system mode if (cg.getOutput() == CodeGenerator::SystemCPP) { cg_printf("true"); if (linemap) cg_printf(")"); return; } const char *vars = m_privateScope ? "lvar_ptr(LVariableTable())" : "variables"; bool require = (m_op == T_REQUIRE || m_op == T_REQUIRE_ONCE); bool once = (m_op == T_INCLUDE_ONCE || m_op == T_REQUIRE_ONCE); if (!getCurrentInclude(ar).empty()) { FileScopePtr fs = ar->findFileScope(getCurrentInclude(ar), false); if (fs) { cg_printf("%s%s(%s, %s)", Option::PseudoMainPrefix, fs->pseudoMainName().c_str(), once ? "true" : "false", vars); if (linemap) cg_printf(")"); return; } } // include() and require() need containing file's directory string currentDir = "NULL"; if (m_loc && m_loc->file && *m_loc->file) { string file = m_loc->file; size_t pos = file.rfind('/'); if (pos != string::npos) { currentDir = '"'; currentDir += file.substr(0, pos + 1); currentDir += '"'; } } // fallback to dynamic include cg_printf("%s(", require ? "require" : "include"); m_exp->outputCPP(cg, ar); cg_printf(", %s, %s, %s)", once ? "true" : "false", vars, currentDir.c_str()); if (linemap) cg_printf(")"); }
ExpressionPtr IncludeExpression::postOptimize(AnalysisResultPtr ar) { if (!m_include.empty()) { if (!m_depsSet) { analyzeInclude(ar, m_include); m_depsSet = true; } FileScopePtr fs = ar->findFileScope(m_include); if (fs) { if (!Option::KeepStatementsWithNoEffect) { if (ExpressionPtr rep = fs->getEffectiveImpl(ar)) { recomputeEffects(); return replaceValue(rep->clone()); } } m_exp.reset(); } } return ExpressionPtr(); }