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_UTIL_INCLUDE_AST_BUILDER 17 #define ES2PANDA_UTIL_INCLUDE_AST_BUILDER 18 19 #include "mem/arena_allocator.h" 20 #include "util/helpers.h" 21 22 namespace ark::es2panda::ir { 23 24 class AstBuilder { 25 public: AstBuilder(ark::ArenaAllocator * allocator)26 explicit AstBuilder(ark::ArenaAllocator *allocator) : allocator_(allocator) {} 27 Allocator()28 ark::ArenaAllocator *Allocator() 29 { 30 return allocator_; 31 } 32 33 template <typename T, typename... Args> AllocNode(Args &&...args)34 T *AllocNode(Args &&...args) 35 { 36 return util::NodeAllocator::ForceSetParent<T>(allocator_, std::forward<Args>(args)...); 37 } 38 39 private: 40 ark::ArenaAllocator *allocator_; 41 }; 42 43 } // namespace ark::es2panda::ir 44 #endif // ES2PANDA_UTIL_INCLUDE_AST_BUILDER