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

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
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','LSHIFT','RSHIFT'),
423 ('left','+','-'),
424 ('left','*','/'),
425 ('right','UMINUS','~'),
426 )
noelallen1 2011/10/06 20:51:44 prec for |, &, ^?
bbudge 2011/10/07 00:04:52 Done.
427
428 def p_expression_binop(self, p):
429 """expression : expression LSHIFT expression
430 | expression RSHIFT expression
431 | expression '|' expression
432 | expression '&' expression
433 | expression '^' expression
434 | expression '+' expression
435 | expression '-' expression
436 | expression '*' expression
437 | expression '/' expression"""
438 p[0] = "%s %s %s" % (str(p[1]), str(p[2]), str(p[3]))
439 if self.parse_debug: DumpReduction('expression_binop', p)
440
441 def p_expression_unop(self, p):
442 """expression : '-' expression %prec UMINUS
443 | '~' expression %prec '~'"""
444 p[0] = "%s %s" % (str(p[1]), str(p[2]))
noelallen1 2011/10/06 20:51:44 Shouldn't unary ops be %s%s such as '-' + '5' ins
bbudge 2011/10/07 00:04:52 Done.
445 if self.parse_debug: DumpReduction('expression_unop', p)
446
447 def p_expression_term(self, p):
448 "expression : '(' expression ')'"
449 p[0] = "%s%s%s" % (str(p[1]), str(p[2]), str(p[3]))
450 if self.parse_debug: DumpReduction('expression_term', p)
451
452 def p_expression_symbol(self, p):
453 "expression : SYMBOL"
422 p[0] = p[1] 454 p[0] = p[1]
423 if self.parse_debug: DumpReduction('number', p) 455 if self.parse_debug: DumpReduction('expression_symbol', p)
424 456
425 def p_number_lshift(self, p): 457 def p_expression_integer(self, p):
426 """number : integer LSHIFT INT""" 458 "expression : integer"
427 p[0] = "%s << %s" % (p[1], p[3]) 459 p[0] = p[1]
428 if self.parse_debug: DumpReduction('number_lshift', p) 460 if self.parse_debug: DumpReduction('expression_integer', p)
429 461
430 # 462 #
431 # Array List 463 # Array List
432 # 464 #
433 # Defined a list of array sizes (if any). 465 # Defined a list of array sizes (if any).
434 # 466 #
435 def p_arrays(self, p): 467 def p_arrays(self, p):
436 """arrays : '[' ']' arrays 468 """arrays : '[' ']' arrays
437 | '[' integer ']' arrays 469 | '[' integer ']' arrays
438 | """ 470 | """
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 # 548 #
517 # An enumeration is a set of named integer constants. An enumeration 549 # An enumeration is a set of named integer constants. An enumeration
518 # is valid type which can be referenced in other definitions. 550 # is valid type which can be referenced in other definitions.
519 # 551 #
520 def p_enum_block(self, p): 552 def p_enum_block(self, p):
521 """enum_block : modifiers ENUM SYMBOL '{' enum_list '}' ';'""" 553 """enum_block : modifiers ENUM SYMBOL '{' enum_list '}' ';'"""
522 p[0] = self.BuildNamed('Enum', p, 3, ListFromConcat(p[1], p[5])) 554 p[0] = self.BuildNamed('Enum', p, 3, ListFromConcat(p[1], p[5]))
523 if self.parse_debug: DumpReduction('enum_block', p) 555 if self.parse_debug: DumpReduction('enum_block', p)
524 556
525 def p_enum_list(self, p): 557 def p_enum_list(self, p):
526 """enum_list : modifiers SYMBOL '=' number enum_cont 558 """enum_list : modifiers SYMBOL '=' expression enum_cont
527 | modifiers SYMBOL enum_cont""" 559 | modifiers SYMBOL enum_cont"""
528 if len(p) > 4: 560 if len(p) > 4:
529 val = self.BuildAttribute('VALUE', p[4]) 561 val = self.BuildAttribute('VALUE', p[4])
530 enum = self.BuildNamed('EnumItem', p, 2, ListFromConcat(val, p[1])) 562 enum = self.BuildNamed('EnumItem', p, 2, ListFromConcat(val, p[1]))
531 p[0] = ListFromConcat(enum, p[5]) 563 p[0] = ListFromConcat(enum, p[5])
532 else: 564 else:
533 enum = self.BuildNamed('EnumItem', p, 2, p[1]) 565 enum = self.BuildNamed('EnumItem', p, 2, p[1])
534 p[0] = ListFromConcat(enum, p[3]) 566 p[0] = ListFromConcat(enum, p[3])
535 if self.parse_debug: DumpReduction('enum_list', p) 567 if self.parse_debug: DumpReduction('enum_list', p)
536 568
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 ast = ParseFiles(filenames) 1041 ast = ParseFiles(filenames)
1010 errs = ast.GetProperty('ERRORS') 1042 errs = ast.GetProperty('ERRORS')
1011 if errs: 1043 if errs:
1012 ErrOut.Log('Found %d error(s).' % errs); 1044 ErrOut.Log('Found %d error(s).' % errs);
1013 InfoOut.Log("%d files processed." % len(filenames)) 1045 InfoOut.Log("%d files processed." % len(filenames))
1014 return errs 1046 return errs
1015 1047
1016 if __name__ == '__main__': 1048 if __name__ == '__main__':
1017 sys.exit(Main(sys.argv[1:])) 1049 sys.exit(Main(sys.argv[1:]))
1018 1050
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698