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