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 23namespace ark::panda_file { 24class ClassDataAccessor; 25} // namespace ark::panda_file 26 27namespace ark::es2panda::parser { 28class Program; 29} // namespace ark::es2panda::parser 30 31namespace ark::es2panda::checker { 32class ETSChecker; 33} // namespace ark::es2panda::checker 34 35namespace ark::es2panda::ir { 36class ClassDeclaration; 37class Expression; 38} // namespace ark::es2panda::ir 39 40namespace ark::es2panda::ir { 41class ClassDeclaration; 42class AstNode; 43} // namespace ark::es2panda::ir 44 45namespace ark::es2panda::evaluate { 46 47class ClassBuilder { 48public: 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 54 [[nodiscard]] bool IsAbstract() const 55 { 56 return (modifierFlags_ & ir::ModifierFlags::ABSTRACT) != 0; 57 } 58 59private: 60 void BuildFields(ArenaVector<ir::AstNode *> &classBody); 61 void BuildMethods(ArenaVector<ir::AstNode *> &classBody); 62 63private: 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