2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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_SYSTEMLIB_H_
18 #define incl_HPHP_SYSTEMLIB_H_
20 #include "hphp/runtime/base/types.h"
21 #include "hphp/runtime/base/type-string.h"
22 #include "hphp/runtime/base/tv-variant.h"
23 #include "hphp/util/portability.h"
36 namespace HPHP::SystemLib
{
37 ///////////////////////////////////////////////////////////////////////////////
39 #define SYSTEMLIB_CLASSES(x) \
42 x(BadMethodCallException,,) \
43 x(InvalidArgumentException,,) \
44 x(TypeAssertionException,,) \
45 x(RuntimeException,,) \
46 x(OutOfBoundsException,,) \
47 x(InvalidOperationException,,) \
48 x(pinitSentinel,, __) \
53 x(DateTimeInterface,,) \
54 x(DateTimeImmutable,,) \
63 x(DirectoryIterator,,) \
64 x(IteratorAggregate,,) \
66 x(LazyKVZipIterable,,) \
67 x(LazyIterableView,,) \
68 x(LazyKeyedIterableView,,) \
70 x(__PHP_Incomplete_Class,,) \
71 x(DivisionByZeroException,,) \
72 x(InvalidForeachArgumentException,,) \
73 x(UndefinedPropertyException,,) \
74 x(UndefinedVariableException,,) \
75 x(TypecastException,,) \
76 x(ReadonlyViolationException,,) \
77 x(CoeffectViolationException,,) \
78 x(ModuleBoundaryViolationException,,) \
79 x(DeploymentBoundaryViolationException,,) \
81 x(BaseException,, \\__SystemLib\\) \
83 x(ArithmeticError,,) \
84 x(ArgumentCountError,,) \
86 x(DivisionByZeroError,,) \
89 x(MethCallerHelper,, \\__SystemLib\\) \
90 x(DynMethCallerHelper,, \\__SystemLib\\) \
91 x(Traversable, HH_, HH\\) \
92 x(Iterator, HH_, HH\\) \
95 extern bool s_anyNonPersistentBuiltins
;
96 extern std::string s_source
;
98 extern Func
* s_nullFunc
;
99 extern Func
* s_nullCtor
;
101 #define DECLARE_SYSTEMLIB_CLASS(cls, prefix, ...) \
102 Class* get ## prefix ## cls ## Class();
103 SYSTEMLIB_CLASSES(DECLARE_SYSTEMLIB_CLASS
)
104 #undef DECLARE_SYSTEMLIB_CLASS
106 Object
AllocStdClassObject();
107 Object
AllocPinitSentinel();
108 Object
AllocExceptionObject(const Variant
& message
);
109 Object
AllocErrorObject(const Variant
& message
);
110 Object
AllocArithmeticErrorObject(const Variant
& message
);
111 Object
AllocArgumentCountErrorObject(const Variant
& message
);
112 Object
AllocDivisionByZeroErrorObject(const Variant
& message
);
113 Object
AllocParseErrorObject(const Variant
& message
);
114 Object
AllocTypeErrorObject(const Variant
& message
);
115 Object
AllocBadMethodCallExceptionObject(const Variant
& message
);
116 Object
AllocInvalidArgumentExceptionObject(const Variant
& message
);
117 Object
AllocTypeAssertionExceptionObject(const Variant
& message
);
118 Object
AllocRuntimeExceptionObject(const Variant
& message
);
119 Object
AllocOutOfBoundsExceptionObject(const Variant
& message
);
120 Object
AllocInvalidOperationExceptionObject(const Variant
& message
);
121 Object
AllocDOMExceptionObject(const Variant
& message
);
122 Object
AllocDivisionByZeroExceptionObject();
123 Object
AllocDirectoryObject();
124 Object
AllocPDOExceptionObject();
125 Object
AllocSoapFaultObject(const Variant
& code
,
126 const Variant
& message
,
127 const Variant
& actor
= uninit_variant
,
128 const Variant
& detail
= uninit_variant
,
129 const Variant
& name
= uninit_variant
,
130 const Variant
& header
= uninit_variant
);
131 Object
AllocLazyKVZipIterableObject(const Variant
& mp
);
133 Object
AllocLazyIterableViewObject(const Variant
& iterable
);
134 Object
AllocLazyKeyedIterableViewObject(const Variant
& iterable
);
136 [[noreturn
]] void throwExceptionObject(const Variant
& message
);
137 [[noreturn
]] void throwErrorObject(const Variant
& message
);
138 [[noreturn
]] void throwArithmeticErrorObject(const Variant
& message
);
139 [[noreturn
]] void throwArgumentCountErrorObject(const Variant
& message
);
140 [[noreturn
]] void throwDivisionByZeroErrorObject(const Variant
& message
);
141 [[noreturn
]] void throwParseErrorObject(const Variant
& message
);
142 [[noreturn
]] void throwTypeErrorObject(const Variant
& message
);
144 void throwBadMethodCallExceptionObject(const Variant
& message
);
146 void throwInvalidArgumentExceptionObject(const Variant
& message
);
147 [[noreturn
]] void throwTypeAssertionExceptionObject(const Variant
& message
);
148 [[noreturn
]] void throwRuntimeExceptionObject(const Variant
& message
);
149 [[noreturn
]] void throwOutOfBoundsExceptionObject(const Variant
& message
);
151 void throwInvalidOperationExceptionObject(const Variant
& message
);
153 void throwDOMExceptionObject(const Variant
& message
);
154 [[noreturn
]] void throwDivisionByZeroExceptionObject();
156 void throwSoapFaultObject(const Variant
& code
,
157 const Variant
& message
,
158 const Variant
& actor
= uninit_variant
,
159 const Variant
& detail
= uninit_variant
,
160 const Variant
& name
= uninit_variant
,
161 const Variant
& header
= uninit_variant
);
162 [[noreturn
]] void throwInvalidForeachArgumentExceptionObject();
163 [[noreturn
]] void throwUndefinedPropertyExceptionObject(const Variant
& message
);
164 [[noreturn
]] void throwUndefinedVariableExceptionObject(const Variant
& message
);
165 [[noreturn
]] void throwTypecastExceptionObject(const Variant
& message
);
166 [[noreturn
]] void throwReadonlyViolationExceptionObject(const Variant
& message
);
167 [[noreturn
]] void throwCoeffectViolationExceptionObject(const Variant
& message
);
168 [[noreturn
]] void throwModuleBoundaryViolationExceptionObject(const Variant
& message
);
169 [[noreturn
]] void throwDeploymentBoundaryViolationExceptionObject(const Variant
& message
);
172 * Register a persistent unit to be re-merged (in non-repo mode)
174 void addPersistentUnit(Unit
* unit
);
177 * Re-merge all persistent units
179 void mergePersistentUnits();
182 * Setup the shared null constructor.
184 void setupNullCtor(Class
* cls
);
187 * Return a fresh 86reifiedinit method.
189 Func
* getNull86reifiedinit(Class
* cls
);
191 Func
* funcLoad(const StringData
* name
, Func
*& cache
);
192 Class
* classLoad(const StringData
* name
, Class
*& cache
);
194 ///////////////////////////////////////////////////////////////////////////////
197 * Keep a list of unit-emitters for systemlib units. Used by HPHPc so
198 * it can put the unit-emitters into the repo.
200 void keepRegisteredUnitEmitters(bool);
202 void registerUnitEmitter(std::unique_ptr
<UnitEmitter
>);
204 std::vector
<std::unique_ptr
<UnitEmitter
>> claimRegisteredUnitEmitters();
206 ///////////////////////////////////////////////////////////////////////////////
209 struct StringLiteral
{
210 /* implicit */ constexpr StringLiteral(const char (&str
)[N
]) {
211 std::copy_n(str
, N
, value
);
216 template<StringLiteral NAME
>
218 static Class
* classof() {
219 static Class
* cls
= nullptr;
220 return SystemLib::classLoad(className().get(), cls
);
223 static const StaticString
& className() {
224 static const StaticString
name(NAME
.value
);
229 ///////////////////////////////////////////////////////////////////////////////
230 } // namespace HPHP::SystemLib