summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/UPT/Xml/PcdXml.py
blob: bbcee45a0132ca89b8aecaa9bfccd16c928659a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
## @file
# This file is used to parse a PCD file of .PKG file
#
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#

'''
PcdXml
'''

##
# Import Modules
#

from Library.Xml.XmlRoutines import XmlElement
from Library.Xml.XmlRoutines import XmlAttribute
from Library.Xml.XmlRoutines import XmlNode
from Library.Xml.XmlRoutines import CreateXmlElement
from Library.Xml.XmlRoutines import XmlList
from Library.StringUtils import GetStringOfList
from Library.StringUtils import ConvertNEToNOTEQ
from Library.StringUtils import ConvertNOTEQToNE
from Library import GlobalData
from Object.POM.CommonObject import PcdObject
from Object.POM.CommonObject import PcdErrorObject
from Xml.CommonXml import HelpTextXml
from Xml.CommonXml import PromptXml
from Xml.CommonXml import CommonDefinesXml
from Xml.XmlParserMisc import GetHelpTextList
from Xml.XmlParserMisc import GetPromptList
import re

##
# PcdErrorXml
#
class PcdErrorXml(object):
    def __init__(self):
        self.ValidValueList = ''
        self.ValidValueListLang = ''
        self.ValidValueRange = ''
        self.Expression = ''
        self.ErrorNumber = ''
        self.ErrorMessage = []

    def FromXml(self, Item, Key):
        self.ValidValueList = XmlElement(Item, '%s/ValidValueList' % Key)
        self.ValidValueListLang = \
        XmlAttribute(XmlNode(Item, '%s/ValidValueList' % Key), 'Lang')
        self.ValidValueRange = self.TransferValidEpxr2ValidRange(XmlElement(Item, '%s/ValidValueRange' % Key))
        self.Expression = XmlElement(Item, '%s/Expression' % Key)
        self.ErrorNumber = XmlElement(Item, '%s/ErrorNumber' % Key)
        for ErrMsg in XmlList(Item, '%s/ErrorMessage' % Key):
            ErrorMessageString = XmlElement(ErrMsg, 'ErrorMessage')
            ErrorMessageLang = \
            XmlAttribute(XmlNode(ErrMsg, 'ErrorMessage'), 'Lang')
            self.ErrorMessage.append((ErrorMessageLang, ErrorMessageString))

        Error = PcdErrorObject()
        Error.SetValidValue(self.ValidValueList)
        Error.SetValidValueLang(self.ValidValueListLang)
        Error.SetValidValueRange(self.ValidValueRange)
        Error.SetExpression(self.Expression)
        Error.SetErrorNumber(self.ErrorNumber)
        Error.SetErrorMessageList(self.ErrorMessage)

        return Error

    def ToXml(self, PcdError, Key):
        if self.Expression:
            pass
        AttributeList = []
        NodeList = []
        if PcdError.GetValidValue():
            Element1 = \
            CreateXmlElement('ValidValueList', PcdError.GetValidValue(), [], \
                             [['Lang', PcdError.GetValidValueLang()]])
            NodeList.append(Element1)
        if PcdError.GetValidValueRange():
            TansferedRangeStr = self.TransferValidRange2Expr(PcdError.GetTokenSpaceGuidCName(),
                                                             PcdError.GetCName(),
                                                             PcdError.GetValidValueRange())
            Element1 = \
            CreateXmlElement('ValidValueRange', \
                             TansferedRangeStr, [], [])
            NodeList.append(Element1)
        if PcdError.GetExpression():
            NodeList.append(['Expression', PcdError.GetExpression()])
        if PcdError.GetErrorNumber():
            NodeList.append(['ErrorNumber', PcdError.GetErrorNumber()])
        for Item in PcdError.GetErrorMessageList():
            Element = \
            CreateXmlElement('ErrorMessage', Item[1], [], [['Lang', Item[0]]])
            NodeList.append(Element)
        Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)

        return Root

    def TransferValidRange2Expr(self, TokenSpaceGuidCName, CName, ValidRange):
        if self.Expression:
            pass
        INT_RANGE_PATTERN1 = '[\t\s]*[0-9]+[\t\s]*-[\t\s]*[0-9]+'
        INT_RANGE_PATTERN2 = '[\t\s]*(LT|GT|LE|GE|XOR|EQ)[\t\s]+\d+[\t\s]*'
        HEX_RANGE_PATTERN1 = \
            '[\t\s]*0[xX][a-fA-F0-9]+[\t\s]*-[\t\s]*0[xX][a-fA-F0-9]+'
        HEX_RANGE_PATTERN2 = '[\t\s]*(LT|GT|LE|GE|XOR|EQ)[\t\s]+0[xX][a-fA-F0-9]+[\t\s]*'
        IntMatch1 = re.compile(INT_RANGE_PATTERN1)
        IntMatch2 = re.compile(INT_RANGE_PATTERN2)
        HexMatch1 = re.compile(HEX_RANGE_PATTERN1)
        HexMatch2 = re.compile(HEX_RANGE_PATTERN2)
        PcdName = '.'.join([TokenSpaceGuidCName, CName])
        HexMatchedList = []
        IntMatchedList = []
        #
        # Convert HEX2 format range
        #
        if HexMatch2:
            for MatchObj in HexMatch2.finditer(ValidRange):
                MatchStr = MatchObj.group()
                TransferedRangeStr = ' '.join(['', PcdName, MatchStr.strip()])
                ValidRange = ValidRange.replace(MatchStr, TransferedRangeStr)
        #
        # Convert INT2 format range
        #
        if IntMatch2:
            for MatchObj in IntMatch2.finditer(ValidRange):
                MatchStr = MatchObj.group()
                TransferedRangeStr = ' '.join(['', PcdName, MatchStr.strip()])
                ValidRange = ValidRange.replace(MatchStr, TransferedRangeStr)
        #
        # Convert HEX1 format range
        #
        if HexMatch1:
            HexMatchedList += HexMatch1.findall(ValidRange)

        for MatchStr in HexMatchedList:
            RangeItemList = MatchStr.strip().split('-')
            TransferedRangeStr = '(%s GE %s) AND (%s LE %s)' % \
                (PcdName, RangeItemList[0].strip(), PcdName, RangeItemList[1].strip())
            ValidRange = ValidRange.replace(MatchStr, TransferedRangeStr)
        #
        # Convert INT1 format range
        #
        if IntMatch1:
            IntMatchedList += IntMatch1.findall(ValidRange)

        for MatchStr in IntMatchedList:
            RangeItemList = MatchStr.strip().split('-')
            TransferedRangeStr = '(%s GE %s) AND (%s LE %s)' % \
                (PcdName, RangeItemList[0].strip(), PcdName, RangeItemList[1].strip())
            ValidRange = ValidRange.replace(MatchStr, TransferedRangeStr)

        return ValidRange

    def TransferValidEpxr2ValidRange(self, ValidRangeExpr):
        if self.Expression:
            pass

        PCD_PATTERN = \
        '[\t\s]*[_a-zA-Z][a-zA-Z0-9_]*[\t\s]*\.[\t\s]*[_a-zA-Z][a-zA-Z0-9_]*[\t\s]*'
        IntPattern1 = \
        '[\t\s]*\([\t\s]*'+PCD_PATTERN+'[\t\s]+GE[\t\s]+\d+[\t\s]*\)[\t\s]+AND[\t\s]+\([\t\s]*'+\
        PCD_PATTERN+'[\t\s]+LE[\t\s]+\d+[\t\s]*\)'
        IntPattern1 = IntPattern1.replace(' ', '')
        IntPattern2 = '[\t\s]*'+PCD_PATTERN+'[\t\s]+(LT|GT|LE|GE|XOR|EQ)[\t\s]+\d+[\t\s]*'

        HexPattern1 = \
        '[\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]*'+\
        PCD_PATTERN+'[\t\s]+LE[\t\s]+0[xX][0-9a-fA-F]+[\t\s]*\)'
        HexPattern1 = HexPattern1.replace(' ', '')
        HexPattern2 = '[\t\s]*'+PCD_PATTERN+'[\t\s]+(LT|GT|LE|GE|XOR|EQ)[\t\s]+0[xX][0-9a-zA-Z]+[\t\s]*'

        #
        # Do the Hex1 conversion
        #
        HexMatchedList = re.compile(HexPattern1).findall(ValidRangeExpr)
        HexRangeDict = {}
        for HexMatchedItem in HexMatchedList:
            #
            # To match items on both sides of '-'
            #
            RangeItemList = re.compile('[\t\s]*0[xX][0-9a-fA-F]+[\t\s]*').findall(HexMatchedItem)
            if RangeItemList and len(RangeItemList) == 2:
                HexRangeDict[HexMatchedItem] = RangeItemList

        for Key in HexRangeDict.keys():
            MaxItem = MixItem = ''
            if int(HexRangeDict[Key][0], 16) > int(HexRangeDict[Key][1], 16):
                MaxItem = HexRangeDict[Key][0]
                MixItem = HexRangeDict[Key][1]
            else:
                MaxItem = HexRangeDict[Key][1]
                MixItem = HexRangeDict[Key][0]

            Range = ' %s - %s' % (MixItem.strip(), MaxItem.strip())
            ValidRangeExpr = ValidRangeExpr.replace(Key, Range)
        #
        # Do the INT1 conversion
        #
        IntRangeDict = {}
        IntMatchList = re.compile(IntPattern1).findall(ValidRangeExpr)
        for MatchedItem in IntMatchList:
            #
            # To match items on both sides of '-'
            #
            RangeItemList = re.compile('[\t\s]*\d+[\t\s]*').findall(MatchedItem)
            if RangeItemList and len(RangeItemList) == 2:
                IntRangeDict[MatchedItem] = RangeItemList

        for Key in IntRangeDict.keys():
            MaxItem = MixItem = ''
            if int(IntRangeDict[Key][0]) > int(IntRangeDict[Key][1]):
                MaxItem = IntRangeDict[Key][0]
                MixItem = IntRangeDict[Key][1]
            else:
                MaxItem = IntRangeDict[Key][1]
                MixItem = IntRangeDict[Key][0]

            Range = ' %s - %s' % (MixItem.strip(), MaxItem.strip())
            ValidRangeExpr = ValidRangeExpr.replace(Key, Range)
        #
        # Do the HEX2 conversion
        #
        for MatchObj in re.compile(HexPattern2).finditer(ValidRangeExpr):
            MatchStr = MatchObj.group()
            Range = re.compile(PCD_PATTERN).sub(' ', MatchStr)
            ValidRangeExpr = ValidRangeExpr.replace(MatchStr, Range)
        #
        # Do the INT2 conversion
        #
        for MatchObj in re.compile(IntPattern2).finditer(ValidRangeExpr):
            MatchStr = MatchObj.group()
            Range = re.compile(PCD_PATTERN).sub(' ', MatchStr)
            ValidRangeExpr = ValidRangeExpr.replace(MatchStr, Range)

        return ValidRangeExpr



    def __str__(self):
        return "ValidValueList = %s ValidValueListLang = %s ValidValueRange \
        = %s Expression = %s ErrorNumber = %s %s" % \
        (self.ValidValueList, self.ValidValueListLang, self.ValidValueRange, \
         self.Expression, self.ErrorNumber, self.ErrorMessage)

##
# PcdEntryXml
#
class PcdEntryXml(object):
    def __init__(self):
        self.PcdItemType = ''
        self.PcdUsage = ''
        self.TokenSpaceGuidCName = ''
        self.TokenSpaceGuidValue = ''
        self.Token = ''
        self.CName = ''
        self.PcdCName = ''
        self.DatumType = ''
        self.ValidUsage = ''
        self.DefaultValue = ''
        self.MaxDatumSize = ''
        self.Value = ''
        self.Offset = ''
        self.CommonDefines = CommonDefinesXml()
        self.Prompt = []
        self.HelpText = []
        self.PcdError = []

    ##
    # AsBuilt will use FromXml
    #
    def FromXml(self, Item, Key):
        self.PcdItemType = \
        XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdItemType')
        self.PcdUsage = XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdUsage')
        self.TokenSpaceGuidCName = \
        XmlElement(Item, '%s/TokenSpaceGuidCname' % Key)
        self.TokenSpaceGuidValue = \
        XmlElement(Item, '%s/TokenSpaceGuidValue' % Key)
        self.Token = XmlElement(Item, '%s/Token' % Key)
        self.CName = XmlElement(Item, '%s/CName' % Key)
        self.PcdCName = XmlElement(Item, '%s/PcdCName' % Key)
        self.DatumType = XmlElement(Item, '%s/DatumType' % Key)
        self.ValidUsage = XmlElement(Item, '%s/ValidUsage' % Key)
        if not GlobalData.gIS_BINARY_INF:
            self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)
        else:
            self.DefaultValue = XmlElement(Item, '%s/Value' % Key)
        self.MaxDatumSize = XmlElement(Item, '%s/MaxDatumSize' % Key)
        self.Value = XmlElement(Item, '%s/Value' % Key)
        self.Offset = XmlElement(Item, '%s/Offset' % Key)
        self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)

        for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
            HelpTextObj = HelpTextXml()
            HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
            self.HelpText.append(HelpTextObj)
        for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):
            PcdErrorObjXml = PcdErrorXml()
            PcdErrorObj = PcdErrorObjXml.FromXml(PcdErrorItem, 'PcdError')
            self.PcdError.append(PcdErrorObj)

        self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)

        PcdEntry = PcdObject()
        PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)
        PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)
        PcdEntry.SetTokenSpaceGuidValue(self.TokenSpaceGuidValue)
        PcdEntry.SetToken(self.Token)
        PcdEntry.SetOffset(self.Offset)
        PcdEntry.SetCName(self.CName)
        PcdEntry.SetPcdCName(self.PcdCName)
        PcdEntry.SetDatumType(self.DatumType)
        PcdEntry.SetValidUsage(self.ValidUsage)
        PcdEntry.SetDefaultValue(self.DefaultValue)
        PcdEntry.SetMaxDatumSize(self.MaxDatumSize)
        PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
        PcdEntry.SetItemType(self.PcdItemType)

        PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))
        PcdEntry.SetPcdErrorsList(self.PcdError)

        return PcdEntry
    ##
    # Package will use FromXml2
    #
    def FromXml2(self, Item, Key):
        self.TokenSpaceGuidCName = \
        XmlElement(Item, '%s/TokenSpaceGuidCname' % Key)
        self.Token = XmlElement(Item, '%s/Token' % Key)
        self.CName = XmlElement(Item, '%s/CName' % Key)
        self.DatumType = XmlElement(Item, '%s/DatumType' % Key)
        self.ValidUsage = XmlElement(Item, '%s/ValidUsage' % Key)
        self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)
        self.MaxDatumSize = XmlElement(Item, '%s/MaxDatumSize' % Key)
        self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
        for PromptItem in XmlList(Item, '%s/Prompt' % Key):
            PromptObj = PromptXml()
            PromptObj.FromXml(PromptItem, '%s/Prompt' % Key)
            self.Prompt.append(PromptObj)
        for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
            HelpTextObj = HelpTextXml()
            HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
            self.HelpText.append(HelpTextObj)
        for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):
            PcdErrorObjXml = PcdErrorXml()
            PcdErrorObj = PcdErrorObjXml.FromXml(PcdErrorItem, 'PcdError')
            self.PcdError.append(PcdErrorObj)

        self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)

        PcdEntry = PcdObject()
        PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)
        PcdEntry.SetSupModuleList(self.CommonDefines.SupModList)
        PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)
        PcdEntry.SetToken(self.Token)
        PcdEntry.SetCName(self.CName)
        PcdEntry.SetDatumType(self.DatumType)
        PcdEntry.SetValidUsage(self.ValidUsage)
        PcdEntry.SetDefaultValue(self.DefaultValue)
        PcdEntry.SetMaxDatumSize(self.MaxDatumSize)
        PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))

        PcdEntry.SetPromptList(GetPromptList(self.Prompt))
        PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))
        PcdEntry.SetPcdErrorsList(self.PcdError)

        return PcdEntry

    ##
    # Module will use FromXml3
    #
    def FromXml3(self, Item, Key):
        self.PcdItemType = \
        XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdItemType')
        self.PcdUsage = XmlAttribute(XmlNode(Item, '%s' % Key), 'PcdUsage')
        self.TokenSpaceGuidCName = \
        XmlElement(Item, '%s/TokenSpaceGuidCName' % Key)
        self.CName = XmlElement(Item, '%s/CName' % Key)
        self.DefaultValue = XmlElement(Item, '%s/DefaultValue' % Key)
        self.CommonDefines.FromXml(XmlNode(Item, '%s' % Key), Key)
        for HelpTextItem in XmlList(Item, '%s/HelpText' % Key):
            HelpTextObj = HelpTextXml()
            HelpTextObj.FromXml(HelpTextItem, '%s/HelpText' % Key)
            self.HelpText.append(HelpTextObj)
        for PcdErrorItem in XmlList(Item, '%s/PcdError' % Key):
            PcdErrorObj = PcdErrorXml()
            PcdErrorObj.FromXml(PcdErrorItem, 'PcdError')
            self.PcdError.append(PcdErrorObj)

        self.DefaultValue = ConvertNOTEQToNE(self.DefaultValue)

        PcdEntry = PcdObject()
        PcdEntry.SetSupArchList(self.CommonDefines.SupArchList)
        PcdEntry.SetTokenSpaceGuidCName(self.TokenSpaceGuidCName)
        PcdEntry.SetCName(self.CName)
        PcdEntry.SetValidUsage(self.PcdUsage)
        PcdEntry.SetDefaultValue(self.DefaultValue)
        PcdEntry.SetFeatureFlag(ConvertNOTEQToNE(self.CommonDefines.FeatureFlag))
        PcdEntry.SetItemType(self.PcdItemType)

        PcdEntry.SetHelpTextList(GetHelpTextList(self.HelpText))
        PcdEntry.SetPcdErrorsList(self.PcdError)

        return PcdEntry

    def ToXml(self, PcdEntry, Key):
        if self.PcdCName:
            pass

        DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())

        AttributeList = \
        [['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \
         ['PcdUsage', PcdEntry.GetValidUsage()], \
         ['PcdItemType', PcdEntry.GetItemType()], \
         ['FeatureFlag', PcdEntry.GetFeatureFlag()],
        ]
        NodeList = [['TokenSpaceGuidCname', PcdEntry.GetTokenSpaceGuidCName()],
                    ['TokenSpaceGuidValue', PcdEntry.GetTokenSpaceGuidValue()],
                    ['Token', PcdEntry.GetToken()],
                    ['CName', PcdEntry.GetCName()],
                    ['DatumType', PcdEntry.GetDatumType()],
                    ['ValidUsage', GetStringOfList(PcdEntry.GetValidUsage())],
                    ['DefaultValue', DefaultValue],
                    ['MaxDatumSize', PcdEntry.GetMaxDatumSize()],
                    ['Offset', PcdEntry.GetOffset()],
                   ]

        for Item in PcdEntry.GetHelpTextList():
            Tmp = HelpTextXml()
            NodeList.append(Tmp.ToXml(Item))
        for Item in PcdEntry.GetPcdErrorsList():
            Tmp = PcdErrorXml()
            NodeList.append(Tmp.ToXml(Item, 'PcdError'))

        Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)

        return Root
    ##
    # Package will use ToXml2
    #
    def ToXml2(self, PcdEntry, Key):
        if self.PcdCName:
            pass

        DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())

        AttributeList = \
        [['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \
         ['SupModList', GetStringOfList(PcdEntry.GetSupModuleList())]
        ]
        NodeList = [['TokenSpaceGuidCname', PcdEntry.GetTokenSpaceGuidCName()],
                    ['Token', PcdEntry.GetToken()],
                    ['CName', PcdEntry.GetCName()],
                    ['DatumType', PcdEntry.GetDatumType()],
                    ['ValidUsage', GetStringOfList(PcdEntry.GetValidUsage())],
                    ['DefaultValue', DefaultValue],
                    ['MaxDatumSize', PcdEntry.GetMaxDatumSize()],
                   ]
        for Item in PcdEntry.GetPromptList():
            Tmp = PromptXml()
            NodeList.append(Tmp.ToXml(Item))

        for Item in PcdEntry.GetHelpTextList():
            Tmp = HelpTextXml()
            NodeList.append(Tmp.ToXml(Item))

        for Item in PcdEntry.GetPcdErrorsList():
            Tmp = PcdErrorXml()
            NodeList.append(Tmp.ToXml(Item, 'PcdError'))

        Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)

        return Root
    ##
    # Module will use ToXml3
    #
    def ToXml3(self, PcdEntry, Key):
        if self.PcdCName:
            pass

        DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())

        AttributeList = \
        [['SupArchList', GetStringOfList(PcdEntry.GetSupArchList())], \
         ['PcdUsage', PcdEntry.GetValidUsage()], \
         ['PcdItemType', PcdEntry.GetItemType()], \
         ['FeatureFlag', ConvertNEToNOTEQ(PcdEntry.GetFeatureFlag())],
        ]
        NodeList = [['CName', PcdEntry.GetCName()],
                    ['TokenSpaceGuidCName', PcdEntry.GetTokenSpaceGuidCName()],
                    ['DefaultValue', DefaultValue],
                   ]

        for Item in PcdEntry.GetHelpTextList():
            Tmp = HelpTextXml()
            NodeList.append(Tmp.ToXml(Item))
        for Item in PcdEntry.GetPcdErrorsList():
            Tmp = PcdErrorXml()
            NodeList.append(Tmp.ToXml(Item, 'PcdError'))

        Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)

        return Root

    ##
    # AsBuild Module will use ToXml4
    #
    def ToXml4(self, PcdEntry, Key):
        if self.PcdCName:
            pass

        DefaultValue = ConvertNEToNOTEQ(PcdEntry.GetDefaultValue())

        AttributeList = []

        NodeList = [
                    ['TokenSpaceGuidValue', PcdEntry.GetTokenSpaceGuidValue()],
                    ['PcdCName', PcdEntry.GetCName()],
                    ['Token', PcdEntry.GetToken()],
                    ['DatumType', PcdEntry.GetDatumType()],
                    ['MaxDatumSize', PcdEntry.GetMaxDatumSize()],
                    ['Value', DefaultValue],
                    ['Offset', PcdEntry.GetOffset()]
                   ]

        for Item in PcdEntry.GetHelpTextList():
            Tmp = HelpTextXml()
            NodeList.append(Tmp.ToXml(Item))
        for Item in PcdEntry.GetPcdErrorsList():
            Tmp = PcdErrorXml()
            NodeList.append(Tmp.ToXml(Item, 'PcdError'))

        Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)

        return Root


    def __str__(self):
        Str = \
        ('PcdItemType = %s PcdUsage = %s TokenSpaceGuidCName = %s \
        TokenSpaceGuidValue = %s Token = %s CName = %s PcdCName = %s \
        DatumType = %s ValidUsage = %s DefaultValue = %s MaxDatumSize = %s \
        Value = %s Offset = %s %s') % \
        (self.PcdItemType, self.PcdUsage, self.TokenSpaceGuidCName, \
         self.TokenSpaceGuidValue, self.Token, self.CName, self.PcdCName, \
         self.DatumType, self.ValidUsage, self.DefaultValue, \
         self.MaxDatumSize, self.Value, self.Offset, self.CommonDefines)
        for Item in self.HelpText:
            Str = Str + "\n\t" + str(Item)
        for Item in self.PcdError:
            Str = Str + "\n\tPcdError:" + str(Item)
        return Str