Documentation ¶
Overview ¶
Package graph defines the graph for the WebIDL integration.
Index ¶
- Constants
- Variables
- func GetUniqueId(irgNode compilergraph.GraphNode) string
- type CollapsedType
- func (ct *CollapsedType) RegisterMember(member IRGMember, reporter typegraph.IssueReporter) bool
- func (ct *CollapsedType) RegisterOperator(name string, opAnnotation IRGAnnotation) bool
- func (ct *CollapsedType) RegisterSpecialization(member IRGMember, reporter typegraph.IssueReporter) bool
- func (ct *CollapsedType) SourceRanges() []compilercommon.SourceRange
- type DeclarationKind
- type IRGAnnotation
- type IRGDeclaration
- func (i *IRGDeclaration) Annotations() []IRGAnnotation
- func (i *IRGDeclaration) CustomOperations() []string
- func (i *IRGDeclaration) FindMember(name string) (IRGMember, bool)
- func (i *IRGDeclaration) GetAnnotations(name string) []IRGAnnotation
- func (i *IRGDeclaration) HasAnnotation(name string) bool
- func (i *IRGDeclaration) HasOneAnnotation(names ...interface{}) bool
- func (i *IRGDeclaration) IsSerializable() bool
- func (i *IRGDeclaration) Kind() DeclarationKind
- func (i *IRGDeclaration) Members() []IRGMember
- func (i *IRGDeclaration) Module() IRGModule
- func (i *IRGDeclaration) Name() string
- func (i *IRGDeclaration) ParentType() (string, bool)
- func (i *IRGDeclaration) SourceRange() (compilercommon.SourceRange, bool)
- type IRGMember
- func (i *IRGMember) Annotations() []IRGAnnotation
- func (i *IRGMember) DeclaredType() string
- func (i *IRGMember) IsReadonly() bool
- func (i *IRGMember) IsStatic() bool
- func (i *IRGMember) Kind() MemberKind
- func (i *IRGMember) Name() (string, bool)
- func (i *IRGMember) Parameters() []IRGParameter
- func (i *IRGMember) Signature() string
- func (i *IRGMember) SourceRange() (compilercommon.SourceRange, bool)
- func (i *IRGMember) Specialization() (MemberSpecialization, bool)
- type IRGModule
- type IRGParameter
- type MemberKind
- type MemberSpecialization
- type TypeCollapser
- func (tc *TypeCollapser) ForEachGlobalDeclaration(handler gdHandler)
- func (tc *TypeCollapser) ForEachType(handler ctHandler)
- func (tc *TypeCollapser) GetType(name string) (*CollapsedType, bool)
- func (tc *TypeCollapser) GetTypeForNodeID(nodeID compilergraph.GraphNodeId) (*CollapsedType, bool)
- func (tc *TypeCollapser) Types() chan *CollapsedType
- type WebIRG
- func (g *WebIRG) Declarations() []IRGDeclaration
- func (g *WebIRG) FindDeclaration(name string) (IRGDeclaration, bool)
- func (g *WebIRG) GetModules() []IRGModule
- func (g *WebIRG) GetNode(nodeId compilergraph.GraphNodeId) compilergraph.GraphNode
- func (g *WebIRG) RootModuleNode() compilergraph.GraphNode
- func (g *WebIRG) SourceHandler() packageloader.SourceHandler
- func (g *WebIRG) SourceRangeOf(node compilergraph.GraphNode) (compilercommon.SourceRange, bool)
- func (g *WebIRG) SourceRangesOf(node compilergraph.GraphNode) []compilercommon.SourceRange
- func (g *WebIRG) TryGetNode(nodeId compilergraph.GraphNodeId) (compilergraph.GraphNode, bool)
- func (g *WebIRG) TypeCollapser() *TypeCollapser
Constants ¶
const CONSTRUCTOR_ANNOTATION = "Constructor"
CONSTRUCTOR_ANNOTATION is an annotation that describes support for a constructor on a WebIDL type. This translates to being able to do "new Type(...)" in ECMAScript.
const NATIVE_OPERATOR_ANNOTATION = "NativeOperator"
NATIVE_OPERATOR_ANNOTATION is an annotation that marks an declaration as supporting the specified operator natively (i.e. not a custom defined operator).
Variables ¶
var GLOBAL_CONTEXT_ANNOTATIONS = []interface{}{"Global", "PrimaryGlobal"}
GLOBAL_CONTEXT_ANNOTATIONS are the annotations that mark an interface as being a global context (e.g. Window) in WebIDL.
var NATIVE_TYPES = map[string]string{
"boolean": "Boolean",
"byte": "Number",
"octet": "Number",
"short": "Number",
"unsigned short": "Number",
"long": "Number",
"unsigned long": "Number",
"long long": "Number",
"float": "Number",
"double": "Number",
"unrestricted float": "Number",
"unrestricted double": "Number",
}
NATIVE_TYPES maps from the predefined WebIDL types to the type actually supported in ES. We lose some information by doing so, but it allows for compatibility with existing WebIDL specifications. In the future, we might find a way to have these types be used in a more specific manner.
var SERIALIZABLE_OPS = map[string]bool{ "jsonifier": true, "serializer": true, }
SERIALIZABLE_OPS defines the WebIDL custom ops that mark a type as serializable.
var SPECIALIZATION_NAMES = map[MemberSpecialization]string{
GetterSpecialization: "index",
SetterSpecialization: "setindex",
}
SPECIALIZATION_NAMES maps WebIDL member specializations into Serulian typegraph names.
Functions ¶
func GetUniqueId ¶
func GetUniqueId(irgNode compilergraph.GraphNode) string
GetUniqueId returns a unique hash ID for the IRG node that is stable across compilations.
Types ¶
type CollapsedType ¶
type CollapsedType struct { RootNode compilergraph.GraphNode // The root node for this type in the IRG. Declarations []IRGDeclaration // The declarations that created this type. Name string // The name of this type. Unique amongst all CollapsedType's. ConstructorAnnotations []IRGAnnotation // The constructor(s) for this type, if any. Serializable bool // Whether this type is marked as serializable. ParentTypes map[string]IRGDeclaration // The parent type(s) for this type, if any. Operators map[string]IRGAnnotation // The registered operators. Members map[string]IRGMember // The registered members. Specializations map[MemberSpecialization]IRGMember // The registered specializations. }
CollapsedType represents a single named type in the WebIDL that has been collapsed from (possibly multiple) declarations.
func (*CollapsedType) RegisterMember ¶
func (ct *CollapsedType) RegisterMember(member IRGMember, reporter typegraph.IssueReporter) bool
RegisterMember registers a member, returning true if this is the first occurance of the member under the collapsed type. If another member of the same name exists *and* its signature does not match, an error is reported on the reporter.
func (*CollapsedType) RegisterOperator ¶
func (ct *CollapsedType) RegisterOperator(name string, opAnnotation IRGAnnotation) bool
RegisterOperator registers an operator with the given name and annotation, returning true if this is the first occurance of the operator under the collapsed type.
func (*CollapsedType) RegisterSpecialization ¶
func (ct *CollapsedType) RegisterSpecialization(member IRGMember, reporter typegraph.IssueReporter) bool
RegisterSpecialization registers a specialization member, returning true if this is the first occurance of the member under the collapsed type. If another member of the same specialization exists *and* its signature does not match, an error is reported on the reporter.
func (*CollapsedType) SourceRanges ¶
func (ct *CollapsedType) SourceRanges() []compilercommon.SourceRange
SourceRanges returns the ranges for this collapsed type.
type DeclarationKind ¶
type DeclarationKind int
const (
InterfaceDeclaration DeclarationKind = iota
)
type IRGAnnotation ¶
type IRGAnnotation struct { compilergraph.GraphNode // contains filtered or unexported fields }
IRGAnnotation wraps a WebIDL annotation.
func (*IRGAnnotation) Name ¶
func (i *IRGAnnotation) Name() string
Name returns the name of the annotation.
func (*IRGAnnotation) Parameters ¶
func (i *IRGAnnotation) Parameters() []IRGParameter
Parameters returns all the parameters declared on the annotation.
func (*IRGAnnotation) SourceRange ¶
func (i *IRGAnnotation) SourceRange() (compilercommon.SourceRange, bool)
SourceRange returns the source range of the parameter in source.
func (*IRGAnnotation) Value ¶
func (i *IRGAnnotation) Value() (string, bool)
Value returns the value of the annotation, if any.
type IRGDeclaration ¶
type IRGDeclaration struct { compilergraph.GraphNode // contains filtered or unexported fields }
IRGDeclaration wraps a WebIDL declaration.
func (*IRGDeclaration) Annotations ¶
func (i *IRGDeclaration) Annotations() []IRGAnnotation
Annotations returns all the annotations declared on the declaration.
func (*IRGDeclaration) CustomOperations ¶
func (i *IRGDeclaration) CustomOperations() []string
CustomOperations returns all the custom operations defined on the declaration.
func (*IRGDeclaration) FindMember ¶
func (i *IRGDeclaration) FindMember(name string) (IRGMember, bool)
FindMember finds the member under this declaration with the given name, if any.
func (*IRGDeclaration) GetAnnotations ¶
func (i *IRGDeclaration) GetAnnotations(name string) []IRGAnnotation
GetAnnotations returns all the annotations with the given name declared on the declaration.
func (*IRGDeclaration) HasAnnotation ¶
func (i *IRGDeclaration) HasAnnotation(name string) bool
HasAnnotation returns true if the declaration is decorated with the given annotation.
func (*IRGDeclaration) HasOneAnnotation ¶
func (i *IRGDeclaration) HasOneAnnotation(names ...interface{}) bool
HasOneAnnotation returns true if the declaration is decorated with one of the given annotations.
func (*IRGDeclaration) IsSerializable ¶
func (i *IRGDeclaration) IsSerializable() bool
IsSerializable returns whether the declaration contains one of the custom operations that makes the declared interface serializable.
func (*IRGDeclaration) Kind ¶
func (i *IRGDeclaration) Kind() DeclarationKind
Kind returns the kind of declaration.
func (*IRGDeclaration) Members ¶
func (i *IRGDeclaration) Members() []IRGMember
Members returns all the members declared in the declaration.
func (*IRGDeclaration) Module ¶
func (i *IRGDeclaration) Module() IRGModule
Module returns the parent module.
func (*IRGDeclaration) Name ¶
func (i *IRGDeclaration) Name() string
Name returns the name of the declaration.
func (*IRGDeclaration) ParentType ¶
func (i *IRGDeclaration) ParentType() (string, bool)
ParentType returns the declared parent type of the declaration, if any.
func (*IRGDeclaration) SourceRange ¶
func (i *IRGDeclaration) SourceRange() (compilercommon.SourceRange, bool)
SourceRange returns the source range of the declaration in source.
type IRGMember ¶
type IRGMember struct { compilergraph.GraphNode // contains filtered or unexported fields }
IRGMember wraps a WebIDL declaration member.
func (*IRGMember) Annotations ¶
func (i *IRGMember) Annotations() []IRGAnnotation
Annotations returns all the annotations declared on the member.
func (*IRGMember) DeclaredType ¶
DeclaredType returns the declared type of the member.
func (*IRGMember) IsReadonly ¶
IsReadonly returns true if this member is read-only.
func (*IRGMember) Name ¶
Name returns the name of the member, if any. Specializations won't have names.
func (*IRGMember) Parameters ¶
func (i *IRGMember) Parameters() []IRGParameter
Parameters returns all the parameters declared on the member.
func (*IRGMember) Signature ¶
Signature returns a signature for comparing two members to determine if they are defined the same way. Used for comparing members when collapsing types in the type constructor. The output of this function should be considered opaque and never used for anything except comparison.
func (*IRGMember) SourceRange ¶
func (i *IRGMember) SourceRange() (compilercommon.SourceRange, bool)
SourceRange returns the source range of the member in source.
func (*IRGMember) Specialization ¶
func (i *IRGMember) Specialization() (MemberSpecialization, bool)
Specialization returns the specialization of the member, if any.
type IRGModule ¶
type IRGModule struct { compilergraph.GraphNode // contains filtered or unexported fields }
IRGModule wraps a module defined in the IRG.
func (IRGModule) Declarations ¶
func (m IRGModule) Declarations() []IRGDeclaration
Declarations returns the declarations directly under the module.
func (IRGModule) InputSource ¶
func (m IRGModule) InputSource() compilercommon.InputSource
InputSource returns the input source for this module.
func (IRGModule) Node ¶
func (m IRGModule) Node() compilergraph.GraphNode
Node returns the underlying node.
type IRGParameter ¶
type IRGParameter struct { compilergraph.GraphNode // contains filtered or unexported fields }
IRGParameter wraps a WebIDL parameter.
func (*IRGParameter) DeclaredType ¶
func (i *IRGParameter) DeclaredType() string
DeclaredType returns the declared type of the parameter.
func (*IRGParameter) IsOptional ¶
func (i *IRGParameter) IsOptional() bool
IsOptional returns true if this parameter is optional.
func (*IRGParameter) Name ¶
func (i *IRGParameter) Name() string
Name returns the name of the parameter.
func (*IRGParameter) SourceRange ¶
func (i *IRGParameter) SourceRange() (compilercommon.SourceRange, bool)
SourceRange returns the source range of the parameter in source.
type MemberKind ¶
type MemberKind int
const ( ConstructorMember MemberKind = iota OperatorMember FunctionMember AttributeMember )
type MemberSpecialization ¶
type MemberSpecialization string
const ( GetterSpecialization MemberSpecialization = "getter" SetterSpecialization MemberSpecialization = "setter" )
type TypeCollapser ¶
type TypeCollapser struct {
// contains filtered or unexported fields
}
TypeCollapser represents a collapsed set of the types that will be emitted into the type graph from the imported WebIDL modules. This is necessary because in order to ensure compatibility in the flat namespace of WebIDL, we need to merge types with the same name.
func (*TypeCollapser) ForEachGlobalDeclaration ¶
func (tc *TypeCollapser) ForEachGlobalDeclaration(handler gdHandler)
ForEachGlobalDeclaration invokes the given handler for each global decl. Note that the handlers will be invoked in parallel via goroutines, so care must be taken if access any shared resources.
func (*TypeCollapser) ForEachType ¶
func (tc *TypeCollapser) ForEachType(handler ctHandler)
ForEachType invokes the given handler for each collapsed type. Note that the handlers will be invoked in parallel via goroutines, so care must be taken if access any shared resources.
func (*TypeCollapser) GetType ¶
func (tc *TypeCollapser) GetType(name string) (*CollapsedType, bool)
GetType returns the collapsed type matching the given name, if any.
func (*TypeCollapser) GetTypeForNodeID ¶
func (tc *TypeCollapser) GetTypeForNodeID(nodeID compilergraph.GraphNodeId) (*CollapsedType, bool)
GetTypeForNodeID returns the collapsed type with the given matching Node ID.
func (*TypeCollapser) Types ¶
func (tc *TypeCollapser) Types() chan *CollapsedType
Types returns all collapsed types found in the WebIDL IRG.
type WebIRG ¶
type WebIRG struct {
// contains filtered or unexported fields
}
WebIRG defines an interface representation graph for the supported subset of WebIDL.
func NewIRG ¶
func NewIRG(graph compilergraph.SerulianGraph) *WebIRG
NewIRG returns a new IRG for populating the graph with parsed source.
func (*WebIRG) Declarations ¶
func (g *WebIRG) Declarations() []IRGDeclaration
Declarations returns all the type declarations in the WebIDL IRG.
func (*WebIRG) FindDeclaration ¶
func (g *WebIRG) FindDeclaration(name string) (IRGDeclaration, bool)
FindDeclaration finds the declaration with the given name in the IRG, if any.
func (*WebIRG) GetModules ¶
GetModules returns all the modules defined in the IRG.
func (*WebIRG) GetNode ¶
func (g *WebIRG) GetNode(nodeId compilergraph.GraphNodeId) compilergraph.GraphNode
GetNode returns the node with the given ID in this layer or panics.
func (*WebIRG) RootModuleNode ¶
func (g *WebIRG) RootModuleNode() compilergraph.GraphNode
RootModuleNode returns the node for the root module containing all the collapsed types.
func (*WebIRG) SourceHandler ¶
func (g *WebIRG) SourceHandler() packageloader.SourceHandler
SourceHandler returns a SourceHandler for populating the IRG via a package loader.
func (*WebIRG) SourceRangeOf ¶
func (g *WebIRG) SourceRangeOf(node compilergraph.GraphNode) (compilercommon.SourceRange, bool)
SourceRangeOf returns the source range of the given IRG node.
func (*WebIRG) SourceRangesOf ¶
func (g *WebIRG) SourceRangesOf(node compilergraph.GraphNode) []compilercommon.SourceRange
SourceRangesOf returns the source ranges of the given IRG node.
func (*WebIRG) TryGetNode ¶
func (g *WebIRG) TryGetNode(nodeId compilergraph.GraphNodeId) (compilergraph.GraphNode, bool)
TryGetNode attempts to return the node with the given ID in this layer, if any.
func (*WebIRG) TypeCollapser ¶
func (g *WebIRG) TypeCollapser() *TypeCollapser
TypeCollapser returns the type collapser for this graph. Will not exist until after source has been loaded into the graph.