OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # This module's classes provide an interface to mojo modules. Modules are | 5 # This module's classes provide an interface to mojo modules. Modules are |
6 # collections of interfaces and structs to be used by mojo ipc clients and | 6 # collections of interfaces and structs to be used by mojo ipc clients and |
7 # servers. | 7 # servers. |
8 # | 8 # |
9 # A simple interface would be created this way: | 9 # A simple interface would be created this way: |
10 # module = mojom.generate.module.Module('Foo') | 10 # module = mojom.generate.module.Module('Foo') |
11 # interface = module.AddInterface('Bar') | 11 # interface = module.AddInterface('Bar') |
12 # method = interface.AddMethod('Tat', 0) | 12 # method = interface.AddMethod('Tat', 0) |
13 # method.AddParameter('baz', 0, mojom.INT32) | 13 # method.AddParameter('baz', 0, mojom.INT32) |
14 | 14 |
15 | |
16 # We use our own version of __repr__ when displaying the AST, as the | 15 # We use our own version of __repr__ when displaying the AST, as the |
17 # AST currently doesn't capture which nodes are reference (e.g. to | 16 # AST currently doesn't capture which nodes are reference (e.g. to |
18 # types) and which nodes are definitions. This allows us to e.g. print | 17 # types) and which nodes are definitions. This allows us to e.g. print |
19 # the definition of a struct when it's defined inside a module, but | 18 # the definition of a struct when it's defined inside a module, but |
20 # only print its name when it's referenced in e.g. a method parameter. | 19 # only print its name when it's referenced in e.g. a method parameter. |
21 def Repr(obj, as_ref=True): | 20 def Repr(obj, as_ref=True): |
22 """A version of __repr__ that can distinguish references. | 21 """A version of __repr__ that can distinguish references. |
23 | 22 |
24 Sometimes we like to print an object's full representation | 23 Sometimes we like to print an object's full representation |
25 (e.g. with its fields) and sometimes we just want to reference an | 24 (e.g. with its fields) and sometimes we just want to reference an |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ',\n'.join(ReprIndent(name, as_ref) | 75 ',\n'.join(ReprIndent(name, as_ref) |
77 for (name, as_ref) in names.iteritems())) | 76 for (name, as_ref) in names.iteritems())) |
78 | 77 |
79 | 78 |
80 class Kind(object): | 79 class Kind(object): |
81 """Kind represents a type (e.g. int8, string). | 80 """Kind represents a type (e.g. int8, string). |
82 | 81 |
83 Attributes: | 82 Attributes: |
84 spec: A string uniquely identifying the type. May be None. | 83 spec: A string uniquely identifying the type. May be None. |
85 module: {Module} The defining module. Set to None for built-in types. | 84 module: {Module} The defining module. Set to None for built-in types. |
86 parent_kind: The enclosing type. For example, a struct defined | 85 parent_kind: The enclosing type. For example, an enum defined |
87 inside an interface has that interface as its parent. May be None. | 86 inside an interface has that interface as its parent. May be None. |
88 """ | 87 """ |
89 def __init__(self, spec=None, module=None): | 88 def __init__(self, spec=None, module=None): |
90 self.spec = spec | 89 self.spec = spec |
91 self.module = module | 90 self.module = module |
92 self.parent_kind = None | 91 self.parent_kind = None |
93 | 92 |
94 def Repr(self, as_ref=True): | 93 def Repr(self, as_ref=True): |
95 return '<%s spec=%r>' % (self.__class__.__name__, self.spec) | 94 return '<%s spec=%r>' % (self.__class__.__name__, self.spec) |
96 | 95 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 NULLABLE_SHAREDBUFFER | 217 NULLABLE_SHAREDBUFFER |
219 ) | 218 ) |
220 | 219 |
221 | 220 |
222 ATTRIBUTE_MIN_VERSION = 'MinVersion' | 221 ATTRIBUTE_MIN_VERSION = 'MinVersion' |
223 ATTRIBUTE_EXTENSIBLE = 'Extensible' | 222 ATTRIBUTE_EXTENSIBLE = 'Extensible' |
224 ATTRIBUTE_SYNC = 'Sync' | 223 ATTRIBUTE_SYNC = 'Sync' |
225 | 224 |
226 | 225 |
227 class NamedValue(object): | 226 class NamedValue(object): |
228 def __init__(self, module, parent_kind, name): | 227 def __init__(self, module, parent_kind, mojom_name): |
229 self.module = module | 228 self.module = module |
230 self.parent_kind = parent_kind | 229 self.parent_kind = parent_kind |
231 self.name = name | 230 self.mojom_name = mojom_name |
232 | 231 |
233 def GetSpec(self): | 232 def GetSpec(self): |
234 return (self.module.namespace + '.' + | 233 return (self.module.mojom_namespace + '.' + |
235 (self.parent_kind and (self.parent_kind.name + '.') or "") + | 234 (self.parent_kind and (self.parent_kind.mojom_name + '.') or "") + |
236 self.name) | 235 self.mojom_name) |
237 | 236 |
238 | 237 |
239 class BuiltinValue(object): | 238 class BuiltinValue(object): |
240 def __init__(self, value): | 239 def __init__(self, value): |
241 self.value = value | 240 self.value = value |
242 | 241 |
243 | 242 |
244 class ConstantValue(NamedValue): | 243 class ConstantValue(NamedValue): |
245 def __init__(self, module, parent_kind, constant): | 244 def __init__(self, module, parent_kind, constant): |
246 NamedValue.__init__(self, module, parent_kind, constant.name) | 245 NamedValue.__init__(self, module, parent_kind, constant.mojom_name) |
247 self.constant = constant | 246 self.constant = constant |
248 | 247 |
| 248 @property |
| 249 def name(self): |
| 250 return self.constant.name |
| 251 |
249 | 252 |
250 class EnumValue(NamedValue): | 253 class EnumValue(NamedValue): |
251 def __init__(self, module, enum, field): | 254 def __init__(self, module, enum, field): |
252 NamedValue.__init__(self, module, enum.parent_kind, field.name) | 255 NamedValue.__init__(self, module, enum.parent_kind, field.mojom_name) |
| 256 self.field = field |
253 self.enum = enum | 257 self.enum = enum |
254 | 258 |
255 def GetSpec(self): | 259 def GetSpec(self): |
256 return (self.module.namespace + '.' + | 260 return (self.module.mojom_namespace + '.' + |
257 (self.parent_kind and (self.parent_kind.name + '.') or "") + | 261 (self.parent_kind and (self.parent_kind.mojom_name + '.') or "") + |
258 self.enum.name + '.' + self.name) | 262 self.enum.mojom_name + '.' + self.mojom_name) |
| 263 |
| 264 @property |
| 265 def name(self): |
| 266 return self.field.name |
259 | 267 |
260 | 268 |
261 class Constant(object): | 269 class Constant(object): |
262 def __init__(self, name=None, kind=None, value=None, parent_kind=None): | 270 def __init__(self, mojom_name=None, kind=None, value=None, parent_kind=None): |
263 self.name = name | 271 self.mojom_name = mojom_name |
264 self.kind = kind | 272 self.kind = kind |
265 self.value = value | 273 self.value = value |
266 self.parent_kind = parent_kind | 274 self.parent_kind = parent_kind |
267 | 275 |
| 276 def Stylize(self, stylizer): |
| 277 self.name = stylizer.StylizeConstant(self.mojom_name) |
| 278 |
268 | 279 |
269 class Field(object): | 280 class Field(object): |
270 def __init__(self, name=None, kind=None, ordinal=None, default=None, | 281 def __init__(self, mojom_name=None, kind=None, ordinal=None, default=None, |
271 attributes=None): | 282 attributes=None): |
272 if self.__class__.__name__ == 'Field': | 283 if self.__class__.__name__ == 'Field': |
273 raise Exception() | 284 raise Exception() |
274 self.name = name | 285 self.mojom_name = mojom_name |
275 self.kind = kind | 286 self.kind = kind |
276 self.ordinal = ordinal | 287 self.ordinal = ordinal |
277 self.default = default | 288 self.default = default |
278 self.attributes = attributes | 289 self.attributes = attributes |
279 | 290 |
280 def Repr(self, as_ref=True): | 291 def Repr(self, as_ref=True): |
281 # Fields are only referenced by objects which define them and thus | 292 # Fields are only referenced by objects which define them and thus |
282 # they are always displayed as non-references. | 293 # they are always displayed as non-references. |
283 return GenericRepr(self, {'name': False, 'kind': True}) | 294 return GenericRepr(self, {'mojom_name': False, 'kind': True}) |
| 295 |
| 296 def Stylize(self, stylizer): |
| 297 self.name = stylizer.StylizeField(self.mojom_name) |
284 | 298 |
285 @property | 299 @property |
286 def min_version(self): | 300 def min_version(self): |
287 return self.attributes.get(ATTRIBUTE_MIN_VERSION) \ | 301 return self.attributes.get(ATTRIBUTE_MIN_VERSION) \ |
288 if self.attributes else None | 302 if self.attributes else None |
289 | 303 |
290 | 304 |
291 class StructField(Field): pass | 305 class StructField(Field): pass |
292 | 306 |
293 | 307 |
294 class UnionField(Field): pass | 308 class UnionField(Field): pass |
295 | 309 |
296 | 310 |
297 class Struct(ReferenceKind): | 311 class Struct(ReferenceKind): |
298 """A struct with typed fields. | 312 """A struct with typed fields. |
299 | 313 |
300 Attributes: | 314 Attributes: |
301 name: {str} The name of the struct type. | 315 mojom_name: {str} The name of the struct type as defined in mojom. |
| 316 name: {str} The stylized name. |
302 native_only: {bool} Does the struct have a body (i.e. any fields) or is it | 317 native_only: {bool} Does the struct have a body (i.e. any fields) or is it |
303 purely a native struct. | 318 purely a native struct. |
304 fields: {List[StructField]} The members of the struct. | 319 fields: {List[StructField]} The members of the struct. |
| 320 enums: {List[Enum]} The enums defined in the struct scope. |
| 321 constants: {List[Constant]} The constants defined in the struct scope. |
305 attributes: {dict} Additional information about the struct, such as | 322 attributes: {dict} Additional information about the struct, such as |
306 if it's a native struct. | 323 if it's a native struct. |
307 """ | 324 """ |
308 | 325 |
| 326 ReferenceKind.AddSharedProperty('mojom_name') |
309 ReferenceKind.AddSharedProperty('name') | 327 ReferenceKind.AddSharedProperty('name') |
310 ReferenceKind.AddSharedProperty('native_only') | 328 ReferenceKind.AddSharedProperty('native_only') |
311 ReferenceKind.AddSharedProperty('fields') | 329 ReferenceKind.AddSharedProperty('fields') |
| 330 ReferenceKind.AddSharedProperty('enums') |
| 331 ReferenceKind.AddSharedProperty('constants') |
312 ReferenceKind.AddSharedProperty('attributes') | 332 ReferenceKind.AddSharedProperty('attributes') |
313 | 333 |
314 def __init__(self, name=None, module=None, attributes=None): | 334 def __init__(self, mojom_name=None, module=None, attributes=None): |
315 if name is not None: | 335 if mojom_name is not None: |
316 spec = 'x:' + name | 336 spec = 'x:' + mojom_name |
317 else: | 337 else: |
318 spec = None | 338 spec = None |
319 ReferenceKind.__init__(self, spec, False, module) | 339 ReferenceKind.__init__(self, spec, False, module) |
320 self.name = name | 340 self.mojom_name = mojom_name |
321 self.native_only = False | 341 self.native_only = False |
322 self.fields = [] | 342 self.fields = [] |
| 343 self.enums = [] |
| 344 self.constants = [] |
323 self.attributes = attributes | 345 self.attributes = attributes |
324 | 346 |
325 def Repr(self, as_ref=True): | 347 def Repr(self, as_ref=True): |
326 if as_ref: | 348 if as_ref: |
327 return '<%s name=%r module=%s>' % ( | 349 return '<%s mojom_name=%r module=%s>' % ( |
328 self.__class__.__name__, self.name, | 350 self.__class__.__name__, self.mojom_name, |
329 Repr(self.module, as_ref=True)) | 351 Repr(self.module, as_ref=True)) |
330 else: | 352 else: |
331 return GenericRepr(self, {'name': False, 'fields': False, 'module': True}) | 353 return GenericRepr(self, |
| 354 {'mojom_name': False, 'fields': False, 'module': True}) |
332 | 355 |
333 def AddField(self, name, kind, ordinal=None, default=None, attributes=None): | 356 def AddField(self, mojom_name, kind, ordinal=None, default=None, |
334 field = StructField(name, kind, ordinal, default, attributes) | 357 attributes=None): |
| 358 field = StructField(mojom_name, kind, ordinal, default, attributes) |
335 self.fields.append(field) | 359 self.fields.append(field) |
336 return field | 360 return field |
337 | 361 |
| 362 def Stylize(self, stylizer): |
| 363 self.name = stylizer.StylizeStruct(self.mojom_name) |
| 364 for field in self.fields: |
| 365 field.Stylize(stylizer) |
| 366 for enum in self.enums: |
| 367 enum.Stylize(stylizer) |
| 368 for constant in self.constants: |
| 369 constant.Stylize(stylizer) |
| 370 |
338 | 371 |
339 class Union(ReferenceKind): | 372 class Union(ReferenceKind): |
340 """A union of several kinds. | 373 """A union of several kinds. |
341 | 374 |
342 Attributes: | 375 Attributes: |
343 name: {str} The name of the union type. | 376 mojom_name: {str} The name of the union type as defined in mojom. |
| 377 name: {str} The stylized name. |
344 fields: {List[UnionField]} The members of the union. | 378 fields: {List[UnionField]} The members of the union. |
345 attributes: {dict} Additional information about the union, such as | 379 attributes: {dict} Additional information about the union, such as |
346 which Java class name to use to represent it in the generated | 380 which Java class name to use to represent it in the generated |
347 bindings. | 381 bindings. |
348 """ | 382 """ |
| 383 ReferenceKind.AddSharedProperty('mojom_name') |
349 ReferenceKind.AddSharedProperty('name') | 384 ReferenceKind.AddSharedProperty('name') |
350 ReferenceKind.AddSharedProperty('fields') | 385 ReferenceKind.AddSharedProperty('fields') |
351 ReferenceKind.AddSharedProperty('attributes') | 386 ReferenceKind.AddSharedProperty('attributes') |
352 | 387 |
353 def __init__(self, name=None, module=None, attributes=None): | 388 def __init__(self, mojom_name=None, module=None, attributes=None): |
354 if name is not None: | 389 if mojom_name is not None: |
355 spec = 'x:' + name | 390 spec = 'x:' + mojom_name |
356 else: | 391 else: |
357 spec = None | 392 spec = None |
358 ReferenceKind.__init__(self, spec, False, module) | 393 ReferenceKind.__init__(self, spec, False, module) |
359 self.name = name | 394 self.mojom_name = mojom_name |
360 self.fields = [] | 395 self.fields = [] |
361 self.attributes = attributes | 396 self.attributes = attributes |
362 | 397 |
363 def Repr(self, as_ref=True): | 398 def Repr(self, as_ref=True): |
364 if as_ref: | 399 if as_ref: |
365 return '<%s spec=%r is_nullable=%r fields=%s>' % ( | 400 return '<%s spec=%r is_nullable=%r fields=%s>' % ( |
366 self.__class__.__name__, self.spec, self.is_nullable, | 401 self.__class__.__name__, self.spec, self.is_nullable, |
367 Repr(self.fields)) | 402 Repr(self.fields)) |
368 else: | 403 else: |
369 return GenericRepr(self, {'fields': True, 'is_nullable': False}) | 404 return GenericRepr(self, {'fields': True, 'is_nullable': False}) |
370 | 405 |
371 def AddField(self, name, kind, ordinal=None, attributes=None): | 406 def AddField(self, mojom_name, kind, ordinal=None, attributes=None): |
372 field = UnionField(name, kind, ordinal, None, attributes) | 407 field = UnionField(mojom_name, kind, ordinal, None, attributes) |
373 self.fields.append(field) | 408 self.fields.append(field) |
374 return field | 409 return field |
375 | 410 |
| 411 def Stylize(self, stylizer): |
| 412 self.name = stylizer.StylizeUnion(self.mojom_name) |
| 413 for field in self.fields: |
| 414 field.Stylize(stylizer) |
| 415 |
376 | 416 |
377 class Array(ReferenceKind): | 417 class Array(ReferenceKind): |
378 """An array. | 418 """An array. |
379 | 419 |
380 Attributes: | 420 Attributes: |
381 kind: {Kind} The type of the elements. May be None. | 421 kind: {Kind} The type of the elements. May be None. |
382 length: The number of elements. None if unknown. | 422 length: The number of elements. None if unknown. |
383 """ | 423 """ |
384 | 424 |
385 ReferenceKind.AddSharedProperty('kind') | 425 ReferenceKind.AddSharedProperty('kind') |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 "Associated interface request requires %r to be an interface " | 510 "Associated interface request requires %r to be an interface " |
471 "request." % kind.spec) | 511 "request." % kind.spec) |
472 assert not kind.is_nullable | 512 assert not kind.is_nullable |
473 ReferenceKind.__init__(self, 'asso:' + kind.spec) | 513 ReferenceKind.__init__(self, 'asso:' + kind.spec) |
474 else: | 514 else: |
475 ReferenceKind.__init__(self) | 515 ReferenceKind.__init__(self) |
476 self.kind = kind.kind if kind is not None else None | 516 self.kind = kind.kind if kind is not None else None |
477 | 517 |
478 | 518 |
479 class Parameter(object): | 519 class Parameter(object): |
480 def __init__(self, name=None, kind=None, ordinal=None, default=None, | 520 def __init__(self, mojom_name=None, kind=None, ordinal=None, default=None, |
481 attributes=None): | 521 attributes=None): |
482 self.name = name | 522 self.mojom_name = mojom_name |
483 self.ordinal = ordinal | 523 self.ordinal = ordinal |
484 self.kind = kind | 524 self.kind = kind |
485 self.default = default | 525 self.default = default |
486 self.attributes = attributes | 526 self.attributes = attributes |
487 | 527 |
488 def Repr(self, as_ref=True): | 528 def Repr(self, as_ref=True): |
489 return '<%s name=%r kind=%s>' % (self.__class__.__name__, self.name, | 529 return '<%s mojom_name=%r kind=%s>' % ( |
490 self.kind.Repr(as_ref=True)) | 530 self.__class__.__name__, self.mojom_name, self.kind.Repr(as_ref=True)) |
| 531 |
| 532 def Stylize(self, stylizer): |
| 533 self.name = stylizer.StylizeParameter(self.mojom_name) |
491 | 534 |
492 @property | 535 @property |
493 def min_version(self): | 536 def min_version(self): |
494 return self.attributes.get(ATTRIBUTE_MIN_VERSION) \ | 537 return self.attributes.get(ATTRIBUTE_MIN_VERSION) \ |
495 if self.attributes else None | 538 if self.attributes else None |
496 | 539 |
497 | 540 |
498 class Method(object): | 541 class Method(object): |
499 def __init__(self, interface, name, ordinal=None, attributes=None): | 542 def __init__(self, interface, mojom_name, ordinal=None, attributes=None): |
500 self.interface = interface | 543 self.interface = interface |
501 self.name = name | 544 self.mojom_name = mojom_name |
502 self.ordinal = ordinal | 545 self.ordinal = ordinal |
503 self.parameters = [] | 546 self.parameters = [] |
| 547 self.param_struct = None |
504 self.response_parameters = None | 548 self.response_parameters = None |
| 549 self.response_param_struct = None |
505 self.attributes = attributes | 550 self.attributes = attributes |
506 | 551 |
507 def Repr(self, as_ref=True): | 552 def Repr(self, as_ref=True): |
508 if as_ref: | 553 if as_ref: |
509 return '<%s name=%r>' % (self.__class__.__name__, self.name) | 554 return '<%s mojom_name=%r>' % (self.__class__.__name__, self.mojom_name) |
510 else: | 555 else: |
511 return GenericRepr(self, {'name': False, 'parameters': True, | 556 return GenericRepr(self, {'mojom_name': False, 'parameters': True, |
512 'response_parameters': True}) | 557 'response_parameters': True}) |
513 | 558 |
514 def AddParameter(self, name, kind, ordinal=None, default=None, | 559 def AddParameter(self, mojom_name, kind, ordinal=None, default=None, |
515 attributes=None): | 560 attributes=None): |
516 parameter = Parameter(name, kind, ordinal, default, attributes) | 561 parameter = Parameter(mojom_name, kind, ordinal, default, attributes) |
517 self.parameters.append(parameter) | 562 self.parameters.append(parameter) |
518 return parameter | 563 return parameter |
519 | 564 |
520 def AddResponseParameter(self, name, kind, ordinal=None, default=None, | 565 def AddResponseParameter(self, mojom_name, kind, ordinal=None, default=None, |
521 attributes=None): | 566 attributes=None): |
522 if self.response_parameters == None: | 567 if self.response_parameters == None: |
523 self.response_parameters = [] | 568 self.response_parameters = [] |
524 parameter = Parameter(name, kind, ordinal, default, attributes) | 569 parameter = Parameter(mojom_name, kind, ordinal, default, attributes) |
525 self.response_parameters.append(parameter) | 570 self.response_parameters.append(parameter) |
526 return parameter | 571 return parameter |
527 | 572 |
| 573 def Stylize(self, stylizer): |
| 574 self.name = stylizer.StylizeMethod(self.mojom_name) |
| 575 for param in self.parameters: |
| 576 param.Stylize(stylizer) |
| 577 if self.response_parameters is not None: |
| 578 for param in self.response_parameters: |
| 579 param.Stylize(stylizer) |
| 580 |
| 581 if self.param_struct: |
| 582 self.param_struct.Stylize(stylizer) |
| 583 if self.response_param_struct: |
| 584 self.response_param_struct.Stylize(stylizer) |
| 585 |
528 @property | 586 @property |
529 def min_version(self): | 587 def min_version(self): |
530 return self.attributes.get(ATTRIBUTE_MIN_VERSION) \ | 588 return self.attributes.get(ATTRIBUTE_MIN_VERSION) \ |
531 if self.attributes else None | 589 if self.attributes else None |
532 | 590 |
533 @property | 591 @property |
534 def sync(self): | 592 def sync(self): |
535 return self.attributes.get(ATTRIBUTE_SYNC) \ | 593 return self.attributes.get(ATTRIBUTE_SYNC) \ |
536 if self.attributes else None | 594 if self.attributes else None |
537 | 595 |
538 | 596 |
539 class Interface(ReferenceKind): | 597 class Interface(ReferenceKind): |
| 598 ReferenceKind.AddSharedProperty('mojom_name') |
540 ReferenceKind.AddSharedProperty('name') | 599 ReferenceKind.AddSharedProperty('name') |
541 ReferenceKind.AddSharedProperty('methods') | 600 ReferenceKind.AddSharedProperty('methods') |
| 601 ReferenceKind.AddSharedProperty('enums') |
| 602 ReferenceKind.AddSharedProperty('constants') |
542 ReferenceKind.AddSharedProperty('attributes') | 603 ReferenceKind.AddSharedProperty('attributes') |
543 | 604 |
544 def __init__(self, name=None, module=None, attributes=None): | 605 def __init__(self, mojom_name=None, module=None, attributes=None): |
545 if name is not None: | 606 if mojom_name is not None: |
546 spec = 'x:' + name | 607 spec = 'x:' + mojom_name |
547 else: | 608 else: |
548 spec = None | 609 spec = None |
549 ReferenceKind.__init__(self, spec, False, module) | 610 ReferenceKind.__init__(self, spec, False, module) |
550 self.name = name | 611 self.mojom_name = mojom_name |
551 self.methods = [] | 612 self.methods = [] |
| 613 self.enums = [] |
| 614 self.constants = [] |
552 self.attributes = attributes | 615 self.attributes = attributes |
553 | 616 |
554 def Repr(self, as_ref=True): | 617 def Repr(self, as_ref=True): |
555 if as_ref: | 618 if as_ref: |
556 return '<%s name=%r>' % (self.__class__.__name__, self.name) | 619 return '<%s mojom_name=%r>' % (self.__class__.__name__, self.mojom_name) |
557 else: | 620 else: |
558 return GenericRepr(self, {'name': False, 'attributes': False, | 621 return GenericRepr(self, {'mojom_name': False, 'attributes': False, |
559 'methods': False}) | 622 'methods': False}) |
560 | 623 |
561 def AddMethod(self, name, ordinal=None, attributes=None): | 624 def AddMethod(self, mojom_name, ordinal=None, attributes=None): |
562 method = Method(self, name, ordinal, attributes) | 625 method = Method(self, mojom_name, ordinal, attributes) |
563 self.methods.append(method) | 626 self.methods.append(method) |
564 return method | 627 return method |
565 | 628 |
566 # TODO(451323): Remove when the language backends no longer rely on this. | 629 def Stylize(self, stylizer): |
567 @property | 630 self.name = stylizer.StylizeInterface(self.mojom_name) |
568 def client(self): | 631 for method in self.methods: |
569 return None | 632 method.Stylize(stylizer) |
| 633 for enum in self.enums: |
| 634 enum.Stylize(stylizer) |
| 635 for constant in self.constants: |
| 636 constant.Stylize(stylizer) |
570 | 637 |
571 | 638 |
572 class AssociatedInterface(ReferenceKind): | 639 class AssociatedInterface(ReferenceKind): |
573 ReferenceKind.AddSharedProperty('kind') | 640 ReferenceKind.AddSharedProperty('kind') |
574 | 641 |
575 def __init__(self, kind=None): | 642 def __init__(self, kind=None): |
576 if kind is not None: | 643 if kind is not None: |
577 if not isinstance(kind, Interface): | 644 if not isinstance(kind, Interface): |
578 raise Exception( | 645 raise Exception( |
579 "Associated interface requires %r to be an interface." % kind.spec) | 646 "Associated interface requires %r to be an interface." % kind.spec) |
580 assert not kind.is_nullable | 647 assert not kind.is_nullable |
581 ReferenceKind.__init__(self, 'asso:' + kind.spec) | 648 ReferenceKind.__init__(self, 'asso:' + kind.spec) |
582 else: | 649 else: |
583 ReferenceKind.__init__(self) | 650 ReferenceKind.__init__(self) |
584 self.kind = kind | 651 self.kind = kind |
585 | 652 |
586 | 653 |
587 class EnumField(object): | 654 class EnumField(object): |
588 def __init__(self, name=None, value=None, attributes=None, | 655 def __init__(self, mojom_name=None, value=None, attributes=None, |
589 numeric_value=None): | 656 numeric_value=None): |
590 self.name = name | 657 self.mojom_name = mojom_name |
591 self.value = value | 658 self.value = value |
592 self.attributes = attributes | 659 self.attributes = attributes |
593 self.numeric_value = numeric_value | 660 self.numeric_value = numeric_value |
594 | 661 |
| 662 def Stylize(self, stylizer): |
| 663 self.name = stylizer.StylizeEnumField(self.mojom_name) |
| 664 |
595 @property | 665 @property |
596 def min_version(self): | 666 def min_version(self): |
597 return self.attributes.get(ATTRIBUTE_MIN_VERSION) \ | 667 return self.attributes.get(ATTRIBUTE_MIN_VERSION) \ |
598 if self.attributes else None | 668 if self.attributes else None |
599 | 669 |
600 | 670 |
601 class Enum(Kind): | 671 class Enum(Kind): |
602 def __init__(self, name=None, module=None, attributes=None): | 672 def __init__(self, mojom_name=None, module=None, attributes=None): |
603 self.name = name | 673 self.mojom_name = mojom_name |
604 self.native_only = False | 674 self.native_only = False |
605 if name is not None: | 675 if mojom_name is not None: |
606 spec = 'x:' + name | 676 spec = 'x:' + mojom_name |
607 else: | 677 else: |
608 spec = None | 678 spec = None |
609 Kind.__init__(self, spec, module) | 679 Kind.__init__(self, spec, module) |
610 self.fields = [] | 680 self.fields = [] |
611 self.attributes = attributes | 681 self.attributes = attributes |
612 | 682 |
613 def Repr(self, as_ref=True): | 683 def Repr(self, as_ref=True): |
614 if as_ref: | 684 if as_ref: |
615 return '<%s name=%r>' % (self.__class__.__name__, self.name) | 685 return '<%s mojom_name=%r>' % (self.__class__.__name__, self.mojom_name) |
616 else: | 686 else: |
617 return GenericRepr(self, {'name': False, 'fields': False}) | 687 return GenericRepr(self, {'mojom_name': False, 'fields': False}) |
| 688 |
| 689 def Stylize(self, stylizer): |
| 690 self.name = stylizer.StylizeEnum(self.mojom_name) |
| 691 for field in self.fields: |
| 692 field.Stylize(stylizer) |
618 | 693 |
619 @property | 694 @property |
620 def extensible(self): | 695 def extensible(self): |
621 return self.attributes.get(ATTRIBUTE_EXTENSIBLE, False) \ | 696 return self.attributes.get(ATTRIBUTE_EXTENSIBLE, False) \ |
622 if self.attributes else False | 697 if self.attributes else False |
623 | 698 |
624 | 699 |
625 class Module(object): | 700 class Module(object): |
626 def __init__(self, path=None, namespace=None, attributes=None): | 701 def __init__(self, path=None, mojom_namespace=None, |
| 702 attributes=None): |
627 self.path = path | 703 self.path = path |
628 self.namespace = namespace | 704 self.mojom_namespace = mojom_namespace |
629 self.structs = [] | 705 self.structs = [] |
630 self.unions = [] | 706 self.unions = [] |
631 self.interfaces = [] | 707 self.interfaces = [] |
| 708 self.enums = [] |
| 709 self.constants = [] |
632 self.kinds = {} | 710 self.kinds = {} |
633 self.attributes = attributes | 711 self.attributes = attributes |
| 712 self.imports = [] |
634 | 713 |
635 def __repr__(self): | 714 def __repr__(self): |
636 # Gives us a decent __repr__ for modules. | 715 # Gives us a decent __repr__ for modules. |
637 return self.Repr() | 716 return self.Repr() |
638 | 717 |
639 def Repr(self, as_ref=True): | 718 def Repr(self, as_ref=True): |
640 if as_ref: | 719 if as_ref: |
641 return '<%s path=%r namespace=%r>' % ( | 720 return '<%s path=%r mojom_namespace=%r>' % ( |
642 self.__class__.__name__, self.path, self.namespace) | 721 self.__class__.__name__, self.path, self.mojom_namespace) |
643 else: | 722 else: |
644 return GenericRepr(self, {'path': False, 'namespace': False, | 723 return GenericRepr(self, {'path': False, 'mojom_namespace': False, |
645 'attributes': False, 'structs': False, | 724 'attributes': False, 'structs': False, |
646 'interfaces': False, 'unions': False}) | 725 'interfaces': False, 'unions': False}) |
647 | 726 |
648 def AddInterface(self, name, attributes=None): | 727 def AddInterface(self, mojom_name, attributes=None): |
649 interface = Interface(name, self, attributes) | 728 interface = Interface(mojom_name, self, attributes) |
650 self.interfaces.append(interface) | 729 self.interfaces.append(interface) |
651 return interface | 730 return interface |
652 | 731 |
653 def AddStruct(self, name, attributes=None): | 732 def AddStruct(self, mojom_name, attributes=None): |
654 struct = Struct(name, self, attributes) | 733 struct = Struct(mojom_name, self, attributes) |
655 self.structs.append(struct) | 734 self.structs.append(struct) |
656 return struct | 735 return struct |
657 | 736 |
658 def AddUnion(self, name, attributes=None): | 737 def AddUnion(self, mojom_name, attributes=None): |
659 union = Union(name, self, attributes) | 738 union = Union(mojom_name, self, attributes) |
660 self.unions.append(union) | 739 self.unions.append(union) |
661 return union | 740 return union |
662 | 741 |
| 742 def Stylize(self, stylizer): |
| 743 self.namespace = stylizer.StylizeModule(self.mojom_namespace) |
| 744 for struct in self.structs: |
| 745 struct.Stylize(stylizer) |
| 746 for union in self.unions: |
| 747 union.Stylize(stylizer) |
| 748 for interface in self.interfaces: |
| 749 interface.Stylize(stylizer) |
| 750 for enum in self.enums: |
| 751 enum.Stylize(stylizer) |
| 752 for constant in self.constants: |
| 753 constant.Stylize(stylizer) |
| 754 |
| 755 for imported_module in self.imports: |
| 756 imported_module.Stylize(stylizer) |
| 757 |
663 | 758 |
664 def IsBoolKind(kind): | 759 def IsBoolKind(kind): |
665 return kind.spec == BOOL.spec | 760 return kind.spec == BOOL.spec |
666 | 761 |
667 | 762 |
668 def IsFloatKind(kind): | 763 def IsFloatKind(kind): |
669 return kind.spec == FLOAT.spec | 764 return kind.spec == FLOAT.spec |
670 | 765 |
671 | 766 |
672 def IsDoubleKind(kind): | 767 def IsDoubleKind(kind): |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 return True | 967 return True |
873 elif IsAnyInterfaceKind(kind): | 968 elif IsAnyInterfaceKind(kind): |
874 return True | 969 return True |
875 elif IsArrayKind(kind): | 970 elif IsArrayKind(kind): |
876 return Check(kind.kind) | 971 return Check(kind.kind) |
877 elif IsMapKind(kind): | 972 elif IsMapKind(kind): |
878 return Check(kind.key_kind) or Check(kind.value_kind) | 973 return Check(kind.key_kind) or Check(kind.value_kind) |
879 else: | 974 else: |
880 return False | 975 return False |
881 return Check(kind) | 976 return Check(kind) |
OLD | NEW |