|
1 /* |
|
2 * Copyright (c) 2006 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 */ |
|
18 |
|
19 |
|
20 #include "MLCompDataLayPerfWriter.h" |
|
21 #include "MLCompData2Cdl.h" // for static methods |
|
22 #include "LayoutCompilerErr.h" |
|
23 #include "CodeGenConsts.h" |
|
24 |
|
25 #include <cdlcompilertoolkit/cdltkinterface.h> |
|
26 #include <cdlcompilertoolkit/cdltkutil.h> |
|
27 |
|
28 #include <iostream> |
|
29 #include <sstream> |
|
30 #include <set> |
|
31 #include <fstream> |
|
32 #include <algorithm> |
|
33 |
|
34 using namespace std; |
|
35 using namespace CdlCompilerToolkit; |
|
36 |
|
37 const string KComma = ","; |
|
38 const string KSpace = " "; |
|
39 const string KMacroNameRoot = "LAYOUT_TEST"; |
|
40 const string KMacroNameWindow = "_WINDOW"; |
|
41 const string KMacroNameText = "_TEXT"; |
|
42 const string KMacroNameComponent = "_COMPONENT"; |
|
43 const string KMacroNameParams = "_PARAMS"; |
|
44 |
|
45 // |
|
46 // TMLCompDataLayPerfTableWriter |
|
47 // |
|
48 |
|
49 TMLCompDataLayPerfTableWriter::TMLCompDataLayPerfTableWriter(TMLCompDataLayPerfWriter* aParent, TMLCompDataTable& aTable, string& aInterfaceName, int aTableId) |
|
50 : |
|
51 iParent(aParent), |
|
52 iTable(aTable), |
|
53 iInterfaceName(aInterfaceName), |
|
54 iTableId(aTableId) |
|
55 { |
|
56 } |
|
57 |
|
58 TMLCompDataLayPerfTableWriter::~TMLCompDataLayPerfTableWriter() |
|
59 { |
|
60 } |
|
61 |
|
62 void TMLCompDataLayPerfTableWriter::Write(ostream& out) |
|
63 { |
|
64 WriteTable(out); |
|
65 } |
|
66 |
|
67 |
|
68 const string KTestAPITableFuntionSig = "\ |
|
69 testLayout_$LAYOUT_$TABLEID()"; |
|
70 |
|
71 string GenerateMLFunctionName(string aInterfaceName, int aTableId) |
|
72 { |
|
73 string tableNum = CdlTkUtil::IntToString(aTableId); |
|
74 |
|
75 CdlTkUtil::CReplaceSet rep; |
|
76 rep.Add("$LAYOUT", aInterfaceName); |
|
77 rep.Add("$TABLEID", tableNum); |
|
78 return CdlTkUtil::MultiReplace(rep, KTestAPITableFuntionSig); |
|
79 } |
|
80 |
|
81 void TMLCompDataLayPerfTableWriter::WriteTable(ostream& out) |
|
82 { |
|
83 out << "void " << GenerateMLFunctionName(iInterfaceName, iTableId) << endl; |
|
84 |
|
85 out << "{" << endl; // start of function |
|
86 out << "DECLARE_LOCAL_VARS_COUNTS" << endl; |
|
87 |
|
88 out << "\n// Layout MACROs for Layout Table : "; |
|
89 out << iTable.Name() << endl; |
|
90 |
|
91 for (int i=0; i<iTable.size(); ++i) |
|
92 { |
|
93 WriteLine(out, *iTable[i]); |
|
94 } |
|
95 |
|
96 out << endl; |
|
97 out << "}\n" << endl; // end of function |
|
98 } |
|
99 |
|
100 void TMLCompDataLayPerfTableWriter::WriteLine(ostream& out, TMLCompDataLine& aLine) |
|
101 { |
|
102 string macroName = BuildMacroName(aLine); |
|
103 string apiName = BuildApiName(aLine); |
|
104 string params = BuildParams(aLine); |
|
105 string paramLimitParams = BuildParamLimitParams(aLine); |
|
106 |
|
107 out << macroName << "( "; |
|
108 |
|
109 if(aLine.NeedsParams()) |
|
110 { |
|
111 out << apiName << KFuncParamLimitsSuffix << "(" << paramLimitParams << ")"; |
|
112 out << ", "; |
|
113 } |
|
114 |
|
115 out << apiName << "(" << params << ")"; |
|
116 out << " )" << endl; // this ends the macro call |
|
117 out << endl; |
|
118 } |
|
119 |
|
120 string TMLCompDataLayPerfTableWriter::BuildMacroName(TMLCompDataLine& aLine) |
|
121 { |
|
122 string macroName = KMacroNameRoot; |
|
123 macroName += (aLine.iType == TMLCompDataLine::ETextComponent) ? KMacroNameText : KMacroNameWindow; |
|
124 macroName += KMacroNameComponent; |
|
125 if(aLine.NeedsParams()) |
|
126 macroName += KMacroNameParams; |
|
127 return macroName; |
|
128 } |
|
129 |
|
130 string TMLCompDataLayPerfTableWriter::BuildApiName(TMLCompDataLine& aLine) |
|
131 { |
|
132 string apiName = iInterfaceName; |
|
133 apiName += string("::"); |
|
134 apiName += MLCompDataToCdl::LineApiName(aLine); |
|
135 return apiName; |
|
136 } |
|
137 |
|
138 string TMLCompDataLayPerfTableWriter::BuildParams(TMLCompDataLine& aLine) |
|
139 { |
|
140 string paramsString; |
|
141 string name = aLine.Name(); |
|
142 |
|
143 // add the params in the order of the CDL interface |
|
144 CCdlTkApi* api = iParent->iInterface.ApiList().Find(name); |
|
145 if(!api) |
|
146 throw NotFoundErr(name + " in interface " + iParent->iInterface.FileName()); |
|
147 CCdlTkFunctionApi* funcApi = static_cast<CCdlTkFunctionApi*>(api); |
|
148 CCdlTkApiParams& params = funcApi->Params(); |
|
149 bool first = true; |
|
150 for(CCdlTkApiParams::iterator pParam = params.begin(); pParam != params.end(); ++pParam) |
|
151 { |
|
152 if(!first) |
|
153 { |
|
154 paramsString.append(KComma); |
|
155 paramsString.append(KSpace); |
|
156 } |
|
157 paramsString.append(pParam->Name()); |
|
158 first = false; |
|
159 } |
|
160 return paramsString; |
|
161 } |
|
162 |
|
163 string TMLCompDataLayPerfTableWriter::BuildParamLimitParams(TMLCompDataLine& aLine) |
|
164 { |
|
165 string paramsString; |
|
166 string name = aLine.Name(); |
|
167 |
|
168 CCdlTkApi* api = iParent->iInterface.ApiList().Find(name); |
|
169 if(!api) |
|
170 throw NotFoundErr(name + " in interface " + iParent->iInterface.FileName()); |
|
171 CCdlTkFunctionApi* funcApi = static_cast<CCdlTkFunctionApi*>(api); |
|
172 CCdlTkApiParams& params = funcApi->Params(); |
|
173 |
|
174 CCdlTkApiParams::iterator pParam = params.FindByName(KParamOptionIndex); |
|
175 if(pParam != params.end() && aLine.NeedsOptions()) |
|
176 { |
|
177 paramsString.append(pParam->Name()); |
|
178 } |
|
179 |
|
180 return paramsString; |
|
181 } |
|
182 |
|
183 |
|
184 // |
|
185 // TMLCompDataLayPerfWriter |
|
186 // |
|
187 |
|
188 TMLCompDataLayPerfWriter::TMLCompDataLayPerfWriter(CCdlTkInterface& aInterface, TMLCompData& aLayout, const std::string& aName) |
|
189 : |
|
190 iInterface(aInterface), |
|
191 TMLWriterBase<TMLCompData>(aLayout, aName) |
|
192 { |
|
193 } |
|
194 |
|
195 void TMLCompDataLayPerfWriter::Write(const std::string& aCdlName) |
|
196 { |
|
197 ofstream out(iName.c_str()); |
|
198 |
|
199 cout << "writing layout " << iName << endl; |
|
200 string cdlFileName(CdlTkUtil::StripPath(aCdlName)); |
|
201 string ifName(iInterface.Header().Name()); |
|
202 |
|
203 out << "// function implementations: " << endl; |
|
204 int tableId = 0; |
|
205 for (TMLCompData::iterator pTab = iLayout.begin(); pTab != iLayout.end(); ++pTab) |
|
206 { |
|
207 TMLCompDataLayPerfTableWriter writer(this, **pTab, ifName, tableId++); |
|
208 writer.Write(out); |
|
209 } |
|
210 |
|
211 out << "void testLayout_" << ifName << "()\n{" << endl; |
|
212 tableId = 0; |
|
213 for(;tableId < iLayout.size(); tableId++) |
|
214 { |
|
215 out << GenerateMLFunctionName(ifName, tableId) << ";" << endl; |
|
216 } |
|
217 out << "}\n" << endl; |
|
218 |
|
219 out.close(); |
|
220 } |
|
221 |
|
222 // End of File |