|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #pragma warning (disable:4786) // disable "identifier was truncated to '255' characters in the browser information" warning |
|
18 #include "CdlCompilerToolkit/CdlTkProcess.h" |
|
19 #include "CdlTkPriv.h" |
|
20 #include <fstream> |
|
21 #include <iomanip> |
|
22 #include <iostream> |
|
23 #include <sstream> |
|
24 using namespace std; |
|
25 |
|
26 namespace CdlCompilerToolkit { |
|
27 |
|
28 CCdlTkWriteInstance::CCdlTkWriteInstance(const CCdlTkInstance& aInstance) |
|
29 : iInstance(aInstance), iCdl(aInstance.Interface()) |
|
30 { |
|
31 } |
|
32 |
|
33 CCdlTkWriteInstance::~CCdlTkWriteInstance() |
|
34 { |
|
35 } |
|
36 |
|
37 void CCdlTkWriteInstance::Process() |
|
38 { |
|
39 string implName = CdlTkUtil::ToLower(CdlTkUtil::OutputPath() + CdlTkUtil::StripPath(iInstance.Name())); |
|
40 string headerName(implName + ".h"); |
|
41 InitReplace(headerName); |
|
42 ProcessCdl(); |
|
43 |
|
44 CCdlTkFileCleanup tempFile; |
|
45 |
|
46 ofstream hrhStream; |
|
47 CdlTkUtil::OpenTempOutput(hrhStream, tempFile); |
|
48 ProcessInstanceHrh(hrhStream, headerName+"rh"); |
|
49 hrhStream.close(); |
|
50 CdlTkUtil::ExportFileIfWritable(tempFile, headerName+"rh"); |
|
51 |
|
52 ofstream headerStream; |
|
53 CdlTkUtil::OpenTempOutput(headerStream, tempFile); |
|
54 ProcessInstanceHeader(headerStream, headerName); |
|
55 headerStream.close(); |
|
56 CdlTkUtil::ExportFileIfWritable(tempFile, headerName); |
|
57 |
|
58 ofstream cppStream; |
|
59 CdlTkUtil::OpenTempOutput(cppStream, tempFile); |
|
60 ProcessInstance(cppStream, headerName); |
|
61 cppStream.close(); |
|
62 CdlTkUtil::ExportFileIfWritable(tempFile, CdlTkUtil::CorrectFilenameCase(implName + ".cpp")); |
|
63 } |
|
64 |
|
65 void CCdlTkWriteInstance::InitReplace(const std::string& aHeaderName) |
|
66 { |
|
67 iReplace.clear(); |
|
68 iReplace.Add("$INSTNAME", iInstance.Name()); |
|
69 iReplace.Add("$CDLNAME", CdlTkUtil::StripPath(iCdl.FileName())); |
|
70 iReplace.Add("$CDLINCNAME", CdlTkUtil::ToLower(CdlTkUtil::StripPath(iCdl.FileName()))); |
|
71 iReplace.Add("$HEADERNAME", CdlTkUtil::ToLower(CdlTkUtil::StripPath(aHeaderName))); |
|
72 iReplace.Add("$EXTRA", iInstance.ExtraCpp()); |
|
73 iReplace.Add("$INSTNS", CdlTkUtil::ToCpp(iInstance.Name())); |
|
74 iReplace.Add("$CDLNS", iCdl.NamespaceName()); |
|
75 iReplace.Add("$CDLGUARD", HeaderGuardName(iCdl.FileName() + ".custom.h")); |
|
76 iReplace.Add("$INSTGUARD", HeaderGuardName(aHeaderName)); |
|
77 iReplace.Add("$CMDLINE", CdlTkUtil::CommandLine()); |
|
78 if (iInstance.Id() == KCdlTkGetInstanceIdFromHostDll) |
|
79 { |
|
80 iReplace.Add("$INSTID", iInstance.DllInstanceName()); |
|
81 iReplace.Add("$DLLINSTHEADER", "#include \"" + KDllInstHeader + "\"\n"); |
|
82 } |
|
83 else |
|
84 { |
|
85 iReplace.Add("$INSTID", CdlTkUtil::IntToString(iInstance.Id())); |
|
86 iReplace.Add("$DLLINSTHEADER", ""); |
|
87 } |
|
88 } |
|
89 |
|
90 void CCdlTkWriteInstance::ProcessCdl() const |
|
91 { |
|
92 AssertInterfaceNotExtended(iCdl); |
|
93 |
|
94 string baseName = CdlBaseNameAndPath(iCdl); |
|
95 |
|
96 string commonHeaderName(baseName + KCommonHeader); |
|
97 CCdlTkWriteCommonDefs::ExportCommonDefs(iCdl, commonHeaderName); |
|
98 |
|
99 CCdlTkFileCleanup tempFile; |
|
100 ofstream out; |
|
101 CdlTkUtil::OpenTempOutput(out, tempFile); |
|
102 string customHeaderName(baseName + ".custom.h"); |
|
103 ProcessInstanceApi(out, customHeaderName); |
|
104 out.close(); |
|
105 CdlTkUtil::ExportFile(tempFile, customHeaderName); |
|
106 } |
|
107 |
|
108 |
|
109 const string KInstanceApiStart = "\ |
|
110 /*\n\ |
|
111 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\ |
|
112 * All rights reserved.\n\ |
|
113 * This component and the accompanying materials are made available\n\ |
|
114 * under the terms of \"Eclipse Public License v1.0\"\n\ |
|
115 * which accompanies this distribution, and is available\n\ |
|
116 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\ |
|
117 *\n\ |
|
118 * Initial Contributors:\n\ |
|
119 * Nokia Corporation - initial contribution.\n\ |
|
120 *\n\ |
|
121 * Contributors:\n\ |
|
122 *\n\ |
|
123 * Description:\n\ |
|
124 *\n\ |
|
125 */\n\n\ |
|
126 // This file was generated from $CDLNAME.\n\ |
|
127 // It contains the customisation API.\n\ |
|
128 // It should not be modified manually.\n\ |
|
129 \n\ |
|
130 #ifndef $CDLGUARD\n\ |
|
131 #define $CDLGUARD\n\ |
|
132 \n\ |
|
133 #include <cdlengdef.h>\n\ |
|
134 #include \"$CDLINCNAME.common.h\"\n\ |
|
135 \n\ |
|
136 namespace $CDLNS\n\ |
|
137 {\n\ |
|
138 \n\ |
|
139 // This structure defines the interface to a customisation instance.\n\ |
|
140 // A customisation instance must supply an instance of this structure, with the pointer\n\ |
|
141 // members either being NULL, or pointing at functions or data of the correct type.\n\ |
|
142 \n\ |
|
143 #ifdef __WINS__\n\ |
|
144 struct SCdlImpl0\n\ |
|
145 #else\n\ |
|
146 struct SCdlImpl\n\ |
|
147 #endif\n\ |
|
148 \t{\n"; |
|
149 |
|
150 const string KInstanceApiEnd = "\ |
|
151 \t};\n\ |
|
152 #ifdef __WINS__\n\ |
|
153 struct SCdlImpl\n\ |
|
154 \t{\n\ |
|
155 \tSCdlImpl0 i0;\n\ |
|
156 $SUBSTRUCTS\ |
|
157 \t};\n\ |
|
158 #endif\n\ |
|
159 \n\ |
|
160 } // end of namespace $CDLNS\n\ |
|
161 #endif // $CDLGUARD\n"; |
|
162 |
|
163 const string KSubStructDecl = "\ |
|
164 #ifdef __WINS__\n\ |
|
165 \t};\n\ |
|
166 \n\ |
|
167 struct SCdlImpl$NUM\n\ |
|
168 \t{\n\ |
|
169 #endif\n"; |
|
170 |
|
171 const string KSubStructUse = "\tSCdlImpl$NUM i$NUM;\n"; |
|
172 |
|
173 const int KMsvcStructSplit = 1000; |
|
174 |
|
175 void CCdlTkWriteInstance::ProcessInstanceApi(ofstream& aStream, const string& aFileName) const |
|
176 { |
|
177 string subStructs; |
|
178 int count=0; |
|
179 aStream << CdlTkUtil::MultiReplace(iReplace, KInstanceApiStart); |
|
180 for (CCdlTkApiList::const_iterator pApi = iCdl.ApiList().begin(); pApi != iCdl.ApiList().end(); ++pApi) |
|
181 { |
|
182 aStream << "\t" << (*pApi)->PointerType() << " " << (*pApi)->Name() << ";" << endl; |
|
183 count++; |
|
184 if ((count%KMsvcStructSplit) == 0) |
|
185 { |
|
186 string num = CdlTkUtil::IntToString(count/KMsvcStructSplit); |
|
187 aStream << CdlTkUtil::Replace("$NUM", num, KSubStructDecl); |
|
188 CdlTkUtil::AppendString(subStructs, CdlTkUtil::Replace("$NUM", num, KSubStructUse)); |
|
189 } |
|
190 } |
|
191 string end = CdlTkUtil::Replace("$SUBSTRUCTS", subStructs, KInstanceApiEnd); |
|
192 aStream << CdlTkUtil::MultiReplace(iReplace, end); |
|
193 } |
|
194 |
|
195 |
|
196 const string KInstanceCppStart = "\ |
|
197 /*\n\ |
|
198 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\ |
|
199 * All rights reserved.\n\ |
|
200 * This component and the accompanying materials are made available\n\ |
|
201 * under the terms of \"Eclipse Public License v1.0\"\n\ |
|
202 * which accompanies this distribution, and is available\n\ |
|
203 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\ |
|
204 *\n\ |
|
205 * Initial Contributors:\n\ |
|
206 * Nokia Corporation - initial contribution.\n\ |
|
207 *\n\ |
|
208 * Contributors:\n\ |
|
209 *\n\ |
|
210 * Description:\n\ |
|
211 *\n\ |
|
212 */\n\n\ |
|
213 // $INSTNAME generated by\n\ |
|
214 // $CMDLINE\n\ |
|
215 // This customisation implements the interface defined in $CDLNAME\n\ |
|
216 \n\ |
|
217 #include \"$HEADERNAME\"\n\ |
|
218 $EXTRA\n\ |
|
219 namespace $INSTNS\n\ |
|
220 {\n\ |
|
221 \n"; |
|
222 |
|
223 const string KInstanceCppMid = "\ |
|
224 \n\ |
|
225 const $CDLNS::SCdlImpl KCdlImpl = \n\ |
|
226 \t{\n"; |
|
227 |
|
228 const string KInstanceCppEnd = "\ |
|
229 \t};\n\ |
|
230 \n\ |
|
231 } // end of namespace $INSTNS\n"; |
|
232 |
|
233 void CCdlTkWriteInstance::ProcessInstance(ofstream& aStream, const string& aHeaderName) const |
|
234 { |
|
235 aStream << CdlTkUtil::MultiReplace(iReplace, KInstanceCppStart); |
|
236 |
|
237 const CCdlTkImplementations& impl = iInstance.Impl(); |
|
238 CCdlTkImplementations::const_iterator pImpl; |
|
239 // write the definitions |
|
240 for (pImpl = impl.begin(); pImpl != impl.end(); ++pImpl) |
|
241 { |
|
242 const string& defn = (*pImpl)->Definition(); |
|
243 if (defn.size()) |
|
244 { |
|
245 aStream << defn << endl; |
|
246 aStream << endl; |
|
247 } |
|
248 } |
|
249 |
|
250 aStream << CdlTkUtil::MultiReplace(iReplace, KInstanceCppMid); |
|
251 |
|
252 // write the pointers |
|
253 for (pImpl = impl.begin(); pImpl != impl.end(); ++pImpl) |
|
254 aStream << "\t" << (*pImpl)->PointerReference() << "," << endl; |
|
255 |
|
256 aStream << CdlTkUtil::MultiReplace(iReplace, KInstanceCppEnd); |
|
257 } |
|
258 |
|
259 |
|
260 const string KInstanceHeader = "\ |
|
261 /*\n\ |
|
262 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\ |
|
263 * All rights reserved.\n\ |
|
264 * This component and the accompanying materials are made available\n\ |
|
265 * under the terms of \"Eclipse Public License v1.0\"\n\ |
|
266 * which accompanies this distribution, and is available\n\ |
|
267 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\ |
|
268 *\n\ |
|
269 * Initial Contributors:\n\ |
|
270 * Nokia Corporation - initial contribution.\n\ |
|
271 *\n\ |
|
272 * Contributors:\n\ |
|
273 *\n\ |
|
274 * Description:\n\ |
|
275 *\n\ |
|
276 */\n\n\ |
|
277 // This header file contains the customisation implementation identity for $INSTNAME\n\ |
|
278 // It was generated by:\n\ |
|
279 // $CMDLINE\n\ |
|
280 // This file may be manually modified.\n\ |
|
281 \n\ |
|
282 #ifndef $INSTGUARD\n\ |
|
283 #define $INSTGUARD\n\ |
|
284 #include \"$CDLINCNAME.custom.h\"\n\ |
|
285 #include \"$HEADERNAMErh\"\n\ |
|
286 \n\ |
|
287 namespace $INSTNS\n\ |
|
288 {\n\ |
|
289 \n\ |
|
290 const TInt KCdlInstanceId = _CDL_$INSTNS_KCdlInstanceId;\n\ |
|
291 using $CDLNS::KCdlInterface;\n\ |
|
292 using $CDLNS::KCdlInterfaceUidValue;\n\ |
|
293 GLREF_D const $CDLNS::SCdlImpl KCdlImpl;\n\ |
|
294 \n\ |
|
295 } // end of namespace $INSTNS\n\ |
|
296 #endif // $INSTGUARD\n"; |
|
297 |
|
298 void CCdlTkWriteInstance::ProcessInstanceHeader(ofstream& aStream, const string& aFileName) const |
|
299 { |
|
300 aStream << CdlTkUtil::MultiReplace(iReplace, KInstanceHeader); |
|
301 } |
|
302 |
|
303 |
|
304 const string KInstanceHrh = "\ |
|
305 /*\n\ |
|
306 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n\ |
|
307 * All rights reserved.\n\ |
|
308 * This component and the accompanying materials are made available\n\ |
|
309 * under the terms of \"Eclipse Public License v1.0\"\n\ |
|
310 * which accompanies this distribution, and is available\n\ |
|
311 * at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n\ |
|
312 *\n\ |
|
313 * Initial Contributors:\n\ |
|
314 * Nokia Corporation - initial contribution.\n\ |
|
315 *\n\ |
|
316 * Contributors:\n\ |
|
317 *\n\ |
|
318 * Description:\n\ |
|
319 *\n\ |
|
320 */\n\n\ |
|
321 // This header file contains the customisation implementation identity for $INSTNAME\n\ |
|
322 // It was generated by:\n\ |
|
323 // $CMDLINE\n\ |
|
324 // This file may be manually modified.\n\ |
|
325 \n\ |
|
326 #ifndef $INSTGUARDRH\n\ |
|
327 #define $INSTGUARDRH\n\ |
|
328 #include \"$CDLINCNAME.common.hrh\"\n\ |
|
329 $DLLINSTHEADER\ |
|
330 \n\ |
|
331 #define _CDL_$INSTNS_KCdlInstanceInterfaceUidValue _CDL_$CDLNS_KCdlInterfaceUidValue\n\ |
|
332 #define _CDL_$INSTNS_KCdlInstanceId $INSTID\n\ |
|
333 \n\ |
|
334 #endif // $INSTGUARDRH\n"; |
|
335 |
|
336 void CCdlTkWriteInstance::ProcessInstanceHrh(ofstream& aStream, const string& aFileName) const |
|
337 { |
|
338 aStream << CdlTkUtil::MultiReplace(iReplace, KInstanceHrh); |
|
339 } |
|
340 |
|
341 } // end of namespace CdlCompilerToolkit |