Skip to content

Commit 2f22656

Browse files
authored
[flang] Minor cleanup (move function into /tools.cpp) (#111587)
The semantics utility GetAllNames has declarations in two header files and a definition that really should be in the common utilities source file. Remove the redudant declaration from resolve-names-utils.h and move code from resolve-names-utils.cpp into Semantics/tools.cpp.
1 parent 4f2b65f commit 2f22656

File tree

3 files changed

+31
-38
lines changed

3 files changed

+31
-38
lines changed

flang/lib/Semantics/resolve-names-utils.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ using common::NumericOperator;
3131
using common::RelationalOperator;
3232
using IntrinsicOperator = parser::DefinedOperator::IntrinsicOperator;
3333

34-
static constexpr const char *operatorPrefix{"operator("};
35-
3634
static GenericKind MapIntrinsicOperator(IntrinsicOperator);
3735

3836
Symbol *Resolve(const parser::Name &name, Symbol *symbol) {
@@ -69,37 +67,6 @@ bool IsIntrinsicOperator(
6967
return false;
7068
}
7169

72-
template <typename E>
73-
std::forward_list<std::string> GetOperatorNames(
74-
const SemanticsContext &context, E opr) {
75-
std::forward_list<std::string> result;
76-
for (const char *name : context.languageFeatures().GetNames(opr)) {
77-
result.emplace_front(std::string{operatorPrefix} + name + ')');
78-
}
79-
return result;
80-
}
81-
82-
std::forward_list<std::string> GetAllNames(
83-
const SemanticsContext &context, const SourceName &name) {
84-
std::string str{name.ToString()};
85-
if (!name.empty() && name.end()[-1] == ')' &&
86-
name.ToString().rfind(std::string{operatorPrefix}, 0) == 0) {
87-
for (int i{0}; i != common::LogicalOperator_enumSize; ++i) {
88-
auto names{GetOperatorNames(context, LogicalOperator{i})};
89-
if (llvm::is_contained(names, str)) {
90-
return names;
91-
}
92-
}
93-
for (int i{0}; i != common::RelationalOperator_enumSize; ++i) {
94-
auto names{GetOperatorNames(context, RelationalOperator{i})};
95-
if (llvm::is_contained(names, str)) {
96-
return names;
97-
}
98-
}
99-
}
100-
return {str};
101-
}
102-
10370
bool IsLogicalConstant(
10471
const SemanticsContext &context, const SourceName &name) {
10572
std::string str{name.ToString()};

flang/lib/Semantics/resolve-names-utils.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ parser::MessageFixedText WithSeverity(
5151
bool IsIntrinsicOperator(const SemanticsContext &, const SourceName &);
5252
bool IsLogicalConstant(const SemanticsContext &, const SourceName &);
5353

54-
// Some intrinsic operators have more than one name (e.g. `operator(.eq.)` and
55-
// `operator(==)`). GetAllNames() returns them all, including symbolName.
56-
std::forward_list<std::string> GetAllNames(
57-
const SemanticsContext &, const SourceName &);
58-
5954
template <typename T>
6055
MaybeIntExpr EvaluateIntExpr(SemanticsContext &context, const T &expr) {
6156
if (MaybeExpr maybeExpr{

flang/lib/Semantics/tools.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,37 @@ bool HasDefinedIo(common::DefinedIo which, const DerivedTypeSpec &derived,
16541654
return parentType && HasDefinedIo(which, *parentType, scope);
16551655
}
16561656

1657+
template <typename E>
1658+
std::forward_list<std::string> GetOperatorNames(
1659+
const SemanticsContext &context, E opr) {
1660+
std::forward_list<std::string> result;
1661+
for (const char *name : context.languageFeatures().GetNames(opr)) {
1662+
result.emplace_front("operator("s + name + ')');
1663+
}
1664+
return result;
1665+
}
1666+
1667+
std::forward_list<std::string> GetAllNames(
1668+
const SemanticsContext &context, const SourceName &name) {
1669+
std::string str{name.ToString()};
1670+
if (!name.empty() && name.end()[-1] == ')' &&
1671+
name.ToString().rfind("operator(", 0) == 0) {
1672+
for (int i{0}; i != common::LogicalOperator_enumSize; ++i) {
1673+
auto names{GetOperatorNames(context, common::LogicalOperator{i})};
1674+
if (llvm::is_contained(names, str)) {
1675+
return names;
1676+
}
1677+
}
1678+
for (int i{0}; i != common::RelationalOperator_enumSize; ++i) {
1679+
auto names{GetOperatorNames(context, common::RelationalOperator{i})};
1680+
if (llvm::is_contained(names, str)) {
1681+
return names;
1682+
}
1683+
}
1684+
}
1685+
return {str};
1686+
}
1687+
16571688
void WarnOnDeferredLengthCharacterScalar(SemanticsContext &context,
16581689
const SomeExpr *expr, parser::CharBlock at, const char *what) {
16591690
if (context.languageFeatures().ShouldWarn(

0 commit comments

Comments
 (0)