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 <binder/binder.h>
19 #include <compiler/core/pandagen.h>
20 #include <ir/astDump.h>
21 #include <ir/base/classDefinition.h>
22 #include <typescript/checker.h>
23 #include <util/helpers.h>
24
25 namespace panda::es2panda::ir {
26
Iterate(const NodeTraverser & cb) const27 void ThisExpression::Iterate([[maybe_unused]] const NodeTraverser &cb) const {}
28
Dump(ir::AstDumper * dumper) const29 void ThisExpression::Dump(ir::AstDumper *dumper) const
30 {
31 dumper->Add({{"type", "ThisExpression"}});
32 }
33
Compile(compiler::PandaGen * pg) const34 void ThisExpression::Compile(compiler::PandaGen *pg) const
35 {
36 binder::ScopeFindResult res = pg->Scope()->Find(binder::Binder::MANDATORY_PARAM_THIS);
37
38 ASSERT(res.variable && res.variable->IsLocalVariable());
39 if (pg->isDebuggerEvaluateExpressionMode()) {
40 pg->LoadObjByNameViaDebugger(this, binder::Binder::MANDATORY_PARAM_THIS, true);
41 } else {
42 pg->LoadAccFromLexEnv(this, res);
43 }
44
45 const ir::ScriptFunction *func = util::Helpers::GetContainingConstructor(this);
46 if (func && util::Helpers::GetClassDefiniton(func)->Super()) {
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