Documentation
¶
Overview ¶
Package ir defines the intermediate representation used by Protocompile.
This package provides both the IR, and the lowering machinery for that IR. The IR is intended to provide a richer and easier to manipulate structure compared to a FileDescriptorProto. This structure is used for name resolution, type checking, tag number validation, and other semantic operations.
Index ¶
- Constants
- func CanonicalizeFilePath(path string) string
- func DescriptorProtoBytes(file *File, options ...DescriptorOption) ([]byte, error)
- func DescriptorSetBytes(files []*File, options ...DescriptorOption) ([]byte, error)
- func GetRef[T ~id.Node[T, *File, Raw], Raw any](base *File, r Ref[T]) T
- func OptionTargets() iter.Seq[OptionTarget]
- type DescriptorOption
- type Element
- func (e Element) AST() ast.ExprAny
- func (e Element) AsBool() (value, ok bool)
- func (e Element) AsEnum() Member
- func (e Element) AsFloat() (float64, bool)
- func (e Element) AsInt() (int64, bool)
- func (e Element) AsMessage() MessageValue
- func (e Element) AsString() (string, bool)
- func (e Element) AsUInt() (uint64, bool)
- func (e Element) Field() Member
- func (e Element) IsZeroValue() bool
- func (e Element) Type() Type
- func (e Element) Value() Value
- func (e Element) ValueNodeIndex() int
- type ErrCycle
- type Extend
- type Feature
- type FeatureInfo
- func (f FeatureInfo) Default(edition syntax.Syntax) Value
- func (f FeatureInfo) Deprecated() syntax.Syntax
- func (f FeatureInfo) DeprecationWarning() string
- func (f FeatureInfo) Introduced() syntax.Syntax
- func (f FeatureInfo) IsDeprecated(in syntax.Syntax) bool
- func (f FeatureInfo) IsIntroduced(in syntax.Syntax) bool
- func (f FeatureInfo) IsRemoved(in syntax.Syntax) bool
- func (f FeatureInfo) Removed() syntax.Syntax
- type FeatureSet
- type File
- func (f *File) AST() *ast.File
- func (f *File) AllExtends() seq.Indexer[Extend]
- func (f *File) AllExtensions() seq.Indexer[Member]
- func (f *File) AllMembers() iter.Seq[Member]
- func (f *File) AllTypes() seq.Indexer[Type]
- func (f *File) Deprecated() Value
- func (f *File) Extends() seq.Indexer[Extend]
- func (f *File) Extensions() seq.Indexer[Member]
- func (f *File) FeatureSet() FeatureSet
- func (f *File) FindSymbol(fqn FullName) Symbol
- func (f *File) FromID(id uint64, want any) any
- func (f *File) ImportFor(that *File) Import
- func (f *File) Imports() seq.Indexer[Import]
- func (f *File) InternedPackage() intern.ID
- func (f *File) InternedPath() intern.ID
- func (f *File) IsDescriptorProto() bool
- func (f *File) Options() MessageValue
- func (f *File) Package() FullName
- func (f *File) Path() string
- func (f *File) Services() seq.Indexer[Service]
- func (f *File) Symbols() seq.Indexer[Symbol]
- func (f *File) Syntax() syntax.Syntax
- func (f *File) TransitiveImports() seq.Indexer[Import]
- func (f *File) Types() seq.Indexer[Type]
- type FullName
- func (n FullName) Absolute() bool
- func (n FullName) Append(names ...string) FullName
- func (n FullName) Components() iter.Seq[string]
- func (n FullName) First() string
- func (n FullName) IsIdent() bool
- func (n FullName) Name() string
- func (n FullName) Parent() FullName
- func (n FullName) ToAbsolute() FullName
- func (n FullName) ToRelative() FullName
- type Import
- type Importer
- type Member
- func (m Member) AST() ast.DeclDef
- func (m Member) AsTagRange() TagRange
- func (m Member) CanTarget(target OptionTarget) bool
- func (m Member) Container() Type
- func (m Member) Deprecated() Value
- func (m Member) Element() Type
- func (m Member) Extend() Extend
- func (m Member) FeatureInfo() FeatureInfo
- func (m Member) FeatureSet() FeatureSet
- func (m Member) FullName() FullName
- func (m Member) InternedFullName() intern.ID
- func (m Member) InternedJSONName() intern.ID
- func (m Member) InternedName() intern.ID
- func (m Member) InternedScope() intern.ID
- func (m Member) IsEnumValue() bool
- func (m Member) IsExtension() bool
- func (m Member) IsGroup() bool
- func (m Member) IsMap() bool
- func (m Member) IsMessageField() bool
- func (m Member) IsPacked() bool
- func (m Member) IsRepeated() bool
- func (m Member) IsSingular() bool
- func (m Member) IsSynthetic() bool
- func (m Member) IsUnicode() bool
- func (m Member) JSONName() string
- func (m Member) Name() string
- func (m Member) Number() int32
- func (m Member) Oneof() Oneof
- func (m Member) Options() MessageValue
- func (m Member) Parent() Type
- func (m Member) Presence() presence.Kind
- func (m Member) PseudoOptions() PseudoFields
- func (m Member) Scope() FullName
- func (m Member) Targets() iter.Seq[OptionTarget]
- func (m Member) TypeAST() ast.TypeAny
- type MessageValue
- func (v MessageValue) AsValue() Value
- func (v MessageValue) Concrete() MessageValue
- func (v MessageValue) Field(field Member) Value
- func (v MessageValue) Fields() iter.Seq[Value]
- func (v MessageValue) Marshal(buf []byte, r *report.Report) []byte
- func (v MessageValue) Type() Type
- func (v MessageValue) TypeURL() string
- type Method
- func (m Method) AST() ast.DeclDef
- func (m Method) Deprecated() Value
- func (m Method) FeatureSet() FeatureSet
- func (m Method) FullName() FullName
- func (m Method) Input() (ty Type, stream bool)
- func (m Method) InternedFullName() intern.ID
- func (m Method) InternedName() intern.ID
- func (m Method) Name() string
- func (m Method) Options() MessageValue
- func (m Method) Output() (ty Type, stream bool)
- func (m Method) Service() Service
- type Oneof
- func (o Oneof) AST() ast.DeclDef
- func (o Oneof) Container() Type
- func (o Oneof) FeatureSet() FeatureSet
- func (o Oneof) FullName() FullName
- func (o Oneof) Index() int
- func (o Oneof) InternedFullName() intern.ID
- func (o Oneof) InternedName() intern.ID
- func (o Oneof) Members() seq.Indexer[Member]
- func (o Oneof) Name() string
- func (o Oneof) Options() MessageValue
- func (o Oneof) Parent() Type
- type OptionTarget
- type PseudoFields
- type Ref
- type ReservedName
- type ReservedRange
- func (r ReservedRange) AST() ast.ExprAny
- func (r ReservedRange) AsTagRange() TagRange
- func (r ReservedRange) DeclAST() ast.DeclRange
- func (r ReservedRange) FeatureSet() FeatureSet
- func (r ReservedRange) ForExtensions() bool
- func (r ReservedRange) Options() MessageValue
- func (r ReservedRange) Range() (start, end int32)
- type Service
- func (s Service) AST() ast.DeclDef
- func (s Service) Deprecated() Value
- func (s Service) FeatureSet() FeatureSet
- func (s Service) FullName() FullName
- func (s Service) InternedFullName() intern.ID
- func (s Service) InternedName() intern.ID
- func (s Service) Methods() seq.Indexer[Method]
- func (s Service) Name() string
- func (s Service) Options() MessageValue
- type Session
- type Symbol
- func (s Symbol) AsMember() Member
- func (s Symbol) AsMethod() Method
- func (s Symbol) AsOneof() Oneof
- func (s Symbol) AsService() Service
- func (s Symbol) AsType() Type
- func (s Symbol) Definition() source.Span
- func (s Symbol) Deprecated() Value
- func (s Symbol) FeatureSet() FeatureSet
- func (s Symbol) FullName() FullName
- func (s Symbol) Import(in *File) Import
- func (s Symbol) InternedFullName() intern.ID
- func (s Symbol) Kind() SymbolKind
- func (s Symbol) Visible(in *File, allowOptions bool) bool
- type SymbolKind
- type TagRange
- type Type
- func (t Type) AST() ast.DeclDef
- func (t Type) AbsoluteRange() (start, end int32)
- func (t Type) AllRanges() seq.Indexer[ReservedRange]
- func (t Type) AllowsAlias() bool
- func (t Type) Deprecated() Value
- func (t Type) EntryFields() (key, value Member)
- func (t Type) Extends() seq.Indexer[Extend]
- func (t Type) ExtensionRanges() seq.Indexer[ReservedRange]
- func (t Type) Extensions() seq.Indexer[Member]
- func (t Type) FeatureSet() FeatureSet
- func (t Type) FullName() FullName
- func (t Type) InternedFullName() intern.ID
- func (t Type) InternedName() intern.ID
- func (t Type) InternedScope() intern.ID
- func (t Type) IsAny() bool
- func (t Type) IsClosedEnum() bool
- func (t Type) IsEnum() bool
- func (t Type) IsExported() (exported, explicit bool)
- func (t Type) IsMapEntry() bool
- func (t Type) IsMessage() bool
- func (t Type) IsMessageSet() bool
- func (t Type) IsPackable() bool
- func (t Type) IsPredeclared() bool
- func (t Type) MapField() Member
- func (t Type) MemberByInternedName(name intern.ID) Member
- func (t Type) MemberByName(name string) Member
- func (t Type) MemberByNumber(number int32) Member
- func (t Type) Members() seq.Indexer[Member]
- func (t Type) Name() string
- func (t Type) Nested() seq.Indexer[Type]
- func (t Type) OccupiedRanges() iter.Seq2[[2]int32, seq.Indexer[TagRange]]
- func (t Type) Oneofs() seq.Indexer[Oneof]
- func (t Type) Options() MessageValue
- func (t Type) Parent() Type
- func (t Type) Predeclared() predeclared.Name
- func (t Type) Ranges(number int32) iter.Seq[TagRange]
- func (t Type) ReservedNames() seq.Indexer[ReservedName]
- func (t Type) ReservedRanges() seq.Indexer[ReservedRange]
- func (t Type) Scope() FullName
- type Value
- func (v Value) AsBool() (value, ok bool)
- func (v Value) AsEnum() Member
- func (v Value) AsFloat() (float64, bool)
- func (v Value) AsInt() (int64, bool)
- func (v Value) AsMessage() MessageValue
- func (v Value) AsString() (string, bool)
- func (v Value) AsUInt() (uint64, bool)
- func (v Value) Container() MessageValue
- func (v Value) Elements() seq.Indexer[Element]
- func (v Value) Field() Member
- func (v Value) IsZeroValue() bool
- func (v Value) KeyAST() ast.ExprAny
- func (v Value) KeyASTs() seq.Indexer[ast.ExprAny]
- func (v Value) Marshal(buf []byte, r *report.Report) []byte
- func (v Value) OptionPaths() seq.Indexer[ast.Path]
- func (v Value) OptionSpan() source.Spanner
- func (v Value) OptionSpans() seq.Indexer[source.Spanner]
- func (v Value) ValueAST() ast.ExprAny
- func (v Value) ValueASTs() seq.Indexer[ast.ExprAny]
Constants ¶
const DescriptorProtoPath = "google/protobuf/descriptor.proto"
Variables ¶
This section is empty.
Functions ¶
func CanonicalizeFilePath ¶
CanonicalizeFilePath puts a file path into canonical form.
This function is exported so that all code depending on this module can make sure paths are consistently canonicalized.
func DescriptorProtoBytes ¶
func DescriptorProtoBytes(file *File, options ...DescriptorOption) ([]byte, error)
DescriptorProtoBytes generates a single FileDescriptorProto for file, and returns the result as an encoded byte slice.
The resulting FileDescriptorProto is fully linked: all names are fully-qualified.
func DescriptorSetBytes ¶
func DescriptorSetBytes(files []*File, options ...DescriptorOption) ([]byte, error)
DescriptorSetBytes generates a FileDescriptorSet for the given files, and returns the result as an encoded byte slice.
The resulting FileDescriptorSet is always fully linked: it contains all dependencies except the WKTs, and all names are fully-qualified.
func OptionTargets ¶
func OptionTargets() iter.Seq[OptionTarget]
OptionTargets returns an iterator over all of the possible valid targets, which excludes OptionTargetInvalid.
Types ¶
type DescriptorOption ¶
type DescriptorOption func(*descGenerator)
DescriptorOption is an option to pass to DescriptorSetBytes or DescriptorProtoBytes.
func ExcludeFiles ¶
func ExcludeFiles(exclude func(*File) bool) DescriptorOption
ExcludeFiles excludes the given files from the output of DescriptorSetBytes.
func IncludeSourceCodeInfo ¶
func IncludeSourceCodeInfo(flag bool) DescriptorOption
IncludeDebugInfo sets whether or not to include google.protobuf.SourceCodeInfo in the output.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element is an element within a Value.
This exists because array values contain multiple non-array elements; this type provides uniform access to such elements. See Value.Elements.
func (Element) AsBool ¶
AsBool returns the bool value of this element.
Returns ok == false if this is not a bool.
func (Element) AsEnum ¶
AsEnum returns the value of this element as a known enum value.
Returns zero if this is not an enum or if the enum value is out of range.
func (Element) AsFloat ¶
AsFloat returns the value of this element as a floating-point number.
Returns false if this is not a float.
func (Element) AsInt ¶
AsInt returns the value of this element as a signed integer.
Returns false if this is not a signed integer (enums are included as signed integers).
func (Element) AsMessage ¶
func (e Element) AsMessage() MessageValue
AsMessage returns the value of this element as a message literal.
Returns the zero value if this is not a message.
func (Element) AsString ¶
AsString returns the value of this element as a string.
Returns false if this is not a string.
func (Element) AsUInt ¶
AsUInt returns the value of this element as an unsigned integer.
Returns false if this is not an unsigned integer.
func (Element) Field ¶
Field returns the field this value sets, which includes the value's type information.
func (Element) IsZeroValue ¶
IsZeroValue returns whether this element contains the zero value for its type.
Always returns false for repeated or message-typed fields.
func (Element) Type ¶
Type returns the type of this element.
Note that this may be distinct from Member.Element. In the case that this is a google.protobuf.Any-typed field, this function will return the concrete type if known, rather than Any.
func (Element) ValueNodeIndex ¶
ValueNodeIndex returns the index into Value.ValueASTs for this element's contributing expression. This can be used to obtain other ASTs related to this element, e.g.
key := e.Value().MessageKeys().At(e.ValueNodeIndex())
If the element is empty, this returns -1.
type ErrCycle ¶
type ErrCycle = cycle.Error[ast.DeclImport]
ErrCycle is returned by an Importer when encountering an import cycle.
type Extend ¶
Extend represents an extend block associated with some extension field.
func (Extend) Extensions ¶
Extensions returns the extensions declared in this block.
func (Extend) InternedScope ¶
InternedScope returns the intern ID for Extend.Scope.
type Feature ¶
type Feature struct {
// contains filtered or unexported fields
}
Feature is a feature setting retrieved from a FeatureSet.
func (Feature) IsDefault ¶
IsDefault returns whether this feature was inherited from edition defaults. An explicit setting to the default will return false for this method.
func (Feature) IsExplicit ¶
IsExplicit returns whether this feature was set explicitly.
func (Feature) IsInherited ¶
IsInherited returns whether this feature value was inherited from its parent.
type FeatureInfo ¶
type FeatureInfo struct {
// contains filtered or unexported fields
}
FeatureInfo represents information about a message field being used as a feature. This corresponds to the edition_defaults and feature_support options on a field.
func (FeatureInfo) Default ¶
func (f FeatureInfo) Default(edition syntax.Syntax) Value
Default returns the default value for this feature.
func (FeatureInfo) Deprecated ¶
func (f FeatureInfo) Deprecated() syntax.Syntax
Deprecated returns whether this feature has been deprecated, and in which edition.
func (FeatureInfo) DeprecationWarning ¶
func (f FeatureInfo) DeprecationWarning() string
DeprecationWarning returns the literal text of the deprecation warning for this feature, if it has been deprecated.
func (FeatureInfo) Introduced ¶
func (f FeatureInfo) Introduced() syntax.Syntax
Introduced returns which edition this feature is first allowed in.
func (FeatureInfo) IsDeprecated ¶
func (f FeatureInfo) IsDeprecated(in syntax.Syntax) bool
IsDeprecated returns whether this feature has been deprecated yet.
func (FeatureInfo) IsIntroduced ¶
func (f FeatureInfo) IsIntroduced(in syntax.Syntax) bool
IsIntroduced returns whether this feature has been introduced yet.
func (FeatureInfo) IsRemoved ¶
func (f FeatureInfo) IsRemoved(in syntax.Syntax) bool
IsRemoved returns whether this feature has been removed yet.
func (FeatureInfo) Removed ¶
func (f FeatureInfo) Removed() syntax.Syntax
Removed returns whether this feature has been removed, and in which edition.
type FeatureSet ¶
type FeatureSet id.Node[FeatureSet, *File, *rawFeatureSet]
FeatureSet represents the Editions-mediated features of a particular declaration.
func (FeatureSet) Lookup ¶
func (fs FeatureSet) Lookup(field Member) Feature
Lookup looks up a feature with the given google.protobuf.FeatureSet member.
func (FeatureSet) LookupCustom ¶
func (fs FeatureSet) LookupCustom(extension, field Member) Feature
LookupCustom looks up a custom feature in the given extension's field.
func (FeatureSet) Options ¶
func (fs FeatureSet) Options() MessageValue
Options returns the value of the google.protobuf.FeatureSet message that this FeatureSet is built from.
func (FeatureSet) Parent ¶
func (fs FeatureSet) Parent() FeatureSet
Parent returns the feature set of the parent scope for this feature.
Returns zero if this is the feature set for the file.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is an IR file, which provides access to the top-level declarations of a Protobuf *File.
func (*File) AllExtends ¶
AllExtends returns all extend blocks in this file.
func (*File) AllExtensions ¶
AllExtensions returns all extensions defined in this file.
func (*File) AllMembers ¶
AllMembers returns all fields defined in this file, including extensions and enum values.
func (*File) Deprecated ¶
Deprecated returns whether this file is deprecated, by returning the relevant option value for setting deprecation.
func (*File) Extensions ¶
Extensions returns the top level extensions defined in this file (i.e., the contents of any top-level `extends` blocks).
func (*File) FeatureSet ¶
func (f *File) FeatureSet() FeatureSet
FeatureSet returns the Editions features associated with this file.
func (*File) FindSymbol ¶
FindSymbol finds a symbol among File.Symbols with the given fully-qualified name.
func (*File) ImportFor ¶
ImportFor returns import metadata for a given file, if this file imports it.
func (*File) InternedPackage ¶
InternedPackage returns the intern ID for the value of File.Package.
func (*File) InternedPath ¶
InternedPath returns the intern ID for the value of File.Path.
func (*File) IsDescriptorProto ¶
IsDescriptorProto returns whether this is the special file google/protobuf/descriptor.proto, which is given special treatment in the language.
func (*File) Options ¶
func (f *File) Options() MessageValue
Options returns the top level options applied to this file.
func (*File) Package ¶
Package returns the package name for this file.
The name will not include a leading dot. It will be empty for the empty package.
func (*File) Path ¶
Path returns the canonical path for this file.
This need not be the same as File.AST().Span().Path().
func (*File) Symbols ¶
Symbols returns this file's symbol table.
The symbol table includes both symbols defined in this file, and symbols imported by the file. The symbols are returned in an arbitrary but fixed order.
func (*File) TransitiveImports ¶
TransitiveImports returns an indexer over the transitive imports for this file.
This function does not report whether those imports are weak or not.
type FullName ¶
type FullName string
FullName is a fully-qualified Protobuf name, which is a dot-separated list of identifiers, with an optional dot prefix.
This is a helper type for common operations on such names. This is essentially protoreflect.FullName, without depending on protoreflect. Unlike protoreflect, we do not provide validation methods.
func (FullName) Absolute ¶
Absolute returns whether this is an absolute name, i.e., has a leading dot.
func (FullName) Append ¶
Append returns a name with the given component(s) appended.
If this is an empty name, the resulting name will not be absolute.
func (FullName) Components ¶
Components returns an iterator over the components of this name.
If there are adjacent dots, e.g. foo..bar, this will yield an empty string within the name.
func (FullName) Parent ¶
Parent returns the name of the parent entity for this name.
If the name only has one component, returns the zero value. In particular, the parent of ".foo" is "".
func (FullName) ToAbsolute ¶
ToAbsolute returns this name with a leading dot.
func (FullName) ToRelative ¶
ToRelative returns this name without a leading dot.
type Import ¶
type Import struct {
*File // The file that is imported.
// The kind of import this is.
Public, Weak, Option bool
Direct bool // Whether this is a direct or transitive import.
Visible bool // Whether this import's symbols are visible in the current file.
Used bool // Whether this import has been marked as used.
Decl ast.DeclImport // The import declaration.
}
Import is an import in a File.
type Importer ¶
Importer is a callback to resolve the imports of an ast.File being lowered.
If a cycle is encountered, should return an *[incremental.ErrCycle], starting from decl and ending when the currently lowered file is imported.
Session.Lower may not call this function on all imports; only those for which it needs the caller to resolve a File for it.
This function will also be called with DescriptorProtoPath if it isn't transitively imported by the lowered file, with an index value of -1. Returning an error or a zero file will trigger an ICE.
type Member ¶
Member is a Protobuf message field, enum value, or extension field.
A member has three types associated with it. The English language struggles to give these succinct names, so we review them here.
Its _element_, i.e. the type it contains. This is the type that a member is declared to be _of_. Not present for enum values.
Its _parent_, i.e., the type it is syntactically defined within. Extensions appear syntactically within their parent.
Its _container_, i.e., the type which it is part of for the purposes of serialization. Extensions are fields of their container, but are declared within their parent.
func (Member) AsTagRange ¶
AsTagRange wraps this member in a TagRange.
func (Member) CanTarget ¶
func (m Member) CanTarget(target OptionTarget) bool
CanTarget returns whether this message field can be set as an option for the given option target type.
This is mediated by the option FieldOptions.targets, which controls whether this field can be set (transitively) on the options of a given entity type. This is useful for options which re-use the same message type for different option types, such as FeatureSet.
func (Member) Container ¶
Container returns the type which contains this member: this is either Member.Parent, or the extendee if this is an extension. This is the type it is declared to be *part of*.
func (Member) Deprecated ¶
Deprecated returns whether this member is deprecated, by returning the relevant option value for setting deprecation.
func (Member) Element ¶
Element returns the this member's element type. This is the type it is declared to be *of*, such as in the phrase "a string field's type is string".
This does not include the member's presence: for example, a repeated int32 member will report the type as being the int32 primitive, not an int32 array.
This is zero for enum values.
func (Member) FeatureInfo ¶
func (m Member) FeatureInfo() FeatureInfo
FeatureInfo returns feature definition information relating to this field (for when using this field as a feature).
Returns a zero value if this information does not exist.
func (Member) FeatureSet ¶
func (m Member) FeatureSet() FeatureSet
FeatureSet returns the Editions features associated with this member.
func (Member) InternedFullName ¶
InternedFullName returns the intern ID for Member.FullName.
func (Member) InternedJSONName ¶
InternedJSONName returns the intern ID for Member.JSONName.
func (Member) InternedName ¶
InternedName returns the intern ID for Member.FullName().Name().
func (Member) InternedScope ¶
InternedScope returns the intern ID for Member.Scope.
func (Member) IsEnumValue ¶
IsEnumValue returns whether this is an enum value.
func (Member) IsExtension ¶
IsExtension returns whether this is a extension message field.
func (Member) IsMessageField ¶
IsMessageField returns whether this is a non-extension message field.
func (Member) IsRepeated ¶
IsRepeated returns whether this is a repeated field; this includes map fields.
func (Member) IsSingular ¶
IsSingular returns whether this is a singular field; this includes oneof members.
func (Member) IsSynthetic ¶
IsSynthetic returns whether or not this is a synthetic field, such as the fields of a map entry.
func (Member) IsUnicode ¶
IsUnicode returns whether this is a string-typed message field that must contain UTF-8 bytes.
func (Member) JSONName ¶
JSONName returns this member's JSON name, either the default-generated one or the one set via the json_name pseudo-option.
func (Member) Number ¶
Number returns the number for this member after expression evaluation.
Defaults to zero if the number is not specified.
func (Member) Oneof ¶
Oneof returns the oneof that this member is a member of.
Returns the zero value if this member does not have presence.Shared.
func (Member) Options ¶
func (m Member) Options() MessageValue
Options returns the options applied to this member.
func (Member) Parent ¶
Parent returns the type this member is syntactically located in. This is the type it is declared *in*, but which it is not necessarily part of.
May be zero for extensions declared at the top level.
func (Member) Presence ¶
Presence returns this member's presence kind.
Returns presence.Unknown for enum values.
func (Member) PseudoOptions ¶
func (m Member) PseudoOptions() PseudoFields
PseudoOptions returns this member's pseudo options.
type MessageValue ¶
type MessageValue id.Node[MessageValue, *File, *rawMessageValue]
MessageValue is a message literal, represented as a list of ordered key-value pairs.
func (MessageValue) AsValue ¶
func (v MessageValue) AsValue() Value
AsValue returns the Value corresponding to this message.
This value can be used to retrieve the associated Member and from it the message's declared Type.
func (MessageValue) Concrete ¶
func (v MessageValue) Concrete() MessageValue
Concrete returns the concrete version of this value if it is an Any.
If it isn't an Any, or a .Raw()" Any (one not specified with the special type URL syntax), this returns v.
func (MessageValue) Field ¶
func (v MessageValue) Field(field Member) Value
Field returns the field corresponding with the given member, if it is set.
func (MessageValue) Fields ¶
func (v MessageValue) Fields() iter.Seq[Value]
Fields yields the fields within this message literal, in insertion order.
func (MessageValue) Marshal ¶
func (v MessageValue) Marshal(buf []byte, r *report.Report) []byte
Marshal serializes this message as wire format and appends it to buf.
If r is not nil, it will be used to record diagnostics generated during the marshal operation.
func (MessageValue) Type ¶
func (v MessageValue) Type() Type
Type returns this value's message type.
If v was returned from MessageValue.Concrete, its type need not be the same as v.AsValue()'s (although it can be, in the case of pathological Any-within-an-Any messages).
func (MessageValue) TypeURL ¶
func (v MessageValue) TypeURL() string
TypeURL returns this value's type URL, if it is the concrete value of an Any.
type Method ¶
Method is a Protobuf service method.
func (Method) Deprecated ¶
Deprecated returns whether this service is deprecated, by returning the relevant option value for setting deprecation.
func (Method) FeatureSet ¶
func (m Method) FeatureSet() FeatureSet
FeatureSet returns the Editions features associated with this method.
func (Method) Input ¶
Input returns the input type for this method, and whether it is a streaming input.
func (Method) InternedFullName ¶
InternedFullName returns the intern ID for Method.FullName.
func (Method) InternedName ¶
InternedName returns the intern ID for Method.FullName().Name().
func (Method) Name ¶
Name returns this method's declared name, i.e. the last component of its full name.
func (Method) Options ¶
func (m Method) Options() MessageValue
Options returns the options applied to this method.
type Oneof ¶
Oneof represents a oneof within a message definition.
func (Oneof) FeatureSet ¶
func (o Oneof) FeatureSet() FeatureSet
FeatureSet returns the Editions features associated with this oneof.
func (Oneof) InternedFullName ¶
InternedFullName returns the intern ID for Oneof.FullName.
func (Oneof) InternedName ¶
InternedName returns the intern ID for Oneof.FullName().Name().
func (Oneof) Options ¶
func (o Oneof) Options() MessageValue
Options returns the options applied to this oneof.
type OptionTarget ¶
type OptionTarget int32
OptionTarget is target for an Editions feature, corresponding to google.protobuf.FieldOptions.OptionTargetType. The values of this enum match those in descriptor.proto one-to-one.
const ( OptionTargetInvalid OptionTarget = iota OptionTargetFile OptionTargetRange OptionTargetMessage OptionTargetField OptionTargetOneof OptionTargetEnum OptionTargetEnumValue OptionTargetService OptionTargetMethod )
func (OptionTarget) GoString ¶
func (v OptionTarget) GoString() string
GoString implements fmt.GoStringer.
type PseudoFields ¶
PseudoFields contains pseudo options, which are special option-like syntax for fields which are not real options. They can be accessed via [Message.PseudoFields].
type Ref ¶
type Ref[T any] struct { // contains filtered or unexported fields }
Ref is a reference in a Protobuf file: an id.ID along with information for retrieving which file that ID is for, relative to the referencing file's context.
The context needed for resolving a ref is called its "base context", which the user is expected to keep track of.
func (Ref[T]) ChangeContext ¶
ChangeContext changes the implicit context for this ref to be with respect to the new one given.
type ReservedName ¶
type ReservedName struct {
// contains filtered or unexported fields
}
ReservedName is a name for a field or enum value that has been reserved for future use.
func (ReservedName) AST ¶
func (r ReservedName) AST() ast.ExprAny
AST returns the expression that this name was evaluated from, if known.
func (ReservedName) InternedName ¶
func (r ReservedName) InternedName() intern.ID
InternedName returns the intern ID for ReservedName.Name.
func (ReservedName) Name ¶
func (r ReservedName) Name() string
Name returns the name (i.e., an identifier) that was reserved.
type ReservedRange ¶
type ReservedRange id.Node[ReservedRange, *File, *rawReservedRange]
ReservedRange is a range of reserved field or enum numbers, either from a reserved or extensions declaration.
func (ReservedRange) AST ¶
func (r ReservedRange) AST() ast.ExprAny
AST returns the expression that this range was evaluated from, if known.
func (ReservedRange) AsTagRange ¶
func (r ReservedRange) AsTagRange() TagRange
AsTagRange wraps this range in a TagRange.
func (ReservedRange) DeclAST ¶
func (r ReservedRange) DeclAST() ast.DeclRange
DeclAST returns the declaration this range came from. Multiple ranges may have the same declaration.
func (ReservedRange) FeatureSet ¶
func (r ReservedRange) FeatureSet() FeatureSet
FeatureSet returns the Editions features associated with this file.
func (ReservedRange) ForExtensions ¶
func (r ReservedRange) ForExtensions() bool
ForExtensions returns whether this is an extension range.
func (ReservedRange) Options ¶
func (r ReservedRange) Options() MessageValue
Options returns the options applied to this range.
Reserved ranges cannot carry options; only extension ranges do.
func (ReservedRange) Range ¶
func (r ReservedRange) Range() (start, end int32)
Range returns the start and end of the range.
type Service ¶
Service is a Protobuf service definition.
func (Service) Deprecated ¶
Deprecated returns whether this service is deprecated, by returning the relevant option value for setting deprecation.
func (Service) FeatureSet ¶
func (s Service) FeatureSet() FeatureSet
FeatureSet returns the Editions features associated with this service.
func (Service) InternedFullName ¶
InternedFullName returns the intern ID for Service.FullName.
func (Service) InternedName ¶
InternedName returns the intern ID for Service.FullName().Name().
func (Service) Name ¶
Name returns this service's declared name, i.e. the last component of its full name.
func (Service) Options ¶
func (s Service) Options() MessageValue
Options returns the options applied to this service.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is shared global configuration and state for all IR values that are being used together.
It is used to track shared book-keeping.
A zero Session is ready to use.
type Symbol ¶
Symbol is an entry in a File's symbol table.
[Symbol.Context] returns the context for the file which imported this symbol. To map this to the context in which the symbol was defined, use [Symbol.InDefFile].
func (Symbol) Definition ¶
Definition returns a span for the definition site of this symbol; specifically, this is (typically) just an identifier.
func (Symbol) Deprecated ¶
Deprecated returns whether this symbol is deprecated, but returning the relevant option value for setting deprecation.
Note that although files can be marked as deprecated, packages cannot, so package symbols never show up as deprecated.
func (Symbol) FeatureSet ¶
func (s Symbol) FeatureSet() FeatureSet
FeatureSet returns the features associated with this symbol.
func (Symbol) Import ¶
Import returns the import declaration that brought this symbol into scope in the given file.
Returns zero if s is defined in the current file or if s is not imported by in.
func (Symbol) InternedFullName ¶
InternedFullName returns the intern ID for Symbol.FullName.
type SymbolKind ¶
type SymbolKind int8
SymbolKind is a kind of symbol, i.e. an IR entity that defines a fully-qualified name.
const ( SymbolKindInvalid SymbolKind = iota SymbolKindPackage SymbolKindScalar SymbolKindMessage SymbolKindEnum SymbolKindField SymbolKindEnumValue SymbolKindExtension SymbolKindOneof SymbolKindService SymbolKindMethod )
func (SymbolKind) GoString ¶
func (v SymbolKind) GoString() string
GoString implements fmt.GoStringer.
func (SymbolKind) IsMember ¶
func (k SymbolKind) IsMember() bool
IsMember returns whether this is a field's symbol kind. This includes enum values, which the ir package treats as fields of enum types.
func (SymbolKind) IsMessageField ¶
func (k SymbolKind) IsMessageField() bool
IsMessageField returns whether this is a field's symbol kind.
func (SymbolKind) IsScope ¶
func (k SymbolKind) IsScope() bool
IsScope returns whether this is a symbol that defines a scope, for the purposes of name lookup.
func (SymbolKind) IsType ¶
func (k SymbolKind) IsType() bool
IsType returns whether this is a type's symbol kind.
func (SymbolKind) OptionTarget ¶
func (k SymbolKind) OptionTarget() OptionTarget
OptionTarget returns the OptionTarget type for a symbol of this kind.
Returns OptionTargetInvalid if there is no corresponding target for this type of symbol.
type TagRange ¶
type TagRange struct {
// contains filtered or unexported fields
}
TagRange is a range of tag numbers in a Type.
This can represent either a Member or a ReservedRange.
func (TagRange) AsMember ¶
AsMember returns the Member this range points to, or zero if it isn't a member.
func (TagRange) AsReserved ¶
func (r TagRange) AsReserved() ReservedRange
AsReserved returns the ReservedRange this range points to, or zero if it isn't a member.
type Type ¶
Type is a Protobuf message field type.
func PredeclaredType ¶
func PredeclaredType(n predeclared.Name) Type
PredeclaredType returns the type corresponding to a predeclared name.
Returns the zero value if !n.IsScalar().
func (Type) AST ¶
AST returns the declaration for this type, if known.
This need not be an ast.DefMessage or ast.DefEnum; it may be something else in the case of e.g. a map field's entry type.
func (Type) AbsoluteRange ¶
AbsoluteRange returns the smallest and largest number a member of this type can have.
This range is inclusive.
func (Type) AllRanges ¶
func (t Type) AllRanges() seq.Indexer[ReservedRange]
AllRanges returns all reserved/extension ranges declared in this type.
This does not include reserved field names; see Type.ReservedNames.
func (Type) AllowsAlias ¶
AllowsAlias returns whether this is an enum type with the allow_alias option set.
func (Type) Deprecated ¶
Deprecated returns whether this type is deprecated, by returning the relevant option value for setting deprecation.
func (Type) EntryFields ¶
EntryFields returns the key and value fields for this map entry type.
func (Type) ExtensionRanges ¶
func (t Type) ExtensionRanges() seq.Indexer[ReservedRange]
ExtensionRanges returns the extension ranges declared in this type.
func (Type) Extensions ¶
Extensions returns any extensions nested within this type.
func (Type) FeatureSet ¶
func (t Type) FeatureSet() FeatureSet
FeatureSet returns the Editions features associated with this type.
func (Type) FullName ¶
FullName returns this type's fully-qualified name.
If t is zero, returns "". Otherwise, the returned name will be absolute unless this is a primitive type.
func (Type) InternedFullName ¶
InternedName returns the intern ID for Type.FullName
Predeclared types do not have an interned name.
func (Type) InternedName ¶
InternedName returns the intern ID for Type.FullName().Name()
Predeclared types do not have an interned name.
func (Type) InternedScope ¶
InternedScope returns the intern ID for Type.Scope
Predeclared types do not have an interned name.
func (Type) IsAny ¶
IsAny returns whether this is the type google.protobuf.Any, which gets special treatment in the language.
func (Type) IsClosedEnum ¶
func (Type) IsExported ¶
IsExported returns whether this type is exported for the purposes of visibility in other files.
Returns whether this was set explicitly via the export or local keywords.
func (Type) IsMapEntry ¶
IsMapEntry returns whether this is a map type's entry.
func (Type) IsMessageSet ¶
IsMessageSet returns whether this is a message type using the message set encoding.
func (Type) IsPackable ¶
IsPackable returns whether this type can be the element of a packed repeated field.
func (Type) IsPredeclared ¶
IsPredeclared returns whether this is a predeclared type.
func (Type) MemberByInternedName ¶
MemberByInternedName is like Type.MemberByName, but takes an interned string.
func (Type) MemberByName ¶
MemberByName looks up a member with the given name.
Returns a zero member if there is no such member.
func (Type) MemberByNumber ¶
MemberByNumber looks up a member with the given number.
Returns a zero member if there is no such member.
func (Type) Members ¶
Members returns the members of this type.
Predeclared types have no members; message and enum types do.
func (Type) Name ¶
Name returns this type's declared name, i.e. the last component of its full name.
func (Type) Nested ¶
Nested returns those types which are nested within this one.
Only message types have nested types.
func (Type) OccupiedRanges ¶
OccupiedRanges returns ranges of member numbers currently in use in this type. The pairs of numbers are inclusive ranges.
func (Type) Options ¶
func (t Type) Options() MessageValue
Options returns the options applied to this type.
func (Type) Parent ¶
Parent returns the type that this type is declared inside of, if it isn't at the top level.
func (Type) Predeclared ¶
func (t Type) Predeclared() predeclared.Name
Predeclared returns the predeclared type that this Type corresponds to, if any.
Returns either predeclared.Unknown or a value such that predeclared.Name.IsScalar returns true. For example, this will *not* return predeclared.Map for map fields.
func (Type) ReservedNames ¶
func (t Type) ReservedNames() seq.Indexer[ReservedName]
ReservedNames returns the reserved named declared in this type.
func (Type) ReservedRanges ¶
func (t Type) ReservedRanges() seq.Indexer[ReservedRange]
ReservedRanges returns the reserved ranges declared in this type.
This does not include reserved field names; see Type.ReservedNames.
type Value ¶
Value is an evaluated expression, corresponding to an option in a Protobuf file.
func (Value) AsBool ¶
AsBool is a shortcut for Element.AsBool, if this value is singular.
func (Value) AsEnum ¶
AsEnum is a shortcut for Element.AsEnum, if this value is singular.
func (Value) AsFloat ¶
AsFloat is a shortcut for Element.AsFloat, if this value is singular.
func (Value) AsInt ¶
AsInt is a shortcut for Element.AsInt, if this value is singular.
func (Value) AsMessage ¶
func (v Value) AsMessage() MessageValue
AsMessage is a shortcut for Element.AsMessage, if this value is singular.
func (Value) AsString ¶
AsString is a shortcut for Element.AsString, if this value is singular.
func (Value) AsUInt ¶
AsUInt is a shortcut for Element.AsUInt, if this value is singular.
func (Value) Container ¶
func (v Value) Container() MessageValue
Container returns the message value which contains this value, assuming it is not a top-level value.
This function is analogous to Member.Container, which returns the type that contains a member; in particular, for extensions, it returns an extendee.
func (Value) Elements ¶
Elements returns an indexer over the elements within this value.
If the value is not an array, it contains the singular element within; otherwise, it returns the elements of the array.
The indexer will be nonempty except for the zero Value. That is to say, unset fields of [MessageValue]s are not represented as a distinct "empty" Value.
func (Value) Field ¶
Field returns the field this value sets, which includes the value's type information.
NOTE: Member.Element returns google.protobuf.Any, the concrete type of the values in Value.Elements may be distinct from it.
func (Value) IsZeroValue ¶
IsZeroValue is a shortcut for Element.IsZeroValue.
func (Value) KeyAST ¶
KeyAST returns a representative AST node for the message key that evaluated from this value.
func (Value) KeyASTs ¶
KeyASTs returns the AST nodes for each key associated with a value in Value.ValueASTs.
This will either be the key value from an ast.FieldExpr (which need not be an ast.PathExpr, in the case of an extension) or the ast.PathExpr associated with the left-hand-side of an option setting.
func (Value) Marshal ¶
Marshal converts this value into a wire format record and appends it to buf.
If r is not nil, it will be used to record diagnostics generated during the marshal operation.
func (Value) OptionPaths ¶
OptionPaths returns the AST nodes for option paths that set this node.
There will be one path per value returned from Value.ValueASTs. Generally, you'll want to use Value.KeyASTs instead.
func (Value) OptionSpan ¶
OptionSpan returns a representative span for the option that set this value.
The Spanner will be an ast.ExprField, if it is set in an ast.ExprDict.
func (Value) OptionSpans ¶
OptionSpans returns an indexer over spans for the option that set this value.
The Spanner will be an ast.ExprField, if it is set in an ast.ExprDict.
Source Files
¶
- builtins.go
- doc.go
- fdp.go
- ir_features.go
- ir_file.go
- ir_imports.go
- ir_member.go
- ir_name.go
- ir_ref.go
- ir_service.go
- ir_symbol.go
- ir_type.go
- ir_value.go
- lower.go
- lower_deprecated.go
- lower_eval.go
- lower_features.go
- lower_imports.go
- lower_json.go
- lower_maps.go
- lower_numbers.go
- lower_options.go
- lower_resolve.go
- lower_symbols.go
- lower_validate.go
- lower_walk.go
- option_target.go
- symbol_kind.go
- synthetic.go