[flang] Rename DoChecker to DoForallChecker
authorTim Keith <tkeith@nvidia.com>
Wed, 19 Feb 2020 21:28:19 +0000 (13:28 -0800)
committerTim Keith <tkeith@nvidia.com>
Wed, 19 Feb 2020 21:28:19 +0000 (13:28 -0800)
This reflects the fact that it now performs checks on both DO
and FORALL constructs. Rename the source files as well.

Original-commit: flang-compiler/f18@8ecb6a279f53ff4cc9493506370664fb1923470a
Reviewed-on: https://github.com/flang-compiler/f18/pull/989

flang/lib/semantics/CMakeLists.txt
flang/lib/semantics/check-do-forall.cpp [moved from flang/lib/semantics/check-do.cpp with 96% similarity]
flang/lib/semantics/check-do-forall.h [moved from flang/lib/semantics/check-do.h with 84% similarity]
flang/lib/semantics/semantics.cpp

index 14e636e..d06c8a2 100644 (file)
@@ -17,7 +17,7 @@ add_library(FortranSemantics
   check-coarray.cpp
   check-deallocate.cpp
   check-declarations.cpp
-  check-do.cpp
+  check-do-forall.cpp
   check-if-stmt.cpp
   check-io.cpp
   check-nullify.cpp
similarity index 96%
rename from flang/lib/semantics/check-do.cpp
rename to flang/lib/semantics/check-do-forall.cpp
index 10596c3..1b1abfd 100644 (file)
@@ -1,4 +1,4 @@
-//===-- lib/semantics/check-do.cpp ----------------------------------------===//
+//===-- lib/semantics/check-do-forall.cpp ---------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "check-do.h"
+#include "check-do-forall.h"
 #include "flang/common/template.h"
 #include "flang/evaluate/call.h"
 #include "flang/evaluate/expression.h"
@@ -763,37 +763,37 @@ private:
   parser::CharBlock currentStatementSourcePosition_;
 };  // class DoContext
 
-void DoChecker::Enter(const parser::DoConstruct &doConstruct) {
+void DoForallChecker::Enter(const parser::DoConstruct &doConstruct) {
   DoContext doContext{context_, IndexVarKind::DO};
   doContext.DefineDoVariables(doConstruct);
 }
 
-void DoChecker::Leave(const parser::DoConstruct &doConstruct) {
+void DoForallChecker::Leave(const parser::DoConstruct &doConstruct) {
   DoContext doContext{context_, IndexVarKind::DO};
   doContext.Check(doConstruct);
   doContext.ResetDoVariables(doConstruct);
 }
 
-void DoChecker::Enter(const parser::ForallConstruct &construct) {
+void DoForallChecker::Enter(const parser::ForallConstruct &construct) {
   DoContext doContext{context_, IndexVarKind::FORALL};
   doContext.ActivateIndexVars(GetControls(construct));
 }
-void DoChecker::Leave(const parser::ForallConstruct &construct) {
+void DoForallChecker::Leave(const parser::ForallConstruct &construct) {
   DoContext doContext{context_, IndexVarKind::FORALL};
   doContext.Check(construct);
   doContext.DeactivateIndexVars(GetControls(construct));
 }
 
-void DoChecker::Enter(const parser::ForallStmt &stmt) {
+void DoForallChecker::Enter(const parser::ForallStmt &stmt) {
   DoContext doContext{context_, IndexVarKind::FORALL};
   doContext.ActivateIndexVars(GetControls(stmt));
 }
-void DoChecker::Leave(const parser::ForallStmt &stmt) {
+void DoForallChecker::Leave(const parser::ForallStmt &stmt) {
   DoContext doContext{context_, IndexVarKind::FORALL};
   doContext.Check(stmt);
   doContext.DeactivateIndexVars(GetControls(stmt));
 }
-void DoChecker::Leave(const parser::ForallAssignmentStmt &stmt) {
+void DoForallChecker::Leave(const parser::ForallAssignmentStmt &stmt) {
   DoContext doContext{context_, IndexVarKind::FORALL};
   doContext.Check(stmt);
 }
@@ -813,8 +813,8 @@ static parser::CharBlock GetNodePosition(const ConstructNode &construct) {
       [&](const auto &x) { return GetConstructPosition(*x); }, construct);
 }
 
-void DoChecker::SayBadLeave(StmtType stmtType, const char *enclosingStmtName,
-    const ConstructNode &construct) const {
+void DoForallChecker::SayBadLeave(StmtType stmtType,
+    const char *enclosingStmtName, const ConstructNode &construct) const {
   context_
       .Say("%s must not leave a %s statement"_err_en_US, EnumToString(stmtType),
           enclosingStmtName)
@@ -838,7 +838,7 @@ static bool ConstructIsDoConcurrent(const ConstructNode &construct) {
 
 // Check that CYCLE and EXIT statements do not cause flow of control to
 // leave DO CONCURRENT, CRITICAL, or CHANGE TEAM constructs.
-void DoChecker::CheckForBadLeave(
+void DoForallChecker::CheckForBadLeave(
     StmtType stmtType, const ConstructNode &construct) const {
   std::visit(
       common::visitors{
@@ -876,7 +876,7 @@ static bool StmtMatchesConstruct(const parser::Name *stmtName,
 }
 
 // C1167 Can't EXIT from a DO CONCURRENT
-void DoChecker::CheckDoConcurrentExit(
+void DoForallChecker::CheckDoConcurrentExit(
     StmtType stmtType, const ConstructNode &construct) const {
   if (stmtType == StmtType::EXIT && ConstructIsDoConcurrent(construct)) {
     SayBadLeave(StmtType::EXIT, "DO CONCURRENT", construct);
@@ -887,7 +887,7 @@ void DoChecker::CheckDoConcurrentExit(
 // nesting levels looking for a construct that matches the CYCLE or EXIT
 // statment.  At every construct, check for a violation.  If we find a match
 // without finding a violation, the check is complete.
-void DoChecker::CheckNesting(
+void DoForallChecker::CheckNesting(
     StmtType stmtType, const parser::Name *stmtName) const {
   const ConstructStack &stack{context_.constructStack()};
   for (auto iter{stack.cend()}; iter-- != stack.cbegin();) {
@@ -909,16 +909,16 @@ void DoChecker::CheckNesting(
 }
 
 // C1135 -- Nesting for CYCLE statements
-void DoChecker::Enter(const parser::CycleStmt &cycleStmt) {
+void DoForallChecker::Enter(const parser::CycleStmt &cycleStmt) {
   CheckNesting(StmtType::CYCLE, common::GetPtrFromOptional(cycleStmt.v));
 }
 
 // C1167 and C1168 -- Nesting for EXIT statements
-void DoChecker::Enter(const parser::ExitStmt &exitStmt) {
+void DoForallChecker::Enter(const parser::ExitStmt &exitStmt) {
   CheckNesting(StmtType::EXIT, common::GetPtrFromOptional(exitStmt.v));
 }
 
-void DoChecker::Leave(const parser::AssignmentStmt &stmt) {
+void DoForallChecker::Leave(const parser::AssignmentStmt &stmt) {
   const auto &variable{std::get<parser::Variable>(stmt.t)};
   context_.CheckIndexVarRedefine(variable);
 }
@@ -947,7 +947,7 @@ static void CheckIfArgIsDoVar(const evaluate::ActualArgument &arg,
 // the same time, we need to iterate over the parser::Expr versions of the
 // actual arguments to get their source locations of the arguments for the
 // messages.
-void DoChecker::Leave(const parser::CallStmt &callStmt) {
+void DoForallChecker::Leave(const parser::CallStmt &callStmt) {
   if (const auto &typedCall{callStmt.typedCall}) {
     const auto &parsedArgs{
         std::get<std::list<parser::ActualArgSpec>>(callStmt.v.t)};
@@ -970,7 +970,7 @@ void DoChecker::Leave(const parser::CallStmt &callStmt) {
   }
 }
 
-void DoChecker::Leave(const parser::ConnectSpec &connectSpec) {
+void DoForallChecker::Leave(const parser::ConnectSpec &connectSpec) {
   const auto *newunit{
       std::get_if<parser::ConnectSpec::Newunit>(&connectSpec.u)};
   if (newunit) {
@@ -997,7 +997,7 @@ template<typename A> ActualArgumentSet CollectActualArguments(const A &x) {
 
 template ActualArgumentSet CollectActualArguments(const SomeExpr &);
 
-void DoChecker::Leave(const parser::Expr &parsedExpr) {
+void DoForallChecker::Leave(const parser::Expr &parsedExpr) {
   if (const SomeExpr * expr{GetExpr(parsedExpr)}) {
     ActualArgumentSet argSet{CollectActualArguments(*expr)};
     for (const evaluate::ActualArgumentRef &argRef : argSet) {
@@ -1006,7 +1006,7 @@ void DoChecker::Leave(const parser::Expr &parsedExpr) {
   }
 }
 
-void DoChecker::Leave(const parser::InquireSpec &inquireSpec) {
+void DoForallChecker::Leave(const parser::InquireSpec &inquireSpec) {
   const auto *intVar{std::get_if<parser::InquireSpec::IntVar>(&inquireSpec.u)};
   if (intVar) {
     const auto &scalar{std::get<parser::ScalarIntVariable>(intVar->t)};
@@ -1014,20 +1014,20 @@ void DoChecker::Leave(const parser::InquireSpec &inquireSpec) {
   }
 }
 
-void DoChecker::Leave(const parser::IoControlSpec &ioControlSpec) {
+void DoForallChecker::Leave(const parser::IoControlSpec &ioControlSpec) {
   const auto *size{std::get_if<parser::IoControlSpec::Size>(&ioControlSpec.u)};
   if (size) {
     context_.CheckIndexVarRedefine(size->v.thing.thing);
   }
 }
 
-void DoChecker::Leave(const parser::OutputImpliedDo &outputImpliedDo) {
+void DoForallChecker::Leave(const parser::OutputImpliedDo &outputImpliedDo) {
   const auto &control{std::get<parser::IoImpliedDoControl>(outputImpliedDo.t)};
   const parser::Name &name{control.name.thing.thing};
   context_.CheckIndexVarRedefine(name.source, *name.symbol);
 }
 
-void DoChecker::Leave(const parser::StatVariable &statVariable) {
+void DoForallChecker::Leave(const parser::StatVariable &statVariable) {
   context_.CheckIndexVarRedefine(statVariable.v.thing.thing);
 }
 
similarity index 84%
rename from flang/lib/semantics/check-do.h
rename to flang/lib/semantics/check-do-forall.h
index fb3a4be..1ba9b6b 100644 (file)
@@ -1,4 +1,4 @@
-//===-- lib/semantics/check-do.h --------------------------------*- C++ -*-===//
+//===-- lib/semantics/check-do-forall.h -------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef FORTRAN_SEMANTICS_CHECK_DO_H_
-#define FORTRAN_SEMANTICS_CHECK_DO_H_
+#ifndef FORTRAN_SEMANTICS_CHECK_DO_FORALL_H_
+#define FORTRAN_SEMANTICS_CHECK_DO_FORALL_H_
 
 #include "flang/common/idioms.h"
 #include "flang/semantics/semantics.h"
@@ -34,9 +34,10 @@ namespace Fortran::semantics {
 // To specify different statement types used in semantic checking.
 ENUM_CLASS(StmtType, CYCLE, EXIT)
 
-class DoChecker : public virtual BaseChecker {
+// Perform semantic checks on DO and FORALL constructs and statements.
+class DoForallChecker : public virtual BaseChecker {
 public:
-  explicit DoChecker(SemanticsContext &context) : context_{context} {}
+  explicit DoForallChecker(SemanticsContext &context) : context_{context} {}
   void Leave(const parser::AssignmentStmt &);
   void Leave(const parser::CallStmt &);
   void Leave(const parser::ConnectSpec &);
@@ -65,4 +66,4 @@ private:
   void CheckNesting(StmtType, const parser::Name *) const;
 };
 }
-#endif  // FORTRAN_SEMANTICS_CHECK_DO_H_
+#endif
index c6353a7..dcb1198 100644 (file)
@@ -15,7 +15,7 @@
 #include "check-coarray.h"
 #include "check-deallocate.h"
 #include "check-declarations.h"
-#include "check-do.h"
+#include "check-do-forall.h"
 #include "check-if-stmt.h"
 #include "check-io.h"
 #include "check-nullify.h"
@@ -110,10 +110,11 @@ private:
 };
 
 using StatementSemanticsPass1 = ExprChecker;
-using StatementSemanticsPass2 = SemanticsVisitor<AllocateChecker,
-    ArithmeticIfStmtChecker, AssignmentChecker, CoarrayChecker,
-    DeallocateChecker, DoChecker, IfStmtChecker, IoChecker, NullifyChecker,
-    OmpStructureChecker, PurityChecker, ReturnStmtChecker, StopChecker>;
+using StatementSemanticsPass2 = SemanticsVisitor<  //
+    AllocateChecker, ArithmeticIfStmtChecker, AssignmentChecker, CoarrayChecker,
+    DeallocateChecker, DoForallChecker, IfStmtChecker, IoChecker,
+    NullifyChecker, OmpStructureChecker, PurityChecker, ReturnStmtChecker,
+    StopChecker>;
 
 static bool PerformStatementSemantics(
     SemanticsContext &context, parser::Program &program) {