Skip to content

Commit 22a1a72

Browse files
committed
Refactor: requested changes.
1 parent 0c7246a commit 22a1a72

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

client-java/instrumentation-shared/src/main/java/org/evomaster/client/java/instrumentation/shared/StringSpecializationInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public TaintType getType() {
5353
return type;
5454
}
5555

56+
/**
57+
* Getter for regex flags bitmask, only meaningful when stringSpecialization is regex type. Defaults to 0 (no flags)
58+
* @return Integer bitmask for the regex flags associated to the string.
59+
*/
5660
public int getRegexFlags() { return regexFlags; }
5761

5862
@Override

client-java/instrumentation/src/main/java/org/evomaster/client/java/instrumentation/coverage/methodreplacement/classes/MatcherClassReplacement.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public static boolean matches(Matcher caller, String idTemplate) {
4848

4949
String text = getText(caller);
5050
String pattern = caller.pattern().toString();
51-
int flags = caller.pattern().flags();
51+
int regexFlags = caller.pattern().flags();
5252

53-
boolean patternMatchesResult = PatternMatchingHelper.matches(pattern, flags, text, idTemplate);
53+
boolean patternMatchesResult = PatternMatchingHelper.matches(pattern, regexFlags, text, idTemplate);
5454

5555
TaintType taintType = ExecutionTracer.getTaintType(text);
5656

@@ -60,7 +60,7 @@ public static boolean matches(Matcher caller, String idTemplate) {
6060
*/
6161
String regex = caller.pattern().toString();
6262
ExecutionTracer.addStringSpecialization(text,
63-
new StringSpecializationInfo(StringSpecialization.REGEX_WHOLE, regex, taintType, flags));
63+
new StringSpecializationInfo(StringSpecialization.REGEX_WHOLE, regex, taintType, regexFlags));
6464
}
6565
boolean matcherMatchesResults = caller.matches();
6666
assert (patternMatchesResult == matcherMatchesResults);
@@ -73,7 +73,7 @@ public static boolean find(Matcher caller, String idTemplate) {
7373

7474
String input = getText(caller);
7575
String regex = caller.pattern().toString();
76-
int flags = caller.pattern().flags();
76+
int regexFlags = caller.pattern().flags();
7777
int end;
7878
try {
7979
end = caller.end();
@@ -106,7 +106,7 @@ match the regex, and find() only requires
106106
TaintType taintType = ExecutionTracer.getTaintType(substring);
107107
if (taintType.isTainted()) {
108108
ExecutionTracer.addStringSpecialization(substring,
109-
new StringSpecializationInfo(StringSpecialization.REGEX_PARTIAL, regex, taintType, flags));
109+
new StringSpecializationInfo(StringSpecialization.REGEX_PARTIAL, regex, taintType, regexFlags));
110110
}
111111

112112
String anyPositionRegexMatch = RegexSharedUtils.handlePartialMatch(regex);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +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
78

89

910
/**
@@ -20,14 +21,14 @@ object RegexHandler {
2021
WARNING mutable static state, but those are just caches.
2122
Key -> regex
2223
*/
23-
private val cacheJVM : MutableMap<Pair<String, RegexFlags>, RegexGene> = mutableMapOf()
24+
private val cacheJVM : MutableMap<RegexWithFlags, RegexGene> = mutableMapOf()
2425
private val cacheEcma262 : MutableMap<String, RegexGene> = mutableMapOf()
2526
private val cachePostgresLike : MutableMap<String, RegexGene> = mutableMapOf()
2627
private val cachePostgresSimilarTo : MutableMap<String, RegexGene> = mutableMapOf()
2728

2829
fun createGeneForJVM(regex: String, flags: RegexFlags = RegexFlags()) : RegexGene {
2930

30-
val key = Pair(regex, flags)
31+
val key = RegexWithFlags(regex, flags)
3132
if(cacheJVM.contains(key)){
3233
return cacheJVM[key]!!.copy() as RegexGene
3334
}

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

Lines changed: 2 additions & 2 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.RegexFlags
39+
import org.evomaster.core.utils.RegexWithFlags
4040
import org.slf4j.Logger
4141
import org.slf4j.LoggerFactory
4242
import java.lang.IllegalStateException
@@ -817,7 +817,7 @@ class StringGene(
817817
} else {
818818
RegexSharedUtils.handlePartialMatch(it.value)
819819
}
820-
Pair(regex, RegexFlags.fromJavaFlags(it.regexFlags))
820+
RegexWithFlags(regex, it.regexFlags)
821821
}
822822
//.joinToString("|")
823823
.forEach {(regex, flags) ->
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 RegexWithFlags(val regex: String, val regexFlags: RegexFlags) {
4+
constructor (regex: String, regexFlagInt: Int) : this(regex, RegexFlags.fromJavaFlags(regexFlagInt))
5+
}

0 commit comments

Comments
 (0)