| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // This is the library |
| library test; |
| |
| using zx; |
| |
| /// we do not aggregate attributes, but they should not be |
| /// lost either |
| /// |
| /// and it's also neat to format them properly |
| using something.or.another as thing; |
| |
| struct arrays { |
| array<handle>:1 handle_0; |
| }; |
| |
| // My oh my |
| struct DirectoryObject { |
| int32 y; |
| }; |
| |
| const uint64 w = 9021; |
| |
| // Random comment |
| |
| const uint32 x = 9021; |
| const uint32 y = 9021; |
| |
| // My wonderful constant |
| const uint32 z = 9021; |
| |
| // Comment requiring space |
| |
| enum Enum2 : uint32 { |
| enum_0 = 0; // More comments |
| }; |
| |
| bits Bats : uint64 { |
| FIRST_MEMBER = 0b010101; |
| }; |
| |
| /// a type alias doc comment |
| alias TheTypeAlias = vector:9; |
| alias MyTypeAlias = vector:9; |
| |
| union MyUnion { // super annoying! |
| 1: string? s; |
| }; |
| |
| union MyExplicitUnion { |
| 1: string? s; |
| 2: reserved; |
| 3: int32 y; |
| 4: reserved; |
| }; |
| |
| flexible union MyXUnion { // super annoying! |
| 1: string? s; |
| }; |
| |
| flexible union MyExplicitXUnion { |
| 4: reserved; |
| 2: reserved; |
| 1: string? s; |
| 3: int32 y; |
| }; |
| |
| union MyUnion { |
| 1: string default_value = "Default Value"; |
| }; |
| |
| /// Doc comments |
| /// of multiple |
| /// lines |
| struct Foo { |
| request<Iface>? nullable_request; |
| vector<zx.handle:CHANNEL> monoid; |
| vector<zx.handle:CHANNEL> drahvin; |
| }; |
| |
| /// Cool new service |
| // align me too |
| service SomeService { |
| [ShouldNotCareAboutTypeAtParsingStage] |
| vector<zx.handle:CHANNEL> drahvin; |
| }; |
| |
| table Table1 { |
| 1: int64 x; |
| 2: int64 y; |
| }; |
| |
| table Table2 { |
| 3: reserved; |
| 2: int64 x; |
| 1: int64 y; |
| }; |
| |
| table Table3 { |
| /// Multiline |
| /// doc comments should |
| 1: int64 indent_correctly; |
| }; |
| |
| table Table4 { |
| 1: int64 default = 0; |
| }; |
| |
| // This { should } not be indented |
| // My protocol is so wonderful. |
| // It is the most wonderful protocol of them all. |
| [Discoverable] |
| protocol PCol |
| { |
| Foo() |
| -> (int i); |
| |
| [Awesome] |
| Analyze(zx.handle:PROCESS process, zx.handle:THREAD thread) |
| -> (); |
| |
| // Figure it out. |
| -> Bar(int32 i, int32 k); |
| Baz(int32 j, string k) -> (int32 y); |
| Nimon(int32 j, string k) |
| -> (int32 y); |
| |
| Mandrel(int32 j, string k) |
| -> (int32 y); |
| |
| Skagra(int32 j, |
| |
| // Weird comment in the middle |
| |
| string k) |
| -> (int32 y); |
| |
| Cat(string? s) -> (bool b); |
| Karfel( |
| int32 x) -> (int y); |
| |
| Gavrok // ( heh heh -> |
| (// ( An annoying comment. |
| int a, int b) -> (); |
| |
| -> Goo(int32 p, string:32 s); |
| Baz(int32 j, string:40 k |
| ) -> (int32 y); |
| SomeMethodWithAResponse() -> (); |
| |
| // A comment that isn't so annoying |
| MethodResponse(int a, int b, string:40 c, |
| int d, int e) -> (int f, int g, |
| int h); |
| |
| MethodResponse2() |
| -> (); |
| |
| MethodResponse3(int64 a) |
| -> (); |
| |
| JustPlainNoOrdinal() -> (); |
| |
| // Comment and |
| NoOrdinal(int64 i) -> (string s); |
| |
| /// Doc Comment and |
| [Attribute] |
| -> End(); |
| |
| /// Multiple |
| /// Doc Comments and |
| [Attribute] |
| -> End(); |
| |
| -> End(); |
| -> End(); |
| |
| // and now, the error syntax |
| MethodWithAnError() -> (int32 a) error uint32; |
| |
| // and now, for something completely different. |
| // the error syntax. |
| MethodWithAZxError() -> (int32 a) error zx.status; |
| |
| MethodWithAZxErrorNoReturn() -> () error zx.status; |
| }; |
| |
| // following example pulled from sample FIDL library |
| // which used to crash the formatter |
| const uint32 MAX_STRING_DESC_SIZE = 384; |
| |
| /// See GetStringDescriptor description below |
| [ForDeprecatedCBindings] |
| protocol Device { |
| }; |
| |
| /// POfMany! |
| protocol POfMany |
| { |
| |
| Before(); |
| |
| compose A; |
| Middle() -> (); |
| compose B; |
| |
| compose C; |
| |
| -> After(); |
| }; |
| |
| // Some multiline |
| // |
| // comment with blank lines |
| struct Hi { |
| }; |
| |
| protocol Example { |
| Method([Attribute1, Attribute2] uint32 name, |
| [Attribute = "value"] uint32 id, |
| [Attribute1, |
| Attribute2] uint32 id2, |
| unit32 id3) |
| -> (); |
| }; |
| |
| resource_definition SomeRes : uint32 { |
| properties { |
| Enum2 subtype; |
| }; |
| }; |
| |
| alias OldHandleAlias = zx.handle:VMO; |
| alias OldHandleAlias2 = zx.handle:THREAD; |
| alias MyOldHandleAlias = zx.handle:VMO; |
| alias MyOldHandleAlias2 = zx.handle:THREAD; |
| |
| struct Constraints { |
| zx.handle:THING1 h1; |
| zx.handle:<THING2> h2; |
| zx.handle:<THING2, zx.rights.TRANSFER | zx.rights.SIGNAL> h3; |
| }; |
| |
| alias HandleAlias = zx.handle:<THING3>; |
| alias MyHandleAlias = zx.handle:<THING3>; |
| |
| using HandleRightsAlias = zx.handle:<THING3, zx.rights.TRANSFER | zx.rights.SIGNAL>; |
| alias MyHandleRightsAlias = zx.handle:<THING3, zx.rights.TRANSFER | zx.rights.SIGNAL>; |
| |
| // Comments at EOF |