From b3e94a06172113991f28a1eff096255c65702a0c Mon Sep 17 00:00:00 2001 From: Zhijux Fan Date: Fri, 7 Dec 2018 12:34:44 +0800 Subject: BaseTools: change the Division Operator PEP 238 -- Changing the Division Operator x/y to return a reasonable approximation of the mathematical result of the division ("true division") x//y to return the floor ("floor division") Cc: Bob Feng Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan Tested-by: Laszlo Ersek Tested-by: Ard Biesheuvel Reviewed-by: Liming Gao Reviewed-by: Bob Feng --- BaseTools/Source/Python/Common/Expression.py | 9 ++++++++- BaseTools/Source/Python/Common/Misc.py | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'BaseTools/Source/Python/Common') diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 19ea13b..0c7e25b 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -439,6 +439,13 @@ class ValueExpression(BaseExpression): else: Val = Val3 continue + # + # PEP 238 -- Changing the Division Operator + # x/y to return a reasonable approximation of the mathematical result of the division ("true division") + # x//y to return the floor ("floor division") + # + if Op == '/': + Op = '//' try: Val = self.Eval(Op, Val, EvalFunc()) except WrnExpression as Warn: @@ -912,7 +919,7 @@ class ValueExpressionEx(ValueExpression): if TmpValue.bit_length() == 0: PcdValue = '{0x00}' else: - for I in range((TmpValue.bit_length() + 7) / 8): + for I in range((TmpValue.bit_length() + 7) // 8): TmpList.append('0x%02x' % ((TmpValue >> I * 8) & 0xff)) PcdValue = '{' + ', '.join(TmpList) + '}' except: diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index d23a075..bd7c281 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -1025,7 +1025,7 @@ def ParseFieldValue (Value): if "{CODE(" in Value: return Value, len(Value.split(",")) if isinstance(Value, type(0)): - return Value, (Value.bit_length() + 7) / 8 + return Value, (Value.bit_length() + 7) // 8 if not isinstance(Value, type('')): raise BadExpression('Type %s is %s' %(Value, type(Value))) Value = Value.strip() @@ -1146,12 +1146,12 @@ def ParseFieldValue (Value): raise BadExpression("invalid hex value: %s" % Value) if Value == 0: return 0, 1 - return Value, (Value.bit_length() + 7) / 8 + return Value, (Value.bit_length() + 7) // 8 if Value[0].isdigit(): Value = int(Value, 10) if Value == 0: return 0, 1 - return Value, (Value.bit_length() + 7) / 8 + return Value, (Value.bit_length() + 7) // 8 if Value.lower() == 'true': return 1, 1 if Value.lower() == 'false': -- cgit v1.1