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

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') | ppapi/generators/test_cgen/enum_typedef.h » ('j') | 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if self.parse_debug: DumpReduction('value', p) 406 if self.parse_debug: DumpReduction('value', p)
407 407
408 # Integers are numbers which may not be floats used in cases like array sizes. 408 # Integers are numbers which may not be floats used in cases like array sizes.
409 def p_integer(self, p): 409 def p_integer(self, p):
410 """integer : HEX 410 """integer : HEX
411 | INT 411 | INT
412 | OCT""" 412 | OCT"""
413 p[0] = p[1] 413 p[0] = p[1]
414 if self.parse_debug: DumpReduction('integer', p) 414 if self.parse_debug: DumpReduction('integer', p)
415 415
416 # Numbers are integers or floats. 416 #
417 def p_number(self, p): 417 # Expression
418 """number : FLOAT 418 #
419 | HEX 419 # A simple arithmetic expression.
420 | INT 420 #
421 | OCT""" 421 precedence = (
422 ('left','|','&','^'),
423 ('left','LSHIFT','RSHIFT'),
424 ('left','+','-'),
425 ('left','*','/'),
426 ('right','UMINUS','~'),
427 )
428
429 def p_expression_binop(self, p):
430 """expression : expression LSHIFT expression
431 | expression RSHIFT expression
432 | expression '|' expression
433 | expression '&' expression
434 | expression '^' expression
435 | expression '+' expression
436 | expression '-' expression
437 | expression '*' expression
438 | expression '/' expression"""
439 p[0] = "%s %s %s" % (str(p[1]), str(p[2]), str(p[3]))
440 if self.parse_debug: DumpReduction('expression_binop', p)
441
442 def p_expression_unop(self, p):
443 """expression : '-' expression %prec UMINUS
444 | '~' expression %prec '~'"""
445 p[0] = "%s%s" % (str(p[1]), str(p[2]))
446 if self.parse_debug: DumpReduction('expression_unop', p)
447
448 def p_expression_term(self, p):
449 "expression : '(' expression ')'"
450 p[0] = "%s%s%s" % (str(p[1]), str(p[2]), str(p[3]))
451 if self.parse_debug: DumpReduction('expression_term', p)
452
453 def p_expression_symbol(self, p):
454 "expression : SYMBOL"
422 p[0] = p[1] 455 p[0] = p[1]
423 if self.parse_debug: DumpReduction('number', p) 456 if self.parse_debug: DumpReduction('expression_symbol', p)
424 457
425 def p_number_lshift(self, p): 458 def p_expression_integer(self, p):
426 """number : integer LSHIFT INT""" 459 "expression : integer"
427 p[0] = "%s << %s" % (p[1], p[3]) 460 p[0] = p[1]
428 if self.parse_debug: DumpReduction('number_lshift', p) 461 if self.parse_debug: DumpReduction('expression_integer', p)
429 462
430 # 463 #
431 # Array List 464 # Array List
432 # 465 #
433 # Defined a list of array sizes (if any). 466 # Defined a list of array sizes (if any).
434 # 467 #
435 def p_arrays(self, p): 468 def p_arrays(self, p):
436 """arrays : '[' ']' arrays 469 """arrays : '[' ']' arrays
437 | '[' integer ']' arrays 470 | '[' integer ']' arrays
438 | """ 471 | """
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 # 549 #
517 # An enumeration is a set of named integer constants. An enumeration 550 # An enumeration is a set of named integer constants. An enumeration
518 # is valid type which can be referenced in other definitions. 551 # is valid type which can be referenced in other definitions.
519 # 552 #
520 def p_enum_block(self, p): 553 def p_enum_block(self, p):
521 """enum_block : modifiers ENUM SYMBOL '{' enum_list '}' ';'""" 554 """enum_block : modifiers ENUM SYMBOL '{' enum_list '}' ';'"""
522 p[0] = self.BuildNamed('Enum', p, 3, ListFromConcat(p[1], p[5])) 555 p[0] = self.BuildNamed('Enum', p, 3, ListFromConcat(p[1], p[5]))
523 if self.parse_debug: DumpReduction('enum_block', p) 556 if self.parse_debug: DumpReduction('enum_block', p)
524 557
525 def p_enum_list(self, p): 558 def p_enum_list(self, p):
526 """enum_list : modifiers SYMBOL '=' number enum_cont 559 """enum_list : modifiers SYMBOL '=' expression enum_cont
527 | modifiers SYMBOL enum_cont""" 560 | modifiers SYMBOL enum_cont"""
528 if len(p) > 4: 561 if len(p) > 4:
529 val = self.BuildAttribute('VALUE', p[4]) 562 val = self.BuildAttribute('VALUE', p[4])
530 enum = self.BuildNamed('EnumItem', p, 2, ListFromConcat(val, p[1])) 563 enum = self.BuildNamed('EnumItem', p, 2, ListFromConcat(val, p[1]))
531 p[0] = ListFromConcat(enum, p[5]) 564 p[0] = ListFromConcat(enum, p[5])
532 else: 565 else:
533 enum = self.BuildNamed('EnumItem', p, 2, p[1]) 566 enum = self.BuildNamed('EnumItem', p, 2, p[1])
534 p[0] = ListFromConcat(enum, p[3]) 567 p[0] = ListFromConcat(enum, p[3])
535 if self.parse_debug: DumpReduction('enum_list', p) 568 if self.parse_debug: DumpReduction('enum_list', p)
536 569
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 ast = ParseFiles(filenames) 1042 ast = ParseFiles(filenames)
1010 errs = ast.GetProperty('ERRORS') 1043 errs = ast.GetProperty('ERRORS')
1011 if errs: 1044 if errs:
1012 ErrOut.Log('Found %d error(s).' % errs); 1045 ErrOut.Log('Found %d error(s).' % errs);
1013 InfoOut.Log("%d files processed." % len(filenames)) 1046 InfoOut.Log("%d files processed." % len(filenames))
1014 return errs 1047 return errs
1015 1048
1016 if __name__ == '__main__': 1049 if __name__ == '__main__':
1017 sys.exit(Main(sys.argv[1:])) 1050 sys.exit(Main(sys.argv[1:]))
1018 1051
OLDNEW
« no previous file with comments | « ppapi/generators/idl_lexer.py ('k') | ppapi/generators/test_cgen/enum_typedef.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698