1 /**
2 * Copyright (c) 2021-2022 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
24 namespace panda::es2panda::ir {
TransformChildren(const NodeTransformer & cb)25 void TSEnumMember::TransformChildren(const NodeTransformer &cb)
26 {
27 key_ = cb(key_)->AsExpression();
28
29 if (init_ != nullptr) {
30 init_ = cb(init_)->AsExpression();
31 }
32 }
33
Iterate(const NodeTraverser & cb) const34 void TSEnumMember::Iterate(const NodeTraverser &cb) const
35 {
36 cb(key_);
37
38 if (init_ != nullptr) {
39 cb(init_);
40 }
41 }
42
Dump(ir::AstDumper * dumper) const43 void TSEnumMember::Dump(ir::AstDumper *dumper) const
44 {
45 dumper->Add({{"type", "TSEnumMember"}, {"id", key_}, {"initializer", AstDumper::Optional(init_)}});
46 }
47
Dump(ir::SrcDumper * dumper) const48 void TSEnumMember::Dump(ir::SrcDumper *dumper) const
49 {
50 ASSERT(key_ != nullptr);
51 key_->Dump(dumper);
52 if (init_ != nullptr) {
53 dumper->Add(" = ");
54 init_->Dump(dumper);
55 }
56 }
57
Name() const58 util::StringView TSEnumMember::Name() const
59 {
60 ASSERT(key_->IsIdentifier());
61 return key_->AsIdentifier()->Name();
62 }
63
Compile(compiler::PandaGen * pg) const64 void TSEnumMember::Compile(compiler::PandaGen *pg) const
65 {
66 pg->GetAstCompiler()->Compile(this);
67 }
68
Compile(compiler::ETSGen * etsg) const69 void TSEnumMember::Compile(compiler::ETSGen *etsg) const
70 {
71 etsg->GetAstCompiler()->Compile(this);
72 }
73
Check(checker::TSChecker * checker)74 checker::Type *TSEnumMember::Check(checker::TSChecker *checker)
75 {
76 return checker->GetAnalyzer()->Check(this);
77 }
78
Check(checker::ETSChecker * checker)79 checker::Type *TSEnumMember::Check(checker::ETSChecker *checker)
80 {
81 return checker->GetAnalyzer()->Check(this);
82 }
83 } // namespace panda::es2panda::ir
84