BaseTools: Update Expression.py for VOID* to support L'a' and 'a'
authorFeng, YunhuaX </o=Intel/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=Feng, YunhuaX4e1>
Fri, 2 Feb 2018 09:01:52 +0000 (17:01 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Sun, 4 Feb 2018 03:19:39 +0000 (11:19 +0800)
Original VOID* type support L"string" and "string" format, now we also
add support for single quote string that without null terminator.
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 '' that not include any character, tool will
report error.

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/Common/Misc.py

index b8c4846..6a1103d 100644 (file)
@@ -740,7 +740,12 @@ class ValueExpressionEx(ValueExpression):
         try:\r
             PcdValue = ValueExpression.__call__(self, RealValue, Depth)\r
             if self.PcdType == 'VOID*' and (PcdValue.startswith("'") or PcdValue.startswith("L'")):\r
-                raise BadExpression\r
+                PcdValue, Size = ParseFieldValue(PcdValue)\r
+                PcdValueList = []\r
+                for I in range(Size):\r
+                    PcdValueList.append('0x%02X'%(PcdValue & 0xff))\r
+                    PcdValue = PcdValue >> 8\r
+                PcdValue = '{' + ','.join(PcdValueList) + '}'\r
             elif self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN'] and (PcdValue.startswith("'") or \\r
                       PcdValue.startswith('"') or PcdValue.startswith("L'") or PcdValue.startswith('L"') or PcdValue.startswith('{')):\r
                 raise BadExpression\r
@@ -755,6 +760,8 @@ class ValueExpressionEx(ValueExpression):
                     TmpValue = 0\r
                     Size = 0\r
                     for Item in PcdValue:\r
+                        if Item.startswith('UINT8'):\r
+                            ItemSize = 1\r
                         if Item.startswith('UINT16'):\r
                             ItemSize = 2\r
                         elif Item.startswith('UINT32'):\r
@@ -776,7 +783,10 @@ class ValueExpressionEx(ValueExpression):
                         TmpValue = (ItemValue << (Size * 8)) | TmpValue\r
                         Size = Size + ItemSize\r
                 else:\r
-                    TmpValue, Size = ParseFieldValue(PcdValue)\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
                 if type(TmpValue) == type(''):\r
                     TmpValue = int(TmpValue)\r
                 else:\r
@@ -858,7 +868,7 @@ class ValueExpressionEx(ValueExpression):
                                     else:\r
                                         raise BadExpression('%s not defined before use' % Offset)\r
                                 ValueType = ""\r
-                                if Item.startswith('UINT16'):\r
+                                if Item.startswith('UINT8'):\r
                                     ItemSize = 1\r
                                     ValueType = "UINT8"\r
                                 elif Item.startswith('UINT16'):\r
@@ -887,6 +897,9 @@ class ValueExpressionEx(ValueExpression):
 \r
                             if Size > 0:\r
                                 PcdValue = '{' + ValueStr[:-2] + '}'\r
+                    else:\r
+                        raise  BadExpression("Type: %s, Value: %s, format or value error"%(self.PcdType, PcdValue))\r
+\r
         if PcdValue == 'True':\r
             PcdValue = '1'\r
         if PcdValue == 'False':\r
index b34cb4c..d80f645 100644 (file)
@@ -1572,6 +1572,8 @@ def ParseFieldValue (Value):
     if Value.startswith("L'") and Value.endswith("'"):\r
         # Unicode Character Constant\r
         List = list(Value[2:-1])\r
+        if len(List) == 0:\r
+            raise BadExpression('Length %s is %s' % (Value, len(List)))\r
         List.reverse()\r
         Value = 0\r
         for Char in List:\r
@@ -1580,6 +1582,8 @@ def ParseFieldValue (Value):
     if Value.startswith("'") and Value.endswith("'"):\r
         # Character constant\r
         List = list(Value[1:-1])\r
+        if len(List) == 0:\r
+            raise BadExpression('Length %s is %s' % (Value, len(List)))\r
         List.reverse()\r
         Value = 0\r
         for Char in List:\r