Fixed #4797 (matchcompiler.py cannot handle overloaded findsimplematch and findmatch)

This commit is contained in:
Frank Zingsheim 2013-05-15 18:18:58 +02:00
parent 4d781a7492
commit 650027a07a
1 changed files with 10 additions and 10 deletions

View File

@ -111,12 +111,12 @@ class MatchCompiler:
return '(tok->str()==' + self._insertMatchStr(tok) + ')/* ' + tok + ' */' return '(tok->str()==' + self._insertMatchStr(tok) + ')/* ' + tok + ' */'
def _compilePattern(self, pattern, nr, varid, isFindMatch=False): def _compilePattern(self, pattern, nr, varid, isFindMatch=False, tokenType="const Token"):
ret = '' ret = ''
returnStatement = '' returnStatement = ''
if isFindMatch: if isFindMatch:
ret = '\nconst Token *tok = start_tok;\n' ret = '\n ' + tokenType + ' * tok = start_tok;\n'
returnStatement = 'continue;\n' returnStatement = 'continue;\n'
else: else:
arg2 = '' arg2 = ''
@ -124,7 +124,7 @@ class MatchCompiler:
arg2 = ', const unsigned int varid' arg2 = ', const unsigned int varid'
ret = '// pattern: ' + pattern + '\n' ret = '// pattern: ' + pattern + '\n'
ret += 'static bool match' + str(nr) + '(const Token *tok'+arg2+') {\n' ret += 'static bool match' + str(nr) + '(' + tokenType + '* tok'+arg2+') {\n'
returnStatement = 'return false;\n' returnStatement = 'return false;\n'
tokens = pattern.split(' ') tokens = pattern.split(' ')
@ -199,16 +199,16 @@ class MatchCompiler:
more_args = '' more_args = ''
endCondition = '' endCondition = ''
if endToken: if endToken:
more_args += ', const Token *end' more_args += ', const Token * end'
endCondition = ' && start_tok != end' endCondition = ' && start_tok != end'
if varId: if varId:
more_args += ', unsigned int varid' more_args += ', unsigned int varid'
ret = '// pattern: ' + pattern + '\n' ret = '// pattern: ' + pattern + '\n'
ret += 'static const Token *findmatch' + str(findmatchnr) + '(const Token *start_tok'+more_args+') {\n' ret += 'template<class T> T * findmatch' + str(findmatchnr) + '(T * start_tok'+more_args+') {\n'
ret += ' for (; start_tok' + endCondition + '; start_tok = start_tok->next()) {\n' ret += ' for (; start_tok' + endCondition + '; start_tok = start_tok->next()) {\n'
ret += self._compilePattern(pattern, -1, varId, True) ret += self._compilePattern(pattern, -1, varId, True, 'T')
ret += ' }\n' ret += ' }\n'
ret += ' return NULL;\n}\n' ret += ' return NULL;\n}\n'
@ -365,25 +365,25 @@ class MatchCompiler:
def _compileVerifyTokenFindMatch(self, is_findsimplematch, verifyNumber, pattern, patternNumber, endToken, varId): def _compileVerifyTokenFindMatch(self, is_findsimplematch, verifyNumber, pattern, patternNumber, endToken, varId):
more_args = '' more_args = ''
if endToken: if endToken:
more_args += ', const Token *endToken' more_args += ', const Token * endToken'
if varId: if varId:
more_args += ', const unsigned int varid' more_args += ', const unsigned int varid'
ret = 'static const Token *findmatch_verify' + str(verifyNumber) + '(const Token *tok'+more_args+') {\n' ret = 'template < class T > T * findmatch_verify' + str(verifyNumber) + '(T * tok'+more_args+') {\n'
origFindMatchName = 'findmatch' origFindMatchName = 'findmatch'
if is_findsimplematch: if is_findsimplematch:
origMatchName = 'findsimplematch' origMatchName = 'findsimplematch'
assert(varId == None) assert(varId == None)
ret += ' const Token *res_compiled_findmatch = findmatch'+str(patternNumber)+'(tok' ret += ' T * res_compiled_findmatch = findmatch'+str(patternNumber)+'(tok'
if endToken: if endToken:
ret += ', endToken' ret += ', endToken'
if varId: if varId:
ret += ', varid' ret += ', varid'
ret += ');\n' ret += ');\n'
ret += ' const Token *res_parsed_findmatch = Token::' + origFindMatchName + '(tok, "' + pattern + '"' ret += ' T * res_parsed_findmatch = Token::' + origFindMatchName + '(tok, "' + pattern + '"'
if endToken: if endToken:
ret += ', endToken' ret += ', endToken'
if varId: if varId: