]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/Xml/PcdXml.py
BaseTools: Use absolute import in UPT
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Xml / PcdXml.py
CommitLineData
4234283c
LG
1## @file\r
2# This file is used to parse a PCD file of .PKG file\r
3#\r
64285f15 4# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
4234283c 5#\r
f7496d71
LG
6# This program and the accompanying materials are licensed and made available\r
7# under the terms and conditions of the BSD License which accompanies this\r
8# distribution. The full text of the license may be found at\r
4234283c
LG
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15'''\r
16PcdXml\r
17'''\r
18\r
19##\r
20# Import Modules\r
21#\r
22\r
23from Library.Xml.XmlRoutines import XmlElement\r
24from Library.Xml.XmlRoutines import XmlAttribute\r
25from Library.Xml.XmlRoutines import XmlNode\r
26from Library.Xml.XmlRoutines import CreateXmlElement\r
27from Library.Xml.XmlRoutines import XmlList\r
64285f15
YZ
28from Library.StringUtils import GetStringOfList\r
29from Library.StringUtils import ConvertNEToNOTEQ\r
30from Library.StringUtils import ConvertNOTEQToNE\r
4234283c
LG
31from Library import GlobalData\r
32from Object.POM.CommonObject import PcdObject\r
33from Object.POM.CommonObject import PcdErrorObject\r
34from Xml.CommonXml import HelpTextXml\r
421ccda3 35from Xml.CommonXml import PromptXml\r
4234283c
LG
36from Xml.CommonXml import CommonDefinesXml\r
37from Xml.XmlParserMisc import GetHelpTextList\r
421ccda3
HC
38from Xml.XmlParserMisc import GetPromptList\r
39import re\r
4234283c
LG
40\r
41##\r
42# PcdErrorXml\r
43#\r
44class PcdErrorXml(object):\r
45 def __init__(self):\r
46 self.ValidValueList = ''\r
47 self.ValidValueListLang = ''\r
48 self.ValidValueRange = ''\r
49 self.Expression = ''\r
50 self.ErrorNumber = ''\r
51 self.ErrorMessage = []\r
f7496d71 52\r
4234283c
LG
53 def FromXml(self, Item, Key):\r
54 self.ValidValueList = XmlElement(Item, '%s/ValidValueList' % Key)\r
55 self.ValidValueListLang = \\r
56 XmlAttribute(XmlNode(Item, '%s/ValidValueList' % Key), 'Lang')\r
421ccda3 57 self.ValidValueRange = self.TransferValidEpxr2ValidRange(XmlElement(Item, '%s/ValidValueRange' % Key))\r
4234283c
LG
58 self.Expression = XmlElement(Item, '%s/Expression' % Key)\r
59 self.ErrorNumber = XmlElement(Item, '%s/ErrorNumber' % Key)\r
60 for ErrMsg in XmlList(Item, '%s/ErrorMessage' % Key):\r
61 ErrorMessageString = XmlElement(ErrMsg, 'ErrorMessage')\r
62 ErrorMessageLang = \\r
63 XmlAttribute(XmlNode(ErrMsg, 'ErrorMessage'), 'Lang')\r
64 self.ErrorMessage.append((ErrorMessageLang, ErrorMessageString))\r
f7496d71 65\r
4234283c
LG
66 Error = PcdErrorObject()\r
67 Error.SetValidValue(self.ValidValueList)\r
68 Error.SetValidValueLang(self.ValidValueListLang)\r
69 Error.SetValidValueRange(self.ValidValueRange)\r
70 Error.SetExpression(self.Expression)\r
71 Error.SetErrorNumber(self.ErrorNumber)\r
72 Error.SetErrorMessageList(self.ErrorMessage)\r
f7496d71 73\r
4234283c
LG
74 return Error\r
75\r
76 def ToXml(self, PcdError, Key):\r
77 if self.Expression:\r
78 pass\r
79 AttributeList = []\r
80 NodeList = []\r
81 if PcdError.GetValidValue():\r
82 Element1 = \\r
83 CreateXmlElement('ValidValueList', PcdError.GetValidValue(), [], \\r
84 [['Lang', PcdError.GetValidValueLang()]])\r
85 NodeList.append(Element1)\r
86 if PcdError.GetValidValueRange():\r
421ccda3
HC
87 TansferedRangeStr = self.TransferValidRange2Expr(PcdError.GetTokenSpaceGuidCName(),\r
88 PcdError.GetCName(),\r
89 PcdError.GetValidValueRange())\r
4234283c
LG
90 Element1 = \\r
91 CreateXmlElement('ValidValueRange', \\r
421ccda3 92 TansferedRangeStr, [], [])\r
4234283c
LG
93 NodeList.append(Element1)\r
94 if PcdError.GetExpression():\r
95 NodeList.append(['Expression', PcdError.GetExpression()])\r
96 if PcdError.GetErrorNumber():\r
97 NodeList.append(['ErrorNumber', PcdError.GetErrorNumber()])\r
98 for Item in PcdError.GetErrorMessageList():\r
99 Element = \\r
100 CreateXmlElement('ErrorMessage', Item[1], [], [['Lang', Item[0]]])\r
101 NodeList.append(Element)\r
102 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r
f7496d71 103\r
4234283c 104 return Root\r
f7496d71 105\r
421ccda3
HC
106 def TransferValidRange2Expr(self, TokenSpaceGuidCName, CName, ValidRange):\r
107 if self.Expression:\r
108 pass\r
109 INT_RANGE_PATTERN1 = '[\t\s]*[0-9]+[\t\s]*-[\t\s]*[0-9]+'\r
110 INT_RANGE_PATTERN2 = '[\t\s]*(LT|GT|LE|GE|XOR|EQ)[\t\s]+\d+[\t\s]*'\r
111 HEX_RANGE_PATTERN1 = \\r
112 '[\t\s]*0[xX][a-fA-F0-9]+[\t\s]*-[\t\s]*0[xX][a-fA-F0-9]+'\r
113 HEX_RANGE_PATTERN2 = '[\t\s]*(LT|GT|LE|GE|XOR|EQ)[\t\s]+0[xX][a-fA-F0-9]+[\t\s]*'\r
114 IntMatch1 = re.compile(INT_RANGE_PATTERN1)\r
115 IntMatch2 = re.compile(INT_RANGE_PATTERN2)\r
116 HexMatch1 = re.compile(HEX_RANGE_PATTERN1)\r
117 HexMatch2 = re.compile(HEX_RANGE_PATTERN2)\r
118 PcdName = '.'.join([TokenSpaceGuidCName, CName])\r
119 HexMatchedList = []\r
120 IntMatchedList = []\r
121 #\r
122 # Convert HEX2 format range\r
123 #\r
124 if HexMatch2:\r
125 for MatchObj in HexMatch2.finditer(ValidRange):\r
126 MatchStr = MatchObj.group()\r
127 TransferedRangeStr = ' '.join(['', PcdName, MatchStr.strip()])\r
f7496d71 128 ValidRange = ValidRange.replace(MatchStr, TransferedRangeStr)\r
421ccda3
HC
129 #\r
130 # Convert INT2 format range\r
131 #\r
132 if IntMatch2:\r
133 for MatchObj in IntMatch2.finditer(ValidRange):\r
134 MatchStr = MatchObj.group()\r
135 TransferedRangeStr = ' '.join(['', PcdName, MatchStr.strip()])\r
f7496d71 136 ValidRange = ValidRange.replace(MatchStr, TransferedRangeStr)\r
421ccda3
HC
137 #\r
138 # Convert HEX1 format range\r
139 #\r
140 if HexMatch1:\r
141 HexMatchedList += HexMatch1.findall(ValidRange)\r
f7496d71 142\r
421ccda3
HC
143 for MatchStr in HexMatchedList:\r
144 RangeItemList = MatchStr.strip().split('-')\r
145 TransferedRangeStr = '(%s GE %s) AND (%s LE %s)' % \\r
146 (PcdName, RangeItemList[0].strip(), PcdName, RangeItemList[1].strip())\r
f7496d71 147 ValidRange = ValidRange.replace(MatchStr, TransferedRangeStr)\r
421ccda3
HC
148 #\r
149 # Convert INT1 format range\r
150 #\r
151 if IntMatch1:\r
152 IntMatchedList += IntMatch1.findall(ValidRange)\r
f7496d71 153\r
421ccda3
HC
154 for MatchStr in IntMatchedList:\r
155 RangeItemList = MatchStr.strip().split('-')\r
156 TransferedRangeStr = '(%s GE %s) AND (%s LE %s)' % \\r
157 (PcdName, RangeItemList[0].strip(), PcdName, RangeItemList[1].strip())\r
f7496d71
LG
158 ValidRange = ValidRange.replace(MatchStr, TransferedRangeStr)\r
159\r
421ccda3 160 return ValidRange\r
f7496d71 161\r
421ccda3
HC
162 def TransferValidEpxr2ValidRange(self, ValidRangeExpr):\r
163 if self.Expression:\r
164 pass\r
f7496d71 165\r
421ccda3
HC
166 PCD_PATTERN = \\r
167 '[\t\s]*[_a-zA-Z][a-zA-Z0-9_]*[\t\s]*\.[\t\s]*[_a-zA-Z][a-zA-Z0-9_]*[\t\s]*'\r
168 IntPattern1 = \\r
169 '[\t\s]*\([\t\s]*'+PCD_PATTERN+'[\t\s]+GE[\t\s]+\d+[\t\s]*\)[\t\s]+AND[\t\s]+\([\t\s]*'+\\r
170 PCD_PATTERN+'[\t\s]+LE[\t\s]+\d+[\t\s]*\)'\r
171 IntPattern1 = IntPattern1.replace(' ', '')\r
172 IntPattern2 = '[\t\s]*'+PCD_PATTERN+'[\t\s]+(LT|GT|LE|GE|XOR|EQ)[\t\s]+\d+[\t\s]*'\r
f7496d71 173\r
421ccda3
HC
174 HexPattern1 = \\r
175 '[\t\s]*\([\t\s]*'+PCD_PATTERN+'[\t\s]+GE[\t\s]+0[xX][0-9a-fA-F]+[\t\s]*\)[\t\s]+AND[\t\s]+\([\t\s]*'+\\r
176 PCD_PATTERN+'[\t\s]+LE[\t\s]+0[xX][0-9a-fA-F]+[\t\s]*\)'\r
177 HexPattern1 = HexPattern1.replace(' ', '')\r
178 HexPattern2 = '[\t\s]*'+PCD_PATTERN+'[\t\s]+(LT|GT|LE|GE|XOR|EQ)[\t\s]+0[xX][0-9a-zA-Z]+[\t\s]*'\r
f7496d71 179\r
421ccda3
HC
180 #\r
181 # Do the Hex1 conversion\r
f7496d71 182 #\r
421ccda3
HC
183 HexMatchedList = re.compile(HexPattern1).findall(ValidRangeExpr)\r
184 HexRangeDict = {}\r
185 for HexMatchedItem in HexMatchedList:\r
186 #\r
187 # To match items on both sides of '-'\r
188 #\r
189 RangeItemList = re.compile('[\t\s]*0[xX][0-9a-fA-F]+[\t\s]*').findall(HexMatchedItem)\r
190 if RangeItemList and len(RangeItemList) == 2:\r
f7496d71
LG
191 HexRangeDict[HexMatchedItem] = RangeItemList\r
192\r
421ccda3
HC
193 for Key in HexRangeDict.keys():\r
194 MaxItem = MixItem = ''\r
195 if int(HexRangeDict[Key][0], 16) > int(HexRangeDict[Key][1], 16):\r
196 MaxItem = HexRangeDict[Key][0]\r
197 MixItem = HexRangeDict[Key][1]\r
198 else:\r
199 MaxItem = HexRangeDict[Key][1]\r
200 MixItem = HexRangeDict[Key][0]\r
f7496d71 201\r
421ccda3
HC
202 Range = ' %s - %s' % (MixItem.strip(), MaxItem.strip())\r
203 ValidRangeExpr = ValidRangeExpr.replace(Key, Range)\r
204 #\r
205 # Do the INT1 conversion\r
206 #\r
207 IntRangeDict = {}\r
208 IntMatchList = re.compile(IntPattern1).findall(ValidRangeExpr)\r
209 for MatchedItem in IntMatchList:\r
210 #\r
211 # To match items on both sides of '-'\r
212 #\r
213 RangeItemList = re.compile('[\t\s]*\d+[\t\s]*').findall(MatchedItem)\r
f7496d71 214 if RangeItemList and len(RangeItemList) == 2:\r
421ccda3 215 IntRangeDict[MatchedItem] = RangeItemList\r
f7496d71 216\r
421ccda3
HC
217 for Key in IntRangeDict.keys():\r
218 MaxItem = MixItem = ''\r
219 if int(IntRangeDict[Key][0]) > int(IntRangeDict[Key][1]):\r
220 MaxItem = IntRangeDict[Key][0]\r
221 MixItem = IntRangeDict[Key][1]\r
222 else:\r
223 MaxItem = IntRangeDict[Key][1]\r
224 MixItem = IntRangeDict[Key][0]\r
f7496d71 225\r
421ccda3
HC
226 Range = ' %s - %s' % (MixItem.strip(), MaxItem.strip())\r
227 ValidRangeExpr = ValidRangeExpr.replace(Key, Range)\r
228 #\r
f7496d71 229 # Do the HEX2 conversion\r
421ccda3
HC
230 #\r
231 for MatchObj in re.compile(HexPattern2).finditer(ValidRangeExpr):\r
232 MatchStr = MatchObj.group()\r
233 Range = re.compile(PCD_PATTERN).sub(' ', MatchStr)\r
234 ValidRangeExpr = ValidRangeExpr.replace(MatchStr, Range)\r
235 #\r
236 # Do the INT2 conversion\r
237 #\r
238 for MatchObj in re.compile(IntPattern2).finditer(ValidRangeExpr):\r
239 MatchStr = MatchObj.group()\r
240 Range = re.compile(PCD_PATTERN).sub(' ', MatchStr)\r
241 ValidRangeExpr = ValidRangeExpr.replace(MatchStr, Range)\r
242\r
243 return ValidRangeExpr\r
f7496d71
LG
244\r
245\r
4234283c
LG
246\r
247 def __str__(self):\r
248 return "ValidValueList = %s ValidValueListLang = %s ValidValueRange \\r
249 = %s Expression = %s ErrorNumber = %s %s" % \\r
250 (self.ValidValueList, self.ValidValueListLang, self.ValidValueRange, \\r
251 self.Expression, self.ErrorNumber, self.ErrorMessage)\r
252\r
253##\r
254# PcdEntryXml\r
255#\r
256class PcdEntryXml(object):\r
257 def __init__(self):\r
258 self.PcdItemType = ''\r
259 self.PcdUsage = ''\r
260 self.TokenSpaceGuidCName = ''\r
261 self.TokenSpaceGuidValue = ''\r
262 self.Token = ''\r
263 self.CName = ''\r
264 self.PcdCName = ''\r
265 self.DatumType = ''\r
266 self.ValidUsage = ''\r
267 self.DefaultValue = ''\r
268 self.MaxDatumSize = ''\r
269 self.Value = ''\r
270 self.Offset = ''\r
271 self.CommonDefines = CommonDefinesXml()\r
421ccda3 272 self.Prompt = []\r
4234283c
LG
273 self.HelpText = []\r
274 self.PcdError = []\r
275\r
276 ##\r
277 # AsBuilt will use FromXml\r
f7496d71 278 #\r
4234283c
LG
279 def FromXml(self, Item, Key):\r
280 self.PcdItemType = \\r
281 XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdItemType')\r
282 self.PcdUsage = XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdUsage')\r
283 self.TokenSpaceGuidCName = \\r
284 XmlElement(Item, '%s/TokenSpaceGuidCname' % Key)\r
285 self.TokenSpaceGuidValue = \\r
286 XmlElement(Item, '%s/TokenSpaceGuidValue' % Key)\r
287 self.Token = XmlElement(Item, '%s/Token' % Key)\r
288 self.CName = XmlElement(Item, '%s/CName' % Key)\r
289 self.PcdCName = XmlElement(Item, '%s/PcdCName' % Key)\r
290 self.DatumType = XmlElement(Item, '%s/DatumType' % Key)\r
291 self.ValidUsage = XmlElement(Item, '%s/ValidUsage' % Key)\r
292 if not GlobalData.gIS_BINARY_INF:\r
293 self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)\r
294 else:\r
295 self.DefaultValue = XmlElement(Item, '%s/Value' % Key)\r
296 self.MaxDatumSize = XmlElement(Item, '%s/MaxDatumSize' % Key)\r
297 self.Value = XmlElement(Item, '%s/Value' % Key)\r
298 self.Offset = XmlElement(Item, '%s/Offset' % Key)\r
299 self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)\r
f7496d71 300\r
4234283c
LG
301 for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):\r
302 HelpTextObj = HelpTextXml()\r
303 HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)\r
304 self.HelpText.append(HelpTextObj)\r
305 for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):\r
306 PcdErrorObjXml = PcdErrorXml()\r
307 PcdErrorObj = PcdErrorObjXml.FromXml(PcdErrorItem, 'PcdError')\r
308 self.PcdError.append(PcdErrorObj)\r
f7496d71 309\r
4234283c 310 self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)\r
f7496d71 311\r
4234283c
LG
312 PcdEntry = PcdObject()\r
313 PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)\r
314 PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)\r
315 PcdEntry.SetTokenSpaceGuidValue(self.TokenSpaceGuidValue)\r
316 PcdEntry.SetToken(self.Token)\r
317 PcdEntry.SetOffset(self.Offset)\r
318 PcdEntry.SetCName(self.CName)\r
319 PcdEntry.SetPcdCName(self.PcdCName)\r
320 PcdEntry.SetDatumType(self.DatumType)\r
321 PcdEntry.SetValidUsage(self.ValidUsage)\r
322 PcdEntry.SetDefaultValue(self.DefaultValue)\r
323 PcdEntry.SetMaxDatumSize(self.MaxDatumSize)\r
324 PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))\r
325 PcdEntry.SetItemType(self.PcdItemType)\r
326\r
327 PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))\r
328 PcdEntry.SetPcdErrorsList(self.PcdError)\r
f7496d71 329\r
4234283c
LG
330 return PcdEntry\r
331 ##\r
332 # Package will use FromXml2\r
f7496d71 333 #\r
4234283c
LG
334 def FromXml2(self, Item, Key):\r
335 self.TokenSpaceGuidCName = \\r
336 XmlElement(Item, '%s/TokenSpaceGuidCname' % Key)\r
337 self.Token = XmlElement(Item, '%s/Token' % Key)\r
338 self.CName = XmlElement(Item, '%s/CName' % Key)\r
339 self.DatumType = XmlElement(Item, '%s/DatumType' % Key)\r
340 self.ValidUsage = XmlElement(Item, '%s/ValidUsage' % Key)\r
341 self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)\r
342 self.MaxDatumSize = XmlElement(Item, '%s/MaxDatumSize' % Key)\r
343 self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)\r
421ccda3
HC
344 for PromptItem in XmlList(Item, '%s/Prompt' % Key):\r
345 PromptObj = PromptXml()\r
346 PromptObj.FromXml(PromptItem, '%s/Prompt' % Key)\r
347 self.Prompt.append(PromptObj)\r
4234283c
LG
348 for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):\r
349 HelpTextObj = HelpTextXml()\r
350 HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)\r
351 self.HelpText.append(HelpTextObj)\r
352 for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):\r
353 PcdErrorObjXml = PcdErrorXml()\r
354 PcdErrorObj = PcdErrorObjXml.FromXml(PcdErrorItem, 'PcdError')\r
355 self.PcdError.append(PcdErrorObj)\r
f7496d71 356\r
4234283c 357 self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)\r
f7496d71 358\r
4234283c
LG
359 PcdEntry = PcdObject()\r
360 PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)\r
361 PcdEntry.SetSupModuleList(self.CommonDefines.SupModList)\r
362 PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)\r
363 PcdEntry.SetToken(self.Token)\r
364 PcdEntry.SetCName(self.CName)\r
365 PcdEntry.SetDatumType(self.DatumType)\r
366 PcdEntry.SetValidUsage(self.ValidUsage)\r
367 PcdEntry.SetDefaultValue(self.DefaultValue)\r
368 PcdEntry.SetMaxDatumSize(self.MaxDatumSize)\r
369 PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))\r
f7496d71 370\r
421ccda3 371 PcdEntry.SetPromptList(GetPromptList(self.Prompt))\r
4234283c
LG
372 PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))\r
373 PcdEntry.SetPcdErrorsList(self.PcdError)\r
f7496d71 374\r
4234283c
LG
375 return PcdEntry\r
376\r
377 ##\r
378 # Module will use FromXml3\r
379 #\r
380 def FromXml3(self, Item, Key):\r
381 self.PcdItemType = \\r
382 XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdItemType')\r
383 self.PcdUsage = XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdUsage')\r
384 self.TokenSpaceGuidCName = \\r
385 XmlElement(Item, '%s/TokenSpaceGuidCName' % Key)\r
386 self.CName = XmlElement(Item, '%s/CName' % Key)\r
387 self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)\r
388 self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)\r
389 for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):\r
390 HelpTextObj = HelpTextXml()\r
391 HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)\r
392 self.HelpText.append(HelpTextObj)\r
393 for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):\r
394 PcdErrorObj = PcdErrorXml()\r
395 PcdErrorObj.FromXml(PcdErrorItem, 'PcdError')\r
396 self.PcdError.append(PcdErrorObj)\r
f7496d71 397\r
4234283c 398 self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)\r
f7496d71 399\r
4234283c
LG
400 PcdEntry = PcdObject()\r
401 PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)\r
402 PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)\r
403 PcdEntry.SetCName(self.CName)\r
404 PcdEntry.SetValidUsage(self.PcdUsage)\r
405 PcdEntry.SetDefaultValue(self.DefaultValue)\r
406 PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))\r
407 PcdEntry.SetItemType(self.PcdItemType)\r
408\r
409 PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))\r
410 PcdEntry.SetPcdErrorsList(self.PcdError)\r
f7496d71 411\r
4234283c 412 return PcdEntry\r
f7496d71 413\r
4234283c
LG
414 def ToXml(self, PcdEntry, Key):\r
415 if self.PcdCName:\r
416 pass\r
f7496d71 417\r
4234283c 418 DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())\r
f7496d71 419\r
4234283c
LG
420 AttributeList = \\r
421 [['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \\r
422 ['PcdUsage', PcdEntry.GetValidUsage()], \\r
423 ['PcdItemType', PcdEntry.GetItemType()], \\r
424 ['FeatureFlag', PcdEntry.GetFeatureFlag()],\r
425 ]\r
426 NodeList = [['TokenSpaceGuidCname', PcdEntry.GetTokenSpaceGuidCName()],\r
427 ['TokenSpaceGuidValue', PcdEntry.GetTokenSpaceGuidValue()],\r
f7496d71 428 ['Token', PcdEntry.GetToken()],\r
4234283c
LG
429 ['CName', PcdEntry.GetCName()],\r
430 ['DatumType', PcdEntry.GetDatumType()],\r
431 ['ValidUsage', GetStringOfList(PcdEntry.GetValidUsage())],\r
432 ['DefaultValue', DefaultValue],\r
433 ['MaxDatumSize', PcdEntry.GetMaxDatumSize()],\r
434 ['Offset', PcdEntry.GetOffset()],\r
435 ]\r
f7496d71 436\r
4234283c
LG
437 for Item in PcdEntry.GetHelpTextList():\r
438 Tmp = HelpTextXml()\r
439 NodeList.append(Tmp.ToXml(Item))\r
440 for Item in PcdEntry.GetPcdErrorsList():\r
441 Tmp = PcdErrorXml()\r
442 NodeList.append(Tmp.ToXml(Item, 'PcdError'))\r
f7496d71 443\r
4234283c 444 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r
f7496d71 445\r
4234283c
LG
446 return Root\r
447 ##\r
448 # Package will use ToXml2\r
f7496d71 449 #\r
4234283c
LG
450 def ToXml2(self, PcdEntry, Key):\r
451 if self.PcdCName:\r
452 pass\r
f7496d71 453\r
4234283c 454 DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())\r
f7496d71 455\r
4234283c
LG
456 AttributeList = \\r
457 [['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \\r
458 ['SupModList', GetStringOfList(PcdEntry.GetSupModuleList())]\r
459 ]\r
460 NodeList = [['TokenSpaceGuidCname', PcdEntry.GetTokenSpaceGuidCName()],\r
461 ['Token', PcdEntry.GetToken()],\r
462 ['CName', PcdEntry.GetCName()],\r
463 ['DatumType', PcdEntry.GetDatumType()],\r
464 ['ValidUsage', GetStringOfList(PcdEntry.GetValidUsage())],\r
465 ['DefaultValue', DefaultValue],\r
466 ['MaxDatumSize', PcdEntry.GetMaxDatumSize()],\r
467 ]\r
421ccda3
HC
468 for Item in PcdEntry.GetPromptList():\r
469 Tmp = PromptXml()\r
470 NodeList.append(Tmp.ToXml(Item))\r
f7496d71 471\r
4234283c
LG
472 for Item in PcdEntry.GetHelpTextList():\r
473 Tmp = HelpTextXml()\r
474 NodeList.append(Tmp.ToXml(Item))\r
475\r
476 for Item in PcdEntry.GetPcdErrorsList():\r
477 Tmp = PcdErrorXml()\r
478 NodeList.append(Tmp.ToXml(Item, 'PcdError'))\r
f7496d71 479\r
4234283c 480 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r
f7496d71 481\r
4234283c
LG
482 return Root\r
483 ##\r
484 # Module will use ToXml3\r
485 #\r
486 def ToXml3(self, PcdEntry, Key):\r
487 if self.PcdCName:\r
488 pass\r
f7496d71 489\r
4234283c 490 DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())\r
f7496d71 491\r
4234283c
LG
492 AttributeList = \\r
493 [['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \\r
494 ['PcdUsage', PcdEntry.GetValidUsage()], \\r
495 ['PcdItemType', PcdEntry.GetItemType()], \\r
496 ['FeatureFlag', ConvertNEToNOTEQ(PcdEntry.GetFeatureFlag())],\r
497 ]\r
498 NodeList = [['CName', PcdEntry.GetCName()],\r
499 ['TokenSpaceGuidCName', PcdEntry.GetTokenSpaceGuidCName()],\r
500 ['DefaultValue', DefaultValue],\r
501 ]\r
f7496d71 502\r
4234283c
LG
503 for Item in PcdEntry.GetHelpTextList():\r
504 Tmp = HelpTextXml()\r
505 NodeList.append(Tmp.ToXml(Item))\r
506 for Item in PcdEntry.GetPcdErrorsList():\r
507 Tmp = PcdErrorXml()\r
508 NodeList.append(Tmp.ToXml(Item, 'PcdError'))\r
f7496d71 509\r
4234283c 510 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r
f7496d71 511\r
4234283c 512 return Root\r
f7496d71 513\r
4234283c
LG
514 ##\r
515 # AsBuild Module will use ToXml4\r
516 #\r
517 def ToXml4(self, PcdEntry, Key):\r
518 if self.PcdCName:\r
519 pass\r
f7496d71 520\r
4234283c 521 DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())\r
f7496d71 522\r
4234283c 523 AttributeList = []\r
f7496d71 524\r
4234283c
LG
525 NodeList = [\r
526 ['TokenSpaceGuidValue', PcdEntry.GetTokenSpaceGuidValue()],\r
527 ['PcdCName', PcdEntry.GetCName()],\r
528 ['Token', PcdEntry.GetToken()],\r
529 ['DatumType', PcdEntry.GetDatumType()],\r
530 ['MaxDatumSize', PcdEntry.GetMaxDatumSize()],\r
531 ['Value', DefaultValue],\r
532 ['Offset', PcdEntry.GetOffset()]\r
533 ]\r
f7496d71 534\r
4234283c
LG
535 for Item in PcdEntry.GetHelpTextList():\r
536 Tmp = HelpTextXml()\r
537 NodeList.append(Tmp.ToXml(Item))\r
538 for Item in PcdEntry.GetPcdErrorsList():\r
539 Tmp = PcdErrorXml()\r
540 NodeList.append(Tmp.ToXml(Item, 'PcdError'))\r
f7496d71 541\r
4234283c 542 Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)\r
f7496d71 543\r
4234283c 544 return Root\r
f7496d71 545\r
4234283c
LG
546\r
547 def __str__(self):\r
548 Str = \\r
549 ('PcdItemType = %s PcdUsage = %s TokenSpaceGuidCName = %s \\r
550 TokenSpaceGuidValue = %s Token = %s CName = %s PcdCName = %s \\r
551 DatumType = %s ValidUsage = %s DefaultValue = %s MaxDatumSize = %s \\r
552 Value = %s Offset = %s %s') % \\r
553 (self.PcdItemType, self.PcdUsage, self.TokenSpaceGuidCName, \\r
554 self.TokenSpaceGuidValue, self.Token, self.CName, self.PcdCName, \\r
555 self.DatumType, self.ValidUsage, self.DefaultValue, \\r
556 self.MaxDatumSize, self.Value, self.Offset, self.CommonDefines)\r
557 for Item in self.HelpText:\r
558 Str = Str + "\n\t" + str(Item)\r
559 for Item in self.PcdError:\r
560 Str = Str + "\n\tPcdError:" + str(Item)\r
421ccda3 561 return Str\r