]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/Expression.py
BaseTools: create and use a standard shared variable for '*'
[mirror_edk2.git] / BaseTools / Source / Python / Common / Expression.py
index ff9271031b0e3351e441fdd4ff195212e1b64dd2..db1310d534fb8cb9d649844f5ca7fb83cb723345 100644 (file)
@@ -22,6 +22,8 @@ import Common.EdkLogger as EdkLogger
 import copy\r
 from Common.DataType import *\r
 import sys\r
+from random import sample\r
+import string\r
 \r
 ERR_STRING_EXPR         = 'This operator cannot be used in string expression: [%s].'\r
 ERR_SNYTAX              = 'Syntax error, the rest of expression cannot be evaluated: [%s].'\r
@@ -55,6 +57,8 @@ PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
 #\r
 def SplitString(String):\r
     # There might be escaped quote: "abc\"def\\\"ghi", 'abc\'def\\\'ghi'\r
+    RanStr = ''.join(sample(string.ascii_letters + string.digits, 8))\r
+    String = String.replace('\\\\', RanStr).strip()\r
     RetList = []\r
     InSingleQuote = False\r
     InDoubleQuote = False\r
@@ -87,11 +91,16 @@ def SplitString(String):
         raise BadExpression(ERR_STRING_TOKEN % Item)\r
     if Item:\r
         RetList.append(Item)\r
+    for i, ch in enumerate(RetList):\r
+        if RanStr in ch:\r
+            RetList[i] = ch.replace(RanStr,'\\\\')\r
     return RetList\r
 \r
 def SplitPcdValueString(String):\r
     # There might be escaped comma in GUID() or DEVICE_PATH() or " "\r
     # or ' ' or L' ' or L" "\r
+    RanStr = ''.join(sample(string.ascii_letters + string.digits, 8))\r
+    String = String.replace('\\\\', RanStr).strip()\r
     RetList = []\r
     InParenthesis = 0\r
     InSingleQuote = False\r
@@ -124,6 +133,9 @@ def SplitPcdValueString(String):
         raise BadExpression(ERR_STRING_TOKEN % Item)\r
     if Item:\r
         RetList.append(Item)\r
+    for i, ch in enumerate(RetList):\r
+        if RanStr in ch:\r
+            RetList[i] = ch.replace(RanStr,'\\\\')\r
     return RetList\r
 \r
 def IsValidCName(Str):\r
@@ -232,7 +244,7 @@ class ValueExpression(BaseExpression):
         'IN' : 'in'\r
     }\r
 \r
-    NonLetterOpLst = ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']\r
+    NonLetterOpLst = ['+', '-', TAB_STAR, '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']\r
 \r
 \r
     SymbolPattern = re.compile("("\r
@@ -297,8 +309,8 @@ class ValueExpression(BaseExpression):
                 else:\r
                     raise BadExpression(ERR_EXPR_TYPE)\r
             if isinstance(Oprand1, type('')) and isinstance(Oprand2, type('')):\r
-                if (Oprand1.startswith('L"') and not Oprand2.startswith('L"')) or \\r
-                    (not Oprand1.startswith('L"') and Oprand2.startswith('L"')):\r
+                if ((Oprand1.startswith('L"') or Oprand1.startswith("L'")) and (not Oprand2.startswith('L"')) and (not Oprand2.startswith("L'"))) or \\r
+                        (((not Oprand1.startswith('L"')) and (not Oprand1.startswith("L'"))) and (Oprand2.startswith('L"') or Oprand2.startswith("L'"))):\r
                     raise BadExpression(ERR_STRING_CMP % (Oprand1, Operator, Oprand2))\r
             if 'in' in Operator and isinstance(Oprand2, type('')):\r
                 Oprand2 = Oprand2.split()\r
@@ -390,7 +402,7 @@ class ValueExpression(BaseExpression):
             elif not Val:\r
                 Val = False\r
                 RealVal = '""'\r
-            elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'"):\r
+            elif not Val.startswith('L"') and not Val.startswith('{') and not Val.startswith("L'") and not Val.startswith("'"):\r
                 Val = True\r
                 RealVal = '"' + RealVal + '"'\r
 \r
@@ -486,7 +498,7 @@ class ValueExpression(BaseExpression):
 \r
     # A [ * B]*\r
     def _MulExpr(self):\r
-        return self._ExprFuncTemplate(self._UnaryExpr, {"*", "/", "%"})\r
+        return self._ExprFuncTemplate(self._UnaryExpr, {TAB_STAR, "/", "%"})\r
 \r
     # [!]*A\r
     def _UnaryExpr(self):\r
@@ -827,6 +839,8 @@ class ValueExpressionEx(ValueExpression):
                 PcdValue = PcdValue.strip()\r
                 if PcdValue.startswith('{') and PcdValue.endswith('}'):\r
                     PcdValue = SplitPcdValueString(PcdValue[1:-1])\r
+                if ERR_STRING_CMP.split(':')[0] in Value.message:\r
+                    raise BadExpression("Type: %s, Value: %s, %s" % (self.PcdType, PcdValue, Value))\r
                 if isinstance(PcdValue, type([])):\r
                     TmpValue = 0\r
                     Size = 0\r