2.1. Domains
A location \ell is a natural number. Locations are never reused.
Lean code for Definition2.1.1●1 definition
Associated Lean declarations
-
CoreCpp.Loc[complete]
-
CoreCpp.Loc[complete]
-
abbrevdefined in CoreCpp/Semantics.leancomplete
abbrev CoreCpp.Loc : Type
abbrev CoreCpp.Loc : Type
Memory location.
The values are \mathsf{int}\,n, \mathsf{bool}\,b, \mathsf{void}, the pointer \mathsf{loc}\,\ell, the value \mathsf{null} of nullptr, the object \mathsf{obj}\,C\,[f_1 \mapsto \ell_1, \ldots, f_n \mapsto \ell_n], a record of one location per field with its class tag, and the instance \mathsf{lib}\,L\,[\ell_0, \ldots, \ell_{n-1}] of an object type L of the library, such as a vector, with one location per element, Definition 8.2.1.
The value \mathsf{void} is the result of a call to a function without return value, and the initial content of a field of function type before the constructor assigns it. The closure is a value too, Definition 2.1.6.
The tag of an object is the class it was created with, its fields are those of the whole chain of classes, the root base first, and the tag decides the dispatch of virtual methods and the destructors that delete runs. Objects and instances of object types of the library live in the store at their own location and are reached only through pointers.
The default value of a type, which new gives to every field and element, is \mathsf{int}\,0, \mathsf{bool}\,\mathtt{false} or \mathsf{null}.
Lean code for Definition2.1.2●2 definitions
Associated Lean declarations
-
CoreCpp.Val[complete]
-
CoreCpp.Ty.default[complete]
-
CoreCpp.Val[complete] -
CoreCpp.Ty.default[complete]
-
inductivedefined in CoreCpp/Semantics.leancomplete
inductive CoreCpp.Val : Type
inductive CoreCpp.Val : Type
Values. `int` is a 32-bit two's complement integer, stored as an `Int` with the range invariant checked at every operation. `loc` is a pointer to the object stored at ℓ, and `null` is the value of `nullptr`. `obj` is an object with its class tag and one location per field, and `lib L ℓ̄` a value of the library entity `L` with its locations. `closure ps τ c cap` is the value of `[=](ps) -> τ { c }`, carrying the values the lambda captured by copy, one per free variable of the body.Constructors
CoreCpp.Val.int (n : Int) : CoreCpp.Val
CoreCpp.Val.bool (b : Bool) : CoreCpp.Val
CoreCpp.Val.void : CoreCpp.Val
CoreCpp.Val.loc (l : CoreCpp.Loc) : CoreCpp.Val
CoreCpp.Val.null : CoreCpp.Val
CoreCpp.Val.obj (tag : String) (fields : List (String × CoreCpp.Loc)) : CoreCpp.Val
CoreCpp.Val.lib (tag : String) (locs : List CoreCpp.Loc) : CoreCpp.Val
CoreCpp.Val.closure (params : List CoreCpp.Param) (ret : CoreCpp.Ty) (body : List CoreCpp.Cmd) (captured : List (String × CoreCpp.Val)) : CoreCpp.Val
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Ty.default : CoreCpp.Ty → CoreCpp.Val
def CoreCpp.Ty.default : CoreCpp.Ty → CoreCpp.Val
The default value of a type, the one `new` gives to every field and element before the constructor runs. Object types have no value, their default is never asked. A field of function type starts empty, `void`, and a call through it before the constructor assigns a lambda is `error`, as the `bad_function_call` of C++.
-
CoreCpp.Int32.min[complete] -
CoreCpp.Int32.max[complete] -
CoreCpp.Int32.inRange[complete]
The type int has 32 bits in two's complement. The partial operation \mathsf{int32} returns the integer when it lies in the range and error otherwise.
C++17 fixes neither the width nor the representation of int. A plain int has the natural size suggested by the architecture of the execution environment, with a range of at least [-32767, 32767] (N4659 §6.9.1 paragraph 2 and §21.3.5, N1570 §5.2.4.2.1). Its representation may be two's complement, ones' complement or signed magnitude (N4659 §6.9.1 paragraph 7). The range of int is therefore a property of the platform.
The ABI of the platform fixes it. The System V AMD64 psABI and AAPCS64 both give int 32 bits, and GCC supports only two's complement integer types.
An arithmetic result outside the range of int has undefined behaviour (N4659 §8 paragraph 4), and Core C++ makes it error. That boundary has to be the boundary of the implementation Core C++ is compared with, g++ and clang on x86‑64 and ARM64. A wider range would give a value where C++ gives none, and a narrower one would give error where C++ gives a value.
The representation enters only through the lower bound -2^{31}. Core C++ has no bitwise operators, no shifts and no unsigned types, so no program observes a bit pattern. The width lives only in Int32.min and Int32.max.
\dfrac{n \in [-2^{31},\, 2^{31}-1]}{\mathsf{int32}\,n = \mathsf{int}\,n} \qquad \dfrac{n \notin [-2^{31},\, 2^{31}-1]}{\mathsf{int32}\,n = \mathsf{error}}
Lean code for Definition2.1.3●3 definitions
Associated Lean declarations
-
CoreCpp.Int32.min[complete]
-
CoreCpp.Int32.max[complete]
-
CoreCpp.Int32.inRange[complete]
-
CoreCpp.Int32.min[complete] -
CoreCpp.Int32.max[complete] -
CoreCpp.Int32.inRange[complete]
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Int32.min : Int
def CoreCpp.Int32.min : Int
Bounds of `int`.
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Int32.max : Int
def CoreCpp.Int32.max : Int
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Int32.inRange (n : Int) : Bool
def CoreCpp.Int32.inRange (n : Int) : Bool
-
CoreCpp.Env[complete] -
CoreCpp.Binding[complete] -
CoreCpp.Env.lookup[complete] -
CoreCpp.Env.extend[complete] -
CoreCpp.Env.alias[complete]
The environment \rho is a finite map from identifiers to locations. The notation \rho[x \mapsto \ell] extends \rho, and the most recent binding prevails.
Each binding records whether the declaration that made it allocated the location, as τ x = e does, or aliased an existing one, as the reference τ& y = e does. Block exit frees only the owned locations.
Inside a member body, this is an alias binding to the location of the receiver, made by the call and never freed by the return.
Lean code for Definition2.1.4●5 definitions
Associated Lean declarations
-
CoreCpp.Env[complete]
-
CoreCpp.Binding[complete]
-
CoreCpp.Env.lookup[complete]
-
CoreCpp.Env.extend[complete]
-
CoreCpp.Env.alias[complete]
-
CoreCpp.Env[complete] -
CoreCpp.Binding[complete] -
CoreCpp.Env.lookup[complete] -
CoreCpp.Env.extend[complete] -
CoreCpp.Env.alias[complete]
-
abbrevdefined in CoreCpp/Semantics.leancomplete
abbrev CoreCpp.Env : Type
abbrev CoreCpp.Env : Type
Environment ρ, a finite map from identifiers to locations. The most recent entry wins, which realises shadowing by inner blocks.
-
structuredefined in CoreCpp/Semantics.leancomplete
structure CoreCpp.Binding : Type
structure CoreCpp.Binding : Type
A binding of ρ. `owned` records whether the declaration that created the binding allocated the location, as `τ x = e` does, or aliased an existing one, as the reference `τ& y = e` does. Block exit frees only owned locations, so an alias never removes the location of the variable it names.
Fields
loc : CoreCpp.Loc
owned : Bool
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Env.lookup (ρ : CoreCpp.Env) (x : String) : Option CoreCpp.Loc
def CoreCpp.Env.lookup (ρ : CoreCpp.Env) (x : String) : Option CoreCpp.Loc
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Env.extend (ρ : CoreCpp.Env) (x : String) (l : CoreCpp.Loc) : CoreCpp.Env
def CoreCpp.Env.extend (ρ : CoreCpp.Env) (x : String) (l : CoreCpp.Loc) : CoreCpp.Env
ρ[x ↦ ℓ], a binding to a location the declaration allocated.
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Env.alias (ρ : CoreCpp.Env) (x : String) (l : CoreCpp.Loc) : CoreCpp.Env
def CoreCpp.Env.alias (ρ : CoreCpp.Env) (x : String) (l : CoreCpp.Loc) : CoreCpp.Env
ρ[x ↦ ℓ] for a reference, a binding to a location that already exists.
-
CoreCpp.Store[complete] -
CoreCpp.Store.read[complete] -
CoreCpp.Store.write[complete] -
CoreCpp.Store.alloc[complete] -
CoreCpp.Store.allocMany[complete] -
CoreCpp.Store.free[complete] -
CoreCpp.Store.dom[complete]
The store \sigma is a finite map from locations to values. The operation \mathrm{alloc}(\sigma, v) returns a fresh location \ell \notin \mathrm{dom}\,\sigma and the store \sigma[\ell \mapsto v]. The operation \sigma \setminus L removes the locations of L from the domain. Reading or writing outside the domain is error.
Lean code for Definition2.1.5●7 definitions
Associated Lean declarations
-
CoreCpp.Store[complete]
-
CoreCpp.Store.read[complete]
-
CoreCpp.Store.write[complete]
-
CoreCpp.Store.alloc[complete]
-
CoreCpp.Store.allocMany[complete]
-
CoreCpp.Store.free[complete]
-
CoreCpp.Store.dom[complete]
-
CoreCpp.Store[complete] -
CoreCpp.Store.read[complete] -
CoreCpp.Store.write[complete] -
CoreCpp.Store.alloc[complete] -
CoreCpp.Store.allocMany[complete] -
CoreCpp.Store.free[complete] -
CoreCpp.Store.dom[complete]
-
structuredefined in CoreCpp/Semantics.leancomplete
structure CoreCpp.Store : Type
structure CoreCpp.Store : Type
Store σ with the location counter. `next` is the next free location.
Fields
mem : List (CoreCpp.Loc × CoreCpp.Val)
next : CoreCpp.Loc
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Store.read (σ : CoreCpp.Store) (l : CoreCpp.Loc) : Option CoreCpp.Val
def CoreCpp.Store.read (σ : CoreCpp.Store) (l : CoreCpp.Loc) : Option CoreCpp.Val
σ(ℓ), or nothing if ℓ ∉ dom σ.
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Store.write (σ : CoreCpp.Store) (l : CoreCpp.Loc) (v : CoreCpp.Val) : CoreCpp.Store
def CoreCpp.Store.write (σ : CoreCpp.Store) (l : CoreCpp.Loc) (v : CoreCpp.Val) : CoreCpp.Store
σ[ℓ ↦ v] for ℓ ∈ dom σ.
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Store.alloc (σ : CoreCpp.Store) (v : CoreCpp.Val) : CoreCpp.Loc × CoreCpp.Store
def CoreCpp.Store.alloc (σ : CoreCpp.Store) (v : CoreCpp.Val) : CoreCpp.Loc × CoreCpp.Store
Allocates a fresh location ℓ ∉ dom σ holding v. Returns ℓ and σ[ℓ ↦ v].
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Store.allocMany (σ : CoreCpp.Store) (vs : List CoreCpp.Val) : List CoreCpp.Loc × CoreCpp.Store
def CoreCpp.Store.allocMany (σ : CoreCpp.Store) (vs : List CoreCpp.Val) : List CoreCpp.Loc × CoreCpp.Store
Allocates one fresh location per value, in order.
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Store.free (σ : CoreCpp.Store) (ls : List CoreCpp.Loc) : CoreCpp.Store
def CoreCpp.Store.free (σ : CoreCpp.Store) (ls : List CoreCpp.Loc) : CoreCpp.Store
σ ∖ L, removes the locations in L from the domain. Realises scope exit.
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.Store.dom (σ : CoreCpp.Store) : List CoreCpp.Loc
def CoreCpp.Store.dom (σ : CoreCpp.Store) : List CoreCpp.Loc
The value of a lambda is the closure \mathsf{closure}(x_1 \ldots x_k, \tau, c, [y_1 \mapsto w_1, \ldots, y_m \mapsto w_m]), with the parameters, the result type, the body and the captured copies, one value per free variable of the body.
The types std::function<τ(τ₁, …, τₖ)> of Definition 8.2.2 have closures as values.
A variable or a parameter holds a closure, a field or a vector element does not, because new would have to give it a default value and there is no empty function in this subset.
Lean code for Definition2.1.6●2 definitions
Associated Lean declarations
-
CoreCpp.Val[complete]
-
CoreCpp.Ty.isFn[complete]
-
CoreCpp.Val[complete] -
CoreCpp.Ty.isFn[complete]
-
inductivedefined in CoreCpp/Semantics.leancomplete
inductive CoreCpp.Val : Type
inductive CoreCpp.Val : Type
Values. `int` is a 32-bit two's complement integer, stored as an `Int` with the range invariant checked at every operation. `loc` is a pointer to the object stored at ℓ, and `null` is the value of `nullptr`. `obj` is an object with its class tag and one location per field, and `lib L ℓ̄` a value of the library entity `L` with its locations. `closure ps τ c cap` is the value of `[=](ps) -> τ { c }`, carrying the values the lambda captured by copy, one per free variable of the body.Constructors
CoreCpp.Val.int (n : Int) : CoreCpp.Val
CoreCpp.Val.bool (b : Bool) : CoreCpp.Val
CoreCpp.Val.void : CoreCpp.Val
CoreCpp.Val.loc (l : CoreCpp.Loc) : CoreCpp.Val
CoreCpp.Val.null : CoreCpp.Val
CoreCpp.Val.obj (tag : String) (fields : List (String × CoreCpp.Loc)) : CoreCpp.Val
CoreCpp.Val.lib (tag : String) (locs : List CoreCpp.Loc) : CoreCpp.Val
CoreCpp.Val.closure (params : List CoreCpp.Param) (ret : CoreCpp.Ty) (body : List CoreCpp.Cmd) (captured : List (String × CoreCpp.Val)) : CoreCpp.Val
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Ty.isFn : CoreCpp.Ty → Bool
def CoreCpp.Ty.isFn : CoreCpp.Ty → Bool
Function types `τ(τ₁, …, τₖ)`, the types of lambdas and the template argument of `std::function`. No variable has a function type.
The control result r of a command is \mathsf{normal} or \mathsf{ret}\,v. A \mathsf{ret} interrupts sequence, block and loop up to the call that consumes it.
Lean code for Definition2.1.7●1 definition
Associated Lean declarations
-
CoreCpp.Ctrl[complete]
-
CoreCpp.Ctrl[complete]
-
inductivedefined in CoreCpp/Semantics.leancomplete
inductive CoreCpp.Ctrl : Type
inductive CoreCpp.Ctrl : Type
Control result of a statement.
Constructors
CoreCpp.Ctrl.normal : CoreCpp.Ctrl
CoreCpp.Ctrl.ret (v : CoreCpp.Val) : CoreCpp.Ctrl
The result error is not a value of the language. It replaces the result of any dynamic judgment and propagates to the whole program.
Its causes are division by zero, int overflow, the dereference of nullptr, an index outside a vector, a negative vector size, a failed assert, a location outside \sigma, an undeclared variable or function, wrong arity, a missing return in a non void function, a second delete of the same object, and a delete through a pointer to a base class without a virtual destructor.
Lean code for Definition2.1.8●1 definition
Associated Lean declarations
-
CoreCpp.Error[complete]
-
CoreCpp.Error[complete]
-
inductivedefined in CoreCpp/Semantics.leancomplete
inductive CoreCpp.Error : Type
inductive CoreCpp.Error : Type
The `error` result. It is not a value of the language. No syntax produces, tests or catches it. It corresponds in C++ to abnormal program termination.
Constructors
CoreCpp.Error.divisionByZero : CoreCpp.Error
CoreCpp.Error.overflow : CoreCpp.Error
CoreCpp.Error.nullDereference : CoreCpp.Error
CoreCpp.Error.outOfBounds (i n : Int) : CoreCpp.Error
CoreCpp.Error.negativeSize (n : Int) : CoreCpp.Error
CoreCpp.Error.danglingLocation (l : CoreCpp.Loc) : CoreCpp.Error
CoreCpp.Error.undeclaredVariable (x : String) : CoreCpp.Error
CoreCpp.Error.undeclaredFunction (f : String) : CoreCpp.Error
CoreCpp.Error.arity (f : String) : CoreCpp.Error
CoreCpp.Error.typeError (msg : String) : CoreCpp.Error
CoreCpp.Error.missingReturn (f : String) : CoreCpp.Error
CoreCpp.Error.notCallable (v : CoreCpp.Val) : CoreCpp.Error
CoreCpp.Error.deleteWithoutVirtualDtor (static tag : String) : CoreCpp.Error
CoreCpp.Error.doubleDelete (l : CoreCpp.Loc) : CoreCpp.Error
CoreCpp.Error.library (msg : String) : CoreCpp.Error
-
CoreCpp.TEnv[complete] -
CoreCpp.TBind[complete] -
CoreCpp.TEnv.lookup[complete] -
CoreCpp.TEnv.isConst[complete] -
CoreCpp.TEnv.bind[complete] -
CoreCpp.TEnv.captured[complete] -
CoreCpp.TEnv.self[complete]
The typing context \Gamma is a finite map from identifiers to types. The types are \mathsf{int}, \mathsf{bool}, \mathsf{void}, a class C, a pointer \tau*, an instance L\langle\tau_1, \ldots, \tau_k\rangle of a class template of the library, a function type \tau(\tau_1, \ldots, \tau_k) as template argument, and the internal type \mathsf{nullptr\_t} of nullptr.
Class types and the object types of the library are object types, they have no values, and no variable, parameter, result or field has one. An expression of object type occurs only as the operand of ., [] or *.
Each binding carries a mark, read only or not. The mark is set on every binding of the enclosing scope when the body of a lambda is checked, so that the copies of [=] are read and never written.
Lean code for Definition2.1.9●7 definitions
Associated Lean declarations
-
CoreCpp.TEnv[complete]
-
CoreCpp.TBind[complete]
-
CoreCpp.TEnv.lookup[complete]
-
CoreCpp.TEnv.isConst[complete]
-
CoreCpp.TEnv.bind[complete]
-
CoreCpp.TEnv.captured[complete]
-
CoreCpp.TEnv.self[complete]
-
CoreCpp.TEnv[complete] -
CoreCpp.TBind[complete] -
CoreCpp.TEnv.lookup[complete] -
CoreCpp.TEnv.isConst[complete] -
CoreCpp.TEnv.bind[complete] -
CoreCpp.TEnv.captured[complete] -
CoreCpp.TEnv.self[complete]
-
abbrevdefined in CoreCpp/Typing.leancomplete
abbrev CoreCpp.TEnv : Type
abbrev CoreCpp.TEnv : Type
Typing context Γ, a finite map from identifiers to types.
-
structuredefined in CoreCpp/Typing.leancomplete
structure CoreCpp.TBind : Type
structure CoreCpp.TBind : Type
A binding of Γ. `const` marks a variable captured by copy in a lambda body, which the body may read and not write.
Fields
ty : CoreCpp.Ty
const : Bool
-
defdefined in CoreCpp/Typing.leancomplete
def CoreCpp.TEnv.lookup (Γ : CoreCpp.TEnv) (x : String) : Option CoreCpp.Ty
def CoreCpp.TEnv.lookup (Γ : CoreCpp.TEnv) (x : String) : Option CoreCpp.Ty
-
defdefined in CoreCpp/Typing.leancomplete
def CoreCpp.TEnv.isConst (Γ : CoreCpp.TEnv) (x : String) : Bool
def CoreCpp.TEnv.isConst (Γ : CoreCpp.TEnv) (x : String) : Bool
-
defdefined in CoreCpp/Typing.leancomplete
def CoreCpp.TEnv.bind (Γ : CoreCpp.TEnv) (x : String) (t : CoreCpp.Ty) : CoreCpp.TEnv
def CoreCpp.TEnv.bind (Γ : CoreCpp.TEnv) (x : String) (t : CoreCpp.Ty) : CoreCpp.TEnv
Γ[x ↦ τ]
-
defdefined in CoreCpp/Typing.leancomplete
def CoreCpp.TEnv.captured (Γ : CoreCpp.TEnv) : CoreCpp.TEnv
def CoreCpp.TEnv.captured (Γ : CoreCpp.TEnv) : CoreCpp.TEnv
Γ with every binding marked read only, the context of a lambda body.
-
defdefined in CoreCpp/Typing.leancomplete
def CoreCpp.TEnv.self (Γ : CoreCpp.TEnv) : Option String
def CoreCpp.TEnv.self (Γ : CoreCpp.TEnv) : Option String
The current class, the class of `this` when Γ binds it, inside a method, a constructor or a destructor.
-
CoreCpp.Decl[complete] -
CoreCpp.Program[complete] -
CoreCpp.Program.funs[complete] -
CoreCpp.FunEnv[complete] -
CoreCpp.FunEnv.lookup[complete]
The function environment gathers the functions a program declares, a finite map from a name to its declaration, built once by the elaboration and implicit in every judgment, which reads it and never changes it. Definition 1.3.1 gives the syntax of the declarations it holds.
Lean code for Definition2.1.10●5 definitions
Associated Lean declarations
-
CoreCpp.Decl[complete]
-
CoreCpp.Program[complete]
-
CoreCpp.Program.funs[complete]
-
CoreCpp.FunEnv[complete]
-
CoreCpp.FunEnv.lookup[complete]
-
CoreCpp.Decl[complete] -
CoreCpp.Program[complete] -
CoreCpp.Program.funs[complete] -
CoreCpp.FunEnv[complete] -
CoreCpp.FunEnv.lookup[complete]
-
inductivedefined in CoreCpp/Syntax.leancomplete
inductive CoreCpp.Decl : Type
inductive CoreCpp.Decl : Type
Top level declarations. A `tmpl T C` is a class template, the class `C` with the type parameter `T`, which is never checked and never run. Only its instantiations are, and `Templates.instantiate` adds one class per instantiation the program mentions. A `libTmpl L Ts` is a class template of the library and a `libFn f τ ps` a function of the library, both declared without a body and implemented by an intrinsic.
Constructors
CoreCpp.Decl.cls (c : CoreCpp.ClassDecl) : CoreCpp.Decl
CoreCpp.Decl.fn (f : CoreCpp.Fun) : CoreCpp.Decl
CoreCpp.Decl.tmpl (param : String) (c : CoreCpp.ClassDecl) : CoreCpp.Decl
CoreCpp.Decl.libTmpl (name : String) (params : List String) : CoreCpp.Decl
CoreCpp.Decl.libFn (name : String) (ret : CoreCpp.Ty) (params : List CoreCpp.Param) : CoreCpp.Decl
-
abbrevdefined in CoreCpp/Syntax.leancomplete
abbrev CoreCpp.Program : Type
abbrev CoreCpp.Program : Type
A program is a list of declarations. There are no global variables.
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Program.funs (p : CoreCpp.Program) : List CoreCpp.Fun
def CoreCpp.Program.funs (p : CoreCpp.Program) : List CoreCpp.Fun
-
abbrevdefined in CoreCpp/Semantics.leancomplete
abbrev CoreCpp.FunEnv : Type
abbrev CoreCpp.FunEnv : Type
Function environment, the program seen as a finite map from names. The whole program is threaded, because `new` also needs the class table.
-
defdefined in CoreCpp/Semantics.leancomplete
def CoreCpp.FunEnv.lookup (fs : CoreCpp.FunEnv) (f : String) : Option CoreCpp.Fun
def CoreCpp.FunEnv.lookup (fs : CoreCpp.FunEnv) (f : String) : Option CoreCpp.Fun
-
CoreCpp.ClassDecl[complete] -
CoreCpp.Field[complete] -
CoreCpp.Method[complete] -
CoreCpp.Ctor[complete] -
CoreCpp.Dtor[complete] -
CoreCpp.Vis[complete] -
CoreCpp.Program.classes[complete] -
CoreCpp.Program.lookupClass[complete] -
CoreCpp.Program.chain[complete] -
CoreCpp.Program.allFields[complete] -
CoreCpp.Program.findField[complete] -
CoreCpp.Program.findMethod[complete] -
CoreCpp.Program.subclass[complete] -
CoreCpp.Program.hasVirtualDtor[complete]
The classes of the program form the class table, a finite map from class names to declarations. A declaration has an optional base, fields and methods with their visibility, at most one constructor and at most one destructor.
The table gives, for a class, its chain up to the root base, every field of the chain with the class that declares it, the nearest method of a given name, the subclass relation and whether some class of the chain has a virtual destructor.
The type checker consults it for types, visibility and dispatch, and new and delete for the fields to allocate and to free. Names are qualified by their namespace, N::C.
Some of the implementations are partial, so Lean records opaque constants that carry the type and not the body, and no property of them is proved here.
Lean code for Definition2.1.11●14 definitions
Associated Lean declarations
-
CoreCpp.ClassDecl[complete]
-
CoreCpp.Field[complete]
-
CoreCpp.Method[complete]
-
CoreCpp.Ctor[complete]
-
CoreCpp.Dtor[complete]
-
CoreCpp.Vis[complete]
-
CoreCpp.Program.classes[complete]
-
CoreCpp.Program.lookupClass[complete]
-
CoreCpp.Program.chain[complete]
-
CoreCpp.Program.allFields[complete]
-
CoreCpp.Program.findField[complete]
-
CoreCpp.Program.findMethod[complete]
-
CoreCpp.Program.subclass[complete]
-
CoreCpp.Program.hasVirtualDtor[complete]
-
CoreCpp.ClassDecl[complete] -
CoreCpp.Field[complete] -
CoreCpp.Method[complete] -
CoreCpp.Ctor[complete] -
CoreCpp.Dtor[complete] -
CoreCpp.Vis[complete] -
CoreCpp.Program.classes[complete] -
CoreCpp.Program.lookupClass[complete] -
CoreCpp.Program.chain[complete] -
CoreCpp.Program.allFields[complete] -
CoreCpp.Program.findField[complete] -
CoreCpp.Program.findMethod[complete] -
CoreCpp.Program.subclass[complete] -
CoreCpp.Program.hasVirtualDtor[complete]
-
structuredefined in CoreCpp/Syntax.leancomplete
structure CoreCpp.ClassDecl : Type
structure CoreCpp.ClassDecl : Type
A class, with an optional base class, fields, methods, at most one constructor and at most one destructor. Names are qualified by their namespace, `N::C`.
Fields
name : String
The name of the class, qualified by its namespace when it has one.
base : Option String
The base class, when the class derives from one.
fields : List CoreCpp.Field
The fields declared by the class itself.
methods : List CoreCpp.Method
The methods declared by the class itself.
ctor : Option CoreCpp.Ctor
The constructor, when the class declares one.
dtor : Option CoreCpp.Dtor
The destructor, when the class declares one.
-
structuredefined in CoreCpp/Syntax.leancomplete
structure CoreCpp.Field : Type
structure CoreCpp.Field : Type
A field of a class.
Fields
ty : CoreCpp.Ty
The type of the field.
name : String
The name of the field.
vis : CoreCpp.Vis
The visibility of the field.
-
structuredefined in CoreCpp/Syntax.leancomplete
structure CoreCpp.Method : Type
structure CoreCpp.Method : Type
A method, defined inside the class. `isVirtual` marks `virtual`, which makes the call dispatch by the class tag of the receiver, and `isOverride` marks `override`, required on a method that redefines a `virtual` one. An operator member is a method whose name is `operator` followed by the operator, `operator+` or `operator[]`, which the type checker reaches by rewriting the infix form.
Fields
name : String
The name of the method.
ret : CoreCpp.Ty
The result type.
params : List CoreCpp.Param
The parameters.
body : List CoreCpp.Cmd
The body, run with `this` bound to the receiver.
vis : CoreCpp.Vis
The visibility of the method.
isVirtual : Bool
Whether the method is declared `virtual`.
isOverride : Bool
Whether the method is declared `override`.
retRef : Bool
Whether the method returns a reference, `τ& m(…)`, so that a call to it denotes the location the body returns.
-
structuredefined in CoreCpp/Syntax.leancomplete
structure CoreCpp.Ctor : Type
structure CoreCpp.Ctor : Type
The constructor of a class, named after the class and run by `new` after the fields are allocated.
Fields
params : List CoreCpp.Param
The parameters of the constructor.
body : List CoreCpp.Cmd
The body, run by `new C(args)` after the fields are allocated.
-
structuredefined in CoreCpp/Syntax.leancomplete
structure CoreCpp.Dtor : Type
structure CoreCpp.Dtor : Type
The destructor of a class, `~C()`, run by `delete` before the locations of the object leave the store.
Fields
body : List CoreCpp.Cmd
The body, run by `delete` before the object leaves the store.
isVirtual : Bool
Whether the destructor is declared `virtual`, which makes `delete` through a pointer to the base well defined.
-
inductivedefined in CoreCpp/Syntax.leancomplete
inductive CoreCpp.Vis : Type
inductive CoreCpp.Vis : Type
Visibility of a member. Members before any section label are private, as in C++.
Constructors
CoreCpp.Vis.pub : CoreCpp.Vis
A public member, visible to every expression.
CoreCpp.Vis.priv : CoreCpp.Vis
A private member, visible only inside a member body of the class that declares it.
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Program.classes (p : CoreCpp.Program) : List CoreCpp.ClassDecl
def CoreCpp.Program.classes (p : CoreCpp.Program) : List CoreCpp.ClassDecl
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Program.lookupClass (p : CoreCpp.Program) (c : String) : Option CoreCpp.ClassDecl
def CoreCpp.Program.lookupClass (p : CoreCpp.Program) (c : String) : Option CoreCpp.ClassDecl
-
opaquedefined in CoreCpp/Syntax.leancomplete
opaque CoreCpp.Program.chain (p : CoreCpp.Program) (c : String) (fuel : Nat := 64) : List CoreCpp.ClassDecl
opaque CoreCpp.Program.chain (p : CoreCpp.Program) (c : String) (fuel : Nat := 64) : List CoreCpp.ClassDecl
The chain of a class, the class itself, its base, the base of the base and so on. A cycle or an unknown base ends the chain, and the type checker rejects both.
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Program.allFields (p : CoreCpp.Program) (c : String) : List (CoreCpp.Field × String)
def CoreCpp.Program.allFields (p : CoreCpp.Program) (c : String) : List (CoreCpp.Field × String)
Every field of a class, the fields of the root base first, each with the class that declares it.
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Program.findField (p : CoreCpp.Program) (c f : String) : Option (CoreCpp.Field × String)
def CoreCpp.Program.findField (p : CoreCpp.Program) (c f : String) : Option (CoreCpp.Field × String)
The field f as seen from class c, with the class that declares it.
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Program.findMethod (p : CoreCpp.Program) (c m : String) : Option (CoreCpp.Method × String)
def CoreCpp.Program.findMethod (p : CoreCpp.Program) (c m : String) : Option (CoreCpp.Method × String)
The method m as seen from class c, the nearest declaration in the chain, with the class that declares it. With m overloaded it is the first of the overload set, and `findMethods` gives them all.
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Program.subclass (p : CoreCpp.Program) (d c : String) : Bool
def CoreCpp.Program.subclass (p : CoreCpp.Program) (d c : String) : Bool
d is c or derives from c.
-
defdefined in CoreCpp/Syntax.leancomplete
def CoreCpp.Program.hasVirtualDtor (p : CoreCpp.Program) (c : String) : Bool
def CoreCpp.Program.hasVirtualDtor (p : CoreCpp.Program) (c : String) : Bool
Some class in the chain of c declares a virtual destructor, so `delete` through a pointer to c reaches the destructor of the tag.