- Untyped AST annotations and locations
- Generated locations
- Visibility modifiers
- Variable information
- Functions for building and destructuring untyped AST elements
- Simplifcation of numeric expressions and constraints
- Set and Map modules for various AST elements
- Functions for working with type quantifiers
- Functions to map over annotations in sub-expressions
- Printing utilities
- Functions for getting identifiers from toplevel definitions
- Misc functions
- Manipulating locations
- Substitutions
package libsail
Module Libsail.Ast_utilSource
Utilities and helper functions for operating on Sail ASTs
Untyped AST annotations and locations
The type of annotations for untyped AST nodes. When expressions are type-checked the untyped annotations are replaced with typed annotations Type_check.tannot.
Aliases for an untyped definitions and full AST for readability
Attributes
Add an attribute to an annotation. Attributes are attached to expressions in Sail via:
$[attribute argument] expressionThe location argument should be a span that corresponds to the attribute itself, and not include the expression.
val find_attribute_opt :
string ->
(Ast.l * string * Ast.attribute_data option) list ->
Ast.attribute_data option optionval mk_def_annot :
?doc:string ->
?attrs:(Ast.l * string * Ast.attribute_data option) list ->
?visibility:Ast.visibility ->
Ast.l ->
'a ->
'a Ast.def_annotval add_def_attribute :
Ast.l ->
string ->
Ast.attribute_data option ->
'a Ast.def_annot ->
'a Ast.def_annotval get_def_attribute :
string ->
'a Ast.def_annot ->
(Ast.l * Ast.attribute_data option) optionThe empty annotation (as a location + uannot pair). Should be used carefully because it can result in unhelpful error messgaes. However a common pattern is generating code with no_annot, then adding location information with the various locate_ functions in this module.
Generated locations
gen_loc l takes a location l and generates a location which means 'generated/derived from location l'. This is useful for debugging errors that occur in generated code.
Visibility modifiers
Variable information
lvar is the type of variables - they can either be registers, local mutable or immutable variables constructors or unbound identifiers.
Functions for building and destructuring untyped AST elements
Functions for building untyped AST elements
Mapping patterns are a subset of patterns, so we can always convert one to the other
Unwrap aux constructors
Destruct type annotated patterns and expressions
untyp_pat (P_aux (P_typ (typ, pat)), _) returns Some (pat, typ) or None if the pattern does not match.
Same as untyp_pat, but for E_typ nodes
Utilites for working with kinded_ids
Utility functions for constructing types
Sail built-in types
Simplifcation of numeric expressions and constraints
These functions simplify nexps and n_constraints using various basic rules. In general they will guarantee to reduce constant numeric expressions like 2 + 5 into 7, although they will not simplify 2^constant, as that often leads to unreadable error messages containing huge numbers.
If a constraint is a conjunction, return a list of all the top-level conjuncts
Same as constraint_conj but for disjunctions
Functions for building numeric expressions
Functions for building numeric constraints
Functions for building type arguments
Set and Map modules for various AST elements
Functions for working with type quantifiers
Functions to map over annotations in sub-expressions
val map_scattered_annot :
('a Ast.annot -> 'b Ast.annot) ->
'a Ast.scattered_def ->
'b Ast.scattered_defval map_def_def_annot :
('a Ast.def_annot -> 'b Ast.def_annot) ->
('c, 'a) Ast.def ->
('c, 'b) Ast.defval map_ast_annot :
('a Ast.annot -> 'b Ast.annot) ->
('a, 'c) Ast_defs.ast ->
('b, 'c) Ast_defs.astExtract locations from terms
Printing utilities
Note: For debugging and error messages only - not guaranteed to produce parseable Sail, or even print all language constructs!
Functions for getting identifiers from toplevel definitions
Functions for manipulating identifiers
Misc functions
Manipulating locations
locate takes an expression and recursively sets the location in every subexpression using a function that takes the orginal location as an argument. Expressions build using mk_exp and similar do not have locations, so they can then be annotated as e.g. locate (gen_loc l) (mk_exp ...) where l is the location from which the code is being generated.
Make a unique location by giving it a Parse_ast.Unique wrapper with a generated number.
Convert unknown locations into known ones by replacing any Unknown subparts of the second argument with the first argument. Set up so one can do: locate (unknown_to l) exp and similar.
Try to find the annotation closest to the provided location (which can be in any format, as long as we can tell if it is smaller than any other location). Note that this function makes no guarantees about finding the closest annotation or even finding an annotation at all. This is used by the LSP to provide type-at-cursor functionality and we don't mind if it's a bit fuzzy in that context.
Substitutions
The function X_subst substitutes a type argument into something of type X. The type of the type argument determines which kind of type variables will be replaced
- Untyped AST annotations and locations
- Generated locations
- Visibility modifiers
- Variable information
- Functions for building and destructuring untyped AST elements
- Simplifcation of numeric expressions and constraints
- Set and Map modules for various AST elements
- Functions for working with type quantifiers
- Functions to map over annotations in sub-expressions
- Printing utilities
- Functions for getting identifiers from toplevel definitions
- Misc functions
- Manipulating locations
- Substitutions