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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/generate/pack.py

Issue 611633002: mojom: Add associative arrays to the mojom language. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved test classes to their own shared file. Created 6 years, 2 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
OLDNEW
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 import module as mojom 5 import module as mojom
6 6
7 # This module provides a mechanism for determining the packed order and offsets 7 # This module provides a mechanism for determining the packed order and offsets
8 # of a mojom.Struct. 8 # of a mojom.Struct.
9 # 9 #
10 # ps = pack.PackedStruct(struct) 10 # ps = pack.PackedStruct(struct)
(...skipping 22 matching lines...) Expand all
33 mojom.NULLABLE_DPPIPE: 4, 33 mojom.NULLABLE_DPPIPE: 4,
34 mojom.INT64: 8, 34 mojom.INT64: 8,
35 mojom.UINT64: 8, 35 mojom.UINT64: 8,
36 mojom.DOUBLE: 8, 36 mojom.DOUBLE: 8,
37 mojom.STRING: 8, 37 mojom.STRING: 8,
38 mojom.NULLABLE_STRING: 8 38 mojom.NULLABLE_STRING: 8
39 } 39 }
40 40
41 @classmethod 41 @classmethod
42 def GetSizeForKind(cls, kind): 42 def GetSizeForKind(cls, kind):
43 if isinstance(kind, (mojom.Array, mojom.Struct, mojom.FixedArray)): 43 if isinstance(kind, (mojom.Array, mojom.Map, mojom.Struct,
44 mojom.FixedArray)):
44 return 8 45 return 8
45 if isinstance(kind, mojom.Interface) or \ 46 if isinstance(kind, mojom.Interface) or \
46 isinstance(kind, mojom.InterfaceRequest): 47 isinstance(kind, mojom.InterfaceRequest):
47 kind = mojom.MSGPIPE 48 kind = mojom.MSGPIPE
48 if isinstance(kind, mojom.Enum): 49 if isinstance(kind, mojom.Enum):
49 # TODO(mpcomplete): what about big enums? 50 # TODO(mpcomplete): what about big enums?
50 return cls.kind_to_size[mojom.INT32] 51 return cls.kind_to_size[mojom.INT32]
51 if not kind in cls.kind_to_size: 52 if not kind in cls.kind_to_size:
52 raise Exception("Invalid kind: %s" % kind.spec) 53 raise Exception("Invalid kind: %s" % kind.spec)
53 return cls.kind_to_size[kind] 54 return cls.kind_to_size[kind]
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 limit_of_previous_field = packed_field.offset + packed_field.size 155 limit_of_previous_field = packed_field.offset + packed_field.size
155 156
156 for i in xrange(limit_of_previous_field, len(bytes)): 157 for i in xrange(limit_of_previous_field, len(bytes)):
157 bytes[i].is_padding = True 158 bytes[i].is_padding = True
158 159
159 for byte in bytes: 160 for byte in bytes:
160 # A given byte cannot both be padding and have a fields packed into it. 161 # A given byte cannot both be padding and have a fields packed into it.
161 assert not (byte.is_padding and byte.packed_fields) 162 assert not (byte.is_padding and byte.packed_fields)
162 163
163 return bytes 164 return bytes
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/generate/module.py ('k') | mojo/public/tools/bindings/pylib/mojom/parse/lexer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698