BaseTools: replace 'UINT8','UINT16','UINT32','UINT64','VOID*' with shared constants.
Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
committed by
Yonghong Zhu
parent
b491aa95ab
commit
656d2539be
@@ -41,6 +41,10 @@ TAB_UINT32 = 'UINT32'
|
||||
TAB_UINT64 = 'UINT64'
|
||||
TAB_VOID = 'VOID*'
|
||||
|
||||
TAB_PCD_CLEAN_NUMERIC_TYPES = {TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64}
|
||||
TAB_PCD_NUMERIC_TYPES = {TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN'}
|
||||
TAB_PCD_NUMERIC_TYPES_VOID = {TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN', TAB_VOID}
|
||||
|
||||
TAB_EDK_SOURCE = '$(EDK_SOURCE)'
|
||||
TAB_EFI_SOURCE = '$(EFI_SOURCE)'
|
||||
TAB_WORKSPACE = '$(WORKSPACE)'
|
||||
|
@@ -18,6 +18,7 @@ from CommonDataClass.Exceptions import WrnExpression
|
||||
from Misc import GuidStringToGuidStructureString, ParseFieldValue, IsFieldValueAnArray
|
||||
import Common.EdkLogger as EdkLogger
|
||||
import copy
|
||||
from Common.DataType import *
|
||||
|
||||
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
|
||||
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
|
||||
@@ -136,7 +137,7 @@ def BuildOptionValue(PcdValue, GuidDict):
|
||||
InputValue = PcdValue
|
||||
if IsFieldValueAnArray(InputValue):
|
||||
try:
|
||||
PcdValue = ValueExpressionEx(InputValue, 'VOID*', GuidDict)(True)
|
||||
PcdValue = ValueExpressionEx(InputValue, TAB_VOID, GuidDict)(True)
|
||||
except:
|
||||
pass
|
||||
return PcdValue
|
||||
@@ -800,20 +801,20 @@ class ValueExpressionEx(ValueExpression):
|
||||
PcdValue = self.PcdValue
|
||||
try:
|
||||
PcdValue = ValueExpression.__call__(self, RealValue, Depth)
|
||||
if self.PcdType == 'VOID*' and (PcdValue.startswith("'") or PcdValue.startswith("L'")):
|
||||
if self.PcdType == TAB_VOID and (PcdValue.startswith("'") or PcdValue.startswith("L'")):
|
||||
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 \
|
||||
elif self.PcdType in TAB_PCD_NUMERIC_TYPES 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, Value:
|
||||
if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
|
||||
if self.PcdType in TAB_PCD_NUMERIC_TYPES:
|
||||
PcdValue = PcdValue.strip()
|
||||
if type(PcdValue) == type('') and PcdValue.startswith('{') and PcdValue.endswith('}'):
|
||||
PcdValue = SplitPcdValueString(PcdValue[1:-1])
|
||||
@@ -823,24 +824,24 @@ class ValueExpressionEx(ValueExpression):
|
||||
ValueType = ''
|
||||
for Item in PcdValue:
|
||||
Item = Item.strip()
|
||||
if Item.startswith('UINT8'):
|
||||
if Item.startswith(TAB_UINT8):
|
||||
ItemSize = 1
|
||||
ValueType = 'UINT8'
|
||||
elif Item.startswith('UINT16'):
|
||||
ValueType = TAB_UINT8
|
||||
elif Item.startswith(TAB_UINT16):
|
||||
ItemSize = 2
|
||||
ValueType = 'UINT16'
|
||||
elif Item.startswith('UINT32'):
|
||||
ValueType = TAB_UINT16
|
||||
elif Item.startswith(TAB_UINT32):
|
||||
ItemSize = 4
|
||||
ValueType = 'UINT32'
|
||||
elif Item.startswith('UINT64'):
|
||||
ValueType = TAB_UINT32
|
||||
elif Item.startswith(TAB_UINT64):
|
||||
ItemSize = 8
|
||||
ValueType = 'UINT64'
|
||||
ValueType = TAB_UINT64
|
||||
elif Item[0] in ['"',"'",'L']:
|
||||
ItemSize = 0
|
||||
ValueType = 'VOID*'
|
||||
ValueType = TAB_VOID
|
||||
else:
|
||||
ItemSize = 0
|
||||
ValueType = 'UINT8'
|
||||
ValueType = TAB_UINT8
|
||||
Item = ValueExpressionEx(Item, ValueType, self._Symb)(True)
|
||||
|
||||
if ItemSize == 0:
|
||||
@@ -875,13 +876,13 @@ class ValueExpressionEx(ValueExpression):
|
||||
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:
|
||||
if self.PcdType == TAB_UINT8 and Size > 1:
|
||||
raise BadExpression('Type %s PCD Value Size is Larger than 1 byte' % self.PcdType)
|
||||
if self.PcdType == 'UINT16' and Size > 2:
|
||||
if self.PcdType == TAB_UINT16 and Size > 2:
|
||||
raise BadExpression('Type %s PCD Value Size is Larger than 2 byte' % self.PcdType)
|
||||
if self.PcdType == 'UINT32' and Size > 4:
|
||||
if self.PcdType == TAB_UINT32 and Size > 4:
|
||||
raise BadExpression('Type %s PCD Value Size is Larger than 4 byte' % self.PcdType)
|
||||
if self.PcdType == 'UINT64' and Size > 8:
|
||||
if self.PcdType == TAB_UINT64 and Size > 8:
|
||||
raise BadExpression('Type %s PCD Value Size is Larger than 8 byte' % self.PcdType)
|
||||
else:
|
||||
try:
|
||||
@@ -910,13 +911,13 @@ class ValueExpressionEx(ValueExpression):
|
||||
raise BadExpression('%s is not a valid c variable name' % Label)
|
||||
if Label not in LabelDict:
|
||||
LabelDict[Label] = str(LabelOffset)
|
||||
if Item.startswith('UINT8'):
|
||||
if Item.startswith(TAB_UINT8):
|
||||
LabelOffset = LabelOffset + 1
|
||||
elif Item.startswith('UINT16'):
|
||||
elif Item.startswith(TAB_UINT16):
|
||||
LabelOffset = LabelOffset + 2
|
||||
elif Item.startswith('UINT32'):
|
||||
elif Item.startswith(TAB_UINT32):
|
||||
LabelOffset = LabelOffset + 4
|
||||
elif Item.startswith('UINT64'):
|
||||
elif Item.startswith(TAB_UINT64):
|
||||
LabelOffset = LabelOffset + 8
|
||||
else:
|
||||
try:
|
||||
@@ -971,18 +972,18 @@ class ValueExpressionEx(ValueExpression):
|
||||
continue
|
||||
else:
|
||||
ValueType = ""
|
||||
if Item.startswith('UINT8'):
|
||||
if Item.startswith(TAB_UINT8):
|
||||
ItemSize = 1
|
||||
ValueType = "UINT8"
|
||||
elif Item.startswith('UINT16'):
|
||||
ValueType = TAB_UINT8
|
||||
elif Item.startswith(TAB_UINT16):
|
||||
ItemSize = 2
|
||||
ValueType = "UINT16"
|
||||
elif Item.startswith('UINT32'):
|
||||
ValueType = TAB_UINT16
|
||||
elif Item.startswith(TAB_UINT32):
|
||||
ItemSize = 4
|
||||
ValueType = "UINT32"
|
||||
elif Item.startswith('UINT64'):
|
||||
ValueType = TAB_UINT32
|
||||
elif Item.startswith(TAB_UINT64):
|
||||
ItemSize = 8
|
||||
ValueType = "UINT64"
|
||||
ValueType = TAB_UINT64
|
||||
else:
|
||||
ItemSize = 0
|
||||
if ValueType:
|
||||
|
@@ -1288,22 +1288,22 @@ def ParseFieldValue (Value):
|
||||
if type(Value) <> type(''):
|
||||
raise BadExpression('Type %s is %s' %(Value, type(Value)))
|
||||
Value = Value.strip()
|
||||
if Value.startswith('UINT8') and Value.endswith(')'):
|
||||
if Value.startswith(TAB_UINT8) and Value.endswith(')'):
|
||||
Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])
|
||||
if Size > 1:
|
||||
raise BadExpression('Value (%s) Size larger than %d' %(Value, Size))
|
||||
return Value, 1
|
||||
if Value.startswith('UINT16') and Value.endswith(')'):
|
||||
if Value.startswith(TAB_UINT16) and Value.endswith(')'):
|
||||
Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])
|
||||
if Size > 2:
|
||||
raise BadExpression('Value (%s) Size larger than %d' %(Value, Size))
|
||||
return Value, 2
|
||||
if Value.startswith('UINT32') and Value.endswith(')'):
|
||||
if Value.startswith(TAB_UINT32) and Value.endswith(')'):
|
||||
Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])
|
||||
if Size > 4:
|
||||
raise BadExpression('Value (%s) Size larger than %d' %(Value, Size))
|
||||
return Value, 4
|
||||
if Value.startswith('UINT64') and Value.endswith(')'):
|
||||
if Value.startswith(TAB_UINT64) and Value.endswith(')'):
|
||||
Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])
|
||||
if Size > 8:
|
||||
raise BadExpression('Value (%s) Size larger than %d' % (Value, Size))
|
||||
@@ -1490,7 +1490,7 @@ def AnalyzeDscPcd(Setting, PcdType, DataType=''):
|
||||
elif PcdType in (MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_VPD):
|
||||
VpdOffset = FieldList[0]
|
||||
Value = Size = ''
|
||||
if not DataType == 'VOID*':
|
||||
if not DataType == TAB_VOID:
|
||||
if len(FieldList) > 1:
|
||||
Value = FieldList[1]
|
||||
else:
|
||||
@@ -1558,7 +1558,7 @@ def AnalyzePcdData(Setting):
|
||||
# For PCD value setting
|
||||
#
|
||||
def CheckPcdDatum(Type, Value):
|
||||
if Type == "VOID*":
|
||||
if Type == TAB_VOID:
|
||||
ValueRe = re.compile(r'\s*L?\".*\"\s*$')
|
||||
if not (((Value.startswith('L"') or Value.startswith('"')) and Value.endswith('"'))
|
||||
or (Value.startswith('{') and Value.endswith('}')) or (Value.startswith("L'") or Value.startswith("'") and Value.endswith("'"))
|
||||
|
@@ -94,11 +94,11 @@ class VpdInfoFile:
|
||||
if not (Offset >= 0 or Offset == "*"):
|
||||
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID, "Invalid offset parameter: %s." % Offset)
|
||||
|
||||
if Vpd.DatumType == "VOID*":
|
||||
if Vpd.DatumType == TAB_VOID:
|
||||
if Vpd.MaxDatumSize <= 0:
|
||||
EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,
|
||||
"Invalid max datum size for VPD PCD %s.%s" % (Vpd.TokenSpaceGuidCName, Vpd.TokenCName))
|
||||
elif Vpd.DatumType in ["BOOLEAN", "UINT8", "UINT16", "UINT32", "UINT64"]:
|
||||
elif Vpd.DatumType in TAB_PCD_NUMERIC_TYPES:
|
||||
if Vpd.MaxDatumSize is None or Vpd.MaxDatumSize == "":
|
||||
Vpd.MaxDatumSize = MAX_SIZE_TYPE[Vpd.DatumType]
|
||||
else:
|
||||
|
Reference in New Issue
Block a user