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

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

Issue 9359040: WIP IDL-IPC2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Checkpoint before going back to returning ListValue via ExtensionMsg_Response. Created 8 years, 9 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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ Parser for PPAPI IDL """ 6 """ Parser for PPAPI IDL """
7 7
8 # 8 #
9 # IDL Parser 9 # IDL Parser
10 # 10 #
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 # 206 #
207 # We force all input files to start with two comments. The first comment is a 207 # We force all input files to start with two comments. The first comment is a
208 # Copyright notice followed by a set of file wide Extended Attributes, followed 208 # Copyright notice followed by a set of file wide Extended Attributes, followed
209 # by the file comment and finally by file level patterns. 209 # by the file comment and finally by file level patterns.
210 # 210 #
211 # Find the Copyright, File comment, and optional file wide attributes. We 211 # Find the Copyright, File comment, and optional file wide attributes. We
212 # use a match with COMMENT instead of comments to force the token to be 212 # use a match with COMMENT instead of comments to force the token to be
213 # present. The extended attributes and the top_list become siblings which 213 # present. The extended attributes and the top_list become siblings which
214 # in turn are children of the file object created from the results of top. 214 # in turn are children of the file object created from the results of top.
215 def p_top(self, p): 215 def p_top(self, p):
216 """top : COMMENT COMMENT ext_attr_block top_list""" 216 """top : COMMENT COMMENT ext_attr_block top_list
217 | namespace"""
218 if len(p) == 2:
219 p[0] = ListFromConcat(p[1])
220 else:
221 copyright_comment = self.BuildComment('Copyright', p, 1)
222 filedoc_comment = self.BuildComment('Comment', p, 2)
223 p[0] = ListFromConcat(copyright_comment, filedoc_comment, p[3], p[4])
224 if self.parse_debug: DumpReduction('top', p)
217 225
218 Copyright = self.BuildComment('Copyright', p, 1) 226 def p_namespace(self, p):
219 Filedoc = self.BuildComment('Comment', p, 2) 227 """namespace : modifiers NAMESPACE namespace_name '{' top_list '}' ';'"""
228 children = ListFromConcat(p[1], p[5])
229 p[0] = self.BuildNamed('Namespace', p, 3, children)
220 230
221 p[0] = ListFromConcat(Copyright, Filedoc, p[3], p[4]) 231 # We allow namespace names of the form foo.bar.baz.
222 if self.parse_debug: DumpReduction('top', p) 232 def p_namespace_name(self, p):
233 """namespace_name : SYMBOL
234 | SYMBOL '.' namespace_name"""
235 p[0] = "".join(p[1:])
236
237 def p_dictionary_block(self, p):
238 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'"""
239 p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[5]))
240
241
242 def p_callback_decl(self, p):
243 """callback_decl : modifiers CALLBACK SYMBOL '=' SYMBOL param_list ';'"""
244 children = ListFromConcat(p[1], p[6])
245 p[0] = self.BuildNamed('Callback', p, 3, children)
223 246
224 # Build a list of top level items. 247 # Build a list of top level items.
225 def p_top_list(self, p): 248 def p_top_list(self, p):
226 """top_list : describe_block top_list 249 """top_list : dictionary_block top_list
250 | describe_block top_list
227 | enum_block top_list 251 | enum_block top_list
228 | inline top_list 252 | inline top_list
229 | interface_block top_list 253 | interface_block top_list
230 | label_block top_list 254 | label_block top_list
231 | struct_block top_list 255 | struct_block top_list
232 | typedef_decl top_list 256 | typedef_decl top_list
257 | callback_decl top_list
233 | """ 258 | """
234 if len(p) > 2: 259 if len(p) > 2:
235 p[0] = ListFromConcat(p[1], p[2]) 260 p[0] = ListFromConcat(p[1], p[2])
236 if self.parse_debug: DumpReduction('top_list', p) 261 if self.parse_debug: DumpReduction('top_list', p)
237 262
238 # Recover from error and continue parsing at the next top match. 263 # Recover from error and continue parsing at the next top match.
239 def p_top_error(self, p): 264 def p_top_error(self, p):
240 """top_list : error top_list""" 265 """top_list : error top_list"""
241 p[0] = p[2] 266 p[0] = p[2]
242 267
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 """param_list : '(' param_item param_cont ')' 517 """param_list : '(' param_item param_cont ')'
493 | '(' ')' """ 518 | '(' ')' """
494 if len(p) > 3: 519 if len(p) > 3:
495 args = ListFromConcat(p[2], p[3]) 520 args = ListFromConcat(p[2], p[3])
496 else: 521 else:
497 args = [] 522 args = []
498 p[0] = self.BuildProduction('Callspec', p, 1, args) 523 p[0] = self.BuildProduction('Callspec', p, 1, args)
499 if self.parse_debug: DumpReduction('param_list', p) 524 if self.parse_debug: DumpReduction('param_list', p)
500 525
501 def p_param_item(self, p): 526 def p_param_item(self, p):
502 """param_item : modifiers SYMBOL arrays SYMBOL""" 527 """param_item : modifiers optional SYMBOL arrays SYMBOL"""
503 typeref = self.BuildAttribute('TYPEREF', p[2]) 528 typeref = self.BuildAttribute('TYPEREF', p[3])
504 children = ListFromConcat(p[1],typeref, p[3]) 529 children = ListFromConcat(p[1],p[2], typeref, p[4])
505 p[0] = self.BuildNamed('Param', p, 4, children) 530 p[0] = self.BuildNamed('Param', p, 5, children)
506 if self.parse_debug: DumpReduction('param_item', p) 531 if self.parse_debug: DumpReduction('param_item', p)
507 532
533 def p_optional(self, p):
534 """optional : OPTIONAL
535 | """
536 if len(p) == 2:
537 p[0] = self.BuildAttribute('OPTIONAL', True)
538
539
508 def p_param_cont(self, p): 540 def p_param_cont(self, p):
509 """param_cont : ',' param_item param_cont 541 """param_cont : ',' param_item param_cont
510 | """ 542 | """
511 if len(p) > 1: 543 if len(p) > 1:
512 p[0] = ListFromConcat(p[2], p[3]) 544 p[0] = ListFromConcat(p[2], p[3])
513 if self.parse_debug: DumpReduction('param_cont', p) 545 if self.parse_debug: DumpReduction('param_cont', p)
514 546
515 def p_param_error(self, p): 547 def p_param_error(self, p):
516 """param_cont : error param_cont""" 548 """param_cont : error param_cont"""
517 p[0] = p[2] 549 p[0] = p[2]
518 550
519 551
520 # 552 #
521 # Typedef 553 # Typedef
522 # 554 #
523 # A typedef creates a new referencable type. The tyepdef can specify an array 555 # A typedef creates a new referencable type. The typedef can specify an array
524 # definition as well as a function declaration. 556 # definition as well as a function declaration.
525 # 557 #
526 def p_typedef_data(self, p): 558 def p_typedef_data(self, p):
527 """typedef_decl : modifiers TYPEDEF SYMBOL SYMBOL ';' """ 559 """typedef_decl : modifiers TYPEDEF SYMBOL SYMBOL ';' """
528 typeref = self.BuildAttribute('TYPEREF', p[3]) 560 typeref = self.BuildAttribute('TYPEREF', p[3])
529 children = ListFromConcat(p[1], typeref) 561 children = ListFromConcat(p[1], typeref)
530 p[0] = self.BuildNamed('Typedef', p, 4, children) 562 p[0] = self.BuildNamed('Typedef', p, 4, children)
531 if self.parse_debug: DumpReduction('typedef_data', p) 563 if self.parse_debug: DumpReduction('typedef_data', p)
532 564
533 def p_typedef_array(self, p): 565 def p_typedef_array(self, p):
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 p[0] = p[2] 640 p[0] = p[2]
609 if self.parse_debug: DumpReduction('label_error', p) 641 if self.parse_debug: DumpReduction('label_error', p)
610 642
611 643
612 # 644 #
613 # Members 645 # Members
614 # 646 #
615 # A member attribute or function of a struct or interface. 647 # A member attribute or function of a struct or interface.
616 # 648 #
617 def p_member_attribute(self, p): 649 def p_member_attribute(self, p):
618 """member_attribute : modifiers SYMBOL SYMBOL """ 650 """member_attribute : modifiers SYMBOL arrays questionmark SYMBOL"""
619 typeref = self.BuildAttribute('TYPEREF', p[2]) 651 typeref = self.BuildAttribute('TYPEREF', p[2])
620 children = ListFromConcat(p[1], typeref) 652 children = ListFromConcat(p[1], typeref, p[3], p[4])
621 p[0] = self.BuildNamed('Member', p, 3, children) 653 p[0] = self.BuildNamed('Member', p, 5, children)
622 if self.parse_debug: DumpReduction('attribute', p)
623
624 def p_member_attribute_array(self, p):
625 """member_attribute : modifiers SYMBOL arrays SYMBOL """
626 typeref = self.BuildAttribute('TYPEREF', p[2])
627 children = ListFromConcat(p[1], typeref, p[3])
628 p[0] = self.BuildNamed('Member', p, 4, children)
629 if self.parse_debug: DumpReduction('attribute', p) 654 if self.parse_debug: DumpReduction('attribute', p)
630 655
631 def p_member_function(self, p): 656 def p_member_function(self, p):
632 """member_function : modifiers SYMBOL SYMBOL param_list""" 657 """member_function : modifiers static SYMBOL SYMBOL param_list"""
633 typeref = self.BuildAttribute('TYPEREF', p[2]) 658 typeref = self.BuildAttribute('TYPEREF', p[3])
634 children = ListFromConcat(p[1], typeref, p[4]) 659 children = ListFromConcat(p[1], p[2], typeref, p[5])
635 p[0] = self.BuildNamed('Member', p, 3, children) 660 p[0] = self.BuildNamed('Member', p, 4, children)
636 if self.parse_debug: DumpReduction('function', p) 661 if self.parse_debug: DumpReduction('function', p)
637 662
663 def p_static(self, p):
664 """static : STATIC
665 | """
666 if len(p) == 2:
667 p[0] = self.BuildAttribute('STATIC', True)
668
669 def p_questionmark(self, p):
670 """questionmark : '?'
671 | """
672 if len(p) == 2:
673 p[0] = self.BuildAttribute('OPTIONAL', True)
674
638 # 675 #
639 # Interface 676 # Interface
640 # 677 #
641 # An interface is a named collection of functions. 678 # An interface is a named collection of functions.
642 # 679 #
643 def p_interface_block(self, p): 680 def p_interface_block(self, p):
644 """interface_block : modifiers INTERFACE SYMBOL '{' interface_list '}' ';'"" " 681 """interface_block : modifiers INTERFACE SYMBOL '{' interface_list '}' ';'"" "
645 p[0] = self.BuildNamed('Interface', p, 3, ListFromConcat(p[1], p[5])) 682 p[0] = self.BuildNamed('Interface', p, 3, ListFromConcat(p[1], p[5]))
646 if self.parse_debug: DumpReduction('interface_block', p) 683 if self.parse_debug: DumpReduction('interface_block', p)
647 684
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 ast = ParseFiles(filenames) 1085 ast = ParseFiles(filenames)
1049 errs = ast.GetProperty('ERRORS') 1086 errs = ast.GetProperty('ERRORS')
1050 if errs: 1087 if errs:
1051 ErrOut.Log('Found %d error(s).' % errs); 1088 ErrOut.Log('Found %d error(s).' % errs);
1052 InfoOut.Log("%d files processed." % len(filenames)) 1089 InfoOut.Log("%d files processed." % len(filenames))
1053 return errs 1090 return errs
1054 1091
1055 1092
1056 if __name__ == '__main__': 1093 if __name__ == '__main__':
1057 sys.exit(Main(sys.argv[1:])) 1094 sys.exit(Main(sys.argv[1:]))
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