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 OHOS_IDL_HDI_CODE_EMITTER_H 17 #define OHOS_IDL_HDI_CODE_EMITTER_H 18 19 #include "codegen/code_emitter.h" 20 #include "hdi_type_emitter.h" 21 22 namespace OHOS { 23 namespace Idl { 24 class HDICodeEmitter : public CodeEmitter { 25 public: 26 using TypeEmitterMap = std::unordered_map<TypeKind, AutoPtr<HdiTypeEmitter>>; 27 28 ~HDICodeEmitter() override = default; 29 30 bool OutPut(const AutoPtr<AST> &ast, const std::string &targetDirectory, GenMode mode) override; 31 32 virtual void EmitUtilMethods(StringBuilder &sb, bool isDecl); 33 34 protected: 35 bool Reset(const AutoPtr<AST> &ast, const std::string &targetDirectory, GenMode mode); 36 37 void CleanData(); 38 39 AutoPtr<HdiTypeEmitter> GetTypeEmitter(AutoPtr<ASTType> astType) const; 40 41 void EmitInterfaceBuffSizeMacro(StringBuilder &sb) const; 42 43 void EmitUtilMethodMap(StringBuilder &sb, const UtilMethodMap &methods); 44 45 GenMode mode_ = GenMode::IPC; 46 std::string implName_; 47 std::string implFullName_; 48 std::string majorVerName_; 49 std::string minorVerName_; 50 51 std::string flagOfSetMemName_; 52 std::string optionName_; 53 54 private: 55 std::string GetNameWithNamespace(AutoPtr<ASTNamespace> space, std::string name) const; 56 57 AutoPtr<HdiTypeEmitter> NewTypeEmitter(AutoPtr<ASTType> astType) const; 58 59 AutoPtr<HdiTypeEmitter> NewMapTypeEmitter(AutoPtr<ASTType> astType) const; 60 61 AutoPtr<HdiTypeEmitter> NewArrayTypeEmitter(AutoPtr<ASTType> astType) const; 62 63 AutoPtr<HdiTypeEmitter> NewListTypeEmitter(AutoPtr<ASTType> astType) const; 64 65 AutoPtr<HdiTypeEmitter> NewEnumTypeEmitter(AutoPtr<ASTType> astType) const; 66 67 AutoPtr<HdiTypeEmitter> NewStructTypeEmitter(AutoPtr<ASTType> astType) const; 68 69 AutoPtr<HdiTypeEmitter> NewUnionTypeEmitter(AutoPtr<ASTType> astType) const; 70 71 AutoPtr<HdiTypeEmitter> NewSmqTypeEmitter(AutoPtr<ASTType> astType) const; 72 73 static TypeEmitterMap basicEmitters_; 74 }; 75 } // namespace Idl 76 } // namespace OHOS 77 78 #endif // OHOS_IDL_CODE_EMITTER_H 79