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 "tsAsExpression.h"
17
18 #include "varbinder/scope.h"
19 #include "checker/TSchecker.h"
20 #include "checker/ets/castingContext.h"
21 #include "checker/types/ets/etsUnionType.h"
22 #include "compiler/core/ETSGen.h"
23 #include "compiler/core/pandagen.h"
24 #include "ir/expressions/identifier.h"
25 #include "ir/expressions/literal.h"
26 #include "ir/expressions/memberExpression.h"
27 #include "ir/expressions/objectExpression.h"
28 #include "ir/expressions/unaryExpression.h"
29 #include "ir/typeNode.h"
30 #include "ir/ets/etsFunctionType.h"
31
32 namespace panda::es2panda::ir {
Expr()33 Expression *TSAsExpression::Expr()
34 {
35 return expression_;
36 }
37
SetExpr(Expression * expr)38 void TSAsExpression::SetExpr(Expression *expr)
39 {
40 expression_ = expr;
41 SetStart(expression_->Start());
42 }
43
TransformChildren(const NodeTransformer & cb)44 void TSAsExpression::TransformChildren(const NodeTransformer &cb)
45 {
46 expression_ = cb(expression_)->AsExpression();
47 SetTsTypeAnnotation(static_cast<TypeNode *>(cb(TypeAnnotation())));
48 }
49
Iterate(const NodeTraverser & cb) const50 void TSAsExpression::Iterate(const NodeTraverser &cb) const
51 {
52 cb(expression_);
53 cb(TypeAnnotation());
54 }
55
Dump(ir::AstDumper * dumper) const56 void TSAsExpression::Dump(ir::AstDumper *dumper) const
57 {
58 dumper->Add({{"type", "TSAsExpression"}, {"expression", expression_}, {"typeAnnotation", TypeAnnotation()}});
59 }
60
Dump(ir::SrcDumper * dumper) const61 void TSAsExpression::Dump(ir::SrcDumper *dumper) const
62 {
63 dumper->Add("TSAsExpression");
64 }
65
Compile(compiler::PandaGen * pg) const66 void TSAsExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const
67 {
68 pg->GetAstCompiler()->Compile(this);
69 }
70
Compile(compiler::ETSGen * etsg) const71 void TSAsExpression::Compile(compiler::ETSGen *etsg) const
72 {
73 etsg->GetAstCompiler()->Compile(this);
74 }
75
Check(checker::TSChecker * checker)76 checker::Type *TSAsExpression::Check([[maybe_unused]] checker::TSChecker *checker)
77 {
78 return checker->GetAnalyzer()->Check(this);
79 }
80
Check(checker::ETSChecker * const checker)81 checker::Type *TSAsExpression::Check(checker::ETSChecker *const checker)
82 {
83 return checker->GetAnalyzer()->Check(this);
84 }
85 } // namespace panda::es2panda::ir
86