llvm/flang/lib/semantics/scope.cc
Tim Keith 75e4108d55 [flang] Change API of Scope to match std::map
The Scope can be thought of as (among other things) a mapping of Name to
Symbol. This change reflects that by changing the API to match std::map.

Original-commit: flang-compiler/f18@37f6ad73cc
Reviewed-on: https://github.com/flang-compiler/f18/pull/46
Tree-same-pre-rewrite: false
2018-04-09 10:07:36 -07:00

35 lines
974 B
C++

#include "scope.h"
#include "symbol.h"
#include <memory>
namespace Fortran::semantics {
const Scope Scope::systemScope{Scope::systemScope, Scope::Kind::System};
Scope Scope::globalScope{Scope::systemScope, Scope::Kind::Global};
Scope &Scope::MakeScope(Kind kind) {
children_.emplace_back(*this, kind);
return children_.back();
}
static const char *ToString(Scope::Kind kind) {
switch (kind) {
case Scope::Kind::System: return "System";
case Scope::Kind::Global: return "Global";
case Scope::Kind::Module: return "Module";
case Scope::Kind::MainProgram: return "MainProgram";
case Scope::Kind::Subprogram: return "Subprogram";
default: CRASH_NO_CASE;
}
}
std::ostream &operator<<(std::ostream &os, const Scope &scope) {
os << ToString(scope.kind()) << " scope: " << scope.children_.size()
<< " children\n";
for (const auto &sym : scope.symbols_) {
os << " " << sym.second << "\n";
}
return os;
}
} // namespace Fortran::semantics