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 # 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
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.
15 InfGuidPpiProtocolSectionParser
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
34 class InfGuidPpiProtocolSectionParser(InfParserSectionRoot
):
38 def InfGuidParser(self
, SectionString
, InfSectionObject
, FileName
):
40 # Macro defined in this section
48 # Parse section content
50 for Line
in SectionString
:
54 if LineContent
.strip() == '':
58 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
59 CommentsList
.append(Line
)
63 # Encounter a GUID entry
65 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
67 LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
70 LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
76 Name
, Value
= MacroParser((LineContent
, LineNo
),
81 SectionMacros
[Name
] = Value
86 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
87 ValueList
[0:len(TokenList
)] = TokenList
90 # Replace with Local section Macro and [Defines] section Macro.
92 ValueList
= [InfExpandMacro(Value
, (FileName
, LineContent
, LineNo
),
93 self
.FileLocalMacros
, SectionMacros
, True)
94 for Value
in ValueList
]
96 CurrentLineVar
= (LineContent
, LineNo
, FileName
)
99 if len(ValueList
) >= 1:
100 GuidList
.append((ValueList
, CommentsList
, CurrentLineVar
))
106 # Current section archs
110 for Item
in self
.LastSectionHeaderContent
:
112 if Item
[1] not in ArchList
:
113 ArchList
.append(Item
[1])
115 if not InfSectionObject
.SetGuid(GuidList
, Arch
=ArchList
):
116 Logger
.Error('InfParser',
118 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Guid]"),
125 def InfPpiParser(self
, SectionString
, InfSectionObject
, FileName
):
127 # Macro defined in this section
133 CurrentLineVar
= None
135 # Parse section content
137 for Line
in SectionString
:
138 LineContent
= Line
[0]
141 if LineContent
.strip() == '':
145 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
146 CommentsList
.append(Line
)
150 # Encounter a PPI entry
152 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
153 CommentsList
.append((
154 LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
157 LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
159 if LineContent
!= '':
163 Name
, Value
= MacroParser((LineContent
, LineNo
),
166 self
.FileLocalMacros
)
168 SectionMacros
[Name
] = Value
173 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
174 ValueList
[0:len(TokenList
)] = TokenList
177 # Replace with Local section Macro and [Defines] section Macro.
179 ValueList
= [InfExpandMacro(Value
, (FileName
, LineContent
, LineNo
), self
.FileLocalMacros
, SectionMacros
)
180 for Value
in ValueList
]
182 CurrentLineVar
= (LineContent
, LineNo
, FileName
)
184 if len(ValueList
) >= 1:
185 PpiList
.append((ValueList
, CommentsList
, CurrentLineVar
))
191 # Current section archs
195 for Item
in self
.LastSectionHeaderContent
:
197 if Item
[1] not in ArchList
:
198 ArchList
.append(Item
[1])
200 if not InfSectionObject
.SetPpi(PpiList
, Arch
=ArchList
):
201 Logger
.Error('InfParser',
203 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Ppis]"),
207 ## InfUserExtensionParser
210 def InfUserExtensionParser(self
, SectionString
, InfSectionObject
, FileName
):
212 UserExtensionContent
= ''
215 # Parse section content
217 for Line
in SectionString
:
218 LineContent
= Line
[0]
220 # Comment the code to support user extension without any statement just the section header in []
221 # if LineContent.strip() == '':
224 UserExtensionContent
+= LineContent
+ DT
.END_OF_LINE
228 # Current section UserId, IdString
233 for Item
in self
.LastSectionHeaderContent
:
237 SectionLineNo
= Item
[4]
238 if not IsValidArch(Arch
):
242 ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
% (Arch
),
243 File
=GlobalData
.gINF_MODULE_NAME
,
247 if (UserId
, IdString
, Arch
) not in IdContentList
:
249 # To check the UserId and IdString valid or not.
251 if not IsValidUserId(UserId
):
252 Logger
.Error('InfParser',
254 ST
.ERR_INF_PARSER_UE_SECTION_USER_ID_ERROR
% (Item
[1]),
255 File
=GlobalData
.gINF_MODULE_NAME
,
259 if not IsValidIdString(IdString
):
260 Logger
.Error('InfParser',
262 ST
.ERR_INF_PARSER_UE_SECTION_ID_STRING_ERROR
% (IdString
),
263 File
=GlobalData
.gINF_MODULE_NAME
, Line
=SectionLineNo
,
265 IdContentList
.append((UserId
, IdString
, Arch
))
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.
278 Logger
.Error('InfParser',
280 ST
.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR
% (
282 File
=GlobalData
.gINF_MODULE_NAME
,
287 if not InfSectionObject
.SetUserExtension(UserExtensionContent
,
288 IdContent
=IdContentList
,
289 LineNo
=SectionLineNo
):
291 ('InfParser', FORMAT_INVALID
, \
292 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[UserExtension]"), \
293 File
=FileName
, Line
=LastItem
[4])
295 def InfProtocolParser(self
, SectionString
, InfSectionObject
, FileName
):
297 # Macro defined in this section
303 CurrentLineVar
= None
305 # Parse section content
307 for Line
in SectionString
:
308 LineContent
= Line
[0]
311 if LineContent
.strip() == '':
315 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
316 CommentsList
.append(Line
)
320 # Encounter a Protocol entry
322 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
323 CommentsList
.append((
324 LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
327 LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
329 if LineContent
!= '':
333 Name
, Value
= MacroParser((LineContent
, LineNo
),
335 DT
.MODEL_EFI_PROTOCOL
,
336 self
.FileLocalMacros
)
338 SectionMacros
[Name
] = Value
343 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
344 ValueList
[0:len(TokenList
)] = TokenList
347 # Replace with Local section Macro and [Defines] section Macro.
349 ValueList
= [InfExpandMacro(Value
, (FileName
, LineContent
, LineNo
), self
.FileLocalMacros
, SectionMacros
)
350 for Value
in ValueList
]
352 CurrentLineVar
= (LineContent
, LineNo
, FileName
)
354 if len(ValueList
) >= 1:
355 ProtocolList
.append((ValueList
, CommentsList
, CurrentLineVar
))
361 # Current section archs
365 for Item
in self
.LastSectionHeaderContent
:
367 if Item
[1] not in ArchList
:
368 ArchList
.append(Item
[1])
370 if not InfSectionObject
.SetProtocol(ProtocolList
, Arch
=ArchList
):
372 ('InfParser', FORMAT_INVALID
, \
373 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Protocol]"), \
374 File
=FileName
, Line
=LineIndex
)