2018-05-01 12:50:34 -07:00
|
|
|
// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// 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.
|
|
|
|
|
2018-03-22 17:08:20 -07:00
|
|
|
#include "scope.h"
|
|
|
|
#include "symbol.h"
|
|
|
|
#include <memory>
|
|
|
|
|
2018-03-23 12:24:29 -07:00
|
|
|
namespace Fortran::semantics {
|
2018-03-22 17:08:20 -07:00
|
|
|
|
2018-05-02 14:06:02 -07:00
|
|
|
const Scope Scope::systemScope{
|
|
|
|
Scope::systemScope, Scope::Kind::System, nullptr};
|
2018-04-18 15:06:35 -07:00
|
|
|
Scope Scope::globalScope{Scope::systemScope, Scope::Kind::Global, nullptr};
|
2018-03-22 17:08:20 -07:00
|
|
|
|
2018-06-19 16:06:41 -07:00
|
|
|
Symbols<1024> Scope::allSymbols;
|
|
|
|
|
2018-05-14 13:51:13 -07:00
|
|
|
Scope &Scope::MakeScope(Kind kind, Symbol *symbol) {
|
2018-04-18 15:06:35 -07:00
|
|
|
children_.emplace_back(*this, kind, symbol);
|
2018-03-22 17:08:20 -07:00
|
|
|
return children_.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream &operator<<(std::ostream &os, const Scope &scope) {
|
2018-05-03 15:57:56 -07:00
|
|
|
os << Scope::EnumToString(scope.kind()) << " scope: ";
|
|
|
|
if (auto *symbol = scope.symbol()) {
|
|
|
|
os << *symbol << ' ';
|
|
|
|
}
|
|
|
|
os << scope.children_.size() << " children\n";
|
2018-03-22 17:08:20 -07:00
|
|
|
for (const auto &sym : scope.symbols_) {
|
2018-06-19 16:06:41 -07:00
|
|
|
os << " " << *sym.second << "\n";
|
2018-03-22 17:08:20 -07:00
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2018-03-23 12:24:29 -07:00
|
|
|
} // namespace Fortran::semantics
|