2 # This file is used to define class objects of INF file [Ppis] section.
3 # It will consumed by InfParser.
5 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
13 from Library
.ParserValidate
import IsValidCVariableName
14 from Library
.CommentParsing
import ParseComment
15 from Library
.ExpressionValidate
import IsValidFeatureFlagExp
17 from Library
.Misc
import Sdict
18 from Library
import DataType
as DT
19 import Logger
.Log
as Logger
20 from Logger
import ToolError
21 from Logger
import StringTable
as ST
23 def ParsePpiComment(CommentsList
, InfPpiItemObj
):
30 for CommentItem
in CommentsList
:
35 CommentItemHelpText
= \
36 ParseComment(CommentItem
,
43 # To avoid PyLint error
48 if CommentItemHelpText
is None:
49 CommentItemHelpText
= ''
50 if Count
== len(CommentsList
) and CommentItemUsage
== CommentItemNotify
== DT
.ITEM_UNDEFINED
:
51 CommentItemHelpText
= DT
.END_OF_LINE
53 # For the Last comment Item, set BlockFlag.
55 if Count
== len(CommentsList
):
56 if BlockFlag
== 1 or BlockFlag
== 2:
57 if CommentItemUsage
== CommentItemNotify
== DT
.ITEM_UNDEFINED
:
65 # Comment USAGE and NOTIFY information are "UNDEFINED"
67 if BlockFlag
== -1 or BlockFlag
== 1 or BlockFlag
== 2:
68 if CommentItemUsage
== CommentItemNotify
== DT
.ITEM_UNDEFINED
:
74 if BlockFlag
== 1 or BlockFlag
== 2:
77 # An item have Usage or Notify information and the first time get this information
83 # Combine two comment line if they are generic comment
85 if CommentItemUsage
== CommentItemNotify
== PreUsage
== PreNotify
== DT
.ITEM_UNDEFINED
:
86 CommentItemHelpText
= PreHelpText
+ DT
.END_OF_LINE
+ CommentItemHelpText
88 # Store this information for next line may still need combine operation.
90 PreHelpText
= CommentItemHelpText
93 CommentItemIns
= InfPpiItemCommentContent()
94 CommentItemIns
.SetUsage(CommentItemUsage
)
95 CommentItemIns
.SetNotify(CommentItemNotify
)
96 CommentItemIns
.SetHelpStringItem(CommentItemHelpText
)
97 CommentInsList
.append(CommentItemIns
)
106 # Add previous help string
108 CommentItemIns
= InfPpiItemCommentContent()
109 CommentItemIns
.SetUsage(DT
.ITEM_UNDEFINED
)
110 CommentItemIns
.SetNotify(DT
.ITEM_UNDEFINED
)
111 if PreHelpText
== '' or PreHelpText
.endswith(DT
.END_OF_LINE
):
112 PreHelpText
+= DT
.END_OF_LINE
113 CommentItemIns
.SetHelpStringItem(PreHelpText
)
114 CommentInsList
.append(CommentItemIns
)
116 # Add Current help string
118 CommentItemIns
= InfPpiItemCommentContent()
119 CommentItemIns
.SetUsage(CommentItemUsage
)
120 CommentItemIns
.SetNotify(CommentItemNotify
)
121 CommentItemIns
.SetHelpStringItem(CommentItemHelpText
)
122 CommentInsList
.append(CommentItemIns
)
129 PreUsage
= CommentItemUsage
130 PreNotify
= CommentItemNotify
131 PreHelpText
= CommentItemHelpText
133 InfPpiItemObj
.SetCommentList(CommentInsList
)
137 class InfPpiItemCommentContent():
140 # ## SOMETIMES_CONSUMES ## HelpString
146 self
.HelpStringItem
= ''
148 self
.CommentList
= []
150 def SetUsage(self
, UsageItem
):
151 self
.UsageItem
= UsageItem
153 return self
.UsageItem
155 def SetNotify(self
, Notify
):
156 if Notify
!= DT
.ITEM_UNDEFINED
:
161 def SetHelpStringItem(self
, HelpStringItem
):
162 self
.HelpStringItem
= HelpStringItem
163 def GetHelpStringItem(self
):
164 return self
.HelpStringItem
169 self
.FeatureFlagExp
= ''
170 self
.SupArchList
= []
171 self
.CommentList
= []
173 def SetName(self
, Name
):
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
188 def SetFeatureFlagExp(self
, FeatureFlagExp
):
189 self
.FeatureFlagExp
= FeatureFlagExp
190 def GetFeatureFlagExp(self
):
191 return self
.FeatureFlagExp
196 class InfPpiObject():
200 # Macro defined in this section should be only used in this section.
204 def SetPpi(self
, PpiList
, Arch
= None):
206 for ArchItem
in Arch
:
210 if (ArchItem
== '' or ArchItem
is None):
212 __SupArchList
.append(ArchItem
)
216 # Get Comment content of this protocol
220 CommentsList
= Item
[1]
221 CurrentLineOfItem
= Item
[2]
223 InfPpiItemObj
= InfPpiItem()
224 if len(Item
) >= 1 and len(Item
) <= 2:
226 # Only CName contained
228 if not IsValidCVariableName(Item
[0]):
229 Logger
.Error("InfParser",
230 ToolError
.FORMAT_INVALID
,
231 ST
.ERR_INF_PARSER_INVALID_CNAME
%(Item
[0]),
232 File
=CurrentLineOfItem
[2],
233 Line
=CurrentLineOfItem
[1],
234 ExtraData
=CurrentLineOfItem
[0])
236 InfPpiItemObj
.SetName(Item
[0])
238 Logger
.Error("InfParser",
239 ToolError
.FORMAT_INVALID
,
240 ST
.ERR_INF_PARSER_CNAME_MISSING
,
241 File
=CurrentLineOfItem
[2],
242 Line
=CurrentLineOfItem
[1],
243 ExtraData
=CurrentLineOfItem
[0])
245 # Have FeatureFlag information
249 # Contained CName and Feature Flag Express
250 # <statements> ::= <CName> ["|" <FeatureFlagExpress>]
251 # Item[1] should not be empty
253 if Item
[1].strip() == '':
254 Logger
.Error("InfParser",
255 ToolError
.FORMAT_INVALID
,
256 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
257 File
=CurrentLineOfItem
[2],
258 Line
=CurrentLineOfItem
[1],
259 ExtraData
=CurrentLineOfItem
[0])
261 # Validate Feature Flag Express for PPI entry
262 # Item[1] contain FFE information
264 FeatureFlagRtv
= IsValidFeatureFlagExp(Item
[1].strip())
265 if not FeatureFlagRtv
[0]:
266 Logger
.Error("InfParser",
267 ToolError
.FORMAT_INVALID
,
268 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
269 File
=CurrentLineOfItem
[2],
270 Line
=CurrentLineOfItem
[1],
271 ExtraData
=CurrentLineOfItem
[0])
272 InfPpiItemObj
.SetFeatureFlagExp(Item
[1])
273 if len(Item
) != 1 and len(Item
) != 2:
275 # Invalid format of Ppi statement
277 Logger
.Error("InfParser",
278 ToolError
.FORMAT_INVALID
,
279 ST
.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR
,
280 File
=CurrentLineOfItem
[2],
281 Line
=CurrentLineOfItem
[1],
282 ExtraData
=CurrentLineOfItem
[0])
285 # Get/Set Usage and HelpString for PPI entry
287 if CommentsList
is not None and len(CommentsList
) != 0:
288 InfPpiItemObj
= ParsePpiComment(CommentsList
, InfPpiItemObj
)
290 CommentItemIns
= InfPpiItemCommentContent()
291 CommentItemIns
.SetUsage(DT
.ITEM_UNDEFINED
)
292 CommentItemIns
.SetNotify(DT
.ITEM_UNDEFINED
)
293 InfPpiItemObj
.SetCommentList([CommentItemIns
])
295 InfPpiItemObj
.SetSupArchList(__SupArchList
)
298 # Determine PPI name duplicate. Follow below rule:
300 # A PPI must not be duplicated within a [Ppis] section.
301 # A PPI may appear in multiple architectural [Ppis]
302 # sections. A PPI listed in an architectural [Ppis]
303 # section must not be listed in the common architectural
306 # NOTE: This check will not report error now.
308 for Item
in self
.Ppis
:
309 if Item
.GetName() == InfPpiItemObj
.GetName():
310 ItemSupArchList
= Item
.GetSupArchList()
311 for ItemArch
in ItemSupArchList
:
312 for PpiItemObjArch
in __SupArchList
:
313 if ItemArch
== PpiItemObjArch
:
315 # ST.ERR_INF_PARSER_ITEM_DUPLICATE
318 if ItemArch
.upper() == 'COMMON' or PpiItemObjArch
.upper() == 'COMMON':
320 # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
324 if (InfPpiItemObj
) in self
.Ppis
:
325 PpiList
= self
.Ppis
[InfPpiItemObj
]
326 PpiList
.append(InfPpiItemObj
)
327 self
.Ppis
[InfPpiItemObj
] = PpiList
330 PpiList
.append(InfPpiItemObj
)
331 self
.Ppis
[InfPpiItemObj
] = PpiList