]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfGuidPpiProtocolSectionParser.py
Sync BaseTool trunk (version r2599) into EDKII BaseTools.
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Parser / InfGuidPpiProtocolSectionParser.py
CommitLineData
4234283c
LG
1## @file\r
2# This file contained the parser for [Guids], [Ppis], [Protocols] sections in INF file \r
3#\r
4# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# This program and the accompanying materials are licensed and made available \r
7# under the terms and conditions of the BSD License which accompanies this \r
8# distribution. The full text of the license may be found at \r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14'''\r
15InfGuidPpiProtocolSectionParser\r
16'''\r
17##\r
18# Import Modules\r
19#\r
20\r
21import Logger.Log as Logger\r
22from Logger import StringTable as ST\r
23from Logger.ToolError import FORMAT_INVALID\r
24from Parser.InfParserMisc import InfExpandMacro\r
25from Library import DataType as DT\r
26from Library import GlobalData\r
27from Library.Parsing import MacroParser\r
28from Library.Misc import GetSplitValueList\r
29from Library.ParserValidate import IsValidIdString\r
30from Library.ParserValidate import IsValidUserId\r
31from Library.ParserValidate import IsValidArch\r
32from Parser.InfParserMisc import InfParserSectionRoot\r
33\r
34class InfGuidPpiProtocolSectionParser(InfParserSectionRoot):\r
35 ## InfGuidParser\r
36 #\r
37 #\r
38 def InfGuidParser(self, SectionString, InfSectionObject, FileName):\r
39 #\r
40 # Macro defined in this section \r
41 #\r
42 SectionMacros = {}\r
43 ValueList = []\r
44 GuidList = []\r
45 CommentsList = []\r
46 CurrentLineVar = None\r
47 #\r
48 # Parse section content\r
49 #\r
50 for Line in SectionString:\r
51 LineContent = Line[0]\r
52 LineNo = Line[1]\r
53\r
54 if LineContent.strip() == '':\r
55 CommentsList = []\r
56 continue\r
57\r
58 if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
59 CommentsList.append(Line)\r
60 continue\r
61 else:\r
62 #\r
63 # Encounter a GUID entry\r
64 #\r
65 if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
66 CommentsList.append((\r
67 LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):],\r
68 LineNo))\r
69 LineContent = \\r
70 LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]\r
71\r
72 if LineContent != '':\r
73 #\r
74 # Find Macro\r
75 #\r
76 Name, Value = MacroParser((LineContent, LineNo),\r
77 FileName,\r
78 DT.MODEL_EFI_GUID,\r
79 self.FileLocalMacros)\r
80 if Name != None:\r
81 SectionMacros[Name] = Value\r
82 CommentsList = []\r
83 ValueList = []\r
84 continue\r
85\r
86 TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)\r
87 ValueList[0:len(TokenList)] = TokenList\r
88\r
89 #\r
90 # Replace with Local section Macro and [Defines] section Macro.\r
91 # \r
92 ValueList = [InfExpandMacro(Value, (FileName, LineContent, LineNo),\r
93 self.FileLocalMacros, SectionMacros, True)\r
94 for Value in ValueList]\r
95\r
96 CurrentLineVar = (LineContent, LineNo, FileName)\r
97\r
98\r
99 if len(ValueList) >= 1:\r
100 GuidList.append((ValueList, CommentsList, CurrentLineVar))\r
101 CommentsList = []\r
102 ValueList = []\r
103 continue\r
104\r
105 #\r
106 # Current section archs\r
107 # \r
108 ArchList = []\r
109 LineIndex = -1\r
110 for Item in self.LastSectionHeaderContent:\r
111 LineIndex = Item[3]\r
112 if Item[1] not in ArchList:\r
113 ArchList.append(Item[1])\r
114\r
115 if not InfSectionObject.SetGuid(GuidList, Arch=ArchList):\r
116 Logger.Error('InfParser',\r
117 FORMAT_INVALID,\r
118 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Guid]"),\r
119 File=FileName,\r
120 Line=LineIndex)\r
121\r
122 ## InfPpiParser\r
123 #\r
124 #\r
125 def InfPpiParser(self, SectionString, InfSectionObject, FileName):\r
126 #\r
127 # Macro defined in this section \r
128 #\r
129 SectionMacros = {}\r
130 ValueList = []\r
131 PpiList = []\r
132 CommentsList = []\r
133 CurrentLineVar = None\r
134 #\r
135 # Parse section content\r
136 #\r
137 for Line in SectionString:\r
138 LineContent = Line[0]\r
139 LineNo = Line[1]\r
140\r
141 if LineContent.strip() == '':\r
142 CommentsList = []\r
143 continue\r
144\r
145 if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
146 CommentsList.append(Line)\r
147 continue\r
148 else:\r
149 #\r
150 # Encounter a PPI entry\r
151 #\r
152 if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
153 CommentsList.append((\r
154 LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):],\r
155 LineNo))\r
156 LineContent = \\r
157 LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]\r
158\r
159 if LineContent != '':\r
160 #\r
161 # Find Macro\r
162 #\r
163 Name, Value = MacroParser((LineContent, LineNo),\r
164 FileName,\r
165 DT.MODEL_EFI_PPI,\r
166 self.FileLocalMacros)\r
167 if Name != None:\r
168 SectionMacros[Name] = Value\r
169 ValueList = []\r
170 CommentsList = []\r
171 continue\r
172\r
173 TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)\r
174 ValueList[0:len(TokenList)] = TokenList\r
175\r
176 #\r
177 # Replace with Local section Macro and [Defines] section Macro.\r
178 # \r
179 ValueList = [InfExpandMacro(Value, (FileName, LineContent, LineNo), self.FileLocalMacros, SectionMacros)\r
180 for Value in ValueList]\r
181\r
182 CurrentLineVar = (LineContent, LineNo, FileName)\r
183\r
184 if len(ValueList) >= 1:\r
185 PpiList.append((ValueList, CommentsList, CurrentLineVar))\r
186 ValueList = []\r
187 CommentsList = []\r
188 continue\r
189\r
190 #\r
191 # Current section archs\r
192 # \r
193 ArchList = []\r
194 LineIndex = -1\r
195 for Item in self.LastSectionHeaderContent:\r
196 LineIndex = Item[3]\r
197 if Item[1] not in ArchList:\r
198 ArchList.append(Item[1])\r
199\r
200 if not InfSectionObject.SetPpi(PpiList, Arch=ArchList):\r
201 Logger.Error('InfParser',\r
202 FORMAT_INVALID,\r
203 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Ppis]"),\r
204 File=FileName,\r
205 Line=LineIndex)\r
206\r
207 ## InfUserExtensionParser\r
208 #\r
209 # \r
210 def InfUserExtensionParser(self, SectionString, InfSectionObject, FileName):\r
211\r
212 UserExtensionContent = ''\r
213\r
214 #\r
215 # Parse section content\r
216 #\r
217 for Line in SectionString:\r
218 LineContent = Line[0]\r
219 LineNo = Line[1]\r
220\r
221 if LineContent.strip() == '':\r
222 continue\r
223 #\r
224 # Replace with [Defines] section Macro\r
225 #\r
226 LineContent = InfExpandMacro(LineContent,\r
227 (FileName, LineContent, LineNo),\r
228 self.FileLocalMacros,\r
229 None)\r
230\r
231 UserExtensionContent += LineContent + DT.END_OF_LINE\r
232\r
233 continue\r
234\r
235 #\r
236 # Current section UserId, IdString\r
237 # \r
238 IdContentList = []\r
239 LastItem = ''\r
240 SectionLineNo = None\r
241 for Item in self.LastSectionHeaderContent:\r
242 UserId = Item[1]\r
243 IdString = Item[2]\r
244 Arch = Item[3]\r
245 SectionLineNo = Item[4]\r
246 if not IsValidArch(Arch):\r
247 Logger.Error(\r
248 'InfParser',\r
249 FORMAT_INVALID,\r
250 ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Arch),\r
251 File=GlobalData.gINF_MODULE_NAME,\r
252 Line=SectionLineNo,\r
253 ExtraData=None)\r
254\r
255 if (UserId, IdString, Arch) not in IdContentList:\r
256 #\r
257 # To check the UserId and IdString valid or not.\r
258 #\r
259 if not IsValidUserId(UserId):\r
260 Logger.Error('InfParser',\r
261 FORMAT_INVALID,\r
262 ST.ERR_INF_PARSER_UE_SECTION_USER_ID_ERROR % (Item[1]),\r
263 File=GlobalData.gINF_MODULE_NAME,\r
264 Line=SectionLineNo,\r
265 ExtraData=None)\r
266\r
267 if not IsValidIdString(IdString):\r
268 Logger.Error('InfParser',\r
269 FORMAT_INVALID,\r
270 ST.ERR_INF_PARSER_UE_SECTION_ID_STRING_ERROR % (IdString),\r
271 File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo,\r
272 ExtraData=None)\r
273 IdContentList.append((UserId, IdString, Arch))\r
274 else:\r
275 #\r
276 # Each UserExtensions section header must have a unique set \r
277 # of UserId, IdString and Arch values.\r
278 # This means that the same UserId can be used in more than one \r
279 # section header, provided the IdString or Arch values are \r
280 # different. The same IdString values can be used in more than \r
281 # one section header if the UserId or Arch values are \r
282 # different. The same UserId and the same IdString can be used \r
283 # in a section header if the Arch values are different in each \r
284 # of the section headers.\r
285 #\r
286 Logger.Error('InfParser',\r
287 FORMAT_INVALID,\r
288 ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR % (\r
289 IdString),\r
290 File=GlobalData.gINF_MODULE_NAME,\r
291 Line=SectionLineNo,\r
292 ExtraData=None)\r
293 LastItem = Item\r
294\r
295 if not InfSectionObject.SetUserExtension(UserExtensionContent,\r
296 IdContent=IdContentList,\r
297 LineNo=SectionLineNo):\r
298 Logger.Error\\r
299 ('InfParser', FORMAT_INVALID, \\r
300 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[UserExtension]"), \\r
301 File=FileName, Line=LastItem[4])\r
302\r
303 def InfProtocolParser(self, SectionString, InfSectionObject, FileName):\r
304 #\r
305 # Macro defined in this section \r
306 #\r
307 SectionMacros = {}\r
308 ValueList = []\r
309 ProtocolList = []\r
310 CommentsList = []\r
311 CurrentLineVar = None\r
312 #\r
313 # Parse section content\r
314 #\r
315 for Line in SectionString:\r
316 LineContent = Line[0]\r
317 LineNo = Line[1]\r
318\r
319 if LineContent.strip() == '':\r
320 CommentsList = []\r
321 continue\r
322\r
323 if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
324 CommentsList.append(Line)\r
325 continue\r
326 else:\r
327 #\r
328 # Encounter a Protocol entry\r
329 #\r
330 if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
331 CommentsList.append((\r
332 LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):],\r
333 LineNo))\r
334 LineContent = \\r
335 LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]\r
336\r
337 if LineContent != '':\r
338 #\r
339 # Find Macro\r
340 #\r
341 Name, Value = MacroParser((LineContent, LineNo),\r
342 FileName,\r
343 DT.MODEL_EFI_PROTOCOL,\r
344 self.FileLocalMacros)\r
345 if Name != None:\r
346 SectionMacros[Name] = Value\r
347 ValueList = []\r
348 CommentsList = []\r
349 continue\r
350\r
351 TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)\r
352 ValueList[0:len(TokenList)] = TokenList\r
353\r
354 #\r
355 # Replace with Local section Macro and [Defines] section Macro.\r
356 # \r
357 ValueList = [InfExpandMacro(Value, (FileName, LineContent, LineNo), self.FileLocalMacros, SectionMacros)\r
358 for Value in ValueList]\r
359\r
360 CurrentLineVar = (LineContent, LineNo, FileName)\r
361\r
362 if len(ValueList) >= 1:\r
363 ProtocolList.append((ValueList, CommentsList, CurrentLineVar))\r
364 ValueList = []\r
365 CommentsList = []\r
366 continue\r
367\r
368 #\r
369 # Current section archs\r
370 # \r
371 ArchList = []\r
372 LineIndex = -1\r
373 for Item in self.LastSectionHeaderContent:\r
374 LineIndex = Item[3]\r
375 if Item[1] not in ArchList:\r
376 ArchList.append(Item[1])\r
377\r
378 if not InfSectionObject.SetProtocol(ProtocolList, Arch=ArchList):\r
379 Logger.Error\\r
380 ('InfParser', FORMAT_INVALID, \\r
381 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Protocol]"), \\r
382 File=FileName, Line=LineIndex)\r