@@ -98,7 +98,8 @@ static std::optional<DynamicTypeWithLength> AnalyzeTypeSpec(
98
98
class ArgumentAnalyzer {
99
99
public:
100
100
explicit ArgumentAnalyzer (ExpressionAnalyzer &context)
101
- : context_{context}, isProcedureCall_{false } {}
101
+ : context_{context}, source_{context.GetContextualMessages ().at ()},
102
+ isProcedureCall_{false } {}
102
103
ArgumentAnalyzer (ExpressionAnalyzer &context, parser::CharBlock source,
103
104
bool isProcedureCall = false )
104
105
: context_{context}, source_{source}, isProcedureCall_{isProcedureCall} {}
@@ -656,6 +657,7 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::BOZLiteralConstant &x) {
656
657
657
658
// Names and named constants
658
659
MaybeExpr ExpressionAnalyzer::Analyze (const parser::Name &n) {
660
+ auto restorer{GetContextualMessages ().SetLocation (n.source )};
659
661
if (std::optional<int > kind{IsImpliedDo (n.source )}) {
660
662
return AsMaybeExpr (ConvertToKind<TypeCategory::Integer>(
661
663
*kind, AsExpr (ImpliedDoIndex{n.source })));
@@ -696,6 +698,7 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::Name &n) {
696
698
}
697
699
698
700
MaybeExpr ExpressionAnalyzer::Analyze (const parser::NamedConstant &n) {
701
+ auto restorer{GetContextualMessages ().SetLocation (n.v .source )};
699
702
if (MaybeExpr value{Analyze (n.v )}) {
700
703
Expr<SomeType> folded{Fold (std::move (*value))};
701
704
if (IsConstantExpr (folded)) {
@@ -967,11 +970,8 @@ static std::optional<Component> CreateComponent(
967
970
// Derived type component references and type parameter inquiries
968
971
MaybeExpr ExpressionAnalyzer::Analyze (const parser::StructureComponent &sc) {
969
972
MaybeExpr base{Analyze (sc.base )};
970
- if (!base) {
971
- return std::nullopt;
972
- }
973
973
Symbol *sym{sc.component .symbol };
974
- if (context_.HasError (sym)) {
974
+ if (!base || !sym || context_.HasError (sym)) {
975
975
return std::nullopt;
976
976
}
977
977
const auto &name{sc.component .source };
@@ -981,6 +981,7 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::StructureComponent &sc) {
981
981
if (auto *designator{UnwrapExpr<Designator<SomeDerived>>(*dtExpr)}) {
982
982
if (std::optional<DynamicType> dyType{DynamicType::From (*sym)}) {
983
983
if (dyType->category () == TypeCategory::Integer) {
984
+ auto restorer{GetContextualMessages ().SetLocation (name)};
984
985
return Fold (ConvertToType (*dyType,
985
986
AsGenericExpr (TypeParamInquiry{
986
987
IgnoreAnySubscripts (std::move (*designator)), *sym})));
@@ -2155,8 +2156,7 @@ const Assignment *ExpressionAnalyzer::Analyze(const parser::AssignmentStmt &x) {
2155
2156
new GenericAssignmentWrapper{}, GenericAssignmentWrapper::Deleter);
2156
2157
} else {
2157
2158
std::optional<ProcedureRef> procRef{analyzer.TryDefinedAssignment ()};
2158
- Assignment assignment{
2159
- Fold (analyzer.MoveExpr (0 )), Fold (analyzer.MoveExpr (1 ))};
2159
+ Assignment assignment{analyzer.MoveExpr (0 ), analyzer.MoveExpr (1 )};
2160
2160
if (procRef) {
2161
2161
assignment.u = std::move (*procRef);
2162
2162
}
@@ -2601,18 +2601,20 @@ static void FixMisparsedFunctionReference(
2601
2601
// Common handling of parse tree node types that retain the
2602
2602
// representation of the analyzed expression.
2603
2603
template <typename PARSED>
2604
- MaybeExpr ExpressionAnalyzer::ExprOrVariable (const PARSED &x) {
2604
+ MaybeExpr ExpressionAnalyzer::ExprOrVariable (
2605
+ const PARSED &x, parser::CharBlock source) {
2605
2606
if (useSavedTypedExprs_ && x.typedExpr ) {
2606
2607
return x.typedExpr ->v ;
2607
2608
}
2609
+ auto restorer{GetContextualMessages ().SetLocation (source)};
2608
2610
if constexpr (std::is_same_v<PARSED, parser::Expr> ||
2609
2611
std::is_same_v<PARSED, parser::Variable>) {
2610
2612
FixMisparsedFunctionReference (context_, x.u );
2611
2613
}
2612
2614
if (AssumedTypeDummy (x)) { // C710
2613
2615
Say (" TYPE(*) dummy argument may only be used as an actual argument" _err_en_US);
2614
- } else if (MaybeExpr result{evaluate::Fold (foldingContext_, Analyze (x.u ) )}) {
2615
- SetExpr (x, std::move (*result));
2616
+ } else if (MaybeExpr result{Analyze (x.u )}) {
2617
+ SetExpr (x, Fold ( std::move (*result) ));
2616
2618
return x.typedExpr ->v ;
2617
2619
}
2618
2620
ResetExpr (x);
@@ -2628,17 +2630,17 @@ MaybeExpr ExpressionAnalyzer::ExprOrVariable(const PARSED &x) {
2628
2630
2629
2631
MaybeExpr ExpressionAnalyzer::Analyze (const parser::Expr &expr) {
2630
2632
auto restorer{GetContextualMessages ().SetLocation (expr.source )};
2631
- return ExprOrVariable (expr);
2633
+ return ExprOrVariable (expr, expr. source );
2632
2634
}
2633
2635
2634
2636
MaybeExpr ExpressionAnalyzer::Analyze (const parser::Variable &variable) {
2635
2637
auto restorer{GetContextualMessages ().SetLocation (variable.GetSource ())};
2636
- return ExprOrVariable (variable);
2638
+ return ExprOrVariable (variable, variable. GetSource () );
2637
2639
}
2638
2640
2639
2641
MaybeExpr ExpressionAnalyzer::Analyze (const parser::DataStmtConstant &x) {
2640
2642
auto restorer{GetContextualMessages ().SetLocation (x.source )};
2641
- return ExprOrVariable (x);
2643
+ return ExprOrVariable (x, x. source );
2642
2644
}
2643
2645
2644
2646
Expr<SubscriptInteger> ExpressionAnalyzer::AnalyzeKindSelector (
@@ -2652,12 +2654,11 @@ Expr<SubscriptInteger> ExpressionAnalyzer::AnalyzeKindSelector(
2652
2654
common::visitors{
2653
2655
[&](const parser::ScalarIntConstantExpr &x) {
2654
2656
if (MaybeExpr kind{Analyze (x)}) {
2655
- Expr<SomeType> folded{Fold (std::move (*kind))};
2656
- if (std::optional<std::int64_t > code{ToInt64 (folded)}) {
2657
+ if (std::optional<std::int64_t > code{ToInt64 (*kind)}) {
2657
2658
if (CheckIntrinsicKind (category, *code)) {
2658
2659
return Expr<SubscriptInteger>{*code};
2659
2660
}
2660
- } else if (auto *intExpr{UnwrapExpr<Expr<SomeInteger>>(folded )}) {
2661
+ } else if (auto *intExpr{UnwrapExpr<Expr<SomeInteger>>(*kind )}) {
2661
2662
return ConvertToType<SubscriptInteger>(std::move (*intExpr));
2662
2663
}
2663
2664
}
@@ -3110,7 +3111,7 @@ std::optional<ActualArgument> ArgumentAnalyzer::AnalyzeExpr(
3110
3111
" TYPE(*) dummy argument may only be used as an actual argument" _err_en_US);
3111
3112
} else if (MaybeExpr argExpr{AnalyzeExprOrWholeAssumedSizeArray (expr)}) {
3112
3113
if (isProcedureCall_ || !IsProcedure (*argExpr)) {
3113
- return ActualArgument{context_. Fold ( std::move (*argExpr) )};
3114
+ return ActualArgument{std::move (*argExpr)};
3114
3115
}
3115
3116
context_.SayAt (expr.source ,
3116
3117
IsFunction (*argExpr) ? " Function call must have argument list" _err_en_US
0 commit comments