def ParseDecPcdGenericComment (GenericComment, ContainerFile, TokenSpaceGuidCName, CName, MacroReplaceDict): HelpStr = '' PromptStr = '' PcdErr = None PcdErrList = [] ValidValueNum = 0 ValidRangeNum = 0 ExpressionNum = 0 for (CommentLine, LineNum) in GenericComment: Comment = CleanString2(CommentLine)[1] # # To replace Macro # MACRO_PATTERN = '[\t\s]*\$\([A-Z][_A-Z0-9]*\)' MatchedStrs = re.findall(MACRO_PATTERN, Comment) for MatchedStr in MatchedStrs: if MatchedStr: Macro = MatchedStr.strip().lstrip('$(').rstrip(')').strip() if Macro in MacroReplaceDict: Comment = Comment.replace(MatchedStr, MacroReplaceDict[Macro]) if Comment.startswith(TAB_PCD_VALIDRANGE): if ValidValueNum > 0 or ExpressionNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File = ContainerFile, Line = LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ValidRangeNum += 1 ValidRange = Comment.replace(TAB_PCD_VALIDRANGE, "", 1).strip() Valid, Cause = _CheckRangeExpression(ValidRange) if Valid: ValueList = ValidRange.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetValidValueRange((TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber(ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetValidValueRange(ValidRange) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_VALIDLIST): if ValidRangeNum > 0 or ExpressionNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File = ContainerFile, Line = LineNum) elif ValidValueNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_VALIDVALUE, File = ContainerFile, Line = LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ValidValueNum += 1 ValidValueExpr = Comment.replace(TAB_PCD_VALIDLIST, "", 1).strip() Valid, Cause = _CheckListExpression(ValidValueExpr) if Valid: ValidValue = Comment.replace(TAB_PCD_VALIDLIST, "", 1).replace(TAB_COMMA_SPLIT, TAB_SPACE_SPLIT) ValueList = ValidValue.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetValidValue((TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber(ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetValidValue(ValidValue) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_EXPRESSION): if ValidRangeNum > 0 or ValidValueNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File = ContainerFile, Line = LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ExpressionNum += 1 Expression = Comment.replace(TAB_PCD_EXPRESSION, "", 1).strip() Valid, Cause = _CheckExpression(Expression) if Valid: ValueList = Expression.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetExpression((TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber(ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetExpression(Expression) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_PROMPT): if PromptStr: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_PROMPT, File = ContainerFile, Line = LineNum) PromptStr = Comment.replace(TAB_PCD_PROMPT, "", 1).strip() else: if Comment: HelpStr += Comment + '\n' # # remove the last EOL if the comment is of format 'FOO\n' # if HelpStr.endswith('\n'): if HelpStr != '\n' and not HelpStr.endswith('\n\n'): HelpStr = HelpStr[:-1] return HelpStr, PcdErrList, PromptStr
def ParseDecPcdGenericComment (GenericComment, ContainerFile, TokenSpaceGuidCName, CName, MacroReplaceDict): HelpStr = '' PromptStr = '' PcdErr = None PcdErrList = [] ValidValueNum = 0 ValidRangeNum = 0 ExpressionNum = 0 for (CommentLine, LineNum) in GenericComment: Comment = CleanString2(CommentLine)[1] # # To replace Macro # MACRO_PATTERN = '[\t\s]*\$\([A-Z][_A-Z0-9]*\)' MatchedStrs = re.findall(MACRO_PATTERN, Comment) for MatchedStr in MatchedStrs: if MatchedStr: Macro = MatchedStr.strip().lstrip('$(').rstrip(')').strip() if Macro in MacroReplaceDict: Comment = Comment.replace(MatchedStr, MacroReplaceDict[Macro]) if Comment.startswith(TAB_PCD_VALIDRANGE): if ValidValueNum > 0 or ExpressionNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File = ContainerFile, Line = LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ValidRangeNum += 1 ValidRange = Comment.replace(TAB_PCD_VALIDRANGE, "", 1).strip() Valid, Cause = _CheckRangeExpression(ValidRange) if Valid: ValueList = ValidRange.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetValidValueRange((TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber(ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetValidValueRange(ValidRange) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_VALIDLIST): if ValidRangeNum > 0 or ExpressionNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File = ContainerFile, Line = LineNum) elif ValidValueNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_VALIDVALUE, File = ContainerFile, Line = LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ValidValueNum += 1 ValidValueExpr = Comment.replace(TAB_PCD_VALIDLIST, "", 1).strip() Valid, Cause = _CheckListExpression(ValidValueExpr) if Valid: ValidValue = Comment.replace(TAB_PCD_VALIDLIST, "", 1).replace(TAB_COMMA_SPLIT, TAB_SPACE_SPLIT) ValueList = ValidValue.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetValidValue((TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber(ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetValidValue(ValidValue) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_EXPRESSION): if ValidRangeNum > 0 or ValidValueNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File = ContainerFile, Line = LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ExpressionNum += 1 Expression = Comment.replace(TAB_PCD_EXPRESSION, "", 1).strip() Valid, Cause = _CheckExpression(Expression) if Valid: ValueList = Expression.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetExpression((TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber(ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetExpression(Expression) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_PROMPT): if PromptStr: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_PROMPT, File = ContainerFile, Line = LineNum) PromptStr = Comment.replace(TAB_PCD_PROMPT, "", 1).strip() else: if Comment: HelpStr += Comment + '\n' # # remove the last EOL if the comment is of format 'FOO\n' # if HelpStr.endswith('\n'): if HelpStr != '\n' and not HelpStr.endswith('\n\n'): HelpStr = HelpStr[:-1] return HelpStr, PcdErrList, PromptStr