2 # This file contained the parser for [Guids], [Ppis], [Protocols] sections in INF file
4 # Copyright (c) 2011, 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]
221 if LineContent
.strip() == '':
224 # Replace with [Defines] section Macro
226 LineContent
= InfExpandMacro(LineContent
,
227 (FileName
, LineContent
, LineNo
),
228 self
.FileLocalMacros
,
231 UserExtensionContent
+= LineContent
+ DT
.END_OF_LINE
236 # Current section UserId, IdString
241 for Item
in self
.LastSectionHeaderContent
:
245 SectionLineNo
= Item
[4]
246 if not IsValidArch(Arch
):
250 ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
% (Arch
),
251 File
=GlobalData
.gINF_MODULE_NAME
,
255 if (UserId
, IdString
, Arch
) not in IdContentList
:
257 # To check the UserId and IdString valid or not.
259 if not IsValidUserId(UserId
):
260 Logger
.Error('InfParser',
262 ST
.ERR_INF_PARSER_UE_SECTION_USER_ID_ERROR
% (Item
[1]),
263 File
=GlobalData
.gINF_MODULE_NAME
,
267 if not IsValidIdString(IdString
):
268 Logger
.Error('InfParser',
270 ST
.ERR_INF_PARSER_UE_SECTION_ID_STRING_ERROR
% (IdString
),
271 File
=GlobalData
.gINF_MODULE_NAME
, Line
=SectionLineNo
,
273 IdContentList
.append((UserId
, IdString
, Arch
))
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.
286 Logger
.Error('InfParser',
288 ST
.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR
% (
290 File
=GlobalData
.gINF_MODULE_NAME
,
295 if not InfSectionObject
.SetUserExtension(UserExtensionContent
,
296 IdContent
=IdContentList
,
297 LineNo
=SectionLineNo
):
299 ('InfParser', FORMAT_INVALID
, \
300 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[UserExtension]"), \
301 File
=FileName
, Line
=LastItem
[4])
303 def InfProtocolParser(self
, SectionString
, InfSectionObject
, FileName
):
305 # Macro defined in this section
311 CurrentLineVar
= None
313 # Parse section content
315 for Line
in SectionString
:
316 LineContent
= Line
[0]
319 if LineContent
.strip() == '':
323 if LineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
324 CommentsList
.append(Line
)
328 # Encounter a Protocol entry
330 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
331 CommentsList
.append((
332 LineContent
[LineContent
.find(DT
.TAB_COMMENT_SPLIT
):],
335 LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
337 if LineContent
!= '':
341 Name
, Value
= MacroParser((LineContent
, LineNo
),
343 DT
.MODEL_EFI_PROTOCOL
,
344 self
.FileLocalMacros
)
346 SectionMacros
[Name
] = Value
351 TokenList
= GetSplitValueList(LineContent
, DT
.TAB_VALUE_SPLIT
, 1)
352 ValueList
[0:len(TokenList
)] = TokenList
355 # Replace with Local section Macro and [Defines] section Macro.
357 ValueList
= [InfExpandMacro(Value
, (FileName
, LineContent
, LineNo
), self
.FileLocalMacros
, SectionMacros
)
358 for Value
in ValueList
]
360 CurrentLineVar
= (LineContent
, LineNo
, FileName
)
362 if len(ValueList
) >= 1:
363 ProtocolList
.append((ValueList
, CommentsList
, CurrentLineVar
))
369 # Current section archs
373 for Item
in self
.LastSectionHeaderContent
:
375 if Item
[1] not in ArchList
:
376 ArchList
.append(Item
[1])
378 if not InfSectionObject
.SetProtocol(ProtocolList
, Arch
=ArchList
):
380 ('InfParser', FORMAT_INVALID
, \
381 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR
% ("[Protocol]"), \
382 File
=FileName
, Line
=LineIndex
)