X-Git-Url: https://git.cworth.org/git?p=apitrace-tests;a=blobdiff_plain;f=tracematch.py;h=aebbfd3d5c2a3be001e4a736a9e881d6825c4d25;hp=68949b16ce35fad0d6ee37c1ee0ad94125255ede;hb=c41cfb0f8cca8818f0a512d58f4c43820321e622;hpb=d9858b16096ac4ec7c99f1430a6ee934e33db2e0 diff --git a/tracematch.py b/tracematch.py index 68949b1..aebbfd3 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: @@ -605,11 +598,12 @@ class TraceParser(Parser): return self.handleString(value) elif self.match(NUMBER): token = self.consume() - if '.' in token.text: + try: + value = int(token.text) + except ValueError: value = float(token.text) return self.handleFloat(value) else: - value = int(token.text) return self.handleInt(value) elif self.match(HEXNUM): token = self.consume() @@ -686,14 +680,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 +721,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 +780,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 +788,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')