summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/UPT/Library/CommentParsing.py
diff options
context:
space:
mode:
authorLiming Gao <liming.gao@intel.com>2018-07-05 17:40:04 +0800
committerLiming Gao <liming.gao@intel.com>2018-07-09 10:25:47 +0800
commitf7496d717357b9af78414d19679b073403812340 (patch)
tree67621e65fd181bdf8a12d12e7706579beaaed0fb /BaseTools/Source/Python/UPT/Library/CommentParsing.py
parent39456d00f36e04b7e7efb208f350f4e83b6c3531 (diff)
downloadedk2-f7496d717357b9af78414d19679b073403812340.tar.gz
edk2-f7496d717357b9af78414d19679b073403812340.tar.bz2
edk2-f7496d717357b9af78414d19679b073403812340.zip
BaseTools: Clean up source files
1. Do not use tab characters 2. No trailing white space in one line 3. All files must end with CRLF Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/UPT/Library/CommentParsing.py')
-rw-r--r--BaseTools/Source/Python/UPT/Library/CommentParsing.py210
1 files changed, 105 insertions, 105 deletions
diff --git a/BaseTools/Source/Python/UPT/Library/CommentParsing.py b/BaseTools/Source/Python/UPT/Library/CommentParsing.py
index 8ee788bd77..285812c9c2 100644
--- a/BaseTools/Source/Python/UPT/Library/CommentParsing.py
+++ b/BaseTools/Source/Python/UPT/Library/CommentParsing.py
@@ -3,9 +3,9 @@
#
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
#
-# This program and the accompanying materials are licensed and made available
-# under the terms and conditions of the BSD License which accompanies this
-# distribution. The full text of the license may be found at
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
@@ -69,7 +69,7 @@ def ParseHeaderCommentSection(CommentList, FileName = None, IsBinaryHeader = Fal
else:
STR_HEADER_COMMENT_START = "@file"
HeaderCommentStage = HEADER_COMMENT_NOT_STARTED
-
+
#
# first find the last copyright line
#
@@ -79,24 +79,24 @@ def ParseHeaderCommentSection(CommentList, FileName = None, IsBinaryHeader = Fal
if _IsCopyrightLine(Line):
Last = Index
break
-
+
for Item in CommentList:
Line = Item[0]
LineNo = Item[1]
-
+
if not Line.startswith(TAB_COMMENT_SPLIT) and Line:
Logger.Error("\nUPT", FORMAT_INVALID, ST.ERR_INVALID_COMMENT_FORMAT, FileName, Item[1])
Comment = CleanString2(Line)[1]
Comment = Comment.strip()
#
- # if there are blank lines between License or Description, keep them as they would be
+ # if there are blank lines between License or Description, keep them as they would be
# indication of different block; or in the position that Abstract should be, also keep it
# as it indicates that no abstract
#
if not Comment and HeaderCommentStage not in [HEADER_COMMENT_LICENSE, \
HEADER_COMMENT_DESCRIPTION, HEADER_COMMENT_ABSTRACT]:
continue
-
+
if HeaderCommentStage == HEADER_COMMENT_NOT_STARTED:
if Comment.startswith(STR_HEADER_COMMENT_START):
HeaderCommentStage = HEADER_COMMENT_ABSTRACT
@@ -114,20 +114,20 @@ def ParseHeaderCommentSection(CommentList, FileName = None, IsBinaryHeader = Fal
ValidateCopyright(Result, ST.WRN_INVALID_COPYRIGHT, FileName, LineNo, ErrMsg)
Copyright += Comment + EndOfLine
HeaderCommentStage = HEADER_COMMENT_COPYRIGHT
- else:
+ else:
Abstract += Comment + EndOfLine
HeaderCommentStage = HEADER_COMMENT_DESCRIPTION
elif HeaderCommentStage == HEADER_COMMENT_DESCRIPTION:
#
# in case there is no description
- #
+ #
if _IsCopyrightLine(Comment):
Result, ErrMsg = _ValidateCopyright(Comment)
ValidateCopyright(Result, ST.WRN_INVALID_COPYRIGHT, FileName, LineNo, ErrMsg)
Copyright += Comment + EndOfLine
HeaderCommentStage = HEADER_COMMENT_COPYRIGHT
else:
- Description += Comment + EndOfLine
+ Description += Comment + EndOfLine
elif HeaderCommentStage == HEADER_COMMENT_COPYRIGHT:
if _IsCopyrightLine(Comment):
Result, ErrMsg = _ValidateCopyright(Comment)
@@ -136,23 +136,23 @@ def ParseHeaderCommentSection(CommentList, FileName = None, IsBinaryHeader = Fal
else:
#
# Contents after copyright line are license, those non-copyright lines in between
- # copyright line will be discarded
+ # copyright line will be discarded
#
if LineNo > Last:
if License:
License += EndOfLine
License += Comment + EndOfLine
- HeaderCommentStage = HEADER_COMMENT_LICENSE
+ HeaderCommentStage = HEADER_COMMENT_LICENSE
else:
if not Comment and not License:
continue
License += Comment + EndOfLine
-
+
return Abstract.strip(), Description.strip(), Copyright.strip(), License.strip()
## _IsCopyrightLine
-# check whether current line is copyright line, the criteria is whether there is case insensitive keyword "Copyright"
-# followed by zero or more white space characters followed by a "(" character
+# check whether current line is copyright line, the criteria is whether there is case insensitive keyword "Copyright"
+# followed by zero or more white space characters followed by a "(" character
#
# @param LineContent: the line need to be checked
# @return: True if current line is copyright line, False else
@@ -160,7 +160,7 @@ def ParseHeaderCommentSection(CommentList, FileName = None, IsBinaryHeader = Fal
def _IsCopyrightLine (LineContent):
LineContent = LineContent.upper()
Result = False
-
+
ReIsCopyrightRe = re.compile(r"""(^|\s)COPYRIGHT *\(""", re.DOTALL)
if ReIsCopyrightRe.search(LineContent):
Result = True
@@ -169,23 +169,23 @@ def _IsCopyrightLine (LineContent):
## ParseGenericComment
#
-# @param GenericComment: Generic comment list, element of
+# @param GenericComment: Generic comment list, element of
# (CommentLine, LineNum)
# @param ContainerFile: Input value for filename of Dec file
-#
+#
def ParseGenericComment (GenericComment, ContainerFile=None, SkipTag=None):
if ContainerFile:
pass
- HelpTxt = None
- HelpStr = ''
-
+ HelpTxt = None
+ HelpStr = ''
+
for Item in GenericComment:
CommentLine = Item[0]
Comment = CleanString2(CommentLine)[1]
if SkipTag is not None and Comment.startswith(SkipTag):
Comment = Comment.replace(SkipTag, '', 1)
HelpStr += Comment + '\n'
-
+
if HelpStr:
HelpTxt = TextObject()
if HelpStr.endswith('\n') and not HelpStr.endswith('\n\n') and HelpStr != '\n':
@@ -196,22 +196,22 @@ def ParseGenericComment (GenericComment, ContainerFile=None, SkipTag=None):
## ParsePcdErrorCode
#
-# @param Value: original ErrorCode value
+# @param Value: original ErrorCode value
# @param ContainerFile: Input value for filename of Dec file
-# @param LineNum: Line Num
-#
-def ParsePcdErrorCode (Value = None, ContainerFile = None, LineNum = None):
- try:
+# @param LineNum: Line Num
+#
+def ParsePcdErrorCode (Value = None, ContainerFile = None, LineNum = None):
+ try:
if Value.strip().startswith((TAB_HEX_START, TAB_CAPHEX_START)):
Base = 16
else:
Base = 10
ErrorCode = long(Value, Base)
if ErrorCode > PCD_ERR_CODE_MAX_SIZE or ErrorCode < 0:
- Logger.Error('Parser',
+ Logger.Error('Parser',
FORMAT_NOT_SUPPORTED,
"The format %s of ErrorCode is not valid, should be UNIT32 type or long type" % Value,
- File = ContainerFile,
+ File = ContainerFile,
Line = LineNum)
#
# To delete the tailing 'L'
@@ -220,27 +220,27 @@ def ParsePcdErrorCode (Value = None, ContainerFile = None, LineNum = None):
except ValueError as XStr:
if XStr:
pass
- Logger.Error('Parser',
+ Logger.Error('Parser',
FORMAT_NOT_SUPPORTED,
"The format %s of ErrorCode is not valid, should be UNIT32 type or long type" % Value,
- File = ContainerFile,
+ File = ContainerFile,
Line = LineNum)
-
+
## ParseDecPcdGenericComment
#
-# @param GenericComment: Generic comment list, element of (CommentLine,
+# @param GenericComment: Generic comment list, element of (CommentLine,
# LineNum)
# @param ContainerFile: Input value for filename of Dec file
-#
-def ParseDecPcdGenericComment (GenericComment, ContainerFile, TokenSpaceGuidCName, CName, MacroReplaceDict):
- HelpStr = ''
+#
+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]
#
@@ -252,13 +252,13 @@ def ParseDecPcdGenericComment (GenericComment, ContainerFile, TokenSpaceGuidCNam
if MatchedStr:
Macro = MatchedStr.strip().lstrip('$(').rstrip(')').strip()
if Macro in MacroReplaceDict:
- Comment = Comment.replace(MatchedStr, MacroReplaceDict[Macro])
+ Comment = Comment.replace(MatchedStr, MacroReplaceDict[Macro])
if Comment.startswith(TAB_PCD_VALIDRANGE):
if ValidValueNum > 0 or ExpressionNum > 0:
- Logger.Error('Parser',
+ Logger.Error('Parser',
FORMAT_NOT_SUPPORTED,
ST.WRN_MULTI_PCD_RANGES,
- File = ContainerFile,
+ File = ContainerFile,
Line = LineNum)
else:
PcdErr = PcdErrorObject()
@@ -280,21 +280,21 @@ def ParseDecPcdGenericComment (GenericComment, ContainerFile, TokenSpaceGuidCNam
else:
Logger.Error("Parser",
FORMAT_NOT_SUPPORTED,
- Cause,
- ContainerFile,
+ Cause,
+ ContainerFile,
LineNum)
elif Comment.startswith(TAB_PCD_VALIDLIST):
if ValidRangeNum > 0 or ExpressionNum > 0:
- Logger.Error('Parser',
+ Logger.Error('Parser',
FORMAT_NOT_SUPPORTED,
ST.WRN_MULTI_PCD_RANGES,
- File = ContainerFile,
+ File = ContainerFile,
Line = LineNum)
elif ValidValueNum > 0:
- Logger.Error('Parser',
+ Logger.Error('Parser',
FORMAT_NOT_SUPPORTED,
ST.WRN_MULTI_PCD_VALIDVALUE,
- File = ContainerFile,
+ File = ContainerFile,
Line = LineNum)
else:
PcdErr = PcdErrorObject()
@@ -317,15 +317,15 @@ def ParseDecPcdGenericComment (GenericComment, ContainerFile, TokenSpaceGuidCNam
else:
Logger.Error("Parser",
FORMAT_NOT_SUPPORTED,
- Cause,
- ContainerFile,
+ Cause,
+ ContainerFile,
LineNum)
elif Comment.startswith(TAB_PCD_EXPRESSION):
if ValidRangeNum > 0 or ValidValueNum > 0:
- Logger.Error('Parser',
+ Logger.Error('Parser',
FORMAT_NOT_SUPPORTED,
ST.WRN_MULTI_PCD_RANGES,
- File = ContainerFile,
+ File = ContainerFile,
Line = LineNum)
else:
PcdErr = PcdErrorObject()
@@ -344,24 +344,24 @@ def ParseDecPcdGenericComment (GenericComment, ContainerFile, TokenSpaceGuidCNam
else:
PcdErr.SetExpression(Expression)
PcdErrList.append(PcdErr)
- else:
+ else:
Logger.Error("Parser",
FORMAT_NOT_SUPPORTED,
- Cause,
- ContainerFile,
- LineNum)
+ Cause,
+ ContainerFile,
+ LineNum)
elif Comment.startswith(TAB_PCD_PROMPT):
if PromptStr:
- Logger.Error('Parser',
+ Logger.Error('Parser',
FORMAT_NOT_SUPPORTED,
ST.WRN_MULTI_PCD_PROMPT,
- File = ContainerFile,
+ 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'
#
@@ -384,9 +384,9 @@ def ParseDecPcdTailComment (TailCommentList, ContainerFile):
LineNum = TailCommentList[0][1]
Comment = TailComment.lstrip(" #")
-
+
ReFindFirstWordRe = re.compile(r"""^([^ #]*)""", re.DOTALL)
-
+
#
# get first word and compare with SUP_MODULE_LIST
#
@@ -398,7 +398,7 @@ def ParseDecPcdTailComment (TailCommentList, ContainerFile):
# parse line, it must have supported module type specified
#
if Comment.find(TAB_COMMENT_SPLIT) == -1:
- Comment += TAB_COMMENT_SPLIT
+ Comment += TAB_COMMENT_SPLIT
SupMode, HelpStr = GetSplitValueList(Comment, TAB_COMMENT_SPLIT, 1)
SupModuleList = []
for Mod in GetSplitValueList(SupMode, TAB_SPACE_SPLIT):
@@ -407,8 +407,8 @@ def ParseDecPcdTailComment (TailCommentList, ContainerFile):
elif Mod not in SUP_MODULE_LIST:
Logger.Error("UPT",
FORMAT_INVALID,
- ST.WRN_INVALID_MODULE_TYPE%Mod,
- ContainerFile,
+ ST.WRN_INVALID_MODULE_TYPE%Mod,
+ ContainerFile,
LineNum)
else:
SupModuleList.append(Mod)
@@ -417,15 +417,15 @@ def ParseDecPcdTailComment (TailCommentList, ContainerFile):
## _CheckListExpression
#
-# @param Expression: Pcd value list expression
+# @param Expression: Pcd value list expression
#
def _CheckListExpression(Expression):
ListExpr = ''
if TAB_VALUE_SPLIT in Expression:
- ListExpr = Expression[Expression.find(TAB_VALUE_SPLIT)+1:]
+ ListExpr = Expression[Expression.find(TAB_VALUE_SPLIT)+1:]
else:
ListExpr = Expression
-
+
return IsValidListExpr(ListExpr)
## _CheckExpreesion
@@ -443,14 +443,14 @@ def _CheckExpression(Expression):
## _CheckRangeExpression
#
# @param Expression: Pcd range expression
-#
+#
def _CheckRangeExpression(Expression):
RangeExpr = ''
if TAB_VALUE_SPLIT in Expression:
RangeExpr = Expression[Expression.find(TAB_VALUE_SPLIT)+1:]
else:
RangeExpr = Expression
-
+
return IsValidRangeExpr(RangeExpr)
## ValidateCopyright
@@ -459,28 +459,28 @@ def _CheckRangeExpression(Expression):
#
def ValidateCopyright(Result, ErrType, FileName, LineNo, ErrMsg):
if not Result:
- Logger.Warn("\nUPT", ErrType, FileName, LineNo, ErrMsg)
+ Logger.Warn("\nUPT", ErrType, FileName, LineNo, ErrMsg)
## _ValidateCopyright
#
# @param Line: Line that contains copyright information, # stripped
-#
+#
# @retval Result: True if line is conformed to Spec format, False else
# @retval ErrMsg: the detailed error description
-#
+#
def _ValidateCopyright(Line):
if Line:
pass
Result = True
ErrMsg = ''
-
+
return Result, ErrMsg
def GenerateTokenList (Comment):
#
# Tokenize Comment using '#' and ' ' as token seperators
#
- RelplacedComment = None
+ RelplacedComment = None
while Comment != RelplacedComment:
RelplacedComment = Comment
Comment = Comment.replace('##', '#').replace(' ', ' ').replace(' ', '#').strip('# ')
@@ -500,25 +500,25 @@ def ParseComment (Comment, UsageTokens, TypeTokens, RemoveTokens, ParseVariable)
Usage = None
Type = None
String = None
-
+
Comment = Comment[0]
-
- NumTokens = 2
+
+ NumTokens = 2
if ParseVariable:
- #
- # Remove white space around first instance of ':' from Comment if 'Variable'
+ #
+ # Remove white space around first instance of ':' from Comment if 'Variable'
# is in front of ':' and Variable is the 1st or 2nd token in Comment.
#
- List = Comment.split(':', 1)
+ List = Comment.split(':', 1)
if len(List) > 1:
SubList = GenerateTokenList (List[0].strip())
if len(SubList) in [1, 2] and SubList[-1] == 'Variable':
- if List[1].strip().find('L"') == 0:
+ if List[1].strip().find('L"') == 0:
Comment = List[0].strip() + ':' + List[1].strip()
-
- #
+
+ #
# Remove first instance of L"<VariableName> from Comment and put into String
- # if and only if L"<VariableName>" is the 1st token, the 2nd token. Or
+ # if and only if L"<VariableName>" is the 1st token, the 2nd token. Or
# L"<VariableName>" is the third token immediately following 'Variable:'.
#
End = -1
@@ -533,25 +533,25 @@ def ParseComment (Comment, UsageTokens, TypeTokens, RemoveTokens, ParseVariable)
End = String[2:].find('"')
if End >= 0:
SubList = GenerateTokenList (Comment[:Start])
- if len(SubList) < 2:
+ if len(SubList) < 2:
Comment = Comment[:Start] + String[End + 3:]
String = String[:End + 3]
Type = 'Variable'
- NumTokens = 1
-
+ NumTokens = 1
+
#
- # Initialze HelpText to Comment.
+ # Initialze HelpText to Comment.
# Content will be remove from HelpText as matching tokens are found
- #
+ #
HelpText = Comment
-
+
#
# Tokenize Comment using '#' and ' ' as token seperators
#
List = GenerateTokenList (Comment)
-
+
#
- # Search first two tokens for Usage and Type and remove any matching tokens
+ # Search first two tokens for Usage and Type and remove any matching tokens
# from HelpText
#
for Token in List[0:NumTokens]:
@@ -563,39 +563,39 @@ def ParseComment (Comment, UsageTokens, TypeTokens, RemoveTokens, ParseVariable)
if Type is None and Token in TypeTokens:
Type = TypeTokens[Token]
HelpText = HelpText.replace(Token, '')
- if Usage is not None:
+ if Usage is not None:
for Token in List[0:NumTokens]:
if Token in RemoveTokens:
HelpText = HelpText.replace(Token, '')
-
+
#
# If no Usage token is present and set Usage to UNDEFINED
- #
+ #
if Usage is None:
Usage = 'UNDEFINED'
-
+
#
# If no Type token is present and set Type to UNDEFINED
- #
+ #
if Type is None:
Type = 'UNDEFINED'
-
+
#
# If Type is not 'Variable:', then set String to None
- #
+ #
if Type != 'Variable':
- String = None
-
+ String = None
+
#
# Strip ' ' and '#' from the beginning of HelpText
- # If HelpText is an empty string after all parsing is
+ # If HelpText is an empty string after all parsing is
# complete then set HelpText to None
- #
+ #
HelpText = HelpText.lstrip('# ')
if HelpText == '':
HelpText = None
-
+
#
# Return parsing results
- #
- return Usage, Type, String, HelpText
+ #
+ return Usage, Type, String, HelpText