Ejemplo n.º 1
0
def ParseGuidComment(CommentsList, InfGuidItemObj):
    #
    # Get/Set Usage and HelpString
    #
    if CommentsList != None and len(CommentsList) != 0 :
        CommentInsList = []
        PreUsage = None
        PreGuidType = None
        PreHelpText = ''
        BlockFlag = -1
        Count = 0
        for CommentItem in CommentsList:
            Count = Count + 1
            CommentItemUsage, \
            CommentItemGuidType, \
            CommentItemVarString, \
            CommentItemHelpText = \
                    ParseComment(CommentItem,
                                 DT.ALL_USAGE_TOKENS,
                                 DT.GUID_TYPE_TOKENS,
                                 [],
                                 True)

            if CommentItemHelpText == None:
                CommentItemHelpText = ''
                if Count == len(CommentsList) and CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:
                    CommentItemHelpText = DT.END_OF_LINE

            if Count == len(CommentsList):
                if BlockFlag == 1 or BlockFlag == 2:
                    if CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:
                        BlockFlag = 4
                    else:
                        BlockFlag = 3
                if BlockFlag == -1:
                    BlockFlag = 4
            if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
                if CommentItemUsage == CommentItemGuidType == DT.ITEM_UNDEFINED:
                    if BlockFlag == -1:
                        BlockFlag = 1
                    elif BlockFlag == 1:
                        BlockFlag = 2
                else:
                    if BlockFlag == 1 or BlockFlag == 2:
                        BlockFlag = 3
                    elif BlockFlag == -1:
                        BlockFlag = 4

            #
            # Combine two comment line if they are generic comment
            #
            if CommentItemUsage == CommentItemGuidType == PreUsage == PreGuidType == DT.ITEM_UNDEFINED:
                CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText
                PreHelpText = CommentItemHelpText

            if BlockFlag == 4:
                CommentItemIns = InfGuidItemCommentContent()
                CommentItemIns.SetUsageItem(CommentItemUsage)
                CommentItemIns.SetGuidTypeItem(CommentItemGuidType)
                CommentItemIns.SetVariableNameItem(CommentItemVarString)
                if CommentItemHelpText == '' or CommentItemHelpText.endswith(DT.END_OF_LINE):
                    CommentItemHelpText = CommentItemHelpText.strip(DT.END_OF_LINE)
                CommentItemIns.SetHelpStringItem(CommentItemHelpText)
                CommentInsList.append(CommentItemIns)

                BlockFlag = -1
                PreUsage = None
                PreGuidType = None
                PreHelpText = ''

            elif BlockFlag == 3:
                #
                # Add previous help string
                #
                CommentItemIns = InfGuidItemCommentContent()
                CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
                CommentItemIns.SetGuidTypeItem(DT.ITEM_UNDEFINED)
                if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
                    PreHelpText = PreHelpText.strip(DT.END_OF_LINE)
                CommentItemIns.SetHelpStringItem(PreHelpText)
                CommentInsList.append(CommentItemIns)
                #
                # Add Current help string
                #
                CommentItemIns = InfGuidItemCommentContent()
                CommentItemIns.SetUsageItem(CommentItemUsage)
                CommentItemIns.SetGuidTypeItem(CommentItemGuidType)
                CommentItemIns.SetVariableNameItem(CommentItemVarString)
                if CommentItemHelpText == '' or CommentItemHelpText.endswith(DT.END_OF_LINE):
                    CommentItemHelpText = CommentItemHelpText.strip(DT.END_OF_LINE)
                CommentItemIns.SetHelpStringItem(CommentItemHelpText)
                CommentInsList.append(CommentItemIns)

                BlockFlag = -1
                PreUsage = None
                PreGuidType = None
                PreHelpText = ''

            else:
                PreUsage = CommentItemUsage
                PreGuidType = CommentItemGuidType
                PreHelpText = CommentItemHelpText

        InfGuidItemObj.SetCommentList(CommentInsList)
    else:
        #
        # Still need to set the USAGE/GUIDTYPE to undefined.
        #
        CommentItemIns = InfGuidItemCommentContent()
        CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
        CommentItemIns.SetGuidTypeItem(DT.ITEM_UNDEFINED)
        InfGuidItemObj.SetCommentList([CommentItemIns])

    return InfGuidItemObj
Ejemplo n.º 2
0
def ParseProtocolComment(CommentsList, InfProtocolItemObj):
    CommentInsList = []
    PreUsage = None
    PreNotify = None
    PreHelpText = ''
    BlockFlag = -1
    Count = 0
    for CommentItem in CommentsList:
        Count = Count + 1
        CommentItemUsage, \
        CommentItemNotify, \
        CommentItemString, \
        CommentItemHelpText = \
                ParseComment(CommentItem,
                             DT.PROTOCOL_USAGE_TOKENS,
                             DT.PROTOCOL_NOTIFY_TOKENS,
                             ['PROTOCOL'],
                             False)

        if CommentItemString:
            pass

        if CommentItemHelpText == None:
            CommentItemHelpText = ''
            if Count == len(
                    CommentsList
            ) and CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
                CommentItemHelpText = DT.END_OF_LINE

        if Count == len(CommentsList):
            if BlockFlag == 1 or BlockFlag == 2:
                if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
                    BlockFlag = 4
                else:
                    BlockFlag = 3
            elif BlockFlag == -1:
                BlockFlag = 4

        if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
            if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
                if BlockFlag == -1:
                    BlockFlag = 1
                elif BlockFlag == 1:
                    BlockFlag = 2
            else:
                if BlockFlag == 1 or BlockFlag == 2:
                    BlockFlag = 3
                elif BlockFlag == -1:
                    BlockFlag = 4

        #
        # Combine two comment line if they are generic comment
        #
        if CommentItemUsage == CommentItemNotify == PreUsage == PreNotify == DT.ITEM_UNDEFINED:
            CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText

            PreHelpText = CommentItemHelpText

        if BlockFlag == 4:
            CommentItemIns = InfProtocolItemCommentContent()
            CommentItemIns.SetUsageItem(CommentItemUsage)
            CommentItemIns.SetNotify(CommentItemNotify)
            CommentItemIns.SetHelpStringItem(CommentItemHelpText)
            CommentInsList.append(CommentItemIns)

            BlockFlag = -1
            PreUsage = None
            PreNotify = None
            PreHelpText = ''

        elif BlockFlag == 3:
            #
            # Add previous help string
            #
            CommentItemIns = InfProtocolItemCommentContent()
            CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
            CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
            if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
                PreHelpText += DT.END_OF_LINE
            CommentItemIns.SetHelpStringItem(PreHelpText)
            CommentInsList.append(CommentItemIns)
            #
            # Add Current help string
            #
            CommentItemIns = InfProtocolItemCommentContent()
            CommentItemIns.SetUsageItem(CommentItemUsage)
            CommentItemIns.SetNotify(CommentItemNotify)
            CommentItemIns.SetHelpStringItem(CommentItemHelpText)
            CommentInsList.append(CommentItemIns)

            BlockFlag = -1
            PreUsage = None
            PreNotify = None
            PreHelpText = ''

        else:
            PreUsage = CommentItemUsage
            PreNotify = CommentItemNotify
            PreHelpText = CommentItemHelpText

    InfProtocolItemObj.SetCommentList(CommentInsList)

    return InfProtocolItemObj
Ejemplo n.º 3
0
    def InfSpecialCommentParser(self, SpecialSectionList, InfSectionObject,
                                ContainerFile, SectionType):
        ReFindSpecialCommentRe = re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""",
                                            re.DOTALL)
        ReFindHobArchRe = re.compile(r"""[Hh][Oo][Bb]\.([^,]*)""", re.DOTALL)
        if self.FileName:
            pass
        SpecialObjectList = []
        ArchList = []
        if SectionType == DT.TYPE_EVENT_SECTION:
            TokenDict = DT.EVENT_TOKENS
        elif SectionType == DT.TYPE_HOB_SECTION:
            TokenDict = DT.HOB_TOKENS
        else:
            TokenDict = DT.BOOTMODE_TOKENS

        for List in SpecialSectionList:
            #
            # Hob has Arch attribute, need to be handled specially here
            #
            if SectionType == DT.TYPE_HOB_SECTION:

                MatchObject = ReFindSpecialCommentRe.search(List[0][0])
                HobSectionStr = MatchObject.group(1)
                ArchList = []
                for Match in ReFindHobArchRe.finditer(HobSectionStr):
                    Arch = Match.groups(1)[0].upper()
                    ArchList.append(Arch)
            CommentSoFar = ''
            for Index in range(1, len(List)):
                Result = ParseComment(List[Index], DT.ALL_USAGE_TOKENS,
                                      TokenDict, [], False)
                Usage = Result[0]
                Type = Result[1]
                HelpText = Result[3]

                if Usage == DT.ITEM_UNDEFINED and Type == DT.ITEM_UNDEFINED:
                    if HelpText is None:
                        HelpText = ''
                    if not HelpText.endswith('\n'):
                        HelpText += '\n'
                    CommentSoFar += HelpText
                else:
                    if HelpText:
                        CommentSoFar += HelpText
                    if SectionType == DT.TYPE_EVENT_SECTION:
                        SpecialObject = InfEventObject()
                        SpecialObject.SetEventType(Type)
                        SpecialObject.SetUsage(Usage)
                        SpecialObject.SetHelpString(CommentSoFar)
                    elif SectionType == DT.TYPE_HOB_SECTION:
                        SpecialObject = InfHobObject()
                        SpecialObject.SetHobType(Type)
                        SpecialObject.SetUsage(Usage)
                        SpecialObject.SetHelpString(CommentSoFar)
                        if len(ArchList) >= 1:
                            SpecialObject.SetSupArchList(ArchList)
                    else:
                        SpecialObject = InfBootModeObject()
                        SpecialObject.SetSupportedBootModes(Type)
                        SpecialObject.SetUsage(Usage)
                        SpecialObject.SetHelpString(CommentSoFar)

                    SpecialObjectList.append(SpecialObject)
                    CommentSoFar = ''
        if not InfSectionObject.SetSpecialComments(SpecialObjectList,
                                                   SectionType):
            Logger.Error(
                'InfParser', FORMAT_INVALID,
                ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (SectionType),
                ContainerFile)
Ejemplo n.º 4
0
def ParsePcdComment(CommentList, PcdTypeItem, PcdItemObj):
    CommentInsList = []
    PreUsage = None
    PreHelpText = ''
    BlockFlag = -1
    FFEHelpText = ''
    CommentItemHelpText = ''
    Count = 0
    for CommentItem in CommentList:
        Count = Count + 1
        CommentItemUsage, CommentType, CommentString, CommentItemHelpText = ParseComment(CommentItem,
                                                                             DT.ALL_USAGE_TOKENS,
                                                                             {},
                                                                             [],
                                                                             False)
        if CommentType and CommentString:
            pass

        if PcdTypeItem == 'FeaturePcd':
            CommentItemUsage = DT.USAGE_ITEM_CONSUMES
            if CommentItemHelpText == None:
                CommentItemHelpText = ''

            if Count == 1:
                FFEHelpText = CommentItemHelpText
            else:
                FFEHelpText = FFEHelpText + DT.END_OF_LINE + CommentItemHelpText

            if Count == len(CommentList):
                CommentItemHelpText = FFEHelpText
                BlockFlag = 4
            else:
                continue

        if CommentItemHelpText == None:
            CommentItemHelpText = ''
            if Count == len(CommentList) and CommentItemUsage == DT.ITEM_UNDEFINED:
                CommentItemHelpText = DT.END_OF_LINE

        if Count == len(CommentList) and (BlockFlag == 1 or BlockFlag == 2):
            if CommentItemUsage == DT.ITEM_UNDEFINED:
                BlockFlag = 4
            else:
                BlockFlag = 3
        elif BlockFlag == -1 and Count == len(CommentList):
            BlockFlag = 4

        if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
            if CommentItemUsage == DT.ITEM_UNDEFINED:
                if BlockFlag == -1:
                    BlockFlag = 1
                elif BlockFlag == 1:
                    BlockFlag = 2
            else:
                if BlockFlag == 1 or BlockFlag == 2:
                    BlockFlag = 3
                elif BlockFlag == -1:
                    BlockFlag = 4
        #
        # Combine two comment line if they are generic comment
        #   
        if CommentItemUsage == PreUsage == DT.ITEM_UNDEFINED:
            CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText

            PreHelpText = CommentItemHelpText

        if BlockFlag == 4:
            CommentItemIns = InfPcdItemCommentContent()
            CommentItemIns.SetUsageItem(CommentItemUsage)
            CommentItemIns.SetHelpStringItem(CommentItemHelpText)
            CommentInsList.append(CommentItemIns)

            BlockFlag = -1
            PreUsage = None
            PreHelpText = ''

        elif BlockFlag == 3:
            #
            # Add previous help string
            # 
            CommentItemIns = InfPcdItemCommentContent()
            CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
            if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
                PreHelpText += DT.END_OF_LINE
            CommentItemIns.SetHelpStringItem(PreHelpText)
            CommentInsList.append(CommentItemIns)
            #
            # Add Current help string
            #
            CommentItemIns = InfPcdItemCommentContent()
            CommentItemIns.SetUsageItem(CommentItemUsage)
            CommentItemIns.SetHelpStringItem(CommentItemHelpText)
            CommentInsList.append(CommentItemIns)

            BlockFlag = -1
            PreUsage = None
            PreHelpText = ''

        else:
            PreUsage = CommentItemUsage
            PreHelpText = CommentItemHelpText

    PcdItemObj.SetHelpStringList(CommentInsList)

    return PcdItemObj
Ejemplo n.º 5
0
def ParsePpiComment(CommentsList, InfPpiItemObj):
    PreNotify = None
    PreUsage = None
    PreHelpText = ''
    BlockFlag = -1
    CommentInsList = []
    Count = 0
    for CommentItem in CommentsList:
        Count = Count + 1
        CommentItemUsage, \
        CommentItemNotify, \
        CommentItemString, \
        CommentItemHelpText = \
                ParseComment(CommentItem,
                             DT.ALL_USAGE_TOKENS,
                             DT.PPI_NOTIFY_TOKENS,
                             ['PPI'],
                             False)

        #
        # To avoid PyLint error
        #
        if CommentItemString:
            pass

        if CommentItemHelpText == None:
            CommentItemHelpText = ''
            if Count == len(
                    CommentsList
            ) and CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
                CommentItemHelpText = DT.END_OF_LINE
        #
        # For the Last comment Item, set BlockFlag.
        #
        if Count == len(CommentsList):
            if BlockFlag == 1 or BlockFlag == 2:
                if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
                    BlockFlag = 4
                else:
                    BlockFlag = 3
            elif BlockFlag == -1:
                BlockFlag = 4

        #
        # Comment USAGE and NOTIFY information are "UNDEFINED"
        #
        if BlockFlag == -1 or BlockFlag == 1 or BlockFlag == 2:
            if CommentItemUsage == CommentItemNotify == DT.ITEM_UNDEFINED:
                if BlockFlag == -1:
                    BlockFlag = 1
                elif BlockFlag == 1:
                    BlockFlag = 2
            else:
                if BlockFlag == 1 or BlockFlag == 2:
                    BlockFlag = 3
                #
                # An item have Usage or Notify information and the first time get this information
                #
                elif BlockFlag == -1:
                    BlockFlag = 4

        #
        # Combine two comment line if they are generic comment
        #
        if CommentItemUsage == CommentItemNotify == PreUsage == PreNotify == DT.ITEM_UNDEFINED:
            CommentItemHelpText = PreHelpText + DT.END_OF_LINE + CommentItemHelpText
            #
            # Store this information for next line may still need  combine operation.
            #
            PreHelpText = CommentItemHelpText

        if BlockFlag == 4:
            CommentItemIns = InfPpiItemCommentContent()
            CommentItemIns.SetUsage(CommentItemUsage)
            CommentItemIns.SetNotify(CommentItemNotify)
            CommentItemIns.SetHelpStringItem(CommentItemHelpText)
            CommentInsList.append(CommentItemIns)

            BlockFlag = -1
            PreUsage = None
            PreNotify = None
            PreHelpText = ''

        elif BlockFlag == 3:
            #
            # Add previous help string
            #
            CommentItemIns = InfPpiItemCommentContent()
            CommentItemIns.SetUsage(DT.ITEM_UNDEFINED)
            CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
            if PreHelpText == '' or PreHelpText.endswith(DT.END_OF_LINE):
                PreHelpText += DT.END_OF_LINE
            CommentItemIns.SetHelpStringItem(PreHelpText)
            CommentInsList.append(CommentItemIns)
            #
            # Add Current help string
            #
            CommentItemIns = InfPpiItemCommentContent()
            CommentItemIns.SetUsage(CommentItemUsage)
            CommentItemIns.SetNotify(CommentItemNotify)
            CommentItemIns.SetHelpStringItem(CommentItemHelpText)
            CommentInsList.append(CommentItemIns)

            BlockFlag = -1
            PreUsage = None
            PreNotify = None
            PreHelpText = ''
        else:
            PreUsage = CommentItemUsage
            PreNotify = CommentItemNotify
            PreHelpText = CommentItemHelpText

    InfPpiItemObj.SetCommentList(CommentInsList)

    return InfPpiItemObj