]>
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 - 2018, Intel Corporation. All rights reserved.<BR>
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
17 from Library
.Misc
import Sdict
18 from Library
.DataType
import TAB_GUIDS
19 from Library
.DataType
import TAB_PPIS
20 from Library
.DataType
import TAB_PROTOCOLS
21 from Library
.DataType
import TAB_DEC_DEFINES
22 from Library
.DataType
import TAB_INCLUDES
23 from Library
.DataType
import TAB_LIBRARY_CLASSES
24 from Library
.DataType
import TAB_USER_EXTENSIONS
25 from Library
.DataType
import TAB_PCDS
26 from Library
.DataType
import TAB_ARCH_COMMON
30 # Base class for all data objects which have head and tail comments
37 self
._HeadComment
= []
38 self
._TailComment
= []
42 def GetComments(self
):
43 return self
._HeadComment
, self
._TailComment
47 def GetHeadComment(self
):
48 return self
._HeadComment
52 # @param Comment: comment content
54 def SetHeadComment(self
, Comment
):
55 self
._HeadComment
= Comment
59 def GetTailComment(self
):
60 return self
._TailComment
64 # @param Comment: comment content
66 def SetTailComment(self
, Comment
):
67 self
._TailComment
= Comment
71 # Base class that hold common info
73 class _DecBaseObject(_DecComments
):
74 def __init__(self
, PkgFullName
):
75 _DecComments
.__init
__(self
)
77 # Key is combined with (Arch, SectionType)
80 self
.ValueDict
= Sdict()
81 self
._PkgFullName
= PkgFullName
82 self
._PackagePath
, self
._FileName
= os
.path
.split(PkgFullName
)
87 def GetSectionName(self
):
92 def GetPackagePath(self
):
93 return self
._PackagePath
97 def GetPackageFile(self
):
100 ## GetPackageFullName
102 def GetPackageFullName(self
):
103 return self
._PkgFullName
106 # Add sub-item to current object, sub-class should override it if needed
108 # @param Item: Sub-item to be added
109 # @param Scope: A list store section name and arch info
111 def AddItem(self
, Item
, Scope
):
118 if Ele
[1] in self
.ValueDict
:
119 self
.ValueDict
[Ele
[1]].append(Item
)
121 self
.ValueDict
[Ele
[1]] = [Item
]
122 ArchModule
.append(Ele
[1])
123 Item
.ArchAndModuleType
= ArchModule
126 # Helper class used by sub-class
129 def _GetItemByArch(self
, Arch
):
131 if Arch
not in self
.ValueDict
:
133 return self
.ValueDict
[Arch
]
136 # Get all items, union all arches, items in returned list are unique
138 def _GetAllItems(self
):
140 for Arch
in self
.ValueDict
:
141 for Item
in self
.ValueDict
[Arch
]:
142 if Item
not in Retlst
:
146 ## _DecItemBaseObject
148 # Module type and arch the item belongs to
150 class _DecItemBaseObject(_DecComments
):
152 _DecComments
.__init
__(self
)
154 # Item's arch, if PCD, also include PCD type
156 self
.ArchAndModuleType
= []
160 def GetArchList(self
):
162 for Arch
in self
.ArchAndModuleType
:
168 # Class to hold define section information
170 class DecDefineObject(_DecBaseObject
):
171 def __init__(self
, PkgFullName
):
172 _DecBaseObject
.__init
__(self
, PkgFullName
)
173 self
._SecName
= TAB_DEC_DEFINES
.upper()
177 self
._PkgVersion
= ''
178 self
._PkgUniFile
= ''
180 ## GetPackageSpecification
182 def GetPackageSpecification(self
):
185 def SetPackageSpecification(self
, DecSpec
):
186 self
._DecSpec
= DecSpec
190 def GetPackageName(self
):
193 def SetPackageName(self
, PkgName
):
194 self
._PkgName
= PkgName
198 def GetPackageGuid(self
):
201 def SetPackageGuid(self
, PkgGuid
):
202 self
._PkgGuid
= PkgGuid
206 def GetPackageVersion(self
):
207 return self
._PkgVersion
209 def SetPackageVersion(self
, PkgVersion
):
210 self
._PkgVersion
= PkgVersion
214 def GetPackageUniFile(self
):
215 return self
._PkgUniFile
217 def SetPackageUniFile(self
, PkgUniFile
):
218 self
._PkgUniFile
= PkgUniFile
222 def GetDefines(self
):
223 return self
._GetItemByArch
(TAB_ARCH_COMMON
)
227 def GetAllDefines(self
):
228 return self
._GetAllItems
()
230 ## DecDefineItemObject
232 # Each item of define section
234 class DecDefineItemObject(_DecItemBaseObject
):
236 _DecItemBaseObject
.__init
__(self
)
243 return hash(self
.Key
+ self
.Value
)
247 def __eq__(self
, Other
):
248 return id(self
) == id(Other
)
253 return str(self
.ArchAndModuleType
) + '\n' + self
.Key
+ \
258 # Class to hold include section info
260 class DecIncludeObject(_DecBaseObject
):
261 def __init__(self
, PkgFullName
):
262 _DecBaseObject
.__init
__(self
, PkgFullName
)
263 self
._SecName
= TAB_INCLUDES
.upper()
267 def GetIncludes(self
, Arch
=TAB_ARCH_COMMON
):
268 return self
._GetItemByArch
(Arch
)
272 def GetAllIncludes(self
):
273 return self
._GetAllItems
()
275 ## DecIncludeItemObject
277 # Item of include section
279 class DecIncludeItemObject(_DecItemBaseObject
):
280 def __init__(self
, File
, Root
):
283 _DecItemBaseObject
.__init
__(self
)
288 return hash(self
.File
)
292 def __eq__(self
, Other
):
293 return id(self
) == id(Other
)
300 ## DecLibraryclassObject
302 # Class to hold library class section info
304 class DecLibraryclassObject(_DecBaseObject
):
305 def __init__(self
, PkgFullName
):
306 _DecBaseObject
.__init
__(self
, PkgFullName
)
307 self
._PackagePath
, self
._FileName
= os
.path
.split(PkgFullName
)
308 self
._SecName
= TAB_LIBRARY_CLASSES
.upper()
312 def GetLibraryclasses(self
, Arch
=TAB_ARCH_COMMON
):
313 return self
._GetItemByArch
(Arch
)
315 ## GetAllLibraryclasses
317 def GetAllLibraryclasses(self
):
318 return self
._GetAllItems
()
320 ## DecLibraryclassItemObject
321 # Item of library class section
323 class DecLibraryclassItemObject(_DecItemBaseObject
):
324 def __init__(self
, Libraryclass
, File
, Root
):
325 _DecItemBaseObject
.__init
__(self
)
328 self
.Libraryclass
= Libraryclass
333 return hash(self
.Libraryclass
+ self
.File
)
337 def __eq__(self
, Other
):
338 return id(self
) == id(Other
)
343 return self
.Libraryclass
+ '|' + self
.File
346 # Class to hold PCD section
348 class DecPcdObject(_DecBaseObject
):
349 def __init__(self
, PkgFullName
):
350 _DecBaseObject
.__init
__(self
, PkgFullName
)
351 self
._SecName
= TAB_PCDS
.upper()
355 # Diff from base class
358 # @param Scope: Scope
360 def AddItem(self
, Item
, Scope
):
366 for Type
, Arch
in Scope
:
367 if (Type
, Arch
) in self
.ValueDict
:
368 self
.ValueDict
[Type
, Arch
].append(Item
)
370 self
.ValueDict
[Type
, Arch
] = [Item
]
371 ArchModule
.append([Type
, Arch
])
372 Item
.ArchAndModuleType
= ArchModule
376 # @param PcdType: PcdType
379 def GetPcds(self
, PcdType
, Arch
=TAB_ARCH_COMMON
):
380 PcdType
= PcdType
.upper()
382 if (PcdType
, Arch
) not in self
.ValueDict
:
384 return self
.ValueDict
[PcdType
, Arch
]
388 # @param PcdType: PcdType
390 def GetPcdsByType(self
, PcdType
):
391 PcdType
= PcdType
.upper()
393 for TypeInDict
, Arch
in self
.ValueDict
:
394 if TypeInDict
!= PcdType
:
396 for Item
in self
.ValueDict
[PcdType
, Arch
]:
397 if Item
not in Retlst
:
403 # Item of PCD section
405 # @param _DecItemBaseObject: _DecItemBaseObject object
407 class DecPcdItemObject(_DecItemBaseObject
):
408 def __init__(self
, Guid
, Name
, Value
, DatumType
,
409 Token
, MaxDatumSize
=''):
410 _DecItemBaseObject
.__init
__(self
)
411 self
.TokenCName
= Name
412 self
.TokenSpaceGuidCName
= Guid
413 self
.DatumType
= DatumType
414 self
.DefaultValue
= Value
415 self
.TokenValue
= Token
416 self
.MaxDatumSize
= MaxDatumSize
421 return hash(self
.TokenSpaceGuidCName
+ self
.TokenCName
)
425 def __eq__(self
, Other
):
426 return id(self
) == id(Other
)
430 # @param PcdType: PcdType
432 def GetArchListOfType(self
, PcdType
):
434 PcdType
= PcdType
.upper()
435 for Type
, Arch
in self
.ArchAndModuleType
:
443 # Base class for PPI, Protocol, and GUID.
444 # Hold same data but has different method for clarification in sub-class
446 # @param _DecBaseObject: Dec Base Object
448 class DecGuidObjectBase(_DecBaseObject
):
449 def __init__(self
, PkgFullName
):
450 _DecBaseObject
.__init
__(self
, PkgFullName
)
456 def GetGuidStyleItems(self
, Arch
=TAB_ARCH_COMMON
):
457 return self
._GetItemByArch
(Arch
)
459 ## GetGuidStyleAllItems
461 def GetGuidStyleAllItems(self
):
462 return self
._GetAllItems
()
466 # Item of GUID, PPI and Protocol section
468 # @param _DecItemBaseObject: Dec Item Base Object
470 class DecGuidItemObject(_DecItemBaseObject
):
471 def __init__(self
, CName
, GuidCValue
, GuidString
):
472 _DecItemBaseObject
.__init
__(self
)
473 self
.GuidCName
= CName
474 self
.GuidCValue
= GuidCValue
475 self
.GuidString
= GuidString
480 return hash(self
.GuidCName
)
484 def __eq__(self
, Other
):
485 return id(self
) == id(Other
)
490 return self
.GuidCName
+ ' = ' + self
.GuidCValue
494 # Class for GUID section
496 # @param DecGuidObjectBase: Dec Guid Object Base
498 class DecGuidObject(DecGuidObjectBase
):
499 def __init__(self
, PkgFullName
):
500 DecGuidObjectBase
.__init
__(self
, PkgFullName
)
501 self
._SecName
= TAB_GUIDS
.upper()
507 def GetGuids(self
, Arch
=TAB_ARCH_COMMON
):
508 return self
._GetItemByArch
(Arch
)
512 def GetAllGuids(self
):
513 return self
._GetAllItems
()
517 # Class for PPI section
519 # @param DecGuidObjectBase: Dec Guid Object Base
521 class DecPpiObject(DecGuidObjectBase
):
522 def __init__(self
, PkgFullName
):
523 DecGuidObjectBase
.__init
__(self
, PkgFullName
)
524 self
._SecName
= TAB_PPIS
.upper()
530 def GetPpis(self
, Arch
=TAB_ARCH_COMMON
):
531 return self
._GetItemByArch
(Arch
)
535 def GetAllPpis(self
):
536 return self
._GetAllItems
()
540 # Class for protocol section
542 # @param DecGuidObjectBase: Dec Guid Object Base
544 class DecProtocolObject(DecGuidObjectBase
):
545 def __init__(self
, PkgFullName
):
546 DecGuidObjectBase
.__init
__(self
, PkgFullName
)
547 self
._SecName
= TAB_PROTOCOLS
.upper()
553 def GetProtocols(self
, Arch
=TAB_ARCH_COMMON
):
554 return self
._GetItemByArch
(Arch
)
558 def GetAllProtocols(self
):
559 return self
._GetAllItems
()
561 ## DecUserExtensionObject
563 # Class for user extension section
565 # @param _DecBaseObject: Dec Guid Object Base
567 class DecUserExtensionObject(_DecBaseObject
):
568 def __init__(self
, PkgFullName
):
569 _DecBaseObject
.__init
__(self
, PkgFullName
)
570 self
._SecName
= TAB_USER_EXTENSIONS
.upper()
576 # @param Scope: Scope
578 def AddItem(self
, Item
, Scope
):
583 self
.ItemList
.append(Item
)
585 ## GetAllUserExtensions
587 def GetAllUserExtensions(self
):
591 ## DecUserExtensionItemObject
592 # Item for user extension section
594 # @param _DecItemBaseObject: Dec Item Base Object
596 class DecUserExtensionItemObject(_DecItemBaseObject
):
598 _DecItemBaseObject
.__init
__(self
)