BaseTools:ECC report errors on account of analyze special characters
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=1751 In case that a C function body contains the string of L'', L'\"', L"\"", L''', L""", L"\"\"", L"\"^", L" \"", L"\" \"", ('L",\\\""') ECC tool running under python3 interpreter will report error. The antlr4 module misidentified this character This patch is going to fix that issue. Cc: Bob Feng <bob.c.feng@intel.com> Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com> Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
@ -73,7 +73,7 @@ class CodeFragmentCollector:
|
|||||||
self.FileName = FileName
|
self.FileName = FileName
|
||||||
self.CurrentLineNumber = 1
|
self.CurrentLineNumber = 1
|
||||||
self.CurrentOffsetWithinLine = 0
|
self.CurrentOffsetWithinLine = 0
|
||||||
|
self.TokenReleaceList = []
|
||||||
self.__Token = ""
|
self.__Token = ""
|
||||||
self.__SkippedChars = ""
|
self.__SkippedChars = ""
|
||||||
|
|
||||||
@ -503,6 +503,9 @@ class CodeFragmentCollector:
|
|||||||
FileStringContents = ''
|
FileStringContents = ''
|
||||||
for fileLine in self.Profile.FileLinesList:
|
for fileLine in self.Profile.FileLinesList:
|
||||||
FileStringContents += fileLine
|
FileStringContents += fileLine
|
||||||
|
for Token in self.TokenReleaceList:
|
||||||
|
if Token in FileStringContents:
|
||||||
|
FileStringContents = FileStringContents.replace(Token, 'TOKENSTRING')
|
||||||
cStream = antlr.InputStream(FileStringContents)
|
cStream = antlr.InputStream(FileStringContents)
|
||||||
lexer = CLexer(cStream)
|
lexer = CLexer(cStream)
|
||||||
tStream = antlr.CommonTokenStream(lexer)
|
tStream = antlr.CommonTokenStream(lexer)
|
||||||
|
@ -114,6 +114,7 @@ _ConfigFileToInternalTranslation = {
|
|||||||
"SmmCommParaCheckBufferType":"SmmCommParaCheckBufferType",
|
"SmmCommParaCheckBufferType":"SmmCommParaCheckBufferType",
|
||||||
"SpaceCheckAll":"SpaceCheckAll",
|
"SpaceCheckAll":"SpaceCheckAll",
|
||||||
"SpellingCheckAll":"SpellingCheckAll",
|
"SpellingCheckAll":"SpellingCheckAll",
|
||||||
|
"TokenReleaceList":"TokenReleaceList",
|
||||||
"UniCheckAll":"UniCheckAll",
|
"UniCheckAll":"UniCheckAll",
|
||||||
"UniCheckHelpInfo":"UniCheckHelpInfo",
|
"UniCheckHelpInfo":"UniCheckHelpInfo",
|
||||||
"UniCheckPCDInfo":"UniCheckPCDInfo",
|
"UniCheckPCDInfo":"UniCheckPCDInfo",
|
||||||
@ -389,6 +390,8 @@ class Configuration(object):
|
|||||||
# A list for Copyright format
|
# A list for Copyright format
|
||||||
self.Copyright = []
|
self.Copyright = []
|
||||||
|
|
||||||
|
self.TokenReleaceList = []
|
||||||
|
|
||||||
self.ParseConfig()
|
self.ParseConfig()
|
||||||
|
|
||||||
def ParseConfig(self):
|
def ParseConfig(self):
|
||||||
@ -419,6 +422,8 @@ class Configuration(object):
|
|||||||
List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
|
List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
|
||||||
if List[0] == 'Copyright':
|
if List[0] == 'Copyright':
|
||||||
List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
|
List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
|
||||||
|
if List[0] == 'TokenReleaceList':
|
||||||
|
List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
|
||||||
self.__dict__[_ConfigFileToInternalTranslation[List[0]]] = List[1]
|
self.__dict__[_ConfigFileToInternalTranslation[List[0]]] = List[1]
|
||||||
|
|
||||||
def ShowMe(self):
|
def ShowMe(self):
|
||||||
|
@ -495,6 +495,8 @@ def CollectSourceCodeDataIntoDB(RootDir):
|
|||||||
tuple = os.walk(RootDir)
|
tuple = os.walk(RootDir)
|
||||||
IgnoredPattern = GetIgnoredDirListPattern()
|
IgnoredPattern = GetIgnoredDirListPattern()
|
||||||
ParseErrorFileList = []
|
ParseErrorFileList = []
|
||||||
|
TokenReleaceList = EccGlobalData.gConfig.TokenReleaceList
|
||||||
|
TokenReleaceList.extend(['L",\\\""'])
|
||||||
|
|
||||||
for dirpath, dirnames, filenames in tuple:
|
for dirpath, dirnames, filenames in tuple:
|
||||||
if IgnoredPattern.match(dirpath.upper()):
|
if IgnoredPattern.match(dirpath.upper()):
|
||||||
@ -519,6 +521,7 @@ def CollectSourceCodeDataIntoDB(RootDir):
|
|||||||
EdkLogger.info("Parsing " + FullName)
|
EdkLogger.info("Parsing " + FullName)
|
||||||
model = f.endswith('c') and DataClass.MODEL_FILE_C or DataClass.MODEL_FILE_H
|
model = f.endswith('c') and DataClass.MODEL_FILE_C or DataClass.MODEL_FILE_H
|
||||||
collector = CodeFragmentCollector.CodeFragmentCollector(FullName)
|
collector = CodeFragmentCollector.CodeFragmentCollector(FullName)
|
||||||
|
collector.TokenReleaceList = TokenReleaceList
|
||||||
try:
|
try:
|
||||||
collector.ParseFile()
|
collector.ParseFile()
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
|
@ -277,3 +277,5 @@ SmmCommParaCheckBufferType = 1
|
|||||||
BinaryExtList = EXE, EFI, FV, ROM, DLL, COM, BMP, GIF, PYD, CMP, BIN, JPG, UNI, RAW, COM2, LIB, DEPEX, SYS, DB
|
BinaryExtList = EXE, EFI, FV, ROM, DLL, COM, BMP, GIF, PYD, CMP, BIN, JPG, UNI, RAW, COM2, LIB, DEPEX, SYS, DB
|
||||||
# A list for only scanning dirs, the dirs should be the top folder(s) under workspace
|
# A list for only scanning dirs, the dirs should be the top folder(s) under workspace
|
||||||
ScanOnlyDirList = ScanFolder1 ScanFolder2
|
ScanOnlyDirList = ScanFolder1 ScanFolder2
|
||||||
|
# A list for Used to circumvent special strings
|
||||||
|
TokenReleaceList = L'', L'\"', L"\"", L''', L""", L"\"\"", L"\"^", L" \"", L"\" \""
|
||||||
|
Reference in New Issue
Block a user