]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Update Expression.py for string comparison and MACRO replace issue
authorYunhua Feng <yunhuax.feng@intel.com>
Wed, 7 Feb 2018 13:37:26 +0000 (21:37 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 9 Feb 2018 00:34:36 +0000 (08:34 +0800)
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 <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/Common/Expression.py
BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools/Source/Python/Workspace/MetaFileParser.py

index 6a1103df2ce02097538d3110fc693d22a7dd33df..a19f35d99161fd5ed7eaaae6a09d0fc0ccfc5684 100644 (file)
@@ -157,19 +157,9 @@ class ValueExpression(object):
     def Eval(Operator, Oprand1, Oprand2 = None):\r
         WrnExp = None\r
 \r
-        if Operator not in ["in", "not in"] and (type(Oprand1) == type('') or type(Oprand2) == type('')):\r
-            if type(Oprand1) == type(''):\r
-                if Oprand1[0] in ['"', "'"] or Oprand1.startswith('L"') or Oprand1.startswith("L'")or Oprand1.startswith('UINT'):\r
-                    Oprand1, Size = ParseFieldValue(Oprand1)\r
-                else:\r
-                    Oprand1,Size = ParseFieldValue('"' + Oprand1 + '"')\r
-            if type(Oprand2) == type(''):\r
-                if Oprand2[0] in ['"', "'"] or Oprand2.startswith('L"') or Oprand2.startswith("L'") or Oprand2.startswith('UINT'):\r
-                    Oprand2, Size = ParseFieldValue(Oprand2)\r
-                else:\r
-                    Oprand2, Size = ParseFieldValue('"' + Oprand2 + '"')\r
-            if type(Oprand1) == type('') or type(Oprand2) == type(''):\r
-                raise BadExpression(ERR_STRING_EXPR % Operator)\r
+        if Operator not in ["==", "!=", ">=", "<=", ">", "<", "in", "not in"] and \\r
+            (type(Oprand1) == type('') or type(Oprand2) == type('')):\r
+            raise BadExpression(ERR_STRING_EXPR % Operator)\r
         if Operator in ['in', 'not in']:\r
             if type(Oprand1) != type(''):\r
                 Oprand1 = IntToStr(Oprand1)\r
@@ -296,8 +286,6 @@ class ValueExpression(object):
             except BadExpression:\r
                 pass\r
             if type(Token) == type('') and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len:\r
-                if len(Token) != len(self._Expr.replace(' ', '')):\r
-                    raise BadExpression\r
                 return self._Expr\r
 \r
             self._Idx = 0\r
@@ -459,7 +447,6 @@ class ValueExpression(object):
                 if self._Token[Index] in ['"']:\r
                     Flag += 1\r
             if Flag == 2 and self._Token.endswith('"'):\r
-                self._Token = ParseFieldValue(self._Token)[0]\r
                 return True\r
         if self._Token.startswith("'") or self._Token.startswith("L'"):\r
             Flag = 0\r
@@ -467,7 +454,6 @@ class ValueExpression(object):
                 if self._Token[Index] in ["'"]:\r
                     Flag += 1\r
             if Flag == 2 and self._Token.endswith("'"):\r
-                self._Token = ParseFieldValue(self._Token)[0]\r
                 return True\r
         try:\r
             self._Token = int(self._Token, Radix)\r
@@ -622,24 +608,16 @@ class ValueExpression(object):
             self._Idx += 1\r
             UStr = self.__GetString()\r
             self._Token = 'L"' + UStr + '"'\r
-            self._Token, Size = ParseFieldValue(self._Token)\r
             return self._Token\r
         elif Expr.startswith("L'"):\r
             # Skip L\r
             self._Idx += 1\r
             UStr = self.__GetString()\r
             self._Token = "L'" + UStr + "'"\r
-            self._Token, Size = ParseFieldValue(self._Token)\r
-            return self._Token\r
-        elif Expr.startswith('"'):\r
-            UStr = self.__GetString()\r
-            self._Token = '"' + UStr + '"'\r
-            self._Token, Size = ParseFieldValue(self._Token)\r
             return self._Token\r
         elif Expr.startswith("'"):\r
             UStr = self.__GetString()\r
             self._Token = "'" + UStr + "'"\r
-            self._Token, Size = ParseFieldValue(self._Token)\r
             return self._Token\r
         elif Expr.startswith('UINT'):\r
             Re = re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)')\r
@@ -751,7 +729,7 @@ class ValueExpressionEx(ValueExpression):
                 raise BadExpression\r
         except WrnExpression, Value:\r
             PcdValue = Value.result\r
-        except BadExpression:\r
+        except BadExpression, Value:\r
             if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
                 PcdValue = PcdValue.strip()\r
                 if type(PcdValue) == type('') and PcdValue.startswith('{') and PcdValue.endswith('}'):\r
@@ -785,10 +763,13 @@ class ValueExpressionEx(ValueExpression):
                 else:\r
                     try:\r
                         TmpValue, Size = ParseFieldValue(PcdValue)\r
-                    except BadExpression:\r
-                        raise BadExpression("Type: %s, Value: %s, format or value error" % (self.PcdType, PcdValue))\r
+                    except BadExpression, Value:\r
+                        raise BadExpression("Type: %s, Value: %s, %s" % (self.PcdType, PcdValue, Value))\r
                 if type(TmpValue) == type(''):\r
-                    TmpValue = int(TmpValue)\r
+                    try:\r
+                        TmpValue = int(TmpValue)\r
+                    except:\r
+                        raise  BadExpression(Value)\r
                 else:\r
                     PcdValue = '0x%0{}X'.format(Size) % (TmpValue)\r
                 if TmpValue < 0:\r
@@ -898,7 +879,7 @@ class ValueExpressionEx(ValueExpression):
                             if Size > 0:\r
                                 PcdValue = '{' + ValueStr[:-2] + '}'\r
                     else:\r
-                        raise  BadExpression("Type: %s, Value: %s, format or value error"%(self.PcdType, PcdValue))\r
+                        raise  BadExpression("Type: %s, Value: %s, %s"%(self.PcdType, PcdValue, Value))\r
 \r
         if PcdValue == 'True':\r
             PcdValue = '1'\r
index 0da3efbb43e00360f2356e802aca30130232de03..75b877a5aac3b1861977dc409f773576ea5dd07c 100644 (file)
@@ -808,7 +808,7 @@ class DscBuildData(PlatformBuildClassObject):
                 PkgSet.update(ModuleData.Packages)\r
 \r
             self._DecPcds, self._GuidDict = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain,PkgSet)\r
-\r
+            self._GuidDict.update(GlobalData.gPlatformPcds)\r
 \r
         if (PcdCName, TokenSpaceGuid) not in self._DecPcds:\r
             EdkLogger.error('build', PARSER_ERROR,\r
index 57642de4ee73ed2ef8af08b1b93f201613efc953..95ea6fb45abb5af1704c5dae9e0e316c6ab5684d 100644 (file)
@@ -1994,6 +1994,7 @@ class DecParser(MetaFileParser):
             PcdValue = ValueList[0]\r
             if PcdValue:\r
                 try:\r
+                    self._GuidDict.update(self._AllPcdDict)\r
                     ValueList[0] = ValueExpressionEx(ValueList[0], ValueList[1], self._GuidDict)(True)\r
                 except BadExpression, Value:\r
                     EdkLogger.error('Parser', FORMAT_INVALID, Value, ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r