package catala
Install
Dune Dependency
Authors
Maintainers
Sources
md5=1408a1cce45c7d5990b981e83e7589c2
sha512=eb3b923aa1f743378b4a05e30f50be5d180dc862a716270d747a90e469017f42fa5fc41352f02fbbf59cd2560f91c4f1b32cf38d80085b105d9387b0aed2039d
doc/catala.desugared/Desugared/Name_resolution/index.html
Module Desugared.Name_resolution
Source
Builds a context that allows for mapping each name to a precise uid, taking lexical scopes into account
Name resolution context
type unique_rulename =
| Ambiguous of Catala_utils.Pos.t list
| Unique of Shared_ast.RuleName.t Catala_utils.Marked.pos
type scope_def_context = {
default_exception_rulename : unique_rulename option;
label_idmap : Shared_ast.LabelName.t Shared_ast.IdentName.Map.t;
}
type scope_var_or_subscope =
| ScopeVar of Shared_ast.ScopeVar.t
| SubScope of Shared_ast.SubScopeName.t * Shared_ast.ScopeName.t
type scope_context = {
var_idmap : scope_var_or_subscope Shared_ast.IdentName.Map.t;
(*All variables, including scope variables and subscopes
*)scope_defs_contexts : scope_def_context Ast.ScopeDefMap.t;
(*What is the default rule to refer to for unnamed exceptions, if any
*)sub_scopes : Shared_ast.ScopeName.Set.t;
(*Other scopes referred to by this scope. Used for dependency analysis
*)
}
Inside a scope, we distinguish between the variables and the subscopes.
Types of the fields of a struct
Types of the payloads of the cases of an enum
type var_sig = {
var_sig_typ : Shared_ast.typ;
var_sig_is_condition : bool;
var_sig_parameters : (Catala_utils.Uid.MarkedString.info * Shared_ast.typ) list Catala_utils.Marked.pos option;
var_sig_io : Surface.Ast.scope_decl_context_io;
var_sig_states_idmap : Shared_ast.StateName.t Shared_ast.IdentName.Map.t;
var_sig_states_list : Shared_ast.StateName.t list;
}
type typedef =
| TStruct of Shared_ast.StructName.t
| TEnum of Shared_ast.EnumName.t
| TScope of Shared_ast.ScopeName.t * Shared_ast.scope_out_struct
(*Implicitly defined output struct
*)
Capitalised type names share a namespace on the user side, but may correspond to only one of the following
type context = {
local_var_idmap : Ast.expr Shared_ast.Var.t Shared_ast.IdentName.Map.t;
(*Inside a definition, local variables can be introduced by functions arguments or pattern matching
*)typedefs : typedef Shared_ast.IdentName.Map.t;
(*Gathers the names of the scopes, structs and enums
*)field_idmap : Shared_ast.StructField.t Shared_ast.StructName.Map.t Shared_ast.IdentName.Map.t;
(*The names of the struct fields. Names of fields can be shared between different structs
*)constructor_idmap : Shared_ast.EnumConstructor.t Shared_ast.EnumName.Map.t Shared_ast.IdentName.Map.t;
(*The names of the enum constructors. Constructor names can be shared between different enums
*)scopes : scope_context Shared_ast.ScopeName.Map.t;
(*For each scope, its context
*)topdefs : Shared_ast.TopdefName.t Shared_ast.IdentName.Map.t;
(*Global definitions
*)structs : struct_context Shared_ast.StructName.Map.t;
(*For each struct, its context
*)enums : enum_context Shared_ast.EnumName.Map.t;
(*For each enum, its context
*)var_typs : var_sig Shared_ast.ScopeVar.Map.t;
(*The signatures of each scope variable declared
*)
}
Main context used throughout Surface.Desugaring
Helpers
Temporary function raising an error message saying that a feature is not supported yet
Function to call whenever an identifier used somewhere has not been declared in the program previously
Gets the type associated to an uid
val get_var_uid :
Shared_ast.ScopeName.t ->
context ->
Shared_ast.IdentName.t Catala_utils.Marked.pos ->
Shared_ast.ScopeVar.t
Get the variable uid inside the scope given in argument
val get_subscope_uid :
Shared_ast.ScopeName.t ->
context ->
Shared_ast.IdentName.t Catala_utils.Marked.pos ->
Shared_ast.SubScopeName.t
Get the subscope uid inside the scope given in argument
is_subscope_uid scope_uid ctxt y
returns true if y
belongs to the subscopes of scope_uid
.
Checks if the var_uid belongs to the scope scope_uid
Retrieves the type of a scope definition from the context
val get_params :
context ->
Ast.ScopeDef.t ->
(Catala_utils.Uid.MarkedString.info * Shared_ast.typ) list
Catala_utils.Marked.pos
option
val add_def_local_var :
context ->
Shared_ast.IdentName.t ->
context * Ast.expr Shared_ast.Var.t
Adds a binding to the context
val get_def_key :
Surface.Ast.scope_var ->
Surface.Ast.lident Catala_utils.Marked.pos option ->
Shared_ast.ScopeName.t ->
context ->
Catala_utils.Pos.t ->
Ast.ScopeDef.t
Usage: get_def_key var_name var_state scope_uid ctxt pos
val get_enum :
context ->
Shared_ast.IdentName.t Catala_utils.Marked.pos ->
Shared_ast.EnumName.t
Find an enum definition from the typedefs, failing if there is none or it has a different kind
val get_struct :
context ->
Shared_ast.IdentName.t Catala_utils.Marked.pos ->
Shared_ast.StructName.t
Find a struct definition from the typedefs (possibly an implicit output struct from a scope), failing if there is none or it has a different kind
val get_scope :
context ->
Shared_ast.IdentName.t Catala_utils.Marked.pos ->
Shared_ast.ScopeName.t
Find a scope definition from the typedefs, failing if there is none or it has a different kind
Convert a surface base type to an AST type
API
Derive the context from metadata, in one pass over the declarations