Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions tools/matchcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _compilePattern(self, pattern, nr, varid,
arg2 = ', const int varid'

ret = '// pattern: ' + pattern + '\n'
ret += 'static inline bool match' + \
ret += 'MAYBE_UNUSED static inline bool match' + \
str(nr) + '(' + tokenType + '* tok' + arg2 + ') {\n'
returnStatement = 'return false;\n'

Expand Down Expand Up @@ -290,7 +290,7 @@ def _compileFindPattern(self, pattern, findmatchnr, endToken, varId):
more_args += ', int varid'

ret = '// pattern: ' + pattern + '\n'
ret += 'template<class T> static inline T * findmatch' + \
ret += 'template<class T> MAYBE_UNUSED static inline T * findmatch' + \
str(findmatchnr) + '(T * start_tok' + more_args + ') {\n'
ret += ' for (; start_tok' + endCondition + \
'; start_tok = start_tok->next()) {\n'
Expand Down Expand Up @@ -373,7 +373,7 @@ def _compileVerifyTokenMatch(
if varId:
more_args = ', const int varid'

ret = 'static inline bool match_verify' + \
ret = 'MAYBE_UNUSED static inline bool match_verify' + \
str(verifyNumber) + '(const Token *tok' + more_args + ') {\n'

origMatchName = 'Match'
Expand Down Expand Up @@ -509,7 +509,7 @@ def _compileVerifyTokenFindMatch(
if varId:
more_args += ', const int varid'

ret = 'template < class T > static inline T * findmatch_verify' + \
ret = 'template < class T > MAYBE_UNUSED static inline T * findmatch_verify' + \
str(verifyNumber) + '(T * tok' + more_args + ') {\n'

origFindMatchName = 'findmatch'
Expand Down Expand Up @@ -721,13 +721,29 @@ def convertFile(self, srcname, destname, line_directive):
if len(self._rawMatchFunctions):
header += '#include "errorlogger.h"\n'
header += '#include "token.h"\n'
header += '#if defined(__clang__)\n'
header += '#include "config.h"\n'
header += '#define MAYBE_UNUSED [[maybe_unused]]\n' # this attribute is also available in earlier standards
header += 'SUPPRESS_WARNING_CLANG_PUSH("-Wc++17-attribute-extensions")\n' # suppress waning about using above attribute in earlier standard
header += '#else\n'
header += '#define MAYBE_UNUSED\n'
header += '#endif\n'

footer = ''
if len(self._rawMatchFunctions):
footer += '#if defined(__clang__)\n'
footer += 'SUPPRESS_WARNING_CLANG_POP\n'
footer += '#endif\n'
footer += '#undef MAYBE_UNUSED\n'

with io.open(destname, 'wt', encoding="utf-8") as fout:
if modified or len(self._rawMatchFunctions):
fout.write(header)
fout.write(strFunctions)
fout.write(lineno)
fout.write(code)
if modified or len(self._rawMatchFunctions):
fout.write(footer)


def main():
Expand Down