Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: ppapi/generators/idl_parser.py

Issue 8161006: Allow enum values in IDL files to be simple arithmetic expressions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/generators/idl_lexer.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """ Parser for PPAPI IDL """ 7 """ Parser for PPAPI IDL """
8 8
9 # 9 #
10 # IDL Parser 10 # IDL Parser
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 | OCT""" 421 | OCT"""
422 p[0] = p[1] 422 p[0] = p[1]
423 if self.parse_debug: DumpReduction('number', p) 423 if self.parse_debug: DumpReduction('number', p)
424 424
425 def p_number_lshift(self, p): 425 def p_number_lshift(self, p):
426 """number : integer LSHIFT INT""" 426 """number : integer LSHIFT INT"""
427 p[0] = "%s << %s" % (p[1], p[3]) 427 p[0] = "%s << %s" % (p[1], p[3])
428 if self.parse_debug: DumpReduction('number_lshift', p) 428 if self.parse_debug: DumpReduction('number_lshift', p)
429 429
430 # 430 #
431 # Expression
432 #
433 # A simple arithmetic expression.
434 #
435 precedence = (
436 ('left','LSHIFT','RSHIFT'),
437 ('left','+','-'),
438 ('left','*','/'),
439 ('right','UMINUS'),
440 )
441
442 def p_expression_binop(self, p):
443 """expression : expression '+' expression
444 | expression '-' expression
445 | expression '*' expression
446 | expression '/' expression
447 | expression LSHIFT expression
448 | expression RSHIFT expression"""
449 if p[2] == '+' : p[0] = p[1] + p[3]
noelallen1 2011/10/05 23:35:51 I think what you really want to do, is take a bunc
450 elif p[2] == '-': p[0] = p[1] - p[3]
451 elif p[2] == '*': p[0] = p[1] * p[3]
452 elif p[2] == '/': p[0] = p[1] / p[3]
453 elif p[2] == 'LSHIFT': p[0] = p[1] << p[3]
454 elif p[2] == 'RSHIFT': p[0] = p[1] >> p[3]
455 if self.parse_debug: DumpReduction('expression_binop', p)
456
457 def p_expression_uminus(self, p):
458 "expression : '-' expression %prec UMINUS"
459 p[0] = -p[2]
460 if self.parse_debug: DumpReduction('expression_uminus', p)
461
462 def p_expression_term(self, p):
463 "expression : '(' expression ')'"
464 p[0] = p[2]
465 if self.parse_debug: DumpReduction('expression_term', p)
466
467 def p_expression_symbol(self, p):
468 "expression : SYMBOL"
469 p[0] = p[1]
470 if self.parse_debug: DumpReduction('expression_symbol', p)
471
472 def p_expression_number(self, p):
473 "expression : number"
474 p[0] = p[1]
noelallen1 2011/10/05 23:35:51 only allow INT, HEX, OCT? No float
475 if self.parse_debug: DumpReduction('expression_integer', p)
476
477 #
431 # Array List 478 # Array List
432 # 479 #
433 # Defined a list of array sizes (if any). 480 # Defined a list of array sizes (if any).
434 # 481 #
435 def p_arrays(self, p): 482 def p_arrays(self, p):
436 """arrays : '[' ']' arrays 483 """arrays : '[' ']' arrays
437 | '[' integer ']' arrays 484 | '[' integer ']' arrays
438 | """ 485 | """
439 # If there are 3 tokens plus a return slot it is an unsized array 486 # If there are 3 tokens plus a return slot it is an unsized array
440 if len(p) == 4: 487 if len(p) == 4:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 # 563 #
517 # An enumeration is a set of named integer constants. An enumeration 564 # An enumeration is a set of named integer constants. An enumeration
518 # is valid type which can be referenced in other definitions. 565 # is valid type which can be referenced in other definitions.
519 # 566 #
520 def p_enum_block(self, p): 567 def p_enum_block(self, p):
521 """enum_block : modifiers ENUM SYMBOL '{' enum_list '}' ';'""" 568 """enum_block : modifiers ENUM SYMBOL '{' enum_list '}' ';'"""
522 p[0] = self.BuildNamed('Enum', p, 3, ListFromConcat(p[1], p[5])) 569 p[0] = self.BuildNamed('Enum', p, 3, ListFromConcat(p[1], p[5]))
523 if self.parse_debug: DumpReduction('enum_block', p) 570 if self.parse_debug: DumpReduction('enum_block', p)
524 571
525 def p_enum_list(self, p): 572 def p_enum_list(self, p):
526 """enum_list : modifiers SYMBOL '=' number enum_cont 573 """enum_list : modifiers SYMBOL '=' expression enum_cont
527 | modifiers SYMBOL enum_cont""" 574 | modifiers SYMBOL enum_cont"""
528 if len(p) > 4: 575 if len(p) > 4:
529 val = self.BuildAttribute('VALUE', p[4]) 576 val = self.BuildAttribute('VALUE', p[4])
530 enum = self.BuildNamed('EnumItem', p, 2, ListFromConcat(val, p[1])) 577 enum = self.BuildNamed('EnumItem', p, 2, ListFromConcat(val, p[1]))
531 p[0] = ListFromConcat(enum, p[5]) 578 p[0] = ListFromConcat(enum, p[5])
532 else: 579 else:
533 enum = self.BuildNamed('EnumItem', p, 2, p[1]) 580 enum = self.BuildNamed('EnumItem', p, 2, p[1])
534 p[0] = ListFromConcat(enum, p[3]) 581 p[0] = ListFromConcat(enum, p[3])
535 if self.parse_debug: DumpReduction('enum_list', p) 582 if self.parse_debug: DumpReduction('enum_list', p)
536 583
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 ast = ParseFiles(filenames) 1056 ast = ParseFiles(filenames)
1010 errs = ast.GetProperty('ERRORS') 1057 errs = ast.GetProperty('ERRORS')
1011 if errs: 1058 if errs:
1012 ErrOut.Log('Found %d error(s).' % errs); 1059 ErrOut.Log('Found %d error(s).' % errs);
1013 InfoOut.Log("%d files processed." % len(filenames)) 1060 InfoOut.Log("%d files processed." % len(filenames))
1014 return errs 1061 return errs
1015 1062
1016 if __name__ == '__main__': 1063 if __name__ == '__main__':
1017 sys.exit(Main(sys.argv[1:])) 1064 sys.exit(Main(sys.argv[1:]))
1018 1065
OLDNEW
« no previous file with comments | « ppapi/generators/idl_lexer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698