matchcompiler: --show-skipped: print locations of skipped patterns in file:line notation.
This commit is contained in:
parent
cf24ea5221
commit
b687e011f2
|
@ -382,7 +382,7 @@ class MatchCompiler:
|
|||
patternNumber) + '(' + tok + more_args + ')' + line[start_pos + end_pos:]
|
||||
)
|
||||
|
||||
def _replaceTokenMatch(self, line):
|
||||
def _replaceTokenMatch(self, line, linenr, filename):
|
||||
while True:
|
||||
is_simplematch = False
|
||||
pos1 = line.find('Token::Match(')
|
||||
|
@ -409,7 +409,7 @@ class MatchCompiler:
|
|||
res = re.match(r'\s*"((?:.|\\")*?)"\s*$', raw_pattern)
|
||||
if res is None:
|
||||
if self._showSkipped:
|
||||
print("[SKIPPING] match pattern: " + raw_pattern)
|
||||
print(filename +":" + str(linenr) +" skipping match pattern:" + raw_pattern)
|
||||
break # Non-const pattern - bailout
|
||||
|
||||
pattern = res.group(1)
|
||||
|
@ -515,7 +515,7 @@ class MatchCompiler:
|
|||
findMatchNumber) + '(' + tok + more_args + ') ' + line[start_pos + end_pos:]
|
||||
)
|
||||
|
||||
def _replaceTokenFindMatch(self, line):
|
||||
def _replaceTokenFindMatch(self, line, linenr, filename):
|
||||
pos1 = 0
|
||||
while True:
|
||||
is_findsimplematch = True
|
||||
|
@ -565,7 +565,7 @@ class MatchCompiler:
|
|||
res = re.match(r'\s*"((?:.|\\")*?)"\s*$', pattern)
|
||||
if res is None:
|
||||
if self._showSkipped:
|
||||
print("[SKIPPING] findmatch pattern: " + pattern)
|
||||
print(filename +":" + str(linenr) +" skipping findmatch pattern:" + pattern)
|
||||
break # Non-const pattern - bailout
|
||||
|
||||
pattern = res.group(1)
|
||||
|
@ -617,12 +617,14 @@ class MatchCompiler:
|
|||
# header += '#include <iostream>\n'
|
||||
code = ''
|
||||
|
||||
linenr = 0
|
||||
for line in srclines:
|
||||
linenr += 1
|
||||
# Compile Token::Match and Token::simpleMatch
|
||||
line = self._replaceTokenMatch(line)
|
||||
line = self._replaceTokenMatch(line, linenr, srcname)
|
||||
|
||||
# Compile Token::findsimplematch
|
||||
line = self._replaceTokenFindMatch(line)
|
||||
line = self._replaceTokenFindMatch(line, linenr, srcname)
|
||||
|
||||
# Cache plain C-strings in C++ strings
|
||||
line = self._replaceCStrings(line)
|
||||
|
|
|
@ -35,103 +35,103 @@ class MatchCompilerTest(unittest.TestCase):
|
|||
|
||||
def test_replaceTokenMatch(self):
|
||||
input = 'if (Token::Match(tok, "foobar")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (match1(tok)) {')
|
||||
|
||||
input = 'if (Token::Match(tok->next()->next(), "foobar %type% %num%")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (match2(tok->next()->next())) {')
|
||||
|
||||
input = 'if (Token::Match(tok, "foo\"special\"bar %num%")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (match3(tok)) {')
|
||||
|
||||
# test that non-static patterns get passed on unmatched
|
||||
input = 'if (Token::Match(tok, "struct " + varname)) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (Token::Match(tok, "struct " + varname)) {')
|
||||
|
||||
# test that non-static patterns get passed on unmatched
|
||||
input = 'if (Token::Match(tok, "extern \"C\" " + varname)) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (Token::Match(tok, "extern \"C\" " + varname)) {')
|
||||
|
||||
def test_replaceTokenMatchWithVarId(self):
|
||||
input = 'if (Token::Match(tok, "foobar %varid%", 123)) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (match1(tok, 123)) {')
|
||||
|
||||
input = 'if (Token::Match(tok->next()->next(), "%varid% foobar", tok->varId())) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (match2(tok->next()->next(), tok->varId())) {')
|
||||
|
||||
input = 'if (Token::Match(tok, "foo\"special\"bar %type% %varid%", my_varid_cache)) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (match3(tok, my_varid_cache)) {')
|
||||
|
||||
# test caching: reuse existing matchX()
|
||||
input = 'if (Token::Match(tok, "foobar %varid%", 123)) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (match1(tok, 123)) {')
|
||||
|
||||
# two in one line
|
||||
input = 'if (Token::Match(tok, "foobar2 %varid%", 123) || Token::Match(tok, "%type% %varid%", 123)) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (match4(tok, 123) || match5(tok, 123)) {')
|
||||
|
||||
def test_replaceTokenSimpleMatch(self):
|
||||
input = 'if (Token::simpleMatch(tok, "foobar")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (match1(tok)) {')
|
||||
|
||||
input = 'if (Token::simpleMatch(tok->next()->next(), "foobar")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (match1(tok->next()->next())) {')
|
||||
|
||||
input = 'if (Token::simpleMatch(tok, "foo\"special\"bar")) {'
|
||||
output = self.mc._replaceTokenMatch(input)
|
||||
output = self.mc._replaceTokenMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (match2(tok)) {')
|
||||
|
||||
def test_replaceTokenFindSimpleMatch(self):
|
||||
input = 'if (Token::findsimplematch(tok, "foobar")) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
output = self.mc._replaceTokenFindMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (findmatch1(tok) ) {')
|
||||
|
||||
input = 'if (Token::findsimplematch(tok->next()->next(), "foobar", tok->link())) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
output = self.mc._replaceTokenFindMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch2(tok->next()->next(), tok->link()) ) {')
|
||||
|
||||
input = 'if (Token::findsimplematch(tok, "foo\"special\"bar")) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
output = self.mc._replaceTokenFindMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch3(tok) ) {')
|
||||
|
||||
def test_replaceTokenFindMatch(self):
|
||||
input = 'if (Token::findmatch(tok, "foobar")) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
output = self.mc._replaceTokenFindMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (findmatch1(tok) ) {')
|
||||
|
||||
# findmatch with varid
|
||||
input = 'if (Token::findmatch(tok, "foobar %varid%", tok->varId())) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
output = self.mc._replaceTokenFindMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(output, 'if (findmatch2(tok, tok->varId()) ) {')
|
||||
|
||||
# findmatch with end token
|
||||
input = 'if (Token::findmatch(tok->next()->next(), "foobar %type%", tok->link())) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
output = self.mc._replaceTokenFindMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch3(tok->next()->next(), tok->link()) ) {')
|
||||
|
||||
# findmatch with end token and varid
|
||||
input = 'if (Token::findmatch(tok->next()->next(), "foobar %type% %varid%", tok->link(), 123)) {'
|
||||
output = self.mc._replaceTokenFindMatch(input)
|
||||
output = self.mc._replaceTokenFindMatch(input, 0, "foo.cpp")
|
||||
self.assertEqual(
|
||||
output, 'if (findmatch4(tok->next()->next(), tok->link(), 123) ) {')
|
||||
|
||||
|
|
Loading…
Reference in New Issue