• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "variableDeclaration.h"
17 
18 #include <ir/astDump.h>
19 #include <ir/statements/variableDeclarator.h>
20 
21 namespace panda::es2panda::ir {
22 
Iterate(const NodeTraverser & cb) const23 void VariableDeclaration::Iterate(const NodeTraverser &cb) const
24 {
25     for (auto *it : declarators_) {
26         cb(it);
27     }
28 }
29 
Dump(ir::AstDumper * dumper) const30 void VariableDeclaration::Dump(ir::AstDumper *dumper) const
31 {
32     const char *kind = nullptr;
33 
34     switch (kind_) {
35         case VariableDeclarationKind::CONST: {
36             kind = "const";
37             break;
38         }
39         case VariableDeclarationKind::LET: {
40             kind = "let";
41             break;
42         }
43         case VariableDeclarationKind::VAR: {
44             kind = "var";
45             break;
46         }
47         default: {
48             UNREACHABLE();
49         }
50     }
51 
52     dumper->Add({{"type", "VariableDeclaration"},
53                  {"declarations", declarators_},
54                  {"kind", kind},
55                  {"declare", AstDumper::Optional(declare_)}});
56 }
57 
Compile(compiler::PandaGen * pg) const58 void VariableDeclaration::Compile(compiler::PandaGen *pg) const
59 {
60     for (const auto *it : declarators_) {
61         it->Compile(pg);
62     }
63 }
64 
Check(checker::Checker * checker) const65 checker::Type *VariableDeclaration::Check(checker::Checker *checker) const
66 {
67     for (auto *it : declarators_) {
68         it->Check(checker);
69     }
70 
71     return nullptr;
72 }
73 
UpdateSelf(const NodeUpdater & cb,binder::Binder * binder)74 void VariableDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)
75 {
76     for (auto iter = declarators_.begin(); iter != declarators_.end(); iter++) {
77         *iter = std::get<ir::AstNode *>(cb(*iter))->AsVariableDeclarator();
78     }
79 }
80 
81 }  // namespace panda::es2panda::ir
82