| OLD | NEW | 
|    1 # Copyright (C) 2013 Google Inc. All rights reserved. |    1 # Copyright (C) 2013 Google Inc. All rights reserved. | 
|    2 # |    2 # | 
|    3 # Redistribution and use in source and binary forms, with or without |    3 # Redistribution and use in source and binary forms, with or without | 
|    4 # modification, are permitted provided that the following conditions are |    4 # modification, are permitted provided that the following conditions are | 
|    5 # met: |    5 # met: | 
|    6 # |    6 # | 
|    7 #     * Redistributions of source code must retain the above copyright |    7 #     * Redistributions of source code must retain the above copyright | 
|    8 # notice, this list of conditions and the following disclaimer. |    8 # notice, this list of conditions and the following disclaimer. | 
|    9 #     * Redistributions in binary form must reproduce the above |    9 #     * Redistributions in binary form must reproduce the above | 
|   10 # copyright notice, this list of conditions and the following disclaimer |   10 # copyright notice, this list of conditions and the following disclaimer | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   50         IdlConstant < TypedObject |   50         IdlConstant < TypedObject | 
|   51         IdlLiteral |   51         IdlLiteral | 
|   52         IdlOperation < TypedObject |   52         IdlOperation < TypedObject | 
|   53             IdlArgument < TypedObject |   53             IdlArgument < TypedObject | 
|   54         IdlStringifier |   54         IdlStringifier | 
|   55     IdlException < IdlInterface |   55     IdlException < IdlInterface | 
|   56         (same contents as IdlInterface) |   56         (same contents as IdlInterface) | 
|   57  |   57  | 
|   58 TypedObject :: mixin for typedef resolution |   58 TypedObject :: mixin for typedef resolution | 
|   59  |   59  | 
 |   60 IdlArgument is 'picklable', as it is stored in interfaces_info. | 
 |   61  | 
|   60 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |   62 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 
|   61 """ |   63 """ | 
|   62  |   64  | 
|   63 import abc |   65 import abc | 
|   64  |   66  | 
|   65 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType, IdlN
     ullableType |   67 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType, IdlN
     ullableType | 
|   66  |   68  | 
|   67 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER'] |   69 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER'] | 
|   68 STANDARD_TYPEDEFS = { |   70 STANDARD_TYPEDEFS = { | 
|   69     # http://www.w3.org/TR/WebIDL/#common-DOMTimeStamp |   71     # http://www.w3.org/TR/WebIDL/#common-DOMTimeStamp | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
|   98 ################################################################################ |  100 ################################################################################ | 
|   99 # Definitions (main container class) |  101 # Definitions (main container class) | 
|  100 ################################################################################ |  102 ################################################################################ | 
|  101  |  103  | 
|  102 class IdlDefinitions(object): |  104 class IdlDefinitions(object): | 
|  103     def __init__(self, idl_name, node): |  105     def __init__(self, idl_name, node): | 
|  104         """Args: node: AST root node, class == 'File'""" |  106         """Args: node: AST root node, class == 'File'""" | 
|  105         self.callback_functions = {} |  107         self.callback_functions = {} | 
|  106         self.dictionaries = {} |  108         self.dictionaries = {} | 
|  107         self.enumerations = {} |  109         self.enumerations = {} | 
 |  110         self.implements = [] | 
|  108         self.interfaces = {} |  111         self.interfaces = {} | 
|  109         self.idl_name = idl_name |  112         self.idl_name = idl_name | 
|  110  |  113  | 
|  111         node_class = node.GetClass() |  114         node_class = node.GetClass() | 
|  112         if node_class != 'File': |  115         if node_class != 'File': | 
|  113             raise ValueError('Unrecognized node class: %s' % node_class) |  116             raise ValueError('Unrecognized node class: %s' % node_class) | 
|  114  |  117  | 
|  115         typedefs = dict((typedef_name, IdlType(type_name)) |  118         typedefs = dict((typedef_name, IdlType(type_name)) | 
|  116                         for typedef_name, type_name in |  119                         for typedef_name, type_name in | 
|  117                         STANDARD_TYPEDEFS.iteritems()) |  120                         STANDARD_TYPEDEFS.iteritems()) | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  129             elif child_class == 'Typedef': |  132             elif child_class == 'Typedef': | 
|  130                 type_name = child.GetName() |  133                 type_name = child.GetName() | 
|  131                 typedefs[type_name] = typedef_node_to_type(child) |  134                 typedefs[type_name] = typedef_node_to_type(child) | 
|  132             elif child_class == 'Enum': |  135             elif child_class == 'Enum': | 
|  133                 enumeration = IdlEnum(idl_name, child) |  136                 enumeration = IdlEnum(idl_name, child) | 
|  134                 self.enumerations[enumeration.name] = enumeration |  137                 self.enumerations[enumeration.name] = enumeration | 
|  135             elif child_class == 'Callback': |  138             elif child_class == 'Callback': | 
|  136                 callback_function = IdlCallbackFunction(idl_name, child) |  139                 callback_function = IdlCallbackFunction(idl_name, child) | 
|  137                 self.callback_functions[callback_function.name] = callback_funct
     ion |  140                 self.callback_functions[callback_function.name] = callback_funct
     ion | 
|  138             elif child_class == 'Implements': |  141             elif child_class == 'Implements': | 
|  139                 # Implements is handled at the interface merging step |  142                 self.implements.append(IdlImplement(child)) | 
|  140                 pass |  | 
|  141             elif child_class == 'Dictionary': |  143             elif child_class == 'Dictionary': | 
|  142                 dictionary = IdlDictionary(idl_name, child) |  144                 dictionary = IdlDictionary(idl_name, child) | 
|  143                 self.dictionaries[dictionary.name] = dictionary |  145                 self.dictionaries[dictionary.name] = dictionary | 
|  144             else: |  146             else: | 
|  145                 raise ValueError('Unrecognized node class: %s' % child_class) |  147                 raise ValueError('Unrecognized node class: %s' % child_class) | 
|  146  |  148  | 
|  147         # Typedefs are not stored in IR: |  149         # Typedefs are not stored in IR: | 
|  148         # Resolve typedefs with the actual types and then discard the Typedefs. |  150         # Resolve typedefs with the actual types and then discard the Typedefs. | 
|  149         # http://www.w3.org/TR/WebIDL/#idl-typedefs |  151         # http://www.w3.org/TR/WebIDL/#idl-typedefs | 
|  150         self.resolve_typedefs(typedefs) |  152         self.resolve_typedefs(typedefs) | 
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  583             elif child_class == 'Argument': |  585             elif child_class == 'Argument': | 
|  584                 child_name = child.GetName() |  586                 child_name = child.GetName() | 
|  585                 if child_name != '...': |  587                 if child_name != '...': | 
|  586                     raise ValueError('Unrecognized Argument node; expected "..."
     , got "%s"' % child_name) |  588                     raise ValueError('Unrecognized Argument node; expected "..."
     , got "%s"' % child_name) | 
|  587                 self.is_variadic = child.GetProperty('ELLIPSIS') or False |  589                 self.is_variadic = child.GetProperty('ELLIPSIS') or False | 
|  588             elif child_class == 'Default': |  590             elif child_class == 'Default': | 
|  589                 self.default_value = default_node_to_idl_literal(child) |  591                 self.default_value = default_node_to_idl_literal(child) | 
|  590             else: |  592             else: | 
|  591                 raise ValueError('Unrecognized node class: %s' % child_class) |  593                 raise ValueError('Unrecognized node class: %s' % child_class) | 
|  592  |  594  | 
 |  595     def __getstate__(self): | 
 |  596         # FIXME: Return a picklable object which has enough information to | 
 |  597         # unpickle. | 
 |  598         return {} | 
 |  599  | 
 |  600     def __setstate__(self, state): | 
 |  601         pass | 
 |  602  | 
|  593  |  603  | 
|  594 def arguments_node_to_arguments(idl_name, node): |  604 def arguments_node_to_arguments(idl_name, node): | 
|  595     # [Constructor] and [CustomConstructor] without arguments (the bare form) |  605     # [Constructor] and [CustomConstructor] without arguments (the bare form) | 
|  596     # have None instead of an arguments node, but have the same meaning as using |  606     # have None instead of an arguments node, but have the same meaning as using | 
|  597     # an empty argument list, [Constructor()], so special-case this. |  607     # an empty argument list, [Constructor()], so special-case this. | 
|  598     # http://www.w3.org/TR/WebIDL/#Constructor |  608     # http://www.w3.org/TR/WebIDL/#Constructor | 
|  599     if node is None: |  609     if node is None: | 
|  600         return [] |  610         return [] | 
|  601     return [IdlArgument(idl_name, argument_node) |  611     return [IdlArgument(idl_name, argument_node) | 
|  602             for argument_node in node.GetChildren()] |  612             for argument_node in node.GetChildren()] | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  627                 raise ValueError('Unrecognized node class: %s' % child_class) |  637                 raise ValueError('Unrecognized node class: %s' % child_class) | 
|  628  |  638  | 
|  629         # Copy the stringifier's extended attributes (such as [Unforgable]) onto |  639         # Copy the stringifier's extended attributes (such as [Unforgable]) onto | 
|  630         # the underlying attribute or operation, if there is one. |  640         # the underlying attribute or operation, if there is one. | 
|  631         if self.attribute or self.operation: |  641         if self.attribute or self.operation: | 
|  632             (self.attribute or self.operation).extended_attributes.update( |  642             (self.attribute or self.operation).extended_attributes.update( | 
|  633                 self.extended_attributes) |  643                 self.extended_attributes) | 
|  634  |  644  | 
|  635  |  645  | 
|  636 ################################################################################ |  646 ################################################################################ | 
 |  647 # Implement statements | 
 |  648 ################################################################################ | 
 |  649  | 
 |  650 class IdlImplement(object): | 
 |  651     def __init__(self, node): | 
 |  652         self.left_interface = node.GetName() | 
 |  653         self.right_interface = node.GetProperty('REFERENCE') | 
 |  654  | 
 |  655  | 
 |  656 ################################################################################ | 
|  637 # Extended attributes |  657 # Extended attributes | 
|  638 ################################################################################ |  658 ################################################################################ | 
|  639  |  659  | 
|  640 def ext_attributes_node_to_extended_attributes(idl_name, node): |  660 def ext_attributes_node_to_extended_attributes(idl_name, node): | 
|  641     """ |  661     """ | 
|  642     Returns: |  662     Returns: | 
|  643       Dictionary of {ExtAttributeName: ExtAttributeValue}. |  663       Dictionary of {ExtAttributeName: ExtAttributeValue}. | 
|  644       Value is usually a string, with these exceptions: |  664       Value is usually a string, with these exceptions: | 
|  645       Constructors: value is a list of Arguments nodes, corresponding to |  665       Constructors: value is a list of Arguments nodes, corresponding to | 
|  646         possible signatures of the constructor. |  666         possible signatures of the constructor. | 
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  821     child_class = child.GetClass() |  841     child_class = child.GetClass() | 
|  822     if child_class != 'Type': |  842     if child_class != 'Type': | 
|  823         raise ValueError('Unrecognized node class: %s' % child_class) |  843         raise ValueError('Unrecognized node class: %s' % child_class) | 
|  824     return type_node_to_type(child) |  844     return type_node_to_type(child) | 
|  825  |  845  | 
|  826  |  846  | 
|  827 def union_type_node_to_idl_union_type(node): |  847 def union_type_node_to_idl_union_type(node): | 
|  828     member_types = [type_node_to_type(member_type_node) |  848     member_types = [type_node_to_type(member_type_node) | 
|  829                     for member_type_node in node.GetChildren()] |  849                     for member_type_node in node.GetChildren()] | 
|  830     return IdlUnionType(member_types) |  850     return IdlUnionType(member_types) | 
| OLD | NEW |