|
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 #include "CdlCompilerToolkit/CdlTkProcess.h" |
|
18 #include "CdlTkPriv.h" |
|
19 #include <fstream> |
|
20 #include <iomanip> |
|
21 #include <direct.h> |
|
22 #include <iostream> |
|
23 using namespace std; |
|
24 |
|
25 namespace CdlCompilerToolkit { |
|
26 |
|
27 // |
|
28 // CppSyntaxErr |
|
29 // |
|
30 |
|
31 class CppSyntaxErr : public CdlCompilerToolkitErr |
|
32 { |
|
33 public: |
|
34 CppSyntaxErr(int aErr); |
|
35 void Show(ostream& aStream) const; |
|
36 private: |
|
37 int iErr; |
|
38 }; |
|
39 |
|
40 CppSyntaxErr::CppSyntaxErr(int aErr) |
|
41 : iErr(aErr) |
|
42 { |
|
43 } |
|
44 |
|
45 void CppSyntaxErr::Show(ostream& aStream) const |
|
46 { |
|
47 aStream << "CDL C++ Syntax check failed. Cpp returned " << iErr << endl; |
|
48 } |
|
49 |
|
50 |
|
51 // |
|
52 // CCdlTkSyntaxCheck |
|
53 // |
|
54 |
|
55 CCdlTkSyntaxCheck::CCdlTkSyntaxCheck(const CCdlTkInterface& aCdl) |
|
56 : CCdlTkWriteClientHeader(aCdl) |
|
57 { |
|
58 } |
|
59 |
|
60 CCdlTkSyntaxCheck::~CCdlTkSyntaxCheck() |
|
61 { |
|
62 } |
|
63 |
|
64 void CCdlTkSyntaxCheck::Process() |
|
65 { |
|
66 AssertInterfaceNotExtended(iCdl); |
|
67 string name = iCdl.FileName() + ".tempCdlSyntaxCheck"; |
|
68 |
|
69 // these will automatically delete the files when the function returns |
|
70 CCdlTkFileCleanup cppClean(name + ".cpp"); |
|
71 CCdlTkFileCleanup objClean(name + ".s"); |
|
72 |
|
73 WriteSyntaxCheckCpp(name + ".cpp"); |
|
74 DoSyntaxCheckBuild(name + ".cpp"); |
|
75 } |
|
76 |
|
77 void CCdlTkSyntaxCheck::WriteSyntaxCheckCpp(string aName) const |
|
78 { |
|
79 ofstream out; |
|
80 CdlTkUtil::OpenOutput(out, aName); |
|
81 |
|
82 out << "#line 1 \"" << CdlTkUtil::StripPath(iCdl.FileName()) << "\"" << endl; |
|
83 out << "#include <cdlengine.h>" << endl; |
|
84 const CCdlTkCpp& cpp = iCdl.Cpp(); |
|
85 for (CCdlTkCpp::const_iterator pCpp = cpp.begin(); pCpp != cpp.end(); ++pCpp) |
|
86 { |
|
87 out << *pCpp << endl; |
|
88 } |
|
89 WriteNamespaceStart(iCdl, out); |
|
90 for (CCdlTkApiList::const_iterator pApi = iCdl.ApiList().begin(); pApi != iCdl.ApiList().end(); ++pApi) |
|
91 WriteSyntaxCheckApi(**pApi, out); |
|
92 WriteNamespaceEnd(iCdl, out); |
|
93 out << "GLDEF_C TInt E32Dll(TDllReason /*aReason*/)" << endl; |
|
94 out << "\t{" << endl; |
|
95 out << "\treturn(KErrNone);" << endl; |
|
96 out << "\t}" << endl; |
|
97 |
|
98 out.close(); |
|
99 } |
|
100 |
|
101 void CCdlTkSyntaxCheck::DoSyntaxCheckBuild(string aName) const |
|
102 { |
|
103 string s = "gcc "; |
|
104 if (!iParams.empty()) |
|
105 { |
|
106 s += "\""; |
|
107 s += iParams; |
|
108 s += "\" "; |
|
109 } |
|
110 s += "-Wp,-DNDEBUG,-D_UNICODE,-D__SYMBIAN32__,-D__GCC32__,-D__EPOC32__,-D__MARM__,-D__MARM_ARMI__,-D__DLL__,-I"; |
|
111 s += CdlTkUtil::CurrentDrive(); // drive |
|
112 s += "\\epoc32\\include -S -xc++ "; |
|
113 s += CdlTkUtil::CurrentDrive(); // drive |
|
114 s += aName; |
|
115 int err = system(s.c_str()); |
|
116 if (err) |
|
117 throw CppSyntaxErr(err); |
|
118 } |
|
119 |
|
120 void CCdlTkSyntaxCheck::WriteSyntaxCheckApi(const CCdlTkApi& aApi, ofstream& aStream) const |
|
121 { |
|
122 aStream << "#line " << setbase(10) << aApi.SourceFileLineNum() << endl; |
|
123 aStream << ClientReturnType(aApi) << " " << aApi.Name() << aApi.ParamsTypeAndNameList() << ";" << endl; |
|
124 } |
|
125 |
|
126 void CCdlTkSyntaxCheck::SetParams(string aParams) |
|
127 { |
|
128 iParams = aParams; |
|
129 } |
|
130 |
|
131 } // end of namespace CdlCompilerToolkit |