1 /** 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "program.h" 17 18 #include "varbinder/varbinder.h" 19 #include "varbinder/ETSBinder.h" 20 #include "ir/astDump.h" 21 #include "ir/base/classDefinition.h" 22 #include "ir/statements/blockStatement.h" 23 24 namespace panda::es2panda::parser { 25 Dump() const26std::string Program::Dump() const 27 { 28 ir::AstDumper dumper {ast_, SourceCode()}; 29 return dumper.Str(); 30 } 31 DumpSilent() const32void Program::DumpSilent() const 33 { 34 [[maybe_unused]] ir::AstDumper dumper {ast_, SourceCode()}; 35 ASSERT(!dumper.Str().empty()); 36 } 37 PackageClassName(util::StringView className)38util::StringView Program::PackageClassName(util::StringView className) 39 { 40 if (packageName_.Empty()) { 41 return className; 42 } 43 44 util::UString name(packageName_, allocator_); 45 name.Append('.'); 46 name.Append(className); 47 return name.View(); 48 } 49 GlobalClassScope()50varbinder::ClassScope *Program::GlobalClassScope() 51 { 52 return globalClass_->Scope()->AsClassScope(); 53 } 54 GlobalClassScope() const55const varbinder::ClassScope *Program::GlobalClassScope() const 56 { 57 return globalClass_->Scope()->AsClassScope(); 58 } 59 GlobalScope()60varbinder::GlobalScope *Program::GlobalScope() 61 { 62 ASSERT(ast_->Scope()->IsGlobalScope() || ast_->Scope()->IsModuleScope()); 63 return static_cast<varbinder::GlobalScope *>(ast_->Scope()); 64 } 65 GlobalScope() const66const varbinder::GlobalScope *Program::GlobalScope() const 67 { 68 ASSERT(ast_->Scope()->IsGlobalScope() || ast_->Scope()->IsModuleScope()); 69 return static_cast<const varbinder::GlobalScope *>(ast_->Scope()); 70 } 71 72 } // namespace panda::es2panda::parser 73