From be0cc08fb4faed1ab69361fcd030af65f9020393 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Wed, 31 Dec 2014 11:49:30 +0000 Subject: [PATCH] ART: Refactored regex code in Checker This patch refactors how Checker constructs regular expressions which it uses to parse tests and verify compiler output. It also replaces all occurrences of the '[0-9]+' ID-matching expression with the '\d+' shorthand. Change-Id: I5f854a25707e44ed2fa1673ff084990e8f43e4a2 --- compiler/optimizing/test/ConstantFolding.java | 110 ++++++++++++------------- compiler/optimizing/test/Inliner.java | 114 +++++++++++++------------- tools/checker.py | 64 +++++++-------- 3 files changed, 143 insertions(+), 145 deletions(-) diff --git a/compiler/optimizing/test/ConstantFolding.java b/compiler/optimizing/test/ConstantFolding.java index 92f2a775b..d08006b4d 100644 --- a/compiler/optimizing/test/ConstantFolding.java +++ b/compiler/optimizing/test/ConstantFolding.java @@ -22,13 +22,13 @@ public class ConstantFolding { */ // CHECK-START: int ConstantFolding.IntNegation() constant_folding (before) - // CHECK-DAG: [[Const42:i[0-9]+]] IntConstant 42 - // CHECK-DAG: [[Neg:i[0-9]+]] Neg [ [[Const42]] ] - // CHECK-DAG: Return [ [[Neg]] ] + // CHECK-DAG: [[Const42:i\d+]] IntConstant 42 + // CHECK-DAG: [[Neg:i\d+]] Neg [ [[Const42]] ] + // CHECK-DAG: Return [ [[Neg]] ] // CHECK-START: int ConstantFolding.IntNegation() constant_folding (after) - // CHECK-DAG: [[ConstN42:i[0-9]+]] IntConstant -42 - // CHECK-DAG: Return [ [[ConstN42]] ] + // CHECK-DAG: [[ConstN42:i\d+]] IntConstant -42 + // CHECK-DAG: Return [ [[ConstN42]] ] public static int IntNegation() { int x, y; @@ -43,14 +43,14 @@ public class ConstantFolding { */ // CHECK-START: int ConstantFolding.IntAddition1() constant_folding (before) - // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1 - // CHECK-DAG: [[Const2:i[0-9]+]] IntConstant 2 - // CHECK-DAG: [[Add:i[0-9]+]] Add [ [[Const1]] [[Const2]] ] - // CHECK-DAG: Return [ [[Add]] ] + // CHECK-DAG: [[Const1:i\d+]] IntConstant 1 + // CHECK-DAG: [[Const2:i\d+]] IntConstant 2 + // CHECK-DAG: [[Add:i\d+]] Add [ [[Const1]] [[Const2]] ] + // CHECK-DAG: Return [ [[Add]] ] // CHECK-START: int ConstantFolding.IntAddition1() constant_folding (after) - // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3 - // CHECK-DAG: Return [ [[Const3]] ] + // CHECK-DAG: [[Const3:i\d+]] IntConstant 3 + // CHECK-DAG: Return [ [[Const3]] ] public static int IntAddition1() { int a, b, c; @@ -66,18 +66,18 @@ public class ConstantFolding { */ // CHECK-START: int ConstantFolding.IntAddition2() constant_folding (before) - // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1 - // CHECK-DAG: [[Const2:i[0-9]+]] IntConstant 2 - // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5 - // CHECK-DAG: [[Const6:i[0-9]+]] IntConstant 6 - // CHECK-DAG: [[Add1:i[0-9]+]] Add [ [[Const1]] [[Const2]] ] - // CHECK-DAG: [[Add2:i[0-9]+]] Add [ [[Const5]] [[Const6]] ] - // CHECK-DAG: [[Add3:i[0-9]+]] Add [ [[Add1]] [[Add2]] ] - // CHECK-DAG: Return [ [[Add3]] ] + // CHECK-DAG: [[Const1:i\d+]] IntConstant 1 + // CHECK-DAG: [[Const2:i\d+]] IntConstant 2 + // CHECK-DAG: [[Const5:i\d+]] IntConstant 5 + // CHECK-DAG: [[Const6:i\d+]] IntConstant 6 + // CHECK-DAG: [[Add1:i\d+]] Add [ [[Const1]] [[Const2]] ] + // CHECK-DAG: [[Add2:i\d+]] Add [ [[Const5]] [[Const6]] ] + // CHECK-DAG: [[Add3:i\d+]] Add [ [[Add1]] [[Add2]] ] + // CHECK-DAG: Return [ [[Add3]] ] // CHECK-START: int ConstantFolding.IntAddition2() constant_folding (after) - // CHECK-DAG: [[Const14:i[0-9]+]] IntConstant 14 - // CHECK-DAG: Return [ [[Const14]] ] + // CHECK-DAG: [[Const14:i\d+]] IntConstant 14 + // CHECK-DAG: Return [ [[Const14]] ] public static int IntAddition2() { int a, b, c; @@ -97,14 +97,14 @@ public class ConstantFolding { */ // CHECK-START: int ConstantFolding.IntSubtraction() constant_folding (before) - // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5 - // CHECK-DAG: [[Const2:i[0-9]+]] IntConstant 2 - // CHECK-DAG: [[Sub:i[0-9]+]] Sub [ [[Const5]] [[Const2]] ] - // CHECK-DAG: Return [ [[Sub]] ] + // CHECK-DAG: [[Const5:i\d+]] IntConstant 5 + // CHECK-DAG: [[Const2:i\d+]] IntConstant 2 + // CHECK-DAG: [[Sub:i\d+]] Sub [ [[Const5]] [[Const2]] ] + // CHECK-DAG: Return [ [[Sub]] ] // CHECK-START: int ConstantFolding.IntSubtraction() constant_folding (after) - // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3 - // CHECK-DAG: Return [ [[Const3]] ] + // CHECK-DAG: [[Const3:i\d+]] IntConstant 3 + // CHECK-DAG: Return [ [[Const3]] ] public static int IntSubtraction() { int a, b, c; @@ -120,14 +120,14 @@ public class ConstantFolding { */ // CHECK-START: long ConstantFolding.LongAddition() constant_folding (before) - // CHECK-DAG: [[Const1:j[0-9]+]] LongConstant 1 - // CHECK-DAG: [[Const2:j[0-9]+]] LongConstant 2 - // CHECK-DAG: [[Add:j[0-9]+]] Add [ [[Const1]] [[Const2]] ] - // CHECK-DAG: Return [ [[Add]] ] + // CHECK-DAG: [[Const1:j\d+]] LongConstant 1 + // CHECK-DAG: [[Const2:j\d+]] LongConstant 2 + // CHECK-DAG: [[Add:j\d+]] Add [ [[Const1]] [[Const2]] ] + // CHECK-DAG: Return [ [[Add]] ] // CHECK-START: long ConstantFolding.LongAddition() constant_folding (after) - // CHECK-DAG: [[Const3:j[0-9]+]] LongConstant 3 - // CHECK-DAG: Return [ [[Const3]] ] + // CHECK-DAG: [[Const3:j\d+]] LongConstant 3 + // CHECK-DAG: Return [ [[Const3]] ] public static long LongAddition() { long a, b, c; @@ -143,14 +143,14 @@ public class ConstantFolding { */ // CHECK-START: long ConstantFolding.LongSubtraction() constant_folding (before) - // CHECK-DAG: [[Const5:j[0-9]+]] LongConstant 5 - // CHECK-DAG: [[Const2:j[0-9]+]] LongConstant 2 - // CHECK-DAG: [[Sub:j[0-9]+]] Sub [ [[Const5]] [[Const2]] ] - // CHECK-DAG: Return [ [[Sub]] ] + // CHECK-DAG: [[Const5:j\d+]] LongConstant 5 + // CHECK-DAG: [[Const2:j\d+]] LongConstant 2 + // CHECK-DAG: [[Sub:j\d+]] Sub [ [[Const5]] [[Const2]] ] + // CHECK-DAG: Return [ [[Sub]] ] // CHECK-START: long ConstantFolding.LongSubtraction() constant_folding (after) - // CHECK-DAG: [[Const3:j[0-9]+]] LongConstant 3 - // CHECK-DAG: Return [ [[Const3]] ] + // CHECK-DAG: [[Const3:j\d+]] LongConstant 3 + // CHECK-DAG: Return [ [[Const3]] ] public static long LongSubtraction() { long a, b, c; @@ -165,14 +165,14 @@ public class ConstantFolding { */ // CHECK-START: int ConstantFolding.StaticCondition() constant_folding (before) - // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5 - // CHECK-DAG: [[Const2:i[0-9]+]] IntConstant 2 - // CHECK-DAG: [[Cond:z[0-9]+]] GreaterThanOrEqual [ [[Const5]] [[Const2]] ] - // CHECK-DAG: If [ [[Cond]] ] + // CHECK-DAG: [[Const5:i\d+]] IntConstant 5 + // CHECK-DAG: [[Const2:i\d+]] IntConstant 2 + // CHECK-DAG: [[Cond:z\d+]] GreaterThanOrEqual [ [[Const5]] [[Const2]] ] + // CHECK-DAG: If [ [[Cond]] ] // CHECK-START: int ConstantFolding.StaticCondition() constant_folding (after) - // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1 - // CHECK-DAG: If [ [[Const1]] ] + // CHECK-DAG: [[Const1:i\d+]] IntConstant 1 + // CHECK-DAG: If [ [[Const1]] ] public static int StaticCondition() { int a, b, c; @@ -195,18 +195,18 @@ public class ConstantFolding { */ // CHECK-START: int ConstantFolding.JumpsAndConditionals(boolean) constant_folding (before) - // CHECK-DAG: [[Const2:i[0-9]+]] IntConstant 2 - // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5 - // CHECK-DAG: [[Add:i[0-9]+]] Add [ [[Const5]] [[Const2]] ] - // CHECK-DAG: [[Sub:i[0-9]+]] Sub [ [[Const5]] [[Const2]] ] - // CHECK-DAG: [[Phi:i[0-9]+]] Phi [ [[Add]] [[Sub]] ] - // CHECK-DAG: Return [ [[Phi]] ] + // CHECK-DAG: [[Const2:i\d+]] IntConstant 2 + // CHECK-DAG: [[Const5:i\d+]] IntConstant 5 + // CHECK-DAG: [[Add:i\d+]] Add [ [[Const5]] [[Const2]] ] + // CHECK-DAG: [[Sub:i\d+]] Sub [ [[Const5]] [[Const2]] ] + // CHECK-DAG: [[Phi:i\d+]] Phi [ [[Add]] [[Sub]] ] + // CHECK-DAG: Return [ [[Phi]] ] // CHECK-START: int ConstantFolding.JumpsAndConditionals(boolean) constant_folding (after) - // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3 - // CHECK-DAG: [[Const7:i[0-9]+]] IntConstant 7 - // CHECK-DAG: [[Phi:i[0-9]+]] Phi [ [[Const7]] [[Const3]] ] - // CHECK-DAG: Return [ [[Phi]] ] + // CHECK-DAG: [[Const3:i\d+]] IntConstant 3 + // CHECK-DAG: [[Const7:i\d+]] IntConstant 7 + // CHECK-DAG: [[Phi:i\d+]] Phi [ [[Const7]] [[Const3]] ] + // CHECK-DAG: Return [ [[Phi]] ] public static int JumpsAndConditionals(boolean cond) { int a, b, c; diff --git a/compiler/optimizing/test/Inliner.java b/compiler/optimizing/test/Inliner.java index ce7409c95..54cce62a5 100644 --- a/compiler/optimizing/test/Inliner.java +++ b/compiler/optimizing/test/Inliner.java @@ -17,12 +17,12 @@ public class Inliner { // CHECK-START: void Inliner.InlineVoid() inliner (before) - // CHECK-DAG: [[Const42:i[0-9]+]] IntConstant 42 - // CHECK-DAG: InvokeStaticOrDirect - // CHECK-DAG: InvokeStaticOrDirect [ [[Const42]] ] + // CHECK-DAG: [[Const42:i\d+]] IntConstant 42 + // CHECK-DAG: InvokeStaticOrDirect + // CHECK-DAG: InvokeStaticOrDirect [ [[Const42]] ] // CHECK-START: void Inliner.InlineVoid() inliner (after) - // CHECK-NOT: InvokeStaticOrDirect + // CHECK-NOT: InvokeStaticOrDirect public static void InlineVoid() { returnVoid(); @@ -30,119 +30,119 @@ public class Inliner { } // CHECK-START: int Inliner.InlineParameter(int) inliner (before) - // CHECK-DAG: [[Param:i[0-9]+]] ParameterValue - // CHECK-DAG: [[Result:i[0-9]+]] InvokeStaticOrDirect [ [[Param]] ] - // CHECK-DAG: Return [ [[Result]] ] + // CHECK-DAG: [[Param:i\d+]] ParameterValue + // CHECK-DAG: [[Result:i\d+]] InvokeStaticOrDirect [ [[Param]] ] + // CHECK-DAG: Return [ [[Result]] ] // CHECK-START: int Inliner.InlineParameter(int) inliner (after) - // CHECK-DAG: [[Param:i[0-9]+]] ParameterValue - // CHECK-DAG: Return [ [[Param]] ] + // CHECK-DAG: [[Param:i\d+]] ParameterValue + // CHECK-DAG: Return [ [[Param]] ] public static int InlineParameter(int a) { return returnParameter(a); } // CHECK-START: long Inliner.InlineWideParameter(long) inliner (before) - // CHECK-DAG: [[Param:j[0-9]+]] ParameterValue - // CHECK-DAG: [[Result:j[0-9]+]] InvokeStaticOrDirect [ [[Param]] ] - // CHECK-DAG: Return [ [[Result]] ] + // CHECK-DAG: [[Param:j\d+]] ParameterValue + // CHECK-DAG: [[Result:j\d+]] InvokeStaticOrDirect [ [[Param]] ] + // CHECK-DAG: Return [ [[Result]] ] // CHECK-START: long Inliner.InlineWideParameter(long) inliner (after) - // CHECK-DAG: [[Param:j[0-9]+]] ParameterValue - // CHECK-DAG: Return [ [[Param]] ] + // CHECK-DAG: [[Param:j\d+]] ParameterValue + // CHECK-DAG: Return [ [[Param]] ] public static long InlineWideParameter(long a) { return returnWideParameter(a); } // CHECK-START: java.lang.Object Inliner.InlineReferenceParameter(java.lang.Object) inliner (before) - // CHECK-DAG: [[Param:l[0-9]+]] ParameterValue - // CHECK-DAG: [[Result:l[0-9]+]] InvokeStaticOrDirect [ [[Param]] ] - // CHECK-DAG: Return [ [[Result]] ] + // CHECK-DAG: [[Param:l\d+]] ParameterValue + // CHECK-DAG: [[Result:l\d+]] InvokeStaticOrDirect [ [[Param]] ] + // CHECK-DAG: Return [ [[Result]] ] // CHECK-START: java.lang.Object Inliner.InlineReferenceParameter(java.lang.Object) inliner (after) - // CHECK-DAG: [[Param:l[0-9]+]] ParameterValue - // CHECK-DAG: Return [ [[Param]] ] + // CHECK-DAG: [[Param:l\d+]] ParameterValue + // CHECK-DAG: Return [ [[Param]] ] public static Object InlineReferenceParameter(Object o) { return returnReferenceParameter(o); } // CHECK-START: int Inliner.InlineInt() inliner (before) - // CHECK-DAG: [[Result:i[0-9]+]] InvokeStaticOrDirect - // CHECK-DAG: Return [ [[Result]] ] + // CHECK-DAG: [[Result:i\d+]] InvokeStaticOrDirect + // CHECK-DAG: Return [ [[Result]] ] // CHECK-START: int Inliner.InlineInt() inliner (after) - // CHECK-DAG: [[Const4:i[0-9]+]] IntConstant 4 - // CHECK-DAG: Return [ [[Const4]] ] + // CHECK-DAG: [[Const4:i\d+]] IntConstant 4 + // CHECK-DAG: Return [ [[Const4]] ] public static int InlineInt() { return returnInt(); } // CHECK-START: long Inliner.InlineWide() inliner (before) - // CHECK-DAG: [[Result:j[0-9]+]] InvokeStaticOrDirect - // CHECK-DAG: Return [ [[Result]] ] + // CHECK-DAG: [[Result:j\d+]] InvokeStaticOrDirect + // CHECK-DAG: Return [ [[Result]] ] // CHECK-START: long Inliner.InlineWide() inliner (after) - // CHECK-DAG: [[Const8:j[0-9]+]] LongConstant 8 - // CHECK-DAG: Return [ [[Const8]] ] + // CHECK-DAG: [[Const8:j\d+]] LongConstant 8 + // CHECK-DAG: Return [ [[Const8]] ] public static long InlineWide() { return returnWide(); } // CHECK-START: int Inliner.InlineAdd() inliner (before) - // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3 - // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5 - // CHECK-DAG: [[Result:i[0-9]+]] InvokeStaticOrDirect - // CHECK-DAG: Return [ [[Result]] ] + // CHECK-DAG: [[Const3:i\d+]] IntConstant 3 + // CHECK-DAG: [[Const5:i\d+]] IntConstant 5 + // CHECK-DAG: [[Result:i\d+]] InvokeStaticOrDirect + // CHECK-DAG: Return [ [[Result]] ] // CHECK-START: int Inliner.InlineAdd() inliner (after) - // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3 - // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5 - // CHECK-DAG: [[Add:i[0-9]+]] Add [ [[Const3]] [[Const5]] ] - // CHECK-DAG: Return [ [[Add]] ] + // CHECK-DAG: [[Const3:i\d+]] IntConstant 3 + // CHECK-DAG: [[Const5:i\d+]] IntConstant 5 + // CHECK-DAG: [[Add:i\d+]] Add [ [[Const3]] [[Const5]] ] + // CHECK-DAG: Return [ [[Add]] ] public static int InlineAdd() { return returnAdd(3, 5); } // CHECK-START: int Inliner.InlineFieldAccess() inliner (before) - // CHECK-DAG: [[After:i[0-9]+]] InvokeStaticOrDirect - // CHECK-DAG: Return [ [[After]] ] + // CHECK-DAG: [[After:i\d+]] InvokeStaticOrDirect + // CHECK-DAG: Return [ [[After]] ] // CHECK-START: int Inliner.InlineFieldAccess() inliner (after) - // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1 - // CHECK-DAG: [[Before:i[0-9]+]] StaticFieldGet - // CHECK-DAG: [[After:i[0-9]+]] Add [ [[Before]] [[Const1]] ] - // CHECK-DAG: StaticFieldSet [ {{l[0-9]+}} [[After]] ] - // CHECK-DAG: Return [ [[After]] ] + // CHECK-DAG: [[Const1:i\d+]] IntConstant 1 + // CHECK-DAG: [[Before:i\d+]] StaticFieldGet + // CHECK-DAG: [[After:i\d+]] Add [ [[Before]] [[Const1]] ] + // CHECK-DAG: StaticFieldSet [ {{l\d+}} [[After]] ] + // CHECK-DAG: Return [ [[After]] ] // CHECK-START: int Inliner.InlineFieldAccess() inliner (after) - // CHECK-NOT: InvokeStaticOrDirect + // CHECK-NOT: InvokeStaticOrDirect public static int InlineFieldAccess() { return incCounter(); } // CHECK-START: int Inliner.InlineWithControlFlow(boolean) inliner (before) - // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1 - // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3 - // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5 - // CHECK-DAG: [[Add:i[0-9]+]] InvokeStaticOrDirect [ [[Const1]] [[Const3]] ] - // CHECK-DAG: [[Sub:i[0-9]+]] InvokeStaticOrDirect [ [[Const5]] [[Const3]] ] - // CHECK-DAG: [[Phi:i[0-9]+]] Phi [ [[Add]] [[Sub]] ] - // CHECK-DAG: Return [ [[Phi]] ] + // CHECK-DAG: [[Const1:i\d+]] IntConstant 1 + // CHECK-DAG: [[Const3:i\d+]] IntConstant 3 + // CHECK-DAG: [[Const5:i\d+]] IntConstant 5 + // CHECK-DAG: [[Add:i\d+]] InvokeStaticOrDirect [ [[Const1]] [[Const3]] ] + // CHECK-DAG: [[Sub:i\d+]] InvokeStaticOrDirect [ [[Const5]] [[Const3]] ] + // CHECK-DAG: [[Phi:i\d+]] Phi [ [[Add]] [[Sub]] ] + // CHECK-DAG: Return [ [[Phi]] ] // CHECK-START: int Inliner.InlineWithControlFlow(boolean) inliner (after) - // CHECK-DAG: [[Const1:i[0-9]+]] IntConstant 1 - // CHECK-DAG: [[Const3:i[0-9]+]] IntConstant 3 - // CHECK-DAG: [[Const5:i[0-9]+]] IntConstant 5 - // CHECK-DAG: [[Add:i[0-9]+]] Add [ [[Const1]] [[Const3]] ] - // CHECK-DAG: [[Sub:i[0-9]+]] Sub [ [[Const5]] [[Const3]] ] - // CHECK-DAG: [[Phi:i[0-9]+]] Phi [ [[Add]] [[Sub]] ] - // CHECK-DAG: Return [ [[Phi]] ] + // CHECK-DAG: [[Const1:i\d+]] IntConstant 1 + // CHECK-DAG: [[Const3:i\d+]] IntConstant 3 + // CHECK-DAG: [[Const5:i\d+]] IntConstant 5 + // CHECK-DAG: [[Add:i\d+]] Add [ [[Const1]] [[Const3]] ] + // CHECK-DAG: [[Sub:i\d+]] Sub [ [[Const5]] [[Const3]] ] + // CHECK-DAG: [[Phi:i\d+]] Phi [ [[Add]] [[Sub]] ] + // CHECK-DAG: Return [ [[Phi]] ] public static int InlineWithControlFlow(boolean cond) { int x, const1, const3, const5; diff --git a/tools/checker.py b/tools/checker.py index 5e910ec15..b1abea2fe 100755 --- a/tools/checker.py +++ b/tools/checker.py @@ -159,6 +159,23 @@ class CheckElement(CommonEqualityMixin): """Supported language constructs.""" Text, Pattern, VarRef, VarDef = range(4) + rStartOptional = r"(" + rEndOptional = r")?" + + rName = r"([a-zA-Z][a-zA-Z0-9]*)" + rRegex = r"(.+?)" + rPatternStartSym = r"(\{\{)" + rPatternEndSym = r"(\}\})" + rVariableStartSym = r"(\[\[)" + rVariableEndSym = r"(\]\])" + rVariableSeparator = r"(:)" + + regexPattern = rPatternStartSym + rRegex + rPatternEndSym + regexVariable = rVariableStartSym + \ + rName + \ + (rStartOptional + rVariableSeparator + rRegex + rEndOptional) + \ + rVariableEndSym + def __init__(self, variant, name, pattern): self.variant = variant self.name = name @@ -170,22 +187,21 @@ class CheckElement(CommonEqualityMixin): @staticmethod def parsePattern(patternElem): - return CheckElement(CheckElement.Variant.Pattern, None, patternElem[2:len(patternElem)-2]) + return CheckElement(CheckElement.Variant.Pattern, None, patternElem[2:-2]) @staticmethod def parseVariable(varElem): colonPos = varElem.find(":") if colonPos == -1: # Variable reference - name = varElem[2:len(varElem)-2] + name = varElem[2:-2] return CheckElement(CheckElement.Variant.VarRef, name, None) else: # Variable definition name = varElem[2:colonPos] - body = varElem[colonPos+1:len(varElem)-2] + body = varElem[colonPos+1:-2] return CheckElement(CheckElement.Variant.VarDef, name, body) - class CheckLine(CommonEqualityMixin): """Representation of a single assertion in the check file formed of one or more regex elements. Matching against an output line is successful only @@ -226,24 +242,6 @@ class CheckLine(CommonEqualityMixin): starts = map(lambda m: len(string) if m is None else m.start(), matches) return min(starts) - # Returns the regex for finding a regex pattern in the check line. - def __getPatternRegex(self): - rStartSym = "\{\{" - rEndSym = "\}\}" - rBody = ".+?" - return rStartSym + rBody + rEndSym - - # Returns the regex for finding a variable use in the check line. - def __getVariableRegex(self): - rStartSym = "\[\[" - rEndSym = "\]\]" - rStartOptional = "(" - rEndOptional = ")?" - rName = "[a-zA-Z][a-zA-Z0-9]*" - rSeparator = ":" - rBody = ".+?" - return rStartSym + rName + rStartOptional + rSeparator + rBody + rEndOptional + rEndSym - # This method parses the content of a check line stripped of the initial # comment symbol and the CHECK keyword. def __parse(self, line): @@ -251,9 +249,9 @@ class CheckLine(CommonEqualityMixin): # Loop as long as there is something to parse. while line: # Search for the nearest occurrence of the special markers. - matchWhitespace = re.search("\s+", line) - matchPattern = re.search(self.__getPatternRegex(), line) - matchVariable = re.search(self.__getVariableRegex(), line) + matchWhitespace = re.search(r"\s+", line) + matchPattern = re.search(CheckElement.regexPattern, line) + matchVariable = re.search(CheckElement.regexVariable, line) # If one of the above was identified at the current position, extract them # from the line, parse them and add to the list of line parts. @@ -262,7 +260,7 @@ class CheckLine(CommonEqualityMixin): # a whitespace, we add a regex pattern for an arbitrary non-zero number # of whitespaces. line = line[matchWhitespace.end():] - lineParts.append(CheckElement.parsePattern("{{\s+}}")) + lineParts.append(CheckElement.parsePattern(r"{{\s+}}")) elif self.__isMatchAtStart(matchPattern): pattern = line[0:matchPattern.end()] line = line[matchPattern.end():] @@ -536,16 +534,16 @@ class CheckFile(FileSplitMixin): # followed by the CHECK keyword, given attribute and a colon at the very # beginning of the line. Whitespaces are ignored. def _extractLine(self, prefix, line): - ignoreWhitespace = "\s*" - commentSymbols = ["//", "#"] - prefixRegex = ignoreWhitespace + \ - "(" + "|".join(commentSymbols) + ")" + \ - ignoreWhitespace + \ - prefix + ":" + rIgnoreWhitespace = r"\s*" + rCommentSymbols = [r"//", r"#"] + regexPrefix = rIgnoreWhitespace + \ + r"(" + r"|".join(rCommentSymbols) + r")" + \ + rIgnoreWhitespace + \ + prefix + r":" # The 'match' function succeeds only if the pattern is matched at the # beginning of the line. - match = re.match(prefixRegex, line) + match = re.match(regexPrefix, line) if match is not None: return line[match.end():].strip() else: -- 2.11.0