2 # This file is used to define class objects of INF file [Guids] section.
3 # It will consumed by InfParser.
5 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
7 # This program and the accompanying materials are licensed and made available
8 # under the terms and conditions of the BSD License which accompanies this
9 # distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 from Library
.ParserValidate
import IsValidCVariableName
20 from Library
.CommentParsing
import ParseComment
21 from Library
.ExpressionValidate
import IsValidFeatureFlagExp
23 from Library
.Misc
import Sdict
24 from Library
import DataType
as DT
25 import Logger
.Log
as Logger
26 from Logger
import ToolError
27 from Logger
import StringTable
as ST
29 class InfGuidItemCommentContent():
32 # ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation"
42 self
.GuidTypeItem
= ''
44 # MemoryTypeInformation
46 self
.VariableNameItem
= ''
50 self
.HelpStringItem
= ''
52 def SetUsageItem(self
, UsageItem
):
53 self
.UsageItem
= UsageItem
54 def GetUsageItem(self
):
57 def SetGuidTypeItem(self
, GuidTypeItem
):
58 self
.GuidTypeItem
= GuidTypeItem
59 def GetGuidTypeItem(self
):
60 return self
.GuidTypeItem
62 def SetVariableNameItem(self
, VariableNameItem
):
63 self
.VariableNameItem
= VariableNameItem
64 def GetVariableNameItem(self
):
65 return self
.VariableNameItem
67 def SetHelpStringItem(self
, HelpStringItem
):
68 self
.HelpStringItem
= HelpStringItem
69 def GetHelpStringItem(self
):
70 return self
.HelpStringItem
75 self
.FeatureFlagExp
= ''
77 # A list contain instance of InfGuidItemCommentContent
82 def SetName(self
, Name
):
87 def SetFeatureFlagExp(self
, FeatureFlagExp
):
88 self
.FeatureFlagExp
= FeatureFlagExp
89 def GetFeatureFlagExp(self
):
90 return self
.FeatureFlagExp
92 def SetCommentList(self
, CommentList
):
93 self
.CommentList
= CommentList
94 def GetCommentList(self
):
95 return self
.CommentList
97 def SetSupArchList(self
, SupArchList
):
98 self
.SupArchList
= SupArchList
99 def GetSupArchList(self
):
100 return self
.SupArchList
106 def ParseGuidComment(CommentsList
, InfGuidItemObj
):
108 # Get/Set Usage and HelpString
110 if CommentsList
!= None and len(CommentsList
) != 0 :
117 for CommentItem
in CommentsList
:
120 CommentItemGuidType
, \
121 CommentItemVarString
, \
122 CommentItemHelpText
= \
123 ParseComment(CommentItem
,
129 if CommentItemHelpText
== None:
130 CommentItemHelpText
= ''
131 if Count
== len(CommentsList
) and CommentItemUsage
== CommentItemGuidType
== DT
.ITEM_UNDEFINED
:
132 CommentItemHelpText
= DT
.END_OF_LINE
134 if Count
== len(CommentsList
):
135 if BlockFlag
== 1 or BlockFlag
== 2:
136 if CommentItemUsage
== CommentItemGuidType
== DT
.ITEM_UNDEFINED
:
142 if BlockFlag
== -1 or BlockFlag
== 1 or BlockFlag
== 2:
143 if CommentItemUsage
== CommentItemGuidType
== DT
.ITEM_UNDEFINED
:
149 if BlockFlag
== 1 or BlockFlag
== 2:
151 elif BlockFlag
== -1:
155 # Combine two comment line if they are generic comment
157 if CommentItemUsage
== CommentItemGuidType
== PreUsage
== PreGuidType
== DT
.ITEM_UNDEFINED
:
158 CommentItemHelpText
= PreHelpText
+ DT
.END_OF_LINE
+ CommentItemHelpText
160 PreHelpText
= CommentItemHelpText
163 CommentItemIns
= InfGuidItemCommentContent()
164 CommentItemIns
.SetUsageItem(CommentItemUsage
)
165 CommentItemIns
.SetGuidTypeItem(CommentItemGuidType
)
166 CommentItemIns
.SetVariableNameItem(CommentItemVarString
)
167 CommentItemIns
.SetHelpStringItem(CommentItemHelpText
)
168 CommentInsList
.append(CommentItemIns
)
177 # Add previous help string
179 CommentItemIns
= InfGuidItemCommentContent()
180 CommentItemIns
.SetUsageItem(DT
.ITEM_UNDEFINED
)
181 CommentItemIns
.SetGuidTypeItem(DT
.ITEM_UNDEFINED
)
182 if PreHelpText
== '' or PreHelpText
.endswith(DT
.END_OF_LINE
):
183 PreHelpText
+= DT
.END_OF_LINE
184 CommentItemIns
.SetHelpStringItem(PreHelpText
)
185 CommentInsList
.append(CommentItemIns
)
187 # Add Current help string
189 CommentItemIns
= InfGuidItemCommentContent()
190 CommentItemIns
.SetUsageItem(CommentItemUsage
)
191 CommentItemIns
.SetGuidTypeItem(CommentItemGuidType
)
192 CommentItemIns
.SetVariableNameItem(CommentItemVarString
)
193 CommentItemIns
.SetHelpStringItem(CommentItemHelpText
)
194 CommentInsList
.append(CommentItemIns
)
202 PreUsage
= CommentItemUsage
203 PreGuidType
= CommentItemGuidType
204 PreHelpText
= CommentItemHelpText
206 InfGuidItemObj
.SetCommentList(CommentInsList
)
209 # Still need to set the USAGE/GUIDTYPE to undefined.
211 CommentItemIns
= InfGuidItemCommentContent()
212 CommentItemIns
.SetUsageItem(DT
.ITEM_UNDEFINED
)
213 CommentItemIns
.SetGuidTypeItem(DT
.ITEM_UNDEFINED
)
214 InfGuidItemObj
.SetCommentList([CommentItemIns
])
216 return InfGuidItemObj
222 class InfGuidObject():
226 # Macro defined in this section should be only used in this section.
230 def SetGuid(self
, GuidList
, Arch
= None):
231 __SupportArchList
= []
232 for ArchItem
in Arch
:
236 if (ArchItem
== '' or ArchItem
== None):
239 __SupportArchList
.append(ArchItem
)
241 for Item
in GuidList
:
243 # Get Comment content of this protocol
247 CommentsList
= Item
[1]
248 CurrentLineOfItem
= Item
[2]
250 InfGuidItemObj
= InfGuidItem()
251 if len(Item
) >= 1 and len(Item
) <= 2:
253 # Only GuildName contained
255 if not IsValidCVariableName(Item
[0]):
256 Logger
.Error("InfParser",
257 ToolError
.FORMAT_INVALID
,
258 ST
.ERR_INF_PARSER_INVALID_CNAME
%(Item
[0]),
259 File
=CurrentLineOfItem
[2],
260 Line
=CurrentLineOfItem
[1],
261 ExtraData
=CurrentLineOfItem
[0])
263 InfGuidItemObj
.SetName(Item
[0])
265 Logger
.Error("InfParser",
266 ToolError
.FORMAT_INVALID
,
267 ST
.ERR_INF_PARSER_CNAME_MISSING
,
268 File
=CurrentLineOfItem
[2],
269 Line
=CurrentLineOfItem
[1],
270 ExtraData
=CurrentLineOfItem
[0])
273 # Contained CName and Feature Flag Express
274 # <statements> ::= <CName> ["|" <FeatureFlagExpress>]
277 if Item
[1].strip() == '':
278 Logger
.Error("InfParser",
279 ToolError
.FORMAT_INVALID
,
280 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
281 File
=CurrentLineOfItem
[2],
282 Line
=CurrentLineOfItem
[1],
283 ExtraData
=CurrentLineOfItem
[0])
285 # Validate Feature Flag Express
287 FeatureFlagRtv
= IsValidFeatureFlagExp(Item
[1].strip())
288 if not FeatureFlagRtv
[0]:
289 Logger
.Error("InfParser",
290 ToolError
.FORMAT_INVALID
,
291 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
292 File
=CurrentLineOfItem
[2],
293 Line
=CurrentLineOfItem
[1],
294 ExtraData
=CurrentLineOfItem
[0])
295 InfGuidItemObj
.SetFeatureFlagExp(Item
[1])
296 if len(Item
) != 1 and len(Item
) != 2:
298 # Invalid format of GUID statement
300 Logger
.Error("InfParser",
301 ToolError
.FORMAT_INVALID
,
302 ST
.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR
,
303 File
=CurrentLineOfItem
[2],
304 Line
=CurrentLineOfItem
[1],
305 ExtraData
=CurrentLineOfItem
[0])
307 InfGuidItemObj
= ParseGuidComment(CommentsList
, InfGuidItemObj
)
308 InfGuidItemObj
.SetSupArchList(__SupportArchList
)
311 # Determine GUID name duplicate. Follow below rule:
313 # A GUID must not be duplicated within a [Guids] section.
314 # A GUID may appear in multiple architectural [Guids]
315 # sections. A GUID listed in an architectural [Guids]
316 # section must not be listed in the common architectural
319 # NOTE: This check will not report error now.
321 for Item
in self
.Guids
:
322 if Item
.GetName() == InfGuidItemObj
.GetName():
323 ItemSupArchList
= Item
.GetSupArchList()
324 for ItemArch
in ItemSupArchList
:
325 for GuidItemObjArch
in __SupportArchList
:
326 if ItemArch
== GuidItemObjArch
:
328 # ST.ERR_INF_PARSER_ITEM_DUPLICATE
332 if ItemArch
.upper() == 'COMMON' or GuidItemObjArch
.upper() == 'COMMON':
334 # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
338 if self
.Guids
.has_key((InfGuidItemObj
)):
339 GuidList
= self
.Guids
[InfGuidItemObj
]
340 GuidList
.append(InfGuidItemObj
)
341 self
.Guids
[InfGuidItemObj
] = GuidList
344 GuidList
.append(InfGuidItemObj
)
345 self
.Guids
[InfGuidItemObj
] = GuidList