]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Object/Parser/DecObject.py
2 # This file is used to define class objects for DEC file. It will consumed by
5 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
7 # This program and the accompanying materials are licensed and made available
8 # under the terms and conditions of the BSD License which accompanies this
9 # distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 from Library
.Misc
import Sdict
24 from Library
.DataType
import TAB_GUIDS
25 from Library
.DataType
import TAB_PPIS
26 from Library
.DataType
import TAB_PROTOCOLS
27 from Library
.DataType
import TAB_DEC_DEFINES
28 from Library
.DataType
import TAB_INCLUDES
29 from Library
.DataType
import TAB_LIBRARY_CLASSES
30 from Library
.DataType
import TAB_USER_EXTENSIONS
31 from Library
.DataType
import TAB_PCDS
32 from Library
.DataType
import TAB_ARCH_COMMON
36 # Base class for all data objects which have head and tail comments
43 self
._HeadComment
= []
44 self
._TailComment
= []
48 def GetComments(self
):
49 return self
._HeadComment
, self
._TailComment
53 def GetHeadComment(self
):
54 return self
._HeadComment
58 # @param Comment: comment content
60 def SetHeadComment(self
, Comment
):
61 self
._HeadComment
= Comment
65 def GetTailComment(self
):
66 return self
._TailComment
70 # @param Comment: comment content
72 def SetTailComment(self
, Comment
):
73 self
._TailComment
= Comment
77 # Base class that hold common info
79 class _DecBaseObject(_DecComments
):
80 def __init__(self
, PkgFullName
):
81 _DecComments
.__init
__(self
)
83 # Key is combined with (Arch, SectionType)
86 self
.ValueDict
= Sdict()
87 self
._PkgFullName
= PkgFullName
88 self
._PackagePath
, self
._FileName
= os
.path
.split(PkgFullName
)
93 def GetSectionName(self
):
98 def GetPackagePath(self
):
99 return self
._PackagePath
103 def GetPackageFile(self
):
104 return self
._FileName
106 ## GetPackageFullName
108 def GetPackageFullName(self
):
109 return self
._PkgFullName
112 # Add sub-item to current object, sub-class should override it if needed
114 # @param Item: Sub-item to be added
115 # @param Scope: A list store section name and arch info
117 def AddItem(self
, Item
, Scope
):
124 if Ele
[1] in self
.ValueDict
:
125 self
.ValueDict
[Ele
[1]].append(Item
)
127 self
.ValueDict
[Ele
[1]] = [Item
]
128 ArchModule
.append(Ele
[1])
129 Item
.ArchAndModuleType
= ArchModule
132 # Helper class used by sub-class
135 def _GetItemByArch(self
, Arch
):
137 if Arch
not in self
.ValueDict
:
139 return self
.ValueDict
[Arch
]
142 # Get all items, union all arches, items in returned list are unique
144 def _GetAllItems(self
):
146 for Arch
in self
.ValueDict
:
147 for Item
in self
.ValueDict
[Arch
]:
148 if Item
not in Retlst
:
152 ## _DecItemBaseObject
154 # Module type and arch the item belongs to
156 class _DecItemBaseObject(_DecComments
):
158 _DecComments
.__init
__(self
)
160 # Item's arch, if PCD, also include PCD type
162 self
.ArchAndModuleType
= []
166 def GetArchList(self
):
168 for Arch
in self
.ArchAndModuleType
:
174 # Class to hold define section infomation
176 class DecDefineObject(_DecBaseObject
):
177 def __init__(self
, PkgFullName
):
178 _DecBaseObject
.__init
__(self
, PkgFullName
)
179 self
._SecName
= TAB_DEC_DEFINES
.upper()
183 self
._PkgVersion
= ''
184 self
._PkgUniFile
= ''
186 ## GetPackageSpecification
188 def GetPackageSpecification(self
):
191 def SetPackageSpecification(self
, DecSpec
):
192 self
._DecSpec
= DecSpec
196 def GetPackageName(self
):
199 def SetPackageName(self
, PkgName
):
200 self
._PkgName
= PkgName
204 def GetPackageGuid(self
):
207 def SetPackageGuid(self
, PkgGuid
):
208 self
._PkgGuid
= PkgGuid
212 def GetPackageVersion(self
):
213 return self
._PkgVersion
215 def SetPackageVersion(self
, PkgVersion
):
216 self
._PkgVersion
= PkgVersion
220 def GetPackageUniFile(self
):
221 return self
._PkgUniFile
223 def SetPackageUniFile(self
, PkgUniFile
):
224 self
._PkgUniFile
= PkgUniFile
228 def GetDefines(self
):
229 return self
._GetItemByArch
(TAB_ARCH_COMMON
)
233 def GetAllDefines(self
):
234 return self
._GetAllItems
()
236 ## DecDefineItemObject
238 # Each item of define section
240 class DecDefineItemObject(_DecItemBaseObject
):
242 _DecItemBaseObject
.__init
__(self
)
249 return hash(self
.Key
+ self
.Value
)
253 def __eq__(self
, Other
):
254 return id(self
) == id(Other
)
259 return str(self
.ArchAndModuleType
) + '\n' + self
.Key
+ \
264 # Class to hold include section info
266 class DecIncludeObject(_DecBaseObject
):
267 def __init__(self
, PkgFullName
):
268 _DecBaseObject
.__init
__(self
, PkgFullName
)
269 self
._SecName
= TAB_INCLUDES
.upper()
273 def GetIncludes(self
, Arch
=TAB_ARCH_COMMON
):
274 return self
._GetItemByArch
(Arch
)
278 def GetAllIncludes(self
):
279 return self
._GetAllItems
()
281 ## DecIncludeItemObject
283 # Item of include section
285 class DecIncludeItemObject(_DecItemBaseObject
):
286 def __init__(self
, File
, Root
):
289 _DecItemBaseObject
.__init
__(self
)
294 return hash(self
.File
)
298 def __eq__(self
, Other
):
299 return id(self
) == id(Other
)
306 ## DecLibraryclassObject
308 # Class to hold library class section info
310 class DecLibraryclassObject(_DecBaseObject
):
311 def __init__(self
, PkgFullName
):
312 _DecBaseObject
.__init
__(self
, PkgFullName
)
313 self
._PackagePath
, self
._FileName
= os
.path
.split(PkgFullName
)
314 self
._SecName
= TAB_LIBRARY_CLASSES
.upper()
318 def GetLibraryclasses(self
, Arch
=TAB_ARCH_COMMON
):
319 return self
._GetItemByArch
(Arch
)
321 ## GetAllLibraryclasses
323 def GetAllLibraryclasses(self
):
324 return self
._GetAllItems
()
326 ## DecLibraryclassItemObject
327 # Item of library class section
329 class DecLibraryclassItemObject(_DecItemBaseObject
):
330 def __init__(self
, Libraryclass
, File
, Root
):
331 _DecItemBaseObject
.__init
__(self
)
334 self
.Libraryclass
= Libraryclass
339 return hash(self
.Libraryclass
+ self
.File
)
343 def __eq__(self
, Other
):
344 return id(self
) == id(Other
)
349 return self
.Libraryclass
+ '|' + self
.File
352 # Class to hold PCD section
354 class DecPcdObject(_DecBaseObject
):
355 def __init__(self
, PkgFullName
):
356 _DecBaseObject
.__init
__(self
, PkgFullName
)
357 self
._SecName
= TAB_PCDS
.upper()
361 # Diff from base class
364 # @param Scope: Scope
366 def AddItem(self
, Item
, Scope
):
372 for Type
, Arch
in Scope
:
373 if (Type
, Arch
) in self
.ValueDict
:
374 self
.ValueDict
[Type
, Arch
].append(Item
)
376 self
.ValueDict
[Type
, Arch
] = [Item
]
377 ArchModule
.append([Type
, Arch
])
378 Item
.ArchAndModuleType
= ArchModule
382 # @param PcdType: PcdType
385 def GetPcds(self
, PcdType
, Arch
=TAB_ARCH_COMMON
):
386 PcdType
= PcdType
.upper()
388 if (PcdType
, Arch
) not in self
.ValueDict
:
390 return self
.ValueDict
[PcdType
, Arch
]
394 # @param PcdType: PcdType
396 def GetPcdsByType(self
, PcdType
):
397 PcdType
= PcdType
.upper()
399 for TypeInDict
, Arch
in self
.ValueDict
:
400 if TypeInDict
!= PcdType
:
402 for Item
in self
.ValueDict
[PcdType
, Arch
]:
403 if Item
not in Retlst
:
409 # Item of PCD section
411 # @param _DecItemBaseObject: _DecItemBaseObject object
413 class DecPcdItemObject(_DecItemBaseObject
):
414 def __init__(self
, Guid
, Name
, Value
, DatumType
,
415 Token
, MaxDatumSize
=''):
416 _DecItemBaseObject
.__init
__(self
)
417 self
.TokenCName
= Name
418 self
.TokenSpaceGuidCName
= Guid
419 self
.DatumType
= DatumType
420 self
.DefaultValue
= Value
421 self
.TokenValue
= Token
422 self
.MaxDatumSize
= MaxDatumSize
427 return hash(self
.TokenSpaceGuidCName
+ self
.TokenCName
)
431 def __eq__(self
, Other
):
432 return id(self
) == id(Other
)
436 # @param PcdType: PcdType
438 def GetArchListOfType(self
, PcdType
):
440 PcdType
= PcdType
.upper()
441 for Type
, Arch
in self
.ArchAndModuleType
:
449 # Base class for PPI, Protocol, and GUID.
450 # Hold same data but has different method for clarification in sub-class
452 # @param _DecBaseObject: Dec Base Object
454 class DecGuidObjectBase(_DecBaseObject
):
455 def __init__(self
, PkgFullName
):
456 _DecBaseObject
.__init
__(self
, PkgFullName
)
462 def GetGuidStyleItems(self
, Arch
=TAB_ARCH_COMMON
):
463 return self
._GetItemByArch
(Arch
)
465 ## GetGuidStyleAllItems
467 def GetGuidStyleAllItems(self
):
468 return self
._GetAllItems
()
472 # Item of GUID, PPI and Protocol section
474 # @param _DecItemBaseObject: Dec Item Base Object
476 class DecGuidItemObject(_DecItemBaseObject
):
477 def __init__(self
, CName
, GuidCValue
, GuidString
):
478 _DecItemBaseObject
.__init
__(self
)
479 self
.GuidCName
= CName
480 self
.GuidCValue
= GuidCValue
481 self
.GuidString
= GuidString
486 return hash(self
.GuidCName
)
490 def __eq__(self
, Other
):
491 return id(self
) == id(Other
)
496 return self
.GuidCName
+ ' = ' + self
.GuidCValue
500 # Class for GUID section
502 # @param DecGuidObjectBase: Dec Guid Object Base
504 class DecGuidObject(DecGuidObjectBase
):
505 def __init__(self
, PkgFullName
):
506 DecGuidObjectBase
.__init
__(self
, PkgFullName
)
507 self
._SecName
= TAB_GUIDS
.upper()
513 def GetGuids(self
, Arch
=TAB_ARCH_COMMON
):
514 return self
._GetItemByArch
(Arch
)
518 def GetAllGuids(self
):
519 return self
._GetAllItems
()
523 # Class for PPI seciont
525 # @param DecGuidObjectBase: Dec Guid Object Base
527 class DecPpiObject(DecGuidObjectBase
):
528 def __init__(self
, PkgFullName
):
529 DecGuidObjectBase
.__init
__(self
, PkgFullName
)
530 self
._SecName
= TAB_PPIS
.upper()
536 def GetPpis(self
, Arch
=TAB_ARCH_COMMON
):
537 return self
._GetItemByArch
(Arch
)
541 def GetAllPpis(self
):
542 return self
._GetAllItems
()
546 # Class for protocol section
548 # @param DecGuidObjectBase: Dec Guid Object Base
550 class DecProtocolObject(DecGuidObjectBase
):
551 def __init__(self
, PkgFullName
):
552 DecGuidObjectBase
.__init
__(self
, PkgFullName
)
553 self
._SecName
= TAB_PROTOCOLS
.upper()
559 def GetProtocols(self
, Arch
=TAB_ARCH_COMMON
):
560 return self
._GetItemByArch
(Arch
)
564 def GetAllProtocols(self
):
565 return self
._GetAllItems
()
567 ## DecUserExtensionObject
569 # Class for user extension section
571 # @param _DecBaseObject: Dec Guid Object Base
573 class DecUserExtensionObject(_DecBaseObject
):
574 def __init__(self
, PkgFullName
):
575 _DecBaseObject
.__init
__(self
, PkgFullName
)
576 self
._SecName
= TAB_USER_EXTENSIONS
.upper()
582 # @param Scope: Scope
584 def AddItem(self
, Item
, Scope
):
589 self
.ItemList
.append(Item
)
591 ## GetAllUserExtensions
593 def GetAllUserExtensions(self
):
597 ## DecUserExtensionItemObject
598 # Item for user extension section
600 # @param _DecItemBaseObject: Dec Item Base Object
602 class DecUserExtensionItemObject(_DecItemBaseObject
):
604 _DecItemBaseObject
.__init
__(self
)