[Perf] Optimize injection
[hiphop-php.git] / src / compiler / expression / function_call.h
blob186fbc3462d7192fa425e30e00f275251d87bfb2
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010 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 +----------------------------------------------------------------------+
17 #ifndef __FUNCTION_CALL_H__
18 #define __FUNCTION_CALL_H__
20 #include <compiler/expression/static_class_name.h>
22 namespace HPHP {
23 ///////////////////////////////////////////////////////////////////////////////
25 DECLARE_BOOST_TYPES(ExpressionList);
26 DECLARE_BOOST_TYPES(FunctionScope);
27 DECLARE_BOOST_TYPES(FunctionCall);
29 class FunctionCall : public Expression, public StaticClassName {
30 public:
31 FunctionCall(EXPRESSION_CONSTRUCTOR_PARAMETERS, ExpressionPtr nameExp,
32 const std::string &name, ExpressionListPtr params,
33 ExpressionPtr classExp);
35 // overriding Expression::outputCPP to implement void wrapper
36 virtual void outputCPP(CodeGenerator &cg, AnalysisResultPtr ar);
37 virtual bool isRefable(bool checkError = false) const { return true;}
38 virtual bool isTemporary() const;
40 virtual ConstructPtr getNthKid(int n) const;
41 virtual void setNthKid(int n, ConstructPtr cp);
42 virtual int getKidCount() const;
44 virtual ExpressionPtr preOptimize(AnalysisResultPtr ar);
45 virtual ExpressionPtr postOptimize(AnalysisResultPtr ar);
47 void setAllowVoidReturn() { m_allowVoidReturn = true;}
48 void setFunctionAndClassScope(FunctionScopePtr fsp, ClassScopePtr csp);
49 bool preOutputCPP(CodeGenerator &cg, AnalysisResultPtr ar,
50 int state);
51 void deepCopy(FunctionCallPtr exp);
53 FunctionScopePtr getFuncScope() const { return m_funcScope; }
54 protected:
55 ExpressionPtr m_nameExp;
56 std::string m_name;
57 std::string m_origName;
58 int m_ciTemp;
59 int m_clsNameTemp;
60 ExpressionListPtr m_params;
62 // Pointers to the corresponding function scope and class scope for this
63 // function call, set during the AnalyzeAll phase. These pointers may be
64 // null if the function scope or class scope could not be resolved.
65 FunctionScopePtr m_funcScope;
66 ClassScopePtr m_classScope;
68 bool m_valid;
69 bool m_validClass;
70 int m_extraArg;
71 bool m_variableArgument;
72 bool m_voidReturn; // no return type
73 bool m_voidWrapper; // void wrapper is needed
74 bool m_allowVoidReturn;
75 bool m_redeclared;
76 bool m_redeclaredClass;
77 bool m_derivedFromRedeclaring;
78 bool m_noStatic;
80 // Extra arguments form an array, to which the scalar array optimization
81 // should also apply.
82 int m_argArrayId;
83 int m_argArrayHash;
84 int m_argArrayIndex;
85 void optimizeArgArray(AnalysisResultPtr ar);
87 void markRefParams(FunctionScopePtr func, const std::string &name,
88 bool canInvokeFewArgs);
90 /**
91 * Each program needs to reset this object's members to revalidate
92 * a function call.
94 void reset();
96 TypePtr checkParamsAndReturn(AnalysisResultPtr ar, TypePtr type,
97 bool coerce, FunctionScopePtr func,
98 bool arrayParams);
101 ///////////////////////////////////////////////////////////////////////////////
103 #endif // __FUNCTION_CALL_H__