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

Unified Diff: mojo/public/tools/bindings/pylib/mojom/generate/data.py

Issue 1515423002: [mojo] Add mojom parser support for native-only structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pickle2
Patch Set: oops Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/pylib/mojom/generate/data.py
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/data.py b/mojo/public/tools/bindings/pylib/mojom/generate/data.py
index 1109a6afe27f0131bd147deb1a475e5a49a09f29..60ae1e0d4c55e3df67b6db1c6cfc508696505527 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/data.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/data.py
@@ -209,15 +209,29 @@ def StructToData(struct):
def StructFromData(module, data):
struct = mojom.Struct(module=module)
struct.name = data['name']
+ struct.native_only = data['native_only']
struct.spec = 'x:' + module.namespace + '.' + struct.name
module.kinds[struct.spec] = struct
- struct.enums = map(lambda enum:
- EnumFromData(module, enum, struct), data['enums'])
- struct.constants = map(lambda constant:
- ConstantFromData(module, constant, struct), data['constants'])
- # Stash fields data here temporarily.
- struct.fields_data = data['fields']
+ if struct.native_only:
+ struct.enums = []
+ struct.constants = []
+ struct.fields_data = []
+ else:
+ struct.enums = map(lambda enum:
+ EnumFromData(module, enum, struct), data['enums'])
+ struct.constants = map(lambda constant:
+ ConstantFromData(module, constant, struct), data['constants'])
+ # Stash fields data here temporarily.
+ struct.fields_data = data['fields']
struct.attributes = data.get('attributes')
+
+ # Enforce that a [native=True] attribute is set to make native-only struct
+ # declarations more explicit.
+ if struct.native_only:
+ if not struct.attributes or not struct.attributes.get('native', False):
+ raise Exception("Native-only struct declarations must include a " +
+ "native=True attribute.")
+
return struct
def UnionToData(union):

Powered by Google App Engine
This is Rietveld 408576698