|
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 #ifndef CDLTKPROCESS_H |
|
18 #define CDLTKPROCESS_H |
|
19 |
|
20 #include <CdlCompilerToolkit/CdlTkInterface.h> |
|
21 #include <CdlCompilerToolkit/CdlTkInstance.h> |
|
22 #include <fstream> |
|
23 |
|
24 namespace CdlCompilerToolkit { |
|
25 |
|
26 /** |
|
27 * CCdlTkProcess |
|
28 * Does very little yet. |
|
29 */ |
|
30 class CCdlTkProcess |
|
31 { |
|
32 public: |
|
33 /** |
|
34 * destructor |
|
35 */ |
|
36 virtual ~CCdlTkProcess(); |
|
37 /** |
|
38 * virtual method to invoke processing |
|
39 */ |
|
40 virtual void Process() = 0; |
|
41 |
|
42 public: |
|
43 static std::string CdlBaseNameAndPath(const CCdlTkInterface& aCdl); |
|
44 static void AssertInterfaceNotExtended(const CCdlTkInterface& aCdl); |
|
45 }; |
|
46 |
|
47 |
|
48 /** |
|
49 * Base class for processes that write source files |
|
50 */ |
|
51 class CCdlTkSourceFileWriter : public CCdlTkProcess |
|
52 { |
|
53 public: |
|
54 /** |
|
55 * destructor |
|
56 */ |
|
57 ~CCdlTkSourceFileWriter(); |
|
58 |
|
59 protected: |
|
60 /** |
|
61 * Writes an opening namespace declaration for a CDL interface to a stream |
|
62 * @param aCdl the CDL interface defining the namespace |
|
63 * @param aStream the stream to write to |
|
64 */ |
|
65 void WriteNamespaceStart(const CCdlTkInterface& aCdl, std::ofstream& aStream) const; |
|
66 /** |
|
67 * Writes a closing namespace declaration for a CDL interface to a stream |
|
68 * @param aCdl the CDL interface defining the namespace |
|
69 * @param aStream the stream to write to |
|
70 */ |
|
71 void WriteNamespaceEnd(const CCdlTkInterface& aCdl, std::ofstream& aStream) const; |
|
72 /** |
|
73 * Calculates a header guard identifier for a file |
|
74 * @param aFileName the file to be protected by the header guard |
|
75 * @return the header guard identifer |
|
76 */ |
|
77 std::string HeaderGuardName(const std::string& aFileName) const; |
|
78 /** |
|
79 * Writes the starting declarations for a header file guard |
|
80 * @param aName the file to be protected by the header guard |
|
81 * @param aStream the stream to write to |
|
82 * @return |
|
83 */ |
|
84 void WriteHeaderGuardStart(const std::string& aName, std::ofstream& aStream) const; |
|
85 /** |
|
86 * Writes the ending declaration for a header file guard |
|
87 * @param aName the file to be protected by the header guard |
|
88 * @param aStream the stream to write to |
|
89 * @return |
|
90 */ |
|
91 void WriteHeaderGuardEnd(const std::string& aName, std::ofstream& aStream) const; |
|
92 }; |
|
93 |
|
94 |
|
95 /** |
|
96 * Process for writing a common definitions header file (.cdl.common.h) |
|
97 */ |
|
98 class CCdlTkWriteCommonDefs : public CCdlTkSourceFileWriter |
|
99 { |
|
100 public: |
|
101 static void ExportCommonDefs(const CCdlTkInterface& aCdl, const std::string& aFileName); |
|
102 |
|
103 private: |
|
104 /** |
|
105 * constructor |
|
106 * @param aCdl the interface to write. |
|
107 * @param aStream the stream to write to |
|
108 */ |
|
109 CCdlTkWriteCommonDefs(const CCdlTkInterface& aCdl, std::ofstream& aStream, const std::string& aFileName); |
|
110 /** |
|
111 * Creates and writes a common definitions header file (.cdl.common.h) |
|
112 */ |
|
113 void Process(); |
|
114 void ProcessHRH(std::ofstream& aStream); |
|
115 |
|
116 private: |
|
117 void WriteApiEnum(); |
|
118 void WriteApiTypedefs(); |
|
119 std::string TypedefForApi(const CCdlTkApi& aApi) const; |
|
120 std::ofstream& Stream(); |
|
121 |
|
122 private: |
|
123 const CCdlTkInterface& iCdl; |
|
124 std::ofstream* iStream; |
|
125 const std::string& iFileName; |
|
126 }; |
|
127 |
|
128 |
|
129 /** |
|
130 * Process for writing a C++ client header file for a C++ interface |
|
131 */ |
|
132 class CCdlTkWriteClientHeader : public CCdlTkSourceFileWriter |
|
133 { |
|
134 public: |
|
135 /** |
|
136 * constructor |
|
137 * @param aCdl The interface to write |
|
138 */ |
|
139 CCdlTkWriteClientHeader(const CCdlTkInterface& aCdl); |
|
140 /** |
|
141 * destructor |
|
142 */ |
|
143 ~CCdlTkWriteClientHeader(); |
|
144 /** |
|
145 * Creates and writes the header files required by a C++ client to use |
|
146 * a CDL interface. |
|
147 */ |
|
148 void Process(); |
|
149 |
|
150 protected: |
|
151 std::string ClientReturnType(const CCdlTkApi& aApi) const; |
|
152 |
|
153 private: |
|
154 void ProcessApi(std::ofstream& aStream, const std::string& aFileName) const; |
|
155 void WriteApi(const CCdlTkApi& aApi, std::ofstream& aStream, bool aCInstanceMember, const std::string& aIndent) const; |
|
156 |
|
157 protected: |
|
158 const CCdlTkInterface& iCdl; |
|
159 }; |
|
160 |
|
161 |
|
162 /** |
|
163 * Process for syntax checking a CDL interface |
|
164 */ |
|
165 class CCdlTkSyntaxCheck : public CCdlTkWriteClientHeader |
|
166 { |
|
167 /** |
|
168 * constructor |
|
169 * @param aCdl the interface to check |
|
170 */ |
|
171 CCdlTkSyntaxCheck(const CCdlTkInterface& aCdl); |
|
172 /** |
|
173 * destructor |
|
174 */ |
|
175 ~CCdlTkSyntaxCheck(); |
|
176 /** |
|
177 * Sets parameters to pass to the C++ compiler which will do the syntax check |
|
178 * @param aParams the parameters for the compiler |
|
179 */ |
|
180 void SetParams(std::string aParams); |
|
181 /** |
|
182 * Runs the syntax checking process |
|
183 */ |
|
184 void Process(); |
|
185 |
|
186 private: // syntax checking |
|
187 void WriteSyntaxCheckCpp(std::string aName) const; |
|
188 void DoSyntaxCheckBuild(std::string aName) const; |
|
189 void WriteSyntaxCheckApi(const CCdlTkApi& aApi, std::ofstream& aStream) const; |
|
190 |
|
191 private: |
|
192 std::string iParams; |
|
193 }; |
|
194 |
|
195 |
|
196 /** |
|
197 * A process for writing a customisation instance to C++ source files |
|
198 */ |
|
199 class CCdlTkWriteInstance : public CCdlTkSourceFileWriter |
|
200 { |
|
201 public: |
|
202 /** |
|
203 * constructor |
|
204 * @param aInstance The instance to write |
|
205 */ |
|
206 CCdlTkWriteInstance(const CCdlTkInstance& aInstance); |
|
207 /** |
|
208 * destructor |
|
209 */ |
|
210 ~CCdlTkWriteInstance(); |
|
211 /** |
|
212 * Run the process of creating and writing the C++ source files for a |
|
213 * customisation instance. |
|
214 */ |
|
215 void Process(); |
|
216 |
|
217 private: |
|
218 void ProcessCdl() const; |
|
219 void ProcessInstanceApi(std::ofstream& aStream, const std::string& aFileName) const; |
|
220 void ProcessInstance(std::ofstream& aStream, const std::string& aHeaderName) const; |
|
221 void ProcessInstanceHeader(std::ofstream& aStream, const std::string& aFileName) const; |
|
222 void ProcessInstanceHrh(std::ofstream& aStream, const std::string& aFileName) const; |
|
223 void InitReplace(const std::string& aHeaderName); |
|
224 |
|
225 private: |
|
226 const CCdlTkInstance& iInstance; |
|
227 const CCdlTkInterface& iCdl; |
|
228 CdlTkUtil::CReplaceSet iReplace; |
|
229 }; |
|
230 |
|
231 |
|
232 /** |
|
233 * A process to write the source and build files for a DLL |
|
234 */ |
|
235 class CCdlTkWriteDll : public CCdlTkSourceFileWriter |
|
236 { |
|
237 public: |
|
238 /** |
|
239 * constructor |
|
240 * @param aDll the DLL to create source and build files for |
|
241 */ |
|
242 CCdlTkWriteDll(const CCdlTkDll& aDll); |
|
243 /** |
|
244 * destructor |
|
245 */ |
|
246 ~CCdlTkWriteDll(); |
|
247 /** |
|
248 * Runs the process of creating and writing source and build files for a DLL |
|
249 */ |
|
250 void Process(); |
|
251 |
|
252 private: |
|
253 void WriteBldInf() const; |
|
254 void WriteMmp() const; |
|
255 void WriteMainCpp() const; |
|
256 void WriteInstanceIdHeader() const; |
|
257 void WriteEcomRss() const; |
|
258 void WriteEcomDetailRss() const; |
|
259 |
|
260 private: |
|
261 const CCdlTkDll& iDll; |
|
262 }; |
|
263 |
|
264 |
|
265 /** |
|
266 * Process for writing a CDL file |
|
267 */ |
|
268 class CCdlTkWriteCdlFile : public CCdlTkProcess |
|
269 { |
|
270 public: |
|
271 /** |
|
272 * constructor |
|
273 * @param aCdl the CDL interface to write |
|
274 */ |
|
275 CCdlTkWriteCdlFile(const CCdlTkInterface& aCdl); |
|
276 /** |
|
277 * destructor |
|
278 */ |
|
279 ~CCdlTkWriteCdlFile(); |
|
280 /** |
|
281 * Run the process of writing the CDL interface to a CDL file |
|
282 */ |
|
283 void Process(); |
|
284 |
|
285 private: |
|
286 void WriteHeaderComment(); |
|
287 void WriteHeader(); |
|
288 void WriteSeparator(const std::string& aSection); |
|
289 void WriteCpp(); |
|
290 void WriteTranslation(); |
|
291 void WriteApi(); |
|
292 |
|
293 private: |
|
294 const CCdlTkInterface* iCdl; |
|
295 std::ofstream iOut; |
|
296 }; |
|
297 |
|
298 |
|
299 /** |
|
300 * A process for reading a CDL file |
|
301 */ |
|
302 class CCdlTkCdlFileParser : public CCdlTkProcess |
|
303 { |
|
304 public: |
|
305 /** |
|
306 * constructor |
|
307 * @param aFileName the name of the CDL file to be read |
|
308 * @return |
|
309 */ |
|
310 CCdlTkCdlFileParser(const std::string& aFileName); |
|
311 /** |
|
312 * destructor |
|
313 */ |
|
314 ~CCdlTkCdlFileParser(); |
|
315 /** |
|
316 * Loads and parses a CDL file |
|
317 * @param aMergeExtensions tells the parser whether to merge and interface |
|
318 * extensions to form a monolithic API |
|
319 * @return an auto pointer to the CDL interface read from the CDL file |
|
320 */ |
|
321 std::auto_ptr<CCdlTkInterface> LoadAndParse(bool aMergeExtensions); |
|
322 /** |
|
323 * virtual Process method from CCdlTkProcess |
|
324 * this function is not to be used |
|
325 */ |
|
326 void Process(); |
|
327 |
|
328 private: |
|
329 enum TParseState {EHeader, ECpp, ETranslation, EApi, EEnd, EParseStateCount}; |
|
330 |
|
331 private: |
|
332 void OpenStream(); |
|
333 void ParseStream(CCdlTkInterface& aCdl); |
|
334 void CloseStream(); |
|
335 |
|
336 void ParseHeader(CCdlTkInterface& aCdl, const std::string& aLine); |
|
337 void ParseCpp(CCdlTkInterface& aCdl, const std::string& aLine); |
|
338 void ParseTranslationLine(CCdlTkInterface& aCdl, const std::string& aLine); |
|
339 void ParseApi(CCdlTkInterface& aCdl, const std::string& aLine); |
|
340 std::auto_ptr<CCdlTkApi> CreateApi(CCdlTkInterface& aCdl, std::string& aLine); |
|
341 void ParseApiParams(CCdlTkApiParams& aParams, std::string& aList); |
|
342 void ParseNameTypeAndDefaultValue(std::string& aStr, std::string& aName, std::string& aType, std::string& aDefaultValue); |
|
343 void ParseTranslationText(CCdlTkDataTypeTranslation& aTrans, std::string& aLine); |
|
344 |
|
345 std::string GetLine(); |
|
346 bool IsSectionBoundary(const std::string& aLine, TParseState& aState); |
|
347 bool MatchLineStart(const std::string& aLine, const std::string& aHeader, std::string& aVal); |
|
348 void StripComments(std::string& aStr, std::string& aComment); |
|
349 |
|
350 void SyntaxError(const std::string& aErr); |
|
351 |
|
352 private: |
|
353 std::string iFileName; |
|
354 std::ifstream iIn; |
|
355 TParseState iState; |
|
356 int iCurrentSourceLineNum; |
|
357 std::string iApiBuf; // buffer for collecting API declarations |
|
358 std::string iComment; // buffer for collecting comments |
|
359 }; |
|
360 |
|
361 |
|
362 /** |
|
363 * Observer mixin interface for the interface checking process |
|
364 */ |
|
365 class MCdlTkApiCheckObserver |
|
366 { |
|
367 public: |
|
368 /** |
|
369 * Called when an interface check is started |
|
370 */ |
|
371 virtual void StartCheck() = 0; |
|
372 /** |
|
373 * Called when an interface check is complete |
|
374 */ |
|
375 virtual void CheckComplete() = 0; |
|
376 /** |
|
377 * Called when an API is found that appears in both interfaces |
|
378 */ |
|
379 virtual void ApiInBoth(const CCdlTkApi& aApi) = 0; |
|
380 /** |
|
381 * Called when an API is found that is only in the right hand interface |
|
382 */ |
|
383 virtual void ApiNotInLeft(const CCdlTkApi& aApi) = 0; |
|
384 /** |
|
385 * Called when an API is found that is only in the left hand interface |
|
386 */ |
|
387 virtual void ApiNotInRight(const CCdlTkApi& aApi) = 0; |
|
388 }; |
|
389 |
|
390 /** |
|
391 * process for checking (diffing) two CDL interfaces' APIs |
|
392 */ |
|
393 class CCdlTkApiChecker : public CCdlTkProcess |
|
394 { |
|
395 public: |
|
396 /** |
|
397 * constructor |
|
398 * @param aLeft a CDL interface to check |
|
399 * @param aRight another CDL interface to check |
|
400 * @param aObserver the observer of the results of the check |
|
401 */ |
|
402 CCdlTkApiChecker(const CCdlTkInterface& aLeft, |
|
403 const CCdlTkInterface& aRight, |
|
404 MCdlTkApiCheckObserver& aObserver); |
|
405 /** |
|
406 * destructor |
|
407 */ |
|
408 ~CCdlTkApiChecker(); |
|
409 /** |
|
410 * Run the process of checking the interfaces' APIs |
|
411 */ |
|
412 void Process(); |
|
413 |
|
414 private: |
|
415 typedef CCdlTkApiList::const_iterator CApiListIter; |
|
416 void FailLeft(CApiListIter& aFrom, const CApiListIter& aTo) const; |
|
417 void FailRight(CApiListIter& aFrom, const CApiListIter& aTo) const; |
|
418 void ReSync(CApiListIter& posLeft, CApiListIter& posRight, |
|
419 const CApiListIter& leftEnd, const CApiListIter& rightEnd) const; |
|
420 |
|
421 private: |
|
422 const CCdlTkInterface& iLeft; |
|
423 const CCdlTkInterface& iRight; |
|
424 MCdlTkApiCheckObserver& iObserver; |
|
425 }; |
|
426 |
|
427 } // end of namespace CdlCompilerToolkit |
|
428 |
|
429 #endif |