Skip to content

Commit d64dabf

Browse files
committed
Factor out copyable and use it on meta::object_declaration
1 parent 82ddf2e commit d64dabf

File tree

3 files changed

+90
-55
lines changed

3 files changed

+90
-55
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8507:1440
2+
cppfront compiler v0.2.1 Build 8507:1526
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/reflect.h

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ namespace meta {
1616
#line 289 "reflect.h2"
1717
class object_declaration;
1818

19-
#line 316 "reflect.h2"
19+
#line 314 "reflect.h2"
2020
}
2121
}
2222

23-
#line 436 "reflect.h2"
23+
#line 434 "reflect.h2"
2424
namespace cpp2 {
2525

26-
#line 739 "reflect.h2"
26+
#line 748 "reflect.h2"
2727
}
2828

2929

@@ -329,17 +329,18 @@ class object_declaration
329329
);
330330

331331
#line 303 "reflect.h2"
332-
public: object_declaration(object_declaration const& that);
333-
334332
public: [[nodiscard]] auto is_const() const -> bool;
335333

336334
public: [[nodiscard]] auto has_wildcard_type() const -> bool;
337335

336+
public: object_declaration(object_declaration const& that);
337+
338338
// TODO: auto get_type() const ->
339339

340+
#line 309 "reflect.h2"
340341
};
341342

342-
#line 314 "reflect.h2"
343+
#line 312 "reflect.h2"
343344
//=======================================================================
344345
// Switch to Cpp1
345346
}
@@ -478,7 +479,7 @@ namespace cpp2 {
478479
//
479480
auto add_virtual_destructor(meta::type_declaration& t) -> void;
480481

481-
#line 457 "reflect.h2"
482+
#line 455 "reflect.h2"
482483
//-----------------------------------------------------------------------
483484
//
484485
// "... an abstract base class defines an interface ..."
@@ -493,7 +494,7 @@ auto add_virtual_destructor(meta::type_declaration& t) -> void;
493494
//
494495
auto interface(meta::type_declaration& t) -> void;
495496

496-
#line 496 "reflect.h2"
497+
#line 494 "reflect.h2"
497498
//-----------------------------------------------------------------------
498499
//
499500
// "C.35: A base class destructor should be either public and
@@ -516,7 +517,7 @@ auto interface(meta::type_declaration& t) -> void;
516517
//
517518
auto polymorphic_base(meta::type_declaration& t) -> void;
518519

519-
#line 541 "reflect.h2"
520+
#line 539 "reflect.h2"
520521
//-----------------------------------------------------------------------
521522
//
522523
// "... A totally ordered type ... requires operator<=> that
@@ -542,27 +543,27 @@ auto ordered_impl(
542543
cpp2::in<std::string_view> ordering// must be "strong_ordering" etc.
543544
) -> void;
544545

545-
#line 586 "reflect.h2"
546+
#line 584 "reflect.h2"
546547
//-----------------------------------------------------------------------
547548
// ordered - a totally ordered type
548549
//
549550
// Note: the ordering that should be encouraged as default gets the nice name
550551
//
551552
auto ordered(meta::type_declaration& t) -> void;
552553

553-
#line 596 "reflect.h2"
554+
#line 594 "reflect.h2"
554555
//-----------------------------------------------------------------------
555556
// weakly_ordered - a weakly ordered type
556557
//
557558
auto weakly_ordered(meta::type_declaration& t) -> void;
558559

559-
#line 604 "reflect.h2"
560+
#line 602 "reflect.h2"
560561
//-----------------------------------------------------------------------
561562
// partially_ordered - a partially ordered type
562563
//
563564
auto partially_ordered(meta::type_declaration& t) -> void;
564565

565-
#line 613 "reflect.h2"
566+
#line 611 "reflect.h2"
566567
//-----------------------------------------------------------------------
567568
//
568569
// "A value is ... a regular type. It must have all public
@@ -575,14 +576,23 @@ auto partially_ordered(meta::type_declaration& t) -> void;
575576
//
576577
//-----------------------------------------------------------------------
577578
//
579+
// copyable
580+
//
581+
// A type with (copy and move) x (construction and assignment)
582+
//
583+
auto copyable(meta::type_declaration& t) -> void;
584+
585+
#line 649 "reflect.h2"
586+
//-----------------------------------------------------------------------
587+
//
578588
// basic_value
579589
//
580-
// A regular type: public default construction, copy/move construction
581-
// and assignment, and no protected or virtual functions
590+
// A regular type: copyable, plus has public default construction
591+
// and no protected or virtual functions
582592
//
583593
auto basic_value(meta::type_declaration& t) -> void;
584594

585-
#line 666 "reflect.h2"
595+
#line 675 "reflect.h2"
586596
//-----------------------------------------------------------------------
587597
//
588598
// "A 'value' is a totally ordered basic_value..."
@@ -594,13 +604,13 @@ auto basic_value(meta::type_declaration& t) -> void;
594604
//
595605
auto value(meta::type_declaration& t) -> void;
596606

597-
#line 681 "reflect.h2"
607+
#line 690 "reflect.h2"
598608
auto weakly_ordered_value(meta::type_declaration& t) -> void;
599609

600-
#line 687 "reflect.h2"
610+
#line 696 "reflect.h2"
601611
auto partially_ordered_value(meta::type_declaration& t) -> void;
602612

603-
#line 694 "reflect.h2"
613+
#line 703 "reflect.h2"
604614
//-----------------------------------------------------------------------
605615
//
606616
// "By definition, a `struct` is a `class` in which members
@@ -628,7 +638,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void;
628638
//
629639
auto cpp2_struct(meta::type_declaration& t) -> void;
630640

631-
#line 737 "reflect.h2"
641+
#line 746 "reflect.h2"
632642
//=======================================================================
633643
// Switch to Cpp1
634644
}
@@ -671,6 +681,12 @@ auto parser::apply_type_meta_functions( declaration_node& n )
671681
else if (meta->to_string() == "partially_ordered") {
672682
partially_ordered( rtype );
673683
}
684+
else if (meta->to_string() == "copyable") {
685+
copyable( rtype );
686+
}
687+
else if (meta->to_string() == "basic_value") {
688+
basic_value( rtype );
689+
}
674690
else if (meta->to_string() == "value") {
675691
value( rtype );
676692
}
@@ -684,7 +700,7 @@ auto parser::apply_type_meta_functions( declaration_node& n )
684700
cpp2_struct( rtype );
685701
}
686702
else {
687-
error( "(temporary alpha limitation) unrecognized metafunction name '" + meta->to_string() + "' - currently the supported names are: interface, polymorphic_base, ordered, weakly_ordered, partially_ordered, value, weakly_ordered_value, partially_ordered_value, struct" );
703+
error( "(temporary alpha limitation) unrecognized metafunction name '" + meta->to_string() + "' - currently the supported names are: interface, polymorphic_base, ordered, weakly_ordered, partially_ordered, copyable, basic_value, value, weakly_ordered_value, partially_ordered_value, struct" );
688704
return false;
689705
}
690706
}
@@ -715,30 +731,28 @@ namespace meta {
715731
cpp2::Default.expects(CPP2_UFCS_0(is_object, (*cpp2::assert_not_null(n))), "");
716732
}
717733

718-
object_declaration::object_declaration(object_declaration const& that)
719-
: declaration{ that }
720-
#line 303 "reflect.h2"
721-
{}
722-
723734
[[nodiscard]] auto object_declaration::is_const() const -> bool { return CPP2_UFCS_0(is_const, (*cpp2::assert_not_null(n))); }
724735

725736
[[nodiscard]] auto object_declaration::has_wildcard_type() const -> bool { return CPP2_UFCS_0(has_wildcard_type, (*cpp2::assert_not_null(n))); }
726737

727-
#line 316 "reflect.h2"
738+
object_declaration::object_declaration(object_declaration const& that)
739+
: declaration{ that }{}
740+
741+
#line 314 "reflect.h2"
728742
}
729743
}
730744

731-
#line 436 "reflect.h2"
745+
#line 434 "reflect.h2"
732746
namespace cpp2 {
733747

734-
#line 450 "reflect.h2"
748+
#line 448 "reflect.h2"
735749
auto add_virtual_destructor(meta::type_declaration& t) -> void
736750
{
737751
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator=: (virtual move this) = { }"),
738752
"could not add virtual destructor");
739753
}
740754

741-
#line 469 "reflect.h2"
755+
#line 467 "reflect.h2"
742756
auto interface(meta::type_declaration& t) -> void
743757
{
744758
auto has_dtor {false};
@@ -760,13 +774,13 @@ auto interface(meta::type_declaration& t) -> void
760774
}
761775
}}
762776

763-
#line 490 "reflect.h2"
777+
#line 488 "reflect.h2"
764778
if (!(std::move(has_dtor))) {
765779
add_virtual_destructor(t);
766780
}
767781
}
768782

769-
#line 516 "reflect.h2"
783+
#line 514 "reflect.h2"
770784
auto polymorphic_base(meta::type_declaration& t) -> void
771785
{
772786
auto has_dtor {false};
@@ -786,13 +800,13 @@ auto polymorphic_base(meta::type_declaration& t) -> void
786800
}
787801
}}
788802

789-
#line 535 "reflect.h2"
803+
#line 533 "reflect.h2"
790804
if (!(std::move(has_dtor))) {
791805
add_virtual_destructor(t);
792806
}
793807
}
794808

795-
#line 561 "reflect.h2"
809+
#line 559 "reflect.h2"
796810
auto ordered_impl(
797811
meta::type_declaration& t,
798812
cpp2::in<std::string_view> ordering
@@ -812,33 +826,33 @@ auto ordered_impl(
812826
}
813827
}}
814828

815-
#line 580 "reflect.h2"
829+
#line 578 "reflect.h2"
816830
if (!(std::move(has_spaceship))) {
817831
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator<=>: (this, that) -> std::" + (cpp2::as_<std::string>(ordering)) + ";"),
818832
"could not add operator<=> with std::" + (cpp2::as_<std::string>(ordering)));
819833
}
820834
}
821835

822-
#line 591 "reflect.h2"
836+
#line 589 "reflect.h2"
823837
auto ordered(meta::type_declaration& t) -> void
824838
{
825839
ordered_impl(t, "strong_ordering");
826840
}
827841

828-
#line 599 "reflect.h2"
842+
#line 597 "reflect.h2"
829843
auto weakly_ordered(meta::type_declaration& t) -> void
830844
{
831845
ordered_impl(t, "weak_ordering");
832846
}
833847

834-
#line 607 "reflect.h2"
848+
#line 605 "reflect.h2"
835849
auto partially_ordered(meta::type_declaration& t) -> void
836850
{
837851
ordered_impl(t, "partial_ordering");
838852
}
839853

840-
#line 630 "reflect.h2"
841-
auto basic_value(meta::type_declaration& t) -> void
854+
#line 627 "reflect.h2"
855+
auto copyable(meta::type_declaration& t) -> void
842856
{
843857
// If the user explicitly wrote any of the copy/move functions,
844858
// they must also have written the most general one - we can't
@@ -858,6 +872,12 @@ auto basic_value(meta::type_declaration& t) -> void
858872
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator=: (out this, that) = { }"),
859873
"could not add general operator=:(out this, that)");
860874
}}
875+
}
876+
877+
#line 656 "reflect.h2"
878+
auto basic_value(meta::type_declaration& t) -> void
879+
{
880+
copyable(t);
861881

862882
auto has_default_ctor {false};
863883
{ auto&& cpp2_range = CPP2_UFCS_0(get_member_functions, t); for ( auto& mf : cpp2_range ) {
@@ -868,14 +888,14 @@ auto basic_value(meta::type_declaration& t) -> void
868888
"a value type may not have a non-public destructor");
869889
}}
870890

871-
#line 660 "reflect.h2"
891+
#line 669 "reflect.h2"
872892
if (!(std::move(has_default_ctor))) {
873893
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator=: (out this) = { }"),
874894
"could not add default constructor");
875895
}
876896
}
877897

878-
#line 675 "reflect.h2"
898+
#line 684 "reflect.h2"
879899
auto value(meta::type_declaration& t) -> void
880900
{
881901
ordered(t);
@@ -894,7 +914,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void
894914
basic_value(t);
895915
}
896916

897-
#line 719 "reflect.h2"
917+
#line 728 "reflect.h2"
898918
auto cpp2_struct(meta::type_declaration& t) -> void
899919
{
900920
{ auto&& cpp2_range = CPP2_UFCS_0(get_members, t); for ( auto& m : cpp2_range )
@@ -909,11 +929,11 @@ auto cpp2_struct(meta::type_declaration& t) -> void
909929
"a struct may not have a user-defined operator=");
910930
}
911931
}}
912-
#line 733 "reflect.h2"
932+
#line 742 "reflect.h2"
913933
basic_value(t); // a plain_struct is-a basic_value
914934
}
915935

916-
#line 739 "reflect.h2"
936+
#line 748 "reflect.h2"
917937
}
918938

919939
#endif

0 commit comments

Comments
 (0)