2 # This file contained the parser for [Guids], [Ppis], [Protocols] sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
9 InfGuidPpiProtocolSectionParser
15 import Logger
.Log
as Logger
16 from Logger
import StringTable
as ST
17 from Logger
.ToolError
import FORMAT_INVALID
18 from Parser
.InfParserMisc
import InfExpandMacro
19 from Library
import DataType
as DT
20 from Library
import GlobalData
21 from Library
.Parsing
import MacroParser
22 from Library
.Misc
import GetSplitValueList
23 from Library
.ParserValidate
import IsValidIdString
24 from Library
.ParserValidate
import IsValidUserId
25 from Library
.ParserValidate
import IsValidArch
26 from Parser
.InfParserMisc
import InfParserSectionRoot
28 class InfGuidPpiProtocolSectionParser(InfParserSectionRoot
):
32 def InfGuidParser(self
, SectionString
, InfSectionObject
, FileName
):
34 # Macro defined in this section
42 # Parse section content
44 for Line
in SectionString
:
48 if LineContent
.strip() == '':
52 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
53 CommentsList
.append(Line
)
57 # Encounter a GUID entry
59 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
61 LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
64 LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
70 Name
, Value
= MacroParser((LineContent
, LineNo
),
75 SectionMacros
[Name
] = Value
80 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
81 ValueList
[0:len(TokenList
)] = TokenList
84 # Replace with Local section Macro and [Defines] section Macro.
86 ValueList
= [InfExpandMacro(Value
, (FileName
, LineContent
, LineNo
),
87 self
.FileLocalMacros
, SectionMacros
, True)
88 for Value
in ValueList
]
90 CurrentLineVar
= (LineContent
, LineNo
, FileName
)
93 if len(ValueList
) >= 1:
94 GuidList
.append((ValueList
, CommentsList
, CurrentLineVar
))
100 # Current section archs
104 for Item
in self
.LastSectionHeaderContent
:
106 if Item
[1] not in ArchList
:
107 ArchList
.append(Item
[1])
109 if not InfSectionObject
.SetGuid(GuidList
, Arch
=ArchList
):
110 Logger
.Error('InfParser',
112 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Guid]"),
119 def InfPpiParser(self
, SectionString
, InfSectionObject
, FileName
):
121 # Macro defined in this section
127 CurrentLineVar
= None
129 # Parse section content
131 for Line
in SectionString
:
132 LineContent
= Line
[0]
135 if LineContent
.strip() == '':
139 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
140 CommentsList
.append(Line
)
144 # Encounter a PPI entry
146 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
147 CommentsList
.append((
148 LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
151 LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
153 if LineContent
!= '':
157 Name
, Value
= MacroParser((LineContent
, LineNo
),
160 self
.FileLocalMacros
)
162 SectionMacros
[Name
] = Value
167 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
168 ValueList
[0:len(TokenList
)] = TokenList
171 # Replace with Local section Macro and [Defines] section Macro.
173 ValueList
= [InfExpandMacro(Value
, (FileName
, LineContent
, LineNo
), self
.FileLocalMacros
, SectionMacros
)
174 for Value
in ValueList
]
176 CurrentLineVar
= (LineContent
, LineNo
, FileName
)
178 if len(ValueList
) >= 1:
179 PpiList
.append((ValueList
, CommentsList
, CurrentLineVar
))
185 # Current section archs
189 for Item
in self
.LastSectionHeaderContent
:
191 if Item
[1] not in ArchList
:
192 ArchList
.append(Item
[1])
194 if not InfSectionObject
.SetPpi(PpiList
, Arch
=ArchList
):
195 Logger
.Error('InfParser',
197 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Ppis]"),
201 ## InfUserExtensionParser
204 def InfUserExtensionParser(self
, SectionString
, InfSectionObject
, FileName
):
206 UserExtensionContent
= ''
209 # Parse section content
211 for Line
in SectionString
:
212 LineContent
= Line
[0]
214 # Comment the code to support user extension without any statement just the section header in []
215 # if LineContent.strip() == '':
218 UserExtensionContent
+= LineContent
+ DT
.END_OF_LINE
222 # Current section UserId, IdString
227 for Item
in self
.LastSectionHeaderContent
:
231 SectionLineNo
= Item
[4]
232 if not IsValidArch(Arch
):
236 ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
% (Arch
),
237 File
=GlobalData
.gINF_MODULE_NAME
,
241 if (UserId
, IdString
, Arch
) not in IdContentList
:
243 # To check the UserId and IdString valid or not.
245 if not IsValidUserId(UserId
):
246 Logger
.Error('InfParser',
248 ST
.ERR_INF_PARSER_UE_SECTION_USER_ID_ERROR
% (Item
[1]),
249 File
=GlobalData
.gINF_MODULE_NAME
,
253 if not IsValidIdString(IdString
):
254 Logger
.Error('InfParser',
256 ST
.ERR_INF_PARSER_UE_SECTION_ID_STRING_ERROR
% (IdString
),
257 File
=GlobalData
.gINF_MODULE_NAME
, Line
=SectionLineNo
,
259 IdContentList
.append((UserId
, IdString
, Arch
))
262 # Each UserExtensions section header must have a unique set
263 # of UserId, IdString and Arch values.
264 # This means that the same UserId can be used in more than one
265 # section header, provided the IdString or Arch values are
266 # different. The same IdString values can be used in more than
267 # one section header if the UserId or Arch values are
268 # different. The same UserId and the same IdString can be used
269 # in a section header if the Arch values are different in each
270 # of the section headers.
272 Logger
.Error('InfParser',
274 ST
.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR
% (
276 File
=GlobalData
.gINF_MODULE_NAME
,
281 if not InfSectionObject
.SetUserExtension(UserExtensionContent
,
282 IdContent
=IdContentList
,
283 LineNo
=SectionLineNo
):
285 ('InfParser', FORMAT_INVALID
, \
286 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[UserExtension]"), \
287 File
=FileName
, Line
=LastItem
[4])
289 def InfProtocolParser(self
, SectionString
, InfSectionObject
, FileName
):
291 # Macro defined in this section
297 CurrentLineVar
= None
299 # Parse section content
301 for Line
in SectionString
:
302 LineContent
= Line
[0]
305 if LineContent
.strip() == '':
309 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
310 CommentsList
.append(Line
)
314 # Encounter a Protocol entry
316 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
317 CommentsList
.append((
318 LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
321 LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
323 if LineContent
!= '':
327 Name
, Value
= MacroParser((LineContent
, LineNo
),
329 DT
.MODEL_EFI_PROTOCOL
,
330 self
.FileLocalMacros
)
332 SectionMacros
[Name
] = Value
337 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
338 ValueList
[0:len(TokenList
)] = TokenList
341 # Replace with Local section Macro and [Defines] section Macro.
343 ValueList
= [InfExpandMacro(Value
, (FileName
, LineContent
, LineNo
), self
.FileLocalMacros
, SectionMacros
)
344 for Value
in ValueList
]
346 CurrentLineVar
= (LineContent
, LineNo
, FileName
)
348 if len(ValueList
) >= 1:
349 ProtocolList
.append((ValueList
, CommentsList
, CurrentLineVar
))
355 # Current section archs
359 for Item
in self
.LastSectionHeaderContent
:
361 if Item
[1] not in ArchList
:
362 ArchList
.append(Item
[1])
364 if not InfSectionObject
.SetProtocol(ProtocolList
, Arch
=ArchList
):
366 ('InfParser', FORMAT_INVALID
, \
367 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Protocol]"), \
368 File
=FileName
, Line
=LineIndex
)