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