Commit 6c6a6024 authored by Ng Zhi An's avatar Ng Zhi An Committed by V8 LUCI CQ

[regexp] Fix -Wshadow warnings

Bug: v8:12244,v8:12245
Change-Id: I38c9a767bd17f76bbf269ad79adc6798d94753a2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3273529Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77914}
parent 1033ab21
...@@ -36,22 +36,22 @@ std::ostream& operator<<(std::ostream& os, const RegExpInstruction& inst) { ...@@ -36,22 +36,22 @@ std::ostream& operator<<(std::ostream& os, const RegExpInstruction& inst) {
case RegExpInstruction::ASSERTION: case RegExpInstruction::ASSERTION:
os << "ASSERTION "; os << "ASSERTION ";
switch (inst.payload.assertion_type) { switch (inst.payload.assertion_type) {
case RegExpAssertion::START_OF_INPUT: case RegExpAssertion::Type::START_OF_INPUT:
os << "START_OF_INPUT"; os << "START_OF_INPUT";
break; break;
case RegExpAssertion::END_OF_INPUT: case RegExpAssertion::Type::END_OF_INPUT:
os << "END_OF_INPUT"; os << "END_OF_INPUT";
break; break;
case RegExpAssertion::START_OF_LINE: case RegExpAssertion::Type::START_OF_LINE:
os << "START_OF_LINE"; os << "START_OF_LINE";
break; break;
case RegExpAssertion::END_OF_LINE: case RegExpAssertion::Type::END_OF_LINE:
os << "END_OF_LINE"; os << "END_OF_LINE";
break; break;
case RegExpAssertion::BOUNDARY: case RegExpAssertion::Type::BOUNDARY:
os << "BOUNDARY"; os << "BOUNDARY";
break; break;
case RegExpAssertion::NON_BOUNDARY: case RegExpAssertion::Type::NON_BOUNDARY:
os << "NON_BOUNDARY"; os << "NON_BOUNDARY";
break; break;
} }
......
...@@ -158,7 +158,7 @@ struct RegExpInstruction { ...@@ -158,7 +158,7 @@ struct RegExpInstruction {
return result; return result;
} }
static RegExpInstruction Assertion(RegExpAssertion::AssertionType t) { static RegExpInstruction Assertion(RegExpAssertion::Type t) {
RegExpInstruction result; RegExpInstruction result;
result.opcode = ASSERTION; result.opcode = ASSERTION;
result.payload.assertion_type = t; result.payload.assertion_type = t;
...@@ -174,7 +174,7 @@ struct RegExpInstruction { ...@@ -174,7 +174,7 @@ struct RegExpInstruction {
// Payload of SET_REGISTER_TO_CP and CLEAR_REGISTER: // Payload of SET_REGISTER_TO_CP and CLEAR_REGISTER:
int32_t register_index; int32_t register_index;
// Payload of ASSERTION: // Payload of ASSERTION:
RegExpAssertion::AssertionType assertion_type; RegExpAssertion::Type assertion_type;
} payload; } payload;
STATIC_ASSERT(sizeof(payload) == 4); STATIC_ASSERT(sizeof(payload) == 4);
}; };
......
...@@ -221,7 +221,7 @@ class BytecodeAssembler { ...@@ -221,7 +221,7 @@ class BytecodeAssembler {
void Accept() { code_.Add(RegExpInstruction::Accept(), zone_); } void Accept() { code_.Add(RegExpInstruction::Accept(), zone_); }
void Assertion(RegExpAssertion::AssertionType t) { void Assertion(RegExpAssertion::Type t) {
code_.Add(RegExpInstruction::Assertion(t), zone_); code_.Add(RegExpInstruction::Assertion(t), zone_);
} }
......
...@@ -22,23 +22,23 @@ namespace { ...@@ -22,23 +22,23 @@ namespace {
constexpr int kUndefinedRegisterValue = -1; constexpr int kUndefinedRegisterValue = -1;
template <class Character> template <class Character>
bool SatisfiesAssertion(RegExpAssertion::AssertionType type, bool SatisfiesAssertion(RegExpAssertion::Type type,
base::Vector<const Character> context, int position) { base::Vector<const Character> context, int position) {
DCHECK_LE(position, context.length()); DCHECK_LE(position, context.length());
DCHECK_GE(position, 0); DCHECK_GE(position, 0);
switch (type) { switch (type) {
case RegExpAssertion::START_OF_INPUT: case RegExpAssertion::Type::START_OF_INPUT:
return position == 0; return position == 0;
case RegExpAssertion::END_OF_INPUT: case RegExpAssertion::Type::END_OF_INPUT:
return position == context.length(); return position == context.length();
case RegExpAssertion::START_OF_LINE: case RegExpAssertion::Type::START_OF_LINE:
if (position == 0) return true; if (position == 0) return true;
return unibrow::IsLineTerminator(context[position - 1]); return unibrow::IsLineTerminator(context[position - 1]);
case RegExpAssertion::END_OF_LINE: case RegExpAssertion::Type::END_OF_LINE:
if (position == context.length()) return true; if (position == context.length()) return true;
return unibrow::IsLineTerminator(context[position]); return unibrow::IsLineTerminator(context[position]);
case RegExpAssertion::BOUNDARY: case RegExpAssertion::Type::BOUNDARY:
if (context.length() == 0) { if (context.length() == 0) {
return false; return false;
} else if (position == 0) { } else if (position == 0) {
...@@ -49,8 +49,9 @@ bool SatisfiesAssertion(RegExpAssertion::AssertionType type, ...@@ -49,8 +49,9 @@ bool SatisfiesAssertion(RegExpAssertion::AssertionType type,
return IsRegExpWord(context[position - 1]) != return IsRegExpWord(context[position - 1]) !=
IsRegExpWord(context[position]); IsRegExpWord(context[position]);
} }
case RegExpAssertion::NON_BOUNDARY: case RegExpAssertion::Type::NON_BOUNDARY:
return !SatisfiesAssertion(RegExpAssertion::BOUNDARY, context, position); return !SatisfiesAssertion(RegExpAssertion::Type::BOUNDARY, context,
position);
} }
} }
......
...@@ -65,12 +65,12 @@ Interval RegExpQuantifier::CaptureRegisters() { ...@@ -65,12 +65,12 @@ Interval RegExpQuantifier::CaptureRegisters() {
bool RegExpAssertion::IsAnchoredAtStart() { bool RegExpAssertion::IsAnchoredAtStart() {
return assertion_type() == RegExpAssertion::START_OF_INPUT; return assertion_type() == RegExpAssertion::Type::START_OF_INPUT;
} }
bool RegExpAssertion::IsAnchoredAtEnd() { bool RegExpAssertion::IsAnchoredAtEnd() {
return assertion_type() == RegExpAssertion::END_OF_INPUT; return assertion_type() == RegExpAssertion::Type::END_OF_INPUT;
} }
...@@ -198,22 +198,22 @@ void* RegExpUnparser::VisitCharacterClass(RegExpCharacterClass* that, ...@@ -198,22 +198,22 @@ void* RegExpUnparser::VisitCharacterClass(RegExpCharacterClass* that,
void* RegExpUnparser::VisitAssertion(RegExpAssertion* that, void* data) { void* RegExpUnparser::VisitAssertion(RegExpAssertion* that, void* data) {
switch (that->assertion_type()) { switch (that->assertion_type()) {
case RegExpAssertion::START_OF_INPUT: case RegExpAssertion::Type::START_OF_INPUT:
os_ << "@^i"; os_ << "@^i";
break; break;
case RegExpAssertion::END_OF_INPUT: case RegExpAssertion::Type::END_OF_INPUT:
os_ << "@$i"; os_ << "@$i";
break; break;
case RegExpAssertion::START_OF_LINE: case RegExpAssertion::Type::START_OF_LINE:
os_ << "@^l"; os_ << "@^l";
break; break;
case RegExpAssertion::END_OF_LINE: case RegExpAssertion::Type::END_OF_LINE:
os_ << "@$l"; os_ << "@$l";
break; break;
case RegExpAssertion::BOUNDARY: case RegExpAssertion::Type::BOUNDARY:
os_ << "@b"; os_ << "@b";
break; break;
case RegExpAssertion::NON_BOUNDARY: case RegExpAssertion::Type::NON_BOUNDARY:
os_ << "@B"; os_ << "@B";
break; break;
} }
......
...@@ -224,16 +224,16 @@ class RegExpAlternative final : public RegExpTree { ...@@ -224,16 +224,16 @@ class RegExpAlternative final : public RegExpTree {
class RegExpAssertion final : public RegExpTree { class RegExpAssertion final : public RegExpTree {
public: public:
enum AssertionType { enum class Type {
START_OF_LINE = 0, START_OF_LINE = 0,
START_OF_INPUT = 1, START_OF_INPUT = 1,
END_OF_LINE = 2, END_OF_LINE = 2,
END_OF_INPUT = 3, END_OF_INPUT = 3,
BOUNDARY = 4, BOUNDARY = 4,
NON_BOUNDARY = 5, NON_BOUNDARY = 5,
LAST_TYPE = NON_BOUNDARY, LAST_ASSERTION_TYPE = NON_BOUNDARY,
}; };
explicit RegExpAssertion(AssertionType type) : assertion_type_(type) {} explicit RegExpAssertion(Type type) : assertion_type_(type) {}
DECL_BOILERPLATE(Assertion); DECL_BOILERPLATE(Assertion);
...@@ -241,10 +241,10 @@ class RegExpAssertion final : public RegExpTree { ...@@ -241,10 +241,10 @@ class RegExpAssertion final : public RegExpTree {
bool IsAnchoredAtEnd() override; bool IsAnchoredAtEnd() override;
int min_match() override { return 0; } int min_match() override { return 0; }
int max_match() override { return 0; } int max_match() override { return 0; }
AssertionType assertion_type() const { return assertion_type_; } Type assertion_type() const { return assertion_type_; }
private: private:
const AssertionType assertion_type_; const Type assertion_type_;
}; };
class CharacterSet final { class CharacterSet final {
......
...@@ -811,7 +811,7 @@ namespace { ...@@ -811,7 +811,7 @@ namespace {
// \B to (?<=\w)(?=\w)|(?<=\W)(?=\W) // \B to (?<=\w)(?=\w)|(?<=\W)(?=\W)
RegExpNode* BoundaryAssertionAsLookaround(RegExpCompiler* compiler, RegExpNode* BoundaryAssertionAsLookaround(RegExpCompiler* compiler,
RegExpNode* on_success, RegExpNode* on_success,
RegExpAssertion::AssertionType type, RegExpAssertion::Type type,
RegExpFlags flags) { RegExpFlags flags) {
CHECK(NeedsUnicodeCaseEquivalents(flags)); CHECK(NeedsUnicodeCaseEquivalents(flags));
Zone* zone = compiler->zone(); Zone* zone = compiler->zone();
...@@ -827,7 +827,7 @@ RegExpNode* BoundaryAssertionAsLookaround(RegExpCompiler* compiler, ...@@ -827,7 +827,7 @@ RegExpNode* BoundaryAssertionAsLookaround(RegExpCompiler* compiler,
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
bool lookbehind_for_word = i == 0; bool lookbehind_for_word = i == 0;
bool lookahead_for_word = bool lookahead_for_word =
(type == RegExpAssertion::BOUNDARY) ^ lookbehind_for_word; (type == RegExpAssertion::Type::BOUNDARY) ^ lookbehind_for_word;
// Look to the left. // Look to the left.
RegExpLookaround::Builder lookbehind(lookbehind_for_word, on_success, RegExpLookaround::Builder lookbehind(lookbehind_for_word, on_success,
stack_register, position_register); stack_register, position_register);
...@@ -851,23 +851,24 @@ RegExpNode* RegExpAssertion::ToNode(RegExpCompiler* compiler, ...@@ -851,23 +851,24 @@ RegExpNode* RegExpAssertion::ToNode(RegExpCompiler* compiler,
Zone* zone = compiler->zone(); Zone* zone = compiler->zone();
switch (assertion_type()) { switch (assertion_type()) {
case START_OF_LINE: case Type::START_OF_LINE:
return AssertionNode::AfterNewline(on_success); return AssertionNode::AfterNewline(on_success);
case START_OF_INPUT: case Type::START_OF_INPUT:
return AssertionNode::AtStart(on_success); return AssertionNode::AtStart(on_success);
case BOUNDARY: case Type::BOUNDARY:
return NeedsUnicodeCaseEquivalents(compiler->flags()) return NeedsUnicodeCaseEquivalents(compiler->flags())
? BoundaryAssertionAsLookaround(compiler, on_success, BOUNDARY, ? BoundaryAssertionAsLookaround(
compiler->flags()) compiler, on_success, Type::BOUNDARY, compiler->flags())
: AssertionNode::AtBoundary(on_success); : AssertionNode::AtBoundary(on_success);
case NON_BOUNDARY: case Type::NON_BOUNDARY:
return NeedsUnicodeCaseEquivalents(compiler->flags()) return NeedsUnicodeCaseEquivalents(compiler->flags())
? BoundaryAssertionAsLookaround( ? BoundaryAssertionAsLookaround(compiler, on_success,
compiler, on_success, NON_BOUNDARY, compiler->flags()) Type::NON_BOUNDARY,
compiler->flags())
: AssertionNode::AtNonBoundary(on_success); : AssertionNode::AtNonBoundary(on_success);
case END_OF_INPUT: case Type::END_OF_INPUT:
return AssertionNode::AtEnd(on_success); return AssertionNode::AtEnd(on_success);
case END_OF_LINE: { case Type::END_OF_LINE: {
// Compile $ in multiline regexps as an alternation with a positive // Compile $ in multiline regexps as an alternation with a positive
// lookahead in one side and an end-of-input on the other side. // lookahead in one side and an end-of-input on the other side.
// We need two registers for the lookahead. // We need two registers for the lookahead.
...@@ -1038,11 +1039,12 @@ class AssertionSequenceRewriter final { ...@@ -1038,11 +1039,12 @@ class AssertionSequenceRewriter final {
// Bitfield of all seen assertions. // Bitfield of all seen assertions.
uint32_t seen_assertions = 0; uint32_t seen_assertions = 0;
STATIC_ASSERT(RegExpAssertion::LAST_TYPE < kUInt32Size * kBitsPerByte); STATIC_ASSERT(static_cast<int>(RegExpAssertion::Type::LAST_ASSERTION_TYPE) <
kUInt32Size * kBitsPerByte);
for (int i = from; i < to; i++) { for (int i = from; i < to; i++) {
RegExpAssertion* t = terms_->at(i)->AsAssertion(); RegExpAssertion* t = terms_->at(i)->AsAssertion();
const uint32_t bit = 1 << t->assertion_type(); const uint32_t bit = 1 << static_cast<int>(t->assertion_type());
if (seen_assertions & bit) { if (seen_assertions & bit) {
// Fold duplicates. // Fold duplicates.
...@@ -1054,7 +1056,8 @@ class AssertionSequenceRewriter final { ...@@ -1054,7 +1056,8 @@ class AssertionSequenceRewriter final {
// Collapse failures. // Collapse failures.
const uint32_t always_fails_mask = const uint32_t always_fails_mask =
1 << RegExpAssertion::BOUNDARY | 1 << RegExpAssertion::NON_BOUNDARY; 1 << static_cast<int>(RegExpAssertion::Type::BOUNDARY) |
1 << static_cast<int>(RegExpAssertion::Type::NON_BOUNDARY);
if ((seen_assertions & always_fails_mask) == always_fails_mask) { if ((seen_assertions & always_fails_mask) == always_fails_mask) {
ReplaceSequenceWithFailure(from, to); ReplaceSequenceWithFailure(from, to);
} }
......
...@@ -611,16 +611,16 @@ RegExpTree* RegExpParserImpl<CharT>::ParseDisjunction() { ...@@ -611,16 +611,16 @@ RegExpTree* RegExpParserImpl<CharT>::ParseDisjunction() {
case '^': { case '^': {
Advance(); Advance();
builder->AddAssertion(zone()->template New<RegExpAssertion>( builder->AddAssertion(zone()->template New<RegExpAssertion>(
builder->multiline() ? RegExpAssertion::START_OF_LINE builder->multiline() ? RegExpAssertion::Type::START_OF_LINE
: RegExpAssertion::START_OF_INPUT)); : RegExpAssertion::Type::START_OF_INPUT));
set_contains_anchor(); set_contains_anchor();
continue; continue;
} }
case '$': { case '$': {
Advance(); Advance();
RegExpAssertion::AssertionType assertion_type = RegExpAssertion::Type assertion_type =
builder->multiline() ? RegExpAssertion::END_OF_LINE builder->multiline() ? RegExpAssertion::Type::END_OF_LINE
: RegExpAssertion::END_OF_INPUT; : RegExpAssertion::Type::END_OF_INPUT;
builder->AddAssertion( builder->AddAssertion(
zone()->template New<RegExpAssertion>(assertion_type)); zone()->template New<RegExpAssertion>(assertion_type));
continue; continue;
...@@ -728,12 +728,12 @@ RegExpTree* RegExpParserImpl<CharT>::ParseDisjunction() { ...@@ -728,12 +728,12 @@ RegExpTree* RegExpParserImpl<CharT>::ParseDisjunction() {
case 'b': case 'b':
Advance(2); Advance(2);
builder->AddAssertion(zone()->template New<RegExpAssertion>( builder->AddAssertion(zone()->template New<RegExpAssertion>(
RegExpAssertion::BOUNDARY)); RegExpAssertion::Type::BOUNDARY));
continue; continue;
case 'B': case 'B':
Advance(2); Advance(2);
builder->AddAssertion(zone()->template New<RegExpAssertion>( builder->AddAssertion(zone()->template New<RegExpAssertion>(
RegExpAssertion::NON_BOUNDARY)); RegExpAssertion::Type::NON_BOUNDARY));
continue; continue;
// AtomEscape :: // AtomEscape ::
// CharacterClassEscape // CharacterClassEscape
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment