MetaData #
The Imperative dialect has a mechanism to store metadata in each of its constructs. Metadata can be used to track both syntactic facts obtained during translation from the source program to this dialect (e.g., line and column numbers), or semantic facts derived during analyses (e.g., global variables implicitly modified by a language construct).
A metadata field, which can be either a variable or an arbitrary string label.
For now, we only track the variables modified by a construct, but we will expand this in the future.
- var
{P : PureExpr}
(v : P.Ident)
: Field P
Metadata indexed by a Strata variable.
- label
{P : PureExpr}
(l : String)
: Field P
Metadata indexed by an arbitrary label.
Instances For
Equations
- (Imperative.MetaDataElem.Field.var v1).beq (Imperative.MetaDataElem.Field.var v2) = (v1 == v2)
- (Imperative.MetaDataElem.Field.label l1).beq (Imperative.MetaDataElem.Field.label l2) = (l1 == l2)
- f1.beq f2 = false
Instances For
Equations
- Imperative.instBEqField = { beq := fun (f1 f2 : Imperative.MetaDataElem.Field P) => f1.beq f2 }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
A metadata value, which can be either an expression, a message, or a fileRange
- expr
{P : PureExpr}
(e : P.Expr)
: Value P
Metadata value in the form of a structured expression.
- msg
{P : PureExpr}
(s : String)
: Value P
Metadata value in the form of an arbitrary string.
- fileRange
{P : PureExpr}
(r : Strata.FileRange)
: Value P
Metadata value in the form of a fileRange.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- (Imperative.MetaDataElem.Value.expr e1).beq (Imperative.MetaDataElem.Value.expr e2) = (e1 == e2)
- (Imperative.MetaDataElem.Value.msg m1).beq (Imperative.MetaDataElem.Value.msg m2) = (m1 == m2)
- (Imperative.MetaDataElem.Value.fileRange r1).beq (Imperative.MetaDataElem.Value.fileRange r2) = (r1 == r2)
- v1.beq v2 = false
Instances For
Equations
- Imperative.instBEqValue = { beq := fun (v1 v2 : Imperative.MetaDataElem.Value P) => v1.beq v2 }
Metadata is an array of tagged elements.
Equations
Instances For
Equations
Instances For
Push a new metadata element.
Equations
- md.pushElem fld value = Array.push md { fld := fld, value := value }
Instances For
Remove the first metadata element with tag fld.
Equations
- md.eraseElem fld = Array.eraseP md fun (e : Imperative.MetaDataElem P) => e.fld == fld
Instances For
Retrieve the first metadata element with tag fld.
Equations
- md.findElem fld = Array.find? (fun (e : Imperative.MetaDataElem P) => e.fld == fld) md
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Imperative.instToFormatMetaDataOfMetaDataElem = { format := fun (md : Imperative.MetaData P) => if Array.isEmpty md = true then Std.format "" else Std.format md ++ Std.format " " }
Equations
- One or more equations did not get rendered due to their size.
Common metadata fields #
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create a DiagnosticModel from metadata and a message. Uses the file range from metadata if available, otherwise uses a default location.
Equations
- md.toDiagnostic msg = match Imperative.getFileRange md with | some fr => Strata.DiagnosticModel.withRange fr (Std.Format.text msg) | none => Strata.DiagnosticModel.fromMessage msg
Instances For
Create a DiagnosticModel from metadata and a Format message.
Equations
- md.toDiagnosticF msg = md.toDiagnostic (toString msg)
Instances For
Get the file range from metadata as a DiagnosticModel (for formatting). This is a compatibility function that formats the file range using byte offsets. For proper line/column display, use toDiagnostic and format with a FileMap at the top level.
Equations
- md.formatFileRangeD fileMap includeEnd? = match Imperative.getFileRange md with | some fr => fr.format fileMap includeEnd? | none => Std.format ""