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 "regExpLiteral.h"
17
18 #include <binder/variable.h>
19 #include <compiler/core/pandagen.h>
20 #include <compiler/core/regScope.h>
21 #include <typescript/checker.h>
22 #include <ir/astDump.h>
23
24 namespace panda::es2panda::ir {
25
Iterate([[maybe_unused]] const NodeTraverser &cb) const26 void RegExpLiteral::Iterate([[maybe_unused]] const NodeTraverser &cb) const {}
27
Dump(ir::AstDumper *dumper) const28 void RegExpLiteral::Dump(ir::AstDumper *dumper) const
29 {
30 dumper->Add({{"type", "RegExpLiteral"}, {"source", pattern_}, {"flags", flags_}});
31 }
32
Compile(compiler::PandaGen *pg) const33 void RegExpLiteral::Compile(compiler::PandaGen *pg) const
34 {
35 compiler::RegScope rs(pg);
36 /* [ ctor, newTarget, regexpPattern(, regexpFlags) ] */
37 compiler::VReg ctor = pg->AllocReg();
38 compiler::VReg pattern = pg->AllocReg();
39 size_t argCount = 2;
40
41 pg->TryLoadGlobalByName(this, "RegExp");
42 pg->StoreAccumulator(this, ctor);
43
44 pg->LoadAccumulatorString(this, pattern_);
45 pg->StoreAccumulator(this, pattern);
46
47 if (!flags_.Empty()) {
48 compiler::VReg flag = pg->AllocReg();
49 pg->LoadAccumulatorString(this, flags_);
50 pg->StoreAccumulator(this, flag);
51 argCount++;
52 }
53
54 pg->NewObject(this, ctor, argCount);
55 }
56
Check(checker::Checker *checker) const57 checker::Type *RegExpLiteral::Check(checker::Checker *checker) const
58 {
59 return checker->GlobalAnyType();
60 }
61
UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder)62 void RegExpLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {}
63
64 } // namespace panda::es2panda::ir
65