1 /**
2  * Copyright (c) 2024 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_EVALUATE_CLASS_BUILDER_H
17 #define ES2PANDA_EVALUATE_CLASS_BUILDER_H
18 
19 #include "ir/base/classDefinition.h"
20 #include "util/ustring.h"
21 #include "libpandabase/utils/arena_containers.h"
22 
23 namespace ark::panda_file {
24 class ClassDataAccessor;
25 }  // namespace ark::panda_file
26 
27 namespace ark::es2panda::parser {
28 class Program;
29 }  // namespace ark::es2panda::parser
30 
31 namespace ark::es2panda::checker {
32 class ETSChecker;
33 }  // namespace ark::es2panda::checker
34 
35 namespace ark::es2panda::ir {
36 class ClassDeclaration;
37 class Expression;
38 }  // namespace ark::es2panda::ir
39 
40 namespace ark::es2panda::ir {
41 class ClassDeclaration;
42 class AstNode;
43 }  // namespace ark::es2panda::ir
44 
45 namespace ark::es2panda::evaluate {
46 
47 class ClassBuilder {
48 public:
49     explicit ClassBuilder(checker::ETSChecker *checker, util::StringView name, panda_file::ClassDataAccessor &cda,
50                           ir::Expression *superClass);
51 
52     ir::ClassDeclaration *Build(parser::Program *program) &&;
53 
IsAbstract() const54     [[nodiscard]] bool IsAbstract() const
55     {
56         return (modifierFlags_ & ir::ModifierFlags::ABSTRACT) != 0;
57     }
58 
59 private:
60     void BuildFields(ArenaVector<ir::AstNode *> &classBody);
61     void BuildMethods(ArenaVector<ir::AstNode *> &classBody);
62 
63 private:
64     checker::ETSChecker *checker_ {nullptr};
65 
66     util::StringView className_ {};
67     panda_file::ClassDataAccessor &cda_;
68     ir::Expression *superClass_ {nullptr};
69 
70     ir::ModifierFlags modifierFlags_ {ir::ModifierFlags::NONE};
71     ir::ClassDefinitionModifiers classModifiers_ {ir::ClassDefinitionModifiers::NONE};
72 };
73 
74 }  // namespace ark::es2panda::evaluate
75 
76 #endif  // ES2PANDA_EVALUATE_CLASS_BUILDER_H
77