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 "thisExpression.h"
17
18 #include <util/helpers.h>
19 #include <binder/binder.h>
20 #include <compiler/core/pandagen.h>
21 #include <typescript/checker.h>
22 #include <ir/astDump.h>
23
24 namespace panda::es2panda::ir {
25
Iterate(const NodeTraverser & cb) const26 void ThisExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const {}
27
Dump(ir::AstDumper * dumper) const28 void ThisExpression::Dump(ir::AstDumper *dumper) const
29 {
30 dumper->Add({{"type", "ThisExpression"}});
31 }
32
Compile(compiler::PandaGen * pg) const33 void ThisExpression::Compile(compiler::PandaGen *pg) const
34 {
35 binder::ScopeFindResult res = pg->Scope()->Find(binder::Binder::MANDATORY_PARAM_THIS);
36
37 ASSERT(res.variable && res.variable->IsLocalVariable());
38 if (pg->isDebuggerEvaluateExpressionMode()) {
39 pg->LoadObjByNameViaDebugger(this, binder::Binder::MANDATORY_PARAM_THIS, true);
40 } else {
41 pg->LoadAccFromLexEnv(this, res);
42 }
43
44 const ir::ScriptFunction *func = util::Helpers::GetContainingConstructor(this);
45
46 if (func) {
47 pg->ThrowIfSuperNotCorrectCall(this, 0);
48 }
49 }
50
Check(checker::Checker * checker) const51 checker::Type *ThisExpression::Check(checker::Checker *checker) const
52 {
53 // TODO(aszilagyi)
54 return checker->GlobalAnyType();
55 }
56
UpdateSelf(const NodeUpdater & cb,binder::Binder * binder)57 void ThisExpression::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {}
58
59 } // namespace panda::es2panda::ir
60