Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

306 lines
11 KiB
Python
Raw Permalink Normal View History

## @file
2018-07-05 17:40:04 +08:00
# This file is used to define class objects of INF file [Protocols] section.
# It will consumed by InfParser.
#
2018-07-05 17:40:04 +08:00
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
'''
InfProtocolObject
'''
from Library.ParserValidate import IsValidCVariableName
from Library.CommentParsing import ParseComment
2018-07-05 17:40:04 +08:00
from Library.ExpressionValidate import IsValidFeatureFlagExp
from Library.Misc import Sdict
from Object.Parser.InfMisc import ErrorInInf
from Library import DataType as DT
from Logger import StringTable as ST
def ParseProtocolComment(CommentsList, InfProtocolItemObj):
CommentInsList = []
PreUsage = None
PreNotify = None
PreHelpText = ''
BlockFlag = -1
Count = 0
for CommentItem in CommentsList:
Count = Count + 1
CommentItemUsage, \
CommentItemNotify, \
CommentItemString, \
CommentItemHelpText = \
2018-07-05 17:40:04 +08:00
ParseComment(CommentItem,
DT.PROTOCOL_USAGE_TOKENS,
DT.PROTOCOL_NOTIFY_TOKENS,
['PROTOCOL'],
False)
2018-07-05 17:40:04 +08:00
if CommentItemString:
pass
2018-07-05 17:40:04 +08:00
if CommentItemHelpText is None:
CommentItemHelpText = ''
if Count == len(CommentsList) and CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
CommentItemHelpText = DT.END_OF_LINE
2018-07-05 17:40:04 +08:00
if Count == len(CommentsList):
if BlockFlag == 1 or BlockFlag == 2:
if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
BlockFlag = 4
else:
BlockFlag = 3
elif BlockFlag == -1:
2018-07-05 17:40:04 +08:00
BlockFlag = 4
if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
if BlockFlag == -1:
BlockFlag = 1
elif BlockFlag == 1:
BlockFlag = 2
else:
if BlockFlag == 1 or BlockFlag == 2:
BlockFlag = 3
elif BlockFlag == -1:
BlockFlag = 4
2018-07-05 17:40:04 +08:00
#
# Combine two comment line if they are generic comment
2018-07-05 17:40:04 +08:00
#
if CommentItemUsage == CommentItemNotify == PreUsage == PreNotify == DT.ITEM_UNDEFINED:
CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText
2018-07-05 17:40:04 +08:00
PreHelpText = CommentItemHelpText
2018-07-05 17:40:04 +08:00
if BlockFlag == 4:
CommentItemIns = InfProtocolItemCommentContent()
CommentItemIns.SetUsageItem(CommentItemUsage)
CommentItemIns.SetNotify(CommentItemNotify)
CommentItemIns.SetHelpStringItem(CommentItemHelpText)
CommentInsList.append(CommentItemIns)
2018-07-05 17:40:04 +08:00
BlockFlag = -1
PreUsage = None
PreNotify = None
PreHelpText = ''
2018-07-05 17:40:04 +08:00
elif BlockFlag == 3:
#
# Add previous help string
2018-07-05 17:40:04 +08:00
#
CommentItemIns = InfProtocolItemCommentContent()
CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
2018-07-05 17:40:04 +08:00
PreHelpText += DT.END_OF_LINE
CommentItemIns.SetHelpStringItem(PreHelpText)
CommentInsList.append(CommentItemIns)
#
# Add Current help string
#
CommentItemIns = InfProtocolItemCommentContent()
CommentItemIns.SetUsageItem(CommentItemUsage)
CommentItemIns.SetNotify(CommentItemNotify)
CommentItemIns.SetHelpStringItem(CommentItemHelpText)
CommentInsList.append(CommentItemIns)
2018-07-05 17:40:04 +08:00
BlockFlag = -1
PreUsage = None
PreNotify = None
2018-07-05 17:40:04 +08:00
PreHelpText = ''
else:
PreUsage = CommentItemUsage
PreNotify = CommentItemNotify
PreHelpText = CommentItemHelpText
2018-07-05 17:40:04 +08:00
InfProtocolItemObj.SetCommentList(CommentInsList)
2018-07-05 17:40:04 +08:00
return InfProtocolItemObj
class InfProtocolItemCommentContent():
def __init__(self):
#
2018-07-05 17:40:04 +08:00
# ## SOMETIMES_CONSUMES ## HelpString
#
self.UsageItem = ''
#
# Help String
#
self.HelpStringItem = ''
self.Notify = ''
self.CommentList = []
2018-07-05 17:40:04 +08:00
def SetUsageItem(self, UsageItem):
self.UsageItem = UsageItem
def GetUsageItem(self):
return self.UsageItem
2018-07-05 17:40:04 +08:00
def SetNotify(self, Notify):
if Notify != DT.ITEM_UNDEFINED:
self.Notify = 'true'
def GetNotify(self):
return self.Notify
2018-07-05 17:40:04 +08:00
def SetHelpStringItem(self, HelpStringItem):
self.HelpStringItem = HelpStringItem
def GetHelpStringItem(self):
return self.HelpStringItem
2018-07-05 17:40:04 +08:00
class InfProtocolItem():
def __init__(self):
self.Name = ''
self.FeatureFlagExp = ''
self.SupArchList = []
self.CommentList = []
2018-07-05 17:40:04 +08:00
def SetName(self, Name):
self.Name = Name
def GetName(self):
return self.Name
2018-07-05 17:40:04 +08:00
def SetFeatureFlagExp(self, FeatureFlagExp):
self.FeatureFlagExp = FeatureFlagExp
def GetFeatureFlagExp(self):
return self.FeatureFlagExp
2018-07-05 17:40:04 +08:00
def SetSupArchList(self, SupArchList):
self.SupArchList = SupArchList
def GetSupArchList(self):
2018-07-05 17:40:04 +08:00
return self.SupArchList
def SetCommentList(self, CommentList):
self.CommentList = CommentList
def GetCommentList(self):
return self.CommentList
##
#
#
#
class InfProtocolObject():
def __init__(self):
self.Protocols = Sdict()
#
# Macro defined in this section should be only used in this section.
#
self.Macros = {}
2018-07-05 17:40:04 +08:00
def SetProtocol(self, ProtocolContent, Arch = None,):
__SupArchList = []
for ArchItem in Arch:
#
# Validate Arch
2018-07-05 17:40:04 +08:00
#
if (ArchItem == '' or ArchItem is None):
ArchItem = 'COMMON'
__SupArchList.append(ArchItem)
for Item in ProtocolContent:
#
# Get Comment content of this protocol
#
CommentsList = None
if len(Item) == 3:
CommentsList = Item[1]
CurrentLineOfItem = Item[2]
LineInfo = (CurrentLineOfItem[2], CurrentLineOfItem[1], CurrentLineOfItem[0])
Item = Item[0]
InfProtocolItemObj = InfProtocolItem()
if len(Item) >= 1 and len(Item) <= 2:
#
# Only CName contained
#
if not IsValidCVariableName(Item[0]):
ErrorInInf(ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]),
LineInfo=LineInfo)
if (Item[0] != ''):
InfProtocolItemObj.SetName(Item[0])
else:
ErrorInInf(ST.ERR_INF_PARSER_CNAME_MISSING,
LineInfo=LineInfo)
if len(Item) == 2:
#
# Contained CName and Feature Flag Express
2018-07-05 17:40:04 +08:00
# <statements> ::= <CName> ["|"
# <FeatureFlagExpress>]
# For Protocol Object
#
if Item[1].strip() == '':
ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
LineInfo=LineInfo)
#
# Validate Feature Flag Express for Item[1]
#
FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())
if not FeatureFlagRtv[0]:
ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
LineInfo=LineInfo)
InfProtocolItemObj.SetFeatureFlagExp(Item[1])
2018-07-05 17:40:04 +08:00
if len(Item) < 1 or len(Item) > 2:
#
2018-07-05 17:40:04 +08:00
# Invalid format of Protocols statement
#
ErrorInInf(ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,
LineInfo=LineInfo)
2018-07-05 17:40:04 +08:00
#
# Get/Set Usage and HelpString for Protocol entry
#
if CommentsList is not None and len(CommentsList) != 0:
InfProtocolItemObj = ParseProtocolComment(CommentsList, InfProtocolItemObj)
else:
CommentItemIns = InfProtocolItemCommentContent()
CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
InfProtocolItemObj.SetCommentList([CommentItemIns])
2018-07-05 17:40:04 +08:00
InfProtocolItemObj.SetSupArchList(__SupArchList)
2018-07-05 17:40:04 +08:00
#
# Determine protocol name duplicate. Follow below rule:
#
2018-07-05 17:40:04 +08:00
# A protocol must not be duplicated within a [Protocols] section.
# A protocol may appear in multiple architectural [Protocols]
# sections. A protocol listed in an architectural [Protocols]
# section must not be listed in the common architectural
# [Protocols] section.
2018-07-05 17:40:04 +08:00
#
# NOTE: This check will not report error now.
2018-07-05 17:40:04 +08:00
#
for Item in self.Protocols:
if Item.GetName() == InfProtocolItemObj.GetName():
ItemSupArchList = Item.GetSupArchList()
for ItemArch in ItemSupArchList:
for ProtocolItemObjArch in __SupArchList:
if ItemArch == ProtocolItemObjArch:
#
# ST.ERR_INF_PARSER_ITEM_DUPLICATE
#
pass
if ItemArch.upper() == 'COMMON' or ProtocolItemObjArch.upper() == 'COMMON':
#
# ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
#
2018-07-05 17:40:04 +08:00
pass
2018-06-25 18:31:29 +08:00
if (InfProtocolItemObj) in self.Protocols:
ProcotolList = self.Protocols[InfProtocolItemObj]
ProcotolList.append(InfProtocolItemObj)
self.Protocols[InfProtocolItemObj] = ProcotolList
else:
ProcotolList = []
ProcotolList.append(InfProtocolItemObj)
self.Protocols[InfProtocolItemObj] = ProcotolList
2018-07-05 17:40:04 +08:00
return True
2018-07-05 17:40:04 +08:00
def GetProtocol(self):
return self.Protocols