BaseTools: Update Expression.py for VOID* to support L'a' and 'a'

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>
This commit is contained in:
Feng, YunhuaX 2018-02-02 17:01:52 +08:00 committed by Yonghong Zhu
parent bee0f2f167
commit 0e6b86731e
2 changed files with 20 additions and 3 deletions

View File

@ -740,7 +740,12 @@ class ValueExpressionEx(ValueExpression):
try:
PcdValue = ValueExpression.__call__(self, RealValue, Depth)
if self.PcdType == 'VOID*' and (PcdValue.startswith("'") or PcdValue.startswith("L'")):
raise BadExpression
PcdValue, Size = ParseFieldValue(PcdValue)
PcdValueList = []
for I in range(Size):
PcdValueList.append('0x%02X'%(PcdValue & 0xff))
PcdValue = PcdValue >> 8
PcdValue = '{' + ','.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 = 0
Size = 0
for Item in PcdValue:
if Item.startswith('UINT8'):
ItemSize = 1
if Item.startswith('UINT16'):
ItemSize = 2
elif Item.startswith('UINT32'):
@ -776,7 +783,10 @@ class ValueExpressionEx(ValueExpression):
TmpValue = (ItemValue << (Size * 8)) | TmpValue
Size = Size + ItemSize
else:
TmpValue, Size = ParseFieldValue(PcdValue)
try:
TmpValue, Size = ParseFieldValue(PcdValue)
except BadExpression:
raise BadExpression("Type: %s, Value: %s, format or value error" % (self.PcdType, PcdValue))
if type(TmpValue) == type(''):
TmpValue = int(TmpValue)
else:
@ -858,7 +868,7 @@ class ValueExpressionEx(ValueExpression):
else:
raise BadExpression('%s not defined before use' % Offset)
ValueType = ""
if Item.startswith('UINT16'):
if Item.startswith('UINT8'):
ItemSize = 1
ValueType = "UINT8"
elif Item.startswith('UINT16'):
@ -887,6 +897,9 @@ class ValueExpressionEx(ValueExpression):
if Size > 0:
PcdValue = '{' + ValueStr[:-2] + '}'
else:
raise BadExpression("Type: %s, Value: %s, format or value error"%(self.PcdType, PcdValue))
if PcdValue == 'True':
PcdValue = '1'
if PcdValue == 'False':

View File

@ -1572,6 +1572,8 @@ def ParseFieldValue (Value):
if Value.startswith("L'") and Value.endswith("'"):
# Unicode Character Constant
List = list(Value[2:-1])
if len(List) == 0:
raise BadExpression('Length %s is %s' % (Value, len(List)))
List.reverse()
Value = 0
for Char in List:
@ -1580,6 +1582,8 @@ def ParseFieldValue (Value):
if Value.startswith("'") and Value.endswith("'"):
# Character constant
List = list(Value[1:-1])
if len(List) == 0:
raise BadExpression('Length %s is %s' % (Value, len(List)))
List.reverse()
Value = 0
for Char in List: