• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef ES2PANDA_COMPILER_BASE_LREFERENCE_H
17 #define ES2PANDA_COMPILER_BASE_LREFERENCE_H
18 
19 #include <binder/scope.h>
20 #include <ir/irnode.h>
21 
22 namespace panda::es2panda::ir {
23 class AstNode;
24 }  // namespace panda::es2panda::ir
25 
26 namespace panda::es2panda::compiler {
27 
28 enum class ReferenceKind {
29     MEMBER,
30     VAR_OR_GLOBAL,
31     DESTRUCTURING,
32 };
33 
34 enum class ReferenceFlags {
35     NONE = 0,
36     DECLARATION = 1U << 0U,
37 };
38 
39 class PandaGen;
40 
41 class LReference {
42 public:
43     LReference(const ir::AstNode *node, PandaGen *pg, bool isDeclaration, ReferenceKind refKind,
44                binder::ScopeFindResult res);
45     ~LReference() = default;
46     NO_COPY_SEMANTIC(LReference);
47     NO_MOVE_SEMANTIC(LReference);
48 
49     void GetValue();
50     void SetValue();
51     binder::Variable *Variable() const;
52     ReferenceKind Kind() const;
53 
54     static LReference CreateLRef(PandaGen *pg, const ir::AstNode *node, bool isDeclaration);
55 
56 private:
57     const ir::AstNode *node_;
58     PandaGen *pg_;
59     ReferenceKind refKind_;
60     binder::ScopeFindResult res_;
61     VReg obj_;
62     Operand prop_;
63     bool isDeclaration_;
64 };
65 
66 }  // namespace panda::es2panda::compiler
67 
68 #endif
69