2 # This file is used to define class objects of INF file [Protocols] 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
25 from Object
.Parser
.InfMisc
import ErrorInInf
27 from Library
import DataType
as DT
28 from Logger
import StringTable
as ST
30 def ParseProtocolComment(CommentsList
, InfProtocolItemObj
):
37 for CommentItem
in CommentsList
:
42 CommentItemHelpText
= \
43 ParseComment(CommentItem
,
44 DT
.PROTOCOL_USAGE_TOKENS
,
45 DT
.PROTOCOL_NOTIFY_TOKENS
,
52 if CommentItemHelpText
== None:
53 CommentItemHelpText
= ''
54 if Count
== len(CommentsList
) and CommentItemUsage
== CommentItemNotify
== DT
.ITEM_UNDEFINED
:
55 CommentItemHelpText
= DT
.END_OF_LINE
57 if Count
== len(CommentsList
):
58 if BlockFlag
== 1 or BlockFlag
== 2:
59 if CommentItemUsage
== CommentItemNotify
== DT
.ITEM_UNDEFINED
:
66 if BlockFlag
== -1 or BlockFlag
== 1 or BlockFlag
== 2:
67 if CommentItemUsage
== CommentItemNotify
== DT
.ITEM_UNDEFINED
:
73 if BlockFlag
== 1 or BlockFlag
== 2:
79 # Combine two comment line if they are generic comment
81 if CommentItemUsage
== CommentItemNotify
== PreUsage
== PreNotify
== DT
.ITEM_UNDEFINED
:
82 CommentItemHelpText
= PreHelpText
+ DT
.END_OF_LINE
+ CommentItemHelpText
84 PreHelpText
= CommentItemHelpText
87 CommentItemIns
= InfProtocolItemCommentContent()
88 CommentItemIns
.SetUsageItem(CommentItemUsage
)
89 CommentItemIns
.SetNotify(CommentItemNotify
)
90 CommentItemIns
.SetHelpStringItem(CommentItemHelpText
)
91 CommentInsList
.append(CommentItemIns
)
100 # Add previous help string
102 CommentItemIns
= InfProtocolItemCommentContent()
103 CommentItemIns
.SetUsageItem(DT
.ITEM_UNDEFINED
)
104 CommentItemIns
.SetNotify(DT
.ITEM_UNDEFINED
)
105 if PreHelpText
== '' or PreHelpText
.endswith(DT
.END_OF_LINE
):
106 PreHelpText
+= DT
.END_OF_LINE
107 CommentItemIns
.SetHelpStringItem(PreHelpText
)
108 CommentInsList
.append(CommentItemIns
)
110 # Add Current help string
112 CommentItemIns
= InfProtocolItemCommentContent()
113 CommentItemIns
.SetUsageItem(CommentItemUsage
)
114 CommentItemIns
.SetNotify(CommentItemNotify
)
115 CommentItemIns
.SetHelpStringItem(CommentItemHelpText
)
116 CommentInsList
.append(CommentItemIns
)
124 PreUsage
= CommentItemUsage
125 PreNotify
= CommentItemNotify
126 PreHelpText
= CommentItemHelpText
128 InfProtocolItemObj
.SetCommentList(CommentInsList
)
130 return InfProtocolItemObj
132 class InfProtocolItemCommentContent():
135 # ## SOMETIMES_CONSUMES ## HelpString
141 self
.HelpStringItem
= ''
143 self
.CommentList
= []
145 def SetUsageItem(self
, UsageItem
):
146 self
.UsageItem
= UsageItem
147 def GetUsageItem(self
):
148 return self
.UsageItem
150 def SetNotify(self
, Notify
):
151 if Notify
!= DT
.ITEM_UNDEFINED
:
156 def SetHelpStringItem(self
, HelpStringItem
):
157 self
.HelpStringItem
= HelpStringItem
158 def GetHelpStringItem(self
):
159 return self
.HelpStringItem
161 class InfProtocolItem():
164 self
.FeatureFlagExp
= ''
165 self
.SupArchList
= []
166 self
.CommentList
= []
168 def SetName(self
, Name
):
173 def SetFeatureFlagExp(self
, FeatureFlagExp
):
174 self
.FeatureFlagExp
= FeatureFlagExp
175 def GetFeatureFlagExp(self
):
176 return self
.FeatureFlagExp
178 def SetSupArchList(self
, SupArchList
):
179 self
.SupArchList
= SupArchList
180 def GetSupArchList(self
):
181 return self
.SupArchList
183 def SetCommentList(self
, CommentList
):
184 self
.CommentList
= CommentList
185 def GetCommentList(self
):
186 return self
.CommentList
192 class InfProtocolObject():
194 self
.Protocols
= Sdict()
196 # Macro defined in this section should be only used in this section.
200 def SetProtocol(self
, ProtocolContent
, Arch
= None,):
202 for ArchItem
in Arch
:
206 if (ArchItem
== '' or ArchItem
== None):
208 __SupArchList
.append(ArchItem
)
210 for Item
in ProtocolContent
:
212 # Get Comment content of this protocol
216 CommentsList
= Item
[1]
217 CurrentLineOfItem
= Item
[2]
218 LineInfo
= (CurrentLineOfItem
[2], CurrentLineOfItem
[1], CurrentLineOfItem
[0])
220 InfProtocolItemObj
= InfProtocolItem()
221 if len(Item
) >= 1 and len(Item
) <= 2:
223 # Only CName contained
225 if not IsValidCVariableName(Item
[0]):
226 ErrorInInf(ST
.ERR_INF_PARSER_INVALID_CNAME
%(Item
[0]),
229 InfProtocolItemObj
.SetName(Item
[0])
231 ErrorInInf(ST
.ERR_INF_PARSER_CNAME_MISSING
,
235 # Contained CName and Feature Flag Express
236 # <statements> ::= <CName> ["|"
237 # <FeatureFlagExpress>]
238 # For Protocol Object
240 if Item
[1].strip() == '':
241 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
244 # Validate Feature Flag Express for Item[1]
246 FeatureFlagRtv
= IsValidFeatureFlagExp(Item
[1].strip())
247 if not FeatureFlagRtv
[0]:
248 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
250 InfProtocolItemObj
.SetFeatureFlagExp(Item
[1])
252 if len(Item
) < 1 or len(Item
) > 2:
254 # Invalid format of Protocols statement
256 ErrorInInf(ST
.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR
,
260 # Get/Set Usage and HelpString for Protocol entry
262 if CommentsList
!= None and len(CommentsList
) != 0:
263 InfProtocolItemObj
= ParseProtocolComment(CommentsList
, InfProtocolItemObj
)
265 CommentItemIns
= InfProtocolItemCommentContent()
266 CommentItemIns
.SetUsageItem(DT
.ITEM_UNDEFINED
)
267 CommentItemIns
.SetNotify(DT
.ITEM_UNDEFINED
)
268 InfProtocolItemObj
.SetCommentList([CommentItemIns
])
270 InfProtocolItemObj
.SetSupArchList(__SupArchList
)
273 # Determine protocol name duplicate. Follow below rule:
275 # A protocol must not be duplicated within a [Protocols] section.
276 # A protocol may appear in multiple architectural [Protocols]
277 # sections. A protocol listed in an architectural [Protocols]
278 # section must not be listed in the common architectural
279 # [Protocols] section.
281 # NOTE: This check will not report error now.
283 for Item
in self
.Protocols
:
284 if Item
.GetName() == InfProtocolItemObj
.GetName():
285 ItemSupArchList
= Item
.GetSupArchList()
286 for ItemArch
in ItemSupArchList
:
287 for ProtocolItemObjArch
in __SupArchList
:
288 if ItemArch
== ProtocolItemObjArch
:
290 # ST.ERR_INF_PARSER_ITEM_DUPLICATE
293 if ItemArch
.upper() == 'COMMON' or ProtocolItemObjArch
.upper() == 'COMMON':
295 # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
299 if self
.Protocols
.has_key((InfProtocolItemObj
)):
300 ProcotolList
= self
.Protocols
[InfProtocolItemObj
]
301 ProcotolList
.append(InfProtocolItemObj
)
302 self
.Protocols
[InfProtocolItemObj
] = ProcotolList
305 ProcotolList
.append(InfProtocolItemObj
)
306 self
.Protocols
[InfProtocolItemObj
] = ProcotolList
310 def GetProtocol(self
):
311 return self
.Protocols