Skip to content

Commit 0c3f21f

Browse files
committed
Refactor to use enum class ProgramTag
1 parent 593571e commit 0c3f21f

File tree

5 files changed

+38
-37
lines changed

5 files changed

+38
-37
lines changed

lib/Backend/Lower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18672,7 +18672,7 @@ Lowerer::GenerateFastInlineRegExpExec(IR::Instr * instr)
1867218672
// We want the program's tag to be BOILiteral2Tag
1867318673
InsertCompareBranch(
1867418674
IR::IndirOpnd::New(opndProgram, (int32)UnifiedRegex::Program::GetOffsetOfTag(), TyUint8, m_func),
18675-
IR::IntConstOpnd::New(UnifiedRegex::Program::GetBOILiteral2Tag(), TyUint8, m_func),
18675+
IR::IntConstOpnd::New((IntConstType)UnifiedRegex::Program::GetBOILiteral2Tag(), TyUint8, m_func),
1867618676
Js::OpCode::BrNeq_A,
1867718677
labelFastHelper,
1867818678
instr);

lib/Parser/RegexCompileTime.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4562,7 +4562,7 @@ namespace UnifiedRegex
45624562
#endif
45634563
)
45644564
{
4565-
program->tag = Program::InstructionsTag;
4565+
program->tag = Program::ProgramTag::InstructionsTag;
45664566
CaptureNoLiterals(program);
45674567
EmitAndCaptureSuccInst(pattern->GetScriptContext()->GetRecycler(), program);
45684568
}
@@ -4642,7 +4642,7 @@ namespace UnifiedRegex
46424642
{
46434643
program->rep.insts.litbuf = nullptr;
46444644
oi.InitializeTrigramInfo(scriptContext, pattern);
4645-
program->tag = Program::OctoquadTag;
4645+
program->tag = Program::ProgramTag::OctoquadTag;
46464646
program->rep.octoquad.matcher = OctoquadMatcher::New(scriptContext->GetRecycler(), standardChars, program->GetCaseMappingSource(), &oi);
46474647
compiled = true;
46484648
}
@@ -4659,29 +4659,29 @@ namespace UnifiedRegex
46594659
if (root->IsSingleChar(compiler, c))
46604660
{
46614661
// SPECIAL CASE: c
4662-
program->tag = Program::SingleCharTag;
4662+
program->tag = Program::ProgramTag::SingleCharTag;
46634663
program->rep.singleChar.c = c;
46644664
}
46654665
else if (root->IsBoundedWord(compiler))
46664666
{
46674667
// SPECIAL CASE: \b\w+\b
4668-
program->tag = Program::BoundedWordTag;
4668+
program->tag = Program::ProgramTag::BoundedWordTag;
46694669
}
46704670
else if (root->IsLeadingTrailingSpaces(compiler,
46714671
program->rep.leadingTrailingSpaces.beginMinMatch,
46724672
program->rep.leadingTrailingSpaces.endMinMatch))
46734673
{
46744674
// SPECIAL CASE: ^\s*|\s*$
4675-
program->tag = Program::LeadingTrailingSpacesTag;
4675+
program->tag = Program::ProgramTag::LeadingTrailingSpacesTag;
46764676
}
46774677
else if (root->IsBOILiteral2(compiler))
46784678
{
4679-
program->tag = Program::BOILiteral2Tag;
4679+
program->tag = Program::ProgramTag::BOILiteral2Tag;
46804680
program->rep.boiLiteral2.literal = *(DWORD *)litbuf;
46814681
}
46824682
else
46834683
{
4684-
program->tag = Program::InstructionsTag;
4684+
program->tag = Program::ProgramTag::InstructionsTag;
46854685
compiler.CaptureLiterals(root, litbuf);
46864686

46874687
root->AnnotatePass0(compiler);
@@ -4759,7 +4759,7 @@ namespace UnifiedRegex
47594759
}
47604760
else
47614761
{
4762-
program->tag = Program::InstructionsTag;
4762+
program->tag = Program::ProgramTag::InstructionsTag;
47634763
compiler.CaptureLiterals(root, litbuf);
47644764
CharCount skipped = 0;
47654765
root->Emit(compiler, skipped);

lib/Parser/RegexCompileTime.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,20 +666,20 @@ namespace UnifiedRegex
666666

667667
void SetBOIInstructionsProgramTag()
668668
{
669-
Assert(this->program->tag == Program::InstructionsTag
670-
|| this->program->tag == Program::BOIInstructionsTag);
669+
Assert(this->program->tag == Program::ProgramTag::InstructionsTag
670+
|| this->program->tag == Program::ProgramTag::BOIInstructionsTag);
671671
Assert(this->CurrentLabel() == 0);
672-
this->program->tag = Program::BOIInstructionsTag;
672+
this->program->tag = Program::ProgramTag::BOIInstructionsTag;
673673
}
674674

675675
void SetBOIInstructionsProgramForStickyFlagTag()
676676
{
677-
Assert(this->program->tag == Program::InstructionsTag
678-
|| this->program->tag == Program::BOIInstructionsForStickyFlagTag);
677+
Assert(this->program->tag == Program::ProgramTag::InstructionsTag
678+
|| this->program->tag == Program::ProgramTag::BOIInstructionsForStickyFlagTag);
679679
Assert(this->CurrentLabel() == 0);
680680
AssertMsg((this->program->flags & StickyRegexFlag) != 0, "Shouldn't set BOIInstructionsForStickyFlagTag, if sticky is false.");
681681

682-
this->program->tag = Program::BOIInstructionsForStickyFlagTag;
682+
this->program->tag = Program::ProgramTag::BOIInstructionsForStickyFlagTag;
683683
}
684684

685685
static void CaptureNoLiterals(Program* program);

lib/Parser/RegexRuntime.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5476,7 +5476,7 @@ namespace UnifiedRegex
54765476
bool isStickyPresent = this->pattern->IsSticky();
54775477
switch (prog->tag)
54785478
{
5479-
case Program::BOIInstructionsTag:
5479+
case Program::ProgramTag::BOIInstructionsTag:
54805480
if (offset != 0)
54815481
{
54825482
groupInfos[0].Reset();
@@ -5486,14 +5486,14 @@ namespace UnifiedRegex
54865486

54875487
// fall through
54885488

5489-
case Program::BOIInstructionsForStickyFlagTag:
5490-
AssertMsg(prog->tag == Program::BOIInstructionsTag || isStickyPresent, "prog->tag should be BOIInstructionsForStickyFlagTag if sticky = true.");
5489+
case Program::ProgramTag::BOIInstructionsForStickyFlagTag:
5490+
AssertMsg(prog->tag == Program::ProgramTag::BOIInstructionsTag || isStickyPresent, "prog->tag should be BOIInstructionsForStickyFlagTag if sticky = true.");
54915491

54925492
loopMatchHere = false;
54935493

54945494
// fall through
54955495

5496-
case Program::InstructionsTag:
5496+
case Program::ProgramTag::InstructionsTag:
54975497
{
54985498
previousQcTime = 0;
54995499
uint qcTicks = 0;
@@ -5519,7 +5519,7 @@ namespace UnifiedRegex
55195519
break;
55205520
}
55215521

5522-
case Program::SingleCharTag:
5522+
case Program::ProgramTag::SingleCharTag:
55235523
if (this->pattern->IsIgnoreCase())
55245524
{
55255525
res = MatchSingleCharCaseInsensitive(input, inputLength, offset, prog->rep.singleChar.c);
@@ -5531,19 +5531,19 @@ namespace UnifiedRegex
55315531

55325532
break;
55335533

5534-
case Program::BoundedWordTag:
5534+
case Program::ProgramTag::BoundedWordTag:
55355535
res = MatchBoundedWord(input, inputLength, offset);
55365536
break;
55375537

5538-
case Program::LeadingTrailingSpacesTag:
5538+
case Program::ProgramTag::LeadingTrailingSpacesTag:
55395539
res = MatchLeadingTrailingSpaces(input, inputLength, offset);
55405540
break;
55415541

5542-
case Program::OctoquadTag:
5542+
case Program::ProgramTag::OctoquadTag:
55435543
res = MatchOctoquad(input, inputLength, offset, prog->rep.octoquad.matcher);
55445544
break;
55455545

5546-
case Program::BOILiteral2Tag:
5546+
case Program::ProgramTag::BOILiteral2Tag:
55475547
res = MatchBOILiteral2(input, inputLength, offset, prog->rep.boiLiteral2.literal);
55485548
break;
55495549

@@ -5593,7 +5593,7 @@ namespace UnifiedRegex
55935593
}
55945594
w->EOL();
55955595
}
5596-
if (program->tag == Program::BOIInstructionsTag || program->tag == Program::InstructionsTag)
5596+
if (program->tag == Program::ProgramTag::BOIInstructionsTag || program->tag == Program::ProgramTag::InstructionsTag)
55975597
{
55985598
w->Print(_u("instPointer: "));
55995599

@@ -5662,7 +5662,7 @@ namespace UnifiedRegex
56625662
, numGroups(0)
56635663
, numLoops(0)
56645664
{
5665-
tag = InstructionsTag;
5665+
tag = ProgramTag::InstructionsTag;
56665666
rep.insts.insts = nullptr;
56675667
rep.insts.instsLen = 0;
56685668
rep.insts.litbuf = nullptr;
@@ -5677,7 +5677,7 @@ namespace UnifiedRegex
56775677

56785678
Field(ScannerInfo *)*Program::CreateScannerArrayForSyncToLiterals(Recycler *const recycler)
56795679
{
5680-
Assert(tag == InstructionsTag);
5680+
Assert(tag == ProgramTag::InstructionsTag);
56815681
Assert(!rep.insts.scannersForSyncToLiterals);
56825682
Assert(recycler);
56835683

@@ -5693,7 +5693,7 @@ namespace UnifiedRegex
56935693
const CharCount length,
56945694
const bool isEquivClass)
56955695
{
5696-
Assert(tag == InstructionsTag);
5696+
Assert(tag == ProgramTag::InstructionsTag);
56975697
Assert(rep.insts.scannersForSyncToLiterals);
56985698
Assert(recycler);
56995699
Assert(scannerIndex >= 0);
@@ -5707,7 +5707,7 @@ namespace UnifiedRegex
57075707

57085708
void Program::FreeBody(ArenaAllocator* rtAllocator)
57095709
{
5710-
if (tag != InstructionsTag || !rep.insts.insts)
5710+
if (tag != ProgramTag::InstructionsTag || !rep.insts.insts)
57115711
{
57125712
return;
57135713
}
@@ -5764,12 +5764,12 @@ namespace UnifiedRegex
57645764
w->PrintEOL(_u("numLoops: %d"), numLoops);
57655765
switch (tag)
57665766
{
5767-
case BOIInstructionsTag:
5768-
case InstructionsTag:
5767+
case ProgramTag::BOIInstructionsTag:
5768+
case ProgramTag::InstructionsTag:
57695769
{
57705770
w->PrintEOL(_u("instructions: {"));
57715771
w->Indent();
5772-
if (tag == BOIInstructionsTag)
5772+
if (tag == ProgramTag::BOIInstructionsTag)
57735773
{
57745774
w->PrintEOL(_u(" BOITest(hardFail: true)"));
57755775
}
@@ -5803,19 +5803,19 @@ namespace UnifiedRegex
58035803
w->PrintEOL(_u("}"));
58045804
}
58055805
break;
5806-
case SingleCharTag:
5806+
case ProgramTag::SingleCharTag:
58075807
w->Print(_u("special form: <match single char "));
58085808
w->PrintQuotedChar(rep.singleChar.c);
58095809
w->PrintEOL(_u(">"));
58105810
break;
5811-
case BoundedWordTag:
5811+
case ProgramTag::BoundedWordTag:
58125812
w->PrintEOL(_u("special form: <match bounded word>"));
58135813
break;
5814-
case LeadingTrailingSpacesTag:
5814+
case ProgramTag::LeadingTrailingSpacesTag:
58155815
w->PrintEOL(_u("special form: <match leading/trailing spaces: minBegin=%d minEnd=%d>"),
58165816
rep.leadingTrailingSpaces.beginMinMatch, rep.leadingTrailingSpaces.endMinMatch);
58175817
break;
5818-
case OctoquadTag:
5818+
case ProgramTag::OctoquadTag:
58195819
w->Print(_u("special form: <octoquad "));
58205820
rep.octoquad.matcher->Print(w);
58215821
w->PrintEOL(_u(">"));

lib/Parser/RegexRuntime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace UnifiedRegex
3030

3131
struct Program : private Chars<char16>
3232
{
33+
friend class Lowerer;
3334
friend class Compiler;
3435
friend struct MatchLiteralNode;
3536
friend struct AltNode;
@@ -64,7 +65,7 @@ namespace UnifiedRegex
6465
Field(RegexFlags) flags;
6566

6667
private:
67-
enum ProgramTag : uint8
68+
enum class ProgramTag : uint8
6869
{
6970
InstructionsTag,
7071
BOIInstructionsTag,

0 commit comments

Comments
 (0)