Skip to content

Commit

Permalink
mojom: Change array syntax from uint8[] to array<uint8>.
Browse files Browse the repository at this point in the history
This makes precedence clearer in the case of nested arrays.

BUG=none

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

Cr-Commit-Position: refs/heads/master@{#297989}
  • Loading branch information
eglaysher authored and Commit bot committed Oct 3, 2014
1 parent 4009aab commit 5a0c878
Show file tree
Hide file tree
Showing 27 changed files with 93 additions and 90 deletions.
8 changes: 4 additions & 4 deletions chrome/browser/ui/webui/omnibox/omnibox.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ struct AutocompleteMatchMojo {
bool starred;
int32 duplicates;
bool from_previous;
AutocompleteAdditionalInfo[] additional_info;
array<AutocompleteAdditionalInfo> additional_info;
};

struct AutocompleteResultsForProviderMojo {
string provider_name;
AutocompleteMatchMojo[] results;
array<AutocompleteMatchMojo> results;
};

struct OmniboxResultMojo {
Expand All @@ -43,8 +43,8 @@ struct OmniboxResultMojo {
int32 time_since_omnibox_started_ms;
string host;
bool is_typed_host;
AutocompleteMatchMojo[] combined_results;
AutocompleteResultsForProviderMojo[] results_by_provider;
array<AutocompleteMatchMojo> combined_results;
array<AutocompleteResultsForProviderMojo> results_by_provider;
};

[Client=OmniboxPage]
Expand Down
2 changes: 1 addition & 1 deletion device/serial/serial.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct DeviceControlSignals {
};

interface SerialService {
GetDevices() => (DeviceInfo[] devices);
GetDevices() => (array<DeviceInfo> devices);

// Creates a |Connection| to |path| with options specified by |options|,
// returning it via |connection|. Sending and receiving data over this
Expand Down
4 changes: 2 additions & 2 deletions media/mojo/interfaces/media_types.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct AudioDecoderConfig {
SampleFormat sample_format;
ChannelLayout channel_layout;
int32 samples_per_second;
uint8[]? extra_data;
array<uint8>? extra_data;
int64 seek_preroll_usec;
int32 codec_delay;
};
Expand All @@ -107,7 +107,7 @@ struct MediaDecoderBuffer {

// This is backed by an std::vector and results in a few copies.
// Into the vector, onto and off the MessagePipe, back into a vector.
uint8[] side_data;
array<uint8> side_data;
uint32 side_data_size;

// These fields indicate the amount of data to discard after decoding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public void testStructPointer() {
@SmallTest
public void testStructArray() {
Struct4 struct = new Struct4();
assertNull(struct.array);
assertNull(struct.data);
assertThrowsSerializationException(struct);

// Create the (1-element) array but have the element null.
struct.array = new Struct1[1];
struct.data = new Struct1[1];
assertThrowsSerializationException(struct);

// Create the array element, struct should serialize now.
struct.array[0] = new Struct1();
struct.data[0] = new Struct1();
struct.serialize(null);
}

Expand Down
2 changes: 1 addition & 1 deletion mojo/apps/js/test/js_to_cpp.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct EchoArgs {
double double_inf;
double double_nan;
string? name;
string[]? string_array;
array<string>? string_array;
handle<message_pipe>? message_handle;
handle<data_pipe_consumer>? data_handle;
};
Expand Down
10 changes: 5 additions & 5 deletions mojo/public/cpp/bindings/tests/serialization_warning_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,25 @@ TEST_F(SerializationWarningTest, StructInStruct) {

TEST_F(SerializationWarningTest, ArrayOfStructsInStruct) {
Struct4Ptr test_struct(Struct4::New());
EXPECT_TRUE(!test_struct->array);
EXPECT_TRUE(!test_struct->data);

TestWarning(test_struct.Pass(),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER);

test_struct = Struct4::New();
test_struct->array.resize(1);
test_struct->data.resize(1);

TestWarning(test_struct.Pass(),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER);

test_struct = Struct4::New();
test_struct->array.resize(0);
test_struct->data.resize(0);

TestWarning(test_struct.Pass(), mojo::internal::VALIDATION_ERROR_NONE);

test_struct = Struct4::New();
test_struct->array.resize(1);
test_struct->array[0] = Struct1::New();
test_struct->data.resize(1);
test_struct->data[0] = Struct1::New();

TestWarning(test_struct.Pass(), mojo::internal::VALIDATION_ERROR_NONE);
}
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/interfaces/application/application.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module mojo {
[Client=Shell]
interface Application {
// Initialize is guaranteed to be called before any AcceptConnection calls.
Initialize(string[]? args);
Initialize(array<string>? args);

AcceptConnection(string? requestor_url, ServiceProvider? provider);
};
Expand Down
2 changes: 1 addition & 1 deletion mojo/public/interfaces/bindings/tests/sample_factory.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module sample {
struct Request {
int32 x;
handle<message_pipe>? pipe;
handle<message_pipe>[]? more_pipes;
array<handle<message_pipe>>? more_pipes;

// Interfaces can be used as members.
imported.ImportedInterface? obj;
Expand Down
16 changes: 8 additions & 8 deletions mojo/public/interfaces/bindings/tests/sample_service.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ struct Foo {
bool b@3;
bool c@4;
Bar? bar@5;
Bar[]? extra_bars@7;
uint8[]? data@6;
array<Bar>? extra_bars@7;
array<uint8>? data@6;
handle<message_pipe>? source@9;
handle<data_pipe_consumer>[]? input_streams@10;
handle<data_pipe_producer>[]? output_streams@11;
bool[][]? array_of_array_of_bools@12;
string[][][]? multi_array_of_strings@13;
bool[]? array_of_bools@14;
array<handle<data_pipe_consumer>>? input_streams@10;
array<handle<data_pipe_producer>>? output_streams@11;
array<array<bool>>? array_of_array_of_bools@12;
array<array<array<string>>>? multi_array_of_strings@13;
array<bool>? array_of_bools@14;
};

struct DefaultsTest {
Expand All @@ -74,7 +74,7 @@ struct DefaultsTest {

// TODO(vtl): Add tests for default vs null when those are implemented (for
// structs, arrays, and strings).
uint8[] a18@18;
array<uint8> a18@18;
string a19@19;

Bar.Type a20@20 = BOTH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ struct Struct3 {
};

struct Struct4 {
Struct1[] array;
array<Struct1> data;
};

struct Struct5 {
Struct1[2] pair;
array<Struct1, 2> pair;
};

struct Struct6 {
Expand Down
10 changes: 5 additions & 5 deletions mojo/public/interfaces/bindings/tests/test_structs.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module mojo.test {

struct NamedRegion {
string? name;
Rect[]? rects;
array<Rect>? rects;
};

struct RectPair {
Expand Down Expand Up @@ -49,10 +49,10 @@ struct NoDefaultFieldValues {
handle? f20;
handle<shared_buffer> f21;
handle<shared_buffer>? f22;
string[] f23;
string?[] f24;
string[]? f25;
string?[]? f26;
array<string> f23;
array<string?> f24;
array<string>? f25;
array<string?>? f26;
EmptyStruct f27;
EmptyStruct? f28;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ struct StructB {
};

struct StructC {
uint8[] array;
array<uint8> data;
};

struct StructD {
handle<message_pipe>[] message_pipes;
array<handle<message_pipe>> message_pipes;
};

struct StructE {
Expand All @@ -28,20 +28,20 @@ struct StructE {
};

struct StructF {
uint8[3] fixed_size_array;
array<uint8, 3> fixed_size_array;
};

interface ConformanceTestInterface {
Method0(float param0);
Method1(StructA param0);
Method2(StructB param0, StructA param1);
Method3(bool[] param0);
Method4(StructC param0, uint8[] param1);
Method3(array<bool> param0);
Method4(StructC param0, array<uint8> param1);
Method5(StructE param0, handle<data_pipe_producer> param1);
Method6(uint8[][] param0);
Method7(StructF param0, uint8[5] param1);
Method8(string[]?[] param0);
Method9(handle?[][]? param0);
Method6(array<array<uint8>> param0);
Method7(StructF param0, array<uint8, 5> param1);
Method8(array<array<string>?> param0);
Method9(array<array<handle?>>? param0);
};

struct BasicStruct {
Expand All @@ -55,7 +55,7 @@ interface IntegrationTestInterface1 {

[Client=IntegrationTestInterface1]
interface IntegrationTestInterface2 {
Method0() => (uint8[] param0);
Method0() => (array<uint8> param0);
};

}
1 change: 1 addition & 0 deletions mojo/public/tools/bindings/pylib/mojom/parse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _error(self, msg, token):
'TRUE',
'FALSE',
'DEFAULT',
'ARRAY'
)

keyword_map = {}
Expand Down
14 changes: 7 additions & 7 deletions mojo/public/tools/bindings/pylib/mojom/parse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,17 @@ def p_handletype(self, p):
p[0] = "handle<" + p[3] + ">"

def p_array(self, p):
"""array : typename LBRACKET RBRACKET"""
p[0] = p[1] + "[]"
"""array : ARRAY LANGLE typename RANGLE"""
p[0] = p[3] + "[]"

def p_fixed_array(self, p):
"""fixed_array : typename LBRACKET INT_CONST_DEC RBRACKET"""
value = int(p[3])
"""fixed_array : ARRAY LANGLE typename COMMA INT_CONST_DEC RANGLE"""
value = int(p[5])
if value == 0 or value > _MAX_ARRAY_SIZE:
raise ParseError(self.filename, "Fixed array size %d invalid" % value,
lineno=p.lineno(3),
snippet=self._GetSnippet(p.lineno(3)))
p[0] = p[1] + "[" + p[3] + "]"
lineno=p.lineno(5),
snippet=self._GetSnippet(p.lineno(5)))
p[0] = p[3] + "[" + p[5] + "]"

def p_interfacerequest(self, p):
"""interfacerequest : identifier AMP"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def testValidKeywords(self):
_MakeLexTokenForKeyword("false"))
self.assertEquals(self._SingleTokenForInput("default"),
_MakeLexTokenForKeyword("default"))
self.assertEquals(self._SingleTokenForInput("array"),
_MakeLexTokenForKeyword("array"))

def testValidIdentifiers(self):
"""Tests identifiers."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,9 @@ def testValidFixedSizeArray(self):

source = """\
struct MyStruct {
int32[] normal_array;
int32[1] fixed_size_array_one_entry;
int32[10] fixed_size_array_ten_entries;
array<int32> normal_array;
array<int32, 1> fixed_size_array_one_entry;
array<int32, 10> fixed_size_array_ten_entries;
};
"""
expected = ast.Mojom(
Expand All @@ -636,7 +636,7 @@ def testValidFixedSizeArray(self):
def testValidNestedArray(self):
"""Tests parsing a nested array."""

source = "struct MyStruct { int32[][] nested_array; };"
source = "struct MyStruct { array<array<int32>> nested_array; };"
expected = ast.Mojom(
None,
ast.ImportList(),
Expand All @@ -652,35 +652,35 @@ def testInvalidFixedArraySize(self):

source1 = """\
struct MyStruct {
int32[0] zero_size_array;
array<int32, 0> zero_size_array;
};
"""
with self.assertRaisesRegexp(
parser.ParseError,
r"^my_file\.mojom:2: Error: Fixed array size 0 invalid\n"
r" *int32\[0\] zero_size_array;$"):
r" *array<int32, 0> zero_size_array;$"):
parser.Parse(source1, "my_file.mojom")

source2 = """\
struct MyStruct {
int32[999999999999] too_big_array;
array<int32, 999999999999> too_big_array;
};
"""
with self.assertRaisesRegexp(
parser.ParseError,
r"^my_file\.mojom:2: Error: Fixed array size 999999999999 invalid\n"
r" *int32\[999999999999\] too_big_array;$"):
r" *array<int32, 999999999999> too_big_array;$"):
parser.Parse(source2, "my_file.mojom")

source3 = """\
struct MyStruct {
int32[abcdefg] not_a_number;
array<int32, abcdefg> not_a_number;
};
"""
with self.assertRaisesRegexp(
parser.ParseError,
r"^my_file\.mojom:2: Error: Unexpected 'abcdefg':\n"
r" *int32\[abcdefg\] not_a_number;"):
r" *array<int32, abcdefg> not_a_number;"):
parser.Parse(source3, "my_file.mojom")

def testValidMethod(self):
Expand Down Expand Up @@ -980,11 +980,11 @@ def testValidNullableTypes(self):
int32? a; // This is actually invalid, but handled at a different
// level.
string? b;
int32[] ? c;
string ? [] ? d;
int32[]?[]? e;
int32[1]? f;
string?[1]? g;
array<int32> ? c;
array<string ? > ? d;
array<array<int32>?>? e;
array<int32, 1>? f;
array<string?, 1>? g;
some_struct? h;
handle? i;
handle<data_pipe_consumer>? j;
Expand Down
Loading

0 comments on commit 5a0c878

Please sign in to comment.