def ParseDecPcdGenericComment(GenericComment, ContainerFile): HelpStr = '' PcdErr = None for (CommentLine, LineNum) in GenericComment: Comment = CleanString2(CommentLine)[1] if Comment.startswith("@ValidRange"): if PcdErr: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File=ContainerFile, Line=LineNum) ValidRange = Comment.replace("@ValidRange", "", 1) if _CheckRangeExpression(ValidRange): PcdErr = PcdErrorObject() PcdErr.SetValidValueRange(ValidRange) elif Comment.startswith("@ValidList"): if PcdErr: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File=ContainerFile, Line=LineNum) ValidValue = Comment.replace("@ValidList", "", 1).replace(TAB_COMMA_SPLIT, TAB_SPACE_SPLIT) PcdErr = PcdErrorObject() PcdErr.SetValidValue(ValidValue) elif Comment.startswith("@Expression"): if PcdErr: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File=ContainerFile, Line=LineNum) Expression = Comment.replace("@Expression", "", 1) if _CheckRangeExpression(Expression): PcdErr = PcdErrorObject() PcdErr.SetExpression(Expression) else: 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, PcdErr
def FromXml(self, Item, Key): self.ValidValueList = XmlElement(Item, '%s/ValidValueList' % Key) self.ValidValueListLang = \ XmlAttribute(XmlNode(Item, '%s/ValidValueList' % Key), 'Lang') self.ValidValueRange = self.TransferValidEpxr2ValidRange(XmlElement(Item, '%s/ValidValueRange' % Key)) self.Expression = XmlElement(Item, '%s/Expression' % Key) self.ErrorNumber = XmlElement(Item, '%s/ErrorNumber' % Key) for ErrMsg in XmlList(Item, '%s/ErrorMessage' % Key): ErrorMessageString = XmlElement(ErrMsg, 'ErrorMessage') ErrorMessageLang = \ XmlAttribute(XmlNode(ErrMsg, 'ErrorMessage'), 'Lang') self.ErrorMessage.append((ErrorMessageLang, ErrorMessageString)) Error = PcdErrorObject() Error.SetValidValue(self.ValidValueList) Error.SetValidValueLang(self.ValidValueListLang) Error.SetValidValueRange(self.ValidValueRange) Error.SetExpression(self.Expression) Error.SetErrorNumber(self.ErrorNumber) Error.SetErrorMessageList(self.ErrorMessage) return Error
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