make PHP_SAPI dynamic based on execution mode
[hiphop-php.git] / hphp / runtime / base / macros.h
blob2ed4dd897a74f85c13a0fc67d76b44298f12b491
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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 incl_HPHP_MACROS_H_
18 #define incl_HPHP_MACROS_H_
20 #include "hphp/util/assertions.h"
22 namespace HPHP {
24 ///////////////////////////////////////////////////////////////////////////////
25 // class macros
27 #define LITSTR_INIT(str) (true ? (str) : ("" str "")), (sizeof(str)-1)
29 #define FORWARD_DECLARE_CLASS(cls) \
30 class c_##cls; \
31 typedef SmartObject<c_##cls> p_##cls; \
33 #define FORWARD_DECLARE_CLASS_BUILTIN(cls) \
34 FORWARD_DECLARE_CLASS(cls) \
36 #define INVOKE_FEW_ARGS_COUNT 6
38 #define INVOKE_FEW_ARGS_DECL3 \
39 CVarRef a0 = null_variant, \
40 CVarRef a1 = null_variant, \
41 CVarRef a2 = null_variant
42 #define INVOKE_FEW_ARGS_DECL6 \
43 INVOKE_FEW_ARGS_DECL3, \
44 CVarRef a3 = null_variant, \
45 CVarRef a4 = null_variant, \
46 CVarRef a5 = null_variant
47 #define INVOKE_FEW_ARGS_DECL10 \
48 INVOKE_FEW_ARGS_DECL6, \
49 CVarRef a6 = null_variant, \
50 CVarRef a7 = null_variant, \
51 CVarRef a8 = null_variant, \
52 CVarRef a9 = null_variant
53 #define INVOKE_FEW_ARGS_IMPL3 \
54 CVarRef a0, CVarRef a1, CVarRef a2
55 #define INVOKE_FEW_ARGS_IMPL6 \
56 INVOKE_FEW_ARGS_IMPL3, CVarRef a3, CVarRef a4, \
57 CVarRef a5
58 #define INVOKE_FEW_ARGS_IMPL10 \
59 INVOKE_FEW_ARGS_IMPL6, CVarRef a6, CVarRef a7, \
60 CVarRef a8, CVarRef a9
62 #define INVOKE_FEW_ARGS_PASS3 a0, a1, a2
63 #define INVOKE_FEW_ARGS_PASS6 INVOKE_FEW_ARGS_PASS3, a3, a4, a5
64 #define INVOKE_FEW_ARGS_PASS10 INVOKE_FEW_ARGS_PASS6, a6, a7, a8, a9
66 #define INVOKE_FEW_ARGS_PASS_ARR3 args[0], args[1], args[2]
67 #define INVOKE_FEW_ARGS_PASS_ARR6 INVOKE_FEW_ARGS_PASS_ARR3, \
68 args[3], args[4], args[5]
69 #define INVOKE_FEW_ARGS_PASS_ARR10 INVOKE_FEW_ARGS_PASS_ARR6, \
70 args[6], args[7], args[8], args[9]
72 #define INVOKE_FEW_ARGS_HELPER(kind,num) kind##num
73 #define INVOKE_FEW_ARGS(kind,num) \
74 INVOKE_FEW_ARGS_HELPER(INVOKE_FEW_ARGS_##kind,num)
77 #define INVOKE_FEW_ARGS_DECL_ARGS INVOKE_FEW_ARGS(DECL,INVOKE_FEW_ARGS_COUNT)
78 #define INVOKE_FEW_ARGS_PASS_ARGS INVOKE_FEW_ARGS(PASS,INVOKE_FEW_ARGS_COUNT)
79 #define INVOKE_FEW_ARGS_PASS_ARR_ARGS \
80 INVOKE_FEW_ARGS(PASS_ARR,INVOKE_FEW_ARGS_COUNT)
81 #define INVOKE_FEW_ARGS_IMPL_ARGS INVOKE_FEW_ARGS(IMPL,INVOKE_FEW_ARGS_COUNT)
83 #define DECLARE_CLASS_COMMON_NO_SWEEP(cls, originalName) \
84 DECLARE_OBJECT_ALLOCATION_NO_SWEEP(c_##cls) \
85 public: \
86 static const char *GetClassName() { return #originalName; } \
87 static StaticString s_class_name; \
88 static HPHP::Class* s_cls; \
90 #define DECLARE_CLASS_COMMON_NO_ALLOCATION(cls, originalName) \
91 public: \
92 static void *ObjAllocatorInitSetup; \
93 static const char *GetClassName() { return #originalName; } \
94 static StaticString s_class_name; \
95 static HPHP::Class* s_cls; \
97 #define DECLARE_CLASS_COMMON(cls, originalName) \
98 DECLARE_OBJECT_ALLOCATION(c_##cls) \
99 public: \
100 static const char *GetClassName() { return #originalName; } \
101 static StaticString s_class_name; \
102 static HPHP::Class* s_cls; \
104 #define DECLARE_CLASS_NO_SWEEP(cls, originalName, parent) \
105 DECLARE_CLASS_COMMON_NO_SWEEP(cls, originalName) \
106 public: \
108 #define DECLARE_CLASS_NO_ALLOCATION(cls, originalName, parent) \
109 DECLARE_CLASS_COMMON_NO_ALLOCATION(cls, originalName) \
110 public: \
112 #define DECLARE_CLASS(cls, originalName, parent) \
113 DECLARE_CLASS_COMMON(cls, originalName) \
114 public: \
116 #define DECLARE_DYNAMIC_CLASS(cls, originalName, parent) \
117 DECLARE_CLASS_COMMON_NO_SWEEP(cls, originalName) \
118 public: \
120 #define IMPLEMENT_CLASS_COMMON(cls) \
121 StaticString c_##cls::s_class_name(c_##cls::GetClassName()); \
122 HPHP::Class* c_##cls::s_cls = nullptr; \
124 #define IMPLEMENT_CLASS(cls) \
125 IMPLEMENT_CLASS_COMMON(cls) \
126 IMPLEMENT_OBJECT_ALLOCATION(c_##cls) \
128 #define IMPLEMENT_CLASS_NO_DEFAULT_SWEEP(cls) \
129 IMPLEMENT_CLASS_COMMON(cls) \
130 IMPLEMENT_OBJECT_ALLOCATION_NO_DEFAULT_SWEEP(c_##cls) \
132 ///////////////////////////////////////////////////////////////////////////////
133 // global variable macros
135 #define GV(s) gvm_ ## s
137 ///////////////////////////////////////////////////////////////////////////////
138 // code instrumentation or injections
140 #define DECLARE_THREAD_INFO \
141 ThreadInfo *info ATTRIBUTE_UNUSED = \
142 ThreadInfo::s_threadInfo.getNoCheck(); \
143 int lc ATTRIBUTE_UNUSED = 0; \
145 #define CT_ASSERT_DESCENDENT_OF_OBJECTDATA(T) \
146 do { \
147 if (false) { \
148 ObjectData * dummy = nullptr; \
149 if (static_cast<T*>(dummy)) {} \
151 } while(0) \
153 //////////////////////////////////////////////////////////////////////////////
156 #endif // incl_HPHP_MACROS_H_