11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_REGEXP_REGEXP_ERROR_H_
61cb0ef41Sopenharmony_ci#define V8_REGEXP_REGEXP_ERROR_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/base/logging.h"
91cb0ef41Sopenharmony_ci#include "src/base/macros.h"
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cinamespace v8 {
121cb0ef41Sopenharmony_cinamespace internal {
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci#define REGEXP_ERROR_MESSAGES(T)                                          \
151cb0ef41Sopenharmony_ci  T(None, "")                                                             \
161cb0ef41Sopenharmony_ci  T(StackOverflow, "Maximum call stack size exceeded")                    \
171cb0ef41Sopenharmony_ci  T(AnalysisStackOverflow, "Stack overflow")                              \
181cb0ef41Sopenharmony_ci  T(TooLarge, "Regular expression too large")                             \
191cb0ef41Sopenharmony_ci  T(UnterminatedGroup, "Unterminated group")                              \
201cb0ef41Sopenharmony_ci  T(UnmatchedParen, "Unmatched ')'")                                      \
211cb0ef41Sopenharmony_ci  T(EscapeAtEndOfPattern, "\\ at end of pattern")                         \
221cb0ef41Sopenharmony_ci  T(InvalidPropertyName, "Invalid property name")                         \
231cb0ef41Sopenharmony_ci  T(InvalidEscape, "Invalid escape")                                      \
241cb0ef41Sopenharmony_ci  T(InvalidDecimalEscape, "Invalid decimal escape")                       \
251cb0ef41Sopenharmony_ci  T(InvalidUnicodeEscape, "Invalid Unicode escape")                       \
261cb0ef41Sopenharmony_ci  T(NothingToRepeat, "Nothing to repeat")                                 \
271cb0ef41Sopenharmony_ci  T(LoneQuantifierBrackets, "Lone quantifier brackets")                   \
281cb0ef41Sopenharmony_ci  T(RangeOutOfOrder, "numbers out of order in {} quantifier")             \
291cb0ef41Sopenharmony_ci  T(IncompleteQuantifier, "Incomplete quantifier")                        \
301cb0ef41Sopenharmony_ci  T(InvalidQuantifier, "Invalid quantifier")                              \
311cb0ef41Sopenharmony_ci  T(InvalidGroup, "Invalid group")                                        \
321cb0ef41Sopenharmony_ci  T(MultipleFlagDashes, "Multiple dashes in flag group")                  \
331cb0ef41Sopenharmony_ci  T(NotLinear, "Cannot be executed in linear time")                       \
341cb0ef41Sopenharmony_ci  T(RepeatedFlag, "Repeated flag in flag group")                          \
351cb0ef41Sopenharmony_ci  T(InvalidFlagGroup, "Invalid flag group")                               \
361cb0ef41Sopenharmony_ci  T(TooManyCaptures, "Too many captures")                                 \
371cb0ef41Sopenharmony_ci  T(InvalidCaptureGroupName, "Invalid capture group name")                \
381cb0ef41Sopenharmony_ci  T(DuplicateCaptureGroupName, "Duplicate capture group name")            \
391cb0ef41Sopenharmony_ci  T(InvalidNamedReference, "Invalid named reference")                     \
401cb0ef41Sopenharmony_ci  T(InvalidNamedCaptureReference, "Invalid named capture referenced")     \
411cb0ef41Sopenharmony_ci  T(InvalidClassEscape, "Invalid class escape")                           \
421cb0ef41Sopenharmony_ci  T(InvalidClassPropertyName, "Invalid property name in character class") \
431cb0ef41Sopenharmony_ci  T(InvalidCharacterClass, "Invalid character class")                     \
441cb0ef41Sopenharmony_ci  T(UnterminatedCharacterClass, "Unterminated character class")           \
451cb0ef41Sopenharmony_ci  T(OutOfOrderCharacterClass, "Range out of order in character class")
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_cienum class RegExpError : uint32_t {
481cb0ef41Sopenharmony_ci#define TEMPLATE(NAME, STRING) k##NAME,
491cb0ef41Sopenharmony_ci  REGEXP_ERROR_MESSAGES(TEMPLATE)
501cb0ef41Sopenharmony_ci#undef TEMPLATE
511cb0ef41Sopenharmony_ci      NumErrors
521cb0ef41Sopenharmony_ci};
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ciV8_EXPORT_PRIVATE const char* RegExpErrorString(RegExpError error);
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ciinline constexpr bool RegExpErrorIsStackOverflow(RegExpError error) {
571cb0ef41Sopenharmony_ci  return error == RegExpError::kStackOverflow ||
581cb0ef41Sopenharmony_ci         error == RegExpError::kAnalysisStackOverflow;
591cb0ef41Sopenharmony_ci}
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci}  // namespace internal
621cb0ef41Sopenharmony_ci}  // namespace v8
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci#endif  // V8_REGEXP_REGEXP_ERROR_H_
65