BaseTools: Unify long and int in Expression.py

Per PEP237(*), 'long' is unified with 'int' and removed from python3.

* To make the script compatible with both python2 and python3,
  'type(0L)' is replaced with 'type(sys.maxsize + 1)'. In python2,
  the number is 'long', while it's 'int' in python3. We can remove
  the workaround after moving to python3 completely.

* long() is replaced with int() since int() returns a long when need.

(*) https://www.python.org/dev/peps/pep-0237/

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Gary Lin 2018-06-27 18:07:56 +08:00 committed by Yonghong Zhu
parent 9fb2cbdac4
commit 39456d00f3
1 changed files with 4 additions and 2 deletions

View File

@ -20,6 +20,7 @@ from Misc import GuidStringToGuidStructureString, ParseFieldValue, IsFieldValueA
import Common.EdkLogger as EdkLogger import Common.EdkLogger as EdkLogger
import copy import copy
from Common.DataType import * from Common.DataType import *
import sys
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].' ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].' ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
@ -254,7 +255,8 @@ class ValueExpression(BaseExpression):
Oprand2 = IntToStr(Oprand2) Oprand2 = IntToStr(Oprand2)
TypeDict = { TypeDict = {
type(0) : 0, type(0) : 0,
type(0L) : 0, # For python2 long type
type(sys.maxsize + 1) : 0,
type('') : 1, type('') : 1,
type(True) : 2 type(True) : 2
} }
@ -892,7 +894,7 @@ class ValueExpressionEx(ValueExpression):
raise BadExpression('Type %s PCD Value Size is Larger than 8 byte' % self.PcdType) raise BadExpression('Type %s PCD Value Size is Larger than 8 byte' % self.PcdType)
else: else:
try: try:
TmpValue = long(PcdValue) TmpValue = int(PcdValue)
TmpList = [] TmpList = []
if TmpValue.bit_length() == 0: if TmpValue.bit_length() == 0:
PcdValue = '{0x00}' PcdValue = '{0x00}'