• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_CPPCODEEMITTER_H
17 #define OHOS_IDL_CPPCODEEMITTER_H
18 
19 #include <string>
20 
21 #include "codegen/code_emitter.h"
22 #include "util/string_builder.h"
23 
24 namespace OHOS {
25 namespace Idl {
26 class CppCodeEmitter : public CodeEmitter {
27 public:
CppCodeEmitter(MetaComponent * mc)28     CppCodeEmitter(MetaComponent* mc)
29         : CodeEmitter(mc)
30     {}
31 
32     void EmitInterface() override;
33 
34     void EmitInterfaceProxy() override;
35 
36     void EmitInterfaceStub() override;
37 
38 private:
39     void EmitInterfaceHeaderFile();
40 
41     void EmitInterfaceInclusions(StringBuilder& sb);
42 
43     void EmitInterfaceStdlibInclusions(StringBuilder& sb);
44 
45     void EmitInterfaceDBinderInclusions(StringBuilder& sb);
46 
47     void EmitInterfaceSelfDefinedTypeInclusions(StringBuilder& sb);
48 
49     bool EmitInterfaceUsings(StringBuilder& sb);
50 
51     void EmitInterfaceSelfDefinedTypeUsings(StringBuilder& sb);
52 
53     void EmitInterfaceDefinition(StringBuilder& sb);
54 
55     void EmitInterfaceBody(StringBuilder& sb, const String& prefix);
56 
57     void EmitInterfaceMemberVariables(StringBuilder& sb, const String& prefix);
58 
59     void EmitInterfaceMethods(StringBuilder& sb, const String& prefix);
60 
61     void EmitInterfaceMethod(MetaMethod* mm, StringBuilder& sb, const String& prefix);
62 
63     void EmitInterfaceMethodParameter(MetaParameter* mp, StringBuilder& sb, const String& prefix);
64 
65     void EmitInterfaceMethodReturn(MetaType* mt, StringBuilder& sb, const String& prefix);
66 
67     void EmitInterfaceProxyHeaderFile();
68 
69     void EmitInterfaceProxyInHeaderFile(StringBuilder& sb);
70 
71     void EmitInterfaceProxyConstructor(StringBuilder& sb, const String& prefix);
72 
73     void EmitInterfaceProxyMethodDecls(StringBuilder& sb, const String& prefix);
74 
75     void EmitInterfaceProxyMethodDecl(MetaMethod* mm, StringBuilder& sb, const String& prefix);
76 
77     void EmitInterfaceProxyConstants(StringBuilder& sb, const String& prefix);
78 
79     void EmitInterfaceProxyCppFile();
80 
81     void EmitInterfaceProxyMethodImpls(StringBuilder& sb, const String& prefix);
82 
83     void EmitInterfaceProxyMethodImpl(MetaMethod* mm, StringBuilder& sb, const String& prefix);
84 
85     void EmitInterfaceProxyMethodBody(MetaMethod* mm, StringBuilder& sb, const String& prefix);
86 
87     void EmitInterfaceProxyMethodRetValue(MetaMethod* mm, StringBuilder& sb, const String& prefix);
88 
89     void EmitWriteMethodParameter(MetaParameter* mp, const String& parcelName, StringBuilder& sb,
90         const String& prefix);
91 
92     void EmitReadMethodParameter(MetaParameter* mp, const String& parcelName, StringBuilder& sb, const String& prefix);
93 
94     void EmitInterfaceStubHeaderFile();
95 
96     void EmitInterfaceStubInHeaderFile(StringBuilder& sb);
97 
98     void EmitInterfaceStubMethodDecls(StringBuilder& sb, const String& prefix);
99 
100     void EmitInterfaceStubConstants(StringBuilder& sb, const String& prefix);
101 
102     void EmitInterfaceStubCppFile();
103 
104     void EmitInterfaceStubMethodImpls(StringBuilder& sb, const String& prefix);
105 
106     void EmitInterfaceStubMethodImpl(MetaMethod* mm, StringBuilder& sb, const String& prefix);
107 
108     void EmitInterfaceMethodCommands(StringBuilder& sb, const String& prefix);
109 
110     void EmitLicense(StringBuilder& sb);
111 
112     void EmitHeadMacro(StringBuilder& sb, const String& fullName);
113 
114     void EmitTailMacro(StringBuilder& sb, const String& fullName);
115 
116     void EmitBeginNamespace(StringBuilder& sb);
117 
118     void EmitEndNamespace(StringBuilder& sb);
119 
120     void EmitWriteVariable(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
121         const String& prefix);
122 
123     void EmitWriteVariableComplex(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
124         const String& prefix);
125 
126     void EmitWriteVariableObject(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
127         const String& prefix);
128 
129     void EmitReadVariable(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
130         const String& prefix, bool emitType = true);
131 
132     void EmitReadVariableComplex(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
133         const String& prefix, bool emitType = true);
134 
135     void EmitReadVariableList(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
136         const String& prefix, bool emitType = true);
137 
138     void EmitReadVariableObject(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
139         const String& prefix, bool emitType = true);
140 
141     void EmitLocalVariable(MetaParameter* mp, StringBuilder& sb, const String& prefix);
142 
143     void EmitReturnParameter(const String& name, MetaType* mt, StringBuilder& sb);
144 
145     String EmitType(MetaType* mt, unsigned int attributes, bool isInnerType);
146 
147     String EmitComplexType(MetaType* mt, unsigned int attributes, bool isInnerType);
148 
149     String EmitListType(MetaType* mt, unsigned int attributes, bool isInnerType);
150 
151     String EmitObjectType(MetaType* mt, unsigned int attributes, bool isInnerType);
152 
153     String FileName(const String& name);
154 
155     String GetFilePath(const String& fpnp);
156 
157     String GetFilePathNoPoint(const String& fpnp);
158 
159     String GetNamespace(const String& fpnp);
160 
161     String MacroName(const String& name);
162 
163     String CppFullName(const String& name);
164 
165     String ConstantName(const String& name);
166 
167     const std::string UnderlineAdded(const String& name);
168 };
169 } // namespace Idl
170 } // namespace OHOS
171 #endif // OHOS_IDL_CPPCODEEMITTER_H
172