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