• 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 "functionDeclaration.h"
17 
18 #include "varbinder/variable.h"
19 #include "varbinder/scope.h"
20 #include "compiler/core/ETSGen.h"
21 #include "checker/TSchecker.h"
22 #include "ir/astDump.h"
23 #include "ir/srcDump.h"
24 #include "compiler/core/pandagen.h"
25 
26 namespace panda::es2panda::ir {
TransformChildren(const NodeTransformer & cb)27 void FunctionDeclaration::TransformChildren(const NodeTransformer &cb)
28 {
29     for (auto *&it : decorators_) {
30         it = cb(it)->AsDecorator();
31     }
32 
33     func_ = cb(func_)->AsScriptFunction();
34 }
35 
Iterate(const NodeTraverser & cb) const36 void FunctionDeclaration::Iterate(const NodeTraverser &cb) const
37 {
38     for (auto *it : decorators_) {
39         cb(it);
40     }
41 
42     cb(func_);
43 }
44 
Dump(ir::AstDumper * dumper) const45 void FunctionDeclaration::Dump(ir::AstDumper *dumper) const
46 {
47     dumper->Add({{"type", func_->IsOverload() ? "TSDeclareFunction" : "FunctionDeclaration"},
48                  {"decorators", AstDumper::Optional(decorators_)},
49                  {"function", func_}});
50 }
51 
Dump(ir::SrcDumper * dumper) const52 void FunctionDeclaration::Dump(ir::SrcDumper *dumper) const
53 {
54     dumper->Add("FunctionDeclaration");
55 }
56 
Compile(compiler::PandaGen * pg) const57 void FunctionDeclaration::Compile(compiler::PandaGen *pg) const
58 {
59     pg->GetAstCompiler()->Compile(this);
60 }
61 
Compile(compiler::ETSGen * etsg) const62 void FunctionDeclaration::Compile(compiler::ETSGen *etsg) const
63 {
64     etsg->GetAstCompiler()->Compile(this);
65 }
66 
Check(checker::TSChecker * checker)67 checker::Type *FunctionDeclaration::Check(checker::TSChecker *checker)
68 {
69     return checker->GetAnalyzer()->Check(this);
70 }
71 
Check(checker::ETSChecker * checker)72 checker::Type *FunctionDeclaration::Check(checker::ETSChecker *checker)
73 {
74     return checker->GetAnalyzer()->Check(this);
75 }
76 }  // namespace panda::es2panda::ir
77