(self, srcname, destname, line_directive)
| 677 | return line |
| 678 | |
| 679 | def convertFile(self, srcname, destname, line_directive): |
| 680 | self._reset() |
| 681 | |
| 682 | with io.open(srcname, "rt", encoding="utf-8") as fin: |
| 683 | srclines = fin.readlines() |
| 684 | |
| 685 | code = '' |
| 686 | |
| 687 | modified = False |
| 688 | |
| 689 | linenr = 0 |
| 690 | for line in srclines: |
| 691 | if not modified: |
| 692 | line_orig = line |
| 693 | else: |
| 694 | line_orig = None |
| 695 | |
| 696 | linenr += 1 |
| 697 | # Compile Token::Match and Token::simpleMatch |
| 698 | line = self._replaceTokenMatch(line, linenr, srcname) |
| 699 | |
| 700 | # Compile Token::findsimplematch |
| 701 | line = self._replaceTokenFindMatch(line, linenr, srcname) |
| 702 | |
| 703 | # Cache plain C-strings in C++ strings |
| 704 | line = self._replaceCStrings(line) |
| 705 | |
| 706 | if not modified and not line_orig == line: |
| 707 | modified = True |
| 708 | |
| 709 | code += line |
| 710 | |
| 711 | # Compute matchFunctions |
| 712 | strFunctions = ''.join(self._rawMatchFunctions) |
| 713 | |
| 714 | lineno = '' |
| 715 | if line_directive: |
| 716 | lineno = '#line 1 "' + srcname + '"\n' |
| 717 | |
| 718 | header = '#include "matchcompiler.h"\n' |
| 719 | header += '#include <string>\n' |
| 720 | header += '#include <cstring>\n' |
| 721 | if len(self._rawMatchFunctions): |
| 722 | header += '#include "errorlogger.h"\n' |
| 723 | header += '#include "token.h"\n' |
| 724 | header += '#if defined(__clang__)\n' |
| 725 | header += '#include "config.h"\n' |
| 726 | header += '#define MAYBE_UNUSED [[maybe_unused]]\n' # this attribute is also available in earlier standards |
| 727 | header += 'SUPPRESS_WARNING_CLANG_PUSH("-Wc++17-attribute-extensions")\n' # suppress waning about using above attribute in earlier standard |
| 728 | header += '#else\n' |
| 729 | header += '#define MAYBE_UNUSED\n' |
| 730 | header += '#endif\n' |
| 731 | |
| 732 | footer = '' |
| 733 | if len(self._rawMatchFunctions): |
| 734 | footer += '#if defined(__clang__)\n' |
| 735 | footer += 'SUPPRESS_WARNING_CLANG_POP\n' |
| 736 | footer += '#endif\n' |
no test coverage detected