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