MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / MatchCompiler

Class MatchCompiler

tools/matchcompiler.py:99–746  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99class MatchCompiler:
100
101 def __init__(self, verify_mode=False, show_skipped=False):
102 self._verifyMode = verify_mode
103 self._showSkipped = show_skipped
104 self._reset()
105
106 def _reset(self):
107 self._rawMatchFunctions = []
108 self._matchFunctionCache = {}
109
110 @staticmethod
111 def _generateCacheSignature(
112 pattern, endToken=None, varId=None, isFindMatch=False):
113 sig = pattern
114
115 if endToken:
116 sig += '|ENDTOKEN'
117 else:
118 sig += '|NO-ENDTOKEN'
119
120 if varId:
121 sig += '|VARID'
122 else:
123 sig += '|NO-VARID'
124
125 if isFindMatch:
126 sig += '|ISFINDMATCH'
127 else:
128 sig += '|NORMALMATCH'
129
130 return sig
131
132 def _lookupMatchFunctionId(
133 self, pattern, endToken=None, varId=None, isFindMatch=False):
134 signature = self._generateCacheSignature(
135 pattern, endToken, varId, isFindMatch)
136
137 if signature in self._matchFunctionCache:
138 return self._matchFunctionCache[signature]
139
140 return None
141
142 def _insertMatchFunctionId(
143 self, id, pattern, endToken=None, varId=None, isFindMatch=False):
144 signature = self._generateCacheSignature(
145 pattern, endToken, varId, isFindMatch)
146
147 # function signature should not be in the cache
148 assert(
149 self._lookupMatchFunctionId(
150 pattern,
151 endToken,
152 varId,
153 isFindMatch) is None)
154
155 self._matchFunctionCache[signature] = id
156

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected