AST
AST represents the parsed or checked expression graph plus metadata.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AST(
exprValue,sourceInfoValue?,typeMap?,refMap?,sourceValue?):AST
Parameters
Section titled “Parameters”exprValue
Section titled “exprValue”sourceInfoValue?
Section titled “sourceInfoValue?”typeMap?
Section titled “typeMap?”Map<number, Type> = ...
refMap?
Section titled “refMap?”Map<number, ReferenceInfo> = ...
sourceValue?
Section titled “sourceValue?”Returns
Section titled “Returns”AST
Methods
Section titled “Methods”clearUnusedIds()
Section titled “clearUnusedIds()”clearUnusedIds():
void
ClearUnusedIds removes source offsets that do not correspond to live ids.
Returns
Section titled “Returns”void
expr()
Section titled “expr()”expr():
Expr
Expr returns the root expression.
Returns
Section titled “Returns”getOverloadIds()
Section titled “getOverloadIds()”getOverloadIds(
id):string[]
GetOverloadIds returns the overload ids for an expression id.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”string[]
getType()
Section titled “getType()”getType(
id):Type|undefined
GetType looks up the type for an expression id.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”Type | undefined
ids():
Set<number>
Ids returns the set of ids referenced by the AST and macro calls.
Returns
Section titled “Returns”Set<number>
isChecked()
Section titled “isChecked()”isChecked():
boolean
IsChecked reports whether type-checking metadata is present.
Returns
Section titled “Returns”boolean
referenceMap()
Section titled “referenceMap()”referenceMap():
Map<number,ReferenceInfo>
ReferenceMap returns a copy of the expression id to reference map.
Returns
Section titled “Returns”Map<number, ReferenceInfo>
referenceMapView()
Section titled “referenceMapView()”referenceMapView():
ReadonlyMap<number,ReferenceInfo>
ReferenceMapView returns the expression id to reference map without copying it.
Copying the map is the dominant cost of planning a small expression once the runtime dispatcher
is shared. Readers that never mutate the result and do not outlive the AST use this accessor;
every other caller uses referenceMap().
Returns
Section titled “Returns”ReadonlyMap<number, ReferenceInfo>
setReference()
Section titled “setReference()”setReference(
id,reference):void
SetReference records the reference for an expression id.
Parameters
Section titled “Parameters”number
reference
Section titled “reference”Returns
Section titled “Returns”void
setType()
Section titled “setType()”setType(
id,type):void
SetType records the type for an expression id.
Parameters
Section titled “Parameters”number
Type
Returns
Section titled “Returns”void
source()
Section titled “source()”source():
Source
Source returns the original source when available, or a metadata-backed source otherwise.
Returns
Section titled “Returns”sourceInfo()
Section titled “sourceInfo()”sourceInfo():
SourceInfo
SourceInfo returns the associated source metadata.
Returns
Section titled “Returns”toCheckedExpr()
Section titled “toCheckedExpr()”toCheckedExpr():
CheckedExpr
toCheckedExpr converts a checked AST to a CheckedExpr protobuf value.
Returns
Section titled “Returns”CheckedExpr
toParsedExpr()
Section titled “toParsedExpr()”toParsedExpr():
ParsedExpr
toParsedExpr converts an unchecked AST to a ParsedExpr protobuf value.
Returns
Section titled “Returns”ParsedExpr
toProto()
Section titled “toProto()”toProto():
ParsedExpr|CheckedExpr
toProto converts the AST to either ParsedExpr or CheckedExpr depending on whether it is checked.
Returns
Section titled “Returns”ParsedExpr | CheckedExpr
typeMap()
Section titled “typeMap()”typeMap():
Map<number,Type>
TypeMap returns a copy of the expression id to type map.
Returns
Section titled “Returns”Map<number, Type>
withSource()
Section titled “withSource()”withSource(
source):AST
WithSource returns an equivalent AST bound to a source, sharing this AST’s checked metadata.
Rebuilding an AST through typeMap() and referenceMap() deep-copies both maps, and copying
the type map structured-clones every entry. Callers that attach a source to an AST they just
produced and are about to discard pay that copy for nothing: check spent roughly a third of
its total time there. Sharing is safe only because the receiver is a temporary; use the
copying accessors when the original AST outlives the result.
Parameters
Section titled “Parameters”source
Section titled “source”Returns
Section titled “Returns”AST