]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Parser/InfGuidPpiProtocolSectionParser.py
BaseTools/UPT: Remove Macro Expend for UserExtension section
[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
4234283c
LG
219\r
220 if LineContent.strip() == '':\r
221 continue\r
4234283c
LG
222\r
223 UserExtensionContent += LineContent + DT.END_OF_LINE\r
4234283c
LG
224 continue\r
225\r
226 #\r
227 # Current section UserId, IdString\r
228 # \r
229 IdContentList = []\r
230 LastItem = ''\r
231 SectionLineNo = None\r
232 for Item in self.LastSectionHeaderContent:\r
233 UserId = Item[1]\r
234 IdString = Item[2]\r
235 Arch = Item[3]\r
236 SectionLineNo = Item[4]\r
237 if not IsValidArch(Arch):\r
238 Logger.Error(\r
239 'InfParser',\r
240 FORMAT_INVALID,\r
241 ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Arch),\r
242 File=GlobalData.gINF_MODULE_NAME,\r
243 Line=SectionLineNo,\r
244 ExtraData=None)\r
245\r
246 if (UserId, IdString, Arch) not in IdContentList:\r
247 #\r
248 # To check the UserId and IdString valid or not.\r
249 #\r
250 if not IsValidUserId(UserId):\r
251 Logger.Error('InfParser',\r
252 FORMAT_INVALID,\r
253 ST.ERR_INF_PARSER_UE_SECTION_USER_ID_ERROR % (Item[1]),\r
254 File=GlobalData.gINF_MODULE_NAME,\r
255 Line=SectionLineNo,\r
256 ExtraData=None)\r
257\r
258 if not IsValidIdString(IdString):\r
259 Logger.Error('InfParser',\r
260 FORMAT_INVALID,\r
261 ST.ERR_INF_PARSER_UE_SECTION_ID_STRING_ERROR % (IdString),\r
262 File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo,\r
263 ExtraData=None)\r
264 IdContentList.append((UserId, IdString, Arch))\r
265 else:\r
266 #\r
267 # Each UserExtensions section header must have a unique set \r
268 # of UserId, IdString and Arch values.\r
269 # This means that the same UserId can be used in more than one \r
270 # section header, provided the IdString or Arch values are \r
271 # different. The same IdString values can be used in more than \r
272 # one section header if the UserId or Arch values are \r
273 # different. The same UserId and the same IdString can be used \r
274 # in a section header if the Arch values are different in each \r
275 # of the section headers.\r
276 #\r
277 Logger.Error('InfParser',\r
278 FORMAT_INVALID,\r
279 ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR % (\r
280 IdString),\r
281 File=GlobalData.gINF_MODULE_NAME,\r
282 Line=SectionLineNo,\r
283 ExtraData=None)\r
284 LastItem = Item\r
285\r
286 if not InfSectionObject.SetUserExtension(UserExtensionContent,\r
287 IdContent=IdContentList,\r
288 LineNo=SectionLineNo):\r
289 Logger.Error\\r
290 ('InfParser', FORMAT_INVALID, \\r
291 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[UserExtension]"), \\r
292 File=FileName, Line=LastItem[4])\r
293\r
294 def InfProtocolParser(self, SectionString, InfSectionObject, FileName):\r
295 #\r
296 # Macro defined in this section \r
297 #\r
298 SectionMacros = {}\r
299 ValueList = []\r
300 ProtocolList = []\r
301 CommentsList = []\r
302 CurrentLineVar = None\r
303 #\r
304 # Parse section content\r
305 #\r
306 for Line in SectionString:\r
307 LineContent = Line[0]\r
308 LineNo = Line[1]\r
309\r
310 if LineContent.strip() == '':\r
311 CommentsList = []\r
312 continue\r
313\r
314 if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
315 CommentsList.append(Line)\r
316 continue\r
317 else:\r
318 #\r
319 # Encounter a Protocol entry\r
320 #\r
321 if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
322 CommentsList.append((\r
323 LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):],\r
324 LineNo))\r
325 LineContent = \\r
326 LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]\r
327\r
328 if LineContent != '':\r
329 #\r
330 # Find Macro\r
331 #\r
332 Name, Value = MacroParser((LineContent, LineNo),\r
333 FileName,\r
334 DT.MODEL_EFI_PROTOCOL,\r
335 self.FileLocalMacros)\r
336 if Name != None:\r
337 SectionMacros[Name] = Value\r
338 ValueList = []\r
339 CommentsList = []\r
340 continue\r
341\r
342 TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)\r
343 ValueList[0:len(TokenList)] = TokenList\r
344\r
345 #\r
346 # Replace with Local section Macro and [Defines] section Macro.\r
347 # \r
348 ValueList = [InfExpandMacro(Value, (FileName, LineContent, LineNo), self.FileLocalMacros, SectionMacros)\r
349 for Value in ValueList]\r
350\r
351 CurrentLineVar = (LineContent, LineNo, FileName)\r
352\r
353 if len(ValueList) >= 1:\r
354 ProtocolList.append((ValueList, CommentsList, CurrentLineVar))\r
355 ValueList = []\r
356 CommentsList = []\r
357 continue\r
358\r
359 #\r
360 # Current section archs\r
361 # \r
362 ArchList = []\r
363 LineIndex = -1\r
364 for Item in self.LastSectionHeaderContent:\r
365 LineIndex = Item[3]\r
366 if Item[1] not in ArchList:\r
367 ArchList.append(Item[1])\r
368\r
369 if not InfSectionObject.SetProtocol(ProtocolList, Arch=ArchList):\r
370 Logger.Error\\r
371 ('InfParser', FORMAT_INVALID, \\r
372 ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Protocol]"), \\r
373 File=FileName, Line=LineIndex)\r