From 615ba7754bdb673ca08728212dc00bcb521e299b Mon Sep 17 00:00:00 2001 From: peter klausler Date: Thu, 14 Mar 2019 16:28:06 -0700 Subject: [PATCH] [flang] Move dump-parse-tree.h from semantics into parser. Original-commit: flang-compiler/f18@9075adfcdf5a300471c9bd5512674ec33a9ad90d Reviewed-on: https://github.com/flang-compiler/f18/pull/330 Tree-same-pre-rewrite: false --- flang/lib/{semantics => parser}/dump-parse-tree.h | 27 +++++++++-------------- flang/lib/semantics/expression.cc | 6 ++--- flang/tools/f18/CMakeLists.txt | 1 - flang/tools/f18/f18-parse-demo.cc | 4 ++-- flang/tools/f18/f18.cc | 4 ++-- 5 files changed, 18 insertions(+), 24 deletions(-) rename flang/lib/{semantics => parser}/dump-parse-tree.h (97%) diff --git a/flang/lib/semantics/dump-parse-tree.h b/flang/lib/parser/dump-parse-tree.h similarity index 97% rename from flang/lib/semantics/dump-parse-tree.h rename to flang/lib/parser/dump-parse-tree.h index 51b73d4..76973e5 100644 --- a/flang/lib/semantics/dump-parse-tree.h +++ b/flang/lib/parser/dump-parse-tree.h @@ -11,19 +11,18 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#ifndef FORTRAN_SEMANTICS_DUMP_PARSE_TREE_H_ -#define FORTRAN_SEMANTICS_DUMP_PARSE_TREE_H_ +#ifndef FORTRAN_PARSER_DUMP_PARSE_TREE_H_ +#define FORTRAN_PARSER_DUMP_PARSE_TREE_H_ -#include "symbol.h" +#include "format-specification.h" +#include "parse-tree-visitor.h" +#include "parse-tree.h" #include "../common/idioms.h" #include "../common/indirection.h" -#include "../parser/format-specification.h" -#include "../parser/parse-tree-visitor.h" -#include "../parser/parse-tree.h" #include #include -namespace Fortran::semantics { +namespace Fortran::parser { using namespace std::string_literals; @@ -733,23 +732,19 @@ public: } } - bool PutName(const std::string &name, const semantics::Symbol *symbol) { + bool PutName(const std::string &name) { IndentEmptyLine(); - if (symbol != nullptr) { - out_ << "symbol = " << *symbol; - } else { - out_ << "Name = '" << name << '\''; - } + out_ << "Name = '" << name << '\''; ++indent_; EndLine(); return true; } - bool Pre(const parser::Name &x) { return PutName(x.ToString(), x.symbol); } + bool Pre(const parser::Name &x) { return PutName(x.ToString()); } void Post(const parser::Name &) { --indent_; } - bool Pre(const std::string &x) { return PutName(x, nullptr); } + bool Pre(const std::string &x) { return PutName(x); } void Post(const std::string &x) { --indent_; } @@ -874,4 +869,4 @@ template void DumpTree(std::ostream &out, const T &x) { parser::Walk(x, dumper); } } -#endif // FORTRAN_SEMANTICS_DUMP_PARSE_TREE_H_ +#endif // FORTRAN_PARSER_DUMP_PARSE_TREE_H_ diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index ac84ce0..83c2161 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -31,7 +31,7 @@ // TODO pmk remove when scaffolding is obsolete #undef PMKDEBUG // #define PMKDEBUG 1 #if PMKDEBUG -#include "dump-parse-tree.h" +#include "../parser/dump-parse-tree.h" #include #endif @@ -322,7 +322,7 @@ static void FixMisparsedSubstring(const parser::Designator &d) { }, arrElement.base.u)}) { const Symbol &ultimate{symbol->GetUltimate()}; - if (const semantics::DeclTypeSpec *type{ultimate.GetType()}) { + if (const semantics::DeclTypeSpec * type{ultimate.GetType()}) { if (!ultimate.IsObjectArray() && type->category() == semantics::DeclTypeSpec::Character) { // The ambiguous S(j:k) was parsed as an array section @@ -1935,7 +1935,7 @@ void ExprChecker::Enter(const parser::Expr &expr) { } else { #if PMKDEBUG std::cout << "TODO: expression analysis failed for this expression: "; - DumpTree(std::cout, expr); + parser::DumpTree(std::cout, expr); #endif } } diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index c04cb47..c962f70 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -36,5 +36,4 @@ add_executable(f18-parse-demo target_link_libraries(f18-parse-demo FortranParser - FortranSemantics ) diff --git a/flang/tools/f18/f18-parse-demo.cc b/flang/tools/f18/f18-parse-demo.cc index 1ac7e83..9379c54 100644 --- a/flang/tools/f18/f18-parse-demo.cc +++ b/flang/tools/f18/f18-parse-demo.cc @@ -29,6 +29,7 @@ #include "../../lib/common/default-kinds.h" #include "../../lib/parser/characters.h" +#include "../../lib/parser/dump-parse-tree.h" #include "../../lib/parser/features.h" #include "../../lib/parser/message.h" #include "../../lib/parser/parse-tree-visitor.h" @@ -36,7 +37,6 @@ #include "../../lib/parser/parsing.h" #include "../../lib/parser/provenance.h" #include "../../lib/parser/unparse.h" -#include "../../lib/semantics/dump-parse-tree.h" #include #include #include @@ -208,7 +208,7 @@ std::string CompileFortran( } auto &parseTree{*parsing.parseTree()}; if (driver.dumpParseTree) { - Fortran::semantics::DumpTree(std::cout, parseTree); + Fortran::parser::DumpTree(std::cout, parseTree); return {}; } if (driver.dumpUnparse) { diff --git a/flang/tools/f18/f18.cc b/flang/tools/f18/f18.cc index acc423f..5665a71 100644 --- a/flang/tools/f18/f18.cc +++ b/flang/tools/f18/f18.cc @@ -20,6 +20,7 @@ #endif #include "../../lib/common/default-kinds.h" #include "../../lib/parser/characters.h" +#include "../../lib/parser/dump-parse-tree.h" #include "../../lib/parser/features.h" #include "../../lib/parser/message.h" #include "../../lib/parser/parse-tree-visitor.h" @@ -27,7 +28,6 @@ #include "../../lib/parser/parsing.h" #include "../../lib/parser/provenance.h" #include "../../lib/parser/unparse.h" -#include "../../lib/semantics/dump-parse-tree.h" #include "../../lib/semantics/expression.h" #include "../../lib/semantics/semantics.h" #include "../../lib/semantics/unparse-with-symbols.h" @@ -249,7 +249,7 @@ std::string CompileFortran(std::string path, Fortran::parser::Options options, return {}; } if (driver.dumpParseTree) { - Fortran::semantics::DumpTree(std::cout, parseTree); + Fortran::parser::DumpTree(std::cout, parseTree); } if (driver.dumpUnparse) { Unparse(std::cout, parseTree, driver.encoding, true /*capitalize*/, -- 2.7.4