1 /* 2 * Copyright (c) 2021 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 virtual ~CCodeEmitter() = default; 22 23 protected: 24 void GetImportInclusions(HeaderFile::HeaderFileSet &headerFiles); 25 26 void EmitInterfaceMethodParameter( 27 const AutoPtr<ASTParameter> ¶meter, StringBuilder &sb, const std::string &prefix); 28 29 void EmitMethodNeedLoopVar( 30 const AutoPtr<ASTMethod> &method, bool needRW, bool needFree, StringBuilder &sb, const std::string &prefix); 31 32 bool EmitNeedLoopVar(const AutoPtr<ASTType> &type, bool needRW, bool needFree); 33 34 void EmitErrorHandle(const AutoPtr<ASTMethod> &method, const std::string &gotoLabel, bool isClient, 35 StringBuilder &sb, const std::string &prefix); 36 37 void EmitLicense(StringBuilder &sb); 38 39 void EmitHeadMacro(StringBuilder &sb, const std::string &fullName); 40 41 void EmitTailMacro(StringBuilder &sb, const std::string &fullName); 42 43 void EmitHeadExternC(StringBuilder &sb); 44 45 void EmitTailExternC(StringBuilder &sb); 46 47 std::string MacroName(const std::string &name); 48 49 std::string ConstantName(const std::string &name); 50 51 std::string SpecificationParam(StringBuilder &sb, const std::string &prefix); 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