[flang] Clean up and prep for review
authorpeter klausler <pklausler@nvidia.com>
Tue, 2 Apr 2019 17:58:26 +0000 (10:58 -0700)
committerpeter klausler <pklausler@nvidia.com>
Tue, 2 Apr 2019 17:59:11 +0000 (10:59 -0700)
Original-commit: flang-compiler/f18@3f96c673e06b630050f8082d9ba019a0ba4ed21b
Reviewed-on: https://github.com/flang-compiler/f18/pull/378
Tree-same-pre-rewrite: false

flang/lib/semantics/scope.cc
flang/lib/semantics/scope.h
flang/lib/semantics/semantics.cc
flang/lib/semantics/semantics.h

index 4580d01..2186dda 100644 (file)
@@ -185,12 +185,17 @@ bool Scope::CanImport(const SourceName &name) const {
   }
 }
 
-const Scope *Scope::FindScope(const parser::CharBlock &source) const {
+const Scope *Scope::FindScope(parser::CharBlock source) const {
+  return const_cast<const Scope *>(
+      const_cast<Scope *>(this)->FindScope(source));
+}
+
+Scope *Scope::FindScope(parser::CharBlock source) {
   if (!sourceRange_.Contains(source)) {
     return nullptr;
   }
-  for (const auto &child : children_) {
-    if (const auto *scope{child.FindScope(source)}) {
+  for (auto &child : children_) {
+    if (auto *scope{child.FindScope(source)}) {
       return scope;
     }
   }
index a7349c7..29f37d1 100644 (file)
@@ -172,7 +172,8 @@ public:
   const parser::CharBlock &sourceRange() const { return sourceRange_; }
   void AddSourceRange(const parser::CharBlock &);
   // Find the smallest scope under this one that contains source
-  const Scope *FindScope(const parser::CharBlock &) const;
+  const Scope *FindScope(parser::CharBlock) const;
+  Scope *FindScope(parser::CharBlock);
 
   // Attempts to find a match for a derived type instance
   const DeclTypeSpec *FindInstantiatedDerivedType(const DerivedTypeSpec &,
index d778c96..6efff1b 100644 (file)
@@ -115,9 +115,13 @@ bool SemanticsContext::AnyFatalError() const {
       (warningsAreErrors_ || messages_.AnyFatalError());
 }
 
-const Scope &SemanticsContext::FindScope(
-    const parser::CharBlock &source) const {
-  if (const auto *scope{globalScope_.FindScope(source)}) {
+const Scope &SemanticsContext::FindScope(parser::CharBlock source) const {
+  return const_cast<const Scope &>(
+      const_cast<SemanticsContext *>(this)->FindScope(source));
+}
+
+Scope &SemanticsContext::FindScope(parser::CharBlock source) {
+  if (auto *scope{globalScope_.FindScope(source)}) {
     return *scope;
   } else {
     common::die("invalid source location");
index 0b47225..6fa3817 100644 (file)
@@ -95,7 +95,8 @@ public:
     return messages_.Say(std::move(msg));
   }
 
-  const Scope &FindScope(const parser::CharBlock &) const;
+  const Scope &FindScope(parser::CharBlock) const;
+  Scope &FindScope(parser::CharBlock);
 
 private:
   const common::IntrinsicTypeDefaultKinds &defaultKinds_;