]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 LG |
2 | # This file is used to define class objects of INF file [Protocols] 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 | InfProtocolObject\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 LG |
17 | from Library.Misc import Sdict\r |
18 | \r | |
19 | from Object.Parser.InfMisc import ErrorInInf\r | |
20 | \r | |
21 | from Library import DataType as DT\r | |
22 | from Logger import StringTable as ST\r | |
23 | \r | |
24 | def ParseProtocolComment(CommentsList, InfProtocolItemObj):\r | |
25 | CommentInsList = []\r | |
26 | PreUsage = None\r | |
27 | PreNotify = None\r | |
28 | PreHelpText = ''\r | |
29 | BlockFlag = -1\r | |
30 | Count = 0\r | |
31 | for CommentItem in CommentsList:\r | |
32 | Count = Count + 1\r | |
33 | CommentItemUsage, \\r | |
34 | CommentItemNotify, \\r | |
35 | CommentItemString, \\r | |
36 | CommentItemHelpText = \\r | |
f7496d71 LG |
37 | ParseComment(CommentItem,\r |
38 | DT.PROTOCOL_USAGE_TOKENS,\r | |
39 | DT.PROTOCOL_NOTIFY_TOKENS,\r | |
40 | ['PROTOCOL'],\r | |
4234283c | 41 | False)\r |
f7496d71 | 42 | \r |
4234283c LG |
43 | if CommentItemString:\r |
44 | pass\r | |
f7496d71 | 45 | \r |
4231a819 | 46 | if CommentItemHelpText is None:\r |
4234283c LG |
47 | CommentItemHelpText = ''\r |
48 | if Count == len(CommentsList) and CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:\r | |
49 | CommentItemHelpText = DT.END_OF_LINE\r | |
f7496d71 | 50 | \r |
4234283c LG |
51 | if Count == len(CommentsList):\r |
52 | if BlockFlag == 1 or BlockFlag == 2:\r | |
53 | if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:\r | |
54 | BlockFlag = 4\r | |
55 | else:\r | |
56 | BlockFlag = 3\r | |
57 | elif BlockFlag == -1:\r | |
f7496d71 LG |
58 | BlockFlag = 4\r |
59 | \r | |
60 | if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:\r | |
4234283c LG |
61 | if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:\r |
62 | if BlockFlag == -1:\r | |
63 | BlockFlag = 1\r | |
64 | elif BlockFlag == 1:\r | |
65 | BlockFlag = 2\r | |
66 | else:\r | |
67 | if BlockFlag == 1 or BlockFlag == 2:\r | |
68 | BlockFlag = 3\r | |
69 | elif BlockFlag == -1:\r | |
70 | BlockFlag = 4\r | |
f7496d71 | 71 | \r |
4234283c LG |
72 | #\r |
73 | # Combine two comment line if they are generic comment\r | |
f7496d71 | 74 | #\r |
4234283c LG |
75 | if CommentItemUsage == CommentItemNotify == PreUsage == PreNotify == DT.ITEM_UNDEFINED:\r |
76 | CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText\r | |
f7496d71 | 77 | \r |
4234283c | 78 | PreHelpText = CommentItemHelpText\r |
f7496d71 LG |
79 | \r |
80 | if BlockFlag == 4:\r | |
4234283c LG |
81 | CommentItemIns = InfProtocolItemCommentContent()\r |
82 | CommentItemIns.SetUsageItem(CommentItemUsage)\r | |
83 | CommentItemIns.SetNotify(CommentItemNotify)\r | |
84 | CommentItemIns.SetHelpStringItem(CommentItemHelpText)\r | |
85 | CommentInsList.append(CommentItemIns)\r | |
f7496d71 | 86 | \r |
4234283c LG |
87 | BlockFlag = -1\r |
88 | PreUsage = None\r | |
89 | PreNotify = None\r | |
90 | PreHelpText = ''\r | |
f7496d71 | 91 | \r |
4234283c LG |
92 | elif BlockFlag == 3:\r |
93 | #\r | |
94 | # Add previous help string\r | |
f7496d71 | 95 | #\r |
4234283c LG |
96 | CommentItemIns = InfProtocolItemCommentContent()\r |
97 | CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)\r | |
98 | CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)\r | |
99 | if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):\r | |
f7496d71 | 100 | PreHelpText += DT.END_OF_LINE\r |
4234283c LG |
101 | CommentItemIns.SetHelpStringItem(PreHelpText)\r |
102 | CommentInsList.append(CommentItemIns)\r | |
103 | #\r | |
104 | # Add Current help string\r | |
105 | #\r | |
106 | CommentItemIns = InfProtocolItemCommentContent()\r | |
107 | CommentItemIns.SetUsageItem(CommentItemUsage)\r | |
108 | CommentItemIns.SetNotify(CommentItemNotify)\r | |
109 | CommentItemIns.SetHelpStringItem(CommentItemHelpText)\r | |
110 | CommentInsList.append(CommentItemIns)\r | |
f7496d71 | 111 | \r |
4234283c LG |
112 | BlockFlag = -1\r |
113 | PreUsage = None\r | |
114 | PreNotify = None\r | |
f7496d71 LG |
115 | PreHelpText = ''\r |
116 | \r | |
4234283c LG |
117 | else:\r |
118 | PreUsage = CommentItemUsage\r | |
119 | PreNotify = CommentItemNotify\r | |
120 | PreHelpText = CommentItemHelpText\r | |
f7496d71 | 121 | \r |
4234283c | 122 | InfProtocolItemObj.SetCommentList(CommentInsList)\r |
f7496d71 | 123 | \r |
4234283c LG |
124 | return InfProtocolItemObj\r |
125 | \r | |
126 | class InfProtocolItemCommentContent():\r | |
127 | def __init__(self):\r | |
128 | #\r | |
f7496d71 | 129 | # ## SOMETIMES_CONSUMES ## HelpString\r |
4234283c LG |
130 | #\r |
131 | self.UsageItem = ''\r | |
132 | #\r | |
133 | # Help String\r | |
134 | #\r | |
135 | self.HelpStringItem = ''\r | |
136 | self.Notify = ''\r | |
137 | self.CommentList = []\r | |
f7496d71 | 138 | \r |
4234283c LG |
139 | def SetUsageItem(self, UsageItem):\r |
140 | self.UsageItem = UsageItem\r | |
141 | def GetUsageItem(self):\r | |
142 | return self.UsageItem\r | |
f7496d71 | 143 | \r |
4234283c LG |
144 | def SetNotify(self, Notify):\r |
145 | if Notify != DT.ITEM_UNDEFINED:\r | |
146 | self.Notify = 'true'\r | |
147 | def GetNotify(self):\r | |
148 | return self.Notify\r | |
f7496d71 | 149 | \r |
4234283c LG |
150 | def SetHelpStringItem(self, HelpStringItem):\r |
151 | self.HelpStringItem = HelpStringItem\r | |
152 | def GetHelpStringItem(self):\r | |
153 | return self.HelpStringItem\r | |
f7496d71 | 154 | \r |
4234283c LG |
155 | class InfProtocolItem():\r |
156 | def __init__(self):\r | |
157 | self.Name = ''\r | |
158 | self.FeatureFlagExp = ''\r | |
159 | self.SupArchList = []\r | |
160 | self.CommentList = []\r | |
f7496d71 | 161 | \r |
4234283c LG |
162 | def SetName(self, Name):\r |
163 | self.Name = Name\r | |
164 | def GetName(self):\r | |
165 | return self.Name\r | |
f7496d71 | 166 | \r |
4234283c LG |
167 | def SetFeatureFlagExp(self, FeatureFlagExp):\r |
168 | self.FeatureFlagExp = FeatureFlagExp\r | |
169 | def GetFeatureFlagExp(self):\r | |
170 | return self.FeatureFlagExp\r | |
f7496d71 | 171 | \r |
4234283c LG |
172 | def SetSupArchList(self, SupArchList):\r |
173 | self.SupArchList = SupArchList\r | |
174 | def GetSupArchList(self):\r | |
f7496d71 | 175 | return self.SupArchList\r |
4234283c LG |
176 | \r |
177 | def SetCommentList(self, CommentList):\r | |
178 | self.CommentList = CommentList\r | |
179 | def GetCommentList(self):\r | |
180 | return self.CommentList\r | |
181 | \r | |
182 | ##\r | |
183 | #\r | |
184 | #\r | |
185 | #\r | |
186 | class InfProtocolObject():\r | |
187 | def __init__(self):\r | |
188 | self.Protocols = Sdict()\r | |
189 | #\r | |
190 | # Macro defined in this section should be only used in this section.\r | |
191 | #\r | |
192 | self.Macros = {}\r | |
f7496d71 | 193 | \r |
4234283c LG |
194 | def SetProtocol(self, ProtocolContent, Arch = None,):\r |
195 | __SupArchList = []\r | |
196 | for ArchItem in Arch:\r | |
197 | #\r | |
198 | # Validate Arch\r | |
f7496d71 | 199 | #\r |
4231a819 | 200 | if (ArchItem == '' or ArchItem is None):\r |
4234283c LG |
201 | ArchItem = 'COMMON'\r |
202 | __SupArchList.append(ArchItem)\r | |
203 | \r | |
204 | for Item in ProtocolContent:\r | |
205 | #\r | |
206 | # Get Comment content of this protocol\r | |
207 | #\r | |
208 | CommentsList = None\r | |
209 | if len(Item) == 3:\r | |
210 | CommentsList = Item[1]\r | |
211 | CurrentLineOfItem = Item[2]\r | |
212 | LineInfo = (CurrentLineOfItem[2], CurrentLineOfItem[1], CurrentLineOfItem[0])\r | |
213 | Item = Item[0]\r | |
214 | InfProtocolItemObj = InfProtocolItem()\r | |
215 | if len(Item) >= 1 and len(Item) <= 2:\r | |
216 | #\r | |
217 | # Only CName contained\r | |
218 | #\r | |
219 | if not IsValidCVariableName(Item[0]):\r | |
220 | ErrorInInf(ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]),\r | |
221 | LineInfo=LineInfo)\r | |
222 | if (Item[0] != ''):\r | |
223 | InfProtocolItemObj.SetName(Item[0])\r | |
224 | else:\r | |
225 | ErrorInInf(ST.ERR_INF_PARSER_CNAME_MISSING,\r | |
226 | LineInfo=LineInfo)\r | |
227 | if len(Item) == 2:\r | |
228 | #\r | |
229 | # Contained CName and Feature Flag Express\r | |
f7496d71 | 230 | # <statements> ::= <CName> ["|"\r |
4234283c LG |
231 | # <FeatureFlagExpress>]\r |
232 | # For Protocol Object\r | |
233 | #\r | |
234 | if Item[1].strip() == '':\r | |
235 | ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,\r | |
236 | LineInfo=LineInfo)\r | |
237 | #\r | |
238 | # Validate Feature Flag Express for Item[1]\r | |
239 | #\r | |
240 | FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())\r | |
241 | if not FeatureFlagRtv[0]:\r | |
242 | ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),\r | |
243 | LineInfo=LineInfo)\r | |
244 | InfProtocolItemObj.SetFeatureFlagExp(Item[1])\r | |
f7496d71 | 245 | \r |
4234283c LG |
246 | if len(Item) < 1 or len(Item) > 2:\r |
247 | #\r | |
f7496d71 | 248 | # Invalid format of Protocols statement\r |
4234283c LG |
249 | #\r |
250 | ErrorInInf(ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,\r | |
251 | LineInfo=LineInfo)\r | |
f7496d71 | 252 | \r |
4234283c LG |
253 | #\r |
254 | # Get/Set Usage and HelpString for Protocol entry\r | |
255 | #\r | |
4231a819 | 256 | if CommentsList is not None and len(CommentsList) != 0:\r |
4234283c LG |
257 | InfProtocolItemObj = ParseProtocolComment(CommentsList, InfProtocolItemObj)\r |
258 | else:\r | |
259 | CommentItemIns = InfProtocolItemCommentContent()\r | |
260 | CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)\r | |
261 | CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)\r | |
262 | InfProtocolItemObj.SetCommentList([CommentItemIns])\r | |
f7496d71 | 263 | \r |
4234283c | 264 | InfProtocolItemObj.SetSupArchList(__SupArchList)\r |
f7496d71 | 265 | \r |
4234283c LG |
266 | #\r |
267 | # Determine protocol name duplicate. Follow below rule:\r | |
268 | #\r | |
f7496d71 LG |
269 | # A protocol must not be duplicated within a [Protocols] section.\r |
270 | # A protocol may appear in multiple architectural [Protocols]\r | |
271 | # sections. A protocol listed in an architectural [Protocols]\r | |
272 | # section must not be listed in the common architectural\r | |
4234283c | 273 | # [Protocols] section.\r |
f7496d71 | 274 | #\r |
4234283c | 275 | # NOTE: This check will not report error now.\r |
f7496d71 | 276 | #\r |
4234283c LG |
277 | for Item in self.Protocols:\r |
278 | if Item.GetName() == InfProtocolItemObj.GetName():\r | |
279 | ItemSupArchList = Item.GetSupArchList()\r | |
280 | for ItemArch in ItemSupArchList:\r | |
281 | for ProtocolItemObjArch in __SupArchList:\r | |
282 | if ItemArch == ProtocolItemObjArch:\r | |
283 | #\r | |
284 | # ST.ERR_INF_PARSER_ITEM_DUPLICATE\r | |
285 | #\r | |
286 | pass\r | |
287 | if ItemArch.upper() == 'COMMON' or ProtocolItemObjArch.upper() == 'COMMON':\r | |
288 | #\r | |
289 | # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON\r | |
290 | #\r | |
f7496d71 LG |
291 | pass\r |
292 | \r | |
27c4ceb4 | 293 | if (InfProtocolItemObj) in self.Protocols:\r |
4234283c LG |
294 | ProcotolList = self.Protocols[InfProtocolItemObj]\r |
295 | ProcotolList.append(InfProtocolItemObj)\r | |
296 | self.Protocols[InfProtocolItemObj] = ProcotolList\r | |
297 | else:\r | |
298 | ProcotolList = []\r | |
299 | ProcotolList.append(InfProtocolItemObj)\r | |
300 | self.Protocols[InfProtocolItemObj] = ProcotolList\r | |
f7496d71 | 301 | \r |
4234283c | 302 | return True\r |
f7496d71 | 303 | \r |
4234283c LG |
304 | def GetProtocol(self):\r |
305 | return self.Protocols\r |