X-Git-Url: https://git.cworth.org/git?p=apitrace-tests;a=blobdiff_plain;f=tracematch.py;h=c1e0948210e8405ba8fdcca6ef3dc1a8680429f2;hp=68949b16ce35fad0d6ee37c1ee0ad94125255ede;hb=0ad1e68df802278f776c4d36f0c266aca62418b8;hpb=d9858b16096ac4ec7c99f1430a6ee934e33db2e0 diff --git a/tracematch.py b/tracematch.py index 68949b1..c1e0948 100755 --- a/tracematch.py +++ b/tracematch.py @@ -430,7 +430,7 @@ class Parser: ####################################################################### -ID, NUMBER, HEXNUM, STRING, WILDCARD, PRAGMA, LPAREN, RPAREN, LCURLY, RCURLY, COMMA, AMP, EQUAL, PLUS, VERT, BLOB = xrange(16) +ID, NUMBER, HEXNUM, STRING, WILDCARD, LPAREN, RPAREN, LCURLY, RCURLY, COMMA, AMP, EQUAL, PLUS, VERT, BLOB = xrange(15) class CallScanner(Scanner): @@ -440,6 +440,9 @@ class CallScanner(Scanner): # whitespace (SKIP, r'[ \t\f\r\n\v]+', False), + # comments + (SKIP, r'//[^\r\n]*', False), + # Alphanumeric IDs (ID, r'[a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z_][a-zA-Z0-9_]*)?', True), @@ -454,9 +457,6 @@ class CallScanner(Scanner): # Wildcard (WILDCARD, r'<[^>]*>', False), - - # Pragma - (PRAGMA, r'#[^\r\n]*', False), ] # symbol table @@ -510,15 +510,8 @@ class TraceParser(Parser): def parse(self): while not self.eof(): - self.parse_element() - return TraceMatcher(self.calls) - - def parse_element(self): - if self.lookahead.type == PRAGMA: - token = self.consume() - self.handlePragma(token.text) - else: self.parse_call() + return TraceMatcher(self.calls) def parse_call(self): if self.lookahead.type == NUMBER: @@ -686,14 +679,11 @@ class TraceParser(Parser): def handleCall(self, callNo, functionName, args, ret): raise NotImplementedError - def handlePragma(self, line): - raise NotImplementedError - class RefTraceParser(TraceParser): - def __init__(self, stream): - TraceParser.__init__(self, stream) + def __init__(self, fileName): + TraceParser.__init__(self, open(fileName, 'rt')) self.calls = [] def parse(self): @@ -730,9 +720,6 @@ class RefTraceParser(TraceParser): def handleCall(self, callNo, functionName, args, ret): call = CallMatcher(callNo, functionName, args, ret) self.calls.append(call) - - def handlePragma(self, line): - pass class SrcTraceParser(TraceParser): @@ -792,8 +779,7 @@ def main(): refFileName, srcFileName = args - refStream = open(refFileName, 'rt') - refParser = RefTraceParser(refStream) + refParser = RefTraceParser(refFileName) refTrace = refParser.parse() if options.verbose: sys.stdout.write('// Reference\n') @@ -801,8 +787,8 @@ def main(): sys.stdout.write('\n') if srcFileName.endswith('.trace'): - cmd = [options.apitrace, 'dump', '--color=never', srcFileName] - p = subprocess.Popen(cmd, stdout=subprocess.PIPE) + cmd = [options.apitrace, 'dump', '--verbose', '--color=never', srcFileName] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) srcStream = p.stdout else: srcStream = open(srcFileName, 'rt')