blob: 44c3fee446fcebc6cb912427dcfc8728c91a0f53 [file] [log] [blame]
// Copyright 2020 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 analysis
// Map from fully qualified name to type.kind, e.g.
// "fuchsia.hardware.camera/Device": "interface"
type decls map[string]string
type dependency struct {
Name LibraryName
Declarations decls
}
type location struct {
Filename string
Line, Column, Length int
}
type attribute struct {
Name string
Value string
}
type TypeKind string
const (
ArrayType TypeKind = "array"
VectorType = "vector"
StringType = "string"
HandleType = "handle"
RequestType = "request"
PrimitiveType = "primitive"
IdentifierType = "identifier"
)
type elementType struct {
Kind string
Identifier string `json:"identifier,omitempty"`
Subtype string `json:"subtype,omitempty"`
}
type typeCtor struct {
Name string
Args []typeCtor
}
type declType struct {
Kind TypeKind
ElementType elementType `json:"element_type,omitempty"`
Identifier string `json:"identifier,omitempty"`
Subtype string `json:"subtype,omitempty"`
}
type member struct {
Name string
Loc location `json:"location"`
Type declType `json:"type,omitempty"`
FromTypeAlias typeCtor `json:"experimental_maybe_from_type_alias,omitempty"`
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
type method struct {
Name string
Loc location `json:"location"`
MaybeRequest []member
MaybeResponse []member
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
type bitsDecl struct {
Name string
Loc location `json:"location"`
Type declType
FromTypeAlias typeCtor `json:"experimental_maybe_from_type_alias,omitempty"`
Attrs []attribute `json:"maybe_attributes,omitempty"`
Members []member
}
type enumDecl struct {
Name string
Loc location `json:"location"`
// For some reason, Bits have a full type in the JSON IR, while enums have
// a string
Type string
FromTypeAlias typeCtor `json:"experimental_maybe_from_type_alias,omitempty"`
Attrs []attribute `json:"maybe_attributes,omitempty"`
Members []member
}
type constDecl struct {
Name string
Loc location `json:"location"`
Type declType
FromTypeAlias typeCtor `json:"experimental_maybe_from_type_alias,omitempty"`
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
type protocolDecl struct {
Name string
Loc location `json:"location"`
Methods []method
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
type serviceDecl struct {
Name string
Loc location `json:"location"`
Members []member
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
type structDecl struct {
Name string
Loc location `json:"location"`
Members []member
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
type tableDecl struct {
Name string
Loc location `json:"location"`
Members []member
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
type unionDecl struct {
Name string
Loc location `json:"location"`
Members []member
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
type typeAliasDecl struct {
Name string
Loc location `json:"location"`
TypeCtor typeCtor `json:"partial_type_ctor"`
Attrs []attribute `json:"maybe_attributes,omitempty"`
}
// TODO: rename to FidlJSONIR, or JSONLibrary?
// FidlLibrary is the type of the deserialized JSON IR of a FIDL library.
type FidlLibrary struct {
Version string
Name string
Deps []dependency `json:"library_dependencies"`
BitsDecls []bitsDecl `json:"bits_declarations"`
ConstDecls []constDecl `json:"const_declarations"`
EnumDecls []enumDecl `json:"enum_declarations"`
ProtocolDecls []protocolDecl `json:"interface_declarations"`
ServiceDecls []serviceDecl `json:"service_declarations"`
StructDecls []structDecl `json:"struct_declarations"`
TableDecls []tableDecl `json:"table_declarations"`
UnionDecls []unionDecl `json:"union_declarations"`
TypeAliasDecls []typeAliasDecl `json:"type_alias_declarations"`
Decls decls `json:"declarations"`
}