]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 | 2 | # This file contained the parser for [Guids], [Ppis], [Protocols] sections in INF file\r |
4234283c | 3 | #\r |
f7496d71 | 4 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 5 | #\r |
f7496d71 LG |
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 | |
4234283c LG |
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 | |
15 | InfGuidPpiProtocolSectionParser\r | |
16 | '''\r | |
17 | ##\r | |
18 | # Import Modules\r | |
19 | #\r | |
20 | \r | |
21 | import Logger.Log as Logger\r | |
22 | from Logger import StringTable as ST\r | |
23 | from Logger.ToolError import FORMAT_INVALID\r | |
24 | from Parser.InfParserMisc import InfExpandMacro\r | |
25 | from Library import DataType as DT\r | |
26 | from Library import GlobalData\r | |
27 | from Library.Parsing import MacroParser\r | |
28 | from Library.Misc import GetSplitValueList\r | |
29 | from Library.ParserValidate import IsValidIdString\r | |
30 | from Library.ParserValidate import IsValidUserId\r | |
31 | from Library.ParserValidate import IsValidArch\r | |
32 | from Parser.InfParserMisc import InfParserSectionRoot\r | |
33 | \r | |
34 | class InfGuidPpiProtocolSectionParser(InfParserSectionRoot):\r | |
35 | ## InfGuidParser\r | |
36 | #\r | |
37 | #\r | |
38 | def InfGuidParser(self, SectionString, InfSectionObject, FileName):\r | |
39 | #\r | |
f7496d71 | 40 | # Macro defined in this section\r |
4234283c LG |
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 | |
4231a819 | 80 | if Name is not None:\r |
4234283c LG |
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 | |
f7496d71 | 91 | #\r |
4234283c LG |
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 | |
f7496d71 | 107 | #\r |
4234283c LG |
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 | |
f7496d71 | 127 | # Macro defined in this section\r |
4234283c LG |
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 | |
4231a819 | 167 | if Name is not None:\r |
4234283c LG |
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 | |
f7496d71 | 178 | #\r |
4234283c LG |
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 | |
f7496d71 | 192 | #\r |
4234283c LG |
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 | |
f7496d71 | 209 | #\r |
4234283c LG |
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 | 219 | \r |
c03f5b2c HC |
220 | # Comment the code to support user extension without any statement just the section header in []\r |
221 | # if LineContent.strip() == '':\r | |
222 | # continue\r | |
4234283c LG |
223 | \r |
224 | UserExtensionContent += LineContent + DT.END_OF_LINE\r | |
4234283c LG |
225 | continue\r |
226 | \r | |
227 | #\r | |
228 | # Current section UserId, IdString\r | |
f7496d71 | 229 | #\r |
4234283c LG |
230 | IdContentList = []\r |
231 | LastItem = ''\r | |
232 | SectionLineNo = None\r | |
233 | for Item in self.LastSectionHeaderContent:\r | |
234 | UserId = Item[1]\r | |
235 | IdString = Item[2]\r | |
236 | Arch = Item[3]\r | |
237 | SectionLineNo = Item[4]\r | |
238 | if not IsValidArch(Arch):\r | |
239 | Logger.Error(\r | |
240 | 'InfParser',\r | |
241 | FORMAT_INVALID,\r | |
242 | ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Arch),\r | |
243 | File=GlobalData.gINF_MODULE_NAME,\r | |
244 | Line=SectionLineNo,\r | |
245 | ExtraData=None)\r | |
246 | \r | |
247 | if (UserId, IdString, Arch) not in IdContentList:\r | |
248 | #\r | |
249 | # To check the UserId and IdString valid or not.\r | |
250 | #\r | |
251 | if not IsValidUserId(UserId):\r | |
252 | Logger.Error('InfParser',\r | |
253 | FORMAT_INVALID,\r | |
254 | ST.ERR_INF_PARSER_UE_SECTION_USER_ID_ERROR % (Item[1]),\r | |
255 | File=GlobalData.gINF_MODULE_NAME,\r | |
256 | Line=SectionLineNo,\r | |
257 | ExtraData=None)\r | |
258 | \r | |
259 | if not IsValidIdString(IdString):\r | |
260 | Logger.Error('InfParser',\r | |
261 | FORMAT_INVALID,\r | |
262 | ST.ERR_INF_PARSER_UE_SECTION_ID_STRING_ERROR % (IdString),\r | |
263 | File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo,\r | |
264 | ExtraData=None)\r | |
265 | IdContentList.append((UserId, IdString, Arch))\r | |
266 | else:\r | |
267 | #\r | |
f7496d71 | 268 | # Each UserExtensions section header must have a unique set\r |
4234283c | 269 | # of UserId, IdString and Arch values.\r |
f7496d71 LG |
270 | # This means that the same UserId can be used in more than one\r |
271 | # section header, provided the IdString or Arch values are\r | |
272 | # different. The same IdString values can be used in more than\r | |
273 | # one section header if the UserId or Arch values are\r | |
274 | # different. The same UserId and the same IdString can be used\r | |
275 | # in a section header if the Arch values are different in each\r | |
4234283c LG |
276 | # of the section headers.\r |
277 | #\r | |
278 | Logger.Error('InfParser',\r | |
279 | FORMAT_INVALID,\r | |
280 | ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR % (\r | |
281 | IdString),\r | |
282 | File=GlobalData.gINF_MODULE_NAME,\r | |
283 | Line=SectionLineNo,\r | |
284 | ExtraData=None)\r | |
285 | LastItem = Item\r | |
286 | \r | |
287 | if not InfSectionObject.SetUserExtension(UserExtensionContent,\r | |
288 | IdContent=IdContentList,\r | |
289 | LineNo=SectionLineNo):\r | |
290 | Logger.Error\\r | |
291 | ('InfParser', FORMAT_INVALID, \\r | |
292 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[UserExtension]"), \\r | |
293 | File=FileName, Line=LastItem[4])\r | |
294 | \r | |
295 | def InfProtocolParser(self, SectionString, InfSectionObject, FileName):\r | |
296 | #\r | |
f7496d71 | 297 | # Macro defined in this section\r |
4234283c LG |
298 | #\r |
299 | SectionMacros = {}\r | |
300 | ValueList = []\r | |
301 | ProtocolList = []\r | |
302 | CommentsList = []\r | |
303 | CurrentLineVar = None\r | |
304 | #\r | |
305 | # Parse section content\r | |
306 | #\r | |
307 | for Line in SectionString:\r | |
308 | LineContent = Line[0]\r | |
309 | LineNo = Line[1]\r | |
310 | \r | |
311 | if LineContent.strip() == '':\r | |
312 | CommentsList = []\r | |
313 | continue\r | |
314 | \r | |
315 | if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r | |
316 | CommentsList.append(Line)\r | |
317 | continue\r | |
318 | else:\r | |
319 | #\r | |
320 | # Encounter a Protocol entry\r | |
321 | #\r | |
322 | if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
323 | CommentsList.append((\r | |
324 | LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):],\r | |
325 | LineNo))\r | |
326 | LineContent = \\r | |
327 | LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]\r | |
328 | \r | |
329 | if LineContent != '':\r | |
330 | #\r | |
331 | # Find Macro\r | |
332 | #\r | |
333 | Name, Value = MacroParser((LineContent, LineNo),\r | |
334 | FileName,\r | |
335 | DT.MODEL_EFI_PROTOCOL,\r | |
336 | self.FileLocalMacros)\r | |
4231a819 | 337 | if Name is not None:\r |
4234283c LG |
338 | SectionMacros[Name] = Value\r |
339 | ValueList = []\r | |
340 | CommentsList = []\r | |
341 | continue\r | |
342 | \r | |
343 | TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1)\r | |
344 | ValueList[0:len(TokenList)] = TokenList\r | |
345 | \r | |
346 | #\r | |
347 | # Replace with Local section Macro and [Defines] section Macro.\r | |
f7496d71 | 348 | #\r |
4234283c LG |
349 | ValueList = [InfExpandMacro(Value, (FileName, LineContent, LineNo), self.FileLocalMacros, SectionMacros)\r |
350 | for Value in ValueList]\r | |
351 | \r | |
352 | CurrentLineVar = (LineContent, LineNo, FileName)\r | |
353 | \r | |
354 | if len(ValueList) >= 1:\r | |
355 | ProtocolList.append((ValueList, CommentsList, CurrentLineVar))\r | |
356 | ValueList = []\r | |
357 | CommentsList = []\r | |
358 | continue\r | |
359 | \r | |
360 | #\r | |
361 | # Current section archs\r | |
f7496d71 | 362 | #\r |
4234283c LG |
363 | ArchList = []\r |
364 | LineIndex = -1\r | |
365 | for Item in self.LastSectionHeaderContent:\r | |
366 | LineIndex = Item[3]\r | |
367 | if Item[1] not in ArchList:\r | |
368 | ArchList.append(Item[1])\r | |
369 | \r | |
370 | if not InfSectionObject.SetProtocol(ProtocolList, Arch=ArchList):\r | |
371 | Logger.Error\\r | |
372 | ('InfParser', FORMAT_INVALID, \\r | |
373 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Protocol]"), \\r | |
374 | File=FileName, Line=LineIndex)\r |