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