@@ -164,19 +164,20 @@ module Make<RegexTreeViewSig TreeImpl> {
164
164
private predicate isCanonicalTerm ( RelevantRegExpTerm term , string str ) {
165
165
term =
166
166
min ( RelevantRegExpTerm t |
167
- str = t . getRawValue ( ) + "|" + getCanonicalizationFlags ( t . getRootTerm ( ) )
167
+ str = getCanonicalizationString ( t )
168
168
|
169
169
t order by getTermLocationString ( t )
170
170
)
171
171
}
172
172
173
173
/**
174
- * Gets a string representation of the flags used with the regular expression.
175
- * Only the flags that are relevant for the canonicalization are included.
174
+ * Gets a string representation of `term` that is used for canonicalization.
176
175
*/
177
- string getCanonicalizationFlags ( RegExpTerm root ) {
178
- root .isRootTerm ( ) and
179
- ( if isIgnoreCase ( root ) then result = "i" else result = "" )
176
+ private string getCanonicalizationString ( RelevantRegExpTerm term ) {
177
+ exists ( string ignoreCase |
178
+ ( if isIgnoreCase ( term .getRootTerm ( ) ) then ignoreCase = "i" else ignoreCase = "" ) and
179
+ result = term .getRawValue ( ) + "|" + ignoreCase
180
+ )
180
181
}
181
182
182
183
/**
@@ -221,12 +222,19 @@ module Make<RegexTreeViewSig TreeImpl> {
221
222
Epsilon ( )
222
223
223
224
/**
224
- * Gets the canonical CharClass for `term`.
225
+ * Gets the the CharClass corresponding to the canonical representative `term`.
225
226
*/
226
- CharClass getCanonicalCharClass ( RegExpTerm term ) {
227
+ private CharClass getCharClassForCanonicalTerm ( RegExpTerm term ) {
227
228
exists ( string str | isCanonicalTerm ( term , str ) | result = CharClass ( str ) )
228
229
}
229
230
231
+ /**
232
+ * Gets a char class that represents `term`, even when `term` is not the canonical representative.
233
+ */
234
+ CharacterClass getCanonicalCharClass ( RegExpTerm term ) {
235
+ exists ( string str | str = getCanonicalizationString ( term ) and result = CharClass ( str ) )
236
+ }
237
+
230
238
/**
231
239
* Holds if `a` and `b` are input symbols from the same regexp.
232
240
*/
@@ -319,7 +327,7 @@ module Make<RegexTreeViewSig TreeImpl> {
319
327
*/
320
328
pragma [ noinline]
321
329
predicate hasChildThatMatchesIgnoringCasingFlags ( RegExpCharacterClass cc , string char ) {
322
- exists ( getCanonicalCharClass ( cc ) ) and
330
+ exists ( getCharClassForCanonicalTerm ( cc ) ) and
323
331
exists ( RegExpTerm child | child = cc .getAChild ( ) |
324
332
char = child .( RegexpCharacterConstant ) .getValue ( )
325
333
or
@@ -420,7 +428,7 @@ module Make<RegexTreeViewSig TreeImpl> {
420
428
private class PositiveCharacterClass extends CharacterClass {
421
429
RegExpCharacterClass cc ;
422
430
423
- PositiveCharacterClass ( ) { this = getCanonicalCharClass ( cc ) and not cc .isInverted ( ) }
431
+ PositiveCharacterClass ( ) { this = getCharClassForCanonicalTerm ( cc ) and not cc .isInverted ( ) }
424
432
425
433
override string getARelevantChar ( ) { result = caseNormalize ( getAMentionedChar ( cc ) , cc ) }
426
434
@@ -433,7 +441,7 @@ module Make<RegexTreeViewSig TreeImpl> {
433
441
private class InvertedCharacterClass extends CharacterClass {
434
442
RegExpCharacterClass cc ;
435
443
436
- InvertedCharacterClass ( ) { this = getCanonicalCharClass ( cc ) and cc .isInverted ( ) }
444
+ InvertedCharacterClass ( ) { this = getCharClassForCanonicalTerm ( cc ) and cc .isInverted ( ) }
437
445
438
446
override string getARelevantChar ( ) {
439
447
result = nextChar ( caseNormalize ( getAMentionedChar ( cc ) , cc ) ) or
@@ -468,7 +476,7 @@ module Make<RegexTreeViewSig TreeImpl> {
468
476
469
477
PositiveCharacterClassEscape ( ) {
470
478
isEscapeClass ( cc , charClass ) and
471
- this = getCanonicalCharClass ( cc ) and
479
+ this = getCharClassForCanonicalTerm ( cc ) and
472
480
charClass = [ "d" , "s" , "w" ]
473
481
}
474
482
@@ -508,7 +516,7 @@ module Make<RegexTreeViewSig TreeImpl> {
508
516
NegativeCharacterClassEscape ( ) {
509
517
exists ( RegExpTerm cc |
510
518
isEscapeClass ( cc , charClass ) and
511
- this = getCanonicalCharClass ( cc ) and
519
+ this = getCharClassForCanonicalTerm ( cc ) and
512
520
charClass = [ "D" , "S" , "W" ]
513
521
)
514
522
}
@@ -703,17 +711,13 @@ module Make<RegexTreeViewSig TreeImpl> {
703
711
cc .isUniversalClass ( ) and q1 = before ( cc ) and lbl = Any ( ) and q2 = after ( cc )
704
712
or
705
713
q1 = before ( cc ) and
706
- lbl =
707
- CharacterClasses:: normalize ( CharClass ( cc .getRawValue ( ) + "|" +
708
- getCanonicalizationFlags ( cc .getRootTerm ( ) ) ) ) and
714
+ lbl = CharacterClasses:: normalize ( CharClass ( getCanonicalizationString ( cc ) ) ) and
709
715
q2 = after ( cc )
710
716
)
711
717
or
712
718
exists ( RegExpTerm cc | isEscapeClass ( cc , _) |
713
719
q1 = before ( cc ) and
714
- lbl =
715
- CharacterClasses:: normalize ( CharClass ( cc .getRawValue ( ) + "|" +
716
- getCanonicalizationFlags ( cc .getRootTerm ( ) ) ) ) and
720
+ lbl = CharacterClasses:: normalize ( CharClass ( getCanonicalizationString ( cc ) ) ) and
717
721
q2 = after ( cc )
718
722
)
719
723
or
0 commit comments