From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 C378722361E43 for ; Thu, 8 Feb 2018 06:40:00 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2018 06:45:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,479,1511856000"; d="scan'208";a="29193145" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.129]) by fmsmga001.fm.intel.com with ESMTP; 08 Feb 2018 06:45:41 -0800 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: Yunhua Feng , Liming Gao Date: Thu, 8 Feb 2018 22:45:38 +0800 Message-Id: <1518101138-10064-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [PATCH] BaseTools: Update Expression.py for string comparison and MACRO replace issue 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: Thu, 08 Feb 2018 14:40:01 -0000 From: Yunhua Feng 1. Fix string comparison incorrect issue, we expected "ABC" is greater than "AAD" since the second char 'B' is greater than 'A'. 2. fix MACRO not replace issue. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/Python/Common/Expression.py | 41 ++++++---------------- BaseTools/Source/Python/Workspace/DscBuildData.py | 2 +- .../Source/Python/Workspace/MetaFileParser.py | 1 + 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 6a1103df2c..a19f35d991 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -155,23 +155,13 @@ class ValueExpression(object): @staticmethod def Eval(Operator, Oprand1, Oprand2 = None): WrnExp = None - if Operator not in ["in", "not in"] and (type(Oprand1) == type('') or type(Oprand2) == type('')): - if type(Oprand1) == type(''): - if Oprand1[0] in ['"', "'"] or Oprand1.startswith('L"') or Oprand1.startswith("L'")or Oprand1.startswith('UINT'): - Oprand1, Size = ParseFieldValue(Oprand1) - else: - Oprand1,Size = ParseFieldValue('"' + Oprand1 + '"') - if type(Oprand2) == type(''): - if Oprand2[0] in ['"', "'"] or Oprand2.startswith('L"') or Oprand2.startswith("L'") or Oprand2.startswith('UINT'): - Oprand2, Size = ParseFieldValue(Oprand2) - else: - Oprand2, Size = ParseFieldValue('"' + Oprand2 + '"') - if type(Oprand1) == type('') or type(Oprand2) == type(''): - raise BadExpression(ERR_STRING_EXPR % Operator) + if Operator not in ["==", "!=", ">=", "<=", ">", "<", "in", "not in"] and \ + (type(Oprand1) == type('') or type(Oprand2) == type('')): + raise BadExpression(ERR_STRING_EXPR % Operator) if Operator in ['in', 'not in']: if type(Oprand1) != type(''): Oprand1 = IntToStr(Oprand1) if type(Oprand2) != type(''): Oprand2 = IntToStr(Oprand2) @@ -294,12 +284,10 @@ class ValueExpression(object): try: Token = self._GetToken() except BadExpression: pass if type(Token) == type('') and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len: - if len(Token) != len(self._Expr.replace(' ', '')): - raise BadExpression return self._Expr self._Idx = 0 self._Token = '' @@ -457,19 +445,17 @@ class ValueExpression(object): Flag = 0 for Index in range(len(self._Token)): if self._Token[Index] in ['"']: Flag += 1 if Flag == 2 and self._Token.endswith('"'): - self._Token = ParseFieldValue(self._Token)[0] return True if self._Token.startswith("'") or self._Token.startswith("L'"): Flag = 0 for Index in range(len(self._Token)): if self._Token[Index] in ["'"]: Flag += 1 if Flag == 2 and self._Token.endswith("'"): - self._Token = ParseFieldValue(self._Token)[0] return True try: self._Token = int(self._Token, Radix) return True except ValueError: @@ -620,28 +606,20 @@ class ValueExpression(object): if Expr.startswith('L"'): # Skip L self._Idx += 1 UStr = self.__GetString() self._Token = 'L"' + UStr + '"' - self._Token, Size = ParseFieldValue(self._Token) return self._Token elif Expr.startswith("L'"): # Skip L self._Idx += 1 UStr = self.__GetString() self._Token = "L'" + UStr + "'" - self._Token, Size = ParseFieldValue(self._Token) - return self._Token - elif Expr.startswith('"'): - UStr = self.__GetString() - self._Token = '"' + UStr + '"' - self._Token, Size = ParseFieldValue(self._Token) return self._Token elif Expr.startswith("'"): UStr = self.__GetString() self._Token = "'" + UStr + "'" - self._Token, Size = ParseFieldValue(self._Token) return self._Token elif Expr.startswith('UINT'): Re = re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)') try: RetValue = Re.search(Expr).group(1) @@ -749,11 +727,11 @@ class ValueExpressionEx(ValueExpression): 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 except WrnExpression, Value: PcdValue = Value.result - except BadExpression: + except BadExpression, Value: if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']: PcdValue = PcdValue.strip() if type(PcdValue) == type('') and PcdValue.startswith('{') and PcdValue.endswith('}'): PcdValue = PcdValue[1:-1].split(',') if type(PcdValue) == type([]): @@ -783,14 +761,17 @@ class ValueExpressionEx(ValueExpression): TmpValue = (ItemValue << (Size * 8)) | TmpValue Size = Size + ItemSize else: try: TmpValue, Size = ParseFieldValue(PcdValue) - except BadExpression: - raise BadExpression("Type: %s, Value: %s, format or value error" % (self.PcdType, PcdValue)) + except BadExpression, Value: + raise BadExpression("Type: %s, Value: %s, %s" % (self.PcdType, PcdValue, Value)) if type(TmpValue) == type(''): - TmpValue = int(TmpValue) + try: + TmpValue = int(TmpValue) + except: + raise BadExpression(Value) else: PcdValue = '0x%0{}X'.format(Size) % (TmpValue) if TmpValue < 0: raise BadExpression('Type %s PCD Value is negative' % self.PcdType) if self.PcdType == 'UINT8' and Size > 1: @@ -896,11 +877,11 @@ class ValueExpressionEx(ValueExpression): Size += ItemSize if Size > 0: PcdValue = '{' + ValueStr[:-2] + '}' else: - raise BadExpression("Type: %s, Value: %s, format or value error"%(self.PcdType, PcdValue)) + raise BadExpression("Type: %s, Value: %s, %s"%(self.PcdType, PcdValue, Value)) if PcdValue == 'True': PcdValue = '1' if PcdValue == 'False': PcdValue = '0' diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index d9165f2ac7..8eef252e30 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -806,11 +806,11 @@ class DscBuildData(PlatformBuildClassObject): continue ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain] PkgSet.update(ModuleData.Packages) self._DecPcds, self._GuidDict = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain,PkgSet) - + self._GuidDict.update(GlobalData.gPlatformPcds) if (PcdCName, TokenSpaceGuid) not in self._DecPcds: EdkLogger.error('build', PARSER_ERROR, "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid, PcdCName, self._Arch), File=self.MetaFile, Line=LineNo) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index 57642de4ee..95ea6fb45a 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1992,10 +1992,11 @@ class DecParser(MetaFileParser): File=self.MetaFile, Line=self._LineIndex + 1) PcdValue = ValueList[0] if PcdValue: try: + self._GuidDict.update(self._AllPcdDict) ValueList[0] = ValueExpressionEx(ValueList[0], ValueList[1], self._GuidDict)(True) except BadExpression, Value: EdkLogger.error('Parser', FORMAT_INVALID, Value, ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1) # check format of default value against the datum type IsValid, Cause = CheckPcdDatum(ValueList[1], ValueList[0]) -- 2.12.2.windows.2