def SetLibraryClass(self, LibraryClass, Comments):
        ValueList = GetSplitValueList(LibraryClass)
        Name = ValueList[0]
        if IsValidWord(Name):
            InfDefineLibraryItemObj = InfDefineLibraryItem()
            InfDefineLibraryItemObj.SetLibraryName(Name)
            InfDefineLibraryItemObj.Comments = Comments
            if len(ValueList) == 2:
                Type = ValueList[1]
                TypeList = GetSplitValueList(Type, ' ')
                TypeList = [Type for Type in TypeList if Type != '']
                for Item in TypeList:
                    if Item not in DT.MODULE_LIST:
                        ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                                   (Item),
                                   LineInfo=self.CurrentLine)
                        return False
                InfDefineLibraryItemObj.SetTypes(TypeList)
            self.LibraryClass.append(InfDefineLibraryItemObj)
        else:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Name),
                       LineInfo=self.CurrentLine)
            return False

        return True
    def SetUnloadImages(self, UnloadImages, Comments):
        #
        # It can be a list
        #
        ValueList = []
        TokenList = GetSplitValueList(UnloadImages, DT.TAB_VALUE_SPLIT)
        ValueList[0:len(TokenList)] = TokenList
        InfDefineUnloadImageItemObj = InfDefineUnloadImageItem()
        if not IsValidCVariableName(ValueList[0]):
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (ValueList[0]),
                       LineInfo=self.CurrentLine)
        InfDefineUnloadImageItemObj.SetCName(ValueList[0])
        if len(ValueList) == 2:
            if ValueList[1].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[1]),
                           LineInfo=self.CurrentLine)
            #
            # Validate FFE
            #
            FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[1].strip())
            if not FeatureFlagRtv[0]:
                ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                           (FeatureFlagRtv[1]),
                           LineInfo=self.CurrentLine)
            InfDefineUnloadImageItemObj.SetFeatureFlagExp(ValueList[1])

        if len(ValueList) > 2:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (UnloadImages),
                       LineInfo=self.CurrentLine)
        InfDefineUnloadImageItemObj.Comments = Comments
        self.UnloadImages.append(InfDefineUnloadImageItemObj)
 def SetModuleType(self, ModuleType, Comments):
     #
     # Value has been set before.
     #
     if self.ModuleType is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
                    %(DT.TAB_INF_DEFINES_MODULE_TYPE),
                    LineInfo=self.CurrentLine)
         return False
     #
     # Valid Module Type or not
     #
     if (IsValidInfMoudleType(ModuleType)):
         self.ModuleType = InfDefMember()
         self.ModuleType.SetValue(ModuleType)
         self.ModuleType.CurrentLine = CurrentLine()
         self.ModuleType.CurrentLine.SetLineNo(self.CurrentLine[1])
         self.ModuleType.CurrentLine.SetLineString(self.CurrentLine[2])
         self.ModuleType.CurrentLine.SetFileName(self.CurrentLine[0])
         self.ModuleType.Comments = Comments
         return True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID%\
                    (ModuleType),
                    LineInfo=self.CurrentLine)
         return False
 def SetSpecification(self, Specification, Comments):
     #
     # Valid the value of Specification
     #
     __ValueList = []
     TokenList = GetSplitValueList(Specification, DT.TAB_EQUAL_SPLIT, 1)
     __ValueList[0:len(TokenList)] = TokenList
     if len(__ValueList) != 2:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME + ' Or ' +
                    ST.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE,
                    LineInfo=self.CurrentLine)
     Name = __ValueList[0].strip()
     Version = __ValueList[1].strip()
     if IsValidIdentifier(Name):
         if IsValidDecVersion(Version):
             self.Specification.append((Name, Version, Comments))
             return True
         else:
             ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Version),
                        LineInfo=self.CurrentLine)
             return False
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Name),
                    LineInfo=self.CurrentLine)
         return False
     return True
    def SetInfVersion(self, InfVersion, Comments):
        #
        # Value has been set before.
        #
        if self.InfVersion is not None:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
                       %(DT.TAB_INF_DEFINES_INF_VERSION),
                       LineInfo=self.CurrentLine)
            return False
        #
        # The InfVersion should be 4 bytes hex string.
        #
        if (IsValidHex(InfVersion)):
            if (InfVersion < '0x00010005'):
                ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
                           ErrorCode=ToolError.EDK1_INF_ERROR,
                           LineInfo=self.CurrentLine)
        elif IsValidDecVersionVal(InfVersion):
            if (InfVersion < 65541):
                ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
                           ErrorCode=ToolError.EDK1_INF_ERROR,
                           LineInfo=self.CurrentLine)
        else:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (InfVersion),
                       LineInfo=self.CurrentLine)
            return False

        self.InfVersion = InfDefMember()
        self.InfVersion.SetValue(InfVersion)
        self.InfVersion.Comments = Comments
        return True
 def SetVersionString(self, VersionString, Comments):
     #
     # Value has been set before.
     #
     if self.VersionString is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
                    %(DT.TAB_INF_DEFINES_VERSION_STRING),
                    LineInfo=self.CurrentLine)
         return False
     if not IsValidDecVersion(VersionString):
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
                    %(VersionString),
                    LineInfo=self.CurrentLine)
     self.VersionString = InfDefMember()
     self.VersionString.SetValue(VersionString)
     self.VersionString.Comments = Comments
     return True
 def SetModuleUniFileName(self, ModuleUniFileName, Comments):
     if Comments:
         pass
     if self.ModuleUniFileName is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND %
                    (DT.TAB_INF_DEFINES_MODULE_UNI_FILE),
                    LineInfo=self.CurrentLine)
     self.ModuleUniFileName = ModuleUniFileName
 def SetShadow(self, Shadow, Comments):
     #
     # Value has been set before.
     #
     if self.Shadow is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND %
                    (DT.TAB_INF_DEFINES_SHADOW),
                    LineInfo=self.CurrentLine)
         return False
     if (IsValidBoolType(Shadow)):
         self.Shadow = InfDefMember()
         self.Shadow.SetValue(Shadow)
         self.Shadow.Comments = Comments
         return True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Shadow),
                    LineInfo=self.CurrentLine)
         return False
 def SetPcdIsDriver(self, PcdIsDriver, Comments):
     #
     # Value has been set before.
     #
     if self.PcdIsDriver is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
                    %(DT.TAB_INF_DEFINES_PCD_IS_DRIVER),
                    LineInfo=self.CurrentLine)
         return False
     if PcdIsDriver == 'PEI_PCD_DRIVER' or PcdIsDriver == 'DXE_PCD_DRIVER':
         self.PcdIsDriver = InfDefMember()
         self.PcdIsDriver.SetValue(PcdIsDriver)
         self.PcdIsDriver.Comments = Comments
         return True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (PcdIsDriver),
                    LineInfo=self.CurrentLine)
         return False
 def SetBaseName(self, BaseName, Comments):
     #
     # Value has been set before.
     #
     if self.BaseName is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND %
                    (DT.TAB_INF_DEFINES_BASE_NAME),
                    LineInfo=self.CurrentLine)
         return False
     if not (BaseName == '' or BaseName is None):
         if IsValidWord(BaseName) and not BaseName.startswith("_"):
             self.BaseName = InfDefMember()
             self.BaseName.SetValue(BaseName)
             self.BaseName.Comments = Comments
             return True
         else:
             ErrorInInf(ST.ERR_INF_PARSER_DEFINE_NAME_INVALID % (BaseName),
                        LineInfo=self.CurrentLine)
             return False
 def SetPciRevision(self, PciRevision, Comments):
     #
     # Value has been set before.
     #
     if self.PciRevision is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND %
                    (DT.TAB_INF_DEFINES_PCI_REVISION),
                    LineInfo=self.CurrentLine)
         return False
     #
     # The PciRevision should be 4 bytes hex string.
     #
     if (IsValidHex(PciRevision)):
         self.PciRevision = InfDefMember()
         self.PciRevision.SetValue(PciRevision)
         self.PciRevision.Comments = Comments
         return True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (PciRevision),
                    LineInfo=self.CurrentLine)
         return False
 def SetPciDeviceId(self, PciDeviceId, Comments):
     #
     # Value has been set before.
     #
     if self.PciDeviceId is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND %
                    (DT.TAB_INF_DEFINES_PCI_DEVICE_ID),
                    LineInfo=self.CurrentLine)
         return False
     #
     # The PciDeviceId should be hex string.
     #
     if (IsValidHex(PciDeviceId)):
         self.PciDeviceId = InfDefMember()
         self.PciDeviceId.SetValue(PciDeviceId)
         self.PciDeviceId.Comments = Comments
         return True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (PciDeviceId),
                    LineInfo=self.CurrentLine)
         return False
 def SetFileGuid(self, FileGuid, Comments):
     #
     # Value has been set before.
     #
     if self.FileGuid is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
                    %(DT.TAB_INF_DEFINES_FILE_GUID),
                    LineInfo=self.CurrentLine)
         return False
     #
     # Do verification of GUID content/format
     #
     if (CheckGuidRegFormat(FileGuid)):
         self.FileGuid = InfDefMember()
         self.FileGuid.SetValue(FileGuid)
         self.FileGuid.Comments = Comments
         return True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_GUID_INVALID % (FileGuid),
                    LineInfo=self.CurrentLine)
         return False
 def SetPciClassCode(self, PciClassCode, Comments):
     #
     # Value has been set before.
     #
     if self.PciClassCode is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND %
                    (DT.TAB_INF_DEFINES_PCI_CLASS_CODE),
                    LineInfo=self.CurrentLine)
         return False
     #
     # The PciClassCode should be 4 bytes hex string.
     #
     if (IsValidHex(PciClassCode)):
         self.PciClassCode = InfDefMember()
         self.PciClassCode.SetValue(PciClassCode)
         self.PciClassCode.Comments = Comments
         return True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%\
                    (PciClassCode),
                    LineInfo=self.CurrentLine)
         return False
    def SetPciCompress(self, PciCompress, Comments):
        #
        # Value has been set before.
        #
        if self.PciCompress is not None:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND %
                       (DT.TAB_INF_DEFINES_PCI_COMPRESS),
                       LineInfo=self.CurrentLine)
            return False

        #
        # The PciCompress should be 'TRUE' or 'FALSE'.
        #
        if (PciCompress == 'TRUE' or PciCompress == 'FALSE'):
            self.PciCompress = InfDefMember()
            self.PciCompress.SetValue(PciCompress)
            self.PciCompress.Comments = Comments
            return True
        else:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (PciCompress),
                       LineInfo=self.CurrentLine)
            return False
 def SetUefiHiiResourceSection(self, UefiHiiResourceSection, Comments):
     #
     # Value has been set before.
     #
     if self.UefiHiiResourceSection is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND %
                    (DT.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION),
                    LineInfo=self.CurrentLine)
         return False
     if not (UefiHiiResourceSection == ''
             or UefiHiiResourceSection is None):
         if (IsValidBoolType(UefiHiiResourceSection)):
             self.UefiHiiResourceSection = InfDefMember()
             self.UefiHiiResourceSection.SetValue(UefiHiiResourceSection)
             self.UefiHiiResourceSection.Comments = Comments
             return True
         else:
             ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                        (UefiHiiResourceSection),
                        LineInfo=self.CurrentLine)
             return False
     else:
         return False
 def SetPiSpecificationVersion(self, PiSpecificationVersion, Comments):
     #
     # Value has been set before.
     #
     if self.PiSpecificationVersion is not None:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
                    %(DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION),
                    LineInfo=self.CurrentLine)
         return False
     #
     # The EdkReleaseVersion should be 4 bytes hex string.
     #
     if IsValidHexVersion(PiSpecificationVersion) or \
        IsValidDecVersionVal(PiSpecificationVersion):
         self.PiSpecificationVersion = InfDefMember()
         self.PiSpecificationVersion.SetValue(PiSpecificationVersion)
         self.PiSpecificationVersion.Comments = Comments
         return True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
                    %(PiSpecificationVersion),
                    LineInfo=self.CurrentLine)
         return False
 def SetCustomMakefile(self, CustomMakefile, Comments):
     if not (CustomMakefile == '' or CustomMakefile is None):
         ValueList = GetSplitValueList(CustomMakefile)
         if len(ValueList) == 1:
             FileName = ValueList[0]
             Family = ''
         else:
             Family = ValueList[0]
             FileName = ValueList[1]
         Family = Family.strip()
         if Family != '':
             if not IsValidFamily(Family):
                 ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                            (Family),
                            LineInfo=self.CurrentLine)
                 return False
         #
         # The MakefileName specified file should exist
         #
         IsValidFileFlag = False
         ModulePath = os.path.split(self.CurrentLine[0])[0]
         if IsValidPath(FileName, ModulePath):
             IsValidFileFlag = True
         else:
             ErrorInInf(ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                        (FileName),
                        LineInfo=self.CurrentLine)
             return False
         if IsValidFileFlag:
             FileName = ConvPathFromAbsToRel(FileName,
                                             GlobalData.gINF_MODULE_DIR)
             self.CustomMakefile.append((Family, FileName, Comments))
             IsValidFileFlag = False
         return True
     else:
         return False
Beispiel #19
0
def InfExpandMacro(Content,
                   LineInfo,
                   GlobalMacros=None,
                   SectionMacros=None,
                   Flag=False):
    if GlobalMacros is None:
        GlobalMacros = {}
    if SectionMacros is None:
        SectionMacros = {}

    FileName = LineInfo[0]
    LineContent = LineInfo[1]
    LineNo = LineInfo[2]

    # Don't expand macros in comments
    if LineContent.strip().startswith("#"):
        return Content

    NewLineInfo = (FileName, LineNo, LineContent)

    #
    # First, replace MARCOs with value defined in specific section
    #
    Content = ReplaceMacro(Content, SectionMacros, False,
                           (LineContent, LineNo), FileName, Flag)
    #
    # Then replace MARCOs with value defined in [Defines] section
    #
    Content = ReplaceMacro(Content, GlobalMacros, False, (LineContent, LineNo),
                           FileName, Flag)

    MacroUsed = gMACRO_PATTERN.findall(Content)
    #
    # no macro found in String, stop replacing
    #
    if len(MacroUsed) == 0:
        return Content
    else:
        for Macro in MacroUsed:
            gQuotedMacro = re.compile(".*\".*\$\(%s\).*\".*" % (Macro))
            if not gQuotedMacro.match(Content):
                #
                # Still have MACROs can't be expanded.
                #
                ErrorInInf(ERR_MARCO_DEFINITION_MISS_ERROR,
                           LineInfo=NewLineInfo)

    return Content
 def SetDpxSource(self, DpxSource, Comments):
     #
     # The MakefileName specified file should exist
     #
     IsValidFileFlag = False
     ModulePath = os.path.split(self.CurrentLine[0])[0]
     if IsValidPath(DpxSource, ModulePath):
         IsValidFileFlag = True
     else:
         ErrorInInf(ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                    (DpxSource),
                    LineInfo=self.CurrentLine)
         return False
     if IsValidFileFlag:
         DpxSource = ConvPathFromAbsToRel(DpxSource,
                                          GlobalData.gINF_MODULE_DIR)
         self.DpxSource.append((DpxSource, Comments))
         IsValidFileFlag = False
     return True
    def SetDestructor(self, Destructor, Comments):
        #
        # It can be a list and only 1 set to TRUE
        #
        ValueList = []
        TokenList = GetSplitValueList(Destructor, DT.TAB_VALUE_SPLIT)
        ValueList[0:len(TokenList)] = TokenList
        InfDefineDestructorItemObj = InfDefineDestructorItem()
        if not IsValidCVariableName(ValueList[0]):
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (ValueList[0]),
                       LineInfo=self.CurrentLine)
        InfDefineDestructorItemObj.SetCName(ValueList[0])
        if len(ValueList) >= 2:
            ModList = GetSplitValueList(ValueList[1].strip(), ' ')
            if ValueList[1].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[1]),
                           LineInfo=self.CurrentLine)
            for ModItem in ModList:
                if ModItem not in DT.MODULE_LIST:
                    ErrorInInf(ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID %
                               (ModItem),
                               LineInfo=self.CurrentLine)
            InfDefineDestructorItemObj.SetSupModList(ModList)
        if len(ValueList) == 3:
            if ValueList[2].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[2]),
                           LineInfo=self.CurrentLine)
            #
            # Validate FFE
            #
            FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[2].strip())
            if not FeatureFlagRtv[0]:
                ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                           (FeatureFlagRtv[1]),
                           LineInfo=self.CurrentLine)
            InfDefineDestructorItemObj.SetFeatureFlagExp(ValueList[2])

        if len(ValueList) > 3:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Destructor),
                       LineInfo=self.CurrentLine)

        InfDefineDestructorItemObj.Comments = Comments
        self.Destructor.append(InfDefineDestructorItemObj)
Beispiel #22
0
    def SetProtocol(
        self,
        ProtocolContent,
        Arch=None,
    ):
        __SupArchList = []
        for ArchItem in Arch:
            #
            # Validate Arch
            #
            if (ArchItem == '' or ArchItem is None):
                ArchItem = 'COMMON'
            __SupArchList.append(ArchItem)

        for Item in ProtocolContent:
            #
            # Get Comment content of this protocol
            #
            CommentsList = None
            if len(Item) == 3:
                CommentsList = Item[1]
            CurrentLineOfItem = Item[2]
            LineInfo = (CurrentLineOfItem[2], CurrentLineOfItem[1],
                        CurrentLineOfItem[0])
            Item = Item[0]
            InfProtocolItemObj = InfProtocolItem()
            if len(Item) >= 1 and len(Item) <= 2:
                #
                # Only CName contained
                #
                if not IsValidCVariableName(Item[0]):
                    ErrorInInf(ST.ERR_INF_PARSER_INVALID_CNAME % (Item[0]),
                               LineInfo=LineInfo)
                if (Item[0] != ''):
                    InfProtocolItemObj.SetName(Item[0])
                else:
                    ErrorInInf(ST.ERR_INF_PARSER_CNAME_MISSING,
                               LineInfo=LineInfo)
            if len(Item) == 2:
                #
                # Contained CName and Feature Flag Express
                # <statements>           ::=  <CName> ["|"
                # <FeatureFlagExpress>]
                # For Protocol Object
                #
                if Item[1].strip() == '':
                    ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                               LineInfo=LineInfo)
                #
                # Validate Feature Flag Express for Item[1]
                #
                FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())
                if not FeatureFlagRtv[0]:
                    ErrorInInf(
                        ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                        (FeatureFlagRtv[1]),
                        LineInfo=LineInfo)
                InfProtocolItemObj.SetFeatureFlagExp(Item[1])

            if len(Item) < 1 or len(Item) > 2:
                #
                # Invalid format of Protocols statement
                #
                ErrorInInf(
                    ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,
                    LineInfo=LineInfo)

            #
            # Get/Set Usage and HelpString for Protocol entry
            #
            if CommentsList is not None and len(CommentsList) != 0:
                InfProtocolItemObj = ParseProtocolComment(
                    CommentsList, InfProtocolItemObj)
            else:
                CommentItemIns = InfProtocolItemCommentContent()
                CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
                CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
                InfProtocolItemObj.SetCommentList([CommentItemIns])

            InfProtocolItemObj.SetSupArchList(__SupArchList)

            #
            # Determine protocol name duplicate. Follow below rule:
            #
            # A protocol must not be duplicated within a [Protocols] section.
            # A protocol may appear in multiple architectural [Protocols]
            # sections. A protocol listed in an architectural [Protocols]
            # section must not be listed in the common architectural
            # [Protocols] section.
            #
            # NOTE: This check will not report error now.
            #
            for Item in self.Protocols:
                if Item.GetName() == InfProtocolItemObj.GetName():
                    ItemSupArchList = Item.GetSupArchList()
                    for ItemArch in ItemSupArchList:
                        for ProtocolItemObjArch in __SupArchList:
                            if ItemArch == ProtocolItemObjArch:
                                #
                                # ST.ERR_INF_PARSER_ITEM_DUPLICATE
                                #
                                pass
                            if ItemArch.upper(
                            ) == 'COMMON' or ProtocolItemObjArch.upper(
                            ) == 'COMMON':
                                #
                                # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
                                #
                                pass

            if (InfProtocolItemObj) in self.Protocols:
                ProcotolList = self.Protocols[InfProtocolItemObj]
                ProcotolList.append(InfProtocolItemObj)
                self.Protocols[InfProtocolItemObj] = ProcotolList
            else:
                ProcotolList = []
                ProcotolList.append(InfProtocolItemObj)
                self.Protocols[InfProtocolItemObj] = ProcotolList

        return True
 def SetDefines(self, DefineContent, Arch=None):
     #
     # Validate Arch
     #
     HasFoundInfVersionFalg = False
     LineInfo = ['', -1, '']
     ArchListString = ' '.join(Arch)
     #
     # Parse Define items.
     #
     for InfDefMemberObj in DefineContent:
         ProcessFunc = None
         Name = InfDefMemberObj.GetName()
         Value = InfDefMemberObj.GetValue()
         if Name == DT.TAB_INF_DEFINES_MODULE_UNI_FILE:
             ValidateUNIFilePath(Value)
             Value = os.path.join(
                 os.path.dirname(InfDefMemberObj.CurrentLine.FileName),
                 Value)
             if not os.path.isfile(Value) or not os.path.exists(Value):
                 LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
                 LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()
                 LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString()
                 ErrorInInf(
                     ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                     (Name),
                     LineInfo=LineInfo)
         InfLineCommentObj = InfLineCommentObject()
         InfLineCommentObj.SetHeaderComments(
             InfDefMemberObj.Comments.GetHeaderComments())
         InfLineCommentObj.SetTailComments(
             InfDefMemberObj.Comments.GetTailComments())
         if Name == 'COMPONENT_TYPE':
             ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
                        ErrorCode=ToolError.EDK1_INF_ERROR,
                        RaiseError=True)
         if Name == DT.TAB_INF_DEFINES_INF_VERSION:
             HasFoundInfVersionFalg = True
         if not (Name == '' or Name is None):
             #
             # Process "SPEC" Keyword definition.
             #
             ReName = re.compile(r"SPEC ", re.DOTALL)
             if ReName.match(Name):
                 SpecValue = Name[Name.find("SPEC") + len("SPEC"):].strip()
                 Name = "SPEC"
                 Value = SpecValue + " = " + Value
             if ArchListString in self.Defines:
                 DefineList = self.Defines[ArchListString]
                 LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
                 LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()
                 LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString()
                 DefineList.CurrentLine = LineInfo
                 #
                 # Found the process function from mapping table.
                 #
                 if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys():
                     ErrorInInf(
                         ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID %
                         (Name),
                         LineInfo=LineInfo)
                 else:
                     ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[
                         Name]
                 if (ProcessFunc is not None):
                     ProcessFunc(DefineList, Value, InfLineCommentObj)
                 self.Defines[ArchListString] = DefineList
             else:
                 DefineList = InfDefSection()
                 LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
                 LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()
                 LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString()
                 DefineList.CurrentLine = LineInfo
                 #
                 # Found the process function from mapping table.
                 #
                 if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys():
                     ErrorInInf(
                         ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID %
                         (Name),
                         LineInfo=LineInfo)
                 #
                 # Found the process function from mapping table.
                 #
                 else:
                     ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[
                         Name]
                 if (ProcessFunc is not None):
                     ProcessFunc(DefineList, Value, InfLineCommentObj)
                 self.Defines[ArchListString] = DefineList
     #
     # After set, check whether INF_VERSION defined.
     #
     if not HasFoundInfVersionFalg:
         ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
                    ErrorCode=ToolError.EDK1_INF_ERROR,
                    RaiseError=True)
     return True
    def InfDefineParser(self, SectionString, InfSectionObject, FileName,
                        SectionComment):

        if SectionComment:
            pass
        #
        # Parser Defines section content and fill self._ContentList dict.
        #
        StillCommentFalg = False
        HeaderComments = []
        SectionContent = ''
        ArchList = []
        _ContentList = []
        _ValueList = []
        #
        # Add WORKSPACE to global Marco dict.
        #
        self.FileLocalMacros['WORKSPACE'] = GlobalData.gWORKSPACE

        for Line in SectionString:
            LineContent = Line[0]
            LineNo = Line[1]
            TailComments = ''
            LineComment = None

            LineInfo = ['', -1, '']
            LineInfo[0] = FileName
            LineInfo[1] = LineNo
            LineInfo[2] = LineContent

            if LineContent.strip() == '':
                continue
            #
            # The first time encountered VALIDATE_ARCHITECHERS will be considered as support arch list.
            #
            if not ArchList:
                ArchList = GetValidateArchList(LineContent)

            #
            # Parser Comment
            #
            if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):
                #
                # Last line is comments, and this line go on.
                #
                if StillCommentFalg:
                    HeaderComments.append(Line)
                    SectionContent += LineContent + DT.END_OF_LINE
                    continue
                #
                # First time encounter comment
                #
                else:
                    #
                    # Clear original data
                    #
                    HeaderComments = []
                    HeaderComments.append(Line)
                    StillCommentFalg = True
                    SectionContent += LineContent + DT.END_OF_LINE
                    continue
            else:
                StillCommentFalg = False

            if len(HeaderComments) >= 1:
                LineComment = InfLineCommentObject()
                LineCommentContent = ''
                for Item in HeaderComments:
                    LineCommentContent += Item[0] + DT.END_OF_LINE
                LineComment.SetHeaderComments(LineCommentContent)

            #
            # Find Tail comment.
            #
            if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:
                TailComments = LineContent[LineContent.
                                           find(DT.TAB_COMMENT_SPLIT):]
                LineContent = LineContent[:LineContent.find(DT.
                                                            TAB_COMMENT_SPLIT)]
                if LineComment is None:
                    LineComment = InfLineCommentObject()
                LineComment.SetTailComments(TailComments)

            #
            # Find Macro
            #
            Name, Value = MacroParser((LineContent, LineNo), FileName,
                                      DT.MODEL_META_DATA_HEADER,
                                      self.FileLocalMacros)
            if Name is not None:
                self.FileLocalMacros[Name] = Value
                continue

            #
            # Replace with [Defines] section Macro
            #
            LineContent = InfExpandMacro(LineContent,
                                         (FileName, LineContent, LineNo),
                                         self.FileLocalMacros, None, True)

            SectionContent += LineContent + DT.END_OF_LINE

            TokenList = GetSplitValueList(LineContent, DT.TAB_EQUAL_SPLIT, 1)
            if len(TokenList) < 2:
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE,
                           LineInfo=LineInfo)
            _ValueList[0:len(TokenList)] = TokenList
            if not _ValueList[0]:
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME,
                           LineInfo=LineInfo)
            if not _ValueList[1]:
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE,
                           LineInfo=LineInfo)

            Name, Value = _ValueList[0], _ValueList[1]

            InfDefMemberObj = InfDefMember(Name, Value)
            if (LineComment is not None):
                InfDefMemberObj.Comments.SetHeaderComments(
                    LineComment.GetHeaderComments())
                InfDefMemberObj.Comments.SetTailComments(
                    LineComment.GetTailComments())

            InfDefMemberObj.CurrentLine.SetFileName(self.FullPath)
            InfDefMemberObj.CurrentLine.SetLineString(LineContent)
            InfDefMemberObj.CurrentLine.SetLineNo(LineNo)

            _ContentList.append(InfDefMemberObj)
            HeaderComments = []
            TailComments = ''

        #
        # Current Define section archs
        #
        if not ArchList:
            ArchList = ['COMMON']

        InfSectionObject.SetAllContent(SectionContent)

        InfSectionObject.SetDefines(_ContentList, Arch=ArchList)