PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/compiler/expression/simple_function_call.h

https://gitlab.com/Blueprint-Marketing/hhvm
C Header | 165 lines | 120 code | 24 blank | 21 comment | 4 complexity | d4b0bf2a4e83088ed4c8964b65515f5f MD5 | raw file
  1. /*
  2. +----------------------------------------------------------------------+
  3. | HipHop for PHP |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. */
  16. #ifndef incl_HPHP_SIMPLE_FUNCTION_CALL_H_
  17. #define incl_HPHP_SIMPLE_FUNCTION_CALL_H_
  18. #include "hphp/compiler/expression/function_call.h"
  19. #include <map>
  20. #include "hphp/compiler/analysis/variable_table.h"
  21. namespace HPHP {
  22. ///////////////////////////////////////////////////////////////////////////////
  23. DECLARE_BOOST_TYPES(SimpleFunctionCall);
  24. struct SimpleFunctionCall final : FunctionCall {
  25. static void InitFunctionTypeMap();
  26. public:
  27. SimpleFunctionCall(EXPRESSION_CONSTRUCTOR_PARAMETERS,
  28. const std::string &name, bool hadBackslash,
  29. ExpressionListPtr params, ExpressionPtr cls);
  30. DECLARE_BASE_EXPRESSION_VIRTUAL_FUNCTIONS;
  31. ExpressionPtr preOptimize(AnalysisResultConstPtr ar);
  32. void deepCopy(SimpleFunctionCallPtr exp);
  33. bool isDefineWithoutImpl(AnalysisResultConstPtr ar);
  34. void setValid() { m_valid = true; }
  35. void setThrowFatal() { m_type = FunType::ThrowFatal; }
  36. void setThrowParseFatal() { m_type = FunType::ThrowParseFatal; }
  37. bool isParseFatalFunction() const {
  38. return m_type == FunType::ThrowParseFatal;
  39. }
  40. bool isFatalFunction() const {
  41. return isParseFatalFunction() || m_type == FunType::ThrowFatal;
  42. }
  43. int isStaticCompact() const { return m_type == FunType::StaticCompact; }
  44. // define(<literal-string>, <scalar>);
  45. bool isSimpleDefine(StringData **name, TypedValue *value) const;
  46. virtual int getLocalEffects() const;
  47. // implementing IParseHandler
  48. virtual void onParse(AnalysisResultConstPtr ar, FileScopePtr fs);
  49. virtual void beforeCheck(AnalysisResultPtr ar) {}
  50. void addLateDependencies(AnalysisResultConstPtr ar);
  51. void setSafeCall(int flag) { m_safe = flag; }
  52. void setSafeDefault(ExpressionPtr def) { m_safeDef = def; }
  53. virtual ConstructPtr getNthKid(int n) const;
  54. virtual void setNthKid(int n, ConstructPtr cp);
  55. static SimpleFunctionCallPtr GetFunctionCallForCallUserFunc(
  56. AnalysisResultConstPtr ar, SimpleFunctionCallPtr call, int testOnly,
  57. int firstParam, bool &error);
  58. void setupScopes(AnalysisResultConstPtr ar);
  59. bool readsLocals() const;
  60. bool writesLocals() const;
  61. void updateVtFlags();
  62. void setLocalThis(const std::string &name) { m_localThis = name; }
  63. bool isCallToFunction(const char *name) const;
  64. void resolveNSFallbackFunc(AnalysisResultConstPtr ar, FileScopePtr fs);
  65. void setOptimizable() {
  66. m_optimizable = true;
  67. }
  68. bool isOptimizable() const {
  69. return m_optimizable;
  70. }
  71. void changeToBytecode() {
  72. m_changedToBytecode = true;
  73. }
  74. bool hasBeenChangedToBytecode() {
  75. return m_changedToBytecode;
  76. }
  77. protected:
  78. enum class FunType {
  79. Unknown,
  80. Define,
  81. Create,
  82. VariableArgument,
  83. Extract,
  84. Assert,
  85. Compact,
  86. StaticCompact, // compact() with statically known variable names
  87. ShellExec,
  88. Constant,
  89. Defined,
  90. FunctionExists,
  91. ClassExists,
  92. InterfaceExists,
  93. Unserialize,
  94. GetDefinedVars,
  95. FBCallUserFuncSafe,
  96. ThrowFatal,
  97. ThrowParseFatal,
  98. ClassAlias,
  99. };
  100. static std::map<std::string,FunType> FunctionTypeMap;
  101. FunType m_type;
  102. unsigned m_dynamicConstant : 1;
  103. unsigned m_builtinFunction : 1;
  104. unsigned m_dynamicInvoke : 1;
  105. unsigned m_transformed : 1;
  106. unsigned m_changedToBytecode : 1; // true if it morphed into a bytecode
  107. unsigned m_optimizable : 1; // true if it can be morphed into a bytecode
  108. int m_safe;
  109. ExpressionPtr m_safeDef;
  110. std::string m_lambda;
  111. ExpressionPtr optimize(AnalysisResultConstPtr ar);
  112. private:
  113. int checkObjCall(AnalysisResultPtr ar);
  114. FunctionScopePtr
  115. getFuncScopeFromParams(AnalysisResultPtr ar,
  116. BlockScopeRawPtr scope,
  117. ExpressionPtr clsName,
  118. ExpressionPtr funcName,
  119. ClassScopePtr &clsScope);
  120. std::string getThisString(bool withArrow);
  121. void mungeIfSpecialFunction(AnalysisResultConstPtr ar, FileScopePtr fs);
  122. std::string m_localThis;
  123. };
  124. SimpleFunctionCallPtr NewSimpleFunctionCall(
  125. EXPRESSION_CONSTRUCTOR_PARAMETERS,
  126. const std::string &name, bool hadBackslash, ExpressionListPtr params,
  127. ExpressionPtr cls);
  128. ///////////////////////////////////////////////////////////////////////////////
  129. // hphp_opt functions
  130. ExpressionPtr hphp_opt_fb_call_user_func(CodeGenerator *cg,
  131. AnalysisResultConstPtr ar,
  132. SimpleFunctionCallPtr call, int mode);
  133. ExpressionPtr hphp_opt_is_callable(CodeGenerator *cg,
  134. AnalysisResultConstPtr ar,
  135. SimpleFunctionCallPtr call, int mode);
  136. ExpressionPtr hphp_opt_call_user_func(CodeGenerator *cg,
  137. AnalysisResultConstPtr ar,
  138. SimpleFunctionCallPtr call, int mode);
  139. ///////////////////////////////////////////////////////////////////////////////
  140. } // HPHP
  141. #endif // incl_HPHP_SIMPLE_FUNCTION_CALL_H_