2 # This file is used to define class objects of [Defines] section for INF file.
3 # It will consumed by InfParser
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.
22 from Logger
import StringTable
as ST
23 from Logger
import ToolError
24 from Library
import GlobalData
25 from Library
import DataType
as DT
26 from Library
.String
import GetSplitValueList
27 from Library
.Misc
import CheckGuidRegFormat
28 from Library
.Misc
import Sdict
29 from Library
.Misc
import ConvPathFromAbsToRel
30 from Library
.ExpressionValidate
import IsValidFeatureFlagExp
31 from Library
.ParserValidate
import IsValidWord
32 from Library
.ParserValidate
import IsValidInfMoudleType
33 from Library
.ParserValidate
import IsValidHex
34 from Library
.ParserValidate
import IsValidHexVersion
35 from Library
.ParserValidate
import IsValidDecVersion
36 from Library
.ParserValidate
import IsValidCVariableName
37 from Library
.ParserValidate
import IsValidBoolType
38 from Library
.ParserValidate
import IsValidPath
39 from Library
.ParserValidate
import IsValidFamily
40 from Library
.ParserValidate
import IsValidIdentifier
41 from Library
.ParserValidate
import IsValidDecVersionVal
42 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
43 from Object
.Parser
.InfCommonObject
import CurrentLine
44 from Object
.Parser
.InfCommonObject
import InfSectionCommonDef
45 from Object
.Parser
.InfMisc
import ErrorInInf
46 from Object
.Parser
.InfDefineCommonObject
import InfDefineLibraryItem
47 from Object
.Parser
.InfDefineCommonObject
import InfDefineEntryPointItem
48 from Object
.Parser
.InfDefineCommonObject
import InfDefineUnloadImageItem
49 from Object
.Parser
.InfDefineCommonObject
import InfDefineConstructorItem
50 from Object
.Parser
.InfDefineCommonObject
import InfDefineDestructorItem
52 class InfDefSectionOptionRomInfo():
54 self
.PciVendorId
= None
55 self
.PciDeviceId
= None
56 self
.PciClassCode
= None
57 self
.PciRevision
= None
58 self
.PciCompress
= None
59 self
.CurrentLine
= ['', -1, '']
60 def SetPciVendorId(self
, PciVendorId
, Comments
):
62 # Value has been set before.
64 if self
.PciVendorId
!= None:
65 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
),
66 LineInfo
=self
.CurrentLine
)
69 # The PciVendorId should be hex string.
71 if (IsValidHex(PciVendorId
)):
72 self
.PciVendorId
= InfDefMember()
73 self
.PciVendorId
.SetValue(PciVendorId
)
74 self
.PciVendorId
.Comments
= Comments
77 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciVendorId),
78 LineInfo
=self
.CurrentLine
)
81 def GetPciVendorId(self
):
82 return self
.PciVendorId
84 def SetPciDeviceId(self
, PciDeviceId
, Comments
):
86 # Value has been set before.
88 if self
.PciDeviceId
!= None:
89 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
),
90 LineInfo
=self
.CurrentLine
)
93 # The PciDeviceId should be hex string.
95 if (IsValidHex(PciDeviceId
)):
96 self
.PciDeviceId
= InfDefMember()
97 self
.PciDeviceId
.SetValue(PciDeviceId
)
98 self
.PciDeviceId
.Comments
= Comments
101 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciDeviceId),
102 LineInfo
=self
.CurrentLine
)
105 def GetPciDeviceId(self
):
106 return self
.PciDeviceId
108 def SetPciClassCode(self
, PciClassCode
, Comments
):
110 # Value has been set before.
112 if self
.PciClassCode
!= None:
113 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
),
114 LineInfo
=self
.CurrentLine
)
117 # The PciClassCode should be 4 bytes hex string.
119 if (IsValidHex(PciClassCode
)):
120 self
.PciClassCode
= InfDefMember()
121 self
.PciClassCode
.SetValue(PciClassCode
)
122 self
.PciClassCode
.Comments
= Comments
125 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
127 LineInfo
=self
.CurrentLine
)
130 def GetPciClassCode(self
):
131 return self
.PciClassCode
133 def SetPciRevision(self
, PciRevision
, Comments
):
135 # Value has been set before.
137 if self
.PciRevision
!= None:
138 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_REVISION
),
139 LineInfo
=self
.CurrentLine
)
142 # The PciRevision should be 4 bytes hex string.
144 if (IsValidHex(PciRevision
)):
145 self
.PciRevision
= InfDefMember()
146 self
.PciRevision
.SetValue(PciRevision
)
147 self
.PciRevision
.Comments
= Comments
150 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciRevision),
151 LineInfo
=self
.CurrentLine
)
154 def GetPciRevision(self
):
155 return self
.PciRevision
157 def SetPciCompress(self
, PciCompress
, Comments
):
159 # Value has been set before.
161 if self
.PciCompress
!= None:
162 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_COMPRESS
),
163 LineInfo
=self
.CurrentLine
)
167 # The PciCompress should be 'TRUE' or 'FALSE'.
169 if (PciCompress
== 'TRUE' or PciCompress
== 'FALSE'):
170 self
.PciCompress
= InfDefMember()
171 self
.PciCompress
.SetValue(PciCompress
)
172 self
.PciCompress
.Comments
= Comments
175 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciCompress),
176 LineInfo
=self
.CurrentLine
)
178 def GetPciCompress(self
):
179 return self
.PciCompress
181 # INF [Define] section Object
183 class InfDefSection(InfDefSectionOptionRomInfo
):
187 self
.ModuleType
= None
188 self
.InfVersion
= None
189 self
.EdkReleaseVersion
= None
190 self
.UefiSpecificationVersion
= None
191 self
.PiSpecificationVersion
= None
192 self
.LibraryClass
= []
194 self
.VersionString
= None
195 self
.PcdIsDriver
= None
197 self
.UnloadImages
= []
198 self
.Constructor
= []
201 self
.CustomMakefile
= []
202 self
.Specification
= []
203 self
.UefiHiiResourceSection
= None
205 self
.CurrentLine
= ['', -1, '']
206 InfDefSectionOptionRomInfo
.__init
__(self
)
210 # @param BaseName: BaseName
212 def SetBaseName(self
, BaseName
, Comments
):
214 # Value has been set before.
216 if self
.BaseName
!= None:
217 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_BASE_NAME
),
218 LineInfo
=self
.CurrentLine
)
221 if not (BaseName
== '' or BaseName
== None):
222 if IsValidWord(BaseName
) and not BaseName
.startswith("_"):
223 self
.BaseName
= InfDefMember()
224 self
.BaseName
.SetValue(BaseName
)
225 self
.BaseName
.Comments
= Comments
228 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_NAME_INVALID
%(BaseName),
229 LineInfo
=self
.CurrentLine
)
234 def GetBaseName(self
):
239 # @param FileGuid: FileGuid
241 def SetFileGuid(self
, FileGuid
, Comments
):
243 # Value has been set before.
245 if self
.FileGuid
!= None:
246 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
247 %(DT
.TAB_INF_DEFINES_FILE_GUID
),
248 LineInfo
=self
.CurrentLine
)
251 # Do verification of GUID content/format
253 if (CheckGuidRegFormat(FileGuid
)):
254 self
.FileGuid
= InfDefMember()
255 self
.FileGuid
.SetValue(FileGuid
)
256 self
.FileGuid
.Comments
= Comments
259 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_GUID_INVALID
%(FileGuid),
260 LineInfo
=self
.CurrentLine
)
265 def GetFileGuid(self
):
270 # @param ModuleType: ModuleType
272 def SetModuleType(self
, ModuleType
, Comments
):
274 # Value has been set before.
276 if self
.ModuleType
!= None:
277 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
278 %(DT
.TAB_INF_DEFINES_MODULE_TYPE
),
279 LineInfo
=self
.CurrentLine
)
282 # Valid Module Type or not
284 if (IsValidInfMoudleType(ModuleType
)):
285 self
.ModuleType
= InfDefMember()
286 self
.ModuleType
.SetValue(ModuleType
)
287 self
.ModuleType
.CurrentLine
= CurrentLine()
288 self
.ModuleType
.CurrentLine
.SetLineNo(self
.CurrentLine
[1])
289 self
.ModuleType
.CurrentLine
.SetLineString(self
.CurrentLine
[2])
290 self
.ModuleType
.CurrentLine
.SetFileName(self
.CurrentLine
[0])
291 self
.ModuleType
.Comments
= Comments
294 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%\
296 LineInfo
=self
.CurrentLine
)
301 def GetModuleType(self
):
302 return self
.ModuleType
306 # @param InfVersion: InfVersion
308 def SetInfVersion(self
, InfVersion
, Comments
):
310 # Value has been set before.
312 if self
.InfVersion
!= None:
313 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
314 %(DT
.TAB_INF_DEFINES_INF_VERSION
),
315 LineInfo
=self
.CurrentLine
)
318 # The InfVersion should be 4 bytes hex string.
320 if (IsValidHex(InfVersion
)):
321 if (InfVersion
< '0x00010005'):
322 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
323 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
324 LineInfo
=self
.CurrentLine
)
326 self
.InfVersion
= InfDefMember()
327 self
.InfVersion
.SetValue(InfVersion
)
328 self
.InfVersion
.Comments
= Comments
331 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(InfVersion),
332 LineInfo
=self
.CurrentLine
)
337 def GetInfVersion(self
):
338 return self
.InfVersion
340 ## SetEdkReleaseVersion
342 # @param EdkReleaseVersion: EdkReleaseVersion
344 def SetEdkReleaseVersion(self
, EdkReleaseVersion
, Comments
):
346 # Value has been set before.
348 if self
.EdkReleaseVersion
!= None:
349 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
350 %(DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
),
351 LineInfo
=self
.CurrentLine
)
354 # The EdkReleaseVersion should be 4 bytes hex string.
356 if IsValidHexVersion(EdkReleaseVersion
) or \
357 IsValidDecVersionVal(EdkReleaseVersion
):
358 self
.EdkReleaseVersion
= InfDefMember()
359 self
.EdkReleaseVersion
.SetValue(EdkReleaseVersion
)
360 self
.EdkReleaseVersion
.Comments
= Comments
363 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
364 %(EdkReleaseVersion),
365 LineInfo
=self
.CurrentLine
)
368 ## GetEdkReleaseVersion
370 def GetEdkReleaseVersion(self
):
371 return self
.EdkReleaseVersion
373 ## SetUefiSpecificationVersion
375 # @param UefiSpecificationVersion: UefiSpecificationVersion
377 def SetUefiSpecificationVersion(self
, UefiSpecificationVersion
, Comments
):
379 # Value has been set before.
381 if self
.UefiSpecificationVersion
!= None:
382 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
383 %(DT
.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
),
384 LineInfo
=self
.CurrentLine
)
387 # The EdkReleaseVersion should be 4 bytes hex string.
389 if IsValidHexVersion(UefiSpecificationVersion
) or \
390 IsValidDecVersionVal(UefiSpecificationVersion
):
391 self
.UefiSpecificationVersion
= InfDefMember()
392 self
.UefiSpecificationVersion
.SetValue(UefiSpecificationVersion
)
393 self
.UefiSpecificationVersion
.Comments
= Comments
396 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
397 %(UefiSpecificationVersion),
398 LineInfo
=self
.CurrentLine
)
401 ## GetUefiSpecificationVersion
403 def GetUefiSpecificationVersion(self
):
404 return self
.UefiSpecificationVersion
406 ## SetPiSpecificationVersion
408 # @param PiSpecificationVersion: PiSpecificationVersion
410 def SetPiSpecificationVersion(self
, PiSpecificationVersion
, Comments
):
412 # Value has been set before.
414 if self
.PiSpecificationVersion
!= None:
415 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
416 %(DT
.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
),
417 LineInfo
=self
.CurrentLine
)
420 # The EdkReleaseVersion should be 4 bytes hex string.
422 if IsValidHexVersion(PiSpecificationVersion
) or \
423 IsValidDecVersionVal(PiSpecificationVersion
):
424 self
.PiSpecificationVersion
= InfDefMember()
425 self
.PiSpecificationVersion
.SetValue(PiSpecificationVersion
)
426 self
.PiSpecificationVersion
.Comments
= Comments
429 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
430 %(PiSpecificationVersion),
431 LineInfo
=self
.CurrentLine
)
434 ## GetPiSpecificationVersion
436 def GetPiSpecificationVersion(self
):
437 return self
.PiSpecificationVersion
441 # @param LibraryClass: LibraryClass
443 def SetLibraryClass(self
, LibraryClass
, Comments
):
444 ValueList
= GetSplitValueList(LibraryClass
)
446 if IsValidWord(Name
):
447 InfDefineLibraryItemObj
= InfDefineLibraryItem()
448 InfDefineLibraryItemObj
.SetLibraryName(Name
)
449 InfDefineLibraryItemObj
.Comments
= Comments
450 if len(ValueList
) == 2:
452 TypeList
= GetSplitValueList(Type
, ' ')
453 for Item
in TypeList
:
454 if Item
not in DT
.MODULE_LIST
:
455 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Item),
456 LineInfo
=self
.CurrentLine
)
458 InfDefineLibraryItemObj
.SetTypes(TypeList
)
459 self
.LibraryClass
.append(InfDefineLibraryItemObj
)
461 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Name),
462 LineInfo
=self
.CurrentLine
)
467 def GetLibraryClass(self
):
468 return self
.LibraryClass
470 def SetVersionString(self
, VersionString
, Comments
):
472 # Value has been set before.
474 if self
.VersionString
!= None:
475 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
476 %(DT
.TAB_INF_DEFINES_VERSION_STRING
),
477 LineInfo
=self
.CurrentLine
)
479 if not IsValidDecVersion(VersionString
):
480 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
482 LineInfo
=self
.CurrentLine
)
483 self
.VersionString
= InfDefMember()
484 self
.VersionString
.SetValue(VersionString
)
485 self
.VersionString
.Comments
= Comments
489 def GetVersionString(self
):
490 return self
.VersionString
492 def SetPcdIsDriver(self
, PcdIsDriver
, Comments
):
494 # Value has been set before.
496 if self
.PcdIsDriver
!= None:
497 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
498 %(DT
.TAB_INF_DEFINES_PCD_IS_DRIVER
),
499 LineInfo
=self
.CurrentLine
)
501 if PcdIsDriver
== 'PEI_PCD_DRIVER' or PcdIsDriver
== 'DXE_PCD_DRIVER':
502 self
.PcdIsDriver
= InfDefMember()
503 self
.PcdIsDriver
.SetValue(PcdIsDriver
)
504 self
.PcdIsDriver
.Comments
= Comments
507 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PcdIsDriver),
508 LineInfo
=self
.CurrentLine
)
511 def GetPcdIsDriver(self
):
512 return self
.PcdIsDriver
517 def SetEntryPoint(self
, EntryPoint
, Comments
):
523 TokenList
= GetSplitValueList(EntryPoint
, DT
.TAB_VALUE_SPLIT
)
524 ValueList
[0:len(TokenList
)] = TokenList
526 InfDefineEntryPointItemObj
= InfDefineEntryPointItem()
527 if not IsValidCVariableName(ValueList
[0]):
528 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
530 LineInfo
=self
.CurrentLine
)
531 InfDefineEntryPointItemObj
.SetCName(ValueList
[0])
532 if len(ValueList
) == 2:
533 if ValueList
[1].strip() == '':
534 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
536 LineInfo
=self
.CurrentLine
)
540 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[1].strip())
541 if not FeatureFlagRtv
[0]:
542 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%\
544 LineInfo
=self
.CurrentLine
)
546 InfDefineEntryPointItemObj
.SetFeatureFlagExp(ValueList
[1])
547 if len(ValueList
) > 2:
548 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(EntryPoint),
549 LineInfo
=self
.CurrentLine
)
551 InfDefineEntryPointItemObj
.Comments
= Comments
552 self
.EntryPoint
.append(InfDefineEntryPointItemObj
)
554 def GetEntryPoint(self
):
555 return self
.EntryPoint
560 def SetUnloadImages(self
, UnloadImages
, Comments
):
566 TokenList
= GetSplitValueList(UnloadImages
, DT
.TAB_VALUE_SPLIT
)
567 ValueList
[0:len(TokenList
)] = TokenList
569 InfDefineUnloadImageItemObj
= InfDefineUnloadImageItem()
570 if not IsValidCVariableName(ValueList
[0]):
571 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
572 LineInfo
=self
.CurrentLine
)
573 InfDefineUnloadImageItemObj
.SetCName(ValueList
[0])
574 if len(ValueList
) == 2:
575 if ValueList
[1].strip() == '':
576 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
577 LineInfo
=self
.CurrentLine
)
581 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[1].strip())
582 if not FeatureFlagRtv
[0]:
583 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
584 LineInfo
=self
.CurrentLine
)
585 InfDefineUnloadImageItemObj
.SetFeatureFlagExp(ValueList
[1])
587 if len(ValueList
) > 2:
588 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(UnloadImages),
589 LineInfo
=self
.CurrentLine
)
591 InfDefineUnloadImageItemObj
.Comments
= Comments
592 self
.UnloadImages
.append(InfDefineUnloadImageItemObj
)
594 def GetUnloadImages(self
):
595 return self
.UnloadImages
600 def SetConstructor(self
, Constructor
, Comments
):
606 TokenList
= GetSplitValueList(Constructor
, DT
.TAB_VALUE_SPLIT
)
607 ValueList
[0:len(TokenList
)] = TokenList
609 InfDefineConstructorItemObj
= InfDefineConstructorItem()
610 if not IsValidCVariableName(ValueList
[0]):
611 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
612 LineInfo
=self
.CurrentLine
)
613 InfDefineConstructorItemObj
.SetCName(ValueList
[0])
614 if len(ValueList
) >= 2:
615 ModList
= GetSplitValueList(ValueList
[1], ' ')
616 if ValueList
[1].strip() == '':
617 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
618 LineInfo
=self
.CurrentLine
)
619 for ModItem
in ModList
:
620 if ModItem
not in DT
.MODULE_LIST
:
621 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%(ModItem),
622 LineInfo
=self
.CurrentLine
)
623 InfDefineConstructorItemObj
.SetSupModList(ModList
)
624 if len(ValueList
) == 3:
625 if ValueList
[2].strip() == '':
626 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[2]),
627 LineInfo
=self
.CurrentLine
)
631 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[2].strip())
632 if not FeatureFlagRtv
[0]:
633 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[2]),
634 LineInfo
=self
.CurrentLine
)
635 InfDefineConstructorItemObj
.SetFeatureFlagExp(ValueList
[2])
637 if len(ValueList
) > 3:
638 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Constructor),
639 LineInfo
=self
.CurrentLine
)
641 InfDefineConstructorItemObj
.Comments
= Comments
642 self
.Constructor
.append(InfDefineConstructorItemObj
)
644 def GetConstructor(self
):
645 return self
.Constructor
650 def SetDestructor(self
, Destructor
, Comments
):
652 # It can be a list and only 1 set to TRUE
656 TokenList
= GetSplitValueList(Destructor
, DT
.TAB_VALUE_SPLIT
)
657 ValueList
[0:len(TokenList
)] = TokenList
659 InfDefineDestructorItemObj
= InfDefineDestructorItem()
660 if not IsValidCVariableName(ValueList
[0]):
661 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
662 LineInfo
=self
.CurrentLine
)
663 InfDefineDestructorItemObj
.SetCName(ValueList
[0])
664 if len(ValueList
) >= 2:
665 ModList
= GetSplitValueList(ValueList
[1].strip(), ' ')
666 if ValueList
[1].strip() == '':
667 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
668 LineInfo
=self
.CurrentLine
)
669 for ModItem
in ModList
:
670 if ModItem
not in DT
.MODULE_LIST
:
671 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%(ModItem),
672 LineInfo
=self
.CurrentLine
)
673 InfDefineDestructorItemObj
.SetSupModList(ModList
)
674 if len(ValueList
) == 3:
675 if ValueList
[2].strip() == '':
676 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[2]),
677 LineInfo
=self
.CurrentLine
)
681 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[2].strip())
682 if not FeatureFlagRtv
[0]:
683 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
684 LineInfo
=self
.CurrentLine
)
685 InfDefineDestructorItemObj
.SetFeatureFlagExp(ValueList
[2])
687 if len(ValueList
) > 3:
688 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Destructor),
689 LineInfo
=self
.CurrentLine
)
691 InfDefineDestructorItemObj
.Comments
= Comments
692 self
.Destructor
.append(InfDefineDestructorItemObj
)
694 def GetDestructor(self
):
695 return self
.Destructor
697 def SetShadow(self
, Shadow
, Comments
):
699 # Value has been set before.
701 if self
.Shadow
!= None:
702 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_SHADOW
),
703 LineInfo
=self
.CurrentLine
)
705 if (IsValidBoolType(Shadow
)):
706 self
.Shadow
= InfDefMember()
707 self
.Shadow
.SetValue(Shadow
)
708 self
.Shadow
.Comments
= Comments
711 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Shadow),
712 LineInfo
=self
.CurrentLine
)
720 # <Family> ::= {"MSFT"} {"GCC"}
721 # <CustomMake> ::= [<Family> "|"] <Filename>
723 def SetCustomMakefile(self
, CustomMakefile
, Comments
):
724 if not (CustomMakefile
== '' or CustomMakefile
== None):
725 ValueList
= GetSplitValueList(CustomMakefile
)
726 if len(ValueList
) == 1:
727 FileName
= ValueList
[0]
730 Family
= ValueList
[0]
731 FileName
= ValueList
[1]
732 Family
= Family
.strip()
734 if not IsValidFamily(Family
):
735 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Family),
736 LineInfo
=self
.CurrentLine
)
739 # The MakefileName specified file should exist
741 IsValidFileFlag
= False
742 ModulePath
= os
.path
.split(self
.CurrentLine
[0])[0]
743 if IsValidPath(FileName
, ModulePath
):
744 IsValidFileFlag
= True
746 ErrorInInf(ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(FileName),
747 LineInfo
=self
.CurrentLine
)
750 FileName
= ConvPathFromAbsToRel(FileName
, GlobalData
.gINF_MODULE_DIR
)
751 self
.CustomMakefile
.append((Family
, FileName
, Comments
))
752 IsValidFileFlag
= False
757 def GetCustomMakefile(self
):
758 return self
.CustomMakefile
761 # ["SPEC" <Spec> <EOL>]*{0,}
762 # <Spec> ::= <Word> "=" <VersionVal>
763 # <VersionVal> ::= {<HexVersion>] {<DecVersion>}
764 # <HexNumber> ::= "0x" [<HexDigit>]{1,}
765 # <DecVersion> ::= (0-9){1,} ["." (0-9){1,2}]
767 def SetSpecification(self
, Specification
, Comments
):
769 # Valid the value of Specification
772 TokenList
= GetSplitValueList(Specification
, DT
.TAB_EQUAL_SPLIT
, 1)
773 __ValueList
[0:len(TokenList
)] = TokenList
774 if len(__ValueList
) != 2:
775 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME
+ ' Or ' + ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE
,
776 LineInfo
=self
.CurrentLine
)
777 Name
= __ValueList
[0].strip()
778 Version
= __ValueList
[1].strip()
779 if IsValidIdentifier(Name
):
780 if IsValidDecVersion(Version
):
781 self
.Specification
.append((Name
, Version
, Comments
))
784 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Version),
785 LineInfo
=self
.CurrentLine
)
788 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Name),
789 LineInfo
=self
.CurrentLine
)
794 def GetSpecification(self
):
795 return self
.Specification
798 # [<UefiHiiResource> <EOL>]{0,1}
799 # <UefiHiiResource> ::= "UEFI_HII_RESOURCE_SECTION" "=" <BoolType>
801 def SetUefiHiiResourceSection(self
, UefiHiiResourceSection
, Comments
):
803 # Value has been set before.
805 if self
.UefiHiiResourceSection
!= None:
806 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
807 %(DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
),
808 LineInfo
=self
.CurrentLine
)
810 if not (UefiHiiResourceSection
== '' or UefiHiiResourceSection
== None):
811 if (IsValidBoolType(UefiHiiResourceSection
)):
812 self
.UefiHiiResourceSection
= InfDefMember()
813 self
.UefiHiiResourceSection
.SetValue(UefiHiiResourceSection
)
814 self
.UefiHiiResourceSection
.Comments
= Comments
817 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(UefiHiiResourceSection),
818 LineInfo
=self
.CurrentLine
)
823 def GetUefiHiiResourceSection(self
):
824 return self
.UefiHiiResourceSection
826 def SetDpxSource(self
, DpxSource
, Comments
):
828 # The MakefileName specified file should exist
830 IsValidFileFlag
= False
831 ModulePath
= os
.path
.split(self
.CurrentLine
[0])[0]
832 if IsValidPath(DpxSource
, ModulePath
):
833 IsValidFileFlag
= True
835 ErrorInInf(ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(DpxSource),
836 LineInfo
=self
.CurrentLine
)
839 DpxSource
= ConvPathFromAbsToRel(DpxSource
,
840 GlobalData
.gINF_MODULE_DIR
)
841 self
.DpxSource
.append((DpxSource
, Comments
))
842 IsValidFileFlag
= False
845 def GetDpxSource(self
):
846 return self
.DpxSource
848 gFUNCTION_MAPPING_FOR_DEFINE_SECTION
= {
852 DT
.TAB_INF_DEFINES_BASE_NAME
: InfDefSection
.SetBaseName
,
853 DT
.TAB_INF_DEFINES_FILE_GUID
: InfDefSection
.SetFileGuid
,
854 DT
.TAB_INF_DEFINES_MODULE_TYPE
: InfDefSection
.SetModuleType
,
856 # Required by EDKII style INF file
858 DT
.TAB_INF_DEFINES_INF_VERSION
: InfDefSection
.SetInfVersion
,
862 DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
: InfDefSection
.SetEdkReleaseVersion
,
863 DT
.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
: InfDefSection
.SetUefiSpecificationVersion
,
864 DT
.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
: InfDefSection
.SetPiSpecificationVersion
,
865 DT
.TAB_INF_DEFINES_LIBRARY_CLASS
: InfDefSection
.SetLibraryClass
,
866 DT
.TAB_INF_DEFINES_VERSION_STRING
: InfDefSection
.SetVersionString
,
867 DT
.TAB_INF_DEFINES_PCD_IS_DRIVER
: InfDefSection
.SetPcdIsDriver
,
868 DT
.TAB_INF_DEFINES_ENTRY_POINT
: InfDefSection
.SetEntryPoint
,
869 DT
.TAB_INF_DEFINES_UNLOAD_IMAGE
: InfDefSection
.SetUnloadImages
,
870 DT
.TAB_INF_DEFINES_CONSTRUCTOR
: InfDefSection
.SetConstructor
,
871 DT
.TAB_INF_DEFINES_DESTRUCTOR
: InfDefSection
.SetDestructor
,
872 DT
.TAB_INF_DEFINES_SHADOW
: InfDefSection
.SetShadow
,
873 DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
: InfDefSection
.SetPciVendorId
,
874 DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
: InfDefSection
.SetPciDeviceId
,
875 DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
: InfDefSection
.SetPciClassCode
,
876 DT
.TAB_INF_DEFINES_PCI_REVISION
: InfDefSection
.SetPciRevision
,
877 DT
.TAB_INF_DEFINES_PCI_COMPRESS
: InfDefSection
.SetPciCompress
,
878 DT
.TAB_INF_DEFINES_CUSTOM_MAKEFILE
: InfDefSection
.SetCustomMakefile
,
879 DT
.TAB_INF_DEFINES_SPEC
: InfDefSection
.SetSpecification
,
880 DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
: InfDefSection
.SetUefiHiiResourceSection
,
881 DT
.TAB_INF_DEFINES_DPX_SOURCE
: InfDefSection
.SetDpxSource
887 class InfDefMember():
888 def __init__(self
, Name
='', Value
=''):
889 self
.Comments
= InfLineCommentObject()
892 self
.CurrentLine
= CurrentLine()
896 def SetName(self
, Name
):
900 def SetValue(self
, Value
):
906 class InfDefObject(InfSectionCommonDef
):
908 self
.Defines
= Sdict()
909 InfSectionCommonDef
.__init
__(self
)
910 def SetDefines(self
, DefineContent
, Arch
= None):
914 HasFoundInfVersionFalg
= False
915 LineInfo
= ['', -1, '']
916 ArchListString
= ' '.join(Arch
)
919 # Parse Define items.
921 for InfDefMemberObj
in DefineContent
:
923 Name
= InfDefMemberObj
.GetName()
924 Value
= InfDefMemberObj
.GetValue()
925 InfLineCommentObj
= InfLineCommentObject()
926 InfLineCommentObj
.SetHeaderComments(InfDefMemberObj
.Comments
.GetHeaderComments())
927 InfLineCommentObj
.SetTailComments(InfDefMemberObj
.Comments
.GetTailComments())
928 if Name
== 'COMPONENT_TYPE':
929 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
930 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
932 if Name
== DT
.TAB_INF_DEFINES_INF_VERSION
:
933 HasFoundInfVersionFalg
= True
935 if not (Name
== '' or Name
== None):
937 # Process "SPEC" Keyword definition.
939 ReName
= re
.compile(r
"SPEC ", re
.DOTALL
)
940 if ReName
.match(Name
):
941 SpecValue
= Name
[Name
.find("SPEC") + len("SPEC"):].strip()
943 Value
= SpecValue
+ " = " + Value
944 if self
.Defines
.has_key(ArchListString
):
945 DefineList
= self
.Defines
[ArchListString
]
946 LineInfo
[0] = InfDefMemberObj
.CurrentLine
.GetFileName()
947 LineInfo
[1] = InfDefMemberObj
.CurrentLine
.GetLineNo()
948 LineInfo
[2] = InfDefMemberObj
.CurrentLine
.GetLineString()
949 DefineList
.CurrentLine
= LineInfo
951 # Found the process function from mapping table.
953 if Name
not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION
.keys():
954 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID
%(Name),
958 ProcessFunc
= gFUNCTION_MAPPING_FOR_DEFINE_SECTION
[Name
]
959 if (ProcessFunc
!= None):
960 ProcessFunc(DefineList
, Value
, InfLineCommentObj
)
961 self
.Defines
[ArchListString
] = DefineList
963 DefineList
= InfDefSection()
964 LineInfo
[0] = InfDefMemberObj
.CurrentLine
.GetFileName()
965 LineInfo
[1] = InfDefMemberObj
.CurrentLine
.GetLineNo()
966 LineInfo
[2] = InfDefMemberObj
.CurrentLine
.GetLineString()
967 DefineList
.CurrentLine
= LineInfo
969 # Found the process function from mapping table.
971 if Name
not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION
.keys():
972 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID
%(Name),
975 # Found the process function from mapping table.
978 ProcessFunc
= gFUNCTION_MAPPING_FOR_DEFINE_SECTION
[Name
]
979 if (ProcessFunc
!= None):
980 ProcessFunc(DefineList
, Value
, InfLineCommentObj
)
981 self
.Defines
[ArchListString
] = DefineList
984 # After set, check whether INF_VERSION defined.
986 if not HasFoundInfVersionFalg
:
987 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
988 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
992 def GetDefines(self
):