xref: /llvm-project/flang/lib/Evaluate/variable.cpp (revision 2ab9990c9eb79682a4d4b183dfbc7612d3e55328)
1 //===-- lib/Evaluate/variable.cpp -----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "flang/Evaluate/variable.h"
10 #include "flang/Common/idioms.h"
11 #include "flang/Evaluate/check-expression.h"
12 #include "flang/Evaluate/fold.h"
13 #include "flang/Evaluate/tools.h"
14 #include "flang/Parser/char-block.h"
15 #include "flang/Parser/characters.h"
16 #include "flang/Parser/message.h"
17 #include "flang/Semantics/scope.h"
18 #include "flang/Semantics/symbol.h"
19 #include <type_traits>
20 
21 using namespace Fortran::parser::literals;
22 
23 namespace Fortran::evaluate {
24 
25 // Constructors, accessors, mutators
26 
27 Triplet::Triplet() : stride_{Expr<SubscriptInteger>{1}} {}
28 
29 Triplet::Triplet(std::optional<Expr<SubscriptInteger>> &&l,
30     std::optional<Expr<SubscriptInteger>> &&u,
31     std::optional<Expr<SubscriptInteger>> &&s)
32     : stride_{s ? std::move(*s) : Expr<SubscriptInteger>{1}} {
33   if (l) {
34     lower_.emplace(std::move(*l));
35   }
36   if (u) {
37     upper_.emplace(std::move(*u));
38   }
39 }
40 
41 std::optional<Expr<SubscriptInteger>> Triplet::lower() const {
42   if (lower_) {
43     return {lower_.value().value()};
44   }
45   return std::nullopt;
46 }
47 
48 Triplet &Triplet::set_lower(Expr<SubscriptInteger> &&expr) {
49   lower_.emplace(std::move(expr));
50   return *this;
51 }
52 
53 std::optional<Expr<SubscriptInteger>> Triplet::upper() const {
54   if (upper_) {
55     return {upper_.value().value()};
56   }
57   return std::nullopt;
58 }
59 
60 Triplet &Triplet::set_upper(Expr<SubscriptInteger> &&expr) {
61   upper_.emplace(std::move(expr));
62   return *this;
63 }
64 
65 Expr<SubscriptInteger> Triplet::stride() const { return stride_.value(); }
66 
67 Triplet &Triplet::set_stride(Expr<SubscriptInteger> &&expr) {
68   stride_.value() = std::move(expr);
69   return *this;
70 }
71 
72 bool Triplet::IsStrideOne() const {
73   if (auto stride{ToInt64(stride_.value())}) {
74     return stride == 1;
75   } else {
76     return false;
77   }
78 }
79 
80 CoarrayRef::CoarrayRef(SymbolVector &&base, std::vector<Subscript> &&ss,
81     std::vector<Expr<SubscriptInteger>> &&css)
82     : base_{std::move(base)}, subscript_(std::move(ss)),
83       cosubscript_(std::move(css)) {
84   CHECK(!base_.empty());
85   CHECK(!cosubscript_.empty());
86 }
87 
88 std::optional<Expr<SomeInteger>> CoarrayRef::stat() const {
89   if (stat_) {
90     return stat_.value().value();
91   } else {
92     return std::nullopt;
93   }
94 }
95 
96 std::optional<Expr<SomeInteger>> CoarrayRef::team() const {
97   if (team_) {
98     return team_.value().value();
99   } else {
100     return std::nullopt;
101   }
102 }
103 
104 CoarrayRef &CoarrayRef::set_stat(Expr<SomeInteger> &&v) {
105   CHECK(IsVariable(v));
106   stat_.emplace(std::move(v));
107   return *this;
108 }
109 
110 CoarrayRef &CoarrayRef::set_team(Expr<SomeInteger> &&v, bool isTeamNumber) {
111   CHECK(IsVariable(v));
112   team_.emplace(std::move(v));
113   teamIsTeamNumber_ = isTeamNumber;
114   return *this;
115 }
116 
117 const Symbol &CoarrayRef::GetFirstSymbol() const { return base_.front(); }
118 
119 const Symbol &CoarrayRef::GetLastSymbol() const { return base_.back(); }
120 
121 void Substring::SetBounds(std::optional<Expr<SubscriptInteger>> &lower,
122     std::optional<Expr<SubscriptInteger>> &upper) {
123   if (lower) {
124     set_lower(std::move(lower.value()));
125   }
126   if (upper) {
127     set_upper(std::move(upper.value()));
128   }
129 }
130 
131 Expr<SubscriptInteger> Substring::lower() const {
132   if (lower_) {
133     return lower_.value().value();
134   } else {
135     return AsExpr(Constant<SubscriptInteger>{1});
136   }
137 }
138 
139 Substring &Substring::set_lower(Expr<SubscriptInteger> &&expr) {
140   lower_.emplace(std::move(expr));
141   return *this;
142 }
143 
144 std::optional<Expr<SubscriptInteger>> Substring::upper() const {
145   if (upper_) {
146     return upper_.value().value();
147   } else {
148     return common::visit(
149         common::visitors{
150             [](const DataRef &dataRef) { return dataRef.LEN(); },
151             [](const StaticDataObject::Pointer &object)
152                 -> std::optional<Expr<SubscriptInteger>> {
153               return AsExpr(Constant<SubscriptInteger>{object->data().size()});
154             },
155         },
156         parent_);
157   }
158 }
159 
160 Substring &Substring::set_upper(Expr<SubscriptInteger> &&expr) {
161   upper_.emplace(std::move(expr));
162   return *this;
163 }
164 
165 std::optional<Expr<SomeCharacter>> Substring::Fold(FoldingContext &context) {
166   if (!upper_) {
167     upper_ = upper();
168     if (!upper_) {
169       return std::nullopt;
170     }
171   }
172   upper_.value() = evaluate::Fold(context, std::move(upper_.value().value()));
173   std::optional<ConstantSubscript> ubi{ToInt64(upper_.value().value())};
174   if (!ubi) {
175     return std::nullopt;
176   }
177   if (!lower_) {
178     lower_ = AsExpr(Constant<SubscriptInteger>{1});
179   }
180   lower_.value() = evaluate::Fold(context, std::move(lower_.value().value()));
181   std::optional<ConstantSubscript> lbi{ToInt64(lower_.value().value())};
182   if (!lbi) {
183     return std::nullopt;
184   }
185   if (*lbi > *ubi) { // empty result; canonicalize
186     *lbi = 1;
187     *ubi = 0;
188     lower_ = AsExpr(Constant<SubscriptInteger>{*lbi});
189     upper_ = AsExpr(Constant<SubscriptInteger>{*ubi});
190   }
191   std::optional<ConstantSubscript> length;
192   std::optional<Expr<SomeCharacter>> strings; // a Constant<Character>
193   if (const auto *literal{std::get_if<StaticDataObject::Pointer>(&parent_)}) {
194     length = (*literal)->data().size();
195     if (auto str{(*literal)->AsString()}) {
196       strings =
197           Expr<SomeCharacter>(Expr<Ascii>(Constant<Ascii>{std::move(*str)}));
198     }
199   } else if (const auto *dataRef{std::get_if<DataRef>(&parent_)}) {
200     if (auto expr{AsGenericExpr(DataRef{*dataRef})}) {
201       auto folded{evaluate::Fold(context, std::move(*expr))};
202       if (IsActuallyConstant(folded)) {
203         if (const auto *value{UnwrapExpr<Expr<SomeCharacter>>(folded)}) {
204           strings = *value;
205         }
206       }
207     }
208   }
209   std::optional<Expr<SomeCharacter>> result;
210   if (strings) {
211     result = common::visit(
212         [&](const auto &expr) -> std::optional<Expr<SomeCharacter>> {
213           using Type = typename std::decay_t<decltype(expr)>::Result;
214           if (const auto *cc{std::get_if<Constant<Type>>(&expr.u)}) {
215             if (auto substr{cc->Substring(*lbi, *ubi)}) {
216               return Expr<SomeCharacter>{Expr<Type>{*substr}};
217             }
218           }
219           return std::nullopt;
220         },
221         strings->u);
222   }
223   if (!result) { // error cases
224     if (*lbi < 1) {
225       context.messages().Say(
226           "Lower bound (%jd) on substring is less than one"_warn_en_US,
227           static_cast<std::intmax_t>(*lbi));
228       *lbi = 1;
229       lower_ = AsExpr(Constant<SubscriptInteger>{1});
230     }
231     if (length && *ubi > *length) {
232       context.messages().Say(
233           "Upper bound (%jd) on substring is greater than character length (%jd)"_warn_en_US,
234           static_cast<std::intmax_t>(*ubi),
235           static_cast<std::intmax_t>(*length));
236       *ubi = *length;
237       upper_ = AsExpr(Constant<SubscriptInteger>{*ubi});
238     }
239   }
240   return result;
241 }
242 
243 DescriptorInquiry::DescriptorInquiry(
244     const NamedEntity &base, Field field, int dim)
245     : base_{base}, field_{field}, dimension_{dim} {
246   const Symbol &last{base_.GetLastSymbol()};
247   CHECK(IsDescriptor(last));
248   CHECK(((field == Field::Len || field == Field::Rank) && dim == 0) ||
249       (field != Field::Len && dim >= 0 && dim < last.Rank()));
250 }
251 
252 DescriptorInquiry::DescriptorInquiry(NamedEntity &&base, Field field, int dim)
253     : base_{std::move(base)}, field_{field}, dimension_{dim} {
254   const Symbol &last{base_.GetLastSymbol()};
255   CHECK(IsDescriptor(last));
256   CHECK((field == Field::Len && dim == 0) ||
257       (field != Field::Len && dim >= 0 && dim < last.Rank()));
258 }
259 
260 // LEN()
261 static std::optional<Expr<SubscriptInteger>> SymbolLEN(const Symbol &symbol) {
262   const Symbol &ultimate{symbol.GetUltimate()};
263   if (const auto *assoc{ultimate.detailsIf<semantics::AssocEntityDetails>()}) {
264     if (const auto *chExpr{UnwrapExpr<Expr<SomeCharacter>>(assoc->expr())}) {
265       return chExpr->LEN();
266     }
267   }
268   if (auto dyType{DynamicType::From(ultimate)}) {
269     if (auto len{dyType->GetCharLength()}) {
270       if (ultimate.owner().IsDerivedType() || IsScopeInvariantExpr(*len)) {
271         return AsExpr(Extremum<SubscriptInteger>{
272             Ordering::Greater, Expr<SubscriptInteger>{0}, std::move(*len)});
273       }
274     }
275   }
276   if (IsDescriptor(ultimate) && !ultimate.owner().IsDerivedType()) {
277     return Expr<SubscriptInteger>{
278         DescriptorInquiry{NamedEntity{symbol}, DescriptorInquiry::Field::Len}};
279   }
280   return std::nullopt;
281 }
282 
283 std::optional<Expr<SubscriptInteger>> BaseObject::LEN() const {
284   return common::visit(
285       common::visitors{
286           [](const Symbol &symbol) { return SymbolLEN(symbol); },
287           [](const StaticDataObject::Pointer &object)
288               -> std::optional<Expr<SubscriptInteger>> {
289             return AsExpr(Constant<SubscriptInteger>{object->data().size()});
290           },
291       },
292       u);
293 }
294 
295 std::optional<Expr<SubscriptInteger>> Component::LEN() const {
296   return SymbolLEN(GetLastSymbol());
297 }
298 
299 std::optional<Expr<SubscriptInteger>> NamedEntity::LEN() const {
300   return SymbolLEN(GetLastSymbol());
301 }
302 
303 std::optional<Expr<SubscriptInteger>> ArrayRef::LEN() const {
304   return base_.LEN();
305 }
306 
307 std::optional<Expr<SubscriptInteger>> CoarrayRef::LEN() const {
308   return SymbolLEN(GetLastSymbol());
309 }
310 
311 std::optional<Expr<SubscriptInteger>> DataRef::LEN() const {
312   return common::visit(common::visitors{
313                            [](SymbolRef symbol) { return SymbolLEN(symbol); },
314                            [](const auto &x) { return x.LEN(); },
315                        },
316       u);
317 }
318 
319 std::optional<Expr<SubscriptInteger>> Substring::LEN() const {
320   if (auto top{upper()}) {
321     return AsExpr(Extremum<SubscriptInteger>{Ordering::Greater,
322         AsExpr(Constant<SubscriptInteger>{0}),
323         *std::move(top) - lower() + AsExpr(Constant<SubscriptInteger>{1})});
324   } else {
325     return std::nullopt;
326   }
327 }
328 
329 template <typename T>
330 std::optional<Expr<SubscriptInteger>> Designator<T>::LEN() const {
331   if constexpr (T::category == TypeCategory::Character) {
332     return common::visit(common::visitors{
333                              [](SymbolRef symbol) { return SymbolLEN(symbol); },
334                              [](const auto &x) { return x.LEN(); },
335                          },
336         u);
337   } else {
338     common::die("Designator<non-char>::LEN() called");
339     return std::nullopt;
340   }
341 }
342 
343 std::optional<Expr<SubscriptInteger>> ProcedureDesignator::LEN() const {
344   using T = std::optional<Expr<SubscriptInteger>>;
345   return common::visit(
346       common::visitors{
347           [](SymbolRef symbol) -> T { return SymbolLEN(symbol); },
348           [](const common::CopyableIndirection<Component> &c) -> T {
349             return c.value().LEN();
350           },
351           [](const SpecificIntrinsic &i) -> T {
352             // Some cases whose results' lengths can be determined
353             // from the lengths of their arguments are handled in
354             // ProcedureRef::LEN() before coming here.
355             if (const auto &result{i.characteristics.value().functionResult}) {
356               if (const auto *type{result->GetTypeAndShape()}) {
357                 if (auto length{type->type().GetCharLength()}) {
358                   return std::move(*length);
359                 }
360               }
361             }
362             return std::nullopt;
363           },
364       },
365       u);
366 }
367 
368 // Rank()
369 int BaseObject::Rank() const {
370   return common::visit(common::visitors{
371                            [](SymbolRef symbol) { return symbol->Rank(); },
372                            [](const StaticDataObject::Pointer &) { return 0; },
373                        },
374       u);
375 }
376 
377 int Component::Rank() const {
378   if (int rank{symbol_->Rank()}; rank > 0) {
379     return rank;
380   }
381   return base().Rank();
382 }
383 
384 int NamedEntity::Rank() const {
385   return common::visit(common::visitors{
386                            [](const SymbolRef s) { return s->Rank(); },
387                            [](const Component &c) { return c.Rank(); },
388                        },
389       u_);
390 }
391 
392 int Subscript::Rank() const {
393   return common::visit(common::visitors{
394                            [](const IndirectSubscriptIntegerExpr &x) {
395                              return x.value().Rank();
396                            },
397                            [](const Triplet &) { return 1; },
398                        },
399       u);
400 }
401 
402 int ArrayRef::Rank() const {
403   int rank{0};
404   for (const auto &expr : subscript_) {
405     rank += expr.Rank();
406   }
407   if (rank > 0) {
408     return rank;
409   } else if (const Component * component{base_.UnwrapComponent()}) {
410     return component->base().Rank();
411   } else {
412     return 0;
413   }
414 }
415 
416 int CoarrayRef::Rank() const {
417   if (!subscript_.empty()) {
418     int rank{0};
419     for (const auto &expr : subscript_) {
420       rank += expr.Rank();
421     }
422     return rank;
423   } else {
424     return base_.back()->Rank();
425   }
426 }
427 
428 int DataRef::Rank() const {
429   return common::visit(common::visitors{
430                            [](SymbolRef symbol) { return symbol->Rank(); },
431                            [](const auto &x) { return x.Rank(); },
432                        },
433       u);
434 }
435 
436 int Substring::Rank() const {
437   return common::visit(
438       common::visitors{
439           [](const DataRef &dataRef) { return dataRef.Rank(); },
440           [](const StaticDataObject::Pointer &) { return 0; },
441       },
442       parent_);
443 }
444 
445 int ComplexPart::Rank() const { return complex_.Rank(); }
446 
447 template <typename T> int Designator<T>::Rank() const {
448   return common::visit(common::visitors{
449                            [](SymbolRef symbol) { return symbol->Rank(); },
450                            [](const auto &x) { return x.Rank(); },
451                        },
452       u);
453 }
454 
455 // GetBaseObject(), GetFirstSymbol(), GetLastSymbol(), &c.
456 const Symbol &Component::GetFirstSymbol() const {
457   return base_.value().GetFirstSymbol();
458 }
459 
460 const Symbol &NamedEntity::GetFirstSymbol() const {
461   return common::visit(common::visitors{
462                            [](SymbolRef s) -> const Symbol & { return s; },
463                            [](const Component &c) -> const Symbol & {
464                              return c.GetFirstSymbol();
465                            },
466                        },
467       u_);
468 }
469 
470 const Symbol &NamedEntity::GetLastSymbol() const {
471   return common::visit(common::visitors{
472                            [](SymbolRef s) -> const Symbol & { return s; },
473                            [](const Component &c) -> const Symbol & {
474                              return c.GetLastSymbol();
475                            },
476                        },
477       u_);
478 }
479 
480 const Component *NamedEntity::UnwrapComponent() const {
481   return common::visit(
482       common::visitors{
483           [](SymbolRef) -> const Component * { return nullptr; },
484           [](const Component &c) { return &c; },
485       },
486       u_);
487 }
488 
489 Component *NamedEntity::UnwrapComponent() {
490   return common::visit(common::visitors{
491                            [](SymbolRef &) -> Component * { return nullptr; },
492                            [](Component &c) { return &c; },
493                        },
494       u_);
495 }
496 
497 const Symbol &ArrayRef::GetFirstSymbol() const {
498   return base_.GetFirstSymbol();
499 }
500 
501 const Symbol &ArrayRef::GetLastSymbol() const { return base_.GetLastSymbol(); }
502 
503 const Symbol &DataRef::GetFirstSymbol() const {
504   return *common::visit(common::visitors{
505                             [](SymbolRef symbol) { return &*symbol; },
506                             [](const auto &x) { return &x.GetFirstSymbol(); },
507                         },
508       u);
509 }
510 
511 const Symbol &DataRef::GetLastSymbol() const {
512   return *common::visit(common::visitors{
513                             [](SymbolRef symbol) { return &*symbol; },
514                             [](const auto &x) { return &x.GetLastSymbol(); },
515                         },
516       u);
517 }
518 
519 BaseObject Substring::GetBaseObject() const {
520   return common::visit(common::visitors{
521                            [](const DataRef &dataRef) {
522                              return BaseObject{dataRef.GetFirstSymbol()};
523                            },
524                            [](StaticDataObject::Pointer pointer) {
525                              return BaseObject{std::move(pointer)};
526                            },
527                        },
528       parent_);
529 }
530 
531 const Symbol *Substring::GetLastSymbol() const {
532   return common::visit(
533       common::visitors{
534           [](const DataRef &dataRef) { return &dataRef.GetLastSymbol(); },
535           [](const auto &) -> const Symbol * { return nullptr; },
536       },
537       parent_);
538 }
539 
540 template <typename T> BaseObject Designator<T>::GetBaseObject() const {
541   return common::visit(
542       common::visitors{
543           [](SymbolRef symbol) { return BaseObject{symbol}; },
544           [](const Substring &sstring) { return sstring.GetBaseObject(); },
545           [](const auto &x) {
546 #if !__clang__ && __GNUC__ == 7 && __GNUC_MINOR__ == 2
547             if constexpr (std::is_same_v<std::decay_t<decltype(x)>,
548                               Substring>) {
549               return x.GetBaseObject();
550             } else
551 #endif
552               return BaseObject{x.GetFirstSymbol()};
553           },
554       },
555       u);
556 }
557 
558 template <typename T> const Symbol *Designator<T>::GetLastSymbol() const {
559   return common::visit(
560       common::visitors{
561           [](SymbolRef symbol) { return &*symbol; },
562           [](const Substring &sstring) { return sstring.GetLastSymbol(); },
563           [](const auto &x) {
564 #if !__clang__ && __GNUC__ == 7 && __GNUC_MINOR__ == 2
565             if constexpr (std::is_same_v<std::decay_t<decltype(x)>,
566                               Substring>) {
567               return x.GetLastSymbol();
568             } else
569 #endif
570               return &x.GetLastSymbol();
571           },
572       },
573       u);
574 }
575 
576 template <typename T>
577 std::optional<DynamicType> Designator<T>::GetType() const {
578   if constexpr (IsLengthlessIntrinsicType<Result>) {
579     return Result::GetType();
580   } else if (const Symbol * symbol{GetLastSymbol()}) {
581     return DynamicType::From(*symbol);
582   } else if constexpr (Result::category == TypeCategory::Character) {
583     if (const Substring * substring{std::get_if<Substring>(&u)}) {
584       const auto *parent{substring->GetParentIf<StaticDataObject::Pointer>()};
585       CHECK(parent);
586       return DynamicType{TypeCategory::Character, (*parent)->itemBytes()};
587     }
588   }
589   return std::nullopt;
590 }
591 
592 static NamedEntity AsNamedEntity(const SymbolVector &x) {
593   CHECK(!x.empty());
594   NamedEntity result{x.front()};
595   int j{0};
596   for (const Symbol &symbol : x) {
597     if (j++ != 0) {
598       DataRef base{result.IsSymbol() ? DataRef{result.GetLastSymbol()}
599                                      : DataRef{result.GetComponent()}};
600       result = NamedEntity{Component{std::move(base), symbol}};
601     }
602   }
603   return result;
604 }
605 
606 NamedEntity CoarrayRef::GetBase() const { return AsNamedEntity(base_); }
607 
608 // Equality testing
609 
610 // For the purposes of comparing type parameter expressions while
611 // testing the compatibility of procedure characteristics, two
612 // object dummy arguments with the same name are considered equal.
613 static bool AreSameSymbol(const Symbol &x, const Symbol &y) {
614   if (&x == &y) {
615     return true;
616   }
617   if (x.name() == y.name()) {
618     if (const auto *xObject{x.detailsIf<semantics::ObjectEntityDetails>()}) {
619       if (const auto *yObject{y.detailsIf<semantics::ObjectEntityDetails>()}) {
620         return xObject->isDummy() && yObject->isDummy();
621       }
622     }
623   }
624   return false;
625 }
626 
627 // Implements operator==() for a union type, using special case handling
628 // for Symbol references.
629 template <typename A> static bool TestVariableEquality(const A &x, const A &y) {
630   const SymbolRef *xSymbol{std::get_if<SymbolRef>(&x.u)};
631   if (const SymbolRef * ySymbol{std::get_if<SymbolRef>(&y.u)}) {
632     return xSymbol && AreSameSymbol(*xSymbol, *ySymbol);
633   } else {
634     return x.u == y.u;
635   }
636 }
637 
638 bool BaseObject::operator==(const BaseObject &that) const {
639   return TestVariableEquality(*this, that);
640 }
641 bool Component::operator==(const Component &that) const {
642   return base_ == that.base_ && &*symbol_ == &*that.symbol_;
643 }
644 bool NamedEntity::operator==(const NamedEntity &that) const {
645   if (IsSymbol()) {
646     return that.IsSymbol() &&
647         AreSameSymbol(GetFirstSymbol(), that.GetFirstSymbol());
648   } else {
649     return !that.IsSymbol() && GetComponent() == that.GetComponent();
650   }
651 }
652 bool TypeParamInquiry::operator==(const TypeParamInquiry &that) const {
653   return &*parameter_ == &*that.parameter_ && base_ == that.base_;
654 }
655 bool Triplet::operator==(const Triplet &that) const {
656   return lower_ == that.lower_ && upper_ == that.upper_ &&
657       stride_ == that.stride_;
658 }
659 bool Subscript::operator==(const Subscript &that) const { return u == that.u; }
660 bool ArrayRef::operator==(const ArrayRef &that) const {
661   return base_ == that.base_ && subscript_ == that.subscript_;
662 }
663 bool CoarrayRef::operator==(const CoarrayRef &that) const {
664   return base_ == that.base_ && subscript_ == that.subscript_ &&
665       cosubscript_ == that.cosubscript_ && stat_ == that.stat_ &&
666       team_ == that.team_ && teamIsTeamNumber_ == that.teamIsTeamNumber_;
667 }
668 bool DataRef::operator==(const DataRef &that) const {
669   return TestVariableEquality(*this, that);
670 }
671 bool Substring::operator==(const Substring &that) const {
672   return parent_ == that.parent_ && lower_ == that.lower_ &&
673       upper_ == that.upper_;
674 }
675 bool ComplexPart::operator==(const ComplexPart &that) const {
676   return part_ == that.part_ && complex_ == that.complex_;
677 }
678 bool ProcedureRef::operator==(const ProcedureRef &that) const {
679   return proc_ == that.proc_ && arguments_ == that.arguments_;
680 }
681 template <typename T>
682 bool Designator<T>::operator==(const Designator<T> &that) const {
683   return TestVariableEquality(*this, that);
684 }
685 bool DescriptorInquiry::operator==(const DescriptorInquiry &that) const {
686   return field_ == that.field_ && base_ == that.base_ &&
687       dimension_ == that.dimension_;
688 }
689 
690 #ifdef _MSC_VER // disable bogus warning about missing definitions
691 #pragma warning(disable : 4661)
692 #endif
693 INSTANTIATE_VARIABLE_TEMPLATES
694 } // namespace Fortran::evaluate
695 
696 template class Fortran::common::Indirection<Fortran::evaluate::Component, true>;
697