1/** 2 * Copyright (c) 2021-2024 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 "tsEnumMember.h" 17 18#include "checker/TSchecker.h" 19#include "compiler/core/ETSGen.h" 20#include "compiler/core/pandagen.h" 21#include "ir/astDump.h" 22#include "ir/srcDump.h" 23 24namespace ark::es2panda::ir { 25void TSEnumMember::TransformChildren(const NodeTransformer &cb, std::string_view transformationName) 26{ 27 if (auto *transformedNode = cb(key_); key_ != transformedNode) { 28 key_->SetTransformedNode(transformationName, transformedNode); 29 key_ = transformedNode->AsExpression(); 30 } 31 32 if (init_ != nullptr) { 33 if (auto *transformedNode = cb(init_); init_ != transformedNode) { 34 init_->SetTransformedNode(transformationName, transformedNode); 35 init_ = transformedNode->AsExpression(); 36 } 37 } 38} 39 40void TSEnumMember::Iterate(const NodeTraverser &cb) const 41{ 42 cb(key_); 43 44 if (init_ != nullptr) { 45 cb(init_); 46 } 47} 48 49void TSEnumMember::Dump(ir::AstDumper *dumper) const 50{ 51 dumper->Add({{"type", "TSEnumMember"}, {"id", key_}, {"initializer", AstDumper::Optional(init_)}}); 52} 53 54void TSEnumMember::Dump(ir::SrcDumper *dumper) const 55{ 56 ASSERT(key_ != nullptr); 57 key_->Dump(dumper); 58 if (init_ != nullptr) { 59 dumper->Add(" = "); 60 init_->Dump(dumper); 61 } 62} 63 64util::StringView TSEnumMember::Name() const 65{ 66 ASSERT(key_->IsIdentifier()); 67 return key_->AsIdentifier()->Name(); 68} 69 70void TSEnumMember::Compile(compiler::PandaGen *pg) const 71{ 72 pg->GetAstCompiler()->Compile(this); 73} 74 75void TSEnumMember::Compile(compiler::ETSGen *etsg) const 76{ 77 etsg->GetAstCompiler()->Compile(this); 78} 79 80checker::Type *TSEnumMember::Check(checker::TSChecker *checker) 81{ 82 return checker->GetAnalyzer()->Check(this); 83} 84 85checker::Type *TSEnumMember::Check(checker::ETSChecker *checker) 86{ 87 return checker->GetAnalyzer()->Check(this); 88} 89} // namespace ark::es2panda::ir 90