]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/Expression.py
BaseTools: Add missing spaces for PCD expression values in AutoGenC
[mirror_edk2.git] / BaseTools / Source / Python / Common / Expression.py
index a5f085d7fb7468227a479207869124453ac4b904..b62efe6f9be681427f33d95d6503ed3c592e62c0 100644 (file)
@@ -2,13 +2,7 @@
 # This file is used to parse and evaluate expression in directive or PCD value.\r
 #\r
 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution.    The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 ## Import Modules\r
 #\r
@@ -17,7 +11,7 @@ from __future__ import absolute_import
 from Common.GlobalData import *\r
 from CommonDataClass.Exceptions import BadExpression\r
 from CommonDataClass.Exceptions import WrnExpression\r
-from .Misc import GuidStringToGuidStructureString, ParseFieldValue\r
+from .Misc import GuidStringToGuidStructureString, ParseFieldValue,CopyDict\r
 import Common.EdkLogger as EdkLogger\r
 import copy\r
 from Common.DataType import *\r
@@ -49,7 +43,7 @@ ERR_IN_OPERAND          = 'Macro after IN operator can only be: $(FAMILY), $(ARC
 __ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')\r
 _ReLabel = re.compile('LABEL\((\w+)\)')\r
 _ReOffset = re.compile('OFFSET_OF\((\w+)\)')\r
-PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')\r
+PcdPattern = re.compile(r'^[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')\r
 \r
 ## SplitString\r
 #  Split string to list according double quote\r
@@ -355,7 +349,7 @@ class ValueExpression(BaseExpression):
         #\r
         # The symbol table including PCD and macro mapping\r
         #\r
-        self._Symb = copy.deepcopy(SymbolTable)\r
+        self._Symb = CopyDict(SymbolTable)\r
         self._Symb.update(self.LogicalOperators)\r
         self._Idx = 0\r
         self._Len = len(self._Expr)\r
@@ -439,6 +433,13 @@ class ValueExpression(BaseExpression):
                 else:\r
                     Val = Val3\r
                 continue\r
+            #\r
+            # PEP 238 -- Changing the Division Operator\r
+            # x/y to return a reasonable approximation of the mathematical result of the division ("true division")\r
+            # x//y to return the floor ("floor division")\r
+            #\r
+            if Op == '/':\r
+                Op = '//'\r
             try:\r
                 Val = self.Eval(Op, Val, EvalFunc())\r
             except WrnExpression as Warn:\r
@@ -912,7 +913,7 @@ class ValueExpressionEx(ValueExpression):
                         if TmpValue.bit_length() == 0:\r
                             PcdValue = '{0x00}'\r
                         else:\r
-                            for I in range((TmpValue.bit_length() + 7) / 8):\r
+                            for I in range((TmpValue.bit_length() + 7) // 8):\r
                                 TmpList.append('0x%02x' % ((TmpValue >> I * 8) & 0xff))\r
                             PcdValue = '{' + ', '.join(TmpList) + '}'\r
                     except:\r
@@ -1025,7 +1026,7 @@ class ValueExpressionEx(ValueExpression):
                                     Size += ItemSize\r
 \r
                             if Size > 0:\r
-                                PcdValue = '{' + ','.join(AllPcdValueList) + '}'\r
+                                PcdValue = '{' + ', '.join(AllPcdValueList) + '}'\r
                         else:\r
                             raise  BadExpression("Type: %s, Value: %s, %s"%(self.PcdType, PcdValue, Value))\r
 \r