• 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_SA_CPP_CODE_EMITTER_H
17 #define OHOS_IDL_SA_CPP_CODE_EMITTER_H
18 
19 #include "codegen/SA/sa_code_emitter.h"
20 
21 namespace OHOS {
22 namespace Idl {
23 class SACppCodeEmitter : public SACodeEmitter {
24 public:
25     ~SACppCodeEmitter() override = default;
26 
27 protected:
28     void GetImportInclusions(HeaderFile::HeaderFileSet &headerFiles);
29 
30     void EmitImportUsingNamespace(StringBuilder &sb) const;
31 
32     void GetStdlibInclusions(HeaderFile::HeaderFileSet &headerFiles);
33 
34     void EmitBeginNamespace(StringBuilder &sb) const;
35 
36     void EmitEndNamespace(StringBuilder &sb) const;
37 
38     void EmitInterfaceMethodParams(AutoPtr<ASTMethod> &method, StringBuilder &sb, const std::string &prefix) const;
39 
40     void EmitInterfaceClientMethodParams(AutoPtr<ASTMethod> &method, StringBuilder &sb,
41         const std::string &prefix, bool includeValue) const;
42 
43     void EmitInterfaceClientMethodParamsWithoutType(
44         AutoPtr<ASTMethod> &method, StringBuilder &sb, const std::string &prefix)  const;
45 
46     void EmitParamsWithReturnType(AutoPtr<ASTMethod> &method, StringBuilder &sb,
47         const std::string &prefix, bool includeType) const;
48 
49     void EmitWriteMethodParameter(const AutoPtr<ASTParameter> &param, const std::string &parcelName,
50         StringBuilder &sb, const std::string &prefix) const;
51 
52     void EmitReadMethodParameter(const AutoPtr<ASTParameter> &param, const std::string &parcelName,
53         bool emitType, StringBuilder &sb, const std::string &prefix) const;
54 
55     void GetOverloadName(AutoPtr<ASTMethod> &method, std::string &overloadname) const;
56 
57     void CheckMethodOverload(AutoPtr<ASTMethod> &method, size_t &index, std::string &overloadname) const;
58 
59     void EmitInterfaceMethodCommands(StringBuilder &sb, const std::string &prefix) override;
60 
61     void EmitSecurecInclusion(StringBuilder &sb) const;
62 
SetOverloadName(const std::string & name)63     inline void SetOverloadName(const std::string &name) const
64     {
65         overloadname_ = name;
66     }
67 
GetOverloadName()68     inline std::string GetOverloadName() const
69     {
70         return overloadname_;
71     }
72 
73     bool isProxy = false;
74 
75     mutable std::string overloadname_;
76 private:
77     std::string EmitCppParameter(AutoPtr<ASTParameter> &param) const;
78 };
79 } // namespace Idl
80 } // namespace OHOS
81 
82 #endif // OHOS_IDL_CPP_CODE_EMITTER_H