| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| // Package base is a simple single-file test of vdl functionality. |
| package base |
| |
| type ( |
| NamedBool bool |
| NamedByte byte |
| NamedUint16 uint16 |
| NamedUint32 uint32 |
| NamedUint64 uint64 |
| NamedInt16 int16 |
| NamedInt32 int32 |
| NamedInt64 int64 |
| NamedFloat32 float32 |
| NamedFloat64 float64 |
| NamedComplex64 complex64 |
| NamedComplex128 complex128 |
| NamedString string |
| NamedEnum enum{A;B;C} |
| NamedArray [2]bool |
| NamedList []uint32 |
| NamedSet set[string] |
| NamedMap map[string]float32 |
| NamedStruct struct{A bool;B string;C int32} |
| NamedUnion union{A bool;B string;C int32} |
| ) |
| |
| type Scalars struct { |
| A0 bool |
| A1 byte |
| A2 uint16 |
| A3 uint32 |
| A4 uint64 |
| A5 int16 |
| A6 int32 |
| A7 int64 |
| A8 float32 |
| A9 float64 |
| A10 complex64 |
| A11 complex128 |
| A12 string |
| A13 error |
| A14 any |
| A15 typeobject |
| |
| B0 NamedBool |
| B1 NamedByte |
| B2 NamedUint16 |
| B3 NamedUint32 |
| B4 NamedUint64 |
| B5 NamedInt16 |
| B6 NamedInt32 |
| B7 NamedInt64 |
| B8 NamedFloat32 |
| B9 NamedFloat64 |
| B10 NamedComplex64 |
| B11 NamedComplex128 |
| B12 NamedString |
| B13 NamedEnum |
| B14 NamedUnion |
| } |
| |
| // These are all scalars that may be used as map or set keys. |
| type KeyScalars struct { |
| A0 bool |
| A1 byte |
| A2 uint16 |
| A3 uint32 |
| A4 uint64 |
| A5 int16 |
| A6 int32 |
| A7 int64 |
| A8 float32 |
| A9 float64 |
| A10 complex64 |
| A11 complex128 |
| A12 string |
| |
| B0 NamedBool |
| B1 NamedByte |
| B2 NamedUint16 |
| B3 NamedUint32 |
| B4 NamedUint64 |
| B5 NamedInt16 |
| B6 NamedInt32 |
| B7 NamedInt64 |
| B8 NamedFloat32 |
| B9 NamedFloat64 |
| B10 NamedComplex64 |
| B11 NamedComplex128 |
| B12 NamedString |
| } |
| |
| type ScalarsArray [2]Scalars |
| |
| type Composites struct { |
| A0 Scalars |
| A1 ScalarsArray |
| A2 []Scalars |
| A3 set[KeyScalars] |
| A4 map[string]Scalars |
| A5 map[KeyScalars][]map[string]complex128 |
| } |
| |
| type CompositesArray [2]Composites |
| |
| type CompComp struct { |
| A0 Composites |
| A1 CompositesArray |
| A2 []Composites |
| A3 map[string]Composites |
| A4 map[KeyScalars][]map[string]Composites |
| } |
| |
| // NestedArgs is defined before Args; that's allowed in regular Go, and also |
| // allowed in our vdl files. The compiler will re-order dependent types to ease |
| // code generation in other languages. |
| type NestedArgs struct { |
| Args Args |
| } |
| |
| // Args will be reordered to show up before NestedArgs in the generated output. |
| type Args struct { |
| A int32 |
| B int32 |
| } |
| |
| const ( |
| Cbool = true |
| Cbyte = byte(1) |
| Cint32 = int32(2) |
| Cint64 = int64(3) |
| Cuint32 = uint32(4) |
| Cuint64 = uint64(5) |
| Cfloat32 = float32(6) |
| Cfloat64 = float64(7) |
| CNamedBool = NamedBool(true) |
| CNamedStruct = NamedStruct{A:true, B: "test",} |
| Ccomplex64 = complex64(8+9i) |
| Ccomplex128 = complex128(10+11i) |
| Cstring = "foo" |
| Cenum = NamedEnum.A |
| Cunion = NamedUnion{A: true} |
| Carray = NamedArray{true, false} |
| Clist = []int32{1, 2, 3} |
| Cset = set[int32]{1, 2, 3} |
| cmap = map[int32]string{1: "A", 2: "B", 3: "C"} |
| Cargs = Args{1, 2} |
| |
| CScalars = Scalars{ |
| A0: true, |
| A1: 1, |
| A2: 2, |
| A3: 3, |
| A4: 4, |
| A5: 5, |
| A6: 6, |
| A7: 7, |
| A8: 8, |
| A9: 9, |
| A10: 10, |
| A11: 11, |
| A12: "abc", |
| A14: false, |
| A15: typeobject(bool), |
| |
| B0: true, |
| B1: 1, |
| B2: 2, |
| B3: 3, |
| B4: 4, |
| B5: 5, |
| B6: 6, |
| B7: 7, |
| B8: 8, |
| B9: 9, |
| B10: 10, |
| B11: 11, |
| B12: "abc", |
| B13: NamedEnum.B, |
| B14: NamedUnion{C: 123}, |
| } |
| |
| True = true |
| Foo = "foo" |
| Five = int32(5) |
| SixSquared = Six*Six |
| FiveSquared = Five*Five |
| Six = uint64(6) |
| |
| CTypeObject_bool = typeobject(bool) |
| CTypeObject_string = typeobject(string) |
| CTypeObject_bytes = typeobject([]byte) |
| CTypeObject_byte = typeobject(byte) |
| CTypeObject_uint16 = typeobject(uint16) |
| CTypeObject_int16 = typeobject(int16) |
| CTypeObject_float32 = typeobject(float32) |
| CTypeObject_complex64 = typeobject(complex64) |
| CTypeObject_enum = typeobject(NamedEnum) |
| CTypeObject_Array = typeobject(NamedArray) |
| CTypeObject_List = typeobject([]string) |
| CTypeObject_Set = typeobject(set[string]) |
| CTypeObject_Map = typeobject(map[string]int64) |
| CTypeObject_Struct = typeobject(Scalars) |
| CTypeObject_Union = typeobject(NamedUnion) |
| CTypeObject_TypeObject = typeobject(typeobject) |
| CTypeObject_Any = typeobject(any) |
| ) |
| |
| type ServiceA interface { |
| MethodA1() error |
| MethodA2(a int32, b string) (s string | error) |
| MethodA3(a int32) stream<_, Scalars> (s string | error) {"tag", Six} |
| MethodA4(a int32) stream<int32, string> error |
| } |
| |
| type ServiceB interface { |
| ServiceA |
| MethodB1(a Scalars, b Composites) (c CompComp | error) |
| } |
| |
| // Error definitions, which allow stable error-checking across different address |
| // spaces. |
| error ( |
| NoParams1() {"en":"en msg"} |
| NoParams2() {RetryRefetch, "en":"en msg", "fr":"fr msg"} |
| |
| WithParams1(x string, y int32) {"en":"en x={x} y={y}"} |
| WithParams2(x string, y int32) { |
| RetryRefetch, |
| "en":"en x={x} y={y}", |
| "fr":"fr y={y} x={x}", |
| } |
| |
| notExported(x string, y int32) {"en":"en x={x} y={y}"} |
| ) |