mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
Apply coding convention to third party
* check_tidy script has been fixed to print only format errors Signed-off-by: HyukWoo Park <hyukwoo.park@samsung.com>
This commit is contained in:
parent
97940b157e
commit
2c386d65b0
27 changed files with 5014 additions and 7495 deletions
245
third_party/checked_arithmetic/CheckedArithmetic.h
vendored
245
third_party/checked_arithmetic/CheckedArithmetic.h
vendored
|
|
@ -20,7 +20,7 @@
|
|||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CheckedArithmetic_h
|
||||
|
|
@ -64,11 +64,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
template <typename T, typename U> struct IsSameType {
|
||||
template <typename T, typename U>
|
||||
struct IsSameType {
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template <typename T> struct IsSameType<T, T> {
|
||||
template <typename T>
|
||||
struct IsSameType<T, T> {
|
||||
static const bool value = true;
|
||||
};
|
||||
|
||||
|
|
@ -79,8 +81,7 @@ protected:
|
|||
CRASH();
|
||||
}
|
||||
|
||||
void clearOverflow() { }
|
||||
|
||||
void clearOverflow() {}
|
||||
public:
|
||||
bool hasOverflowed() const { return false; }
|
||||
};
|
||||
|
|
@ -104,17 +105,21 @@ protected:
|
|||
|
||||
public:
|
||||
bool hasOverflowed() const { return m_overflowed; }
|
||||
|
||||
private:
|
||||
unsigned char m_overflowed;
|
||||
};
|
||||
|
||||
template <typename T, class OverflowHandler = CrashOnOverflow> class Checked;
|
||||
template <typename T> struct RemoveChecked;
|
||||
template <typename T> struct RemoveChecked<Checked<T> >;
|
||||
template <typename T, class OverflowHandler = CrashOnOverflow>
|
||||
class Checked;
|
||||
template <typename T>
|
||||
struct RemoveChecked;
|
||||
template <typename T>
|
||||
struct RemoveChecked<Checked<T> >;
|
||||
|
||||
template <typename Target, typename Source, bool targetSigned = std::numeric_limits<Target>::is_signed, bool sourceSigned = std::numeric_limits<Source>::is_signed> struct BoundsChecker;
|
||||
template <typename Target, typename Source> struct BoundsChecker<Target, Source, false, false> {
|
||||
template <typename Target, typename Source, bool targetSigned = std::numeric_limits<Target>::is_signed, bool sourceSigned = std::numeric_limits<Source>::is_signed>
|
||||
struct BoundsChecker;
|
||||
template <typename Target, typename Source>
|
||||
struct BoundsChecker<Target, Source, false, false> {
|
||||
static bool inBounds(Source value)
|
||||
{
|
||||
// Same signedness so implicit type conversion will always increase precision
|
||||
|
|
@ -123,7 +128,8 @@ template <typename Target, typename Source> struct BoundsChecker<Target, Source,
|
|||
}
|
||||
};
|
||||
|
||||
template <typename Target, typename Source> struct BoundsChecker<Target, Source, true, true> {
|
||||
template <typename Target, typename Source>
|
||||
struct BoundsChecker<Target, Source, true, true> {
|
||||
static bool inBounds(Source value)
|
||||
{
|
||||
// Same signedness so implicit type conversion will always increase precision
|
||||
|
|
@ -132,7 +138,8 @@ template <typename Target, typename Source> struct BoundsChecker<Target, Source,
|
|||
}
|
||||
};
|
||||
|
||||
template <typename Target, typename Source> struct BoundsChecker<Target, Source, false, true> {
|
||||
template <typename Target, typename Source>
|
||||
struct BoundsChecker<Target, Source, false, true> {
|
||||
static bool inBounds(Source value)
|
||||
{
|
||||
// Target is unsigned so any value less than zero is clearly unsafe
|
||||
|
|
@ -140,7 +147,7 @@ template <typename Target, typename Source> struct BoundsChecker<Target, Source,
|
|||
return false;
|
||||
// If our (unsigned) Target is the same or greater width we can
|
||||
// convert value to type Target without losing precision
|
||||
if (sizeof(Target) >= sizeof(Source))
|
||||
if (sizeof(Target) >= sizeof(Source))
|
||||
return static_cast<Target>(value) <= std::numeric_limits<Target>::max();
|
||||
// The signed Source type has greater precision than the target so
|
||||
// max(Target) -> Source will widen.
|
||||
|
|
@ -148,11 +155,12 @@ template <typename Target, typename Source> struct BoundsChecker<Target, Source,
|
|||
}
|
||||
};
|
||||
|
||||
template <typename Target, typename Source> struct BoundsChecker<Target, Source, true, false> {
|
||||
template <typename Target, typename Source>
|
||||
struct BoundsChecker<Target, Source, true, false> {
|
||||
static bool inBounds(Source value)
|
||||
{
|
||||
// Signed target with an unsigned source
|
||||
if (sizeof(Target) <= sizeof(Source))
|
||||
if (sizeof(Target) <= sizeof(Source))
|
||||
return value <= static_cast<Source>(std::numeric_limits<Target>::max());
|
||||
// Target is Wider than Source so we're guaranteed to fit any value in
|
||||
// unsigned Source
|
||||
|
|
@ -160,76 +168,96 @@ template <typename Target, typename Source> struct BoundsChecker<Target, Source,
|
|||
}
|
||||
};
|
||||
|
||||
template <typename Target, typename Source, bool CanElide = IsSameType<Target, Source>::value || (sizeof(Target) > sizeof(Source)) > struct BoundsCheckElider;
|
||||
template <typename Target, typename Source> struct BoundsCheckElider<Target, Source, true> {
|
||||
template <typename Target, typename Source, bool CanElide = IsSameType<Target, Source>::value || (sizeof(Target) > sizeof(Source))>
|
||||
struct BoundsCheckElider;
|
||||
template <typename Target, typename Source>
|
||||
struct BoundsCheckElider<Target, Source, true> {
|
||||
static bool inBounds(Source) { return true; }
|
||||
};
|
||||
template <typename Target, typename Source> struct BoundsCheckElider<Target, Source, false> : public BoundsChecker<Target, Source> {
|
||||
template <typename Target, typename Source>
|
||||
struct BoundsCheckElider<Target, Source, false> : public BoundsChecker<Target, Source> {
|
||||
};
|
||||
|
||||
template <typename Target, typename Source> static inline bool isInBounds(Source value)
|
||||
template <typename Target, typename Source>
|
||||
static inline bool isInBounds(Source value)
|
||||
{
|
||||
return BoundsCheckElider<Target, Source>::inBounds(value);
|
||||
}
|
||||
|
||||
template <typename T> struct RemoveChecked {
|
||||
template <typename T>
|
||||
struct RemoveChecked {
|
||||
typedef T CleanType;
|
||||
static const CleanType DefaultValue = 0;
|
||||
static const CleanType DefaultValue = 0;
|
||||
};
|
||||
|
||||
template <typename T> struct RemoveChecked<Checked<T, CrashOnOverflow> > {
|
||||
template <typename T>
|
||||
struct RemoveChecked<Checked<T, CrashOnOverflow> > {
|
||||
typedef typename RemoveChecked<T>::CleanType CleanType;
|
||||
static const CleanType DefaultValue = 0;
|
||||
};
|
||||
|
||||
template <typename T> struct RemoveChecked<Checked<T, RecordOverflow> > {
|
||||
template <typename T>
|
||||
struct RemoveChecked<Checked<T, RecordOverflow> > {
|
||||
typedef typename RemoveChecked<T>::CleanType CleanType;
|
||||
static const CleanType DefaultValue = 0;
|
||||
};
|
||||
|
||||
// The ResultBase and SignednessSelector are used to workaround typeof not being
|
||||
// available in MSVC
|
||||
template <typename U, typename V, bool uIsBigger = (sizeof(U) > sizeof(V)), bool sameSize = (sizeof(U) == sizeof(V))> struct ResultBase;
|
||||
template <typename U, typename V> struct ResultBase<U, V, true, false> {
|
||||
template <typename U, typename V, bool uIsBigger = (sizeof(U) > sizeof(V)), bool sameSize = (sizeof(U) == sizeof(V))>
|
||||
struct ResultBase;
|
||||
template <typename U, typename V>
|
||||
struct ResultBase<U, V, true, false> {
|
||||
typedef U ResultType;
|
||||
};
|
||||
|
||||
template <typename U, typename V> struct ResultBase<U, V, false, false> {
|
||||
template <typename U, typename V>
|
||||
struct ResultBase<U, V, false, false> {
|
||||
typedef V ResultType;
|
||||
};
|
||||
|
||||
template <typename U> struct ResultBase<U, U, false, true> {
|
||||
template <typename U>
|
||||
struct ResultBase<U, U, false, true> {
|
||||
typedef U ResultType;
|
||||
};
|
||||
|
||||
template <typename U, typename V, bool uIsSigned = std::numeric_limits<U>::is_signed, bool vIsSigned = std::numeric_limits<V>::is_signed> struct SignednessSelector;
|
||||
template <typename U, typename V> struct SignednessSelector<U, V, true, true> {
|
||||
template <typename U, typename V, bool uIsSigned = std::numeric_limits<U>::is_signed, bool vIsSigned = std::numeric_limits<V>::is_signed>
|
||||
struct SignednessSelector;
|
||||
template <typename U, typename V>
|
||||
struct SignednessSelector<U, V, true, true> {
|
||||
typedef U ResultType;
|
||||
};
|
||||
|
||||
template <typename U, typename V> struct SignednessSelector<U, V, false, false> {
|
||||
template <typename U, typename V>
|
||||
struct SignednessSelector<U, V, false, false> {
|
||||
typedef U ResultType;
|
||||
};
|
||||
|
||||
template <typename U, typename V> struct SignednessSelector<U, V, true, false> {
|
||||
template <typename U, typename V>
|
||||
struct SignednessSelector<U, V, true, false> {
|
||||
typedef V ResultType;
|
||||
};
|
||||
|
||||
template <typename U, typename V> struct SignednessSelector<U, V, false, true> {
|
||||
template <typename U, typename V>
|
||||
struct SignednessSelector<U, V, false, true> {
|
||||
typedef U ResultType;
|
||||
};
|
||||
|
||||
template <typename U, typename V> struct ResultBase<U, V, false, true> {
|
||||
template <typename U, typename V>
|
||||
struct ResultBase<U, V, false, true> {
|
||||
typedef typename SignednessSelector<U, V>::ResultType ResultType;
|
||||
};
|
||||
|
||||
template <typename U, typename V> struct Result : ResultBase<typename RemoveChecked<U>::CleanType, typename RemoveChecked<V>::CleanType> {
|
||||
template <typename U, typename V>
|
||||
struct Result : ResultBase<typename RemoveChecked<U>::CleanType, typename RemoveChecked<V>::CleanType> {
|
||||
};
|
||||
|
||||
template <typename LHS, typename RHS, typename ResultType = typename Result<LHS, RHS>::ResultType,
|
||||
bool lhsSigned = std::numeric_limits<LHS>::is_signed, bool rhsSigned = std::numeric_limits<RHS>::is_signed> struct ArithmeticOperations;
|
||||
template <typename LHS, typename RHS, typename ResultType = typename Result<LHS, RHS>::ResultType,
|
||||
bool lhsSigned = std::numeric_limits<LHS>::is_signed, bool rhsSigned = std::numeric_limits<RHS>::is_signed>
|
||||
struct ArithmeticOperations;
|
||||
|
||||
template <typename LHS, typename RHS, typename ResultType> struct ArithmeticOperations<LHS, RHS, ResultType, true, true> {
|
||||
template <typename LHS, typename RHS, typename ResultType>
|
||||
struct ArithmeticOperations<LHS, RHS, ResultType, true, true> {
|
||||
// LHS and RHS are signed types
|
||||
|
||||
// Helper function
|
||||
|
|
@ -295,10 +323,10 @@ template <typename LHS, typename RHS, typename ResultType> struct ArithmeticOper
|
|||
}
|
||||
|
||||
static inline bool equals(LHS lhs, RHS rhs) { return lhs == rhs; }
|
||||
|
||||
};
|
||||
|
||||
template <typename LHS, typename RHS, typename ResultType> struct ArithmeticOperations<LHS, RHS, ResultType, false, false> {
|
||||
template <typename LHS, typename RHS, typename ResultType>
|
||||
struct ArithmeticOperations<LHS, RHS, ResultType, false, false> {
|
||||
// LHS and RHS are unsigned types so bounds checks are nice and easy
|
||||
static inline bool add(LHS lhs, RHS rhs, ResultType& result)
|
||||
{
|
||||
|
|
@ -328,10 +356,10 @@ template <typename LHS, typename RHS, typename ResultType> struct ArithmeticOper
|
|||
}
|
||||
|
||||
static inline bool equals(LHS lhs, RHS rhs) { return lhs == rhs; }
|
||||
|
||||
};
|
||||
|
||||
template <typename ResultType> struct ArithmeticOperations<int, unsigned, ResultType, true, false> {
|
||||
template <typename ResultType>
|
||||
struct ArithmeticOperations<int, unsigned, ResultType, true, false> {
|
||||
static inline bool add(int64_t lhs, int64_t rhs, ResultType& result)
|
||||
{
|
||||
int64_t temp = lhs + rhs;
|
||||
|
|
@ -342,7 +370,7 @@ template <typename ResultType> struct ArithmeticOperations<int, unsigned, Result
|
|||
result = static_cast<ResultType>(temp);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static inline bool sub(int64_t lhs, int64_t rhs, ResultType& result)
|
||||
{
|
||||
int64_t temp = lhs - rhs;
|
||||
|
|
@ -371,12 +399,13 @@ template <typename ResultType> struct ArithmeticOperations<int, unsigned, Result
|
|||
}
|
||||
};
|
||||
|
||||
template <typename ResultType> struct ArithmeticOperations<unsigned, int, ResultType, false, true> {
|
||||
template <typename ResultType>
|
||||
struct ArithmeticOperations<unsigned, int, ResultType, false, true> {
|
||||
static inline bool add(int64_t lhs, int64_t rhs, ResultType& result)
|
||||
{
|
||||
return ArithmeticOperations<int, unsigned, ResultType>::add(rhs, lhs, result);
|
||||
}
|
||||
|
||||
|
||||
static inline bool sub(int64_t lhs, int64_t rhs, ResultType& result)
|
||||
{
|
||||
return ArithmeticOperations<int, unsigned, ResultType>::sub(lhs, rhs, result);
|
||||
|
|
@ -393,34 +422,39 @@ template <typename ResultType> struct ArithmeticOperations<unsigned, int, Result
|
|||
}
|
||||
};
|
||||
|
||||
template <typename U, typename V, typename R> static inline bool safeAdd(U lhs, V rhs, R& result)
|
||||
template <typename U, typename V, typename R>
|
||||
static inline bool safeAdd(U lhs, V rhs, R& result)
|
||||
{
|
||||
return ArithmeticOperations<U, V, R>::add(lhs, rhs, result);
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename R> static inline bool safeSub(U lhs, V rhs, R& result)
|
||||
template <typename U, typename V, typename R>
|
||||
static inline bool safeSub(U lhs, V rhs, R& result)
|
||||
{
|
||||
return ArithmeticOperations<U, V, R>::sub(lhs, rhs, result);
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename R> static inline bool safeMultiply(U lhs, V rhs, R& result)
|
||||
template <typename U, typename V, typename R>
|
||||
static inline bool safeMultiply(U lhs, V rhs, R& result)
|
||||
{
|
||||
return ArithmeticOperations<U, V, R>::multiply(lhs, rhs, result);
|
||||
}
|
||||
|
||||
template <typename U, typename V> static inline bool safeEquals(U lhs, V rhs)
|
||||
template <typename U, typename V>
|
||||
static inline bool safeEquals(U lhs, V rhs)
|
||||
{
|
||||
return ArithmeticOperations<U, V>::equals(lhs, rhs);
|
||||
}
|
||||
|
||||
enum ResultOverflowedTag { ResultOverflowed };
|
||||
|
||||
|
||||
// FIXME: Needed to workaround http://llvm.org/bugs/show_bug.cgi?id=10801
|
||||
static inline bool workAroundClangBug() { return true; }
|
||||
|
||||
template <typename T, class OverflowHandler> class Checked : public OverflowHandler {
|
||||
template <typename T, class OverflowHandler>
|
||||
class Checked : public OverflowHandler {
|
||||
public:
|
||||
template <typename _T, class _OverflowHandler> friend class Checked;
|
||||
template <typename _T, class _OverflowHandler>
|
||||
friend class Checked;
|
||||
Checked()
|
||||
: m_value(0)
|
||||
{
|
||||
|
|
@ -434,29 +468,33 @@ public:
|
|||
this->overflowed();
|
||||
}
|
||||
|
||||
template <typename U> Checked(U value)
|
||||
template <typename U>
|
||||
Checked(U value)
|
||||
{
|
||||
if (!isInBounds<T>(value))
|
||||
this->overflowed();
|
||||
m_value = static_cast<T>(value);
|
||||
}
|
||||
|
||||
template <typename V> Checked(const Checked<T, V>& rhs)
|
||||
|
||||
template <typename V>
|
||||
Checked(const Checked<T, V>& rhs)
|
||||
: m_value(rhs.m_value)
|
||||
{
|
||||
if (rhs.hasOverflowed())
|
||||
this->overflowed();
|
||||
}
|
||||
|
||||
template <typename U> Checked(const Checked<U, OverflowHandler>& rhs)
|
||||
|
||||
template <typename U>
|
||||
Checked(const Checked<U, OverflowHandler>& rhs)
|
||||
: OverflowHandler(rhs)
|
||||
{
|
||||
if (!isInBounds<T>(rhs.m_value))
|
||||
this->overflowed();
|
||||
m_value = static_cast<T>(rhs.m_value);
|
||||
}
|
||||
|
||||
template <typename U, typename V> Checked(const Checked<U, V>& rhs)
|
||||
|
||||
template <typename U, typename V>
|
||||
Checked(const Checked<U, V>& rhs)
|
||||
{
|
||||
if (rhs.hasOverflowed())
|
||||
this->overflowed();
|
||||
|
|
@ -464,7 +502,7 @@ public:
|
|||
this->overflowed();
|
||||
m_value = static_cast<T>(rhs.m_value);
|
||||
}
|
||||
|
||||
|
||||
const Checked& operator=(Checked rhs)
|
||||
{
|
||||
this->clearOverflow();
|
||||
|
|
@ -473,17 +511,19 @@ public:
|
|||
m_value = static_cast<T>(rhs.m_value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U> const Checked& operator=(U value)
|
||||
|
||||
template <typename U>
|
||||
const Checked& operator=(U value)
|
||||
{
|
||||
return *this = Checked(value);
|
||||
}
|
||||
|
||||
template <typename U, typename V> const Checked& operator=(const Checked<U, V>& rhs)
|
||||
|
||||
template <typename U, typename V>
|
||||
const Checked& operator=(const Checked<U, V>& rhs)
|
||||
{
|
||||
return *this = Checked(rhs);
|
||||
}
|
||||
|
||||
|
||||
// prefix
|
||||
const Checked& operator++()
|
||||
{
|
||||
|
|
@ -492,7 +532,7 @@ public:
|
|||
m_value++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const Checked& operator--()
|
||||
{
|
||||
if (m_value == std::numeric_limits<T>::min())
|
||||
|
|
@ -500,7 +540,7 @@ public:
|
|||
m_value--;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// postfix operators
|
||||
const Checked operator++(int)
|
||||
{
|
||||
|
|
@ -508,14 +548,14 @@ public:
|
|||
this->overflowed();
|
||||
return Checked(m_value++);
|
||||
}
|
||||
|
||||
|
||||
const Checked operator--(int)
|
||||
{
|
||||
if (m_value == std::numeric_limits<T>::min())
|
||||
this->overflowed();
|
||||
return Checked(m_value--);
|
||||
}
|
||||
|
||||
|
||||
// Boolean operators
|
||||
bool operator!() const
|
||||
{
|
||||
|
|
@ -524,7 +564,7 @@ public:
|
|||
return !m_value;
|
||||
}
|
||||
|
||||
typedef void* (Checked::*UnspecifiedBoolType);
|
||||
typedef void*(Checked::*UnspecifiedBoolType);
|
||||
operator UnspecifiedBoolType*() const
|
||||
{
|
||||
if (this->hasOverflowed())
|
||||
|
|
@ -539,7 +579,7 @@ public:
|
|||
CRASH();
|
||||
return m_value;
|
||||
}
|
||||
|
||||
|
||||
bool safeGet(T& value) const
|
||||
{
|
||||
value = m_value;
|
||||
|
|
@ -547,21 +587,24 @@ public:
|
|||
}
|
||||
|
||||
// Mutating assignment
|
||||
template <typename U> const Checked operator+=(U rhs)
|
||||
template <typename U>
|
||||
const Checked operator+=(U rhs)
|
||||
{
|
||||
if (!safeAdd(m_value, rhs, m_value))
|
||||
this->overflowed();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U> const Checked operator-=(U rhs)
|
||||
template <typename U>
|
||||
const Checked operator-=(U rhs)
|
||||
{
|
||||
if (!safeSub(m_value, rhs, m_value))
|
||||
this->overflowed();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U> const Checked operator*=(U rhs)
|
||||
template <typename U>
|
||||
const Checked operator*=(U rhs)
|
||||
{
|
||||
if (!safeMultiply(m_value, rhs, m_value))
|
||||
this->overflowed();
|
||||
|
|
@ -582,22 +625,25 @@ public:
|
|||
{
|
||||
return *this *= (double)rhs;
|
||||
}
|
||||
|
||||
template <typename U, typename V> const Checked operator+=(Checked<U, V> rhs)
|
||||
|
||||
template <typename U, typename V>
|
||||
const Checked operator+=(Checked<U, V> rhs)
|
||||
{
|
||||
if (rhs.hasOverflowed())
|
||||
this->overflowed();
|
||||
return *this += rhs.m_value;
|
||||
}
|
||||
|
||||
template <typename U, typename V> const Checked operator-=(Checked<U, V> rhs)
|
||||
template <typename U, typename V>
|
||||
const Checked operator-=(Checked<U, V> rhs)
|
||||
{
|
||||
if (rhs.hasOverflowed())
|
||||
this->overflowed();
|
||||
return *this -= rhs.m_value;
|
||||
}
|
||||
|
||||
template <typename U, typename V> const Checked operator*=(Checked<U, V> rhs)
|
||||
template <typename U, typename V>
|
||||
const Checked operator*=(Checked<U, V> rhs)
|
||||
{
|
||||
if (rhs.hasOverflowed())
|
||||
this->overflowed();
|
||||
|
|
@ -605,24 +651,28 @@ public:
|
|||
}
|
||||
|
||||
// Equality comparisons
|
||||
template <typename V> bool operator==(Checked<T, V> rhs)
|
||||
template <typename V>
|
||||
bool operator==(Checked<T, V> rhs)
|
||||
{
|
||||
return unsafeGet() == rhs.unsafeGet();
|
||||
}
|
||||
|
||||
template <typename U> bool operator==(U rhs)
|
||||
template <typename U>
|
||||
bool operator==(U rhs)
|
||||
{
|
||||
if (this->hasOverflowed())
|
||||
this->overflowed();
|
||||
return safeEquals(m_value, rhs);
|
||||
}
|
||||
|
||||
template <typename U, typename V> const Checked operator==(Checked<U, V> rhs)
|
||||
|
||||
template <typename U, typename V>
|
||||
const Checked operator==(Checked<U, V> rhs)
|
||||
{
|
||||
return unsafeGet() == Checked(rhs.unsafeGet());
|
||||
}
|
||||
|
||||
template <typename U> bool operator!=(U rhs)
|
||||
template <typename U>
|
||||
bool operator!=(U rhs)
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
|
@ -640,7 +690,8 @@ private:
|
|||
T m_value;
|
||||
};
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs)
|
||||
{
|
||||
U x = 0;
|
||||
V y = 0;
|
||||
|
|
@ -652,7 +703,8 @@ template <typename U, typename V, typename OverflowHandler> static inline Checke
|
|||
return result;
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs)
|
||||
{
|
||||
U x = 0;
|
||||
V y = 0;
|
||||
|
|
@ -664,7 +716,8 @@ template <typename U, typename V, typename OverflowHandler> static inline Checke
|
|||
return result;
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(Checked<U, OverflowHandler> lhs, Checked<V, OverflowHandler> rhs)
|
||||
{
|
||||
U x = 0;
|
||||
V y = 0;
|
||||
|
|
@ -676,32 +729,38 @@ template <typename U, typename V, typename OverflowHandler> static inline Checke
|
|||
return result;
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(Checked<U, OverflowHandler> lhs, V rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(Checked<U, OverflowHandler> lhs, V rhs)
|
||||
{
|
||||
return lhs + Checked<V, OverflowHandler>(rhs);
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(Checked<U, OverflowHandler> lhs, V rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(Checked<U, OverflowHandler> lhs, V rhs)
|
||||
{
|
||||
return lhs - Checked<V, OverflowHandler>(rhs);
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(Checked<U, OverflowHandler> lhs, V rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(Checked<U, OverflowHandler> lhs, V rhs)
|
||||
{
|
||||
return lhs * Checked<V, OverflowHandler>(rhs);
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(U lhs, Checked<V, OverflowHandler> rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator+(U lhs, Checked<V, OverflowHandler> rhs)
|
||||
{
|
||||
return Checked<U, OverflowHandler>(lhs) + rhs;
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(U lhs, Checked<V, OverflowHandler> rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator-(U lhs, Checked<V, OverflowHandler> rhs)
|
||||
{
|
||||
return Checked<U, OverflowHandler>(lhs) - rhs;
|
||||
}
|
||||
|
||||
template <typename U, typename V, typename OverflowHandler> static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(U lhs, Checked<V, OverflowHandler> rhs)
|
||||
template <typename U, typename V, typename OverflowHandler>
|
||||
static inline Checked<typename Result<U, V>::ResultType, OverflowHandler> operator*(U lhs, Checked<V, OverflowHandler> rhs)
|
||||
{
|
||||
return Checked<U, OverflowHandler>(lhs) * rhs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ static std::string extractLocaleName(std::string input)
|
|||
|
||||
std::string ICU::findSystemLocale()
|
||||
{
|
||||
char* c = getenv("LANG");
|
||||
char *c = getenv("LANG");
|
||||
if (c && strlen(c)) {
|
||||
return extractLocaleName(c);
|
||||
}
|
||||
|
|
|
|||
55
third_party/yarr/ASCIICType.h
vendored
55
third_party/yarr/ASCIICType.h
vendored
|
|
@ -6,13 +6,13 @@
|
|||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
|
|
@ -47,42 +47,50 @@
|
|||
|
||||
namespace WTF {
|
||||
|
||||
template<typename CharType> inline bool isASCII(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCII(CharType c)
|
||||
{
|
||||
return !(c & ~0x7F);
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIIAlpha(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIIAlpha(CharType c)
|
||||
{
|
||||
return (c | 0x20) >= 'a' && (c | 0x20) <= 'z';
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIIDigit(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIIDigit(CharType c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIIAlphanumeric(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIIAlphanumeric(CharType c)
|
||||
{
|
||||
return isASCIIDigit(c) || isASCIIAlpha(c);
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIIHexDigit(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIIHexDigit(CharType c)
|
||||
{
|
||||
return isASCIIDigit(c) || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIILower(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIILower(CharType c)
|
||||
{
|
||||
return c >= 'a' && c <= 'z';
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIIOctalDigit(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIIOctalDigit(CharType c)
|
||||
{
|
||||
return (c >= '0') & (c <= '7');
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIIPrintable(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIIPrintable(CharType c)
|
||||
{
|
||||
return c >= ' ' && c <= '~';
|
||||
}
|
||||
|
|
@ -100,22 +108,26 @@ template<typename CharType> inline bool isASCIIPrintable(CharType c)
|
|||
0C \f 0
|
||||
0B \v 0
|
||||
*/
|
||||
template<typename CharType> inline bool isASCIISpace(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIISpace(CharType c)
|
||||
{
|
||||
return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIIUpper(CharType c)
|
||||
template <typename CharType>
|
||||
inline bool isASCIIUpper(CharType c)
|
||||
{
|
||||
return c >= 'A' && c <= 'Z';
|
||||
}
|
||||
|
||||
template<typename CharType> inline CharType toASCIILower(CharType c)
|
||||
template <typename CharType>
|
||||
inline CharType toASCIILower(CharType c)
|
||||
{
|
||||
return c | ((c >= 'A' && c <= 'Z') << 5);
|
||||
}
|
||||
|
||||
template<typename CharType> inline CharType toASCIILowerUnchecked(CharType character)
|
||||
template <typename CharType>
|
||||
inline CharType toASCIILowerUnchecked(CharType character)
|
||||
{
|
||||
// This function can be used for comparing any input character
|
||||
// to a lowercase English character. The isASCIIAlphaCaselessEqual
|
||||
|
|
@ -125,18 +137,21 @@ template<typename CharType> inline CharType toASCIILowerUnchecked(CharType chara
|
|||
return character | 0x20;
|
||||
}
|
||||
|
||||
template<typename CharType> inline CharType toASCIIUpper(CharType c)
|
||||
template <typename CharType>
|
||||
inline CharType toASCIIUpper(CharType c)
|
||||
{
|
||||
return c & ~((c >= 'a' && c <= 'z') << 5);
|
||||
}
|
||||
|
||||
template<typename CharType> inline int toASCIIHexValue(CharType c)
|
||||
template <typename CharType>
|
||||
inline int toASCIIHexValue(CharType c)
|
||||
{
|
||||
ASSERT(isASCIIHexDigit(c));
|
||||
return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF;
|
||||
}
|
||||
|
||||
template<typename CharType> inline int toASCIIHexValue(CharType upperValue, CharType lowerValue)
|
||||
template <typename CharType>
|
||||
inline int toASCIIHexValue(CharType upperValue, CharType lowerValue)
|
||||
{
|
||||
ASSERT(isASCIIHexDigit(upperValue) && isASCIIHexDigit(lowerValue));
|
||||
return ((toASCIIHexValue(upperValue) << 4) & 0xF0) | toASCIIHexValue(lowerValue);
|
||||
|
|
@ -154,14 +169,14 @@ inline char upperNibbleToASCIIHexDigit(char c)
|
|||
return nibble < 10 ? '0' + nibble : 'A' + nibble - 10;
|
||||
}
|
||||
|
||||
template<typename CharType> inline bool isASCIIAlphaCaselessEqual(CharType cssCharacter, char character)
|
||||
template <typename CharType>
|
||||
inline bool isASCIIAlphaCaselessEqual(CharType cssCharacter, char character)
|
||||
{
|
||||
// This function compares a (preferrably) constant ASCII
|
||||
// lowercase letter to any input character.
|
||||
ASSERT(character >= 'a' && character <= 'z');
|
||||
return LIKELY(toASCIILowerUnchecked(cssCharacter) == character);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using WTF::isASCII;
|
||||
|
|
|
|||
5
third_party/yarr/BumpPointerAllocator.h
vendored
5
third_party/yarr/BumpPointerAllocator.h
vendored
|
|
@ -20,7 +20,7 @@
|
|||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef BumpPointerAllocator_h
|
||||
|
|
@ -165,7 +165,7 @@ private:
|
|||
return pool;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
void* current = pool->m_current;
|
||||
void* allocationEnd = static_cast<char*>(current) + size;
|
||||
ASSERT(allocationEnd > current); // check for overflow
|
||||
|
|
@ -249,7 +249,6 @@ public:
|
|||
private:
|
||||
BumpPointerPool* m_head;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using WTF::BumpPointerAllocator;
|
||||
|
|
|
|||
4
third_party/yarr/OSAllocator.h
vendored
4
third_party/yarr/OSAllocator.h
vendored
|
|
@ -76,7 +76,7 @@ public:
|
|||
// Reallocate an existing, committed allocation.
|
||||
// The prior allocation must be fully comitted, and the new size will also be fully committed.
|
||||
// This interface is provided since it may be possible to optimize this operation on some platforms.
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
static T* reallocateCommitted(T*, size_t oldSize, size_t newSize, Usage = UnknownUsage, bool writable = true, bool executable = false);
|
||||
};
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ inline void OSAllocator::decommitAndRelease(void* base, size_t size)
|
|||
decommitAndRelease(base, size, base, size);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
inline T* OSAllocator::reallocateCommitted(T* oldBase, size_t oldSize, size_t newSize, Usage usage, bool writable, bool executable)
|
||||
{
|
||||
void* newBase = reserveAndCommit(newSize, usage, writable, executable);
|
||||
|
|
|
|||
17
third_party/yarr/OSAllocatorPosix.cpp
vendored
17
third_party/yarr/OSAllocatorPosix.cpp
vendored
|
|
@ -57,7 +57,8 @@ void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable,
|
|||
madvise(result, bytes, MADV_DONTNEED);
|
||||
#elif defined(HAVE_MADV_FREE_REUSE)
|
||||
// To support the "reserve then commit" model, we have to initially decommit.
|
||||
while (madvise(result, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
|
||||
while (madvise(result, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OS(QNX)
|
||||
|
|
@ -157,7 +158,8 @@ void OSAllocator::commit(void* address, size_t bytes, bool writable, bool execut
|
|||
#elif defined(HAVE_MADV_FREE_REUSE)
|
||||
UNUSED_PARAM(writable);
|
||||
UNUSED_PARAM(executable);
|
||||
while (madvise(address, bytes, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
|
||||
while (madvise(address, bytes, MADV_FREE_REUSE) == -1 && errno == EAGAIN) {
|
||||
}
|
||||
#else
|
||||
// Non-MADV_FREE_REUSE reservations automatically commit on demand.
|
||||
UNUSED_PARAM(address);
|
||||
|
|
@ -175,11 +177,14 @@ void OSAllocator::decommit(void* address, size_t bytes)
|
|||
#elif defined(OS_LINUX)
|
||||
madvise(address, bytes, MADV_DONTNEED);
|
||||
#elif defined(HAVE_MADV_FREE_REUSE)
|
||||
while (madvise(address, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
|
||||
while (madvise(address, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) {
|
||||
}
|
||||
#elif defined(HAVE_MADV_FREE)
|
||||
while (madvise(address, bytes, MADV_FREE) == -1 && errno == EAGAIN) { }
|
||||
while (madvise(address, bytes, MADV_FREE) == -1 && errno == EAGAIN) {
|
||||
}
|
||||
#elif defined(HAVE_MADV_DONTNEED)
|
||||
while (madvise(address, bytes, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
|
||||
while (madvise(address, bytes, MADV_DONTNEED) == -1 && errno == EAGAIN) {
|
||||
}
|
||||
#else
|
||||
UNUSED_PARAM(address);
|
||||
UNUSED_PARAM(bytes);
|
||||
|
|
@ -195,4 +200,4 @@ void OSAllocator::releaseDecommitted(void* address, size_t bytes)
|
|||
|
||||
} // namespace WTF
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
44
third_party/yarr/OSAllocatorWin.cpp
vendored
44
third_party/yarr/OSAllocatorWin.cpp
vendored
|
|
@ -44,50 +44,48 @@ namespace WTF {
|
|||
|
||||
static inline DWORD protection(bool writable, bool executable)
|
||||
{
|
||||
return executable ?
|
||||
(writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) :
|
||||
(writable ? PAGE_READWRITE : PAGE_READONLY);
|
||||
return executable ? (writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) : (writable ? PAGE_READWRITE : PAGE_READONLY);
|
||||
}
|
||||
|
||||
void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable, bool includesGuardPages)
|
||||
{
|
||||
void* result = VirtualAlloc(0, bytes, MEM_RESERVE, protection(writable, executable));
|
||||
if (!result)
|
||||
CRASH();
|
||||
return result;
|
||||
void* result = VirtualAlloc(0, bytes, MEM_RESERVE, protection(writable, executable));
|
||||
if (!result)
|
||||
CRASH();
|
||||
return result;
|
||||
}
|
||||
|
||||
void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable, bool includesGuardPages)
|
||||
{
|
||||
void* result = VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, protection(writable, executable));
|
||||
if (!result)
|
||||
CRASH();
|
||||
return result;
|
||||
void* result = VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, protection(writable, executable));
|
||||
if (!result)
|
||||
CRASH();
|
||||
return result;
|
||||
}
|
||||
|
||||
void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
|
||||
{
|
||||
void* result = VirtualAlloc(address, bytes, MEM_COMMIT, protection(writable, executable));
|
||||
if (!result)
|
||||
CRASH();
|
||||
void* result = VirtualAlloc(address, bytes, MEM_COMMIT, protection(writable, executable));
|
||||
if (!result)
|
||||
CRASH();
|
||||
}
|
||||
|
||||
void OSAllocator::decommit(void* address, size_t bytes)
|
||||
{
|
||||
bool result = VirtualFree(address, bytes, MEM_DECOMMIT);
|
||||
if (!result)
|
||||
CRASH();
|
||||
bool result = VirtualFree(address, bytes, MEM_DECOMMIT);
|
||||
if (!result)
|
||||
CRASH();
|
||||
}
|
||||
|
||||
void OSAllocator::releaseDecommitted(void* address, size_t bytes)
|
||||
{
|
||||
// According to http://msdn.microsoft.com/en-us/library/aa366892(VS.85).aspx,
|
||||
// dwSize must be 0 if dwFreeType is MEM_RELEASE.
|
||||
bool result = VirtualFree(address, 0, MEM_RELEASE);
|
||||
if (!result)
|
||||
CRASH();
|
||||
// According to http://msdn.microsoft.com/en-us/library/aa366892(VS.85).aspx,
|
||||
// dwSize must be 0 if dwFreeType is MEM_RELEASE.
|
||||
bool result = VirtualFree(address, 0, MEM_RELEASE);
|
||||
if (!result)
|
||||
CRASH();
|
||||
}
|
||||
|
||||
} // namespace WTF
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
5
third_party/yarr/PageBlock.h
vendored
5
third_party/yarr/PageBlock.h
vendored
|
|
@ -37,18 +37,15 @@ WTF_EXPORT_PRIVATE size_t pageMask();
|
|||
inline bool isPageAligned(void* address) { return !(reinterpret_cast<intptr_t>(address) & (pageSize() - 1)); }
|
||||
inline bool isPageAligned(size_t size) { return !(size & (pageSize() - 1)); }
|
||||
inline bool isPowerOfTwo(size_t size) { return !(size & (size - 1)); }
|
||||
|
||||
class PageBlock {
|
||||
public:
|
||||
PageBlock();
|
||||
PageBlock(const PageBlock&);
|
||||
PageBlock(void*, size_t, bool hasGuardPages);
|
||||
|
||||
|
||||
void* base() const { return m_base; }
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
operator bool() const { return !!m_realBase; }
|
||||
|
||||
bool contains(void* containedBase, size_t containedSize)
|
||||
{
|
||||
return containedBase >= m_base
|
||||
|
|
|
|||
5245
third_party/yarr/RegExpJitTables.h
vendored
5245
third_party/yarr/RegExpJitTables.h
vendored
File diff suppressed because it is too large
Load diff
6322
third_party/yarr/UnicodePatternTables.h
vendored
6322
third_party/yarr/UnicodePatternTables.h
vendored
File diff suppressed because one or more lines are too long
2
third_party/yarr/WTFBridge.h
vendored
2
third_party/yarr/WTFBridge.h
vendored
|
|
@ -385,7 +385,7 @@ public:
|
|||
return m_impl;
|
||||
}
|
||||
|
||||
template<const size_t srcLen>
|
||||
template <const size_t srcLen>
|
||||
ALWAYS_INLINE bool operator==(const char (&src)[srcLen]) const
|
||||
{
|
||||
return m_impl->equals(src);
|
||||
|
|
|
|||
7
third_party/yarr/Yarr.h
vendored
7
third_party/yarr/Yarr.h
vendored
|
|
@ -30,7 +30,8 @@
|
|||
#include <limits.h>
|
||||
#include "YarrErrorCode.h"
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
#define YarrStackSpaceForBackTrackInfoPatternCharacter 2 // Only for !fixed quantifiers.
|
||||
#define YarrStackSpaceForBackTrackInfoCharacterClass 2 // Only for !fixed quantifiers.
|
||||
|
|
@ -73,5 +74,5 @@ enum class BuiltInCharacterClassID : unsigned {
|
|||
};
|
||||
|
||||
struct BytecodePattern;
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
22
third_party/yarr/YarrCanonicalize.h
vendored
22
third_party/yarr/YarrCanonicalize.h
vendored
|
|
@ -20,14 +20,15 @@
|
|||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
// This set of data provides information for each UCS2 code point as to the set of code points
|
||||
// that it should match under the ES6 case insensitive RegExp matching rules, specified in 21.2.2.8.2.
|
||||
|
|
@ -35,11 +36,11 @@ namespace JSC { namespace Yarr {
|
|||
// The Unicode tables are autogenerated using the python script generateYarrCanonicalizeUnicode
|
||||
// which creates YarrCanonicalizeUnicode.cpp.
|
||||
enum UCS2CanonicalizationType {
|
||||
CanonicalizeUnique, // No canonically equal values, e.g. 0x0.
|
||||
CanonicalizeSet, // Value indicates a set in characterSetInfo.
|
||||
CanonicalizeRangeLo, // Value is positive delta to pair, E.g. 0x41 has value 0x20, -> 0x61.
|
||||
CanonicalizeRangeHi, // Value is positive delta to pair, E.g. 0x61 has value 0x20, -> 0x41.
|
||||
CanonicalizeAlternatingAligned, // Aligned consequtive pair, e.g. 0x1f4,0x1f5.
|
||||
CanonicalizeUnique, // No canonically equal values, e.g. 0x0.
|
||||
CanonicalizeSet, // Value indicates a set in characterSetInfo.
|
||||
CanonicalizeRangeLo, // Value is positive delta to pair, E.g. 0x41 has value 0x20, -> 0x61.
|
||||
CanonicalizeRangeHi, // Value is positive delta to pair, E.g. 0x61 has value 0x20, -> 0x41.
|
||||
CanonicalizeAlternatingAligned, // Aligned consequtive pair, e.g. 0x1f4,0x1f5.
|
||||
CanonicalizeAlternatingUnaligned, // Unaligned consequtive pair, e.g. 0x241,0x242.
|
||||
};
|
||||
struct CanonicalizationRange {
|
||||
|
|
@ -57,7 +58,8 @@ extern const size_t UNICODE_CANONICALIZATION_RANGES;
|
|||
extern const UChar32* const unicodeCharacterSetInfo[];
|
||||
extern const CanonicalizationRange unicodeRangeInfo[];
|
||||
|
||||
enum class CanonicalMode { UCS2, Unicode };
|
||||
enum class CanonicalMode { UCS2,
|
||||
Unicode };
|
||||
|
||||
inline const UChar32* canonicalCharacterSetInfo(unsigned index, CanonicalMode canonicalMode)
|
||||
{
|
||||
|
|
@ -138,5 +140,5 @@ inline bool areCanonicallyEquivalent(UChar32 a, UChar32 b, CanonicalMode canonic
|
|||
RELEASE_ASSERT_NOT_REACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
} } // JSC::Yarr
|
||||
}
|
||||
} // JSC::Yarr
|
||||
|
|
|
|||
10
third_party/yarr/YarrCanonicalizeUCS2.cpp
vendored
10
third_party/yarr/YarrCanonicalizeUCS2.cpp
vendored
|
|
@ -20,7 +20,7 @@
|
|||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// DO NOT EDIT! - this file autogenerated by YarrCanonicalize.js
|
||||
|
|
@ -28,7 +28,8 @@
|
|||
#include "WTFBridge.h"
|
||||
#include "YarrCanonicalize.h"
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
const UChar32 ucs2CharacterSet0[] = { 0x01c4, 0x01c5, 0x01c6, 0 };
|
||||
const UChar32 ucs2CharacterSet1[] = { 0x01c7, 0x01c8, 0x01c9, 0 };
|
||||
|
|
@ -459,6 +460,5 @@ const CanonicalizationRange ucs2RangeInfo[UCS2_CANONICALIZATION_RANGES] = {
|
|||
{ 0xff41, 0xff5a, 0x0020, CanonicalizeRangeHi },
|
||||
{ 0xff5b, 0xffff, 0x0000, CanonicalizeUnique },
|
||||
};
|
||||
|
||||
} } // JSC::Yarr
|
||||
|
||||
}
|
||||
} // JSC::Yarr
|
||||
|
|
|
|||
11
third_party/yarr/YarrCanonicalizeUnicode.cpp
vendored
11
third_party/yarr/YarrCanonicalizeUnicode.cpp
vendored
|
|
@ -6,10 +6,10 @@
|
|||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
|
|
@ -28,7 +28,8 @@
|
|||
#include "WTFBridge.h"
|
||||
#include "YarrCanonicalize.h"
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
const UChar32 unicodeCharacterSet0[] = { 0x004b, 0x006b, 0x212a, 0 };
|
||||
const UChar32 unicodeCharacterSet1[] = { 0x0053, 0x0073, 0x017f, 0 };
|
||||
|
|
@ -587,5 +588,5 @@ const CanonicalizationRange unicodeRangeInfo[UNICODE_CANONICALIZATION_RANGES] =
|
|||
{ 0x1e922, 0x1e943, 0x0022, CanonicalizeRangeHi },
|
||||
{ 0x1e944, 0x10ffff, 0x0000, CanonicalizeUnique },
|
||||
};
|
||||
|
||||
} } // JSC::Yarr
|
||||
}
|
||||
} // JSC::Yarr
|
||||
|
|
|
|||
57
third_party/yarr/YarrErrorCode.cpp
vendored
57
third_party/yarr/YarrErrorCode.cpp
vendored
|
|
@ -26,41 +26,42 @@
|
|||
#include "WTFBridge.h"
|
||||
#include "YarrErrorCode.h"
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
const char* errorMessage(ErrorCode error)
|
||||
{
|
||||
#define REGEXP_ERROR_PREFIX "Invalid regular expression: "
|
||||
// The order of this array must match the ErrorCode enum.
|
||||
static const char* errorMessages[] = {
|
||||
nullptr, // NoError
|
||||
REGEXP_ERROR_PREFIX "regular expression too large", // PatternTooLarge
|
||||
REGEXP_ERROR_PREFIX "numbers out of order in {} quantifier", // QuantifierOutOfOrder
|
||||
REGEXP_ERROR_PREFIX "nothing to repeat", // QuantifierWithoutAtom
|
||||
REGEXP_ERROR_PREFIX "number too large in {} quantifier", // QuantifierTooLarge
|
||||
REGEXP_ERROR_PREFIX "quantifier is unmatched", // QuantifierUnmatched
|
||||
REGEXP_ERROR_PREFIX "missing )", // MissingParentheses
|
||||
REGEXP_ERROR_PREFIX "unmatched parentheses", // ParenthesesUnmatched
|
||||
REGEXP_ERROR_PREFIX "unrecognized character after (?", // ParenthesesTypeInvalid
|
||||
REGEXP_ERROR_PREFIX "invalid group specifier name", // InvalidGroupName
|
||||
REGEXP_ERROR_PREFIX "duplicate group specifier name", // DuplicateGroupName
|
||||
REGEXP_ERROR_PREFIX "missing terminating ] for character class", // CharacterClassUnmatched
|
||||
REGEXP_ERROR_PREFIX "character class is invalid", // CharacterClassInvalid
|
||||
REGEXP_ERROR_PREFIX "range out of order in character class", // CharacterClassOutOfOrder
|
||||
REGEXP_ERROR_PREFIX "\\ at end of pattern", // EscapeUnterminated
|
||||
REGEXP_ERROR_PREFIX "invalid unicode {} escape", // InvalidUnicodeEscape
|
||||
REGEXP_ERROR_PREFIX "invalid class escape", // InvalidClassEscape
|
||||
REGEXP_ERROR_PREFIX "invalid backreference for unicode pattern", // InvalidBackreference
|
||||
REGEXP_ERROR_PREFIX "invalid escaped character for unicode pattern", // InvalidIdentityEscape
|
||||
REGEXP_ERROR_PREFIX "invalid property expression", // InvalidUnicodePropertyExpression
|
||||
REGEXP_ERROR_PREFIX "invalid decimal escape", // InvalidDecimalEscape
|
||||
REGEXP_ERROR_PREFIX "invalid quantifier", // InvalidQuantifier
|
||||
REGEXP_ERROR_PREFIX "too many nested disjunctions", // TooManyDisjunctions
|
||||
REGEXP_ERROR_PREFIX "pattern exceeds string length limits", // OffsetTooLarge
|
||||
REGEXP_ERROR_PREFIX "invalid flags" // InvalidRegularExpressionFlags
|
||||
nullptr, // NoError
|
||||
REGEXP_ERROR_PREFIX "regular expression too large", // PatternTooLarge
|
||||
REGEXP_ERROR_PREFIX "numbers out of order in {} quantifier", // QuantifierOutOfOrder
|
||||
REGEXP_ERROR_PREFIX "nothing to repeat", // QuantifierWithoutAtom
|
||||
REGEXP_ERROR_PREFIX "number too large in {} quantifier", // QuantifierTooLarge
|
||||
REGEXP_ERROR_PREFIX "quantifier is unmatched", // QuantifierUnmatched
|
||||
REGEXP_ERROR_PREFIX "missing )", // MissingParentheses
|
||||
REGEXP_ERROR_PREFIX "unmatched parentheses", // ParenthesesUnmatched
|
||||
REGEXP_ERROR_PREFIX "unrecognized character after (?", // ParenthesesTypeInvalid
|
||||
REGEXP_ERROR_PREFIX "invalid group specifier name", // InvalidGroupName
|
||||
REGEXP_ERROR_PREFIX "duplicate group specifier name", // DuplicateGroupName
|
||||
REGEXP_ERROR_PREFIX "missing terminating ] for character class", // CharacterClassUnmatched
|
||||
REGEXP_ERROR_PREFIX "character class is invalid", // CharacterClassInvalid
|
||||
REGEXP_ERROR_PREFIX "range out of order in character class", // CharacterClassOutOfOrder
|
||||
REGEXP_ERROR_PREFIX "\\ at end of pattern", // EscapeUnterminated
|
||||
REGEXP_ERROR_PREFIX "invalid unicode {} escape", // InvalidUnicodeEscape
|
||||
REGEXP_ERROR_PREFIX "invalid class escape", // InvalidClassEscape
|
||||
REGEXP_ERROR_PREFIX "invalid backreference for unicode pattern", // InvalidBackreference
|
||||
REGEXP_ERROR_PREFIX "invalid escaped character for unicode pattern", // InvalidIdentityEscape
|
||||
REGEXP_ERROR_PREFIX "invalid property expression", // InvalidUnicodePropertyExpression
|
||||
REGEXP_ERROR_PREFIX "invalid decimal escape", // InvalidDecimalEscape
|
||||
REGEXP_ERROR_PREFIX "invalid quantifier", // InvalidQuantifier
|
||||
REGEXP_ERROR_PREFIX "too many nested disjunctions", // TooManyDisjunctions
|
||||
REGEXP_ERROR_PREFIX "pattern exceeds string length limits", // OffsetTooLarge
|
||||
REGEXP_ERROR_PREFIX "invalid flags" // InvalidRegularExpressionFlags
|
||||
};
|
||||
|
||||
return errorMessages[static_cast<unsigned>(error)];
|
||||
}
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
7
third_party/yarr/YarrErrorCode.h
vendored
7
third_party/yarr/YarrErrorCode.h
vendored
|
|
@ -25,7 +25,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
enum class ErrorCode : unsigned {
|
||||
NoError = 0,
|
||||
|
|
@ -60,5 +61,5 @@ inline bool hasError(ErrorCode errorCode)
|
|||
{
|
||||
return errorCode != ErrorCode::NoError;
|
||||
}
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
55
third_party/yarr/YarrInterpreter.cpp
vendored
55
third_party/yarr/YarrInterpreter.cpp
vendored
|
|
@ -33,9 +33,10 @@
|
|||
|
||||
using namespace WTF;
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
template<typename CharType>
|
||||
template <typename CharType>
|
||||
class Interpreter {
|
||||
public:
|
||||
struct ParenthesesDisjunctionContext;
|
||||
|
|
@ -60,8 +61,7 @@ public:
|
|||
--backTrack->matchAmount;
|
||||
}
|
||||
|
||||
struct DisjunctionContext
|
||||
{
|
||||
struct DisjunctionContext {
|
||||
DisjunctionContext()
|
||||
: term(0)
|
||||
{
|
||||
|
|
@ -91,8 +91,7 @@ public:
|
|||
allocatorPool = allocatorPool->dealloc(context);
|
||||
}
|
||||
|
||||
struct ParenthesesDisjunctionContext
|
||||
{
|
||||
struct ParenthesesDisjunctionContext {
|
||||
ParenthesesDisjunctionContext(unsigned* output, ByteTerm& term)
|
||||
: next(0)
|
||||
{
|
||||
|
|
@ -184,13 +183,13 @@ public:
|
|||
if (U16_IS_LEAD(result) && decodeSurrogatePairs && p + 1 < length && U16_IS_TRAIL(input[p + 1])) {
|
||||
if (atEnd())
|
||||
return -1;
|
||||
|
||||
|
||||
result = U16_GET_SUPPLEMENTARY(result, input[p + 1]);
|
||||
next();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int readSurrogatePairChecked(unsigned negativePositionOffset)
|
||||
{
|
||||
RELEASE_ASSERT(pos >= negativePositionOffset);
|
||||
|
|
@ -1003,7 +1002,7 @@ public:
|
|||
// The match failed; try to find an alternate point to carry on from.
|
||||
resetMatches(term, context);
|
||||
freeParenthesesDisjunctionContext(context);
|
||||
|
||||
|
||||
if (fixedMatchResult != JSRegExpNoMatch)
|
||||
return fixedMatchResult;
|
||||
JSRegExpResult backtrackResult = parenthesesDoBacktrack(term, backTrack);
|
||||
|
|
@ -1221,7 +1220,9 @@ public:
|
|||
unsigned matchEnd = input.getPos();
|
||||
|
||||
for (; (matchEnd != input.end())
|
||||
&& (!testCharacterClass(pattern->newlineCharacterClass, input.reread(matchEnd))); matchEnd++) { }
|
||||
&& (!testCharacterClass(pattern->newlineCharacterClass, input.reread(matchEnd)));
|
||||
matchEnd++) {
|
||||
}
|
||||
|
||||
if (((matchBegin && term.anchors.m_bol)
|
||||
|| ((matchEnd != input.end()) && term.anchors.m_eol))
|
||||
|
|
@ -1233,8 +1234,16 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
#define MATCH_NEXT() { ++context->term; goto matchAgain; }
|
||||
#define BACKTRACK() { --context->term; goto backtrack; }
|
||||
#define MATCH_NEXT() \
|
||||
{ \
|
||||
++context->term; \
|
||||
goto matchAgain; \
|
||||
}
|
||||
#define BACKTRACK() \
|
||||
{ \
|
||||
--context->term; \
|
||||
goto backtrack; \
|
||||
}
|
||||
#define currentTerm() (disjunction->terms[context->term])
|
||||
JSRegExpResult matchDisjunction(ByteDisjunction* disjunction, DisjunctionContext* context, bool btrack = false)
|
||||
{
|
||||
|
|
@ -1340,7 +1349,7 @@ public:
|
|||
ASSERT(U_IS_BMP(currentTerm().atom.patternCharacter));
|
||||
|
||||
unsigned position = input.getPos(); // May need to back out reading a surrogate pair.
|
||||
|
||||
|
||||
for (unsigned matchAmount = 0; matchAmount < currentTerm().atom.quantityMaxCount; ++matchAmount) {
|
||||
if (!checkCasedCharacter(currentTerm().atom.casedCharacter.lo, currentTerm().atom.casedCharacter.hi, currentTerm().inputPosition - matchAmount)) {
|
||||
input.setPos(position);
|
||||
|
|
@ -1379,7 +1388,7 @@ public:
|
|||
|
||||
// Case insensitive matching of unicode characters is handled as TypeCharacterClass.
|
||||
ASSERT(!unicode || U_IS_BMP(currentTerm().atom.patternCharacter));
|
||||
|
||||
|
||||
backTrack->matchAmount = 0;
|
||||
MATCH_NEXT();
|
||||
}
|
||||
|
|
@ -1397,7 +1406,7 @@ public:
|
|||
|
||||
if (result == JSRegExpMatch) {
|
||||
MATCH_NEXT();
|
||||
} else if (result != JSRegExpNoMatch)
|
||||
} else if (result != JSRegExpNoMatch)
|
||||
return result;
|
||||
|
||||
BACKTRACK();
|
||||
|
|
@ -1435,7 +1444,7 @@ public:
|
|||
case ByteTerm::TypeUncheckInput:
|
||||
input.uncheckInput(currentTerm().checkInputCount);
|
||||
MATCH_NEXT();
|
||||
|
||||
|
||||
case ByteTerm::TypeDotStarEnclosure:
|
||||
if (matchDotStarEnclosure(currentTerm(), context))
|
||||
return JSRegExpMatch;
|
||||
|
|
@ -1639,7 +1648,7 @@ class ByteCompiler {
|
|||
struct ParenthesesStackEntry {
|
||||
unsigned beginTerm;
|
||||
unsigned savedAlternativeIndex;
|
||||
ParenthesesStackEntry(unsigned beginTerm, unsigned savedAlternativeIndex/*, unsigned subpatternId, bool capture = false*/)
|
||||
ParenthesesStackEntry(unsigned beginTerm, unsigned savedAlternativeIndex /*, unsigned subpatternId, bool capture = false*/)
|
||||
: beginTerm(beginTerm)
|
||||
, savedAlternativeIndex(savedAlternativeIndex)
|
||||
{
|
||||
|
|
@ -1671,7 +1680,7 @@ public:
|
|||
{
|
||||
m_bodyDisjunction->terms.append(ByteTerm::UncheckInput(count));
|
||||
}
|
||||
|
||||
|
||||
void assertionBOL(unsigned inputPosition)
|
||||
{
|
||||
m_bodyDisjunction->terms.append(ByteTerm::BOL(inputPosition));
|
||||
|
|
@ -2041,12 +2050,12 @@ public:
|
|||
break;
|
||||
|
||||
case PatternTerm::TypeCharacterClass:
|
||||
atomCharacterClass(term.characterClass, term.invert(), currentCountAlreadyChecked- term.inputPosition, term.frameLocation, term.quantityMaxCount, term.quantityType);
|
||||
atomCharacterClass(term.characterClass, term.invert(), currentCountAlreadyChecked - term.inputPosition, term.frameLocation, term.quantityMaxCount, term.quantityType);
|
||||
break;
|
||||
|
||||
case PatternTerm::TypeBackReference:
|
||||
atomBackReference(term.backReferenceSubpatternId, currentCountAlreadyChecked - term.inputPosition, term.frameLocation, term.quantityMaxCount, term.quantityType);
|
||||
break;
|
||||
break;
|
||||
|
||||
case PatternTerm::TypeForwardReference:
|
||||
break;
|
||||
|
|
@ -2110,6 +2119,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
YarrPattern& m_pattern;
|
||||
std::unique_ptr<ByteDisjunction> m_bodyDisjunction;
|
||||
|
|
@ -2149,6 +2159,5 @@ COMPILE_ASSERT(sizeof(BackTrackInfoAlternative) == (YarrStackSpaceForBackTrackIn
|
|||
COMPILE_ASSERT(sizeof(BackTrackInfoParentheticalAssertion) == (YarrStackSpaceForBackTrackInfoParentheticalAssertion * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheticalAssertion);
|
||||
COMPILE_ASSERT(sizeof(BackTrackInfoParenthesesOnce) == (YarrStackSpaceForBackTrackInfoParenthesesOnce * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParenthesesOnce);
|
||||
COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoParentheses) <= (YarrStackSpaceForBackTrackInfoParentheses * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheses);
|
||||
|
||||
|
||||
} }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
third_party/yarr/YarrInterpreter.h
vendored
19
third_party/yarr/YarrInterpreter.h
vendored
|
|
@ -32,7 +32,8 @@ class BumpPointerAllocator;
|
|||
}
|
||||
using WTF::BumpPointerAllocator;
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
class ByteDisjunction;
|
||||
|
||||
|
|
@ -326,6 +327,7 @@ struct ByteTerm {
|
|||
|
||||
class ByteDisjunction {
|
||||
WTF_MAKE_FAST_ALLOCATED;
|
||||
|
||||
public:
|
||||
ByteDisjunction(unsigned numSubpatterns, unsigned frameSize)
|
||||
: m_numSubpatterns(numSubpatterns)
|
||||
|
|
@ -334,14 +336,14 @@ public:
|
|||
}
|
||||
|
||||
size_t estimatedSizeInBytes() const { return terms.capacity() * sizeof(ByteTerm); }
|
||||
|
||||
Vector<ByteTerm> terms;
|
||||
unsigned m_numSubpatterns;
|
||||
unsigned m_frameSize;
|
||||
};
|
||||
|
||||
struct BytecodePattern : public gc {
|
||||
struct BytecodePattern : public gc {
|
||||
WTF_MAKE_FAST_ALLOCATED;
|
||||
|
||||
public:
|
||||
BytecodePattern(std::unique_ptr<ByteDisjunction> body, Vector<std::unique_ptr<ByteDisjunction>>& parenthesesInfoToAdopt, YarrPattern& pattern, BumpPointerAllocator* allocator)
|
||||
: m_body(WTFMove(body))
|
||||
|
|
@ -362,10 +364,11 @@ public:
|
|||
m_userCharacterClasses.swap(pattern.m_userCharacterClasses);
|
||||
m_userCharacterClasses.shrinkToFit();
|
||||
|
||||
GC_REGISTER_FINALIZER_NO_ORDER(this, [] (void* obj, void* cd) {
|
||||
GC_REGISTER_FINALIZER_NO_ORDER(this, [](void* obj, void* cd) {
|
||||
BytecodePattern* pattern = (BytecodePattern*)obj;
|
||||
pattern->clear();
|
||||
}, NULL, NULL, NULL);
|
||||
},
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
~BytecodePattern()
|
||||
|
|
@ -387,13 +390,11 @@ public:
|
|||
}
|
||||
|
||||
size_t estimatedSizeInBytes() const { return m_body->estimatedSizeInBytes(); }
|
||||
|
||||
bool ignoreCase() const { return m_flags & FlagIgnoreCase; }
|
||||
bool multiline() const { return m_flags & FlagMultiline; }
|
||||
bool sticky() const { return m_flags & FlagSticky; }
|
||||
bool unicode() const { return m_flags & FlagUnicode; }
|
||||
bool dotAll() const { return m_flags & FlagDotAll; }
|
||||
|
||||
std::unique_ptr<ByteDisjunction> m_body;
|
||||
RegExpFlags m_flags;
|
||||
// Each BytecodePattern is associated with a RegExp, each RegExp is associated
|
||||
|
|
@ -412,5 +413,5 @@ JS_EXPORT_PRIVATE std::unique_ptr<BytecodePattern> byteCompile(YarrPattern&, Bum
|
|||
JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, const String& input, unsigned start, unsigned* output);
|
||||
unsigned interpret(BytecodePattern*, const LChar* input, unsigned length, unsigned start, unsigned* output);
|
||||
unsigned interpret(BytecodePattern*, const UChar* input, unsigned length, unsigned start, unsigned* output);
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
81
third_party/yarr/YarrParser.h
vendored
81
third_party/yarr/YarrParser.h
vendored
|
|
@ -29,13 +29,14 @@
|
|||
#include "YarrPattern.h"
|
||||
#include "YarrUnicodeProperties.h"
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
// The Parser class should not be used directly - only via the Yarr::parse() method.
|
||||
template<class Delegate, typename CharType>
|
||||
template <class Delegate, typename CharType>
|
||||
class Parser {
|
||||
private:
|
||||
template<class FriendDelegate>
|
||||
template <class FriendDelegate>
|
||||
friend ErrorCode parse(FriendDelegate&, const String& pattern, bool isUnicode, unsigned backReferenceLimit);
|
||||
|
||||
/*
|
||||
|
|
@ -118,13 +119,13 @@ private:
|
|||
m_state = Empty;
|
||||
return;
|
||||
|
||||
// See coment in atomBuiltInCharacterClass below.
|
||||
// This too is technically an error, per ECMA-262, and again we
|
||||
// we chose to allow this. Note a subtlely here that while we
|
||||
// diverge from the spec's definition of CharacterRange we do
|
||||
// remain in compliance with the grammar. For example, consider
|
||||
// the expression /[\d-a-z]/. We comply with the grammar in
|
||||
// this case by not allowing a-z to be matched as a range.
|
||||
// See coment in atomBuiltInCharacterClass below.
|
||||
// This too is technically an error, per ECMA-262, and again we
|
||||
// we chose to allow this. Note a subtlely here that while we
|
||||
// diverge from the spec's definition of CharacterRange we do
|
||||
// remain in compliance with the grammar. For example, consider
|
||||
// the expression /[\d-a-z]/. We comply with the grammar in
|
||||
// this case by not allowing a-z to be matched as a range.
|
||||
case AfterCharacterClassHyphen:
|
||||
m_delegate.atomCharacterClassAtom(ch);
|
||||
m_state = Empty;
|
||||
|
|
@ -150,14 +151,14 @@ private:
|
|||
m_delegate.atomCharacterClassBuiltIn(classID, invert);
|
||||
return;
|
||||
|
||||
// If we hit either of these cases, we have an invalid range that
|
||||
// looks something like /[x-\d]/ or /[\d-\d]/.
|
||||
// According to ECMA-262 this should be a syntax error, but
|
||||
// empirical testing shows this to break teh webz. Instead we
|
||||
// comply with to the ECMA-262 grammar, and assume the grammar to
|
||||
// have matched the range correctly, but tweak our interpretation
|
||||
// of CharacterRange. Effectively we implicitly handle the hyphen
|
||||
// as if it were escaped, e.g. /[\w-_]/ is treated as /[\w\-_]/.
|
||||
// If we hit either of these cases, we have an invalid range that
|
||||
// looks something like /[x-\d]/ or /[\d-\d]/.
|
||||
// According to ECMA-262 this should be a syntax error, but
|
||||
// empirical testing shows this to break teh webz. Instead we
|
||||
// comply with to the ECMA-262 grammar, and assume the grammar to
|
||||
// have matched the range correctly, but tweak our interpretation
|
||||
// of CharacterRange. Effectively we implicitly handle the hyphen
|
||||
// as if it were escaped, e.g. /[\w-_]/ is treated as /[\w\-_]/.
|
||||
case CachedCharacterHyphen:
|
||||
m_delegate.atomCharacterClassAtom(m_character);
|
||||
m_delegate.atomCharacterClassAtom('-');
|
||||
|
|
@ -192,7 +193,6 @@ private:
|
|||
NO_RETURN_DUE_TO_ASSERT void atomNamedBackReference(String) { RELEASE_ASSERT_NOT_REACHED(); }
|
||||
NO_RETURN_DUE_TO_ASSERT bool isValidNamedForwardReference(const String&) { RELEASE_ASSERT_NOT_REACHED(); }
|
||||
NO_RETURN_DUE_TO_ASSERT void atomNamedForwardReference(const String&) { RELEASE_ASSERT_NOT_REACHED(); }
|
||||
|
||||
private:
|
||||
Delegate& m_delegate;
|
||||
ErrorCode& m_errorCode;
|
||||
|
|
@ -248,7 +248,7 @@ private:
|
|||
* parsed was an atom (outside of a characted class \b and \B will be
|
||||
* interpreted as assertions).
|
||||
*/
|
||||
template<bool inCharacterClass, class EscapeDelegate>
|
||||
template <bool inCharacterClass, class EscapeDelegate>
|
||||
bool parseEscape(EscapeDelegate& delegate)
|
||||
{
|
||||
ASSERT(!hasError(m_errorCode));
|
||||
|
|
@ -476,9 +476,9 @@ private:
|
|||
}
|
||||
|
||||
if (delegate.isValidNamedForwardReference(groupName.value())) {
|
||||
delegate.atomNamedForwardReference(groupName.value());
|
||||
break;
|
||||
}
|
||||
delegate.atomNamedForwardReference(groupName.value());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (m_isUnicode) {
|
||||
|
|
@ -725,7 +725,6 @@ private:
|
|||
if (m_isUnicode) {
|
||||
m_isLookaheadExistOnParentheses.push_back(isLookhead);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -802,8 +801,7 @@ private:
|
|||
lastTokenWasAnAtom = false;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
{
|
||||
case ')': {
|
||||
bool isLookahead = parseParenthesesEnd();
|
||||
lastTokenWasAnAtom = true;
|
||||
|
||||
|
|
@ -904,8 +902,8 @@ private:
|
|||
|
||||
restoreState(state);
|
||||
}
|
||||
// if we did not find a complete quantifer, fall through to the default case.
|
||||
FALLTHROUGH;
|
||||
// if we did not find a complete quantifer, fall through to the default case.
|
||||
FALLTHROUGH;
|
||||
|
||||
defaultCase:
|
||||
default:
|
||||
|
|
@ -1085,7 +1083,7 @@ private:
|
|||
{
|
||||
unsigned n = consumeDigit();
|
||||
// check for overflow.
|
||||
for (unsigned newValue; peekIsDigit() && ((newValue = n * 10 + peekDigit()) >= n); ) {
|
||||
for (unsigned newValue; peekIsDigit() && ((newValue = n * 10 + peekDigit()) >= n);) {
|
||||
n = newValue;
|
||||
consume();
|
||||
}
|
||||
|
|
@ -1137,11 +1135,10 @@ private:
|
|||
ParseState state = saveState();
|
||||
UChar32 surrogate2 = consume();
|
||||
if (U16_IS_TRAIL(surrogate2)) {
|
||||
ch = U16_GET_SUPPLEMENTARY(ch, surrogate2);
|
||||
}
|
||||
else
|
||||
restoreState(state);
|
||||
}
|
||||
ch = U16_GET_SUPPLEMENTARY(ch, surrogate2);
|
||||
} else
|
||||
restoreState(state);
|
||||
}
|
||||
|
||||
|
||||
if (isIdentifierStart(ch)) {
|
||||
|
|
@ -1156,7 +1153,7 @@ private:
|
|||
if (U16_IS_TRAIL(surrogate2))
|
||||
ch = U16_GET_SUPPLEMENTARY(ch, surrogate2);
|
||||
else
|
||||
restoreState(state);
|
||||
restoreState(state);
|
||||
}
|
||||
if (ch == '>')
|
||||
return Optional<String>(identifierBuilder.toString());
|
||||
|
|
@ -1229,13 +1226,13 @@ private:
|
|||
|
||||
Delegate& m_delegate;
|
||||
unsigned m_backReferenceLimit;
|
||||
ErrorCode m_errorCode { ErrorCode::NoError };
|
||||
ErrorCode m_errorCode{ ErrorCode::NoError };
|
||||
const CharType* m_data;
|
||||
unsigned m_size;
|
||||
unsigned m_index { 0 };
|
||||
unsigned m_index{ 0 };
|
||||
bool m_isUnicode;
|
||||
unsigned m_parenthesesNestingDepth { 0 };
|
||||
unsigned m_squareBracketsNestingDepth { 0 };
|
||||
unsigned m_parenthesesNestingDepth{ 0 };
|
||||
unsigned m_squareBracketsNestingDepth{ 0 };
|
||||
std::vector<bool> m_isLookaheadExistOnParentheses; // this is used only unicode flag is true
|
||||
HashSet<String> m_captureGroupNames;
|
||||
|
||||
|
|
@ -1305,12 +1302,12 @@ private:
|
|||
* will be greater than the subpatternId passed to end.
|
||||
*/
|
||||
|
||||
template<class Delegate>
|
||||
template <class Delegate>
|
||||
ErrorCode parse(Delegate& delegate, const String& pattern, bool isUnicode, unsigned backReferenceLimit = quantifyInfinite)
|
||||
{
|
||||
if (pattern.is8Bit())
|
||||
return Parser<Delegate, LChar>(delegate, pattern, isUnicode, backReferenceLimit).parse();
|
||||
return Parser<Delegate, UChar>(delegate, pattern, isUnicode, backReferenceLimit).parse();
|
||||
}
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
72
third_party/yarr/YarrPattern.cpp
vendored
72
third_party/yarr/YarrPattern.cpp
vendored
|
|
@ -33,7 +33,8 @@
|
|||
|
||||
using namespace WTF;
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
#include "RegExpJitTables.h"
|
||||
|
||||
|
|
@ -72,8 +73,8 @@ public:
|
|||
void appendInverted(const CharacterClass* other)
|
||||
{
|
||||
auto addSortedInverted = [&](UChar32 min, UChar32 max,
|
||||
const Vector<UChar32>& srcMatches, const Vector<CharacterRange>& srcRanges,
|
||||
Vector<UChar32>& destMatches, Vector<CharacterRange>& destRanges) {
|
||||
const Vector<UChar32>& srcMatches, const Vector<CharacterRange>& srcRanges,
|
||||
Vector<UChar32>& destMatches, Vector<CharacterRange>& destRanges) {
|
||||
|
||||
auto addSortedMatchOrRange = [&](UChar32 lo, UChar32 hiPlusOne) {
|
||||
if (lo < hiPlusOne) {
|
||||
|
|
@ -172,9 +173,9 @@ public:
|
|||
|
||||
if (m_isCaseInsensitive) {
|
||||
if ((asciiLo <= 'Z') && (asciiHi >= 'A'))
|
||||
addSortedRange(m_ranges, std::max(asciiLo, 'A')+('a'-'A'), std::min(asciiHi, 'Z')+('a'-'A'));
|
||||
addSortedRange(m_ranges, std::max(asciiLo, 'A') + ('a' - 'A'), std::min(asciiHi, 'Z') + ('a' - 'A'));
|
||||
if ((asciiLo <= 'z') && (asciiHi >= 'a'))
|
||||
addSortedRange(m_ranges, std::max(asciiLo, 'a')+('A'-'a'), std::min(asciiHi, 'z')+('A'-'a'));
|
||||
addSortedRange(m_ranges, std::max(asciiLo, 'a') + ('A' - 'a'), std::min(asciiHi, 'z') + ('A' - 'a'));
|
||||
}
|
||||
}
|
||||
if (isASCII(hi))
|
||||
|
|
@ -229,7 +230,6 @@ public:
|
|||
++info;
|
||||
lo = info->begin;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<CharacterClass> charClass()
|
||||
|
|
@ -269,7 +269,7 @@ private:
|
|||
while (range) {
|
||||
unsigned index = range >> 1;
|
||||
|
||||
int val = matches[pos+index] - ch;
|
||||
int val = matches[pos + index] - ch;
|
||||
if (!val)
|
||||
return;
|
||||
else if (val > 0) {
|
||||
|
|
@ -297,8 +297,8 @@ private:
|
|||
addSortedRange(isASCII(ch) ? m_ranges : m_rangesUnicode, lo, hi);
|
||||
return;
|
||||
}
|
||||
pos += (index+1);
|
||||
range -= (index+1);
|
||||
pos += (index + 1);
|
||||
range -= (index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -358,7 +358,6 @@ private:
|
|||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void coalesceTables()
|
||||
|
|
@ -456,20 +455,18 @@ public:
|
|||
m_unmatchedNamedForwardReferences.clear();
|
||||
bool unique = true;
|
||||
for (auto& entry : m_pattern.m_namedForwardReferences) {
|
||||
for(auto& entry2 : m_pattern.m_captureGroupNames){
|
||||
if (entry.equals(entry2)){
|
||||
unique = false;
|
||||
}
|
||||
if(unique) {
|
||||
m_unmatchedNamedForwardReferences.append(entry);
|
||||
unique = true;
|
||||
}
|
||||
for (auto& entry2 : m_pattern.m_captureGroupNames) {
|
||||
if (entry.equals(entry2)) {
|
||||
unique = false;
|
||||
}
|
||||
if (unique) {
|
||||
m_unmatchedNamedForwardReferences.append(entry);
|
||||
unique = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void assertionBOL()
|
||||
{
|
||||
if (!m_alternative->m_terms.size() && !m_invertParentheticalAssertion) {
|
||||
|
|
@ -688,20 +685,20 @@ public:
|
|||
|
||||
bool isValidNamedForwardReference(const String& subpatternName)
|
||||
{
|
||||
for (auto& entry : m_unmatchedNamedForwardReferences) {
|
||||
if (entry.equals(subpatternName)){
|
||||
return false;
|
||||
}
|
||||
for (auto& entry : m_unmatchedNamedForwardReferences) {
|
||||
if (entry.equals(subpatternName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void atomNamedForwardReference(const String& subpatternName)
|
||||
{
|
||||
for(auto& entry : m_pattern.m_namedForwardReferences) {
|
||||
if(entry.equals(subpatternName)) {
|
||||
return;
|
||||
}
|
||||
for (auto& entry : m_pattern.m_namedForwardReferences) {
|
||||
if (entry.equals(subpatternName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_pattern.m_namedForwardReferences.add(subpatternName);
|
||||
m_alternative->m_terms.append(PatternTerm::ForwardReference());
|
||||
|
|
@ -1064,7 +1061,7 @@ public:
|
|||
if ((firstNonAnchorTerm.type != PatternTerm::TypeCharacterClass)
|
||||
|| (firstNonAnchorTerm.characterClass != dotCharacterClass)
|
||||
|| !((firstNonAnchorTerm.quantityType == QuantifierGreedy)
|
||||
|| (firstNonAnchorTerm.quantityType == QuantifierNonGreedy)))
|
||||
|| (firstNonAnchorTerm.quantityType == QuantifierNonGreedy)))
|
||||
return;
|
||||
|
||||
firstExpressionTerm = termIndex + 1;
|
||||
|
|
@ -1104,7 +1101,7 @@ private:
|
|||
{
|
||||
if (!m_stackLimit)
|
||||
return true;
|
||||
// ASSERT(Thread::current().stack().isGrowingDownward());
|
||||
// ASSERT(Thread::current().stack().isGrowingDownward());
|
||||
#ifndef STACK_GROWS_DOWN
|
||||
#error "ASSERT(Thread::current().stack().isGrowingDownward());"
|
||||
#endif
|
||||
|
|
@ -1118,8 +1115,8 @@ private:
|
|||
CharacterClassConstructor m_characterClassConstructor;
|
||||
Vector<String> m_unmatchedNamedForwardReferences;
|
||||
void* m_stackLimit;
|
||||
bool m_invertCharacterClass { false };
|
||||
bool m_invertParentheticalAssertion { false };
|
||||
bool m_invertCharacterClass{ false };
|
||||
bool m_invertParentheticalAssertion{ false };
|
||||
};
|
||||
|
||||
ErrorCode YarrPattern::compile(const String& patternString, void* stackLimit)
|
||||
|
|
@ -1175,10 +1172,11 @@ YarrPattern::YarrPattern(const String& pattern, RegExpFlags flags, ErrorCode& er
|
|||
{
|
||||
error = compile(pattern, stackLimit);
|
||||
|
||||
GC_REGISTER_FINALIZER_NO_ORDER(this, [] (void* obj, void* cd) {
|
||||
GC_REGISTER_FINALIZER_NO_ORDER(this, [](void* obj, void* cd) {
|
||||
YarrPattern* pattern = (YarrPattern*)obj;
|
||||
pattern->reset();
|
||||
}, NULL, NULL, NULL);
|
||||
},
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
std::unique_ptr<CharacterClass> anycharCreate()
|
||||
|
|
@ -1190,5 +1188,5 @@ std::unique_ptr<CharacterClass> anycharCreate()
|
|||
characterClass->m_anyCharacter = true;
|
||||
return characterClass;
|
||||
}
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
175
third_party/yarr/YarrPattern.h
vendored
175
third_party/yarr/YarrPattern.h
vendored
|
|
@ -31,7 +31,8 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
enum RegExpFlags {
|
||||
NoFlags = 0,
|
||||
|
|
@ -49,8 +50,8 @@ struct YarrPattern;
|
|||
struct PatternDisjunction;
|
||||
|
||||
struct CharacterRange {
|
||||
UChar32 begin { 0 };
|
||||
UChar32 end { 0x10ffff };
|
||||
UChar32 begin{ 0 };
|
||||
UChar32 end{ 0x10ffff };
|
||||
|
||||
CharacterRange(UChar32 begin, UChar32 end)
|
||||
: begin(begin)
|
||||
|
|
@ -61,6 +62,7 @@ struct CharacterRange {
|
|||
|
||||
struct CharacterClass {
|
||||
WTF_MAKE_FAST_ALLOCATED;
|
||||
|
||||
public:
|
||||
// All CharacterClass instances have to have the full set of matches and ranges,
|
||||
// they may have an optional m_table for faster lookups (which must match the
|
||||
|
|
@ -121,8 +123,8 @@ struct PatternTerm {
|
|||
TypeParentheticalAssertion,
|
||||
TypeDotStarEnclosure,
|
||||
} type;
|
||||
bool m_capture :1;
|
||||
bool m_invert :1;
|
||||
bool m_capture : 1;
|
||||
bool m_invert : 1;
|
||||
union {
|
||||
UChar32 patternCharacter;
|
||||
CharacterClass* characterClass;
|
||||
|
|
@ -264,6 +266,7 @@ struct PatternTerm {
|
|||
|
||||
struct PatternAlternative {
|
||||
WTF_MAKE_FAST_ALLOCATED;
|
||||
|
||||
public:
|
||||
PatternAlternative(PatternDisjunction* disjunction)
|
||||
: m_parent(disjunction)
|
||||
|
|
@ -307,6 +310,7 @@ public:
|
|||
|
||||
struct PatternDisjunction {
|
||||
WTF_MAKE_FAST_ALLOCATED;
|
||||
|
||||
public:
|
||||
PatternDisjunction(PatternAlternative* parent = 0)
|
||||
: m_parent(parent)
|
||||
|
|
@ -346,7 +350,8 @@ std::unique_ptr<CharacterClass> nonwordUnicodeIgnoreCaseCharCreate();
|
|||
struct TermChain {
|
||||
TermChain(PatternTerm term)
|
||||
: term(term)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
PatternTerm term;
|
||||
Vector<TermChain> hotTerms;
|
||||
|
|
@ -400,22 +405,21 @@ struct YarrPattern : public gc {
|
|||
return false;
|
||||
bool notContains = true;
|
||||
for (auto& entry : m_namedForwardReferences) {
|
||||
for(auto& entry2 : m_captureGroupNames){
|
||||
if (entry.equals(entry2)){
|
||||
notContains = false;
|
||||
break;
|
||||
for (auto& entry2 : m_captureGroupNames) {
|
||||
if (entry.equals(entry2)) {
|
||||
notContains = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(notContains)
|
||||
{
|
||||
return true;
|
||||
if (notContains) {
|
||||
return true;
|
||||
}
|
||||
notContains = true;
|
||||
}
|
||||
notContains = true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
bool containsUnsignedLengthPattern()
|
||||
{
|
||||
return m_containsUnsignedLengthPattern;
|
||||
|
|
@ -523,16 +527,15 @@ struct YarrPattern : public gc {
|
|||
bool sticky() const { return m_flags & FlagSticky; }
|
||||
bool unicode() const { return m_flags & FlagUnicode; }
|
||||
bool dotAll() const { return m_flags & FlagDotAll; }
|
||||
|
||||
bool m_containsBackreferences : 1;
|
||||
bool m_containsBOL : 1;
|
||||
bool m_containsUnsignedLengthPattern : 1;
|
||||
bool m_hasCopiedParenSubexpressions : 1;
|
||||
bool m_saveInitialStartValue : 1;
|
||||
RegExpFlags m_flags;
|
||||
unsigned m_numSubpatterns { 0 };
|
||||
unsigned m_maxBackReference { 0 };
|
||||
unsigned m_initialStartValueFrameLocation { 0 };
|
||||
unsigned m_numSubpatterns{ 0 };
|
||||
unsigned m_maxBackReference{ 0 };
|
||||
unsigned m_initialStartValueFrameLocation{ 0 };
|
||||
PatternDisjunction* m_body;
|
||||
Vector<std::unique_ptr<PatternDisjunction>, 4> m_disjunctions;
|
||||
Vector<std::unique_ptr<CharacterClass>> m_userCharacterClasses;
|
||||
|
|
@ -557,79 +560,79 @@ private:
|
|||
|
||||
ErrorCode compile(const String& patternString, void* stackLimit);
|
||||
|
||||
CharacterClass* anycharCached { nullptr };
|
||||
CharacterClass* newlineCached { nullptr };
|
||||
CharacterClass* digitsCached { nullptr };
|
||||
CharacterClass* spacesCached { nullptr };
|
||||
CharacterClass* wordcharCached { nullptr };
|
||||
CharacterClass* wordUnicodeIgnoreCaseCharCached { nullptr };
|
||||
CharacterClass* nondigitsCached { nullptr };
|
||||
CharacterClass* nonspacesCached { nullptr };
|
||||
CharacterClass* nonwordcharCached { nullptr };
|
||||
CharacterClass* nonwordUnicodeIgnoreCasecharCached { nullptr };
|
||||
CharacterClass* anycharCached{ nullptr };
|
||||
CharacterClass* newlineCached{ nullptr };
|
||||
CharacterClass* digitsCached{ nullptr };
|
||||
CharacterClass* spacesCached{ nullptr };
|
||||
CharacterClass* wordcharCached{ nullptr };
|
||||
CharacterClass* wordUnicodeIgnoreCaseCharCached{ nullptr };
|
||||
CharacterClass* nondigitsCached{ nullptr };
|
||||
CharacterClass* nonspacesCached{ nullptr };
|
||||
CharacterClass* nonwordcharCached{ nullptr };
|
||||
CharacterClass* nonwordUnicodeIgnoreCasecharCached{ nullptr };
|
||||
HashMap<unsigned, CharacterClass*> unicodePropertiesCached;
|
||||
};
|
||||
|
||||
struct BackTrackInfoPatternCharacter {
|
||||
uintptr_t begin; // Only needed for unicode patterns
|
||||
uintptr_t matchAmount;
|
||||
struct BackTrackInfoPatternCharacter {
|
||||
uintptr_t begin; // Only needed for unicode patterns
|
||||
uintptr_t matchAmount;
|
||||
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoPatternCharacter, begin) / sizeof(uintptr_t); }
|
||||
static unsigned matchAmountIndex() { return offsetof(BackTrackInfoPatternCharacter, matchAmount) / sizeof(uintptr_t); }
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoPatternCharacter, begin) / sizeof(uintptr_t); }
|
||||
static unsigned matchAmountIndex() { return offsetof(BackTrackInfoPatternCharacter, matchAmount) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
struct BackTrackInfoCharacterClass {
|
||||
uintptr_t begin; // Only needed for unicode patterns
|
||||
uintptr_t matchAmount;
|
||||
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoCharacterClass, begin) / sizeof(uintptr_t); }
|
||||
static unsigned matchAmountIndex() { return offsetof(BackTrackInfoCharacterClass, matchAmount) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
struct BackTrackInfoBackReference {
|
||||
uintptr_t begin; // Not really needed for greedy quantifiers.
|
||||
uintptr_t matchAmount; // Not really needed for fixed quantifiers.
|
||||
|
||||
unsigned beginIndex() { return offsetof(BackTrackInfoBackReference, begin) / sizeof(uintptr_t); }
|
||||
unsigned matchAmountIndex() { return offsetof(BackTrackInfoBackReference, matchAmount) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
struct BackTrackInfoAlternative {
|
||||
union {
|
||||
uintptr_t offset;
|
||||
};
|
||||
};
|
||||
|
||||
struct BackTrackInfoCharacterClass {
|
||||
uintptr_t begin; // Only needed for unicode patterns
|
||||
uintptr_t matchAmount;
|
||||
struct BackTrackInfoParentheticalAssertion {
|
||||
uintptr_t begin;
|
||||
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoCharacterClass, begin) / sizeof(uintptr_t); }
|
||||
static unsigned matchAmountIndex() { return offsetof(BackTrackInfoCharacterClass, matchAmount) / sizeof(uintptr_t); }
|
||||
};
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoParentheticalAssertion, begin) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
struct BackTrackInfoBackReference {
|
||||
uintptr_t begin; // Not really needed for greedy quantifiers.
|
||||
uintptr_t matchAmount; // Not really needed for fixed quantifiers.
|
||||
struct BackTrackInfoParenthesesOnce {
|
||||
uintptr_t begin;
|
||||
uintptr_t returnAddress;
|
||||
|
||||
unsigned beginIndex() { return offsetof(BackTrackInfoBackReference, begin) / sizeof(uintptr_t); }
|
||||
unsigned matchAmountIndex() { return offsetof(BackTrackInfoBackReference, matchAmount) / sizeof(uintptr_t); }
|
||||
};
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoParenthesesOnce, begin) / sizeof(uintptr_t); }
|
||||
static unsigned returnAddressIndex() { return offsetof(BackTrackInfoParenthesesOnce, returnAddress) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
struct BackTrackInfoAlternative {
|
||||
union {
|
||||
uintptr_t offset;
|
||||
};
|
||||
};
|
||||
struct BackTrackInfoParenthesesTerminal {
|
||||
uintptr_t begin;
|
||||
|
||||
struct BackTrackInfoParentheticalAssertion {
|
||||
uintptr_t begin;
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoParenthesesTerminal, begin) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoParentheticalAssertion, begin) / sizeof(uintptr_t); }
|
||||
};
|
||||
struct BackTrackInfoParentheses {
|
||||
uintptr_t begin;
|
||||
uintptr_t returnAddress;
|
||||
uintptr_t matchAmount;
|
||||
uintptr_t parenContextHead;
|
||||
|
||||
struct BackTrackInfoParenthesesOnce {
|
||||
uintptr_t begin;
|
||||
uintptr_t returnAddress;
|
||||
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoParenthesesOnce, begin) / sizeof(uintptr_t); }
|
||||
static unsigned returnAddressIndex() { return offsetof(BackTrackInfoParenthesesOnce, returnAddress) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
struct BackTrackInfoParenthesesTerminal {
|
||||
uintptr_t begin;
|
||||
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoParenthesesTerminal, begin) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
struct BackTrackInfoParentheses {
|
||||
uintptr_t begin;
|
||||
uintptr_t returnAddress;
|
||||
uintptr_t matchAmount;
|
||||
uintptr_t parenContextHead;
|
||||
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoParentheses, begin) / sizeof(uintptr_t); }
|
||||
static unsigned returnAddressIndex() { return offsetof(BackTrackInfoParentheses, returnAddress) / sizeof(uintptr_t); }
|
||||
static unsigned matchAmountIndex() { return offsetof(BackTrackInfoParentheses, matchAmount) / sizeof(uintptr_t); }
|
||||
static unsigned parenContextHeadIndex() { return offsetof(BackTrackInfoParentheses, parenContextHead) / sizeof(uintptr_t); }
|
||||
};
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
static unsigned beginIndex() { return offsetof(BackTrackInfoParentheses, begin) / sizeof(uintptr_t); }
|
||||
static unsigned returnAddressIndex() { return offsetof(BackTrackInfoParentheses, returnAddress) / sizeof(uintptr_t); }
|
||||
static unsigned matchAmountIndex() { return offsetof(BackTrackInfoParentheses, matchAmount) / sizeof(uintptr_t); }
|
||||
static unsigned parenContextHeadIndex() { return offsetof(BackTrackInfoParentheses, parenContextHead) / sizeof(uintptr_t); }
|
||||
};
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
7
third_party/yarr/YarrSyntaxChecker.cpp
vendored
7
third_party/yarr/YarrSyntaxChecker.cpp
vendored
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
#include "YarrParser.h"
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
class SyntaxChecker {
|
||||
public:
|
||||
|
|
@ -58,5 +59,5 @@ ErrorCode checkSyntax(const String& pattern, const String& flags)
|
|||
SyntaxChecker syntaxChecker;
|
||||
return parse(syntaxChecker, pattern, flags.contains('u'));
|
||||
}
|
||||
|
||||
}} // JSC::Yarr
|
||||
}
|
||||
} // JSC::Yarr
|
||||
|
|
|
|||
9
third_party/yarr/YarrSyntaxChecker.h
vendored
9
third_party/yarr/YarrSyntaxChecker.h
vendored
|
|
@ -20,15 +20,16 @@
|
|||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "YarrErrorCode.h"
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
ErrorCode checkSyntax(const String& pattern, const String& flags);
|
||||
|
||||
}} // JSC::Yarr
|
||||
}
|
||||
} // JSC::Yarr
|
||||
|
|
|
|||
10
third_party/yarr/YarrUnicodeProperties.cpp
vendored
10
third_party/yarr/YarrUnicodeProperties.cpp
vendored
|
|
@ -31,7 +31,8 @@
|
|||
|
||||
using namespace WTF;
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
struct HashIndex {
|
||||
int16_t value;
|
||||
|
|
@ -51,8 +52,7 @@ struct HashTable {
|
|||
|
||||
ALWAYS_INLINE int entry(WTF::String& key) const
|
||||
{
|
||||
for(int i = 0 ; i < numberOfValues; i++)
|
||||
{
|
||||
for (int i = 0; i < numberOfValues; i++) {
|
||||
if (key.impl()->equals(values[i].key, strlen(values[i].key)))
|
||||
return values[i].index;
|
||||
}
|
||||
|
|
@ -99,5 +99,5 @@ std::unique_ptr<CharacterClass> createUnicodeCharacterClassFor(BuiltInCharacterC
|
|||
|
||||
return createFunctions[unicodePropertyIndex]();
|
||||
}
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
9
third_party/yarr/YarrUnicodeProperties.h
vendored
9
third_party/yarr/YarrUnicodeProperties.h
vendored
|
|
@ -20,14 +20,15 @@
|
|||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Yarr.h"
|
||||
|
||||
namespace JSC { namespace Yarr {
|
||||
namespace JSC {
|
||||
namespace Yarr {
|
||||
|
||||
struct CharacterClass;
|
||||
|
||||
|
|
@ -35,5 +36,5 @@ JS_EXPORT_PRIVATE Optional<BuiltInCharacterClassID> unicodeMatchPropertyValue(WT
|
|||
JS_EXPORT_PRIVATE Optional<BuiltInCharacterClassID> unicodeMatchProperty(WTF::String);
|
||||
|
||||
std::unique_ptr<CharacterClass> createUnicodeCharacterClassFor(BuiltInCharacterClassID);
|
||||
|
||||
} } // namespace JSC::Yarr
|
||||
}
|
||||
} // namespace JSC::Yarr
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ import sys
|
|||
from argparse import ArgumentParser
|
||||
from difflib import unified_diff
|
||||
#from check_license import CheckLicenser
|
||||
from os.path import join, relpath, splitext
|
||||
from os.path import abspath, dirname, join, relpath, splitext
|
||||
|
||||
DEFAULT_DIR = dirname(dirname(abspath(__file__)))
|
||||
|
||||
TERM_RED = '\033[1;31m'
|
||||
TERM_GREEN = '\033[1;32m'
|
||||
|
|
@ -34,7 +35,7 @@ TERM_EMPTY = '\033[0m'
|
|||
|
||||
|
||||
clang_format_exts = ['.cpp', '.h']
|
||||
skip_dirs = ['node_modules', 'out', 'test', 'third_party', '.git', 'CMakeFiles']
|
||||
skip_dirs = ['build', 'CMakeFiles', 'docs', 'out', 'test', 'tools', 'double_conversion', 'GCutil', 'lz4', 'rapidjson', 'windows', '.git']
|
||||
skip_files = []
|
||||
|
||||
|
||||
|
|
@ -52,15 +53,13 @@ def is_checked_by_clang(file):
|
|||
|
||||
|
||||
def check_tidy(src_dir, update, clang_format, stats):
|
||||
print('%sprocessing directory: %s%s' % (TERM_PURPLE, src_dir, TERM_EMPTY))
|
||||
print('processing directory: %s' % src_dir)
|
||||
|
||||
for dirpath, _, filenames in os.walk(src_dir):
|
||||
if any(d in relpath(dirpath, src_dir) for d in skip_dirs):
|
||||
continue
|
||||
|
||||
for file in [join(dirpath, name) for name in filenames if is_checked_by_clang(name)]:
|
||||
print(file)
|
||||
|
||||
def report_error(msg, line=None):
|
||||
print('%s%s:%s %s%s' % (TERM_YELLOW, file, '%d:' % line if line else '', msg, TERM_EMPTY))
|
||||
stats.errors += 1
|
||||
|
|
@ -107,14 +106,13 @@ def main():
|
|||
help='path to clang-format (default: %(default)s)')
|
||||
parser.add_argument('--update', action='store_true',
|
||||
help='reformat files')
|
||||
parser.add_argument('dir', nargs='*', default=['.'],
|
||||
help='directory to process (default: .)')
|
||||
parser.add_argument('--dir', metavar='PATH', default=DEFAULT_DIR,
|
||||
help='directory to process (default: %(default)s)')
|
||||
args = parser.parse_args()
|
||||
|
||||
stats = Stats()
|
||||
|
||||
for dir in args.dir:
|
||||
check_tidy(dir, args.update, args.clang_format, stats)
|
||||
check_tidy(args.dir, args.update, args.clang_format, stats)
|
||||
|
||||
print()
|
||||
print('* Total number of files: %d' % stats.files)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue