| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 def p_StructMembers(self, p): | 117 def p_StructMembers(self, p): |
| 118 """StructMembers : StructMember StructMembers | 118 """StructMembers : StructMember StructMembers |
| 119 |""" | 119 |""" |
| 120 if len(p) > 1: | 120 if len(p) > 1: |
| 121 p[0] = ListFromConcat(p[1], p[2]) | 121 p[0] = ListFromConcat(p[1], p[2]) |
| 122 | 122 |
| 123 def p_StructMember(self, p): | 123 def p_StructMember(self, p): |
| 124 """StructMember : ExtendedAttributeList Type identifier ';'""" | 124 """StructMember : ExtendedAttributeList Type identifier ';'""" |
| 125 p[0] = self.BuildNamed('Member', p, 3, ListFromConcat(p[1], p[2])) | 125 p[0] = self.BuildNamed('Member', p, 3, ListFromConcat(p[1], p[2])) |
| 126 | 126 |
| 127 # [24] | |
| 128 def p_Typedef(self, p): | 127 def p_Typedef(self, p): |
| 129 """Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'""" | 128 """Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'""" |
| 130 p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3])) | 129 p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3])) |
| 131 | 130 |
| 132 # [24.1] | |
| 133 def p_TypedefFunc(self, p): | 131 def p_TypedefFunc(self, p): |
| 134 """Typedef : TYPEDEF ExtendedAttributeListNoComments ReturnType identifier '
(' ArgumentList ')' ';'""" | 132 """Typedef : TYPEDEF ExtendedAttributeListNoComments ReturnType identifier '
(' ArgumentList ')' ';'""" |
| 135 args = self.BuildProduction('Arguments', p, 5, p[6]) | 133 args = self.BuildProduction('Arguments', p, 5, p[6]) |
| 136 p[0] = self.BuildNamed('Callback', p, 4, ListFromConcat(p[2], p[3], args)) | 134 p[0] = self.BuildNamed('Callback', p, 4, ListFromConcat(p[2], p[3], args)) |
| 137 | 135 |
| 138 # [27] | |
| 139 def p_ConstValue(self, p): | 136 def p_ConstValue(self, p): |
| 140 """ConstValue : integer | 137 """ConstValue : integer |
| 141 | integer LSHIFT integer | 138 | integer LSHIFT integer |
| 142 | integer RSHIFT integer""" | 139 | integer RSHIFT integer""" |
| 143 val = str(p[1]) | 140 val = str(p[1]) |
| 144 if len(p) > 2: | 141 if len(p) > 2: |
| 145 val = "%s %s %s" % (p[1], p[2], p[3]) | 142 val = "%s %s %s" % (p[1], p[2], p[3]) |
| 146 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'integer'), | 143 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'integer'), |
| 147 self.BuildAttribute('VALUE', val)) | 144 self.BuildAttribute('VALUE', val)) |
| 148 | 145 |
| 149 def p_ConstValueStr(self, p): | 146 def p_ConstValueStr(self, p): |
| 150 """ConstValue : string""" | 147 """ConstValue : string""" |
| 151 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'string'), | 148 p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'string'), |
| 152 self.BuildAttribute('VALUE', p[1])) | 149 self.BuildAttribute('VALUE', p[1])) |
| 153 | 150 |
| 154 # Boolean & Float Literals area already BuildAttributes | 151 # Boolean & Float Literals area already BuildAttributes |
| 155 def p_ConstValueLiteral(self, p): | 152 def p_ConstValueLiteral(self, p): |
| 156 """ConstValue : FloatLiteral | 153 """ConstValue : FloatLiteral |
| 157 | BooleanLiteral """ | 154 | BooleanLiteral """ |
| 158 p[0] = p[1] | 155 p[0] = p[1] |
| 159 | 156 |
| 160 # [21] | |
| 161 def p_EnumValueList(self, p): | 157 def p_EnumValueList(self, p): |
| 162 """EnumValueList : EnumValue EnumValues""" | 158 """EnumValueList : EnumValue EnumValues""" |
| 163 p[0] = ListFromConcat(p[1], p[2]) | 159 p[0] = ListFromConcat(p[1], p[2]) |
| 164 | 160 |
| 165 # [22] | |
| 166 def p_EnumValues(self, p): | 161 def p_EnumValues(self, p): |
| 167 """EnumValues : ',' EnumValue EnumValues | 162 """EnumValues : ',' EnumValue EnumValues |
| 168 |""" | 163 |""" |
| 169 if len(p) > 1: | 164 if len(p) > 1: |
| 170 p[0] = ListFromConcat(p[2], p[3]) | 165 p[0] = ListFromConcat(p[2], p[3]) |
| 171 | 166 |
| 172 def p_EnumValue(self, p): | 167 def p_EnumValue(self, p): |
| 173 """EnumValue : ExtendedAttributeList identifier | 168 """EnumValue : ExtendedAttributeList identifier |
| 174 | ExtendedAttributeList identifier '=' ConstValue""" | 169 | ExtendedAttributeList identifier '=' ConstValue""" |
| 175 p[0] = self.BuildNamed('EnumItem', p, 2, p[1]) | 170 p[0] = self.BuildNamed('EnumItem', p, 2, p[1]) |
| 176 if len(p) > 3: | 171 if len(p) > 3: |
| 177 p[0].AddChildren(p[4]) | 172 p[0].AddChildren(p[4]) |
| 178 | 173 |
| 174 # Omit PromiseType, as it is a JS type. |
| 175 def p_NonAnyType(self, p): |
| 176 """NonAnyType : PrimitiveType TypeSuffix |
| 177 | identifier TypeSuffix |
| 178 | SEQUENCE '<' Type '>' Null""" |
| 179 IDLParser.p_NonAnyType(self, p) |
| 180 |
| 179 def p_PrimitiveType(self, p): | 181 def p_PrimitiveType(self, p): |
| 180 """PrimitiveType : IntegerType | 182 """PrimitiveType : IntegerType |
| 181 | UnsignedIntegerType | 183 | UnsignedIntegerType |
| 182 | FloatType | 184 | FloatType |
| 183 | HandleType | 185 | HandleType |
| 184 | PointerType""" | 186 | PointerType""" |
| 185 if type(p[1]) == str: | 187 if type(p[1]) == str: |
| 186 p[0] = self.BuildNamed('PrimitiveType', p, 1) | 188 p[0] = self.BuildNamed('PrimitiveType', p, 1) |
| 187 else: | 189 else: |
| 188 p[0] = p[1] | 190 p[0] = p[1] |
| 189 | 191 |
| 190 def p_PointerType(self, p): | 192 def p_PointerType(self, p): |
| 191 """PointerType : STR_T | 193 """PointerType : STR_T |
| 192 | MEM_T | 194 | MEM_T |
| 193 | CSTR_T | 195 | CSTR_T |
| 194 | INTERFACE_T | 196 | INTERFACE_T |
| 195 | NULL""" | 197 | NULL""" |
| 196 p[0] = p[1] | 198 p[0] = p[1] |
| 197 | 199 |
| 198 def p_HandleType(self, p): | 200 def p_HandleType(self, p): |
| 199 """HandleType : HANDLE_T | 201 """HandleType : HANDLE_T |
| 200 | PP_FILEHANDLE""" | 202 | PP_FILEHANDLE""" |
| 201 p[0] = p[1] | 203 p[0] = p[1] |
| 202 | 204 |
| 203 # [66] | |
| 204 def p_FloatType(self, p): | 205 def p_FloatType(self, p): |
| 205 """FloatType : FLOAT_T | 206 """FloatType : FLOAT_T |
| 206 | DOUBLE_T""" | 207 | DOUBLE_T""" |
| 207 p[0] = p[1] | 208 p[0] = p[1] |
| 208 | 209 |
| 209 # [67] | |
| 210 def p_UnsignedIntegerType(self, p): | 210 def p_UnsignedIntegerType(self, p): |
| 211 """UnsignedIntegerType : UINT8_T | 211 """UnsignedIntegerType : UINT8_T |
| 212 | UINT16_T | 212 | UINT16_T |
| 213 | UINT32_T | 213 | UINT32_T |
| 214 | UINT64_T""" | 214 | UINT64_T""" |
| 215 p[0] = p[1] | 215 p[0] = p[1] |
| 216 | 216 |
| 217 | 217 |
| 218 # [68] | |
| 219 def p_IntegerType(self, p): | 218 def p_IntegerType(self, p): |
| 220 """IntegerType : CHAR | 219 """IntegerType : CHAR |
| 221 | INT8_T | 220 | INT8_T |
| 222 | INT16_T | 221 | INT16_T |
| 223 | INT32_T | 222 | INT32_T |
| 224 | INT64_T""" | 223 | INT64_T""" |
| 225 p[0] = p[1] | 224 p[0] = p[1] |
| 226 | 225 |
| 227 # These targets are no longer used | 226 # These targets are no longer used |
| 228 def p_OptionalLong(self, p): | 227 def p_OptionalLong(self, p): |
| 229 """ """ | 228 """ """ |
| 230 pass | 229 pass |
| 231 | 230 |
| 232 def p_UnrestrictedFloatType(self, p): | 231 def p_UnrestrictedFloatType(self, p): |
| 233 """ """ | 232 """ """ |
| 234 pass | 233 pass |
| 235 | 234 |
| 236 def p_null(self, p): | 235 def p_null(self, p): |
| 237 """ """ | 236 """ """ |
| 238 pass | 237 pass |
| 239 | 238 |
| 239 def p_PromiseType(self, p): |
| 240 """ """ |
| 241 pass |
| 242 |
| 240 # We only support: | 243 # We only support: |
| 241 # [ identifier ] | 244 # [ identifier ] |
| 242 # [ identifier ( ArgumentList )] | 245 # [ identifier ( ArgumentList )] |
| 243 # [ identifier ( ValueList )] | 246 # [ identifier ( ValueList )] |
| 244 # [ identifier = identifier ] | 247 # [ identifier = identifier ] |
| 245 # [ identifier = ( IdentifierList )] | 248 # [ identifier = ( IdentifierList )] |
| 246 # [ identifier = ConstValue ] | 249 # [ identifier = ConstValue ] |
| 247 # [ identifier = identifier ( ArgumentList )] | 250 # [ identifier = identifier ( ArgumentList )] |
| 248 # [51] map directly to 74-77 | 251 # [51] map directly to 74-77 |
| 249 # [52-54, 56] are unsupported | 252 # [52-54, 56] are unsupported |
| (...skipping 15 matching lines...) Expand all Loading... |
| 265 def p_ValueList(self, p): | 268 def p_ValueList(self, p): |
| 266 """ValueList : ConstValue ValueListCont""" | 269 """ValueList : ConstValue ValueListCont""" |
| 267 p[0] = ListFromConcat(p[1], p[2]) | 270 p[0] = ListFromConcat(p[1], p[2]) |
| 268 | 271 |
| 269 def p_ValueListCont(self, p): | 272 def p_ValueListCont(self, p): |
| 270 """ValueListCont : ValueList | 273 """ValueListCont : ValueList |
| 271 |""" | 274 |""" |
| 272 if len(p) > 1: | 275 if len(p) > 1: |
| 273 p[0] = p[1] | 276 p[0] = p[1] |
| 274 | 277 |
| 275 # [76] | |
| 276 def p_ExtendedAttributeIdentConst(self, p): | 278 def p_ExtendedAttributeIdentConst(self, p): |
| 277 """ExtendedAttributeIdentConst : identifier '=' ConstValue""" | 279 """ExtendedAttributeIdentConst : identifier '=' ConstValue""" |
| 278 p[0] = self.BuildNamed('ExtAttribute', p, 1, p[3]) | 280 p[0] = self.BuildNamed('ExtAttribute', p, 1, p[3]) |
| 279 | 281 |
| 280 | 282 |
| 281 def __init__(self, lexer, verbose=False, debug=False, mute_error=False): | 283 def __init__(self, lexer, verbose=False, debug=False, mute_error=False): |
| 282 IDLParser.__init__(self, lexer, verbose, debug, mute_error) | 284 IDLParser.__init__(self, lexer, verbose, debug, mute_error) |
| 283 | 285 |
| 284 | 286 |
| 285 def main(argv): | 287 def main(argv): |
| (...skipping 12 matching lines...) Expand all Loading... |
| 298 print '\n'.join(ast.Tree(accept_props=['PROD', 'TYPE', 'VALUE'])) | 300 print '\n'.join(ast.Tree(accept_props=['PROD', 'TYPE', 'VALUE'])) |
| 299 if errors: | 301 if errors: |
| 300 print '\nFound %d errors.\n' % errors | 302 print '\nFound %d errors.\n' % errors |
| 301 | 303 |
| 302 | 304 |
| 303 return errors | 305 return errors |
| 304 | 306 |
| 305 | 307 |
| 306 if __name__ == '__main__': | 308 if __name__ == '__main__': |
| 307 sys.exit(main(sys.argv[1:])) | 309 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |