From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: bob.c.feng@intel.com) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by groups.io with SMTP; Mon, 06 May 2019 18:30:56 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 May 2019 18:30:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,440,1549958400"; d="scan'208";a="140750375" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga008.jf.intel.com with ESMTP; 06 May 2019 18:30:55 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 6 May 2019 18:30:55 -0700 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.129]) by shsmsx102.ccr.corp.intel.com ([169.254.2.249]) with mapi id 14.03.0415.000; Tue, 7 May 2019 09:30:53 +0800 From: "Bob Feng" To: "Fan, ZhijuX" , "devel@edk2.groups.io" CC: "Gao, Liming" Subject: Re: [PATCH] BaseTools:ECC report errors on account of analyze special characters Thread-Topic: [PATCH] BaseTools:ECC report errors on account of analyze special characters Thread-Index: AdUDtAp7PFu2tHUrTs6tJWIguAzO+gAwGw1Q Date: Tue, 7 May 2019 01:30:53 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D160104563@SHSMSX101.ccr.corp.intel.com> References: In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: bob.c.feng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Fan, ZhijuX=20 Sent: Monday, May 6, 2019 10:35 AM To: devel@edk2.groups.io Cc: Gao, Liming ; Feng, Bob C Subject: [PATCH] BaseTools:ECC report errors on account of analyze special = characters BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1751 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.=20 The antlr4 module misidentified this character This patch is going to fix that issue. Cc: Bob Feng Cc: Liming Gao Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/Ecc/CodeFragmentCollector.py | 5 ++++- BaseTools/Source/Python/Ecc/Configuration.py | 5 +++++ BaseTools/Source/Python/Ecc/c.py | 3 +++ BaseTools/Source/Python/Ecc/config.ini | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py b/BaseToo= ls/Source/Python/Ecc/CodeFragmentCollector.py index f844b4a0b3..589e8d91e6 100644 --- a/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py +++ b/BaseTools/Source/Python/Ecc/CodeFragmentCollector.py @@ -79,7 +79,7 @@ class CodeFragmentCollector: self.FileName =3D FileName self.CurrentLineNumber =3D 1 self.CurrentOffsetWithinLine =3D 0 - + self.TokenReleaceList =3D [] self.__Token =3D "" self.__SkippedChars =3D "" =20 @@ -509,6 +509,9 @@ class CodeFragmentCollector: FileStringContents =3D '' for fileLine in self.Profile.FileLinesList: FileStringContents +=3D fileLine + for Token in self.TokenReleaceList: + if Token in FileStringContents: + FileStringContents =3D FileStringContents.replace(Token,=20 + 'TOKENSTRING') cStream =3D antlr.InputStream(FileStringContents) lexer =3D CLexer(cStream) tStream =3D antlr.CommonTokenStream(lexer) diff --git a/BaseTools/= Source/Python/Ecc/Configuration.py b/BaseTools/Source/Python/Ecc/Configurat= ion.py index 66c8dd7880..9ebd130c31 100644 --- a/BaseTools/Source/Python/Ecc/Configuration.py +++ b/BaseTools/Source/Python/Ecc/Configuration.py @@ -120,6 +120,7 @@ _ConfigFileToInternalTranslation =3D { "SmmCommParaCheckBufferType":"SmmCommParaCheckBufferType", "SpaceCheckAll":"SpaceCheckAll", "SpellingCheckAll":"SpellingCheckAll", + "TokenReleaceList":"TokenReleaceList", "UniCheckAll":"UniCheckAll", "UniCheckHelpInfo":"UniCheckHelpInfo", "UniCheckPCDInfo":"UniCheckPCDInfo", @@ -395,6 +396,8 @@ class Configuration(object): # A list for Copyright format self.Copyright =3D [] =20 + self.TokenReleaceList =3D [] + self.ParseConfig() =20 def ParseConfig(self): @@ -425,6 +428,8 @@ class Configuration(object): List[1] =3D GetSplitValueList(List[1], TAB_COMMA_SPLIT= ) if List[0] =3D=3D 'Copyright': List[1] =3D GetSplitValueList(List[1], TAB_COMMA_SPLIT= ) + if List[0] =3D=3D 'TokenReleaceList': + List[1] =3D GetSplitValueList(List[1],=20 + TAB_COMMA_SPLIT) self.__dict__[_ConfigFileToInternalTranslation[List[0]]] = =3D List[1] =20 def ShowMe(self): diff --git a/BaseTools/Source/Python/Ecc/c.py b/BaseTools/Source/Python/Ecc= /c.py index 7b645ff053..75fe4544a1 100644 --- a/BaseTools/Source/Python/Ecc/c.py +++ b/BaseTools/Source/Python/Ecc/c.py @@ -501,6 +501,8 @@ def CollectSourceCodeDataIntoDB(RootDir): tuple =3D os.walk(RootDir) IgnoredPattern =3D GetIgnoredDirListPattern() ParseErrorFileList =3D [] + TokenReleaceList =3D EccGlobalData.gConfig.TokenReleaceList + TokenReleaceList.extend(['L",\\\""']) =20 for dirpath, dirnames, filenames in tuple: if IgnoredPattern.match(dirpath.upper()): @@ -525,6 +527,7 @@ def CollectSourceCodeDataIntoDB(RootDir): EdkLogger.info("Parsing " + FullName) model =3D f.endswith('c') and DataClass.MODEL_FILE_C or Da= taClass.MODEL_FILE_H collector =3D CodeFragmentCollector.CodeFragmentCollector(= FullName) + collector.TokenReleaceList =3D TokenReleaceList try: collector.ParseFile() except UnicodeError: diff --git a/BaseTools/Source/Python/Ecc/config.ini b/BaseTools/Source/Pyth= on/Ecc/config.ini index 00c98c6232..cdd294280e 100644 --- a/BaseTools/Source/Python/Ecc/config.ini +++ b/BaseTools/Source/Python/Ecc/config.ini @@ -283,3 +283,5 @@ SmmCommParaCheckBufferType =3D 1 BinaryExtList =3D 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 t= op folder(s) under workspace ScanOnlyDirList =3D ScanFolder1 ScanFolder2 +# A list for Used to circumvent special strings TokenReleaceList =3D L'',= =20 +L'\"', L"\"", L''', L""", L"\"\"", L"\"^", L" \"", L"\" \"" -- 2.14.1.windows.1 GitPatchExtractor 1.1