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 #include "codegen/code_generator.h" 17 #include "util/options.h" 18 #include "util/logger.h" 19 20 namespace OHOS { 21 namespace Idl { DoGenerate(const StrAstMap & allAst)22bool CodeGenerator::DoGenerate(const StrAstMap &allAst) 23 { 24 return false; 25 } 26 GetInstance()27CodegenBuilder &CodegenBuilder::GetInstance() 28 { 29 static CodegenBuilder genBuilder; 30 return genBuilder; 31 } 32 Generate(const StrAstMap & allAst)33bool CodegenBuilder::Generate(const StrAstMap &allAst) 34 { 35 auto generator = generators.find(Options::GetInstance().GetInterfaceType()); 36 if (generator == generators.end()) { 37 Logger::E(TAG, "the interface type is not supported, please check option"); 38 return false; 39 } 40 41 return generator->second->DoGenerate(allAst); 42 } 43 GeneratorRegister(InterfaceType type,AutoPtr<CodeGenerator> generator)44void CodegenBuilder::GeneratorRegister(InterfaceType type, AutoPtr<CodeGenerator> generator) 45 { 46 generators[type] = generator; 47 } 48 } // namespace Idl 49 } // namespace OHOS