Skip to content

Commit cab73aa

Browse files
committed
Refactor, renaming
1 parent 5e362dd commit cab73aa

5 files changed

Lines changed: 17 additions & 17 deletions

File tree

core/src/main/kotlin/org/evomaster/core/parser/GeneRegexJavaVisitor.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ private const val EOF_TOKEN = "<EOF>"
1111
/**
1212
* Created by arcuri82 on 11-Sep-19.
1313
*/
14-
class GeneRegexJavaVisitor(externalFlags: RegexFlags = RegexFlags()) : RegexJavaBaseVisitor<VisitResult>(){
14+
class GeneRegexJavaVisitor(externalRegexFlags: RegexFlags = RegexFlags()) : RegexJavaBaseVisitor<VisitResult>(){
1515

1616
private val hexEscapePrefixes = setOf('x', 'u')
1717

@@ -52,9 +52,9 @@ class GeneRegexJavaVisitor(externalFlags: RegexFlags = RegexFlags()) : RegexJava
5252
/**
5353
* Tracks the flags active in the current lexical scope.
5454
* Updated when entering a flag group, restored on exit.
55-
* Initialized from [externalFlags].
55+
* Initialized from [externalRegexFlags].
5656
*/
57-
private var currentFlags = externalFlags
57+
private var currentFlags = externalRegexFlags
5858

5959
/**
6060
* Parses a FLAG_GROUP_OPEN or FLAG_SCOPE_OPEN token text like "(?i:", "(?iu:", "(?-i:", "(?i-u:", "(?iu)", etc.

core/src/main/kotlin/org/evomaster/core/parser/RegexHandler.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.antlr.v4.runtime.*
44
import org.antlr.v4.runtime.misc.ParseCancellationException
55
import org.evomaster.core.search.gene.regex.RegexGene
66
import org.evomaster.core.utils.RegexFlags
7-
import org.evomaster.core.utils.RegexWithFlags
7+
import org.evomaster.core.utils.RegexWithExternalFlags
88

99

1010
/**
@@ -21,14 +21,14 @@ object RegexHandler {
2121
WARNING mutable static state, but those are just caches.
2222
Key -> regex
2323
*/
24-
private val cacheJVM : MutableMap<RegexWithFlags, RegexGene> = mutableMapOf()
24+
private val cacheJVM : MutableMap<RegexWithExternalFlags, RegexGene> = mutableMapOf()
2525
private val cacheEcma262 : MutableMap<String, RegexGene> = mutableMapOf()
2626
private val cachePostgresLike : MutableMap<String, RegexGene> = mutableMapOf()
2727
private val cachePostgresSimilarTo : MutableMap<String, RegexGene> = mutableMapOf()
2828

29-
fun createGeneForJVM(regex: String, flags: RegexFlags = RegexFlags()) : RegexGene {
29+
fun createGeneForJVM(regex: String, externalRegexFlags: RegexFlags = RegexFlags()) : RegexGene {
3030

31-
val key = RegexWithFlags(regex, flags)
31+
val key = RegexWithExternalFlags(regex, externalRegexFlags)
3232
if(cacheJVM.contains(key)){
3333
return cacheJVM[key]!!.copy() as RegexGene
3434
}
@@ -41,7 +41,7 @@ object RegexHandler {
4141

4242
val pattern = parser.pattern()
4343

44-
val res = GeneRegexJavaVisitor(flags).visit(pattern)
44+
val res = GeneRegexJavaVisitor(externalRegexFlags).visit(pattern)
4545

4646
val gene= res.genes.first() as RegexGene
4747
cacheJVM[key] = gene.copy() as RegexGene

core/src/main/kotlin/org/evomaster/core/search/gene/string/StringGene.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import org.evomaster.core.search.service.Randomness
3636
import org.evomaster.core.search.service.mutator.MutationWeightControl
3737
import org.evomaster.core.search.service.mutator.genemutation.AdditionalGeneMutationInfo
3838
import org.evomaster.core.search.service.mutator.genemutation.SubsetGeneMutationSelectionStrategy
39-
import org.evomaster.core.utils.RegexWithFlags
39+
import org.evomaster.core.utils.RegexWithExternalFlags
4040
import org.slf4j.Logger
4141
import org.slf4j.LoggerFactory
4242
import java.lang.IllegalStateException
@@ -817,12 +817,12 @@ class StringGene(
817817
} else {
818818
RegexSharedUtils.handlePartialMatch(it.value)
819819
}
820-
RegexWithFlags(regex, it.externalRegexFlagsBitmask)
820+
RegexWithExternalFlags(regex, it.externalRegexFlagsBitmask)
821821
}
822822
//.joinToString("|")
823-
.forEach {(regex, flags) ->
823+
.forEach {(regex, externalFlags) ->
824824
try {
825-
toAddGenes.add(RegexHandler.createGeneForJVM(regex, flags))
825+
toAddGenes.add(RegexHandler.createGeneForJVM(regex, externalFlags))
826826
log.trace("Regex, added specification for: {}", regex)
827827
} catch (e: Exception) {
828828
LoggingUtil.uniqueWarn(log, "Failed to handle regex: $regex")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.evomaster.core.utils
2+
3+
data class RegexWithExternalFlags(val regex: String, val externalRegexFlags: RegexFlags) {
4+
constructor (regex: String, externalRegexFlagBitmask: Int) : this(regex, RegexFlags.fromExternalJavaRegexFlagBitmask(externalRegexFlagBitmask))
5+
}

core/src/main/kotlin/org/evomaster/core/utils/RegexWithFlags.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)