package catala

  1. Overview
  2. Docs

Builds a context that allows for mapping each name to a precise uid, taking lexical scopes into account

module Pos = Utils.Pos
module Errors = Utils.Errors

Name resolution context

type ident = string
type scope_context = {
  1. var_idmap : Scopelang.Ast.ScopeVar.t Desugared.Ast.IdentMap.t;
    (*

    Scope variables

    *)
  2. label_idmap : Desugared.Ast.RuleName.t Desugared.Ast.IdentMap.t;
  3. sub_scopes_idmap : Scopelang.Ast.SubScopeName.t Desugared.Ast.IdentMap.t;
    (*

    Sub-scopes variables

    *)
  4. 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.

type struct_context = typ Pos.marked Scopelang.Ast.StructFieldMap.t

Types of the fields of a struct

type enum_context = typ Pos.marked Scopelang.Ast.EnumConstructorMap.t

Types of the payloads of the cases of an enum

type context = {
  1. 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

    *)
  2. scope_idmap : Scopelang.Ast.ScopeName.t Desugared.Ast.IdentMap.t;
    (*

    The names of the scopes

    *)
  3. struct_idmap : Scopelang.Ast.StructName.t Desugared.Ast.IdentMap.t;
    (*

    The names of the structs

    *)
  4. 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

    *)
  5. enum_idmap : Scopelang.Ast.EnumName.t Desugared.Ast.IdentMap.t;
    (*

    The names of the enums

    *)
  6. 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

    *)
  7. scopes : scope_context Scopelang.Ast.ScopeMap.t;
    (*

    For each scope, its context

    *)
  8. structs : struct_context Scopelang.Ast.StructMap.t;
    (*

    For each struct, its context

    *)
  9. enums : enum_context Scopelang.Ast.EnumMap.t;
    (*

    For each enum, its context

    *)
  10. var_typs : typ Pos.marked Scopelang.Ast.ScopeVarMap.t;
    (*

    The types of each scope variable declared

    *)
}

Main context used throughout Surface.Desugaring

Helpers

val raise_unsupported_feature : string -> Pos.t -> 'a

Temporary function raising an error message saying that a feature is not supported yet

val raise_unknown_identifier : string -> ident Pos.marked -> 'a

Function to call whenever an identifier used somewhere has not been declared in the program previously

Gets the type associated to an uid

Get the variable uid inside the scope given in argument

Get the subscope uid inside the scope given in argument

val is_subscope_uid : Scopelang.Ast.ScopeName.t -> context -> ident -> bool

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

Process a subscope declaration

Process a basic type (all types except function types)

Process a type (function or not)

Process data declaration

Process an item declaration

val add_def_local_var : context -> ident Pos.marked -> context * Scopelang.Ast.Var.t

Adds a binding to the context

val process_scope_decl : context -> Ast.scope_decl -> context

Process a scope declaration

val process_struct_decl : context -> Ast.struct_decl -> context

Process a struct declaration

val process_enum_decl : context -> Ast.enum_decl -> context

Process an enum declaration

val process_decl_item : context -> Ast.code_item Pos.marked -> context

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_definition : context -> Scopelang.Ast.ScopeName.t -> Ast.definition -> context
val process_scope_use : context -> Ast.scope_use -> context
val process_use_item : context -> Ast.code_item Pos.marked -> context

API

val form_context : Ast.program -> context

Derive the context from metadata, in one pass over the declarations