PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/base/runtime-error.h

http://github.com/facebook/hiphop-php
C Header | 287 lines | 180 code | 40 blank | 67 comment | 0 complexity | 274f641ab41ff5ed49e4f93ef0b534c1 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  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. +----------------------------------------------------------------------+
  15. */
  16. #ifndef incl_HPHP_RUNTIME_ERROR_H_
  17. #define incl_HPHP_RUNTIME_ERROR_H_
  18. #include <cstdarg>
  19. #include <string>
  20. #include "hphp/util/portability.h"
  21. #include "hphp/runtime/base/annot-type.h"
  22. #include "hphp/runtime/base/datatype.h"
  23. #ifdef ERROR
  24. #undef ERROR
  25. #endif
  26. #ifdef STRICT
  27. #undef STRICT
  28. #endif
  29. namespace HPHP {
  30. ///////////////////////////////////////////////////////////////////////////////
  31. struct Class;
  32. struct Func;
  33. struct ArrayData;
  34. struct StringData;
  35. struct TypeConstraint;
  36. enum class HackStrictOption;
  37. enum class ErrorMode {
  38. ERROR = 1,
  39. WARNING = 2,
  40. PARSE = 4, // not supported
  41. NOTICE = 8,
  42. CORE_ERROR = 16, // not supported
  43. CORE_WARNING = 32, // not supported
  44. COMPILE_ERROR = 64, // not supported
  45. COMPILE_WARNING = 128, // not supported
  46. USER_ERROR = 256,
  47. USER_WARNING = 512,
  48. USER_NOTICE = 1024,
  49. STRICT = 2048,
  50. RECOVERABLE_ERROR = 4096,
  51. PHP_DEPRECATED = 8192, // DEPRECATED conflicts with macro definitions
  52. USER_DEPRECATED = 16384,
  53. /*
  54. * PHP's fatal errors cannot be fed into error handler. HipHop can. We
  55. * still need "ERROR" bit, so old PHP error handler can see this error.
  56. * The extra 24th bit will help people who want to find out if it's
  57. * a fatal error only HipHop throws or not.
  58. */
  59. FATAL_ERROR = ERROR | (1 << 24), // 16777217
  60. PHP_ALL = ERROR | WARNING | PARSE | NOTICE | CORE_ERROR | CORE_WARNING |
  61. COMPILE_ERROR | COMPILE_WARNING | USER_ERROR | USER_WARNING |
  62. USER_NOTICE | RECOVERABLE_ERROR | PHP_DEPRECATED | USER_DEPRECATED,
  63. HPHP_ALL = PHP_ALL | FATAL_ERROR,
  64. /* Errors that can be upgraded to E_USER_ERROR. */
  65. UPGRADEABLE_ERROR = WARNING | USER_WARNING | NOTICE | USER_NOTICE
  66. };
  67. [[noreturn]] void raise_error(const std::string&);
  68. [[noreturn]] void raise_error(ATTRIBUTE_PRINTF_STRING const char*, ...)
  69. ATTRIBUTE_PRINTF(1, 2);
  70. [[noreturn]] void raise_error_without_first_frame(const std::string&);
  71. void raise_recoverable_error(const std::string &msg);
  72. void raise_recoverable_error(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
  73. ATTRIBUTE_PRINTF(1, 2);
  74. void raise_recoverable_error_without_first_frame(const std::string &msg);
  75. void raise_strict_warning(const std::string &msg);
  76. void raise_strict_warning(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
  77. ATTRIBUTE_PRINTF(1, 2);
  78. void raise_strict_warning_without_first_frame(const std::string &msg);
  79. void raise_warning(const std::string &msg);
  80. void raise_warning(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
  81. ATTRIBUTE_PRINTF(1, 2);
  82. void raise_warning_without_first_frame(const std::string &msg);
  83. void raise_notice(const std::string &msg);
  84. void raise_notice(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
  85. ATTRIBUTE_PRINTF(1, 2);
  86. void raise_notice_without_first_frame(const std::string &msg);
  87. void raise_deprecated(const std::string &msg);
  88. void raise_deprecated(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
  89. ATTRIBUTE_PRINTF(1, 2);
  90. void raise_deprecated_without_first_frame(const std::string &msg);
  91. void raise_warning_unsampled(const std::string &msg);
  92. void raise_warning_unsampled(ATTRIBUTE_PRINTF_STRING const char *fmt, ...)
  93. ATTRIBUTE_PRINTF(1, 2);
  94. void raise_message(ErrorMode mode, const char *fmt, va_list ap);
  95. void raise_message(ErrorMode mode,
  96. ATTRIBUTE_PRINTF_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3);
  97. void raise_message(ErrorMode mode, bool skipTop, const std::string& msg);
  98. std::string param_type_error_message(
  99. const char* func_name,
  100. int param_num,
  101. const char* expected_type,
  102. TypedValue actual_value);
  103. void raise_param_type_warning(
  104. const char* func_name,
  105. int param_num,
  106. const char* expected_type,
  107. TypedValue actual_value);
  108. void raise_hack_strict(HackStrictOption option, const char *ini_setting,
  109. const std::string& msg);
  110. void raise_hack_strict(HackStrictOption option, const char *ini_setting,
  111. const char *fmt, ...);
  112. /*
  113. * raise_typehint_error() is the same as raise_recoverable_error(), except
  114. * the error handler is not allowed to recover.
  115. * raise_reified_typehint_error flavor also takes a warn flag that demotes the
  116. * error to a warning for reified generics migrations purposes
  117. */
  118. void raise_typehint_error(const std::string& msg);
  119. void raise_reified_typehint_error(const std::string& msg, bool warn);
  120. /*
  121. * raise_return_typehint_error() is the same as raise_recoverable_error(),
  122. * except when compiled in RepoAuthoritative mode with CheckReturnTypeHints >= 3
  123. * the error handler is not allowed to recover.
  124. */
  125. void raise_return_typehint_error(const std::string& msg);
  126. /*
  127. * Raise the appropriate warning or error (with the given message) for some
  128. * violation of a property type-hint. If isSoft is true, than a warning is
  129. * always raised.
  130. */
  131. void raise_property_typehint_error(const std::string& msg, bool isSoft);
  132. /*
  133. * Raise the appropriate warning or error (with the given message) for some
  134. * violation of a record field type-hint. If isSoft is true, than a warning is
  135. * always raised.
  136. */
  137. void raise_record_field_typehint_error(const std::string& msg, bool isSoft);
  138. /*
  139. * Raise error if a record field is not inititialized after construction.
  140. */
  141. void raise_record_init_error(const StringData* recName,
  142. const StringData* fieldName);
  143. /*
  144. * Raise error if a record field is not declared.
  145. */
  146. [[noreturn]] void raise_record_field_error(const StringData* recName,
  147. const StringData* fieldName);
  148. /*
  149. * Raise the appropriate warning or error if we try to unset a property, and
  150. * that property has a type-hint which we're enforcing.
  151. */
  152. void raise_property_typehint_unset_error(const Class* declCls,
  153. const StringData* propName,
  154. bool isSoft);
  155. void raise_resolve_undefined(const StringData* name, const Class* c = nullptr);
  156. [[noreturn]] void raise_call_to_undefined(const StringData* name,
  157. const Class* c = nullptr);
  158. void raise_convert_object_to_string(const char* cls_name);
  159. void raise_convert_record_to_type(const char* typeName);
  160. void raise_recordarray_promotion_notice(const std::string& op);
  161. void raise_recordarray_unsupported_op_notice(const std::string& op);
  162. ///////////////////////////////////////////////////////////////////////////////
  163. /*
  164. * Hack arrays compat notices.
  165. */
  166. void raise_hack_arr_compat_serialize_notice(const ArrayData*);
  167. void raise_hack_arr_compat_array_producing_func_notice(const std::string& name);
  168. void raise_hackarr_compat_type_hint_param_notice(const Func* func,
  169. const ArrayData* ad,
  170. const char* name,
  171. int param);
  172. void raise_hackarr_compat_type_hint_ret_notice(const Func* func,
  173. const ArrayData* ad,
  174. const char* name);
  175. void raise_hackarr_compat_type_hint_outparam_notice(const Func* func,
  176. const ArrayData* ad,
  177. const char* name,
  178. int param);
  179. void raise_hackarr_compat_type_hint_property_notice(const Class* declCls,
  180. const ArrayData* ad,
  181. const char* name,
  182. const StringData* propName,
  183. bool isStatic);
  184. void raise_hackarr_compat_type_hint_rec_field_notice(
  185. const StringData* recName,
  186. const ArrayData* ad,
  187. const char* name,
  188. const StringData* fieldName);
  189. void raise_hackarr_compat_is_operator(const char* source, const char* target);
  190. void raise_hackarr_compat_notice(const std::string& msg);
  191. enum class SerializationSite {
  192. IsDict,
  193. IsVec,
  194. IsTuple,
  195. IsShape,
  196. IsArray,
  197. IsVArray,
  198. IsDArray,
  199. FBSerialize,
  200. FBCompactSerialize,
  201. Gettype,
  202. Serialize,
  203. VarExport,
  204. PrintR,
  205. JsonEncode,
  206. Count
  207. };
  208. void raise_array_serialization_notice(SerializationSite src,
  209. const ArrayData* arr);
  210. [[noreturn]] void raise_use_of_specialized_array();
  211. #define HC(Opt, opt) void raise_hac_##opt##_notice(const std::string& msg);
  212. HAC_CHECK_OPTS
  213. #undef HC
  214. /*
  215. * RAII mechanism to temporarily suppress a specific Hack array compat notice
  216. * within a scope.
  217. */
  218. #define HC(Opt, ...) \
  219. struct SuppressHAC##Opt##Notices { \
  220. SuppressHAC##Opt##Notices(); \
  221. ~SuppressHAC##Opt##Notices(); \
  222. SuppressHAC##Opt##Notices(const SuppressHAC##Opt##Notices&) = delete; \
  223. SuppressHAC##Opt##Notices(SuppressHAC##Opt##Notices&&) = delete; \
  224. SuppressHAC##Opt##Notices& \
  225. operator=(const SuppressHAC##Opt##Notices&) = delete; \
  226. SuppressHAC##Opt##Notices& \
  227. operator=(SuppressHAC##Opt##Notices&&) = delete; \
  228. private: \
  229. bool old; \
  230. };
  231. HAC_CHECK_OPTS
  232. #undef HC
  233. ///////////////////////////////////////////////////////////////////////////////
  234. void raise_str_to_class_notice(const StringData* name);
  235. /*
  236. * class_meth compact notices.
  237. */
  238. void raise_clsmeth_compat_type_hint(
  239. const Func* func, const std::string& displayName, folly::Optional<int> param);
  240. void raise_clsmeth_compat_type_hint_outparam_notice(
  241. const Func* func, const std::string& displayName, int paramNum);
  242. void raise_clsmeth_compat_type_hint_property_notice(
  243. const Class* declCls, const StringData* propName,
  244. const std::string& displayName, bool isStatic);
  245. ///////////////////////////////////////////////////////////////////////////////
  246. }
  247. #endif // incl_HPHP_RUNTIME_ERROR_H_