/** * Copyright (c) 2021 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 "classDeclaration.h" #include #include #include #include #include #include #include #include #include #include namespace panda::es2panda::ir { void ClassDeclaration::Iterate(const NodeTraverser &cb) const { cb(def_); for (auto *it : decorators_) { cb(it); } } void ClassDeclaration::Dump(ir::AstDumper *dumper) const { dumper->Add({{"type", "ClassDeclaration"}, {"definition", def_}, {"decorators", decorators_}, {"isAnnotationDeclaration", isAnnotationDecl_}}); } void ClassDeclaration::Compile(compiler::PandaGen *pg) const { // [ClassDeclaration] without [Identifier] must have parent node // of [ExportDefaultDeclaration] during compiling phase. So we use // the parent node to create a lreference with boundName of [*default*]. if (def_->Declare()) { return; } if (isAnnotationDecl_) { std::string annoName = std::string(def_->GetName()); if (pg->Context()->IsMergeAbc()) { std::string prefix = std::string(pg->Context()->RecordName()) + "."; annoName.insert(0, prefix); } pg->Context()->GetEmitter()->AddAnnotationRecord(annoName, this); return; } const auto *node = def_->Ident() ? def_->Ident() : this->Parent(); auto lref = compiler::LReference::CreateLRef(pg, node, true); def_->Compile(pg); lref.SetValue(); } checker::Type *ClassDeclaration::Check([[maybe_unused]] checker::Checker *checker) const { return nullptr; } void ClassDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) { def_ = std::get(cb(def_))->AsClassDefinition(); for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { *iter = std::get(cb(*iter))->AsDecorator(); } } } // namespace panda::es2panda::ir