Skip to content

Commit 327495b

Browse files
Merge pull request #251 from SkyLabsAI/gmalecha/parser-const-scoped-conversion-functions
Bug fix for parsing const, scoped conversion functions
2 parents 49f8618 + e82fe76 commit 327495b

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

  • rocq-skylabs-brick/theories/lang/cpp/syntax/name_notation

rocq-skylabs-brick/theories/lang/cpp/syntax/name_notation/parser.v

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,23 @@ Module internal.
427427
let* post := parse_postfix_type in
428428
mret $ post (List.fold_right (fun f x => f x) t quals).
429429

430-
Fixpoint as_conv (q : function_qualifiers.t) (t : type) : option (type * list type * function_qualifiers.t) :=
430+
Fixpoint final_function (nm : name) : option (name * list type * function_qualifiers.t) :=
431+
match nm with
432+
| Nglobal (Nfunction q nm []) => Some (Nglobal (Nid nm), [], q)
433+
| Nscoped s (Nfunction q nm []) => Some (Nscoped s (Nid nm), [], q)
434+
| Ninst n inst => (fun '(nm, args, q) => (Ninst nm inst, args, q)) <$> final_function n
435+
| _ => None
436+
end.
437+
438+
Fixpoint as_conv (q : function_qualifiers.t) (t : type)
439+
: option (type * list type * function_qualifiers.t) :=
431440
match t with
432441
| Tqualified cv t =>
433442
as_conv (function_qualifiers.join q $ function_qualifiers.mk (q_const cv) (q_volatile cv) Prvalue) t
434443
| Tref t => as_conv (function_qualifiers.join q $ function_qualifiers.mk false false Lvalue) t
435444
| Trv_ref t => as_conv (function_qualifiers.join q $ function_qualifiers.mk false false Xvalue) t
436445
| Tfunction ft => Some (ft.(ft_return), ft.(ft_params), q)
446+
| Tnamed nm => (fun '(nm, args, q') => (Tnamed nm, args, function_qualifiers.join q' q)) <$> final_function nm
437447
| _ => None
438448
end.
439449

@@ -817,6 +827,17 @@ Module Type TESTS.
817827
Succeed Example _0 : TEST "foo(typename $T)" (Nglobal (Nfunction function_qualifiers.N "foo" [Tparam "T"])) := eq_refl.
818828
Succeed Example _0 : TEST "foo(typename $T::nested)" (Nglobal (Nfunction function_qualifiers.N "foo" [Tnamed (Nscoped (Ndependent (Tparam "T")) (Nid "nested"))])) := eq_refl.
819829

830+
Succeed Example _0 : TEST "C::foo() const" (Nscoped (Nglobal (Nid "C")) (Nfunction function_qualifiers.Nc "foo" [])) := eq_refl.
831+
Succeed Example _0 : TEST "C::operator foo() const" (Nscoped (Nglobal (Nid "C")) (Nop_conv function_qualifiers.Nc (Tnamed (Nglobal $ Nid "foo")))) := eq_refl.
832+
833+
Succeed Example _0 : TEST "std::strong_ordering::operator std::partial_ordering() const"
834+
(Nscoped (Nscoped (Nglobal (Nid "std")) (Nid "strong_ordering"))
835+
(Nop_conv function_qualifiers.Nc (Tnamed (Nscoped (Nglobal (Nid "std")) (Nid "partial_ordering"))))) := eq_refl.
836+
837+
Succeed Example _0 : TEST "std::operator foo<int>() const"
838+
(Nscoped (Nglobal (Nid "std"))
839+
(Nop_conv function_qualifiers.Nc (Tnamed (Ninst (Nglobal (Nid "foo")) [Atype Tint])))) := eq_refl.
840+
820841
(* known issues *)
821842

822843
(* NOTE: non-standard names *)

0 commit comments

Comments
 (0)