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