mirror of https://github.com/acidanthera/audk.git
BaseTools: Update Expression.py for string comparison and MACRO replace issue
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>
This commit is contained in:
parent
2052cb675f
commit
9efe8d6040
|
@ -157,19 +157,9 @@ class ValueExpression(object):
|
|||
def Eval(Operator, Oprand1, Oprand2 = None):
|
||||
WrnExp = None
|
||||
|
||||
if Operator not in ["in", "not in"] and (type(Oprand1) == type('') or type(Oprand2) == type('')):
|
||||
if type(Oprand1) == type(''):
|
||||
if Oprand1[0] in ['"', "'"] or Oprand1.startswith('L"') or Oprand1.startswith("L'")or Oprand1.startswith('UINT'):
|
||||
Oprand1, Size = ParseFieldValue(Oprand1)
|
||||
else:
|
||||
Oprand1,Size = ParseFieldValue('"' + Oprand1 + '"')
|
||||
if type(Oprand2) == type(''):
|
||||
if Oprand2[0] in ['"', "'"] or Oprand2.startswith('L"') or Oprand2.startswith("L'") or Oprand2.startswith('UINT'):
|
||||
Oprand2, Size = ParseFieldValue(Oprand2)
|
||||
else:
|
||||
Oprand2, Size = ParseFieldValue('"' + Oprand2 + '"')
|
||||
if type(Oprand1) == type('') or type(Oprand2) == type(''):
|
||||
raise BadExpression(ERR_STRING_EXPR % Operator)
|
||||
if Operator not in ["==", "!=", ">=", "<=", ">", "<", "in", "not in"] and \
|
||||
(type(Oprand1) == type('') or type(Oprand2) == type('')):
|
||||
raise BadExpression(ERR_STRING_EXPR % Operator)
|
||||
if Operator in ['in', 'not in']:
|
||||
if type(Oprand1) != type(''):
|
||||
Oprand1 = IntToStr(Oprand1)
|
||||
|
@ -296,8 +286,6 @@ class ValueExpression(object):
|
|||
except BadExpression:
|
||||
pass
|
||||
if type(Token) == type('') and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len:
|
||||
if len(Token) != len(self._Expr.replace(' ', '')):
|
||||
raise BadExpression
|
||||
return self._Expr
|
||||
|
||||
self._Idx = 0
|
||||
|
@ -459,7 +447,6 @@ class ValueExpression(object):
|
|||
if self._Token[Index] in ['"']:
|
||||
Flag += 1
|
||||
if Flag == 2 and self._Token.endswith('"'):
|
||||
self._Token = ParseFieldValue(self._Token)[0]
|
||||
return True
|
||||
if self._Token.startswith("'") or self._Token.startswith("L'"):
|
||||
Flag = 0
|
||||
|
@ -467,7 +454,6 @@ class ValueExpression(object):
|
|||
if self._Token[Index] in ["'"]:
|
||||
Flag += 1
|
||||
if Flag == 2 and self._Token.endswith("'"):
|
||||
self._Token = ParseFieldValue(self._Token)[0]
|
||||
return True
|
||||
try:
|
||||
self._Token = int(self._Token, Radix)
|
||||
|
@ -622,24 +608,16 @@ class ValueExpression(object):
|
|||
self._Idx += 1
|
||||
UStr = self.__GetString()
|
||||
self._Token = 'L"' + UStr + '"'
|
||||
self._Token, Size = ParseFieldValue(self._Token)
|
||||
return self._Token
|
||||
elif Expr.startswith("L'"):
|
||||
# Skip L
|
||||
self._Idx += 1
|
||||
UStr = self.__GetString()
|
||||
self._Token = "L'" + UStr + "'"
|
||||
self._Token, Size = ParseFieldValue(self._Token)
|
||||
return self._Token
|
||||
elif Expr.startswith('"'):
|
||||
UStr = self.__GetString()
|
||||
self._Token = '"' + UStr + '"'
|
||||
self._Token, Size = ParseFieldValue(self._Token)
|
||||
return self._Token
|
||||
elif Expr.startswith("'"):
|
||||
UStr = self.__GetString()
|
||||
self._Token = "'" + UStr + "'"
|
||||
self._Token, Size = ParseFieldValue(self._Token)
|
||||
return self._Token
|
||||
elif Expr.startswith('UINT'):
|
||||
Re = re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)')
|
||||
|
@ -751,7 +729,7 @@ class ValueExpressionEx(ValueExpression):
|
|||
raise BadExpression
|
||||
except WrnExpression, Value:
|
||||
PcdValue = Value.result
|
||||
except BadExpression:
|
||||
except BadExpression, Value:
|
||||
if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:
|
||||
PcdValue = PcdValue.strip()
|
||||
if type(PcdValue) == type('') and PcdValue.startswith('{') and PcdValue.endswith('}'):
|
||||
|
@ -785,10 +763,13 @@ class ValueExpressionEx(ValueExpression):
|
|||
else:
|
||||
try:
|
||||
TmpValue, Size = ParseFieldValue(PcdValue)
|
||||
except BadExpression:
|
||||
raise BadExpression("Type: %s, Value: %s, format or value error" % (self.PcdType, PcdValue))
|
||||
except BadExpression, Value:
|
||||
raise BadExpression("Type: %s, Value: %s, %s" % (self.PcdType, PcdValue, Value))
|
||||
if type(TmpValue) == type(''):
|
||||
TmpValue = int(TmpValue)
|
||||
try:
|
||||
TmpValue = int(TmpValue)
|
||||
except:
|
||||
raise BadExpression(Value)
|
||||
else:
|
||||
PcdValue = '0x%0{}X'.format(Size) % (TmpValue)
|
||||
if TmpValue < 0:
|
||||
|
@ -898,7 +879,7 @@ class ValueExpressionEx(ValueExpression):
|
|||
if Size > 0:
|
||||
PcdValue = '{' + ValueStr[:-2] + '}'
|
||||
else:
|
||||
raise BadExpression("Type: %s, Value: %s, format or value error"%(self.PcdType, PcdValue))
|
||||
raise BadExpression("Type: %s, Value: %s, %s"%(self.PcdType, PcdValue, Value))
|
||||
|
||||
if PcdValue == 'True':
|
||||
PcdValue = '1'
|
||||
|
|
|
@ -808,7 +808,7 @@ class DscBuildData(PlatformBuildClassObject):
|
|||
PkgSet.update(ModuleData.Packages)
|
||||
|
||||
self._DecPcds, self._GuidDict = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain,PkgSet)
|
||||
|
||||
self._GuidDict.update(GlobalData.gPlatformPcds)
|
||||
|
||||
if (PcdCName, TokenSpaceGuid) not in self._DecPcds:
|
||||
EdkLogger.error('build', PARSER_ERROR,
|
||||
|
|
|
@ -1994,6 +1994,7 @@ class DecParser(MetaFileParser):
|
|||
PcdValue = ValueList[0]
|
||||
if PcdValue:
|
||||
try:
|
||||
self._GuidDict.update(self._AllPcdDict)
|
||||
ValueList[0] = ValueExpressionEx(ValueList[0], ValueList[1], self._GuidDict)(True)
|
||||
except BadExpression, Value:
|
||||
EdkLogger.error('Parser', FORMAT_INVALID, Value, ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
|
||||
|
|
Loading…
Reference in New Issue