skylabs.lang.cpp.parser
(*
* Copyright (c) 2024-2025 BlueRock Security, Inc.
* This software is distributed under the terms of the BedRock Open-Source License.
* See the LICENSE-BedRock file in the repository root for details.
*)
Require Ltac2.Ltac2.
Require Export skylabs.prelude.base. (* for, e.g., <<::>> *)
Require Import Stdlib.Numbers.Cyclic.Int63.PrimInt63.
Require Import skylabs.prelude.parray.
Require Import skylabs.prelude.uint63.
Require Export Stdlib.Strings.PrimString.
Require Import skylabs.prelude.avl.
Require Export skylabs.lang.cpp.syntax. (* NOTE: too much *)
Require skylabs.lang.cpp.semantics.sub_module.
Require Export skylabs.lang.cpp.parser.stmt.
Require Import skylabs.lang.cpp.parser.lang.
Require Import skylabs.lang.cpp.parser.type.
Require Import skylabs.lang.cpp.parser.name.
Require Import skylabs.lang.cpp.parser.expr.
Require Import skylabs.lang.cpp.parser.decl.
Require Import skylabs.lang.cpp.parser.notation.
Require Import skylabs.lang.cpp.parser.reduction.
Include ParserName.
Include ParserType.
Include ParserExpr.
Include ParserDecl.
Module Import translation_unit.
(* Sort and remove duplicates
Doing both of these operations at the same time is more efficient than
doing them separately. Since this is computed on TUs, performance may
be important.
*)
Module sort.
Fixpoint insert (x : name) (ls : list name) : list name :=
match ls with
| nil => x :: nil
| l :: ls' =>
match compare.compareN x l with
| Lt => x :: ls
| Eq => ls
| Gt => l :: insert x ls'
end
end.
Fixpoint sort (ls : list name) : list name :=
match ls with
| nil => nil
| l :: ls => insert l $ sort ls
end.
End sort.
Module sort_static_assert.
Definition compare (x y : StaticAssert) : comparison :=
match PrimString.compare x.(sa_message) y.(sa_message) with
| Eq => base.compare x.(sa_condition) y.(sa_condition)
| c => c
end.
Fixpoint insert (x : StaticAssert) (ls : list StaticAssert) : list StaticAssert :=
match ls with
| nil => x :: nil
| l :: ls' =>
match compare x l with
| Lt => x :: ls
| Eq => ls (* remove duplicates *)
| Gt => l :: insert x ls'
end
end.
Fixpoint sort (ls : list StaticAssert) : list StaticAssert :=
match ls with
| nil => nil
| l :: ls => insert l $ sort ls
end.
End sort_static_assert.
* Copyright (c) 2024-2025 BlueRock Security, Inc.
* This software is distributed under the terms of the BedRock Open-Source License.
* See the LICENSE-BedRock file in the repository root for details.
*)
Require Ltac2.Ltac2.
Require Export skylabs.prelude.base. (* for, e.g., <<::>> *)
Require Import Stdlib.Numbers.Cyclic.Int63.PrimInt63.
Require Import skylabs.prelude.parray.
Require Import skylabs.prelude.uint63.
Require Export Stdlib.Strings.PrimString.
Require Import skylabs.prelude.avl.
Require Export skylabs.lang.cpp.syntax. (* NOTE: too much *)
Require skylabs.lang.cpp.semantics.sub_module.
Require Export skylabs.lang.cpp.parser.stmt.
Require Import skylabs.lang.cpp.parser.lang.
Require Import skylabs.lang.cpp.parser.type.
Require Import skylabs.lang.cpp.parser.name.
Require Import skylabs.lang.cpp.parser.expr.
Require Import skylabs.lang.cpp.parser.decl.
Require Import skylabs.lang.cpp.parser.notation.
Require Import skylabs.lang.cpp.parser.reduction.
Include ParserName.
Include ParserType.
Include ParserExpr.
Include ParserDecl.
Module Import translation_unit.
(* Sort and remove duplicates
Doing both of these operations at the same time is more efficient than
doing them separately. Since this is computed on TUs, performance may
be important.
*)
Module sort.
Fixpoint insert (x : name) (ls : list name) : list name :=
match ls with
| nil => x :: nil
| l :: ls' =>
match compare.compareN x l with
| Lt => x :: ls
| Eq => ls
| Gt => l :: insert x ls'
end
end.
Fixpoint sort (ls : list name) : list name :=
match ls with
| nil => nil
| l :: ls => insert l $ sort ls
end.
End sort.
Module sort_static_assert.
Definition compare (x y : StaticAssert) : comparison :=
match PrimString.compare x.(sa_message) y.(sa_message) with
| Eq => base.compare x.(sa_condition) y.(sa_condition)
| c => c
end.
Fixpoint insert (x : StaticAssert) (ls : list StaticAssert) : list StaticAssert :=
match ls with
| nil => x :: nil
| l :: ls' =>
match compare x l with
| Lt => x :: ls
| Eq => ls (* remove duplicates *)
| Gt => l :: insert x ls'
end
end.
Fixpoint sort (ls : list StaticAssert) : list StaticAssert :=
match ls with
| nil => nil
| l :: ls => insert l $ sort ls
end.
End sort_static_assert.
We work with an exploded translation_unit and raw trees for
efficiency.
Definition raw_symbol_table : Type := NM.Raw.t ObjValue.
Definition raw_type_table : Type := NM.Raw.t GlobDecl.
Definition raw_alias_table : Type := NM.Raw.t (list name).
#[global] Instance raw_structured_insert : forall {T}, Insert globname T (NM.Raw.t T) := _.
Definition dup_info := list (name * (GlobDecl + ObjValue)).
The accumulator of t: duplicates as in dup_info, and (n, None) for
a symbol n that _symbols dropped. Sharing one accumulator keeps t
as cheap as before when nothing is dropped.
Definition t : Type :=
raw_symbol_table -> raw_type_table -> list name -> raw_alias_table -> list StaticAssert -> dup_acc ->
(raw_symbol_table -> raw_type_table -> list name -> raw_alias_table -> list StaticAssert -> dup_acc -> translation_unit * dup_info) ->
translation_unit * dup_info.
Definition merge_obj_value (a b : ObjValue) : option ObjValue :=
if sub_module.ObjValue_le a b then
Some b
else if sub_module.ObjValue_le b a then Some a
else None.
raw_symbol_table -> raw_type_table -> list name -> raw_alias_table -> list StaticAssert -> dup_acc ->
(raw_symbol_table -> raw_type_table -> list name -> raw_alias_table -> list StaticAssert -> dup_acc -> translation_unit * dup_info) ->
translation_unit * dup_info.
Definition merge_obj_value (a b : ObjValue) : option ObjValue :=
if sub_module.ObjValue_le a b then
Some b
else if sub_module.ObjValue_le b a then Some a
else None.
Constructs a translation_unit.t with one symbol, mapping n to v.
A symbol whose name may not identify one entity (has_unsupportedN) is
dropped: two such entities would otherwise share one _global n, and so
one address. decls records it in dropped_symbols.
Definition _symbols (n : name) (v : ObjValue) : t :=
fun s t ga a asserts dups k =>
if has_unsupportedN n then k s t ga a asserts ((n, None) :: dups) else
match s !! n with
| None => k (<[n := v]> s) t ga a asserts dups
| Some v' => match merge_obj_value v v' with
| Some v => k (<[n:=v]> s) t ga a asserts dups
| None => k s t ga a asserts ((n, Some (inr v)) :: (n, Some (inr v')) :: dups)
end
end.
Definition merge_glob_decl (a b : GlobDecl) : option GlobDecl :=
if sub_module.GlobDecl_le a b then
Some b
else if sub_module.GlobDecl_le b a then Some a
else None.
fun s t ga a asserts dups k =>
if has_unsupportedN n then k s t ga a asserts ((n, None) :: dups) else
match s !! n with
| None => k (<[n := v]> s) t ga a asserts dups
| Some v' => match merge_obj_value v v' with
| Some v => k (<[n:=v]> s) t ga a asserts dups
| None => k s t ga a asserts ((n, Some (inr v)) :: (n, Some (inr v')) :: dups)
end
end.
Definition merge_glob_decl (a b : GlobDecl) : option GlobDecl :=
if sub_module.GlobDecl_le a b then
Some b
else if sub_module.GlobDecl_le b a then Some a
else None.
A type whose name may not identify one entity (has_unsupportedN) is
replaced by this, so that no fact about it is available.
Definition unsupported_name (n : name) : GlobDecl :=
Gunsupported ("Name " ++ pretty.print_name n ++ " may denote several types")%pstring.
Gunsupported ("Name " ++ pretty.print_name n ++ " may denote several types")%pstring.
Constructs a translation_unit.t with one type, mapping n to v.
Definition _types (n : name) (v : GlobDecl) : t :=
fun s t ga a asserts dups k =>
if bool_decide (Gtypedef (Tnamed n) = v \/ Gtypedef (Tenum n) = v)
then
(* ignore self-aliases. These arise when you do
something like
<<
typedef enum memory_order { .. } memory_order;
>>
*)
k s t ga a asserts dups
else
let v := if has_unsupportedN n then unsupported_name n else v in
match t !! n with
| None => k s (<[n := v]> t) ga a asserts dups
| Some v' => match merge_glob_decl v v' with
| Some v => k s (<[n:=v]> t) ga a asserts dups
| None => k s t ga a asserts ((n, Some (inl v)) :: (n, Some (inl v')) :: dups)
end
end.
Definition _type_alias (n : name) (ty : type) : t :=
_types n (Gtypedef ty).
Definition _value_alias (n : name) (canon : name) : t :=
fun s t ga a asserts dups k =>
match a !! n with
| None => k s t ga (<[n := canon :: nil]> a) asserts dups
| Some canon' => k s t ga (<[n := canon :: canon']> a) asserts dups
end.
Definition _global_alias (canon : name) : t :=
fun s t ga a asserts dups k => k s t (canon :: ga) a asserts dups.
Definition _static_assert (msg : option PrimString.string) (e : Expr) : t :=
let msg := match msg with
| Some msg => msg
| None => ""%pstring
end in
fun s t ga a asserts dups k =>
k s t ga a (Build_StaticAssert msg e :: asserts) dups.
fun s t ga a asserts dups k =>
if bool_decide (Gtypedef (Tnamed n) = v \/ Gtypedef (Tenum n) = v)
then
(* ignore self-aliases. These arise when you do
something like
<<
typedef enum memory_order { .. } memory_order;
>>
*)
k s t ga a asserts dups
else
let v := if has_unsupportedN n then unsupported_name n else v in
match t !! n with
| None => k s (<[n := v]> t) ga a asserts dups
| Some v' => match merge_glob_decl v v' with
| Some v => k s (<[n:=v]> t) ga a asserts dups
| None => k s t ga a asserts ((n, Some (inl v)) :: (n, Some (inl v')) :: dups)
end
end.
Definition _type_alias (n : name) (ty : type) : t :=
_types n (Gtypedef ty).
Definition _value_alias (n : name) (canon : name) : t :=
fun s t ga a asserts dups k =>
match a !! n with
| None => k s t ga (<[n := canon :: nil]> a) asserts dups
| Some canon' => k s t ga (<[n := canon :: canon']> a) asserts dups
end.
Definition _global_alias (canon : name) : t :=
fun s t ga a asserts dups k => k s t (canon :: ga) a asserts dups.
Definition _static_assert (msg : option PrimString.string) (e : Expr) : t :=
let msg := match msg with
| Some msg => msg
| None => ""%pstring
end in
fun s t ga a asserts dups k =>
k s t ga a (Build_StaticAssert msg e :: asserts) dups.
Constructs an empty translation_unit.t.
Definition _skip : t :=
fun s t ga a asserts dups k => k s t ga a asserts dups.
Fixpoint array_fold {A B}
(f : A -> B -> B) (ar : PArray.array A) (fuel : nat) (i : PrimInt63.int) (acc : B) : B :=
match fuel with
| 0 => acc
| S fuel =>
array_fold f ar fuel (PrimInt63.add i 1) (f (PArray.get ar i) acc)
end.
Definition decls' (ds : PArray.array t) : t :=
array_fold (fun (X Y : t) s t ga a asserts dups K =>
X s t ga a asserts dups (fun s t ga a asserts dups => Y s t ga a asserts dups K))
ds
(Z.to_nat (Uint63.to_Z (PArray.length ds))) 0%uint63
(fun s t ga a asserts dups k => k s t ga a asserts dups).
Definition conflict (n : name) : ObjValue :=
let error_msg := ("Name collision on " ++ pretty.print_name n ++ " replaced by this dummy function")%pstring in
Ofunction {|
f_return := Tunsupported error_msg;
f_params := [];
f_cc := CC_C;
f_arity := Ar_Definite;
f_exception := exception_spec.Unknown;
f_attrs := [];
f_body := Some (Impl (Sunsupported error_msg))
|}.
fun s t ga a asserts dups k => k s t ga a asserts dups.
Fixpoint array_fold {A B}
(f : A -> B -> B) (ar : PArray.array A) (fuel : nat) (i : PrimInt63.int) (acc : B) : B :=
match fuel with
| 0 => acc
| S fuel =>
array_fold f ar fuel (PrimInt63.add i 1) (f (PArray.get ar i) acc)
end.
Definition decls' (ds : PArray.array t) : t :=
array_fold (fun (X Y : t) s t ga a asserts dups K =>
X s t ga a asserts dups (fun s t ga a asserts dups => Y s t ga a asserts dups K))
ds
(Z.to_nat (Uint63.to_Z (PArray.length ds))) 0%uint63
(fun s t ga a asserts dups k => k s t ga a asserts dups).
Definition conflict (n : name) : ObjValue :=
let error_msg := ("Name collision on " ++ pretty.print_name n ++ " replaced by this dummy function")%pstring in
Ofunction {|
f_return := Tunsupported error_msg;
f_params := [];
f_cc := CC_C;
f_arity := Ar_Definite;
f_exception := exception_spec.Unknown;
f_attrs := [];
f_body := Some (Impl (Sunsupported error_msg))
|}.
Incompatible type definitions sharing a name are replaced by this, so
that no fact about either definition (size, fields, layout, enumerators)
is available.
Definition type_conflict (n : name) : GlobDecl :=
Gunsupported ("Name collision on " ++ pretty.print_name n ++ " replaced by this unsupported type")%pstring.
Definition decls (ds : PArray.array t) (info : abi.t) : translation_unit * dup_info :=
decls' ds ∅ ∅ [] ∅ [] [] $ fun s t ga a asserts acc =>
let dups : dup_info :=
List.fold_right (fun '(n, d) r => if d is Some d then (n, d) :: r else r) [] acc in
let dropped :=
List.fold_right (fun '(n, d) r => if d is None then n :: r else r) [] acc in
pair {|
symbols := List.fold_left (fun t '(n, _) => <[n:=conflict n]> t) dups (NM.from_raw s);
types := List.fold_left (fun t '(n, d) =>
if d is inl _ then <[n:=type_conflict n]> t else t) dups (NM.from_raw t);
namespace_aliases := (Listset (sort.sort ga), NM.from_raw $ NM.Raw.map (fun x => Listset $ sort.sort x) a);
initializer := nil;
Gunsupported ("Name collision on " ++ pretty.print_name n ++ " replaced by this unsupported type")%pstring.
Definition decls (ds : PArray.array t) (info : abi.t) : translation_unit * dup_info :=
decls' ds ∅ ∅ [] ∅ [] [] $ fun s t ga a asserts acc =>
let dups : dup_info :=
List.fold_right (fun '(n, d) r => if d is Some d then (n, d) :: r else r) [] acc in
let dropped :=
List.fold_right (fun '(n, d) r => if d is None then n :: r else r) [] acc in
pair {|
symbols := List.fold_left (fun t '(n, _) => <[n:=conflict n]> t) dups (NM.from_raw s);
types := List.fold_left (fun t '(n, d) =>
if d is inl _ then <[n:=type_conflict n]> t else t) dups (NM.from_raw t);
namespace_aliases := (Listset (sort.sort ga), NM.from_raw $ NM.Raw.map (fun x => Listset $ sort.sort x) a);
initializer := nil;
TODO
asserts := sort_static_assert.sort asserts;
abi := info;
msymbols := ∅;
mtypes := ∅;
maliases := ∅;
minstances := ∅;
dropped_symbols := sort.sort dropped
|} dups.
Definition list_decls (ls : list translation_unit.t) :=
decls $ PArray.of_list _skip ls.
Module make.
Import Ltac2.Ltac2.
Ltac2 Type exn ::= [DuplicateSymbols (constr)].
(* check_translation_unit tu
*)
Ltac2 check_translation_unit (tu : preterm) (en : preterm) :=
let info := Constr.Pretype.pretype Constr.Pretype.Flags.constr_flags (Constr.Pretype.expected_oftype '(abi.t)) en in
let tu := Constr.Pretype.pretype Constr.Pretype.Flags.constr_flags (Constr.Pretype.expected_oftype '(PArray.array t)) tu in
let term := Constr.Unsafe.make (Constr.Unsafe.App ('decls) (Array.of_list [tu; info])) in
let rtu := Std.eval_vm None term in
lazy_match! rtu with
| pair ?tu nil => Std.exact_no_check tu
| pair _ ?dups =>
let _ := Message.print (Message.concat (Message.of_string "Duplicate symbols found in translation unit: ") (Message.of_constr dups)) in
Control.throw (DuplicateSymbols dups)
end.
End make.
Notation check tu en :=
ltac2:(translation_unit.make.check_translation_unit tu en) (only parsing).
End translation_unit.
Export translation_unit(decls).
#[local] Notation K := translation_unit.t (only parsing).
Definition Dvariable (n : obj_name) (t : type) (init : global_init.t) : K :=
_symbols n $ Ovar t init.
Definition Dfunction (n : obj_name) (f : Func) : K :=
_symbols n $ Ofunction f.
Definition Dmethod (n : obj_name) (static : bool) (f : Method) : K :=
_symbols n $ if static then Ofunction $ static_method f else Omethod f.
Definition Dconstructor (n : obj_name) (f : Ctor) : K :=
_symbols n $ Oconstructor f.
Definition Ddestructor (n : obj_name) (f : Dtor) : K :=
_symbols n $ Odestructor f.
Definition Dtype (n : globname) : K :=
_types n $ Gtype.
Definition Dunsupported (n : globname) (msg : PrimString.string) : K :=
_types n $ Gunsupported msg.
abi := info;
msymbols := ∅;
mtypes := ∅;
maliases := ∅;
minstances := ∅;
dropped_symbols := sort.sort dropped
|} dups.
Definition list_decls (ls : list translation_unit.t) :=
decls $ PArray.of_list _skip ls.
Module make.
Import Ltac2.Ltac2.
Ltac2 Type exn ::= [DuplicateSymbols (constr)].
(* check_translation_unit tu
*)
Ltac2 check_translation_unit (tu : preterm) (en : preterm) :=
let info := Constr.Pretype.pretype Constr.Pretype.Flags.constr_flags (Constr.Pretype.expected_oftype '(abi.t)) en in
let tu := Constr.Pretype.pretype Constr.Pretype.Flags.constr_flags (Constr.Pretype.expected_oftype '(PArray.array t)) tu in
let term := Constr.Unsafe.make (Constr.Unsafe.App ('decls) (Array.of_list [tu; info])) in
let rtu := Std.eval_vm None term in
lazy_match! rtu with
| pair ?tu nil => Std.exact_no_check tu
| pair _ ?dups =>
let _ := Message.print (Message.concat (Message.of_string "Duplicate symbols found in translation unit: ") (Message.of_constr dups)) in
Control.throw (DuplicateSymbols dups)
end.
End make.
Notation check tu en :=
ltac2:(translation_unit.make.check_translation_unit tu en) (only parsing).
End translation_unit.
Export translation_unit(decls).
#[local] Notation K := translation_unit.t (only parsing).
Definition Dvariable (n : obj_name) (t : type) (init : global_init.t) : K :=
_symbols n $ Ovar t init.
Definition Dfunction (n : obj_name) (f : Func) : K :=
_symbols n $ Ofunction f.
Definition Dmethod (n : obj_name) (static : bool) (f : Method) : K :=
_symbols n $ if static then Ofunction $ static_method f else Omethod f.
Definition Dconstructor (n : obj_name) (f : Ctor) : K :=
_symbols n $ Oconstructor f.
Definition Ddestructor (n : obj_name) (f : Dtor) : K :=
_symbols n $ Odestructor f.
Definition Dtype (n : globname) : K :=
_types n $ Gtype.
Definition Dunsupported (n : globname) (msg : PrimString.string) : K :=
_types n $ Gunsupported msg.
A complete record whose body cpp2v cannot model; see Opaque.
BRiCk identifies a field by its name (see offset_of), so a record whose
members do not have distinct names is unsupported. sort.sort drops
duplicates.
Definition record_or_dup_fields (n : globname) (fs : list Member) (r : GlobDecl) : GlobDecl :=
let names := List.map (fun m => Nglobal m.(mem_name)) fs in
if Nat.eqb (List.length (sort.sort names)) (List.length names) then r
else Gunsupported ("Duplicate field names in " ++ pretty.print_name n)%pstring.
Definition Dstruct (n : globname) (f : option Struct) : K :=
_types n $ if f is Some f then record_or_dup_fields n f.(s_fields) (Gstruct f) else Gtype.
Definition Dunion (n : globname) (f : option Union) : K :=
_types n $ if f is Some f then record_or_dup_fields n f.(u_fields) (Gunion f) else Gtype.
Definition Denum (n : globname) (u : type) (cs : list ident) : K :=
_types n $ Genum u cs.
Definition Denum_constant (n : globname)
(gn : globname) (ut : exprtype) (v : N + Z) (init : option Expr) : K :=
_types n $
let v := match v with inl n => Echar n ut | inr z => Eint z ut end in
let t := Tenum gn in
Gconstant t $ Some $ Ecast (Cintegral t) v.
Definition Dtypedef (n : globname) (t : type) : K :=
_type_alias n t.
Definition Dinline_namespace (ns : name) (child : ident) : K :=
_value_alias ns (Nscoped ns (Nid child)).
Definition Dusing_namespace (alias : name) (canonical : name) : K :=
_value_alias alias canonical.
Definition Dglobal_using_namespace (alias : name) : K :=
_global_alias alias.
Definition Dstatic_assert (msg : option PrimString.string) (e : Expr) : K :=
_static_assert msg e.
Definition Oimplicit_default_ctor (n : globname) : K :=
let ctor := Oconstructor
{| c_class := n
; c_params := []
; c_cc := CC_C
; c_arity := Ar_Definite
; c_exception := exception_spec.Unknown (* TODO: problematic? *)
; c_body := Some Defaulted |} in
_symbols (Nscoped n $ Nctor []) ctor.
Definition Oimplicit_copy_ctor (n : globname) (is_const : bool) : K :=
let arg := Tref $ if is_const then (Tconst (Tnamed n)) else Tnamed n in
let ctor := Oconstructor
{| c_class := n
; c_params := [("#0"%pstring, arg)]
; c_cc := CC_C
; c_arity := Ar_Definite
; c_exception := exception_spec.Unknown (* TODO: problematic? *)
; c_body := Some Defaulted |} in
_symbols (Nscoped n $ Nctor [arg]) ctor.
let names := List.map (fun m => Nglobal m.(mem_name)) fs in
if Nat.eqb (List.length (sort.sort names)) (List.length names) then r
else Gunsupported ("Duplicate field names in " ++ pretty.print_name n)%pstring.
Definition Dstruct (n : globname) (f : option Struct) : K :=
_types n $ if f is Some f then record_or_dup_fields n f.(s_fields) (Gstruct f) else Gtype.
Definition Dunion (n : globname) (f : option Union) : K :=
_types n $ if f is Some f then record_or_dup_fields n f.(u_fields) (Gunion f) else Gtype.
Definition Denum (n : globname) (u : type) (cs : list ident) : K :=
_types n $ Genum u cs.
Definition Denum_constant (n : globname)
(gn : globname) (ut : exprtype) (v : N + Z) (init : option Expr) : K :=
_types n $
let v := match v with inl n => Echar n ut | inr z => Eint z ut end in
let t := Tenum gn in
Gconstant t $ Some $ Ecast (Cintegral t) v.
Definition Dtypedef (n : globname) (t : type) : K :=
_type_alias n t.
Definition Dinline_namespace (ns : name) (child : ident) : K :=
_value_alias ns (Nscoped ns (Nid child)).
Definition Dusing_namespace (alias : name) (canonical : name) : K :=
_value_alias alias canonical.
Definition Dglobal_using_namespace (alias : name) : K :=
_global_alias alias.
Definition Dstatic_assert (msg : option PrimString.string) (e : Expr) : K :=
_static_assert msg e.
Definition Oimplicit_default_ctor (n : globname) : K :=
let ctor := Oconstructor
{| c_class := n
; c_params := []
; c_cc := CC_C
; c_arity := Ar_Definite
; c_exception := exception_spec.Unknown (* TODO: problematic? *)
; c_body := Some Defaulted |} in
_symbols (Nscoped n $ Nctor []) ctor.
Definition Oimplicit_copy_ctor (n : globname) (is_const : bool) : K :=
let arg := Tref $ if is_const then (Tconst (Tnamed n)) else Tnamed n in
let ctor := Oconstructor
{| c_class := n
; c_params := [("#0"%pstring, arg)]
; c_cc := CC_C
; c_arity := Ar_Definite
; c_exception := exception_spec.Unknown (* TODO: problematic? *)
; c_body := Some Defaulted |} in
_symbols (Nscoped n $ Nctor [arg]) ctor.
The form is always
X::X(X&&), in every standard from C++17 (N4659) on
(https://eel.is/c++draft/class.copy.ctor9). The [bool] is accepted only
so that existing cpp2v output, which always passes [false], still parses.
Definition Oimplicit_move_ctor (n : globname) (_ : bool) : K :=
let arg := Trv_ref $ Tnamed n in
let ctor := Oconstructor
{| c_class := n
; c_params := [("#0"%pstring, arg)]
; c_cc := CC_C
; c_arity := Ar_Definite
; c_exception := exception_spec.Unknown (* TODO: problematic? *)
; c_body := Some Defaulted |} in
_symbols (Nscoped n $ Nctor [arg]) ctor.
let arg := Trv_ref $ Tnamed n in
let ctor := Oconstructor
{| c_class := n
; c_params := [("#0"%pstring, arg)]
; c_cc := CC_C
; c_arity := Ar_Definite
; c_exception := exception_spec.Unknown (* TODO: problematic? *)
; c_body := Some Defaulted |} in
_symbols (Nscoped n $ Nctor [arg]) ctor.
is_const picks the parameter, >
either way (https://eel.is/c++draft/class.copy.assign6). Both are the
same in every standard from C++17 (N4659) on.
const X& or X&
(https://eel.is/c++draft/class.copy.assign2); the return type is <
Definition Oimplicit_copy_assign (n : globname) (is_const : bool) : K :=
let arg := Tref $ if is_const then (Tconst (Tnamed n)) else Tnamed n in
let ctor := Omethod
{| m_class := n
; m_params := [("#0"%pstring, arg)]
; m_return := Tref (Tnamed n)
; m_this_qual := QM
; m_cc := CC_C
; m_arity := Ar_Definite
; m_exception := exception_spec.Unknown (* TODO: problematic? *)
; m_attrs := []
; m_body := Some Defaulted |} in
_symbols (Nscoped n $ Nop function_qualifiers.N OOEqual [arg]) ctor.
Definition Oimplicit_move_assign (n : globname) : K :=
let arg := Tnamed n in
let ctor := Omethod
{| m_class := n
; m_params := [("#0"%pstring, Trv_ref arg)]
; m_return := Tref (Tnamed n)
; m_this_qual := QM
; m_cc := CC_C
; m_arity := Ar_Definite
; m_exception := exception_spec.Unknown (* TODO: problematic? *)
; m_attrs := []
; m_body := Some Defaulted |} in
_symbols (Nscoped n $ Nop function_qualifiers.N OOEqual [Trv_ref arg]) ctor.
Definition Oimplicit_dtor (n : globname) : K :=
let dtor := Odestructor
{| d_class := n
; d_cc := CC_C
; d_exception := exception_spec.Unknown (* TODO: problematic? *)
; d_body := Some Defaulted |} in
_symbols (Nscoped n $ Ndtor) dtor.
Definition Qconst_volatile : type -> type := tqualified QCV.
Definition Qconst : type -> type := tqualified QC.
Definition Qvolatile : type -> type := tqualified QV.
let arg := Tref $ if is_const then (Tconst (Tnamed n)) else Tnamed n in
let ctor := Omethod
{| m_class := n
; m_params := [("#0"%pstring, arg)]
; m_return := Tref (Tnamed n)
; m_this_qual := QM
; m_cc := CC_C
; m_arity := Ar_Definite
; m_exception := exception_spec.Unknown (* TODO: problematic? *)
; m_attrs := []
; m_body := Some Defaulted |} in
_symbols (Nscoped n $ Nop function_qualifiers.N OOEqual [arg]) ctor.
Definition Oimplicit_move_assign (n : globname) : K :=
let arg := Tnamed n in
let ctor := Omethod
{| m_class := n
; m_params := [("#0"%pstring, Trv_ref arg)]
; m_return := Tref (Tnamed n)
; m_this_qual := QM
; m_cc := CC_C
; m_arity := Ar_Definite
; m_exception := exception_spec.Unknown (* TODO: problematic? *)
; m_attrs := []
; m_body := Some Defaulted |} in
_symbols (Nscoped n $ Nop function_qualifiers.N OOEqual [Trv_ref arg]) ctor.
Definition Oimplicit_dtor (n : globname) : K :=
let dtor := Odestructor
{| d_class := n
; d_cc := CC_C
; d_exception := exception_spec.Unknown (* TODO: problematic? *)
; d_body := Some Defaulted |} in
_symbols (Nscoped n $ Ndtor) dtor.
Definition Qconst_volatile : type -> type := tqualified QCV.
Definition Qconst : type -> type := tqualified QC.
Definition Qvolatile : type -> type := tqualified QV.