2
# This file is used to define class objects of INF file [Ppis] 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
def ParsePpiComment(CommentsList, InfPpiItemObj):
36
for CommentItem in CommentsList:
41
CommentItemHelpText = \
42
ParseComment(CommentItem,
49
# To avoid PyLint error
54
if CommentItemHelpText == None:
55
CommentItemHelpText = ''
56
if Count == len(CommentsList) and CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
57
CommentItemHelpText = DT.END_OF_LINE
59
# For the Last comment Item, set BlockFlag.
61
if Count == len(CommentsList):
62
if BlockFlag == 1 or BlockFlag == 2:
63
if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
71
# Comment USAGE and NOTIFY information are "UNDEFINED"
73
if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
74
if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
80
if BlockFlag == 1 or BlockFlag == 2:
83
# An item have Usage or Notify information and the first time get this information
89
# Combine two comment line if they are generic comment
91
if CommentItemUsage == CommentItemNotify == PreUsage == PreNotify == DT.ITEM_UNDEFINED:
92
CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText
94
# Store this information for next line may still need combine operation.
96
PreHelpText = CommentItemHelpText
99
CommentItemIns = InfPpiItemCommentContent()
100
CommentItemIns.SetUsage(CommentItemUsage)
101
CommentItemIns.SetNotify(CommentItemNotify)
102
CommentItemIns.SetHelpStringItem(CommentItemHelpText)
103
CommentInsList.append(CommentItemIns)
112
# Add previous help string
114
CommentItemIns = InfPpiItemCommentContent()
115
CommentItemIns.SetUsage(DT.ITEM_UNDEFINED)
116
CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
117
if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
118
PreHelpText += DT.END_OF_LINE
119
CommentItemIns.SetHelpStringItem(PreHelpText)
120
CommentInsList.append(CommentItemIns)
122
# Add Current help string
124
CommentItemIns = InfPpiItemCommentContent()
125
CommentItemIns.SetUsage(CommentItemUsage)
126
CommentItemIns.SetNotify(CommentItemNotify)
127
CommentItemIns.SetHelpStringItem(CommentItemHelpText)
128
CommentInsList.append(CommentItemIns)
135
PreUsage = CommentItemUsage
136
PreNotify = CommentItemNotify
137
PreHelpText = CommentItemHelpText
139
InfPpiItemObj.SetCommentList(CommentInsList)
143
class InfPpiItemCommentContent():
146
# ## SOMETIMES_CONSUMES ## HelpString
152
self.HelpStringItem = ''
154
self.CommentList = []
156
def SetUsage(self, UsageItem):
157
self.UsageItem = UsageItem
159
return self.UsageItem
161
def SetNotify(self, Notify):
162
if Notify != DT.ITEM_UNDEFINED:
167
def SetHelpStringItem(self, HelpStringItem):
168
self.HelpStringItem = HelpStringItem
169
def GetHelpStringItem(self):
170
return self.HelpStringItem
175
self.FeatureFlagExp = ''
176
self.SupArchList = []
177
self.CommentList = []
179
def SetName(self, Name):
184
def SetSupArchList(self, SupArchList):
185
self.SupArchList = SupArchList
186
def GetSupArchList(self):
187
return self.SupArchList
189
def SetCommentList(self, CommentList):
190
self.CommentList = CommentList
191
def GetCommentList(self):
192
return self.CommentList
194
def SetFeatureFlagExp(self, FeatureFlagExp):
195
self.FeatureFlagExp = FeatureFlagExp
196
def GetFeatureFlagExp(self):
197
return self.FeatureFlagExp
202
class InfPpiObject():
206
# Macro defined in this section should be only used in this section.
210
def SetPpi(self, PpiList, Arch = None):
212
for ArchItem in Arch:
216
if (ArchItem == '' or ArchItem == None):
218
__SupArchList.append(ArchItem)
222
# Get Comment content of this protocol
226
CommentsList = Item[1]
227
CurrentLineOfItem = Item[2]
229
InfPpiItemObj = InfPpiItem()
230
if len(Item) >= 1 and len(Item) <= 2:
232
# Only CName contained
234
if not IsValidCVariableName(Item[0]):
235
Logger.Error("InfParser",
236
ToolError.FORMAT_INVALID,
237
ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]),
238
File=CurrentLineOfItem[2],
239
Line=CurrentLineOfItem[1],
240
ExtraData=CurrentLineOfItem[0])
242
InfPpiItemObj.SetName(Item[0])
244
Logger.Error("InfParser",
245
ToolError.FORMAT_INVALID,
246
ST.ERR_INF_PARSER_CNAME_MISSING,
247
File=CurrentLineOfItem[2],
248
Line=CurrentLineOfItem[1],
249
ExtraData=CurrentLineOfItem[0])
251
# Have FeatureFlag information
255
# Contained CName and Feature Flag Express
256
# <statements> ::= <CName> ["|" <FeatureFlagExpress>]
257
# Item[1] should not be empty
259
if Item[1].strip() == '':
260
Logger.Error("InfParser",
261
ToolError.FORMAT_INVALID,
262
ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
263
File=CurrentLineOfItem[2],
264
Line=CurrentLineOfItem[1],
265
ExtraData=CurrentLineOfItem[0])
267
# Validate Feature Flag Express for PPI entry
268
# Item[1] contain FFE information
270
FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())
271
if not FeatureFlagRtv[0]:
272
Logger.Error("InfParser",
273
ToolError.FORMAT_INVALID,
274
ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
275
File=CurrentLineOfItem[2],
276
Line=CurrentLineOfItem[1],
277
ExtraData=CurrentLineOfItem[0])
278
InfPpiItemObj.SetFeatureFlagExp(Item[1])
279
if len(Item) != 1 and len(Item) != 2:
281
# Invalid format of Ppi statement
283
Logger.Error("InfParser",
284
ToolError.FORMAT_INVALID,
285
ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,
286
File=CurrentLineOfItem[2],
287
Line=CurrentLineOfItem[1],
288
ExtraData=CurrentLineOfItem[0])
291
# Get/Set Usage and HelpString for PPI entry
293
if CommentsList != None and len(CommentsList) != 0:
294
InfPpiItemObj = ParsePpiComment(CommentsList, InfPpiItemObj)
296
CommentItemIns = InfPpiItemCommentContent()
297
CommentItemIns.SetUsage(DT.ITEM_UNDEFINED)
298
CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
299
InfPpiItemObj.SetCommentList([CommentItemIns])
301
InfPpiItemObj.SetSupArchList(__SupArchList)
304
# Determine PPI name duplicate. Follow below rule:
306
# A PPI must not be duplicated within a [Ppis] section.
307
# A PPI may appear in multiple architectural [Ppis]
308
# sections. A PPI listed in an architectural [Ppis]
309
# section must not be listed in the common architectural
312
# NOTE: This check will not report error now.
314
for Item in self.Ppis:
315
if Item.GetName() == InfPpiItemObj.GetName():
316
ItemSupArchList = Item.GetSupArchList()
317
for ItemArch in ItemSupArchList:
318
for PpiItemObjArch in __SupArchList:
319
if ItemArch == PpiItemObjArch:
321
# ST.ERR_INF_PARSER_ITEM_DUPLICATE
324
if ItemArch.upper() == 'COMMON' or PpiItemObjArch.upper() == 'COMMON':
326
# ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
330
if self.Ppis.has_key((InfPpiItemObj)):
331
PpiList = self.Ppis[InfPpiItemObj]
332
PpiList.append(InfPpiItemObj)
333
self.Ppis[InfPpiItemObj] = PpiList
336
PpiList.append(InfPpiItemObj)
337
self.Ppis[InfPpiItemObj] = PpiList
b'\\ No newline at end of file'