• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CPP_CODE_EMITTER_H
17 #define OHOS_IDL_HDI_CPP_CODE_EMITTER_H
18 
19 #include "codegen/HDI/hdi_code_emitter.h"
20 
21 namespace OHOS {
22 namespace Idl {
23 class HDICppCodeEmitter : public HDICodeEmitter {
24 public:
25     ~HDICppCodeEmitter() override = default;
26 
27 protected:
28 
29     void GetImportInclusions(HeaderFile::HeaderFileSet &headerFiles);
30 
31     void EmitInterfaceMethodParameter(
32         const AutoPtr<ASTParameter> &param, StringBuilder &sb, const std::string &prefix) const;
33 
34     bool IsVersion(const std::string &name) const;
35 
36     void GetStdlibInclusions(HeaderFile::HeaderFileSet &headerFiles);
37 
38     std::vector<std::string> EmitCppNameSpaceVec(const std::string &namespaceStr) const;
39 
40     std::string EmitPackageToNameSpace(const std::string &packageName) const;
41 
42     virtual void EmitBeginNamespace(StringBuilder &sb);
43 
44     virtual void EmitEndNamespace(StringBuilder &sb);
45 
46     virtual void EmitUsingNamespace(StringBuilder &sb);
47 
48     std::string EmitNamespace(const std::string &packageName) const;
49 
50     void EmitImportUsingNamespace(StringBuilder &sb);
51 
52     void EmitWriteMethodParameter(const AutoPtr<ASTParameter> &param, const std::string &parcelName, StringBuilder &sb,
53         const std::string &prefix) const;
54 
55     void EmitReadMethodParameter(const AutoPtr<ASTParameter> &param, TypeMode mode, StringBuilder &sb,
56         const std::string &prefix) const;
57 
58     std::string SpecificationParam(StringBuilder &paramSb, const std::string &prefix) const;
59 
60     std::string EmitHeaderNameByInterface(AutoPtr<ASTInterfaceType> interface, const std::string &name);
61 
62     std::string EmitDefinitionByInterface(AutoPtr<ASTInterfaceType> interface, const std::string &name) const;
63 };
64 } // namespace Idl
65 } // namespace OHOS
66 
67 #endif // OHOS_IDL_CPP_CODE_EMITTER_H