package catala
Install
Dune Dependency
Authors
Maintainers
Sources
md5=4c6f725ef4d21c5ff91f60d74b454ef7
sha512=98806e03daa6f33740b80a0f78a37320fb70ebea8cb927ea8fed022673459189c32e2389ccba0fa25d93f754b0fa0128a5ee28e1bb9abefa330deb4be8cc7d95
doc/catala.surface/Surface/Name_resolution/index.html
Module Surface.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 scope_context = {
var_idmap : Scopelang.Ast.ScopeVar.t Desugared.Ast.IdentMap.t;
(*Scope variables
*)label_idmap : Desugared.Ast.RuleName.t Desugared.Ast.IdentMap.t;
sub_scopes_idmap : Scopelang.Ast.SubScopeName.t Desugared.Ast.IdentMap.t;
(*Sub-scopes variables
*)sub_scopes : Scopelang.Ast.ScopeName.t Scopelang.Ast.SubScopeMap.t;
(*To what scope sub-scopes refer to?
*)
}
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 context = {
local_var_idmap : Scopelang.Ast.Var.t Desugared.Ast.IdentMap.t;
(*Inside a definition, local variables can be introduced by functions arguments or pattern matching
*)scope_idmap : Scopelang.Ast.ScopeName.t Desugared.Ast.IdentMap.t;
(*The names of the scopes
*)struct_idmap : Scopelang.Ast.StructName.t Desugared.Ast.IdentMap.t;
(*The names of the structs
*)field_idmap : Scopelang.Ast.StructFieldName.t Scopelang.Ast.StructMap.t Desugared.Ast.IdentMap.t;
(*The names of the struct fields. Names of fields can be shared between different structs
*)enum_idmap : Scopelang.Ast.EnumName.t Desugared.Ast.IdentMap.t;
(*The names of the enums
*)constructor_idmap : Scopelang.Ast.EnumConstructor.t Scopelang.Ast.EnumMap.t Desugared.Ast.IdentMap.t;
(*The names of the enum constructors. Constructor names can be shared between different enums
*)scopes : scope_context Scopelang.Ast.ScopeMap.t;
(*For each scope, its context
*)structs : struct_context Scopelang.Ast.StructMap.t;
(*For each struct, its context
*)enums : enum_context Scopelang.Ast.EnumMap.t;
(*For each enum, its context
*)var_typs : typ Pos.marked Scopelang.Ast.ScopeVarMap.t;
(*The types 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 :
Scopelang.Ast.ScopeName.t ->
context ->
ident Pos.marked ->
Scopelang.Ast.ScopeVar.t
Get the variable uid inside the scope given in argument
val get_subscope_uid :
Scopelang.Ast.ScopeName.t ->
context ->
ident Pos.marked ->
Scopelang.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
Declarations pass
val process_subscope_decl :
Scopelang.Ast.ScopeName.t ->
context ->
Ast.scope_decl_context_scope ->
context
Process a subscope declaration
Process a basic type (all types except function types)
Process a type (function or not)
val process_data_decl :
Scopelang.Ast.ScopeName.t ->
context ->
Ast.scope_decl_context_data ->
context
Process data declaration
val process_item_decl :
Scopelang.Ast.ScopeName.t ->
context ->
Ast.scope_decl_context_item ->
context
Process an item declaration
Adds a binding to the context
Process a scope declaration
Process a struct declaration
Process an enum declaration
Process a code item that is a declaration
val process_code_block :
context ->
Ast.code_block ->
(context -> Ast.code_item Pos.marked -> context) ->
context
Process a code block
val process_law_article_item :
context ->
Ast.law_article_item ->
(context -> Ast.code_item Pos.marked -> context) ->
context
Process a law article item, only considering the code blocks
val process_law_structure :
context ->
Ast.law_structure ->
(context -> Ast.code_item Pos.marked -> context) ->
context
Process a law structure, only considering the code blocks
val process_program_item :
context ->
Ast.program_item ->
(context -> Ast.code_item Pos.marked -> context) ->
context
Process a program item, only considering the code blocks
Scope uses pass
val process_scope_use_item :
Scopelang.Ast.ScopeName.t ->
context ->
Ast.scope_use_item Pos.marked ->
context
API
Derive the context from metadata, in one pass over the declarations