Skip to content

Commit

Permalink
Mojom: allow attributes that are not assigned a value.
Browse files Browse the repository at this point in the history
For example, with this CL you can use [Extensible], which is the same as [Extensible=true].

This CL also fixes the issue that boolean attribute values are not correctly evaluated: if you use the mojom keywords "true"/"false" there is parsing error; if you use "True"/"False" they are actually considered as strings.

BUG=None

Review URL: https://codereview.chromium.org/1671613002

Cr-Commit-Position: refs/heads/master@{#373707}
  • Loading branch information
yzshen authored and Commit bot committed Feb 5, 2016
1 parent d2e2254 commit 600b32e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion components/arc/common/ime.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module arc;

// Represents the type of text input field currently focused.
[Extensible=True]
[Extensible]
enum TextInputType {
NONE,
TEXT,
Expand Down
2 changes: 1 addition & 1 deletion components/arc/common/net.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module arc;

[Extensible=True]
[Extensible]
enum NetworkResult {
SUCCESS = 0,
FAILURE = 1,
Expand Down
2 changes: 1 addition & 1 deletion components/arc/common/power.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module arc;

// Enumerates the types of wake lock the ARC instance can request from the
// host.
[Extensible=True]
[Extensible]
enum DisplayWakeLockType {
// Does not allow the screen to dim, turn off, or lock; prevents
// idle suspend.
Expand Down
2 changes: 1 addition & 1 deletion components/mus/public/interfaces/input_key_codes.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module mus.mojom;
//
// Because the web has standardized on Win32 keyboard codes, so does mojo.
// TODO: shouldn't need extensible, see http://crbug.com/582279
[Extensible=True]
[Extensible]
enum KeyboardCode {
BACK = 0x08,
TAB = 0x09,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "mojo/public/interfaces/bindings/tests/rect.mojom";

// Used to verify that structs can be declared with no body in mojom.

[Native=True]
[Native]
struct PickledStruct;

struct PickleContainer {
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/interfaces/bindings/tests/test_unions.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enum AnEnum {
FIRST, SECOND
};

[Extensible=True]
[Extensible]
enum AnExtensibleEnum {
FIRST, SECOND, THIRD
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ enum EnumA {
ENUM_A_1
};

[Extensible=True]
[Extensible]
enum EnumB {
ENUM_B_0,
ENUM_B_1,
Expand Down
4 changes: 2 additions & 2 deletions mojo/public/tools/bindings/pylib/mojom/generate/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ def StructFromData(module, data):
struct.fields_data = data['fields']
struct.attributes = data.get('attributes')

# Enforce that a [Native=True] attribute is set to make native-only struct
# Enforce that a [Native] 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.")
"Native attribute.")

return struct

Expand Down
17 changes: 14 additions & 3 deletions mojo/public/tools/bindings/pylib/mojom/parse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,26 @@ def p_nonempty_attribute_list_2(self, p):
p[0] = p[1]
p[0].Append(p[3])

def p_attribute(self, p):
def p_attribute_1(self, p):
"""attribute : NAME EQUALS evaled_literal
| NAME EQUALS NAME"""
p[0] = ast.Attribute(p[1], p[3], filename=self.filename, lineno=p.lineno(1))

def p_attribute_2(self, p):
"""attribute : NAME"""
p[0] = ast.Attribute(p[1], True, filename=self.filename, lineno=p.lineno(1))

def p_evaled_literal(self, p):
"""evaled_literal : literal"""
# 'eval' the literal to strip the quotes.
p[0] = eval(p[1])
# 'eval' the literal to strip the quotes. Handle keywords "true" and "false"
# specially since they cannot directly be evaluated to python boolean
# values.
if p[1] == "true":
p[0] = True
elif p[1] == "false":
p[0] = False
else:
p[0] = eval(p[1])

def p_struct_1(self, p):
"""struct : attribute_section STRUCT NAME LBRACE struct_body RBRACE SEMI"""
Expand Down

0 comments on commit 600b32e

Please sign in to comment.