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) {
case RegExpInstruction::ASSERTION:
os << "ASSERTION ";
switch (inst.payload.assertion_type) {
case RegExpAssertion::START_OF_INPUT:
case RegExpAssertion::Type::START_OF_INPUT:
os << "START_OF_INPUT";
break;
case RegExpAssertion::END_OF_INPUT:
case RegExpAssertion::Type::END_OF_INPUT:
os << "END_OF_INPUT";
break;
case RegExpAssertion::START_OF_LINE:
case RegExpAssertion::Type::START_OF_LINE:
os << "START_OF_LINE";
break;
case RegExpAssertion::END_OF_LINE:
case RegExpAssertion::Type::END_OF_LINE:
os << "END_OF_LINE";
break;
case RegExpAssertion::BOUNDARY:
case RegExpAssertion::Type::BOUNDARY:
os << "BOUNDARY";
break;
case RegExpAssertion::NON_BOUNDARY:
case RegExpAssertion::Type::NON_BOUNDARY:
os << "NON_BOUNDARY";
break;
}
......
......@@ -158,7 +158,7 @@ struct RegExpInstruction {
return result;
}
static RegExpInstruction Assertion(RegExpAssertion::AssertionType t) {
static RegExpInstruction Assertion(RegExpAssertion::Type t) {
RegExpInstruction result;
result.opcode = ASSERTION;
result.payload.assertion_type = t;
......@@ -174,7 +174,7 @@ struct RegExpInstruction {
// Payload of SET_REGISTER_TO_CP and CLEAR_REGISTER:
int32_t register_index;
// Payload of ASSERTION:
RegExpAssertion::AssertionType assertion_type;
RegExpAssertion::Type assertion_type;
} payload;
STATIC_ASSERT(sizeof(payload) == 4);
};
......
......@@ -221,7 +221,7 @@ class BytecodeAssembler {
void Accept() { code_.Add(RegExpInstruction::Accept(), zone_); }
void Assertion(RegExpAssertion::AssertionType t) {
void Assertion(RegExpAssertion::Type t) {
code_.Add(RegExpInstruction::Assertion(t), zone_);
}
......
......@@ -22,23 +22,23 @@ namespace {
constexpr int kUndefinedRegisterValue = -1;
template <class Character>
bool SatisfiesAssertion(RegExpAssertion::AssertionType type,
bool SatisfiesAssertion(RegExpAssertion::Type type,
base::Vector<const Character> context, int position) {
DCHECK_LE(position, context.length());
DCHECK_GE(position, 0);
switch (type) {
case RegExpAssertion::START_OF_INPUT:
case RegExpAssertion::Type::START_OF_INPUT:
return position == 0;
case RegExpAssertion::END_OF_INPUT:
case RegExpAssertion::Type::END_OF_INPUT:
return position == context.length();
case RegExpAssertion::START_OF_LINE:
case RegExpAssertion::Type::START_OF_LINE:
if (position == 0) return true;
return unibrow::IsLineTerminator(context[position - 1]);
case RegExpAssertion::END_OF_LINE:
case RegExpAssertion::Type::END_OF_LINE:
if (position == context.length()) return true;
return unibrow::IsLineTerminator(context[position]);
case RegExpAssertion::BOUNDARY:
case RegExpAssertion::Type::BOUNDARY:
if (context.length() == 0) {
return false;
} else if (position == 0) {
......@@ -49,8 +49,9 @@ bool SatisfiesAssertion(RegExpAssertion::AssertionType type,
return IsRegExpWord(context[position - 1]) !=
IsRegExpWord(context[position]);
}
case RegExpAssertion::NON_BOUNDARY:
return !SatisfiesAssertion(RegExpAssertion::BOUNDARY, context, position);
case RegExpAssertion::Type::NON_BOUNDARY:
return !SatisfiesAssertion(RegExpAssertion::Type::BOUNDARY, context,
position);
}
}
......
......@@ -65,12 +65,12 @@ Interval RegExpQuantifier::CaptureRegisters() {
bool RegExpAssertion::IsAnchoredAtStart() {
return assertion_type() == RegExpAssertion::START_OF_INPUT;
return assertion_type() == RegExpAssertion::Type::START_OF_INPUT;
}
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,
void* RegExpUnparser::VisitAssertion(RegExpAssertion* that, void* data) {
switch (that->assertion_type()) {
case RegExpAssertion::START_OF_INPUT:
case RegExpAssertion::Type::START_OF_INPUT:
os_ << "@^i";
break;
case RegExpAssertion::END_OF_INPUT:
case RegExpAssertion::Type::END_OF_INPUT:
os_ << "@$i";
break;
case RegExpAssertion::START_OF_LINE:
case RegExpAssertion::Type::START_OF_LINE:
os_ << "@^l";
break;
case RegExpAssertion::END_OF_LINE:
case RegExpAssertion::Type::END_OF_LINE:
os_ << "@$l";
break;
case RegExpAssertion::BOUNDARY:
case RegExpAssertion::Type::BOUNDARY:
os_ << "@b";
break;
case RegExpAssertion::NON_BOUNDARY:
case RegExpAssertion::Type::NON_BOUNDARY:
os_ << "@B";
break;
}
......
......@@ -224,16 +224,16 @@ class RegExpAlternative final : public RegExpTree {
class RegExpAssertion final : public RegExpTree {
public:
enum AssertionType {
enum class Type {
START_OF_LINE = 0,
START_OF_INPUT = 1,
END_OF_LINE = 2,
END_OF_INPUT = 3,
BOUNDARY = 4,
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);
......@@ -241,10 +241,10 @@ class RegExpAssertion final : public RegExpTree {
bool IsAnchoredAtEnd() override;
int min_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:
const AssertionType assertion_type_;
const Type assertion_type_;
};
class CharacterSet final {
......
......@@ -811,7 +811,7 @@ namespace {
// \B to (?<=\w)(?=\w)|(?<=\W)(?=\W)
RegExpNode* BoundaryAssertionAsLookaround(RegExpCompiler* compiler,
RegExpNode* on_success,
RegExpAssertion::AssertionType type,
RegExpAssertion::Type type,
RegExpFlags flags) {
CHECK(NeedsUnicodeCaseEquivalents(flags));
Zone* zone = compiler->zone();
......@@ -827,7 +827,7 @@ RegExpNode* BoundaryAssertionAsLookaround(RegExpCompiler* compiler,
for (int i = 0; i < 2; i++) {
bool lookbehind_for_word = i == 0;
bool lookahead_for_word =
(type == RegExpAssertion::BOUNDARY) ^ lookbehind_for_word;
(type == RegExpAssertion::Type::BOUNDARY) ^ lookbehind_for_word;
// Look to the left.
RegExpLookaround::Builder lookbehind(lookbehind_for_word, on_success,
stack_register, position_register);
......@@ -851,23 +851,24 @@ RegExpNode* RegExpAssertion::ToNode(RegExpCompiler* compiler,
Zone* zone = compiler->zone();
switch (assertion_type()) {
case START_OF_LINE:
case Type::START_OF_LINE:
return AssertionNode::AfterNewline(on_success);
case START_OF_INPUT:
case Type::START_OF_INPUT:
return AssertionNode::AtStart(on_success);
case BOUNDARY:
case Type::BOUNDARY:
return NeedsUnicodeCaseEquivalents(compiler->flags())
? BoundaryAssertionAsLookaround(compiler, on_success, BOUNDARY,
compiler->flags())
? BoundaryAssertionAsLookaround(
compiler, on_success, Type::BOUNDARY, compiler->flags())
: AssertionNode::AtBoundary(on_success);
case NON_BOUNDARY:
case Type::NON_BOUNDARY:
return NeedsUnicodeCaseEquivalents(compiler->flags())
? BoundaryAssertionAsLookaround(
compiler, on_success, NON_BOUNDARY, compiler->flags())
? BoundaryAssertionAsLookaround(compiler, on_success,
Type::NON_BOUNDARY,
compiler->flags())
: AssertionNode::AtNonBoundary(on_success);
case END_OF_INPUT:
case Type::END_OF_INPUT:
return AssertionNode::AtEnd(on_success);
case END_OF_LINE: {
case Type::END_OF_LINE: {
// Compile $ in multiline regexps as an alternation with a positive
// lookahead in one side and an end-of-input on the other side.
// We need two registers for the lookahead.
......@@ -1038,11 +1039,12 @@ class AssertionSequenceRewriter final {
// Bitfield of all seen assertions.
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++) {
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) {
// Fold duplicates.
......@@ -1054,7 +1056,8 @@ class AssertionSequenceRewriter final {
// Collapse failures.
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) {
ReplaceSequenceWithFailure(from, to);
}
......
......@@ -611,16 +611,16 @@ RegExpTree* RegExpParserImpl<CharT>::ParseDisjunction() {
case '^': {
Advance();
builder->AddAssertion(zone()->template New<RegExpAssertion>(
builder->multiline() ? RegExpAssertion::START_OF_LINE
: RegExpAssertion::START_OF_INPUT));
builder->multiline() ? RegExpAssertion::Type::START_OF_LINE
: RegExpAssertion::Type::START_OF_INPUT));
set_contains_anchor();
continue;
}
case '$': {
Advance();
RegExpAssertion::AssertionType assertion_type =
builder->multiline() ? RegExpAssertion::END_OF_LINE
: RegExpAssertion::END_OF_INPUT;
RegExpAssertion::Type assertion_type =
builder->multiline() ? RegExpAssertion::Type::END_OF_LINE
: RegExpAssertion::Type::END_OF_INPUT;
builder->AddAssertion(
zone()->template New<RegExpAssertion>(assertion_type));
continue;
......@@ -728,12 +728,12 @@ RegExpTree* RegExpParserImpl<CharT>::ParseDisjunction() {
case 'b':
Advance(2);
builder->AddAssertion(zone()->template New<RegExpAssertion>(
RegExpAssertion::BOUNDARY));
RegExpAssertion::Type::BOUNDARY));
continue;
case 'B':
Advance(2);
builder->AddAssertion(zone()->template New<RegExpAssertion>(
RegExpAssertion::NON_BOUNDARY));
RegExpAssertion::Type::NON_BOUNDARY));
continue;
// AtomEscape ::
// 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