/** * Copyright (c) 2021 - 2024 Huawei Device Co., Ltd. * 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. */ #include "program.h" #include "varbinder/varbinder.h" #include "varbinder/ETSBinder.h" #include "ir/astDump.h" #include "ir/base/classDefinition.h" #include "ir/statements/blockStatement.h" namespace ark::es2panda::parser { std::string Program::Dump() const { ir::AstDumper dumper {ast_, SourceCode()}; return dumper.Str(); } void Program::DumpSilent() const { [[maybe_unused]] ir::AstDumper dumper {ast_, SourceCode()}; ASSERT(!dumper.Str().empty()); } varbinder::ClassScope *Program::GlobalClassScope() { return globalClass_->Scope()->AsClassScope(); } const varbinder::ClassScope *Program::GlobalClassScope() const { return globalClass_->Scope()->AsClassScope(); } varbinder::GlobalScope *Program::GlobalScope() { ASSERT(ast_->Scope()->IsGlobalScope() || ast_->Scope()->IsModuleScope()); return static_cast(ast_->Scope()); } const varbinder::GlobalScope *Program::GlobalScope() const { ASSERT(ast_->Scope()->IsGlobalScope() || ast_->Scope()->IsModuleScope()); return static_cast(ast_->Scope()); } void Program::SetDeclarationModuleInfo() { bool onlyDeclarations = true; for (auto stmt : ast_->Statements()) { if (stmt->IsDeclare() || stmt->IsTSTypeAliasDeclaration()) { continue; } onlyDeclarations = false; break; } moduleInfo_.isDeclModule = onlyDeclarations; } void Program::AddNodeToETSNolintCollection(const ir::AstNode *node, const std::set &warningsCollection) { ArenaSet tmp(allocator_->Adapter()); tmp.insert(warningsCollection.begin(), warningsCollection.end()); etsnolintCollection_.insert({node, tmp}); } bool Program::NodeContainsETSNolint(const ir::AstNode *node, ETSWarnings warning) { auto nodeEtsnolints = etsnolintCollection_.find(node); if (nodeEtsnolints == etsnolintCollection_.end()) { return false; } return nodeEtsnolints->second.find(warning) != nodeEtsnolints->second.end(); } } // namespace ark::es2panda::parser