| {{/* |
| * Copyright (C) 2015 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */}} |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the fully qualified name (prefixed with the package) of the specified |
| type or variable. |
| |
| Single argument: |
| The name to fully qualify |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "Go.RPC.QualifiedName"}} |
| {{AssertType $ "string"}} |
| |
| {{Global "module"}}{{$}} |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Verifies that the field is not a direct reference to an interface type. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "VerifyInterfaceFieldIsRef"}} |
| {{AssertType $.Field "Field"}} |
| {{AssertType $.Class "Class"}} |
| |
| {{$c := TypeOf $.Field}} |
| {{if IsClass $c}} |
| {{if (GetAnnotation $c "Interface")}} |
| {{Error $.Name "." $.Field.Name " is a non-reference to interface type " $c.Name ". This must be stored as ref<" $c.Name ">."}} |
| {{end}} |
| {{end}} |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Verifies that the parameter is not a direct reference to an interface type. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "VerifyInterfaceParameterIsRef"}} |
| {{AssertType $.Parameter "Parameter"}} |
| {{AssertType $.Command "Function"}} |
| |
| {{$c := TypeOf $.Parameter}} |
| {{if IsClass $c}} |
| {{if (GetAnnotation $c "Interface")}} |
| {{Error $.Command.Name " parameter " $.Parameter.Name " is a non-reference to interface type " $c.Name ". This must be passed as ref<" $c.Name ">."}} |
| {{end}} |
| {{end}} |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Verifies that the return type of a command is not a direct reference to an |
| interface type. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "VerifyInterfaceReturnTypeIsRef"}} |
| {{AssertType $ "Function"}} |
| |
| {{if IsClass $.Return.Type}} |
| {{if (GetAnnotation $.Return.Type "Interface")}} |
| {{Error $.Name " return value is a non-reference to interface type " $.Return.Type.Name ". This must be passed as ref<" $.Return.Type.Name ">."}} |
| {{end}} |
| {{end}} |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the go type for the provided AST type. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "Type"}} |
| {{AssertType $ "Type"}} |
| |
| {{ if IsSlice $}}{{Macro "ArrayType" $.To}} |
| {{else if GetAnnotation $ "handle"}}{{Macro "Go.RPC.QualifiedName" $.Name}} |
| {{else if IsAny $}}interface{} |
| {{else if IsMap $}}{{Macro "Go.RPC.QualifiedName" $.Name}} |
| {{else if IsClass $}}{{Macro "Go.RPC.QualifiedName" $.Name}} |
| {{else if IsPointer $}}{{if not (GetAnnotation $.To "Interface")}}*{{end}}{{Macro "Go.RPC.QualifiedName" $.To.Typename}} |
| {{else if IsEnum $}}{{Macro "Go.RPC.QualifiedName" $.Name}} |
| {{else if IsBool $}}bool |
| {{else if IsS8 $}}int8 |
| {{else if IsU8 $}}uint8 |
| {{else if IsS16 $}}int16 |
| {{else if IsU16 $}}uint16 |
| {{else if IsS32 $}}int32 |
| {{else if IsU32 $}}uint32 |
| {{else if IsF32 $}}float32 |
| {{else if IsS64 $}}int64 |
| {{else if IsU64 $}}uint64 |
| {{else if IsF64 $}}float64 |
| {{else if IsString $}}string |
| {{else}}{{Error "macro Type called with unsupported type: %v (%T)" $.Name $.Detail}} |
| {{end}} |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits the go type for the provided AST type. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "ArrayType"}} |
| {{ if IsBool $}}{{Macro "Go.RPC.QualifiedName" "BoolArray"}} |
| {{else if IsS8 $}}{{Macro "Go.RPC.QualifiedName" "S8Array"}} |
| {{else if IsU8 $}}{{Macro "Go.RPC.QualifiedName" "U8Array"}} |
| {{else if IsS16 $}}{{Macro "Go.RPC.QualifiedName" "S16Array"}} |
| {{else if IsU16 $}}{{Macro "Go.RPC.QualifiedName" "U16Array"}} |
| {{else if IsS32 $}}{{Macro "Go.RPC.QualifiedName" "I32Array"}} |
| {{else if IsU32 $}}{{Macro "Go.RPC.QualifiedName" "U32Array"}} |
| {{else if IsF32 $}}{{Macro "Go.RPC.QualifiedName" "F32Array"}} |
| {{else if IsS64 $}}{{Macro "Go.RPC.QualifiedName" "S64Array"}} |
| {{else if IsU64 $}}{{Macro "Go.RPC.QualifiedName" "U64Array"}} |
| {{else if IsF64 $}}{{Macro "Go.RPC.QualifiedName" "F64Array"}} |
| {{else if IsString $}}{{Macro "Go.RPC.QualifiedName" "StringArray"}} |
| {{else if IsPointer $}}{{Macro "Type" $.To}}PtrArray |
| {{else }}{{Macro "Type" $}}Array |
| {{end}} |
| {{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits a comment stating that the file is automatically generated. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "GeneratedHeader"}}{{Copyright "generated_by" "rpcapi"}}ΒΆ{{end}} |
| |
| |
| {{/* |
| ------------------------------------------------------------------------------- |
| Emits a comment block containing the specified text. |
| ------------------------------------------------------------------------------- |
| */}} |
| {{define "CommentHeader"}} |
| //////////////////////////////////////////////////////////////////////////////// |
| // {{.}} |
| //////////////////////////////////////////////////////////////////////////////// |
| {{end}} |