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