Skip to content

Commit 82ddf2e

Browse files
committed
Actually emit correct source_position on metafunction error messages
1 parent 59fc520 commit 82ddf2e

File tree

3 files changed

+68
-64
lines changed

3 files changed

+68
-64
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:1428
2+
cppfront compiler v0.2.1 Build 8507:1440
33
Copyright(c) Herb Sutter All rights reserved
44

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

source/reflect.h

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
#include "cpp2util.h"
1010

1111

12-
#line 281 "reflect.h2"
12+
#line 283 "reflect.h2"
1313
namespace cpp2 {
1414
namespace meta {
1515

16-
#line 287 "reflect.h2"
16+
#line 289 "reflect.h2"
1717
class object_declaration;
1818

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

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

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

2929

@@ -132,29 +132,31 @@ class compiler_services
132132
}
133133

134134
public:
135+
virtual auto position() const
136+
-> source_position
137+
{
138+
return {};
139+
}
140+
135141
auto require(
136142
bool b,
137-
std::string_view msg,
138-
source_position pos = source_position{}
143+
std::string_view msg
139144
) const
140145
-> void
141146
{
142147
if (!b) {
143-
error( msg, pos );
148+
error( msg );
144149
}
145150
}
146151

147-
auto error(
148-
std::string_view msg,
149-
source_position pos = source_position{}
150-
) const
152+
auto error(std::string_view msg) const
151153
-> void
152154
{
153155
auto message = std::string{msg};
154156
if (!meta_function_name.empty()) {
155157
message = "while applying @" + meta_function_name + " - " + message;
156158
}
157-
errors->emplace_back( pos, message );
159+
errors->emplace_back( position(), message);
158160
}
159161
};
160162

@@ -183,6 +185,8 @@ class declaration_base : public compiler_services
183185
{
184186
assert(n && "a meta::declaration must point to a valid declaration_node, not null");
185187
}
188+
189+
auto position() const -> source_position override { return n->position(); }
186190
};
187191

188192
class function_declaration;
@@ -204,8 +208,6 @@ class declaration
204208
: declaration_base{n_, s}
205209
{ }
206210

207-
auto position() const -> source_position { return n->position(); }
208-
209211
auto is_public () const -> bool { return n->is_public(); }
210212
auto is_protected () const -> bool { return n->is_protected(); }
211213
auto is_private () const -> bool { return n->is_private(); }
@@ -309,7 +311,7 @@ auto declaration::as_function() const
309311
// Switch to Cpp2
310312
}
311313
}
312-
#line 281 "reflect.h2"
314+
#line 283 "reflect.h2"
313315
namespace cpp2 {
314316
namespace meta {
315317

@@ -319,14 +321,14 @@ namespace meta {
319321
class object_declaration
320322
: public declaration {
321323

322-
#line 291 "reflect.h2"
324+
#line 293 "reflect.h2"
323325
public: object_declaration(
324326

325327
cpp2::in<declaration_node*> n_,
326328
cpp2::in<compiler_services> s
327329
);
328330

329-
#line 301 "reflect.h2"
331+
#line 303 "reflect.h2"
330332
public: object_declaration(object_declaration const& that);
331333

332334
public: [[nodiscard]] auto is_const() const -> bool;
@@ -337,7 +339,7 @@ class object_declaration
337339

338340
};
339341

340-
#line 312 "reflect.h2"
342+
#line 314 "reflect.h2"
341343
//=======================================================================
342344
// Switch to Cpp1
343345
}
@@ -476,7 +478,7 @@ namespace cpp2 {
476478
//
477479
auto add_virtual_destructor(meta::type_declaration& t) -> void;
478480

479-
#line 455 "reflect.h2"
481+
#line 457 "reflect.h2"
480482
//-----------------------------------------------------------------------
481483
//
482484
// "... an abstract base class defines an interface ..."
@@ -491,7 +493,7 @@ auto add_virtual_destructor(meta::type_declaration& t) -> void;
491493
//
492494
auto interface(meta::type_declaration& t) -> void;
493495

494-
#line 494 "reflect.h2"
496+
#line 496 "reflect.h2"
495497
//-----------------------------------------------------------------------
496498
//
497499
// "C.35: A base class destructor should be either public and
@@ -514,7 +516,7 @@ auto interface(meta::type_declaration& t) -> void;
514516
//
515517
auto polymorphic_base(meta::type_declaration& t) -> void;
516518

517-
#line 539 "reflect.h2"
519+
#line 541 "reflect.h2"
518520
//-----------------------------------------------------------------------
519521
//
520522
// "... A totally ordered type ... requires operator<=> that
@@ -540,27 +542,27 @@ auto ordered_impl(
540542
cpp2::in<std::string_view> ordering// must be "strong_ordering" etc.
541543
) -> void;
542544

543-
#line 584 "reflect.h2"
545+
#line 586 "reflect.h2"
544546
//-----------------------------------------------------------------------
545547
// ordered - a totally ordered type
546548
//
547549
// Note: the ordering that should be encouraged as default gets the nice name
548550
//
549551
auto ordered(meta::type_declaration& t) -> void;
550552

551-
#line 594 "reflect.h2"
553+
#line 596 "reflect.h2"
552554
//-----------------------------------------------------------------------
553555
// weakly_ordered - a weakly ordered type
554556
//
555557
auto weakly_ordered(meta::type_declaration& t) -> void;
556558

557-
#line 602 "reflect.h2"
559+
#line 604 "reflect.h2"
558560
//-----------------------------------------------------------------------
559561
// partially_ordered - a partially ordered type
560562
//
561563
auto partially_ordered(meta::type_declaration& t) -> void;
562564

563-
#line 611 "reflect.h2"
565+
#line 613 "reflect.h2"
564566
//-----------------------------------------------------------------------
565567
//
566568
// "A value is ... a regular type. It must have all public
@@ -580,7 +582,7 @@ auto partially_ordered(meta::type_declaration& t) -> void;
580582
//
581583
auto basic_value(meta::type_declaration& t) -> void;
582584

583-
#line 664 "reflect.h2"
585+
#line 666 "reflect.h2"
584586
//-----------------------------------------------------------------------
585587
//
586588
// "A 'value' is a totally ordered basic_value..."
@@ -592,13 +594,13 @@ auto basic_value(meta::type_declaration& t) -> void;
592594
//
593595
auto value(meta::type_declaration& t) -> void;
594596

595-
#line 679 "reflect.h2"
597+
#line 681 "reflect.h2"
596598
auto weakly_ordered_value(meta::type_declaration& t) -> void;
597599

598-
#line 685 "reflect.h2"
600+
#line 687 "reflect.h2"
599601
auto partially_ordered_value(meta::type_declaration& t) -> void;
600602

601-
#line 692 "reflect.h2"
603+
#line 694 "reflect.h2"
602604
//-----------------------------------------------------------------------
603605
//
604606
// "By definition, a `struct` is a `class` in which members
@@ -626,7 +628,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void;
626628
//
627629
auto cpp2_struct(meta::type_declaration& t) -> void;
628630

629-
#line 735 "reflect.h2"
631+
#line 737 "reflect.h2"
630632
//=======================================================================
631633
// Switch to Cpp1
632634
}
@@ -696,47 +698,47 @@ auto parser::apply_type_meta_functions( declaration_node& n )
696698
//=== Cpp2 function definitions =================================================
697699

698700

699-
#line 281 "reflect.h2"
701+
#line 283 "reflect.h2"
700702
namespace cpp2 {
701703
namespace meta {
702704

703-
#line 291 "reflect.h2"
705+
#line 293 "reflect.h2"
704706
object_declaration::object_declaration(
705707

706708
cpp2::in<declaration_node*> n_,
707709
cpp2::in<compiler_services> s
708710
)
709711
: declaration{ n_, s }
710-
#line 296 "reflect.h2"
712+
#line 298 "reflect.h2"
711713
{
712714

713715
cpp2::Default.expects(CPP2_UFCS_0(is_object, (*cpp2::assert_not_null(n))), "");
714716
}
715717

716718
object_declaration::object_declaration(object_declaration const& that)
717719
: declaration{ that }
718-
#line 301 "reflect.h2"
720+
#line 303 "reflect.h2"
719721
{}
720722

721723
[[nodiscard]] auto object_declaration::is_const() const -> bool { return CPP2_UFCS_0(is_const, (*cpp2::assert_not_null(n))); }
722724

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

725-
#line 314 "reflect.h2"
727+
#line 316 "reflect.h2"
726728
}
727729
}
728730

729-
#line 434 "reflect.h2"
731+
#line 436 "reflect.h2"
730732
namespace cpp2 {
731733

732-
#line 448 "reflect.h2"
734+
#line 450 "reflect.h2"
733735
auto add_virtual_destructor(meta::type_declaration& t) -> void
734736
{
735737
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator=: (virtual move this) = { }"),
736738
"could not add virtual destructor");
737739
}
738740

739-
#line 467 "reflect.h2"
741+
#line 469 "reflect.h2"
740742
auto interface(meta::type_declaration& t) -> void
741743
{
742744
auto has_dtor {false};
@@ -758,13 +760,13 @@ auto interface(meta::type_declaration& t) -> void
758760
}
759761
}}
760762

761-
#line 488 "reflect.h2"
763+
#line 490 "reflect.h2"
762764
if (!(std::move(has_dtor))) {
763765
add_virtual_destructor(t);
764766
}
765767
}
766768

767-
#line 514 "reflect.h2"
769+
#line 516 "reflect.h2"
768770
auto polymorphic_base(meta::type_declaration& t) -> void
769771
{
770772
auto has_dtor {false};
@@ -784,13 +786,13 @@ auto polymorphic_base(meta::type_declaration& t) -> void
784786
}
785787
}}
786788

787-
#line 533 "reflect.h2"
789+
#line 535 "reflect.h2"
788790
if (!(std::move(has_dtor))) {
789791
add_virtual_destructor(t);
790792
}
791793
}
792794

793-
#line 559 "reflect.h2"
795+
#line 561 "reflect.h2"
794796
auto ordered_impl(
795797
meta::type_declaration& t,
796798
cpp2::in<std::string_view> ordering
@@ -810,32 +812,32 @@ auto ordered_impl(
810812
}
811813
}}
812814

813-
#line 578 "reflect.h2"
815+
#line 580 "reflect.h2"
814816
if (!(std::move(has_spaceship))) {
815817
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator<=>: (this, that) -> std::" + (cpp2::as_<std::string>(ordering)) + ";"),
816818
"could not add operator<=> with std::" + (cpp2::as_<std::string>(ordering)));
817819
}
818820
}
819821

820-
#line 589 "reflect.h2"
822+
#line 591 "reflect.h2"
821823
auto ordered(meta::type_declaration& t) -> void
822824
{
823825
ordered_impl(t, "strong_ordering");
824826
}
825827

826-
#line 597 "reflect.h2"
828+
#line 599 "reflect.h2"
827829
auto weakly_ordered(meta::type_declaration& t) -> void
828830
{
829831
ordered_impl(t, "weak_ordering");
830832
}
831833

832-
#line 605 "reflect.h2"
834+
#line 607 "reflect.h2"
833835
auto partially_ordered(meta::type_declaration& t) -> void
834836
{
835837
ordered_impl(t, "partial_ordering");
836838
}
837839

838-
#line 628 "reflect.h2"
840+
#line 630 "reflect.h2"
839841
auto basic_value(meta::type_declaration& t) -> void
840842
{
841843
// If the user explicitly wrote any of the copy/move functions,
@@ -866,14 +868,14 @@ auto basic_value(meta::type_declaration& t) -> void
866868
"a value type may not have a non-public destructor");
867869
}}
868870

869-
#line 658 "reflect.h2"
871+
#line 660 "reflect.h2"
870872
if (!(std::move(has_default_ctor))) {
871873
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator=: (out this) = { }"),
872874
"could not add default constructor");
873875
}
874876
}
875877

876-
#line 673 "reflect.h2"
878+
#line 675 "reflect.h2"
877879
auto value(meta::type_declaration& t) -> void
878880
{
879881
ordered(t);
@@ -892,7 +894,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void
892894
basic_value(t);
893895
}
894896

895-
#line 717 "reflect.h2"
897+
#line 719 "reflect.h2"
896898
auto cpp2_struct(meta::type_declaration& t) -> void
897899
{
898900
{ auto&& cpp2_range = CPP2_UFCS_0(get_members, t); for ( auto& m : cpp2_range )
@@ -907,11 +909,11 @@ auto cpp2_struct(meta::type_declaration& t) -> void
907909
"a struct may not have a user-defined operator=");
908910
}
909911
}}
910-
#line 731 "reflect.h2"
912+
#line 733 "reflect.h2"
911913
basic_value(t); // a plain_struct is-a basic_value
912914
}
913915

914-
#line 737 "reflect.h2"
916+
#line 739 "reflect.h2"
915917
}
916918

917919
#endif

0 commit comments

Comments
 (0)