75e4108d55
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
35 lines
974 B
C++
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
|