]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 LG |
2 | # This file is used to define class objects of INF file [Guids] section.\r |
3 | # It will consumed by InfParser.\r | |
4234283c | 4 | #\r |
f7496d71 | 5 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 6 | #\r |
2e351cbe | 7 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
4234283c LG |
8 | \r |
9 | '''\r | |
10 | InfGuidObject\r | |
11 | '''\r | |
12 | \r | |
13 | from Library.ParserValidate import IsValidCVariableName\r | |
14 | from Library.CommentParsing import ParseComment\r | |
f7496d71 LG |
15 | from Library.ExpressionValidate import IsValidFeatureFlagExp\r |
16 | \r | |
4234283c | 17 | from Library.Misc import Sdict\r |
f7496d71 | 18 | from Library import DataType as DT\r |
4234283c LG |
19 | import Logger.Log as Logger\r |
20 | from Logger import ToolError\r | |
21 | from Logger import StringTable as ST\r | |
22 | \r | |
23 | class InfGuidItemCommentContent():\r | |
24 | def __init__(self):\r | |
25 | #\r | |
f7496d71 | 26 | # ## SOMETIMES_CONSUMES ## Variable:L"MemoryTypeInformation"\r |
4234283c LG |
27 | # TailString.\r |
28 | #\r | |
29 | #\r | |
30 | # SOMETIMES_CONSUMES\r | |
31 | #\r | |
32 | self.UsageItem = ''\r | |
33 | #\r | |
34 | # Variable\r | |
35 | #\r | |
36 | self.GuidTypeItem = ''\r | |
37 | #\r | |
38 | # MemoryTypeInformation\r | |
39 | #\r | |
40 | self.VariableNameItem = ''\r | |
41 | #\r | |
42 | # TailString\r | |
43 | #\r | |
44 | self.HelpStringItem = ''\r | |
f7496d71 | 45 | \r |
4234283c LG |
46 | def SetUsageItem(self, UsageItem):\r |
47 | self.UsageItem = UsageItem\r | |
48 | def GetUsageItem(self):\r | |
49 | return self.UsageItem\r | |
f7496d71 | 50 | \r |
4234283c LG |
51 | def SetGuidTypeItem(self, GuidTypeItem):\r |
52 | self.GuidTypeItem = GuidTypeItem\r | |
53 | def GetGuidTypeItem(self):\r | |
54 | return self.GuidTypeItem\r | |
f7496d71 | 55 | \r |
4234283c LG |
56 | def SetVariableNameItem(self, VariableNameItem):\r |
57 | self.VariableNameItem = VariableNameItem\r | |
58 | def GetVariableNameItem(self):\r | |
59 | return self.VariableNameItem\r | |
f7496d71 | 60 | \r |
4234283c LG |
61 | def SetHelpStringItem(self, HelpStringItem):\r |
62 | self.HelpStringItem = HelpStringItem\r | |
63 | def GetHelpStringItem(self):\r | |
64 | return self.HelpStringItem\r | |
f7496d71 | 65 | \r |
4234283c LG |
66 | class InfGuidItem():\r |
67 | def __init__(self):\r | |
68 | self.Name = ''\r | |
69 | self.FeatureFlagExp = ''\r | |
70 | #\r | |
71 | # A list contain instance of InfGuidItemCommentContent\r | |
72 | #\r | |
73 | self.CommentList = []\r | |
74 | self.SupArchList = []\r | |
f7496d71 | 75 | \r |
4234283c LG |
76 | def SetName(self, Name):\r |
77 | self.Name = Name\r | |
78 | def GetName(self):\r | |
79 | return self.Name\r | |
f7496d71 | 80 | \r |
4234283c LG |
81 | def SetFeatureFlagExp(self, FeatureFlagExp):\r |
82 | self.FeatureFlagExp = FeatureFlagExp\r | |
83 | def GetFeatureFlagExp(self):\r | |
84 | return self.FeatureFlagExp\r | |
f7496d71 | 85 | \r |
4234283c LG |
86 | def SetCommentList(self, CommentList):\r |
87 | self.CommentList = CommentList\r | |
88 | def GetCommentList(self):\r | |
89 | return self.CommentList\r | |
f7496d71 | 90 | \r |
4234283c LG |
91 | def SetSupArchList(self, SupArchList):\r |
92 | self.SupArchList = SupArchList\r | |
93 | def GetSupArchList(self):\r | |
94 | return self.SupArchList\r | |
95 | \r | |
96 | ## ParseComment\r | |
97 | #\r | |
98 | # ParseComment\r | |
99 | #\r | |
100 | def ParseGuidComment(CommentsList, InfGuidItemObj):\r | |
101 | #\r | |
102 | # Get/Set Usage and HelpString\r | |
103 | #\r | |
4231a819 | 104 | if CommentsList is not None and len(CommentsList) != 0 :\r |
4234283c LG |
105 | CommentInsList = []\r |
106 | PreUsage = None\r | |
107 | PreGuidType = None\r | |
108 | PreHelpText = ''\r | |
109 | BlockFlag = -1\r | |
110 | Count = 0\r | |
111 | for CommentItem in CommentsList:\r | |
112 | Count = Count + 1\r | |
113 | CommentItemUsage, \\r | |
114 | CommentItemGuidType, \\r | |
115 | CommentItemVarString, \\r | |
116 | CommentItemHelpText = \\r | |
f7496d71 LG |
117 | ParseComment(CommentItem,\r |
118 | DT.ALL_USAGE_TOKENS,\r | |
119 | DT.GUID_TYPE_TOKENS,\r | |
120 | [],\r | |
4234283c | 121 | True)\r |
f7496d71 | 122 | \r |
4231a819 | 123 | if CommentItemHelpText is None:\r |
4234283c LG |
124 | CommentItemHelpText = ''\r |
125 | if Count == len(CommentsList) and CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:\r | |
126 | CommentItemHelpText = DT.END_OF_LINE\r | |
f7496d71 | 127 | \r |
4234283c LG |
128 | if Count == len(CommentsList):\r |
129 | if BlockFlag == 1 or BlockFlag == 2:\r | |
130 | if CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:\r | |
131 | BlockFlag = 4\r | |
132 | else:\r | |
133 | BlockFlag = 3\r | |
134 | if BlockFlag == -1:\r | |
f7496d71 | 135 | BlockFlag = 4\r |
4234283c LG |
136 | if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:\r |
137 | if CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:\r | |
138 | if BlockFlag == -1:\r | |
139 | BlockFlag = 1\r | |
140 | elif BlockFlag == 1:\r | |
141 | BlockFlag = 2\r | |
142 | else:\r | |
143 | if BlockFlag == 1 or BlockFlag == 2:\r | |
144 | BlockFlag = 3\r | |
145 | elif BlockFlag == -1:\r | |
146 | BlockFlag = 4\r | |
f7496d71 | 147 | \r |
4234283c LG |
148 | #\r |
149 | # Combine two comment line if they are generic comment\r | |
f7496d71 | 150 | #\r |
4234283c LG |
151 | if CommentItemUsage == CommentItemGuidType == PreUsage == PreGuidType == DT.ITEM_UNDEFINED:\r |
152 | CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText\r | |
4234283c | 153 | PreHelpText = CommentItemHelpText\r |
f7496d71 LG |
154 | \r |
155 | if BlockFlag == 4:\r | |
4234283c LG |
156 | CommentItemIns = InfGuidItemCommentContent()\r |
157 | CommentItemIns.SetUsageItem(CommentItemUsage)\r | |
158 | CommentItemIns.SetGuidTypeItem(CommentItemGuidType)\r | |
159 | CommentItemIns.SetVariableNameItem(CommentItemVarString)\r | |
421ccda3 HC |
160 | if CommentItemHelpText == '' or CommentItemHelpText.endswith(DT.END_OF_LINE):\r |
161 | CommentItemHelpText = CommentItemHelpText.strip(DT.END_OF_LINE)\r | |
4234283c LG |
162 | CommentItemIns.SetHelpStringItem(CommentItemHelpText)\r |
163 | CommentInsList.append(CommentItemIns)\r | |
f7496d71 | 164 | \r |
4234283c LG |
165 | BlockFlag = -1\r |
166 | PreUsage = None\r | |
167 | PreGuidType = None\r | |
168 | PreHelpText = ''\r | |
f7496d71 | 169 | \r |
4234283c LG |
170 | elif BlockFlag == 3:\r |
171 | #\r | |
172 | # Add previous help string\r | |
f7496d71 | 173 | #\r |
4234283c LG |
174 | CommentItemIns = InfGuidItemCommentContent()\r |
175 | CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)\r | |
176 | CommentItemIns.SetGuidTypeItem(DT.ITEM_UNDEFINED)\r | |
177 | if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):\r | |
421ccda3 | 178 | PreHelpText = PreHelpText.strip(DT.END_OF_LINE)\r |
4234283c LG |
179 | CommentItemIns.SetHelpStringItem(PreHelpText)\r |
180 | CommentInsList.append(CommentItemIns)\r | |
181 | #\r | |
182 | # Add Current help string\r | |
183 | #\r | |
184 | CommentItemIns = InfGuidItemCommentContent()\r | |
185 | CommentItemIns.SetUsageItem(CommentItemUsage)\r | |
186 | CommentItemIns.SetGuidTypeItem(CommentItemGuidType)\r | |
187 | CommentItemIns.SetVariableNameItem(CommentItemVarString)\r | |
421ccda3 HC |
188 | if CommentItemHelpText == '' or CommentItemHelpText.endswith(DT.END_OF_LINE):\r |
189 | CommentItemHelpText = CommentItemHelpText.strip(DT.END_OF_LINE)\r | |
4234283c LG |
190 | CommentItemIns.SetHelpStringItem(CommentItemHelpText)\r |
191 | CommentInsList.append(CommentItemIns)\r | |
f7496d71 | 192 | \r |
4234283c LG |
193 | BlockFlag = -1\r |
194 | PreUsage = None\r | |
195 | PreGuidType = None\r | |
f7496d71 LG |
196 | PreHelpText = ''\r |
197 | \r | |
4234283c LG |
198 | else:\r |
199 | PreUsage = CommentItemUsage\r | |
200 | PreGuidType = CommentItemGuidType\r | |
201 | PreHelpText = CommentItemHelpText\r | |
f7496d71 | 202 | \r |
4234283c LG |
203 | InfGuidItemObj.SetCommentList(CommentInsList)\r |
204 | else:\r | |
205 | #\r | |
206 | # Still need to set the USAGE/GUIDTYPE to undefined.\r | |
207 | #\r | |
208 | CommentItemIns = InfGuidItemCommentContent()\r | |
209 | CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)\r | |
210 | CommentItemIns.SetGuidTypeItem(DT.ITEM_UNDEFINED)\r | |
211 | InfGuidItemObj.SetCommentList([CommentItemIns])\r | |
f7496d71 | 212 | \r |
4234283c LG |
213 | return InfGuidItemObj\r |
214 | \r | |
215 | ## InfGuidObject\r | |
216 | #\r | |
217 | # InfGuidObject\r | |
218 | #\r | |
219 | class InfGuidObject():\r | |
220 | def __init__(self):\r | |
221 | self.Guids = Sdict()\r | |
222 | #\r | |
223 | # Macro defined in this section should be only used in this section.\r | |
224 | #\r | |
225 | self.Macros = {}\r | |
f7496d71 | 226 | \r |
4234283c LG |
227 | def SetGuid(self, GuidList, Arch = None):\r |
228 | __SupportArchList = []\r | |
229 | for ArchItem in Arch:\r | |
230 | #\r | |
231 | # Validate Arch\r | |
f7496d71 | 232 | #\r |
4231a819 | 233 | if (ArchItem == '' or ArchItem is None):\r |
f7496d71 LG |
234 | ArchItem = 'COMMON'\r |
235 | \r | |
4234283c | 236 | __SupportArchList.append(ArchItem)\r |
f7496d71 | 237 | \r |
4234283c LG |
238 | for Item in GuidList:\r |
239 | #\r | |
240 | # Get Comment content of this protocol\r | |
241 | #\r | |
242 | CommentsList = None\r | |
243 | if len(Item) == 3:\r | |
244 | CommentsList = Item[1]\r | |
245 | CurrentLineOfItem = Item[2]\r | |
246 | Item = Item[0]\r | |
f7496d71 | 247 | InfGuidItemObj = InfGuidItem()\r |
4234283c LG |
248 | if len(Item) >= 1 and len(Item) <= 2:\r |
249 | #\r | |
250 | # Only GuildName contained\r | |
251 | #\r | |
252 | if not IsValidCVariableName(Item[0]):\r | |
f7496d71 LG |
253 | Logger.Error("InfParser",\r |
254 | ToolError.FORMAT_INVALID,\r | |
4234283c | 255 | ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]),\r |
f7496d71 LG |
256 | File=CurrentLineOfItem[2],\r |
257 | Line=CurrentLineOfItem[1],\r | |
4234283c LG |
258 | ExtraData=CurrentLineOfItem[0])\r |
259 | if (Item[0] != ''):\r | |
260 | InfGuidItemObj.SetName(Item[0])\r | |
261 | else:\r | |
f7496d71 LG |
262 | Logger.Error("InfParser",\r |
263 | ToolError.FORMAT_INVALID,\r | |
4234283c | 264 | ST.ERR_INF_PARSER_CNAME_MISSING,\r |
f7496d71 LG |
265 | File=CurrentLineOfItem[2],\r |
266 | Line=CurrentLineOfItem[1],\r | |
4234283c LG |
267 | ExtraData=CurrentLineOfItem[0])\r |
268 | if len(Item) == 2:\r | |
269 | #\r | |
270 | # Contained CName and Feature Flag Express\r | |
271 | # <statements> ::= <CName> ["|" <FeatureFlagExpress>]\r | |
f7496d71 | 272 | # For GUID entry.\r |
4234283c LG |
273 | #\r |
274 | if Item[1].strip() == '':\r | |
f7496d71 LG |
275 | Logger.Error("InfParser",\r |
276 | ToolError.FORMAT_INVALID,\r | |
4234283c | 277 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,\r |
f7496d71 LG |
278 | File=CurrentLineOfItem[2],\r |
279 | Line=CurrentLineOfItem[1],\r | |
4234283c LG |
280 | ExtraData=CurrentLineOfItem[0])\r |
281 | #\r | |
f7496d71 | 282 | # Validate Feature Flag Express\r |
4234283c LG |
283 | #\r |
284 | FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())\r | |
285 | if not FeatureFlagRtv[0]:\r | |
f7496d71 | 286 | Logger.Error("InfParser",\r |
4234283c LG |
287 | ToolError.FORMAT_INVALID,\r |
288 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),\r | |
f7496d71 LG |
289 | File=CurrentLineOfItem[2],\r |
290 | Line=CurrentLineOfItem[1],\r | |
4234283c LG |
291 | ExtraData=CurrentLineOfItem[0])\r |
292 | InfGuidItemObj.SetFeatureFlagExp(Item[1])\r | |
293 | if len(Item) != 1 and len(Item) != 2:\r | |
294 | #\r | |
f7496d71 | 295 | # Invalid format of GUID statement\r |
4234283c | 296 | #\r |
f7496d71 | 297 | Logger.Error("InfParser",\r |
4234283c LG |
298 | ToolError.FORMAT_INVALID,\r |
299 | ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,\r | |
f7496d71 LG |
300 | File=CurrentLineOfItem[2],\r |
301 | Line=CurrentLineOfItem[1],\r | |
4234283c | 302 | ExtraData=CurrentLineOfItem[0])\r |
f7496d71 | 303 | \r |
4234283c LG |
304 | InfGuidItemObj = ParseGuidComment(CommentsList, InfGuidItemObj)\r |
305 | InfGuidItemObj.SetSupArchList(__SupportArchList)\r | |
f7496d71 | 306 | \r |
4234283c LG |
307 | #\r |
308 | # Determine GUID name duplicate. Follow below rule:\r | |
309 | #\r | |
f7496d71 LG |
310 | # A GUID must not be duplicated within a [Guids] section.\r |
311 | # A GUID may appear in multiple architectural [Guids]\r | |
312 | # sections. A GUID listed in an architectural [Guids]\r | |
313 | # section must not be listed in the common architectural\r | |
4234283c | 314 | # [Guids] section.\r |
f7496d71 | 315 | #\r |
4234283c | 316 | # NOTE: This check will not report error now.\r |
f7496d71 | 317 | #\r |
4234283c LG |
318 | for Item in self.Guids:\r |
319 | if Item.GetName() == InfGuidItemObj.GetName():\r | |
320 | ItemSupArchList = Item.GetSupArchList()\r | |
321 | for ItemArch in ItemSupArchList:\r | |
322 | for GuidItemObjArch in __SupportArchList:\r | |
323 | if ItemArch == GuidItemObjArch:\r | |
324 | #\r | |
325 | # ST.ERR_INF_PARSER_ITEM_DUPLICATE\r | |
326 | #\r | |
327 | pass\r | |
328 | \r | |
329 | if ItemArch.upper() == 'COMMON' or GuidItemObjArch.upper() == 'COMMON':\r | |
330 | #\r | |
331 | # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON\r | |
332 | #\r | |
333 | pass\r | |
f7496d71 | 334 | \r |
27c4ceb4 | 335 | if (InfGuidItemObj) in self.Guids:\r |
f7496d71 | 336 | GuidList = self.Guids[InfGuidItemObj]\r |
4234283c LG |
337 | GuidList.append(InfGuidItemObj)\r |
338 | self.Guids[InfGuidItemObj] = GuidList\r | |
339 | else:\r | |
340 | GuidList = []\r | |
341 | GuidList.append(InfGuidItemObj)\r | |
342 | self.Guids[InfGuidItemObj] = GuidList\r | |
f7496d71 | 343 | \r |
4234283c | 344 | return True\r |
f7496d71 | 345 | \r |
4234283c | 346 | def GetGuid(self):\r |
27c4ceb4 | 347 | return self.Guids\r |