2 # This file is used to define class objects of INF file [Guids] section.
3 # It will consumed by InfParser.
5 # Copyright (c) 2011 - 2014, 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
is not None and len(CommentsList
) != 0 :
117 for CommentItem
in CommentsList
:
120 CommentItemGuidType
, \
121 CommentItemVarString
, \
122 CommentItemHelpText
= \
123 ParseComment(CommentItem
,
129 if CommentItemHelpText
is 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
159 PreHelpText
= CommentItemHelpText
162 CommentItemIns
= InfGuidItemCommentContent()
163 CommentItemIns
.SetUsageItem(CommentItemUsage
)
164 CommentItemIns
.SetGuidTypeItem(CommentItemGuidType
)
165 CommentItemIns
.SetVariableNameItem(CommentItemVarString
)
166 if CommentItemHelpText
== '' or CommentItemHelpText
.endswith(DT
.END_OF_LINE
):
167 CommentItemHelpText
= CommentItemHelpText
.strip(DT
.END_OF_LINE
)
168 CommentItemIns
.SetHelpStringItem(CommentItemHelpText
)
169 CommentInsList
.append(CommentItemIns
)
178 # Add previous help string
180 CommentItemIns
= InfGuidItemCommentContent()
181 CommentItemIns
.SetUsageItem(DT
.ITEM_UNDEFINED
)
182 CommentItemIns
.SetGuidTypeItem(DT
.ITEM_UNDEFINED
)
183 if PreHelpText
== '' or PreHelpText
.endswith(DT
.END_OF_LINE
):
184 PreHelpText
= PreHelpText
.strip(DT
.END_OF_LINE
)
185 CommentItemIns
.SetHelpStringItem(PreHelpText
)
186 CommentInsList
.append(CommentItemIns
)
188 # Add Current help string
190 CommentItemIns
= InfGuidItemCommentContent()
191 CommentItemIns
.SetUsageItem(CommentItemUsage
)
192 CommentItemIns
.SetGuidTypeItem(CommentItemGuidType
)
193 CommentItemIns
.SetVariableNameItem(CommentItemVarString
)
194 if CommentItemHelpText
== '' or CommentItemHelpText
.endswith(DT
.END_OF_LINE
):
195 CommentItemHelpText
= CommentItemHelpText
.strip(DT
.END_OF_LINE
)
196 CommentItemIns
.SetHelpStringItem(CommentItemHelpText
)
197 CommentInsList
.append(CommentItemIns
)
205 PreUsage
= CommentItemUsage
206 PreGuidType
= CommentItemGuidType
207 PreHelpText
= CommentItemHelpText
209 InfGuidItemObj
.SetCommentList(CommentInsList
)
212 # Still need to set the USAGE/GUIDTYPE to undefined.
214 CommentItemIns
= InfGuidItemCommentContent()
215 CommentItemIns
.SetUsageItem(DT
.ITEM_UNDEFINED
)
216 CommentItemIns
.SetGuidTypeItem(DT
.ITEM_UNDEFINED
)
217 InfGuidItemObj
.SetCommentList([CommentItemIns
])
219 return InfGuidItemObj
225 class InfGuidObject():
229 # Macro defined in this section should be only used in this section.
233 def SetGuid(self
, GuidList
, Arch
= None):
234 __SupportArchList
= []
235 for ArchItem
in Arch
:
239 if (ArchItem
== '' or ArchItem
is None):
242 __SupportArchList
.append(ArchItem
)
244 for Item
in GuidList
:
246 # Get Comment content of this protocol
250 CommentsList
= Item
[1]
251 CurrentLineOfItem
= Item
[2]
253 InfGuidItemObj
= InfGuidItem()
254 if len(Item
) >= 1 and len(Item
) <= 2:
256 # Only GuildName contained
258 if not IsValidCVariableName(Item
[0]):
259 Logger
.Error("InfParser",
260 ToolError
.FORMAT_INVALID
,
261 ST
.ERR_INF_PARSER_INVALID_CNAME
%(Item
[0]),
262 File
=CurrentLineOfItem
[2],
263 Line
=CurrentLineOfItem
[1],
264 ExtraData
=CurrentLineOfItem
[0])
266 InfGuidItemObj
.SetName(Item
[0])
268 Logger
.Error("InfParser",
269 ToolError
.FORMAT_INVALID
,
270 ST
.ERR_INF_PARSER_CNAME_MISSING
,
271 File
=CurrentLineOfItem
[2],
272 Line
=CurrentLineOfItem
[1],
273 ExtraData
=CurrentLineOfItem
[0])
276 # Contained CName and Feature Flag Express
277 # <statements> ::= <CName> ["|" <FeatureFlagExpress>]
280 if Item
[1].strip() == '':
281 Logger
.Error("InfParser",
282 ToolError
.FORMAT_INVALID
,
283 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
284 File
=CurrentLineOfItem
[2],
285 Line
=CurrentLineOfItem
[1],
286 ExtraData
=CurrentLineOfItem
[0])
288 # Validate Feature Flag Express
290 FeatureFlagRtv
= IsValidFeatureFlagExp(Item
[1].strip())
291 if not FeatureFlagRtv
[0]:
292 Logger
.Error("InfParser",
293 ToolError
.FORMAT_INVALID
,
294 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
295 File
=CurrentLineOfItem
[2],
296 Line
=CurrentLineOfItem
[1],
297 ExtraData
=CurrentLineOfItem
[0])
298 InfGuidItemObj
.SetFeatureFlagExp(Item
[1])
299 if len(Item
) != 1 and len(Item
) != 2:
301 # Invalid format of GUID statement
303 Logger
.Error("InfParser",
304 ToolError
.FORMAT_INVALID
,
305 ST
.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR
,
306 File
=CurrentLineOfItem
[2],
307 Line
=CurrentLineOfItem
[1],
308 ExtraData
=CurrentLineOfItem
[0])
310 InfGuidItemObj
= ParseGuidComment(CommentsList
, InfGuidItemObj
)
311 InfGuidItemObj
.SetSupArchList(__SupportArchList
)
314 # Determine GUID name duplicate. Follow below rule:
316 # A GUID must not be duplicated within a [Guids] section.
317 # A GUID may appear in multiple architectural [Guids]
318 # sections. A GUID listed in an architectural [Guids]
319 # section must not be listed in the common architectural
322 # NOTE: This check will not report error now.
324 for Item
in self
.Guids
:
325 if Item
.GetName() == InfGuidItemObj
.GetName():
326 ItemSupArchList
= Item
.GetSupArchList()
327 for ItemArch
in ItemSupArchList
:
328 for GuidItemObjArch
in __SupportArchList
:
329 if ItemArch
== GuidItemObjArch
:
331 # ST.ERR_INF_PARSER_ITEM_DUPLICATE
335 if ItemArch
.upper() == 'COMMON' or GuidItemObjArch
.upper() == 'COMMON':
337 # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
341 if (InfGuidItemObj
) in self
.Guids
:
342 GuidList
= self
.Guids
[InfGuidItemObj
]
343 GuidList
.append(InfGuidItemObj
)
344 self
.Guids
[InfGuidItemObj
] = GuidList
347 GuidList
.append(InfGuidItemObj
)
348 self
.Guids
[InfGuidItemObj
] = GuidList