Make comparison IR ops layout agnostic
[hiphop-php.git] / hphp / runtime / base / runtime-error.h
blob72c9996a10252e4c49b589153743bfb47ba63873
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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_RUNTIME_ERROR_H_
18 #define incl_HPHP_RUNTIME_ERROR_H_
20 #include <cstdarg>
21 #include <string>
23 #include "hphp/util/portability.h"
24 #include "hphp/runtime/base/datatype.h"
25 #include "hphp/runtime/base/ham-runtime-option.h"
27 #ifdef ERROR
28 #undef ERROR
29 #endif
31 #ifdef STRICT
32 #undef STRICT
33 #endif
35 namespace HPHP {
37 ///////////////////////////////////////////////////////////////////////////////
39 struct Class;
40 struct Func;
41 struct ArrayData;
42 struct StringData;
43 struct TypeConstraint;
44 struct TypedValue;
46 enum class HackStrictOption;
48 enum class ErrorMode {
49 ERROR = 1,
50 WARNING = 2,
51 PARSE = 4, // not supported
52 NOTICE = 8,
53 CORE_ERROR = 16, // not supported
54 CORE_WARNING = 32, // not supported
55 COMPILE_ERROR = 64, // not supported
56 COMPILE_WARNING = 128, // not supported
57 USER_ERROR = 256,
58 USER_WARNING = 512,
59 USER_NOTICE = 1024,
60 STRICT = 2048,
61 RECOVERABLE_ERROR = 4096,
62 PHP_DEPRECATED = 8192, // DEPRECATED conflicts with macro definitions
63 USER_DEPRECATED = 16384,
66 * PHP's fatal errors cannot be fed into error handler. HipHop can. We
67 * still need "ERROR" bit, so old PHP error handler can see this error.
68 * The extra 24th bit will help people who want to find out if it's
69 * a fatal error only HipHop throws or not.
71 FATAL_ERROR = ERROR | (1 << 24), // 16777217
73 PHP_ALL = ERROR | WARNING | PARSE | NOTICE | CORE_ERROR | CORE_WARNING |
74 COMPILE_ERROR | COMPILE_WARNING | USER_ERROR | USER_WARNING |
75 USER_NOTICE | RECOVERABLE_ERROR | PHP_DEPRECATED | USER_DEPRECATED,
77 HPHP_ALL = PHP_ALL | FATAL_ERROR,
79 /* Errors that can be upgraded to E_USER_ERROR. */
80 UPGRADEABLE_ERROR = WARNING | USER_WARNING | NOTICE | USER_NOTICE
83 [[noreturn]] void raise_error(const std::string&);
84 [[noreturn]] void raise_error(ATTRIBUTE_PRINTF_STRING const char*, ...)
85 ATTRIBUTE_PRINTF(1, 2);
86 [[noreturn]] void raise_error_without_first_frame(const std::string&);
87 void raise_recoverable_error(const std::string &msg);
88 void raise_recoverable_error(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
89 ATTRIBUTE_PRINTF(1, 2);
90 void raise_recoverable_error_without_first_frame(const std::string &msg);
91 void raise_strict_warning(const std::string &msg);
92 void raise_strict_warning(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
93 ATTRIBUTE_PRINTF(1, 2);
94 void raise_strict_warning_without_first_frame(const std::string &msg);
95 void raise_warning(const std::string &msg);
96 void raise_warning(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
97 ATTRIBUTE_PRINTF(1, 2);
98 void raise_warning_without_first_frame(const std::string &msg);
99 void raise_notice(const std::string &msg);
100 void raise_notice(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
101 ATTRIBUTE_PRINTF(1, 2);
102 void raise_notice_without_first_frame(const std::string &msg);
103 void raise_deprecated(const std::string &msg);
104 void raise_deprecated(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
105 ATTRIBUTE_PRINTF(1, 2);
106 void raise_deprecated_without_first_frame(const std::string &msg);
107 void raise_warning_unsampled(const std::string &msg);
108 void raise_warning_unsampled(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
109 ATTRIBUTE_PRINTF(1, 2);
110 void raise_message(ErrorMode mode, const char *fmt, va_list ap);
111 void raise_message(ErrorMode mode,
112 ATTRIBUTE_PRINTF_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
113 void raise_message(ErrorMode mode, bool skipTop, const std::string& msg);
114 std::string param_type_error_message(
115 const char* func_name,
116 int param_num,
117 const char* expected_type,
118 TypedValue actual_value);
119 void raise_param_type_warning(
120 const char* func_name,
121 int param_num,
122 const char* expected_type,
123 TypedValue actual_value);
124 void raise_hack_strict(HackStrictOption option, const char *ini_setting,
125 const std::string& msg);
126 void raise_hack_strict(HackStrictOption option, const char *ini_setting,
127 const char *fmt, ...);
130 * raise_typehint_error() is the same as raise_recoverable_error(), except
131 * the error handler is not allowed to recover.
132 * raise_reified_typehint_error flavor also takes a warn flag that demotes the
133 * error to a warning for reified generics migrations purposes
135 void raise_typehint_error(const std::string& msg);
136 void raise_reified_typehint_error(const std::string& msg, bool warn);
139 * raise_return_typehint_error() is the same as raise_recoverable_error(),
140 * except the error handler is not allowed to recover.
142 void raise_return_typehint_error(const std::string& msg);
145 * Raise the appropriate warning or error (with the given message) for some
146 * violation of a property type-hint. If isSoft is true, than a warning is
147 * always raised.
149 void raise_property_typehint_error(const std::string& msg,
150 bool isSoft, bool isUB);
153 * Raise the appropriate warning or error (with the given message) for some
154 * violation of a record field type-hint. If isSoft is true, than a warning is
155 * always raised.
157 void raise_record_field_typehint_error(const std::string& msg, bool isSoft);
160 * Raise error if a record field is not inititialized after construction.
162 void raise_record_init_error(const StringData* recName,
163 const StringData* fieldName);
166 * Raise error if a record field is not declared.
168 [[noreturn]] void raise_record_field_error(const StringData* recName,
169 const StringData* fieldName);
172 * Raise the appropriate warning or error if we try to unset a property, and
173 * that property has a type-hint which we're enforcing.
175 void raise_property_typehint_unset_error(const Class* declCls,
176 const StringData* propName,
177 bool isSoft, bool isUB);
179 void raise_resolve_undefined(const StringData* name, const Class* c = nullptr);
180 [[noreturn]] void raise_call_to_undefined(const StringData* name,
181 const Class* c = nullptr);
183 void raise_convert_object_to_string(const char* cls_name);
184 void raise_convert_record_to_type(const char* typeName);
185 void raise_convert_rfunc_to_type(const char* typeName);
186 void raise_convert_rcls_meth_to_type(const char* typeName);
188 ///////////////////////////////////////////////////////////////////////////////
190 * Hack arrays compat notices.
193 void raise_hack_arr_compat_serialize_notice(const ArrayData*);
195 void raise_hack_arr_compat_array_producing_func_notice(const std::string& name);
197 void raise_hackarr_compat_is_operator(const char* source, const char* target);
199 void raise_hackarr_compat_notice(const std::string& msg);
202 enum class SerializationSite {
203 IsDict,
204 IsVec,
205 IsTuple,
206 IsShape,
207 IsArray,
208 FBSerialize,
209 FBCompactSerialize,
210 Gettype,
211 Serialize,
212 VarExport,
213 PrintR,
214 JsonEncode,
215 Count
218 void raise_array_serialization_notice(SerializationSite src,
219 const ArrayData* arr);
221 [[noreturn]] void raise_use_of_specialized_array();
223 #define HC(Opt, opt) void raise_hac_##opt##_notice(const std::string& msg);
224 HAC_CHECK_OPTS
225 #undef HC
228 * RAII mechanism to temporarily suppress a specific Hack array compat notice
229 * within a scope.
231 #define HC(Opt, ...) \
232 struct SuppressHAC##Opt##Notices { \
233 SuppressHAC##Opt##Notices(); \
234 ~SuppressHAC##Opt##Notices(); \
235 SuppressHAC##Opt##Notices(const SuppressHAC##Opt##Notices&) = delete; \
236 SuppressHAC##Opt##Notices(SuppressHAC##Opt##Notices&&) = delete; \
237 SuppressHAC##Opt##Notices& \
238 operator=(const SuppressHAC##Opt##Notices&) = delete; \
239 SuppressHAC##Opt##Notices& \
240 operator=(SuppressHAC##Opt##Notices&&) = delete; \
241 private: \
242 bool old; \
244 HAC_CHECK_OPTS
245 #undef HC
247 ///////////////////////////////////////////////////////////////////////////////
249 void raise_str_to_class_notice(const StringData* name);
252 * class_meth compact notices.
254 void raise_clsmeth_compat_type_hint(
255 const Func* func, const std::string& displayName, folly::Optional<int> param);
256 void raise_clsmeth_compat_type_hint_outparam_notice(
257 const Func* func, const std::string& displayName, int paramNum);
258 void raise_clsmeth_compat_type_hint_property_notice(
259 const Class* declCls, const StringData* propName,
260 const std::string& displayName, bool isStatic);
262 ///////////////////////////////////////////////////////////////////////////////
265 #endif // incl_HPHP_RUNTIME_ERROR_H_