1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef OHOS_HDI_C_CODE_EMITTER_H 10 #define OHOS_HDI_C_CODE_EMITTER_H 11 12 #include "ast/ast.h" 13 #include "codegen/code_emitter.h" 14 #include "util/autoptr.h" 15 #include "util/string_builder.h" 16 17 namespace OHOS { 18 namespace HDI { 19 class CCodeEmitter : public CodeEmitter { 20 public: 21 ~CCodeEmitter() override = default; 22 23 protected: 24 void GetStdlibInclusions(HeaderFile::HeaderFileSet &headerFiles); 25 26 void GetImportInclusions(HeaderFile::HeaderFileSet &headerFiles); 27 28 void EmitInterfaceMethodParameter( 29 const AutoPtr<ASTParameter> ¶meter, StringBuilder &sb, const std::string &prefix) const; 30 31 void EmitMethodNeedLoopVar(const AutoPtr<ASTMethod> &method, 32 bool needRW, bool needFree, StringBuilder &sb, const std::string &prefix) const; 33 34 bool EmitNeedLoopVar(const AutoPtr<ASTType> &type, bool needRW, bool needFree) const; 35 36 void EmitErrorHandle(const AutoPtr<ASTMethod> &method, const std::string &gotoLabel, bool isClient, 37 StringBuilder &sb, const std::string &prefix) const; 38 39 void EmitLicense(StringBuilder &sb); 40 41 void EmitHeadMacro(StringBuilder &sb, const std::string &fullName) const; 42 43 void EmitTailMacro(StringBuilder &sb, const std::string &fullName) const; 44 45 void EmitHeadExternC(StringBuilder &sb) const; 46 47 void EmitTailExternC(StringBuilder &sb) const; 48 49 std::string MacroName(const std::string &name) const; 50 51 std::string SpecificationParam(StringBuilder ¶mSb, const std::string &prefix) const; 52 53 static constexpr const char *errorsLabelName_ = "ERRORS"; 54 static constexpr const char *finishedLabelName_ = "FINISHED"; 55 }; 56 } // namespace HDI 57 } // namespace OHOS 58 59 #endif // OHOS_HDI_C_CODE_EMITTER_H