forked from OSchip/llvm-project
[flang] Change formatting of common::visitors{}
Including a comma after the last lambda in a `common::visitors{}` list causes clang-format to do a better job of formatting them. Add that recommendation to C++style.md, insert the missing commas, and reformat the changed files. Original-commit: flang-compiler/f18@a2486ca3b6 Reviewed-on: https://github.com/flang-compiler/f18/pull/232
This commit is contained in:
parent
ffa47bfbeb
commit
daa0b054ba
|
@ -96,6 +96,10 @@ easily read and understood with a minimum of scrolling.
|
|||
|
||||
Avoid using assignments in controlling expressions of `if()` &c., even with
|
||||
the idiom of wrapping them with extra parentheses.
|
||||
|
||||
In multi-element initializer lists (especially `common::visitors{...}`),
|
||||
including a comma after the last element often causes `clang-format` to do
|
||||
a better jobs of formatting.
|
||||
### C++ language
|
||||
Use *C++17*, unless some compiler to which we must be portable lacks a feature
|
||||
you are considering.
|
||||
|
|
|
@ -144,11 +144,13 @@ std::ostream &ArrayConstructor<T>::AsFortran(std::ostream &o) const {
|
|||
template<typename RESULT>
|
||||
std::ostream &ExpressionBase<RESULT>::AsFortran(std::ostream &o) const {
|
||||
std::visit(
|
||||
common::visitors{[&](const BOZLiteralConstant &x) {
|
||||
o << "z'" << x.Hexadecimal() << "'";
|
||||
},
|
||||
common::visitors{
|
||||
[&](const BOZLiteralConstant &x) {
|
||||
o << "z'" << x.Hexadecimal() << "'";
|
||||
},
|
||||
[&](const CopyableIndirection<Substring> &s) { s->AsFortran(o); },
|
||||
[&](const auto &x) { x.AsFortran(o); }},
|
||||
[&](const auto &x) { x.AsFortran(o); },
|
||||
},
|
||||
derived().u);
|
||||
return o;
|
||||
}
|
||||
|
@ -161,10 +163,10 @@ template<typename T> Expr<SubscriptInteger> ArrayConstructor<T>::LEN() const {
|
|||
template<int KIND>
|
||||
Expr<SubscriptInteger> Expr<Type<TypeCategory::Character, KIND>>::LEN() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Constant<Result> &c) {
|
||||
return AsExpr(
|
||||
Constant<SubscriptInteger>{c.value.size()});
|
||||
},
|
||||
common::visitors{
|
||||
[](const Constant<Result> &c) {
|
||||
return AsExpr(Constant<SubscriptInteger>{c.value.size()});
|
||||
},
|
||||
[](const ArrayConstructor<Result> &a) { return a.LEN(); },
|
||||
[](const Parentheses<Result> &x) { return x.left().LEN(); },
|
||||
[](const Concat<KIND> &c) {
|
||||
|
@ -175,7 +177,8 @@ Expr<SubscriptInteger> Expr<Type<TypeCategory::Character, KIND>>::LEN() const {
|
|||
Extremum<SubscriptInteger>{c.left().LEN(), c.right().LEN()}};
|
||||
},
|
||||
[](const Designator<Result> &dr) { return dr.LEN(); },
|
||||
[](const FunctionRef<Result> &fr) { return fr.LEN(); }},
|
||||
[](const FunctionRef<Result> &fr) { return fr.LEN(); },
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,16 +27,17 @@ ConvertRealOperandsResult ConvertRealOperands(
|
|||
parser::ContextualMessages &messages, Expr<SomeType> &&x,
|
||||
Expr<SomeType> &&y, int defaultRealKind) {
|
||||
return std::visit(
|
||||
common::visitors{[&](Expr<SomeInteger> &&ix, Expr<SomeInteger> &&iy)
|
||||
-> ConvertRealOperandsResult {
|
||||
// Can happen in a CMPLX() constructor. Per F'2018,
|
||||
// both integer operands are converted to default REAL.
|
||||
return {AsSameKindExprs<TypeCategory::Real>(
|
||||
ConvertToKind<TypeCategory::Real>(
|
||||
defaultRealKind, std::move(ix)),
|
||||
ConvertToKind<TypeCategory::Real>(
|
||||
defaultRealKind, std::move(iy)))};
|
||||
},
|
||||
common::visitors{
|
||||
[&](Expr<SomeInteger> &&ix,
|
||||
Expr<SomeInteger> &&iy) -> ConvertRealOperandsResult {
|
||||
// Can happen in a CMPLX() constructor. Per F'2018,
|
||||
// both integer operands are converted to default REAL.
|
||||
return {AsSameKindExprs<TypeCategory::Real>(
|
||||
ConvertToKind<TypeCategory::Real>(
|
||||
defaultRealKind, std::move(ix)),
|
||||
ConvertToKind<TypeCategory::Real>(
|
||||
defaultRealKind, std::move(iy)))};
|
||||
},
|
||||
[&](Expr<SomeInteger> &&ix,
|
||||
Expr<SomeReal> &&ry) -> ConvertRealOperandsResult {
|
||||
return {AsSameKindExprs<TypeCategory::Real>(
|
||||
|
@ -81,7 +82,8 @@ ConvertRealOperandsResult ConvertRealOperands(
|
|||
[&](auto &&, auto &&) -> ConvertRealOperandsResult {
|
||||
messages.Say("operands must be INTEGER or REAL"_err_en_US);
|
||||
return std::nullopt;
|
||||
}},
|
||||
},
|
||||
},
|
||||
std::move(x.u), std::move(y.u));
|
||||
}
|
||||
|
||||
|
@ -248,11 +250,11 @@ std::optional<Expr<SomeType>> NumericOperation(
|
|||
parser::ContextualMessages &messages, Expr<SomeType> &&x,
|
||||
Expr<SomeType> &&y, int defaultRealKind) {
|
||||
return std::visit(
|
||||
common::visitors{[](Expr<SomeInteger> &&ix, Expr<SomeInteger> &&iy) {
|
||||
return Package(
|
||||
PromoteAndCombine<OPR, TypeCategory::Integer>(
|
||||
std::move(ix), std::move(iy)));
|
||||
},
|
||||
common::visitors{
|
||||
[](Expr<SomeInteger> &&ix, Expr<SomeInteger> &&iy) {
|
||||
return Package(PromoteAndCombine<OPR, TypeCategory::Integer>(
|
||||
std::move(ix), std::move(iy)));
|
||||
},
|
||||
[](Expr<SomeReal> &&rx, Expr<SomeReal> &&ry) {
|
||||
return Package(PromoteAndCombine<OPR, TypeCategory::Real>(
|
||||
std::move(rx), std::move(ry)));
|
||||
|
@ -316,7 +318,8 @@ std::optional<Expr<SomeType>> NumericOperation(
|
|||
// TODO: defined operator
|
||||
messages.Say("non-numeric operands to numeric operation"_err_en_US);
|
||||
return NoExpr();
|
||||
}},
|
||||
},
|
||||
},
|
||||
std::move(x.u), std::move(y.u));
|
||||
}
|
||||
|
||||
|
@ -396,10 +399,11 @@ Expr<LogicalResult> PromoteAndRelate(
|
|||
std::optional<Expr<LogicalResult>> Relate(parser::ContextualMessages &messages,
|
||||
RelationalOperator opr, Expr<SomeType> &&x, Expr<SomeType> &&y) {
|
||||
return std::visit(
|
||||
common::visitors{[=](Expr<SomeInteger> &&ix, Expr<SomeInteger> &&iy) {
|
||||
return std::make_optional(PromoteAndRelate(
|
||||
opr, std::move(ix), std::move(iy)));
|
||||
},
|
||||
common::visitors{
|
||||
[=](Expr<SomeInteger> &&ix, Expr<SomeInteger> &&iy) {
|
||||
return std::make_optional(
|
||||
PromoteAndRelate(opr, std::move(ix), std::move(iy)));
|
||||
},
|
||||
[=](Expr<SomeReal> &&rx, Expr<SomeReal> &&ry) {
|
||||
return std::make_optional(
|
||||
PromoteAndRelate(opr, std::move(rx), std::move(ry)));
|
||||
|
@ -478,7 +482,8 @@ std::optional<Expr<LogicalResult>> Relate(parser::ContextualMessages &messages,
|
|||
messages.Say(
|
||||
"relational operands do not have comparable types"_err_en_US);
|
||||
return std::optional<Expr<LogicalResult>>{};
|
||||
}},
|
||||
},
|
||||
},
|
||||
std::move(x.u), std::move(y.u));
|
||||
}
|
||||
|
||||
|
|
|
@ -114,10 +114,12 @@ Expr<SubscriptInteger> Substring::upper() const {
|
|||
return **upper_;
|
||||
} else {
|
||||
return std::visit(
|
||||
common::visitors{[](const DataRef &dataRef) { return dataRef.LEN(); },
|
||||
common::visitors{
|
||||
[](const DataRef &dataRef) { return dataRef.LEN(); },
|
||||
[](const StaticDataObject::Pointer &object) {
|
||||
return AsExpr(Constant<SubscriptInteger>{object->data().size()});
|
||||
}},
|
||||
},
|
||||
},
|
||||
parent_);
|
||||
}
|
||||
}
|
||||
|
@ -339,8 +341,10 @@ std::ostream &ProcedureDesignator::AsFortran(std::ostream &o) const {
|
|||
template<typename T>
|
||||
std::ostream &Designator<T>::AsFortran(std::ostream &o) const {
|
||||
std::visit(
|
||||
common::visitors{[&](const Symbol *sym) { o << sym->name().ToString(); },
|
||||
[&](const auto &x) { x.AsFortran(o); }},
|
||||
common::visitors{
|
||||
[&](const Symbol *sym) { o << sym->name().ToString(); },
|
||||
[&](const auto &x) { x.AsFortran(o); },
|
||||
},
|
||||
u);
|
||||
return o;
|
||||
}
|
||||
|
@ -352,10 +356,12 @@ static Expr<SubscriptInteger> SymbolLEN(const Symbol &sym) {
|
|||
|
||||
Expr<SubscriptInteger> BaseObject::LEN() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *symbol) { return SymbolLEN(*symbol); },
|
||||
common::visitors{
|
||||
[](const Symbol *symbol) { return SymbolLEN(*symbol); },
|
||||
[](const StaticDataObject::Pointer &object) {
|
||||
return AsExpr(Constant<SubscriptInteger>{object->data().size()});
|
||||
}},
|
||||
},
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
|
@ -364,8 +370,10 @@ Expr<SubscriptInteger> Component::LEN() const {
|
|||
}
|
||||
Expr<SubscriptInteger> ArrayRef::LEN() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *symbol) { return SymbolLEN(*symbol); },
|
||||
[](const Component &component) { return component.LEN(); }},
|
||||
common::visitors{
|
||||
[](const Symbol *symbol) { return SymbolLEN(*symbol); },
|
||||
[](const Component &component) { return component.LEN(); },
|
||||
},
|
||||
u);
|
||||
}
|
||||
Expr<SubscriptInteger> CoarrayRef::LEN() const {
|
||||
|
@ -373,8 +381,10 @@ Expr<SubscriptInteger> CoarrayRef::LEN() const {
|
|||
}
|
||||
Expr<SubscriptInteger> DataRef::LEN() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *s) { return SymbolLEN(*s); },
|
||||
[](const auto &x) { return x.LEN(); }},
|
||||
common::visitors{
|
||||
[](const Symbol *s) { return SymbolLEN(*s); },
|
||||
[](const auto &x) { return x.LEN(); },
|
||||
},
|
||||
u);
|
||||
}
|
||||
Expr<SubscriptInteger> Substring::LEN() const {
|
||||
|
@ -385,9 +395,11 @@ Expr<SubscriptInteger> Substring::LEN() const {
|
|||
template<typename T> Expr<SubscriptInteger> Designator<T>::LEN() const {
|
||||
if constexpr (Result::category == TypeCategory::Character) {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *s) { return SymbolLEN(*s); },
|
||||
common::visitors{
|
||||
[](const Symbol *s) { return SymbolLEN(*s); },
|
||||
[](const Component &c) { return c.LEN(); },
|
||||
[](const auto &x) { return x.LEN(); }},
|
||||
[](const auto &x) { return x.LEN(); },
|
||||
},
|
||||
u);
|
||||
} else {
|
||||
CHECK(!"LEN() on non-character Designator");
|
||||
|
@ -396,20 +408,24 @@ template<typename T> Expr<SubscriptInteger> Designator<T>::LEN() const {
|
|||
}
|
||||
Expr<SubscriptInteger> ProcedureDesignator::LEN() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *s) { return SymbolLEN(*s); },
|
||||
common::visitors{
|
||||
[](const Symbol *s) { return SymbolLEN(*s); },
|
||||
[](const Component &c) { return c.LEN(); },
|
||||
[](const auto &) {
|
||||
CRASH_NO_CASE;
|
||||
return AsExpr(Constant<SubscriptInteger>{0});
|
||||
}},
|
||||
},
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
// Rank()
|
||||
int BaseObject::Rank() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *symbol) { return symbol->Rank(); },
|
||||
[](const StaticDataObject::Pointer &) { return 0; }},
|
||||
common::visitors{
|
||||
[](const Symbol *symbol) { return symbol->Rank(); },
|
||||
[](const StaticDataObject::Pointer &) { return 0; },
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
|
@ -421,12 +437,15 @@ int Component::Rank() const {
|
|||
}
|
||||
|
||||
int Subscript::Rank() const {
|
||||
return std::visit(common::visitors{[](const IndirectSubscriptIntegerExpr &x) {
|
||||
int rank{x->Rank()};
|
||||
CHECK(rank <= 1);
|
||||
return rank;
|
||||
},
|
||||
[](const Triplet &) { return 1; }},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[](const IndirectSubscriptIntegerExpr &x) {
|
||||
int rank{x->Rank()};
|
||||
CHECK(rank <= 1);
|
||||
return rank;
|
||||
},
|
||||
[](const Triplet &) { return 1; },
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
|
@ -470,16 +489,20 @@ int DataRef::Rank() const {
|
|||
|
||||
int Substring::Rank() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const DataRef &dataRef) { return dataRef.Rank(); },
|
||||
[](const StaticDataObject::Pointer &) { return 0; }},
|
||||
common::visitors{
|
||||
[](const DataRef &dataRef) { return dataRef.Rank(); },
|
||||
[](const StaticDataObject::Pointer &) { return 0; },
|
||||
},
|
||||
parent_);
|
||||
}
|
||||
|
||||
int ComplexPart::Rank() const { return complex_.Rank(); }
|
||||
template<typename T> int Designator<T>::Rank() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *sym) { return sym->Rank(); },
|
||||
[](const auto &x) { return x.Rank(); }},
|
||||
common::visitors{
|
||||
[](const Symbol *sym) { return sym->Rank(); },
|
||||
[](const auto &x) { return x.Rank(); },
|
||||
},
|
||||
u);
|
||||
}
|
||||
int ProcedureDesignator::Rank() const {
|
||||
|
@ -511,58 +534,70 @@ const Symbol &Component::GetFirstSymbol() const {
|
|||
|
||||
const Symbol &ArrayRef::GetFirstSymbol() const {
|
||||
return *std::visit(
|
||||
common::visitors{[](const Symbol *symbol) { return symbol; },
|
||||
common::visitors{
|
||||
[](const Symbol *symbol) { return symbol; },
|
||||
[=](const Component &component) {
|
||||
return &component.GetFirstSymbol();
|
||||
}},
|
||||
},
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
const Symbol &ArrayRef::GetLastSymbol() const {
|
||||
return *std::visit(common::visitors{[](const Symbol *sym) { return sym; },
|
||||
[=](const Component &component) {
|
||||
return &component.GetLastSymbol();
|
||||
}},
|
||||
return *std::visit(
|
||||
common::visitors{
|
||||
[](const Symbol *sym) { return sym; },
|
||||
[=](const Component &component) {
|
||||
return &component.GetLastSymbol();
|
||||
},
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
const Symbol &DataRef::GetFirstSymbol() const {
|
||||
return *std::visit(
|
||||
common::visitors{[](const Symbol *symbol) { return symbol; },
|
||||
[](const auto &x) { return &x.GetFirstSymbol(); }},
|
||||
common::visitors{
|
||||
[](const Symbol *symbol) { return symbol; },
|
||||
[](const auto &x) { return &x.GetFirstSymbol(); },
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
const Symbol &DataRef::GetLastSymbol() const {
|
||||
return *std::visit(
|
||||
common::visitors{[](const Symbol *symbol) { return symbol; },
|
||||
[](const auto &x) { return &x.GetLastSymbol(); }},
|
||||
common::visitors{
|
||||
[](const Symbol *symbol) { return symbol; },
|
||||
[](const auto &x) { return &x.GetLastSymbol(); },
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
BaseObject Substring::GetBaseObject() const {
|
||||
return std::visit(common::visitors{[](const DataRef &dataRef) {
|
||||
return BaseObject{
|
||||
dataRef.GetFirstSymbol()};
|
||||
},
|
||||
|
||||
[](StaticDataObject::Pointer pointer) {
|
||||
return BaseObject{std::move(pointer)};
|
||||
}},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[](const DataRef &dataRef) {
|
||||
return BaseObject{dataRef.GetFirstSymbol()};
|
||||
},
|
||||
[](StaticDataObject::Pointer pointer) {
|
||||
return BaseObject{std::move(pointer)};
|
||||
},
|
||||
},
|
||||
parent_);
|
||||
}
|
||||
|
||||
const Symbol *Substring::GetLastSymbol() const {
|
||||
return std::visit(common::visitors{[](const DataRef &dataRef) {
|
||||
return &dataRef.GetLastSymbol();
|
||||
},
|
||||
[](const auto &) -> const Symbol * { return nullptr; }},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[](const DataRef &dataRef) { return &dataRef.GetLastSymbol(); },
|
||||
[](const auto &) -> const Symbol * { return nullptr; },
|
||||
},
|
||||
parent_);
|
||||
}
|
||||
|
||||
template<typename T> BaseObject Designator<T>::GetBaseObject() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *symbol) { return BaseObject{*symbol}; },
|
||||
common::visitors{
|
||||
[](const Symbol *symbol) { return BaseObject{*symbol}; },
|
||||
[](const auto &x) {
|
||||
if constexpr (std::is_same_v<std::decay_t<decltype(x)>,
|
||||
Substring>) {
|
||||
|
@ -570,13 +605,15 @@ template<typename T> BaseObject Designator<T>::GetBaseObject() const {
|
|||
} else {
|
||||
return BaseObject{x.GetFirstSymbol()};
|
||||
}
|
||||
}},
|
||||
},
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
template<typename T> const Symbol *Designator<T>::GetLastSymbol() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const Symbol *symbol) { return symbol; },
|
||||
common::visitors{
|
||||
[](const Symbol *symbol) { return symbol; },
|
||||
[](const auto &x) {
|
||||
if constexpr (std::is_same_v<std::decay_t<decltype(x)>,
|
||||
Substring>) {
|
||||
|
@ -584,14 +621,18 @@ template<typename T> const Symbol *Designator<T>::GetLastSymbol() const {
|
|||
} else {
|
||||
return &x.GetLastSymbol();
|
||||
}
|
||||
}},
|
||||
},
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
const Symbol *ProcedureDesignator::GetSymbol() const {
|
||||
return std::visit(common::visitors{[](const Symbol *sym) { return sym; },
|
||||
[](const Component &c) { return &c.GetLastSymbol(); },
|
||||
[](const auto &) -> const Symbol * { return nullptr; }},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[](const Symbol *sym) { return sym; },
|
||||
[](const Component &c) { return &c.GetLastSymbol(); },
|
||||
[](const auto &) -> const Symbol * { return nullptr; },
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,11 +52,12 @@ MessageFormattedText::MessageFormattedText(MessageFixedText text, ...)
|
|||
|
||||
std::string MessageExpectedText::ToString() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const CharBlock &cb) {
|
||||
return MessageFormattedText("expected '%s'"_err_en_US,
|
||||
cb.NULTerminatedToString().data())
|
||||
.MoveString();
|
||||
},
|
||||
common::visitors{
|
||||
[](const CharBlock &cb) {
|
||||
return MessageFormattedText(
|
||||
"expected '%s'"_err_en_US, cb.NULTerminatedToString().data())
|
||||
.MoveString();
|
||||
},
|
||||
[](const SetOfChars &set) {
|
||||
SetOfChars expect{set};
|
||||
if (expect.Has('\n')) {
|
||||
|
@ -85,16 +86,20 @@ std::string MessageExpectedText::ToString() const {
|
|||
return MessageFormattedText("expected '%s'"_err_en_US, s.data())
|
||||
.MoveString();
|
||||
}
|
||||
}},
|
||||
},
|
||||
},
|
||||
u_);
|
||||
}
|
||||
|
||||
bool MessageExpectedText::Merge(const MessageExpectedText &that) {
|
||||
return std::visit(common::visitors{[](SetOfChars &s1, const SetOfChars &s2) {
|
||||
s1 = s1.Union(s2);
|
||||
return true;
|
||||
},
|
||||
[](const auto &, const auto &) { return false; }},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[](SetOfChars &s1, const SetOfChars &s2) {
|
||||
s1 = s1.Union(s2);
|
||||
return true;
|
||||
},
|
||||
[](const auto &, const auto &) { return false; },
|
||||
},
|
||||
u_, that.u_);
|
||||
}
|
||||
|
||||
|
@ -106,32 +111,38 @@ bool Message::SortBefore(const Message &that) const {
|
|||
// are speculative. Messages with ProvenanceRange locations are ordered
|
||||
// before others for sorting.
|
||||
return std::visit(
|
||||
common::visitors{[](const CharBlock &cb1, const CharBlock &cb2) {
|
||||
return cb1.begin() < cb2.begin();
|
||||
},
|
||||
common::visitors{
|
||||
[](const CharBlock &cb1, const CharBlock &cb2) {
|
||||
return cb1.begin() < cb2.begin();
|
||||
},
|
||||
[](const CharBlock &, const ProvenanceRange &) { return false; },
|
||||
[](const ProvenanceRange &pr1, const ProvenanceRange &pr2) {
|
||||
return pr1.start() < pr2.start();
|
||||
},
|
||||
[](const ProvenanceRange &, const CharBlock &) { return true; }},
|
||||
[](const ProvenanceRange &, const CharBlock &) { return true; },
|
||||
},
|
||||
location_, that.location_);
|
||||
}
|
||||
|
||||
bool Message::IsFatal() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const MessageExpectedText &) { return true; },
|
||||
common::visitors{
|
||||
[](const MessageExpectedText &) { return true; },
|
||||
[](const MessageFixedText &x) { return x.isFatal(); },
|
||||
[](const MessageFormattedText &x) { return x.isFatal(); }},
|
||||
[](const MessageFormattedText &x) { return x.isFatal(); },
|
||||
},
|
||||
text_);
|
||||
}
|
||||
|
||||
std::string Message::ToString() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const MessageFixedText &t) {
|
||||
return t.text().NULTerminatedToString();
|
||||
},
|
||||
common::visitors{
|
||||
[](const MessageFixedText &t) {
|
||||
return t.text().NULTerminatedToString();
|
||||
},
|
||||
[](const MessageFormattedText &t) { return t.string(); },
|
||||
[](const MessageExpectedText &e) { return e.ToString(); }},
|
||||
[](const MessageExpectedText &e) { return e.ToString(); },
|
||||
},
|
||||
text_);
|
||||
}
|
||||
|
||||
|
@ -152,7 +163,8 @@ std::optional<ProvenanceRange> Message::GetProvenanceRange(
|
|||
return std::visit(
|
||||
common::visitors{
|
||||
[&](const CharBlock &cb) { return cooked.GetProvenanceRange(cb); },
|
||||
[](const ProvenanceRange &pr) { return std::make_optional(pr); }},
|
||||
[](const ProvenanceRange &pr) { return std::make_optional(pr); },
|
||||
},
|
||||
location_);
|
||||
}
|
||||
|
||||
|
@ -192,11 +204,13 @@ bool Message::Merge(const Message &that) {
|
|||
return AtSameLocation(that) &&
|
||||
(!that.attachment_.get() ||
|
||||
attachment_.get() == that.attachment_.get()) &&
|
||||
std::visit(common::visitors{[](MessageExpectedText &e1,
|
||||
const MessageExpectedText &e2) {
|
||||
return e1.Merge(e2);
|
||||
},
|
||||
[](const auto &, const auto &) { return false; }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[](MessageExpectedText &e1, const MessageExpectedText &e2) {
|
||||
return e1.Merge(e2);
|
||||
},
|
||||
[](const auto &, const auto &) { return false; },
|
||||
},
|
||||
text_, that.text_);
|
||||
}
|
||||
|
||||
|
@ -211,13 +225,15 @@ Message &Message::Attach(Message *m) {
|
|||
|
||||
bool Message::AtSameLocation(const Message &that) const {
|
||||
return std::visit(
|
||||
common::visitors{[](const CharBlock &cb1, const CharBlock &cb2) {
|
||||
return cb1.begin() == cb2.begin();
|
||||
},
|
||||
common::visitors{
|
||||
[](const CharBlock &cb1, const CharBlock &cb2) {
|
||||
return cb1.begin() == cb2.begin();
|
||||
},
|
||||
[](const ProvenanceRange &pr1, const ProvenanceRange &pr2) {
|
||||
return pr1.start() == pr2.start();
|
||||
},
|
||||
[](const auto &, const auto &) { return false; }},
|
||||
[](const auto &, const auto &) { return false; },
|
||||
},
|
||||
location_, that.location_);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,13 +30,15 @@ ImportStmt::ImportStmt(common::ImportKind &&k, std::list<Name> &&n)
|
|||
// R901 designator
|
||||
bool Designator::EndsInBareName() const {
|
||||
return std::visit(
|
||||
common::visitors{[](const ObjectName &) { return true; },
|
||||
common::visitors{
|
||||
[](const ObjectName &) { return true; },
|
||||
[](const DataRef &dr) {
|
||||
return std::holds_alternative<Name>(dr.u) ||
|
||||
std::holds_alternative<common::Indirection<StructureComponent>>(
|
||||
dr.u);
|
||||
},
|
||||
[](const Substring &) { return false; }},
|
||||
[](const Substring &) { return false; },
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
|
|
|
@ -212,29 +212,32 @@ void AllSources::EmitMessage(std::ostream &o,
|
|||
o << "^\n";
|
||||
}
|
||||
},
|
||||
[&](const CompilerInsertion &ins) { o << message << '\n'; }},
|
||||
[&](const CompilerInsertion &ins) { o << message << '\n'; },
|
||||
},
|
||||
origin.u);
|
||||
}
|
||||
|
||||
const SourceFile *AllSources::GetSourceFile(
|
||||
Provenance at, std::size_t *offset) const {
|
||||
const Origin &origin{MapToOrigin(at)};
|
||||
return std::visit(common::visitors{[&](const Inclusion &inc) {
|
||||
if (offset != nullptr) {
|
||||
*offset =
|
||||
origin.covers.MemberOffset(at);
|
||||
}
|
||||
return &inc.source;
|
||||
},
|
||||
[&](const Macro &mac) {
|
||||
return GetSourceFile(origin.replaces.start(), offset);
|
||||
},
|
||||
[offset](const CompilerInsertion &) {
|
||||
if (offset != nullptr) {
|
||||
*offset = 0;
|
||||
}
|
||||
return static_cast<const SourceFile *>(nullptr);
|
||||
}},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[&](const Inclusion &inc) {
|
||||
if (offset != nullptr) {
|
||||
*offset = origin.covers.MemberOffset(at);
|
||||
}
|
||||
return &inc.source;
|
||||
},
|
||||
[&](const Macro &mac) {
|
||||
return GetSourceFile(origin.replaces.start(), offset);
|
||||
},
|
||||
[offset](const CompilerInsertion &) {
|
||||
if (offset != nullptr) {
|
||||
*offset = 0;
|
||||
}
|
||||
return static_cast<const SourceFile *>(nullptr);
|
||||
},
|
||||
},
|
||||
origin.u);
|
||||
}
|
||||
|
||||
|
@ -281,13 +284,15 @@ AllSources::Origin::Origin(ProvenanceRange r, const std::string &text)
|
|||
|
||||
const char &AllSources::Origin::operator[](std::size_t n) const {
|
||||
return std::visit(
|
||||
common::visitors{[n](const Inclusion &inc) -> const char & {
|
||||
return inc.source.content()[n];
|
||||
},
|
||||
common::visitors{
|
||||
[n](const Inclusion &inc) -> const char & {
|
||||
return inc.source.content()[n];
|
||||
},
|
||||
[n](const Macro &mac) -> const char & { return mac.expansion[n]; },
|
||||
[n](const CompilerInsertion &ins) -> const char & {
|
||||
return ins.text[n];
|
||||
}},
|
||||
},
|
||||
},
|
||||
u);
|
||||
}
|
||||
|
||||
|
@ -356,21 +361,23 @@ std::ostream &AllSources::Dump(std::ostream &o) const {
|
|||
o << " ";
|
||||
DumpRange(o, m.covers);
|
||||
o << " -> ";
|
||||
std::visit(common::visitors{[&](const Inclusion &inc) {
|
||||
if (inc.isModule) {
|
||||
o << "module ";
|
||||
}
|
||||
o << "file " << inc.source.path();
|
||||
},
|
||||
[&](const Macro &mac) { o << "macro " << mac.expansion; },
|
||||
[&](const CompilerInsertion &ins) {
|
||||
o << "compiler '" << ins.text << '\'';
|
||||
if (ins.text.length() == 1) {
|
||||
int ch = ins.text[0];
|
||||
o << " (0x" << std::hex << (ch & 0xff) << std::dec
|
||||
<< ")";
|
||||
}
|
||||
}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const Inclusion &inc) {
|
||||
if (inc.isModule) {
|
||||
o << "module ";
|
||||
}
|
||||
o << "file " << inc.source.path();
|
||||
},
|
||||
[&](const Macro &mac) { o << "macro " << mac.expansion; },
|
||||
[&](const CompilerInsertion &ins) {
|
||||
o << "compiler '" << ins.text << '\'';
|
||||
if (ins.text.length() == 1) {
|
||||
int ch = ins.text[0];
|
||||
o << " (0x" << std::hex << (ch & 0xff) << std::dec << ")";
|
||||
}
|
||||
},
|
||||
},
|
||||
m.u);
|
||||
if (IsValid(m.replaces)) {
|
||||
o << " replaces ";
|
||||
|
|
|
@ -137,10 +137,12 @@ public:
|
|||
}
|
||||
void Unparse(const KindSelector &x) { // R706
|
||||
std::visit(
|
||||
common::visitors{[&](const ScalarIntConstantExpr &y) {
|
||||
Put('('), Word("KIND="), Walk(y), Put(')');
|
||||
},
|
||||
[&](const KindSelector::StarSize &y) { Put('*'), Walk(y.v); }},
|
||||
common::visitors{
|
||||
[&](const ScalarIntConstantExpr &y) {
|
||||
Put('('), Word("KIND="), Walk(y), Put(')');
|
||||
},
|
||||
[&](const KindSelector::StarSize &y) { Put('*'), Walk(y.v); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const SignedIntLiteralConstant &x) { // R707
|
||||
|
@ -165,17 +167,21 @@ public:
|
|||
Walk(", LEN=", x.length), Put(')');
|
||||
}
|
||||
void Unparse(const LengthSelector &x) { // R722
|
||||
std::visit(common::visitors{[&](const TypeParamValue &y) {
|
||||
Put('('), Word("LEN="), Walk(y), Put(')');
|
||||
},
|
||||
[&](const CharLength &y) { Put('*'), Walk(y); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const TypeParamValue &y) {
|
||||
Put('('), Word("LEN="), Walk(y), Put(')');
|
||||
},
|
||||
[&](const CharLength &y) { Put('*'), Walk(y); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const CharLength &x) { // R723
|
||||
std::visit(common::visitors{[&](const TypeParamValue &y) {
|
||||
Put('('), Walk(y), Put(')');
|
||||
},
|
||||
[&](const std::int64_t &y) { Walk(y); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const TypeParamValue &y) { Put('('), Walk(y), Put(')'); },
|
||||
[&](const std::int64_t &y) { Walk(y); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const CharLiteralConstant &x) { // R724
|
||||
|
@ -259,15 +265,20 @@ public:
|
|||
void Unparse(const Contiguous &x) { Word("CONTIGUOUS"); }
|
||||
void Before(const ComponentAttrSpec &x) {
|
||||
std::visit(
|
||||
common::visitors{[&](const CoarraySpec &) { Word("CODIMENSION["); },
|
||||
common::visitors{
|
||||
[&](const CoarraySpec &) { Word("CODIMENSION["); },
|
||||
[&](const ComponentArraySpec &) { Word("DIMENSION("); },
|
||||
[](const auto &) {}},
|
||||
[](const auto &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Post(const ComponentAttrSpec &x) {
|
||||
std::visit(
|
||||
common::visitors{[&](const CoarraySpec &) { Put(']'); },
|
||||
[&](const ComponentArraySpec &) { Put(')'); }, [](const auto &) {}},
|
||||
common::visitors{
|
||||
[&](const CoarraySpec &) { Put(']'); },
|
||||
[&](const ComponentArraySpec &) { Put(')'); },
|
||||
[](const auto &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const ComponentDecl &x) { // R739
|
||||
|
@ -278,10 +289,11 @@ public:
|
|||
Walk(std::get<std::optional<Initialization>>(x.t));
|
||||
}
|
||||
void Unparse(const ComponentArraySpec &x) { // R740
|
||||
std::visit(common::visitors{[&](const std::list<ExplicitShapeSpec> &y) {
|
||||
Walk(y, ",");
|
||||
},
|
||||
[&](const DeferredShapeSpecList &y) { Walk(y); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const std::list<ExplicitShapeSpec> &y) { Walk(y, ","); },
|
||||
[&](const DeferredShapeSpecList &y) { Walk(y); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const ProcComponentDefStmt &x) { // R741
|
||||
|
@ -296,12 +308,14 @@ public:
|
|||
void Unparse(const Pass &x) { Word("PASS"), Walk("(", x.v, ")"); }
|
||||
void Unparse(const Initialization &x) { // R743 & R805
|
||||
std::visit(
|
||||
common::visitors{[&](const ConstantExpr &y) { Put(" = "), Walk(y); },
|
||||
common::visitors{
|
||||
[&](const ConstantExpr &y) { Put(" = "), Walk(y); },
|
||||
[&](const NullInit &y) { Put(" => "), Walk(y); },
|
||||
[&](const InitialDataTarget &y) { Put(" => "), Walk(y); },
|
||||
[&](const std::list<common::Indirection<DataStmtValue>> &y) {
|
||||
Walk("/", y, ", ", "/");
|
||||
}},
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const PrivateStmt &x) { // R745
|
||||
|
@ -442,14 +456,20 @@ public:
|
|||
}
|
||||
void Before(const AttrSpec &x) { // R802
|
||||
std::visit(
|
||||
common::visitors{[&](const CoarraySpec &y) { Word("CODIMENSION["); },
|
||||
common::visitors{
|
||||
[&](const CoarraySpec &y) { Word("CODIMENSION["); },
|
||||
[&](const ArraySpec &y) { Word("DIMENSION("); },
|
||||
[](const auto &) {}},
|
||||
[](const auto &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Post(const AttrSpec &x) {
|
||||
std::visit(common::visitors{[&](const CoarraySpec &y) { Put(']'); },
|
||||
[&](const ArraySpec &y) { Put(')'); }, [](const auto &) {}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const CoarraySpec &y) { Put(']'); },
|
||||
[&](const ArraySpec &y) { Put(')'); },
|
||||
[](const auto &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const EntityDecl &x) { // R803
|
||||
|
@ -467,8 +487,10 @@ public:
|
|||
}
|
||||
void Unparse(const CoarraySpec &x) { // R809
|
||||
std::visit(
|
||||
common::visitors{[&](const DeferredCoshapeSpecList &y) { Walk(y); },
|
||||
[&](const ExplicitCoshapeSpec &y) { Walk(y); }},
|
||||
common::visitors{
|
||||
[&](const DeferredCoshapeSpecList &y) { Walk(y); },
|
||||
[&](const ExplicitCoshapeSpec &y) { Walk(y); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const DeferredCoshapeSpecList &x) { // R810
|
||||
|
@ -488,14 +510,15 @@ public:
|
|||
Walk(std::get<SpecificationExpr>(x.t));
|
||||
}
|
||||
void Unparse(const ArraySpec &x) { // R815
|
||||
std::visit(common::visitors{[&](const std::list<ExplicitShapeSpec> &y) {
|
||||
Walk(y, ",");
|
||||
},
|
||||
[&](const std::list<AssumedShapeSpec> &y) { Walk(y, ","); },
|
||||
[&](const DeferredShapeSpecList &y) { Walk(y); },
|
||||
[&](const AssumedSizeSpec &y) { Walk(y); },
|
||||
[&](const ImpliedShapeSpec &y) { Walk(y); },
|
||||
[&](const AssumedRankSpec &y) { Walk(y); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const std::list<ExplicitShapeSpec> &y) { Walk(y, ","); },
|
||||
[&](const std::list<AssumedShapeSpec> &y) { Walk(y, ","); },
|
||||
[&](const DeferredShapeSpecList &y) { Walk(y); },
|
||||
[&](const AssumedSizeSpec &y) { Walk(y); },
|
||||
[&](const ImpliedShapeSpec &y) { Walk(y); },
|
||||
[&](const AssumedRankSpec &y) { Walk(y); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Post(const AssumedShapeSpec &) { Put(':'); } // R819
|
||||
|
@ -630,12 +653,13 @@ public:
|
|||
}
|
||||
void Unparse(const ImplicitStmt &x) { // R863
|
||||
Word("IMPLICIT ");
|
||||
std::visit(common::visitors{[&](const std::list<ImplicitSpec> &y) {
|
||||
Walk(y, ", ");
|
||||
},
|
||||
[&](const std::list<ImplicitStmt::ImplicitNoneNameSpec> &y) {
|
||||
Word("NONE"), Walk(" (", y, ", ", ")");
|
||||
}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const std::list<ImplicitSpec> &y) { Walk(y, ", "); },
|
||||
[&](const std::list<ImplicitStmt::ImplicitNoneNameSpec> &y) {
|
||||
Word("NONE"), Walk(" (", y, ", ", ")");
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const ImplicitSpec &x) { // R864
|
||||
|
@ -742,9 +766,12 @@ public:
|
|||
Walk(", ", std::get<std::list<AllocOpt>>(x.t), ", "), Put(')');
|
||||
}
|
||||
void Before(const AllocOpt &x) { // R928, R931
|
||||
std::visit(common::visitors{[&](const AllocOpt::Mold &) { Word("MOLD="); },
|
||||
[&](const AllocOpt::Source &) { Word("SOURCE="); },
|
||||
[](const StatOrErrmsg &) {}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const AllocOpt::Mold &) { Word("MOLD="); },
|
||||
[&](const AllocOpt::Source &) { Word("SOURCE="); },
|
||||
[](const StatOrErrmsg &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const Allocation &x) { // R932
|
||||
|
@ -769,8 +796,11 @@ public:
|
|||
Walk(", ", std::get<std::list<StatOrErrmsg>>(x.t), ", "), Put(')');
|
||||
}
|
||||
void Before(const StatOrErrmsg &x) { // R942 & R1165
|
||||
std::visit(common::visitors{[&](const StatVariable &) { Word("STAT="); },
|
||||
[&](const MsgVariable &) { Word("ERRMSG="); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const StatVariable &) { Word("STAT="); },
|
||||
[&](const MsgVariable &) { Word("ERRMSG="); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
|
||||
|
@ -816,10 +846,12 @@ public:
|
|||
void Unparse(const PointerAssignmentStmt &x) { // R1033, R1034, R1038
|
||||
Walk(std::get<DataRef>(x.t));
|
||||
std::visit(
|
||||
common::visitors{[&](const std::list<BoundsRemapping> &y) {
|
||||
Put('('), Walk(y), Put(')');
|
||||
},
|
||||
[&](const std::list<BoundsSpec> &y) { Walk("(", y, ", ", ")"); }},
|
||||
common::visitors{
|
||||
[&](const std::list<BoundsRemapping> &y) {
|
||||
Put('('), Walk(y), Put(')');
|
||||
},
|
||||
[&](const std::list<BoundsSpec> &y) { Walk("(", y, ", ", ")"); },
|
||||
},
|
||||
std::get<PointerAssignmentStmt::Bounds>(x.t).u);
|
||||
Put(" => "), Walk(std::get<Expr>(x.t));
|
||||
}
|
||||
|
@ -916,10 +948,13 @@ public:
|
|||
Word("DO "), Walk(std::get<std::optional<LoopControl>>(x.t));
|
||||
}
|
||||
void Unparse(const LoopControl &x) { // R1123
|
||||
std::visit(common::visitors{[&](const ScalarLogicalExpr &y) {
|
||||
Word("WHILE ("), Walk(y), Put(')');
|
||||
},
|
||||
[&](const auto &y) { Walk(y); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const ScalarLogicalExpr &y) {
|
||||
Word("WHILE ("), Walk(y), Put(')');
|
||||
},
|
||||
[&](const auto &y) { Walk(y); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const ConcurrentHeader &x) { // R1125
|
||||
|
@ -983,10 +1018,13 @@ public:
|
|||
Outdent(), Word("END SELECT"), Walk(" ", x.v);
|
||||
}
|
||||
void Unparse(const CaseSelector &x) { // R1145
|
||||
std::visit(common::visitors{[&](const std::list<CaseValueRange> &y) {
|
||||
Put('('), Walk(y), Put(')');
|
||||
},
|
||||
[&](const Default &) { Word("DEFAULT"); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const std::list<CaseValueRange> &y) {
|
||||
Put('('), Walk(y), Put(')');
|
||||
},
|
||||
[&](const Default &) { Word("DEFAULT"); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const CaseValueRange::Range &x) { // R1146
|
||||
|
@ -999,11 +1037,14 @@ public:
|
|||
}
|
||||
void Unparse(const SelectRankCaseStmt &x) { // R1150
|
||||
Outdent(), Word("RANK ");
|
||||
std::visit(common::visitors{[&](const ScalarIntConstantExpr &y) {
|
||||
Put('('), Walk(y), Put(')');
|
||||
},
|
||||
[&](const Star &) { Put("(*)"); },
|
||||
[&](const Default &) { Word("DEFAULT"); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const ScalarIntConstantExpr &y) {
|
||||
Put('('), Walk(y), Put(')');
|
||||
},
|
||||
[&](const Star &) { Put("(*)"); },
|
||||
[&](const Default &) { Word("DEFAULT"); },
|
||||
},
|
||||
std::get<SelectRankCaseStmt::Rank>(x.t).u);
|
||||
Walk(" ", std::get<std::optional<Name>>(x.t)), Indent();
|
||||
}
|
||||
|
@ -1017,13 +1058,14 @@ public:
|
|||
Walk(" ", std::get<std::optional<Name>>(x.t)), Indent();
|
||||
}
|
||||
void Unparse(const TypeGuardStmt::Guard &x) {
|
||||
std::visit(common::visitors{[&](const TypeSpec &y) {
|
||||
Word("TYPE IS ("), Walk(y), Put(')');
|
||||
},
|
||||
[&](const DerivedTypeSpec &y) {
|
||||
Word("CLASS IS ("), Walk(y), Put(')');
|
||||
},
|
||||
[&](const Default &) { Word("CLASS DEFAULT"); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const TypeSpec &y) { Word("TYPE IS ("), Walk(y), Put(')'); },
|
||||
[&](const DerivedTypeSpec &y) {
|
||||
Word("CLASS IS ("), Walk(y), Put(')');
|
||||
},
|
||||
[&](const Default &) { Word("CLASS DEFAULT"); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const ExitStmt &x) { // R1156
|
||||
|
@ -1069,8 +1111,10 @@ public:
|
|||
}
|
||||
void Before(const EventWaitStmt::EventWaitSpec &x) { // R1173, R1174
|
||||
std::visit(
|
||||
common::visitors{[&](const ScalarIntExpr &x) { Word("UNTIL_COUNT="); },
|
||||
[](const StatOrErrmsg &) {}},
|
||||
common::visitors{
|
||||
[&](const ScalarIntExpr &x) { Word("UNTIL_COUNT="); },
|
||||
[](const StatOrErrmsg &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const EventWaitStmt &x) { // R1170
|
||||
|
@ -1086,8 +1130,10 @@ public:
|
|||
}
|
||||
void Before(const FormTeamStmt::FormTeamSpec &x) { // R1176, R1177
|
||||
std::visit(
|
||||
common::visitors{[&](const ScalarIntExpr &x) { Word("NEW_INDEX="); },
|
||||
[](const StatOrErrmsg &) {}},
|
||||
common::visitors{
|
||||
[&](const ScalarIntExpr &x) { Word("NEW_INDEX="); },
|
||||
[](const StatOrErrmsg &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const LockStmt &x) { // R1178
|
||||
|
@ -1096,10 +1142,11 @@ public:
|
|||
Put(')');
|
||||
}
|
||||
void Before(const LockStmt::LockStat &x) { // R1179
|
||||
std::visit(common::visitors{[&](const ScalarLogicalVariable &) {
|
||||
Word("ACQUIRED_LOCK=");
|
||||
},
|
||||
[](const StatOrErrmsg &y) {}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const ScalarLogicalVariable &) { Word("ACQUIRED_LOCK="); },
|
||||
[](const StatOrErrmsg &y) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const UnlockStmt &x) { // R1180
|
||||
|
@ -1112,53 +1159,59 @@ public:
|
|||
Word("OPEN ("), Walk(x.v, ", "), Put(')');
|
||||
}
|
||||
bool Pre(const ConnectSpec &x) { // R1205
|
||||
return std::visit(common::visitors{[&](const FileUnitNumber &) {
|
||||
Word("UNIT=");
|
||||
return true;
|
||||
},
|
||||
[&](const FileNameExpr &) {
|
||||
Word("FILE=");
|
||||
return true;
|
||||
},
|
||||
[&](const ConnectSpec::CharExpr &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const MsgVariable &) {
|
||||
Word("IOMSG=");
|
||||
return true;
|
||||
},
|
||||
[&](const StatVariable &) {
|
||||
Word("IOSTAT=");
|
||||
return true;
|
||||
},
|
||||
[&](const ConnectSpec::Recl &) {
|
||||
Word("RECL=");
|
||||
return true;
|
||||
},
|
||||
[&](const ConnectSpec::Newunit &) {
|
||||
Word("NEWUNIT=");
|
||||
return true;
|
||||
},
|
||||
[&](const ErrLabel &) {
|
||||
Word("ERR=");
|
||||
return true;
|
||||
},
|
||||
[&](const StatusExpr &) {
|
||||
Word("STATUS=");
|
||||
return true;
|
||||
}},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[&](const FileUnitNumber &) {
|
||||
Word("UNIT=");
|
||||
return true;
|
||||
},
|
||||
[&](const FileNameExpr &) {
|
||||
Word("FILE=");
|
||||
return true;
|
||||
},
|
||||
[&](const ConnectSpec::CharExpr &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const MsgVariable &) {
|
||||
Word("IOMSG=");
|
||||
return true;
|
||||
},
|
||||
[&](const StatVariable &) {
|
||||
Word("IOSTAT=");
|
||||
return true;
|
||||
},
|
||||
[&](const ConnectSpec::Recl &) {
|
||||
Word("RECL=");
|
||||
return true;
|
||||
},
|
||||
[&](const ConnectSpec::Newunit &) {
|
||||
Word("NEWUNIT=");
|
||||
return true;
|
||||
},
|
||||
[&](const ErrLabel &) {
|
||||
Word("ERR=");
|
||||
return true;
|
||||
},
|
||||
[&](const StatusExpr &) {
|
||||
Word("STATUS=");
|
||||
return true;
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const CloseStmt &x) { // R1208
|
||||
Word("CLOSE ("), Walk(x.v, ", "), Put(')');
|
||||
}
|
||||
void Before(const CloseStmt::CloseSpec &x) { // R1209
|
||||
std::visit(common::visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
|
||||
[&](const StatVariable &) { Word("IOSTAT="); },
|
||||
[&](const MsgVariable &) { Word("IOMSG="); },
|
||||
[&](const ErrLabel &) { Word("ERR="); },
|
||||
[&](const StatusExpr &) { Word("STATUS="); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const FileUnitNumber &) { Word("UNIT="); },
|
||||
[&](const StatVariable &) { Word("IOSTAT="); },
|
||||
[&](const MsgVariable &) { Word("IOMSG="); },
|
||||
[&](const ErrLabel &) { Word("ERR="); },
|
||||
[&](const StatusExpr &) { Word("STATUS="); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const ReadStmt &x) { // R1210
|
||||
|
@ -1198,62 +1251,65 @@ public:
|
|||
Walk(", ", std::get<std::list<OutputItem>>(x.t), ", ");
|
||||
}
|
||||
bool Pre(const IoControlSpec &x) { // R1213
|
||||
return std::visit(common::visitors{[&](const IoUnit &) {
|
||||
Word("UNIT=");
|
||||
return true;
|
||||
},
|
||||
[&](const Format &) {
|
||||
Word("FMT=");
|
||||
return true;
|
||||
},
|
||||
[&](const Name &) {
|
||||
Word("NML=");
|
||||
return true;
|
||||
},
|
||||
[&](const IoControlSpec::CharExpr &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const IoControlSpec::Asynchronous &) {
|
||||
Word("ASYNCHRONOUS=");
|
||||
return true;
|
||||
},
|
||||
[&](const EndLabel &) {
|
||||
Word("END=");
|
||||
return true;
|
||||
},
|
||||
[&](const EorLabel &) {
|
||||
Word("EOR=");
|
||||
return true;
|
||||
},
|
||||
[&](const ErrLabel &) {
|
||||
Word("ERR=");
|
||||
return true;
|
||||
},
|
||||
[&](const IdVariable &) {
|
||||
Word("ID=");
|
||||
return true;
|
||||
},
|
||||
[&](const MsgVariable &) {
|
||||
Word("IOMSG=");
|
||||
return true;
|
||||
},
|
||||
[&](const StatVariable &) {
|
||||
Word("IOSTAT=");
|
||||
return true;
|
||||
},
|
||||
[&](const IoControlSpec::Pos &) {
|
||||
Word("POS=");
|
||||
return true;
|
||||
},
|
||||
[&](const IoControlSpec::Rec &) {
|
||||
Word("REC=");
|
||||
return true;
|
||||
},
|
||||
[&](const IoControlSpec::Size &) {
|
||||
Word("SIZE=");
|
||||
return true;
|
||||
}},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[&](const IoUnit &) {
|
||||
Word("UNIT=");
|
||||
return true;
|
||||
},
|
||||
[&](const Format &) {
|
||||
Word("FMT=");
|
||||
return true;
|
||||
},
|
||||
[&](const Name &) {
|
||||
Word("NML=");
|
||||
return true;
|
||||
},
|
||||
[&](const IoControlSpec::CharExpr &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const IoControlSpec::Asynchronous &) {
|
||||
Word("ASYNCHRONOUS=");
|
||||
return true;
|
||||
},
|
||||
[&](const EndLabel &) {
|
||||
Word("END=");
|
||||
return true;
|
||||
},
|
||||
[&](const EorLabel &) {
|
||||
Word("EOR=");
|
||||
return true;
|
||||
},
|
||||
[&](const ErrLabel &) {
|
||||
Word("ERR=");
|
||||
return true;
|
||||
},
|
||||
[&](const IdVariable &) {
|
||||
Word("ID=");
|
||||
return true;
|
||||
},
|
||||
[&](const MsgVariable &) {
|
||||
Word("IOMSG=");
|
||||
return true;
|
||||
},
|
||||
[&](const StatVariable &) {
|
||||
Word("IOSTAT=");
|
||||
return true;
|
||||
},
|
||||
[&](const IoControlSpec::Pos &) {
|
||||
Word("POS=");
|
||||
return true;
|
||||
},
|
||||
[&](const IoControlSpec::Rec &) {
|
||||
Word("REC=");
|
||||
return true;
|
||||
},
|
||||
[&](const IoControlSpec::Size &) {
|
||||
Word("SIZE=");
|
||||
return true;
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const InputImpliedDo &x) { // R1218
|
||||
|
@ -1268,13 +1324,16 @@ public:
|
|||
Word("WAIT ("), Walk(x.v, ", "), Put(')');
|
||||
}
|
||||
void Before(const WaitSpec &x) { // R1223
|
||||
std::visit(common::visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
|
||||
[&](const EndLabel &) { Word("END="); },
|
||||
[&](const EorLabel &) { Word("EOR="); },
|
||||
[&](const ErrLabel &) { Word("ERR="); },
|
||||
[&](const IdExpr &) { Word("ID="); },
|
||||
[&](const MsgVariable &) { Word("IOMSG="); },
|
||||
[&](const StatVariable &) { Word("IOSTAT="); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const FileUnitNumber &) { Word("UNIT="); },
|
||||
[&](const EndLabel &) { Word("END="); },
|
||||
[&](const EorLabel &) { Word("EOR="); },
|
||||
[&](const ErrLabel &) { Word("ERR="); },
|
||||
[&](const IdExpr &) { Word("ID="); },
|
||||
[&](const MsgVariable &) { Word("IOMSG="); },
|
||||
[&](const StatVariable &) { Word("IOSTAT="); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const BackspaceStmt &x) { // R1224
|
||||
|
@ -1287,10 +1346,13 @@ public:
|
|||
Word("REWIND ("), Walk(x.v, ", "), Put(')');
|
||||
}
|
||||
void Before(const PositionOrFlushSpec &x) { // R1227 & R1229
|
||||
std::visit(common::visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
|
||||
[&](const MsgVariable &) { Word("IOMSG="); },
|
||||
[&](const StatVariable &) { Word("IOSTAT="); },
|
||||
[&](const ErrLabel &) { Word("ERR="); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const FileUnitNumber &) { Word("UNIT="); },
|
||||
[&](const MsgVariable &) { Word("IOMSG="); },
|
||||
[&](const StatVariable &) { Word("IOSTAT="); },
|
||||
[&](const ErrLabel &) { Word("ERR="); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const FlushStmt &x) { // R1228
|
||||
|
@ -1299,41 +1361,46 @@ public:
|
|||
void Unparse(const InquireStmt &x) { // R1230
|
||||
Word("INQUIRE (");
|
||||
std::visit(
|
||||
common::visitors{[&](const InquireStmt::Iolength &y) {
|
||||
Word("IOLENGTH="), Walk(y.t, ") ");
|
||||
},
|
||||
[&](const std::list<InquireSpec> &y) { Walk(y, ", "), Put(')'); }},
|
||||
common::visitors{
|
||||
[&](const InquireStmt::Iolength &y) {
|
||||
Word("IOLENGTH="), Walk(y.t, ") ");
|
||||
},
|
||||
[&](const std::list<InquireSpec> &y) { Walk(y, ", "), Put(')'); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
bool Pre(const InquireSpec &x) { // R1231
|
||||
return std::visit(common::visitors{[&](const FileUnitNumber &) {
|
||||
Word("UNIT=");
|
||||
return true;
|
||||
},
|
||||
[&](const FileNameExpr &) {
|
||||
Word("FILE=");
|
||||
return true;
|
||||
},
|
||||
[&](const InquireSpec::CharVar &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const InquireSpec::IntVar &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const InquireSpec::LogVar &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const IdExpr &) {
|
||||
Word("ID=");
|
||||
return true;
|
||||
},
|
||||
[&](const ErrLabel &) {
|
||||
Word("ERR=");
|
||||
return true;
|
||||
}},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[&](const FileUnitNumber &) {
|
||||
Word("UNIT=");
|
||||
return true;
|
||||
},
|
||||
[&](const FileNameExpr &) {
|
||||
Word("FILE=");
|
||||
return true;
|
||||
},
|
||||
[&](const InquireSpec::CharVar &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const InquireSpec::IntVar &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const InquireSpec::LogVar &y) {
|
||||
Walk(y.t, "=");
|
||||
return false;
|
||||
},
|
||||
[&](const IdExpr &) {
|
||||
Word("ID=");
|
||||
return true;
|
||||
},
|
||||
[&](const ErrLabel &) {
|
||||
Word("ERR=");
|
||||
return true;
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
|
||||
|
@ -1348,14 +1415,16 @@ public:
|
|||
if (x.repeatCount.has_value()) {
|
||||
Walk(*x.repeatCount);
|
||||
}
|
||||
std::visit(common::visitors{[&](const std::string &y) {
|
||||
Put(QuoteCharacterLiteral(
|
||||
y, true, backslashEscapes_));
|
||||
},
|
||||
[&](const std::list<format::FormatItem> &y) {
|
||||
Walk("(", y, ",", ")");
|
||||
},
|
||||
[&](const auto &y) { Walk(y); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const std::string &y) {
|
||||
Put(QuoteCharacterLiteral(y, true, backslashEscapes_));
|
||||
},
|
||||
[&](const std::list<format::FormatItem> &y) {
|
||||
Walk("(", y, ",", ")");
|
||||
},
|
||||
[&](const auto &y) { Walk(y); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(
|
||||
|
@ -1461,15 +1530,18 @@ public:
|
|||
std::visit(
|
||||
common::visitors{
|
||||
[&](const std::list<Rename> &y) { Walk(", ", y, ", "); },
|
||||
[&](const std::list<Only> &y) { Walk(", ONLY: ", y, ", "); }},
|
||||
[&](const std::list<Only> &y) { Walk(", ONLY: ", y, ", "); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const Rename &x) { // R1411
|
||||
std::visit(
|
||||
common::visitors{[&](const Rename::Names &y) { Walk(y.t, " => "); },
|
||||
common::visitors{
|
||||
[&](const Rename::Names &y) { Walk(y.t, " => "); },
|
||||
[&](const Rename::Operators &y) {
|
||||
Word("OPERATOR("), Walk(y.t, ") => OPERATOR("), Put(")");
|
||||
}},
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const SubmoduleStmt &x) { // R1417
|
||||
|
@ -1489,10 +1561,13 @@ public:
|
|||
}
|
||||
|
||||
void Unparse(const InterfaceStmt &x) { // R1503
|
||||
std::visit(common::visitors{[&](const std::optional<GenericSpec> &y) {
|
||||
Word("INTERFACE"), Walk(" ", y);
|
||||
},
|
||||
[&](const Abstract &) { Word("ABSTRACT INTERFACE"); }},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const std::optional<GenericSpec> &y) {
|
||||
Word("INTERFACE"), Walk(" ", y);
|
||||
},
|
||||
[&](const Abstract &) { Word("ABSTRACT INTERFACE"); },
|
||||
},
|
||||
x.u);
|
||||
Indent();
|
||||
}
|
||||
|
@ -1509,7 +1584,8 @@ public:
|
|||
}
|
||||
void Before(const GenericSpec &x) { // R1508, R1509
|
||||
std::visit(
|
||||
common::visitors{[&](const DefinedOperator &x) { Word("OPERATOR("); },
|
||||
common::visitors{
|
||||
[&](const DefinedOperator &x) { Word("OPERATOR("); },
|
||||
[&](const GenericSpec::Assignment &) { Word("ASSIGNMENT(=)"); },
|
||||
[&](const GenericSpec::ReadFormatted &) {
|
||||
Word("READ(FORMATTED)");
|
||||
|
@ -1523,12 +1599,16 @@ public:
|
|||
[&](const GenericSpec::WriteUnformatted &) {
|
||||
Word("WRITE(UNFORMATTED)");
|
||||
},
|
||||
[](const auto &) {}},
|
||||
[](const auto &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Post(const GenericSpec &x) {
|
||||
std::visit(common::visitors{[&](const DefinedOperator &x) { Put(')'); },
|
||||
[](const auto &) {}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[&](const DefinedOperator &x) { Put(')'); },
|
||||
[](const auto &) {},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const GenericStmt &x) { // R1510
|
||||
|
@ -1652,7 +1732,8 @@ public:
|
|||
Word("!DIR$ IGNORE_TKR");
|
||||
Walk(" ", tkr, ", ");
|
||||
},
|
||||
[&](const CompilerDirective::IVDEP &) { Word("!DIR$ IVDEP\n"); }},
|
||||
[&](const CompilerDirective::IVDEP &) { Word("!DIR$ IVDEP\n"); },
|
||||
},
|
||||
x.u);
|
||||
Put('\n');
|
||||
}
|
||||
|
@ -1736,20 +1817,23 @@ public:
|
|||
Put(")");
|
||||
}
|
||||
bool Pre(const OmpDependClause &x) {
|
||||
return std::visit(common::visitors{[&](const OmpDependClause::Source &y) {
|
||||
Word("DEPEND(SOURCE)");
|
||||
return false;
|
||||
},
|
||||
[&](const OmpDependClause::Sink &y) {
|
||||
Word("DEPEND(SINK:");
|
||||
Walk(y.v);
|
||||
Put(")");
|
||||
return false;
|
||||
},
|
||||
[&](const OmpDependClause::InOut &y) {
|
||||
Word("DEPEND");
|
||||
return true;
|
||||
}},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[&](const OmpDependClause::Source &y) {
|
||||
Word("DEPEND(SOURCE)");
|
||||
return false;
|
||||
},
|
||||
[&](const OmpDependClause::Sink &y) {
|
||||
Word("DEPEND(SINK:");
|
||||
Walk(y.v);
|
||||
Put(")");
|
||||
return false;
|
||||
},
|
||||
[&](const OmpDependClause::InOut &y) {
|
||||
Word("DEPEND");
|
||||
return true;
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
bool Pre(const OmpDefaultClause &x) {
|
||||
|
@ -1939,21 +2023,24 @@ public:
|
|||
},
|
||||
[&](const OmpLoopDirective::TeamsDistribute &) {
|
||||
Word("TEAMS DISTRIBUTE ");
|
||||
}},
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const OmpObjectList &x) { Walk(x.v, ","); }
|
||||
void Unparse(const OmpStandaloneDirective &x) {
|
||||
std::visit(
|
||||
common::visitors{[&](const OmpStandaloneDirective::TargetEnterData &) {
|
||||
Word("TARGET ENTER DATA ");
|
||||
},
|
||||
common::visitors{
|
||||
[&](const OmpStandaloneDirective::TargetEnterData &) {
|
||||
Word("TARGET ENTER DATA ");
|
||||
},
|
||||
[&](const OmpStandaloneDirective::TargetExitData &) {
|
||||
Word("TARGET EXIT DATA ");
|
||||
},
|
||||
[&](const OmpStandaloneDirective::TargetUpdate &) {
|
||||
Word("TARGET UPDATE ");
|
||||
}},
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const OmpBlockDirective &x) {
|
||||
|
@ -1977,7 +2064,8 @@ public:
|
|||
[&](const OmpBlockDirective::Target &) { Word("TARGET "); },
|
||||
[&](const OmpBlockDirective::Taskgroup &) { Word("TASKGROUP "); },
|
||||
[&](const OmpBlockDirective::Task &) { Word("TASK "); },
|
||||
[&](const OmpBlockDirective::Teams &) { Word("TEAMS "); }},
|
||||
[&](const OmpBlockDirective::Teams &) { Word("TEAMS "); },
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Unparse(const OmpAtomic &x) {
|
||||
|
@ -2099,10 +2187,11 @@ public:
|
|||
BeginOpenMP();
|
||||
Word("!$OMP ");
|
||||
return std::visit(
|
||||
common::visitors{[&](const OpenMPDeclareReductionConstruct &y) {
|
||||
Word("DECLARE REDUCTION ");
|
||||
return true;
|
||||
},
|
||||
common::visitors{
|
||||
[&](const OpenMPDeclareReductionConstruct &y) {
|
||||
Word("DECLARE REDUCTION ");
|
||||
return true;
|
||||
},
|
||||
[&](const OpenMPDeclareSimdConstruct &y) {
|
||||
Word("DECLARE SIMD ");
|
||||
Walk("(", std::get<std::optional<Name>>(y.t), ")");
|
||||
|
@ -2118,7 +2207,8 @@ public:
|
|||
[&](const OpenMPDeclarativeConstruct::Threadprivate &y) {
|
||||
Word("THREADPRIVATE (");
|
||||
return true;
|
||||
}},
|
||||
},
|
||||
},
|
||||
x.u);
|
||||
}
|
||||
void Post(const OpenMPDeclarativeConstruct &x) {
|
||||
|
|
|
@ -31,7 +31,8 @@ public:
|
|||
for (auto i{block.begin()}, end{block.end()}; i != end; ++i) {
|
||||
if (auto *executableConstruct{std::get_if<ExecutableConstruct>(&i->u)}) {
|
||||
std::visit(
|
||||
common::visitors{[](auto &) {},
|
||||
common::visitors{
|
||||
[](auto &) {},
|
||||
[&](Statement<common::Indirection<LabelDoStmt>> &labelDoStmt) {
|
||||
auto &label{std::get<Label>(labelDoStmt.statement->t)};
|
||||
stack.push_back(LabelInfo{i, label});
|
||||
|
@ -41,7 +42,8 @@ public:
|
|||
},
|
||||
[&](Statement<ActionStmt> &actionStmt) {
|
||||
CanonicalizeIfMatch(block, stack, i, actionStmt);
|
||||
}},
|
||||
},
|
||||
},
|
||||
executableConstruct->u);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,25 +233,28 @@ static CS GatherAllVariableNames(
|
|||
const std::list<parser::LocalitySpec> &localitySpecs) {
|
||||
CS names;
|
||||
for (auto &ls : localitySpecs) {
|
||||
std::visit(common::visitors{[](auto &) {},
|
||||
[&](const parser::LocalitySpec::Local &local) {
|
||||
for (auto &v : local.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
[&](const parser::LocalitySpec::LocalInit &localInit) {
|
||||
for (auto &v : localInit.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
[&](const parser::LocalitySpec::Shared &shared) {
|
||||
for (auto &v : shared.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[](auto &) {},
|
||||
[&](const parser::LocalitySpec::Local &local) {
|
||||
for (auto &v : local.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
[&](const parser::LocalitySpec::LocalInit &localInit) {
|
||||
for (auto &v : localInit.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
[&](const parser::LocalitySpec::Shared &shared) {
|
||||
for (auto &v : shared.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
},
|
||||
ls.u);
|
||||
}
|
||||
return names;
|
||||
|
@ -260,19 +263,22 @@ static CS GatherNotSharedVariableNames(
|
|||
const std::list<parser::LocalitySpec> &localitySpecs) {
|
||||
CS names;
|
||||
for (auto &ls : localitySpecs) {
|
||||
std::visit(common::visitors{[](auto &) {},
|
||||
[&](const parser::LocalitySpec::Local &local) {
|
||||
for (auto &v : local.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
[&](const parser::LocalitySpec::LocalInit &localInit) {
|
||||
for (auto &v : localInit.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[](auto &) {},
|
||||
[&](const parser::LocalitySpec::Local &local) {
|
||||
for (auto &v : local.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
[&](const parser::LocalitySpec::LocalInit &localInit) {
|
||||
for (auto &v : localInit.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
},
|
||||
ls.u);
|
||||
}
|
||||
return names;
|
||||
|
@ -281,13 +287,16 @@ static CS GatherLocalVariableNames(
|
|||
const std::list<parser::LocalitySpec> &localitySpecs) {
|
||||
CS names;
|
||||
for (auto &ls : localitySpecs) {
|
||||
std::visit(common::visitors{[](auto &) {},
|
||||
[&](const parser::LocalitySpec::Local &local) {
|
||||
for (auto &v : local.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
}},
|
||||
std::visit(
|
||||
common::visitors{
|
||||
[](auto &) {},
|
||||
[&](const parser::LocalitySpec::Local &local) {
|
||||
for (auto &v : local.v) {
|
||||
CHECK(v.symbol);
|
||||
names.push_back(v.symbol);
|
||||
}
|
||||
},
|
||||
},
|
||||
ls.u);
|
||||
}
|
||||
return names;
|
||||
|
|
|
@ -89,10 +89,12 @@ std::optional<DataRef> ExtractDataRef(Expr<SomeKind<CAT>> &&expr) {
|
|||
|
||||
template<> std::optional<DataRef> ExtractDataRef(Expr<SomeType> &&expr) {
|
||||
return std::visit(
|
||||
common::visitors{[](BOZLiteralConstant &&) -> std::optional<DataRef> {
|
||||
return std::nullopt;
|
||||
},
|
||||
[](auto &&catExpr) { return ExtractDataRef(std::move(catExpr)); }},
|
||||
common::visitors{
|
||||
[](BOZLiteralConstant &&) -> std::optional<DataRef> {
|
||||
return std::nullopt;
|
||||
},
|
||||
[](auto &&catExpr) { return ExtractDataRef(std::move(catExpr)); },
|
||||
},
|
||||
std::move(expr.u));
|
||||
}
|
||||
|
||||
|
@ -290,7 +292,8 @@ int ExprAnalyzer::Analyze(const std::optional<parser::KindParam> &kindParam,
|
|||
return defaultKind;
|
||||
}
|
||||
return std::visit(
|
||||
common::visitors{[](std::uint64_t k) { return static_cast<int>(k); },
|
||||
common::visitors{
|
||||
[](std::uint64_t k) { return static_cast<int>(k); },
|
||||
[&](const parser::Scalar<
|
||||
parser::Integer<parser::Constant<parser::Name>>> &n) {
|
||||
if (MaybeExpr ie{AnalyzeHelper(*this, n)}) {
|
||||
|
@ -310,7 +313,8 @@ int ExprAnalyzer::Analyze(const std::optional<parser::KindParam> &kindParam,
|
|||
}
|
||||
Say("Kanji not allowed here"_err_en_US);
|
||||
return defaultKind;
|
||||
}},
|
||||
},
|
||||
},
|
||||
kindParam->u);
|
||||
}
|
||||
|
||||
|
@ -672,19 +676,20 @@ std::optional<Expr<SubscriptInteger>> ExprAnalyzer::TripletPart(
|
|||
std::optional<Subscript> ExprAnalyzer::Analyze(
|
||||
const parser::SectionSubscript &ss) {
|
||||
return std::visit(
|
||||
common::visitors{[&](const parser::SubscriptTriplet &t) {
|
||||
return std::make_optional(
|
||||
Subscript{Triplet{TripletPart(std::get<0>(t.t)),
|
||||
TripletPart(std::get<1>(t.t)),
|
||||
TripletPart(std::get<2>(t.t))}});
|
||||
},
|
||||
common::visitors{
|
||||
[&](const parser::SubscriptTriplet &t) {
|
||||
return std::make_optional(Subscript{Triplet{
|
||||
TripletPart(std::get<0>(t.t)), TripletPart(std::get<1>(t.t)),
|
||||
TripletPart(std::get<2>(t.t))}});
|
||||
},
|
||||
[&](const auto &s) -> std::optional<Subscript> {
|
||||
if (auto subscriptExpr{AsSubscript(AnalyzeHelper(*this, s))}) {
|
||||
return {Subscript{std::move(*subscriptExpr)}};
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}},
|
||||
},
|
||||
},
|
||||
ss.u);
|
||||
}
|
||||
|
||||
|
@ -713,7 +718,8 @@ MaybeExpr ExprAnalyzer::ApplySubscripts(
|
|||
ArrayRef{std::move(base), std::move(subscripts)});
|
||||
}
|
||||
return std::nullopt;
|
||||
}},
|
||||
},
|
||||
},
|
||||
std::move(dataRef.u));
|
||||
}
|
||||
|
||||
|
@ -914,7 +920,8 @@ std::optional<CallAndArguments> ExprAnalyzer::Procedure(
|
|||
Say("TODO: unimplemented/invalid kind of symbol as procedure designator '%s'"_err_en_US,
|
||||
n.ToString().data());
|
||||
return std::nullopt;
|
||||
}},
|
||||
},
|
||||
},
|
||||
n.symbol->details());
|
||||
},
|
||||
[&](const parser::ProcComponentRef &pcr)
|
||||
|
@ -941,9 +948,10 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::FunctionReference &funcRef) {
|
|||
std::get<std::list<parser::ActualArgSpec>>(funcRef.v.t)) {
|
||||
MaybeExpr actualArgExpr;
|
||||
std::visit(
|
||||
common::visitors{[&](const common::Indirection<parser::Variable> &v) {
|
||||
actualArgExpr = AnalyzeHelper(*this, v);
|
||||
},
|
||||
common::visitors{
|
||||
[&](const common::Indirection<parser::Variable> &v) {
|
||||
actualArgExpr = AnalyzeHelper(*this, v);
|
||||
},
|
||||
[&](const common::Indirection<parser::Expr> &x) {
|
||||
actualArgExpr = Analyze(*x);
|
||||
},
|
||||
|
@ -961,7 +969,8 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::FunctionReference &funcRef) {
|
|||
},
|
||||
[&](const parser::ActualArg::PercentVal &) {
|
||||
Say("TODO: %VAL() argument"_err_en_US);
|
||||
}},
|
||||
},
|
||||
},
|
||||
std::get<parser::ActualArg>(arg.t).u);
|
||||
if (actualArgExpr.has_value()) {
|
||||
arguments.emplace_back(std::make_optional(
|
||||
|
@ -1008,7 +1017,8 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::Expr::Parentheses &x) {
|
|||
return {AsGenericExpr(Parentheses<Ty>{std::move(expr)})};
|
||||
},
|
||||
std::move(catExpr.u));
|
||||
}},
|
||||
},
|
||||
},
|
||||
std::move(operand->u));
|
||||
}
|
||||
return std::nullopt;
|
||||
|
@ -1026,7 +1036,8 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::Expr::UnaryPlus &x) {
|
|||
cat != TypeCategory::Complex) {
|
||||
Say("operand of unary + must be of a numeric type"_err_en_US);
|
||||
}
|
||||
}},
|
||||
},
|
||||
},
|
||||
value->u);
|
||||
}
|
||||
return value;
|
||||
|
@ -1041,16 +1052,18 @@ MaybeExpr ExprAnalyzer::Analyze(const parser::Expr::Negate &x) {
|
|||
|
||||
MaybeExpr ExprAnalyzer::Analyze(const parser::Expr::NOT &x) {
|
||||
if (MaybeExpr operand{AnalyzeHelper(*this, *x.v)}) {
|
||||
return std::visit(common::visitors{[](Expr<SomeLogical> &&lx) -> MaybeExpr {
|
||||
return {AsGenericExpr(
|
||||
LogicalNegation(std::move(lx)))};
|
||||
},
|
||||
[=](auto &&) -> MaybeExpr {
|
||||
// TODO: accept INTEGER operand and maybe typeless
|
||||
// if not overridden
|
||||
Say("Operand of .NOT. must be LOGICAL"_err_en_US);
|
||||
return std::nullopt;
|
||||
}},
|
||||
return std::visit(
|
||||
common::visitors{
|
||||
[](Expr<SomeLogical> &&lx) -> MaybeExpr {
|
||||
return {AsGenericExpr(LogicalNegation(std::move(lx)))};
|
||||
},
|
||||
[=](auto &&) -> MaybeExpr {
|
||||
// TODO: accept INTEGER operand and maybe typeless
|
||||
// if not overridden
|
||||
Say("Operand of .NOT. must be LOGICAL"_err_en_US);
|
||||
return std::nullopt;
|
||||
},
|
||||
},
|
||||
std::move(operand->u));
|
||||
}
|
||||
return std::nullopt;
|
||||
|
@ -1195,7 +1208,8 @@ MaybeExpr LogicalHelper(
|
|||
// need to define IAND, IOR, IEOR intrinsic representation
|
||||
ea.Say("operands to LOGICAL operation must be LOGICAL"_err_en_US);
|
||||
return {};
|
||||
}},
|
||||
},
|
||||
},
|
||||
std::move(std::get<0>(*both).u), std::move(std::get<1>(*both).u));
|
||||
}
|
||||
return std::nullopt;
|
||||
|
|
|
@ -162,7 +162,8 @@ void ModFileWriter::PutSymbol(const Symbol &symbol, bool &didContains) {
|
|||
PutLower(decls_ << "final::", symbol) << '\n';
|
||||
},
|
||||
[](const HostAssocDetails &) {},
|
||||
[&](const auto &) { PutEntity(decls_, symbol); }},
|
||||
[&](const auto &) { PutEntity(decls_, symbol); },
|
||||
},
|
||||
symbol.details());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue