From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=yunhuax.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 722CC21E0B9F2 for ; Fri, 2 Feb 2018 00:56:18 -0800 (PST) X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Feb 2018 01:01:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,447,1511856000"; d="dat'59?scan'59,208,59";a="24161486" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga003.jf.intel.com with ESMTP; 02 Feb 2018 01:01:55 -0800 Received: from fmsmsx124.amr.corp.intel.com (10.18.125.39) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 2 Feb 2018 01:01:55 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx124.amr.corp.intel.com (10.18.125.39) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 2 Feb 2018 01:01:54 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.124]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.192]) with mapi id 14.03.0319.002; Fri, 2 Feb 2018 17:01:53 +0800 From: "Feng, YunhuaX" To: "edk2-devel@lists.01.org" CC: "Zhu, Yonghong" , "Gao, Liming" Thread-Topic: [PATCH] BaseTools: Update Expression.py for VOID* support L'a' and 'a' Thread-Index: AdOcBHdjJyb7bj7oSMaYfhDyWzXAYA== Date: Fri, 2 Feb 2018 09:01:52 +0000 Message-ID: <47C64442C08CCD4089DC43B6B5E46BC4822A49@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <47C64442C08CCD4089DC43B6B5E46BC4822A49@shsmsx102.ccr.corp.intel.com> x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 Subject: [PATCH] BaseTools: Update Expression.py for VOID* support L'a' and 'a' X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Feb 2018 08:56:18 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Type VOID* support L'a' and 'a', the value transfer to c style value. L'a' --> {0x61, 0x00} L'ab' --> {0x61, 0x00, 0x62, 0x00} 'a' --> {0x61} 'ab' --> {0x61, 0x62} when the value is L'' or '', will report error Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/Python/Common/Expression.py | 19 ++++++++++++++++--- BaseTools/Source/Python/Common/Misc.py | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index b8c48460ff..6a1103df2c 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -740,7 +740,12 @@ class ValueExpressionEx(ValueExpression): try: PcdValue =3D ValueExpression.__call__(self, RealValue, Depth) if self.PcdType =3D=3D 'VOID*' and (PcdValue.startswith("'") o= r PcdValue.startswith("L'")): - raise BadExpression + PcdValue, Size =3D ParseFieldValue(PcdValue) + PcdValueList =3D [] + for I in range(Size): + PcdValueList.append('0x%02X'%(PcdValue & 0xff)) + PcdValue =3D PcdValue >> 8 + PcdValue =3D '{' + ','.join(PcdValueList) + '}' elif self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', '= BOOLEAN'] and (PcdValue.startswith("'") or \ PcdValue.startswith('"') or PcdValue.startswith("L'"= ) or PcdValue.startswith('L"') or PcdValue.startswith('{')): raise BadExpression @@ -755,6 +760,8 @@ class ValueExpressionEx(ValueExpression): TmpValue =3D 0 Size =3D 0 for Item in PcdValue: + if Item.startswith('UINT8'): + ItemSize =3D 1 if Item.startswith('UINT16'): ItemSize =3D 2 elif Item.startswith('UINT32'): @@ -776,7 +783,10 @@ class ValueExpressionEx(ValueExpression): TmpValue =3D (ItemValue << (Size * 8)) | TmpValue Size =3D Size + ItemSize else: - TmpValue, Size =3D ParseFieldValue(PcdValue) + try: + TmpValue, Size =3D ParseFieldValue(PcdValue) + except BadExpression: + raise BadExpression("Type: %s, Value: %s, format o= r value error" % (self.PcdType, PcdValue)) if type(TmpValue) =3D=3D type(''): TmpValue =3D int(TmpValue) else: @@ -858,7 +868,7 @@ class ValueExpressionEx(ValueExpression): else: raise BadExpression('%s not define= d before use' % Offset) ValueType =3D "" - if Item.startswith('UINT16'): + if Item.startswith('UINT8'): ItemSize =3D 1 ValueType =3D "UINT8" elif Item.startswith('UINT16'): @@ -887,6 +897,9 @@ class ValueExpressionEx(ValueExpression): =20 if Size > 0: PcdValue =3D '{' + ValueStr[:-2] + '}' + else: + raise BadExpression("Type: %s, Value: %s, format = or value error"%(self.PcdType, PcdValue)) + if PcdValue =3D=3D 'True': PcdValue =3D '1' if PcdValue =3D=3D 'False': diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index b34cb4c3be..d80f645d2e 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1572,6 +1572,8 @@ def ParseFieldValue (Value): if Value.startswith("L'") and Value.endswith("'"): # Unicode Character Constant List =3D list(Value[2:-1]) + if len(List) =3D=3D 0: + raise BadExpression('Length %s is %s' % (Value, len(List))) List.reverse() Value =3D 0 for Char in List: @@ -1580,6 +1582,8 @@ def ParseFieldValue (Value): if Value.startswith("'") and Value.endswith("'"): # Character constant List =3D list(Value[1:-1]) + if len(List) =3D=3D 0: + raise BadExpression('Length %s is %s' % (Value, len(List))) List.reverse() Value =3D 0 for Char in List: --=20 2.12.2.windows.2