blob: f92b333ee393b2fa0b275e063b0e20d47c4b26bf [file] [log] [blame]
// 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.
package codegen
const headerTemplate = `
{{- define "Header" -}}
// WARNING: This file is machine generated by fidlgen.
#pragma once
{{ if IncludeProxiesAndStubs }}
#include "lib/fidl/cpp/internal/header.h"
{{- else }}
#include "lib/fidl/cpp/internal/natural_types_header.h"
{{- end }}
{{ $root := . -}}
{{ range .Headers -}}
#include <{{ . }}/{{ $root.IncludeStem }}.h>
{{ end -}}
{{ template "Header/NaturalTypes" . }}
{{ if IncludeProxiesAndStubs -}}
{{ template "Header/ProxiesAndStubs" . }}
{{- end }}
{{ end }}
{{- define "Header/NaturalTypes" }}
//
// Domain objects declarations (i.e. "natural types" in unified bindings).
//
{{- range .Library }}
namespace {{ . }} {
{{- end }}
{{ "" }}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Bits }}{{ template "BitsForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Enum }}{{ template "EnumForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Protocol }}{{ template "DispatchProtocolForwardDeclaration/NaturalTypes" . }}{{- end }}
{{- if Eq .Kind Kinds.Service }}{{ template "DispatchServiceForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Struct }}{{ template "StructForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Table }}{{ template "TableForwardDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Union }}{{ template "UnionForwardDeclaration" . }}{{- end }}
{{- end }}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Const }}{{ template "ConstDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Protocol }}{{ template "DispatchProtocolDeclaration/NaturalTypes" . }}{{- end }}
{{- if Eq .Kind Kinds.Struct }}{{ template "StructDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Table }}{{ template "TableDeclaration" . }}{{- end }}
{{- if Eq .Kind Kinds.Union }}{{ template "UnionDeclaration" . }}{{- end }}
{{- end }}
{{- range .LibraryReversed }}
} // namespace {{ . }}
{{- end }}
namespace fidl {
{{ "" }}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Bits }}{{ template "BitsTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Enum }}{{ template "EnumTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Struct }}{{ template "StructTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Table }}{{ template "TableTraits" . }}{{- end }}
{{- if Eq .Kind Kinds.Union }}{{ template "UnionTraits" . }}{{- end }}
{{- end -}}
} // namespace fidl
{{- end }}
{{- define "Header/ProxiesAndStubs" }}
//
// Proxies and stubs declarations
//
{{- range .Library }}
namespace {{ . }} {
{{- end }}
{{ "" }}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Protocol }}{{ template "DispatchProtocolForwardDeclaration/ProxiesAndStubs" . }}{{- end }}
{{- if Eq .Kind Kinds.Service }}{{ template "DispatchServiceForwardDeclaration" . }}{{- end }}
{{- end }}
{{- range .Decls }}
{{- if Eq .Kind Kinds.Protocol }}{{ template "DispatchProtocolDeclaration/ProxiesAndStubs" . }}{{- end }}
{{- if Eq .Kind Kinds.Service }}{{ template "DispatchServiceDeclaration" . }}{{- end }}
{{- end }}
{{- range .LibraryReversed }}
} // namespace {{ . }}
{{- end }}
{{- end }}
{{- define "DispatchProtocolForwardDeclaration/NaturalTypes" -}}
{{- range $transport, $_ := .Transports }}
{{- if eq $transport "Channel" -}}{{ template "ProtocolForwardDeclaration/NaturalTypes" $ }}{{- end }}
{{- end }}
{{- end -}}
{{- define "DispatchProtocolDeclaration/NaturalTypes" -}}
{{- range $transport, $_ := .Transports }}
{{- if eq $transport "Channel" -}}{{ template "ProtocolDeclaration/NaturalTypes" $ }}{{- end }}
{{- end }}
{{- end -}}
{{- define "DispatchProtocolForwardDeclaration/ProxiesAndStubs" -}}
{{- range $transport, $_ := .Transports }}
{{- if eq $transport "Channel" -}}{{ template "ProtocolForwardDeclaration/ProxiesAndStubs" $ }}{{- end }}
{{- end }}
{{- end -}}
{{- define "DispatchProtocolDeclaration/ProxiesAndStubs" -}}
{{- range $transport, $_ := .Transports }}
{{- if eq $transport "Channel" -}}{{ template "ProtocolDeclaration/ProxiesAndStubs" $ }}{{- end }}
{{- end }}
{{- end -}}
{{- define "DispatchServiceForwardDeclaration" -}}
{{- range $transport, $_ := .Transports }}
{{- if eq $transport "Channel" -}}{{ template "ServiceForwardDeclaration" $ }}{{- end }}
{{- end }}
{{- end }}
{{- define "DispatchServiceDeclaration" -}}
{{- range $transport, $_ := .Transports }}
{{- if eq $transport "Channel" -}}{{ template "ServiceDeclaration" $ }}{{- end }}
{{- end }}
{{- end }}
`