[flang-commits] [flang] 4f1ab33 - [flang] Visit "source" member in all AST nodes (#175211)
via flang-commits
flang-commits at lists.llvm.org
Fri Jan 9 12:09:05 PST 2026
Author: Krzysztof Parzyszek
Date: 2026-01-09T14:09:02-06:00
New Revision: 4f1ab334a4ba5e3c8ba96a0b8bba2c71c779cfca
URL: https://github.com/llvm/llvm-project/commit/4f1ab334a4ba5e3c8ba96a0b8bba2c71c779cfca
DIFF: https://github.com/llvm/llvm-project/commit/4f1ab334a4ba5e3c8ba96a0b8bba2c71c779cfca.diff
LOG: [flang] Visit "source" member in all AST nodes (#175211)
Some AST nodes had their "source" member visited by the parse tree
visitor, while others, in particular those that were handled by the
trait-based visitors, did not.
Make sure that we call the Walk function on the "source" member for all
classes that have it.
Added:
Modified:
flang/include/flang/Parser/parse-tree-visitor.h
Removed:
################################################################################
diff --git a/flang/include/flang/Parser/parse-tree-visitor.h b/flang/include/flang/Parser/parse-tree-visitor.h
index 67f5481144c52..b7d41254c75c4 100644
--- a/flang/include/flang/Parser/parse-tree-visitor.h
+++ b/flang/include/flang/Parser/parse-tree-visitor.h
@@ -10,6 +10,7 @@
#define FORTRAN_PARSER_PARSE_TREE_VISITOR_H_
#include "parse-tree.h"
+#include "tools.h"
#include "flang/Common/enum-set.h"
#include "flang/Common/visit.h"
#include <cstddef>
@@ -58,6 +59,13 @@ struct ParseTreeVisitorLookupScope {
}
}
+ template <typename A, typename VM>
+ static void WalkSource(A &x, VM &visitorOrMutator) {
+ if constexpr (HasSource<A>::value) {
+ Walk(x.source, visitorOrMutator);
+ }
+ }
+
// Traversal of needed STL template classes (optional, list, tuple, variant)
// For most lists, just traverse the elements; but when a list constitutes
// a Block (i.e., std::list<ExecutionPartConstruct>), also invoke the
@@ -168,12 +176,14 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename V>
static std::enable_if_t<EmptyTrait<A>> Walk(const A &x, V &visitor) {
if (visitor.Pre(x)) {
+ WalkSource(x, visitor);
visitor.Post(x);
}
}
template <typename A, typename M>
static std::enable_if_t<EmptyTrait<A>> Walk(A &x, M &mutator) {
if (mutator.Pre(x)) {
+ WalkSource(x, mutator);
mutator.Post(x);
}
}
@@ -181,6 +191,7 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename V>
static std::enable_if_t<TupleTrait<A>> Walk(const A &x, V &visitor) {
if (visitor.Pre(x)) {
+ WalkSource(x, visitor);
Walk(x.t, visitor);
visitor.Post(x);
}
@@ -188,6 +199,7 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename M>
static std::enable_if_t<TupleTrait<A>> Walk(A &x, M &mutator) {
if (mutator.Pre(x)) {
+ WalkSource(x, mutator);
Walk(x.t, mutator);
mutator.Post(x);
}
@@ -196,6 +208,7 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename V>
static std::enable_if_t<UnionTrait<A>> Walk(const A &x, V &visitor) {
if (visitor.Pre(x)) {
+ WalkSource(x, visitor);
Walk(x.u, visitor);
visitor.Post(x);
}
@@ -203,6 +216,7 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename M>
static std::enable_if_t<UnionTrait<A>> Walk(A &x, M &mutator) {
if (mutator.Pre(x)) {
+ WalkSource(x, mutator);
Walk(x.u, mutator);
mutator.Post(x);
}
@@ -211,6 +225,7 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename V>
static std::enable_if_t<WrapperTrait<A>> Walk(const A &x, V &visitor) {
if (visitor.Pre(x)) {
+ WalkSource(x, visitor);
Walk(x.v, visitor);
visitor.Post(x);
}
@@ -218,6 +233,7 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename M>
static std::enable_if_t<WrapperTrait<A>> Walk(A &x, M &mutator) {
if (mutator.Pre(x)) {
+ WalkSource(x, mutator);
Walk(x.v, mutator);
mutator.Post(x);
}
@@ -226,6 +242,7 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename V>
static std::enable_if_t<ConstraintTrait<A>> Walk(const A &x, V &visitor) {
if (visitor.Pre(x)) {
+ WalkSource(x, visitor);
Walk(x.thing, visitor);
visitor.Post(x);
}
@@ -233,6 +250,7 @@ struct ParseTreeVisitorLookupScope {
template <typename A, typename M>
static std::enable_if_t<ConstraintTrait<A>> Walk(A &x, M &mutator) {
if (mutator.Pre(x)) {
+ WalkSource(x, mutator);
Walk(x.thing, mutator);
mutator.Post(x);
}
More information about the flang-commits
mailing list