BaseTools: Enhance parse performance by optimize ValueExpressionEx
authorYunhua Feng <yunhuax.feng@intel.com>
Fri, 26 Jan 2018 16:28:05 +0000 (00:28 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Tue, 30 Jan 2018 14:44:59 +0000 (22:44 +0800)
Optimize ValueExpressionEx function to enhance meta-data file parse
performance.

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>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/Common/Expression.py
BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools/Source/Python/Workspace/MetaFileParser.py
BaseTools/Source/Python/build/BuildReport.py

index ab178c9a4ab8170baf918cc1a722b60a16a4686e..1cf50e872fcd0f695bcdce1b2596000d5a4c367e 100644 (file)
@@ -1245,6 +1245,7 @@ class PlatformAutoGen(AutoGen):
         # get the original module/package/platform objects\r
         self.BuildDatabase = Workspace.BuildDatabase\r
         self.DscBuildDataObj = Workspace.Platform\r
         # get the original module/package/platform objects\r
         self.BuildDatabase = Workspace.BuildDatabase\r
         self.DscBuildDataObj = Workspace.Platform\r
+        self._GuidDict = Workspace._GuidDict\r
 \r
         # flag indicating if the makefile/C-code file has been created or not\r
         self.IsMakeFileCreated  = False\r
 \r
         # flag indicating if the makefile/C-code file has been created or not\r
         self.IsMakeFileCreated  = False\r
@@ -2463,22 +2464,9 @@ class PlatformAutoGen(AutoGen):
             if FromPcd.SkuInfoList not in [None, '', []]:\r
                 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
             # Add Flexible PCD format parse\r
             if FromPcd.SkuInfoList not in [None, '', []]:\r
                 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
             # Add Flexible PCD format parse\r
-            PcdValue = ToPcd.DefaultValue\r
-            if PcdValue:\r
-                try:\r
-                    ToPcd.DefaultValue = ValueExpression(PcdValue)(True)\r
-                except WrnExpression, Value:\r
-                    ToPcd.DefaultValue = Value.result\r
-                except BadExpression, Value:\r
-                    EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.DefaultValue, Value),\r
-                                    File=self.MetaFile)\r
             if ToPcd.DefaultValue:\r
             if ToPcd.DefaultValue:\r
-                _GuidDict = {}\r
-                for Pkg in self.PackageList:\r
-                    Guids = Pkg.Guids\r
-                    _GuidDict.update(Guids)\r
                 try:\r
                 try:\r
-                    ToPcd.DefaultValue = ValueExpressionEx(ToPcd.DefaultValue, ToPcd.DatumType, _GuidDict)(True)\r
+                    ToPcd.DefaultValue = ValueExpressionEx(ToPcd.DefaultValue, ToPcd.DatumType, self._GuidDict)(True)\r
                 except BadExpression, Value:\r
                     EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.DefaultValue, Value),\r
                                         File=self.MetaFile)\r
                 except BadExpression, Value:\r
                     EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.DefaultValue, Value),\r
                                         File=self.MetaFile)\r
index 55fa06d414ea1029293ee1c92bc2ceb314e4d26f..486c537029571bd04c0d2cbac8e3633bcf65e44d 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to parse and evaluate expression in directive or PCD value.\r
 #\r
 ## @file\r
 # This file is used to parse and evaluate expression in directive or PCD value.\r
 #\r
-# Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>\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
 # 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
@@ -251,9 +251,6 @@ class ValueExpression(object):
             self._Expr = Expression\r
             self._NoProcess = True\r
             return\r
             self._Expr = Expression\r
             self._NoProcess = True\r
             return\r
-        if Expression.strip().startswith('{') and Expression.strip().endswith('}'):\r
-            self._Expr = Expression\r
-            self._NoProcess = True\r
 \r
         self._Expr = ReplaceExprMacro(Expression.strip(),\r
                                   SymbolTable,\r
 \r
         self._Expr = ReplaceExprMacro(Expression.strip(),\r
                                   SymbolTable,\r
@@ -293,13 +290,15 @@ class ValueExpression(object):
             self._Token = self._Expr\r
             if self.__IsNumberToken():\r
                 return self._Expr\r
             self._Token = self._Expr\r
             if self.__IsNumberToken():\r
                 return self._Expr\r
-\r
+            Token = ''\r
             try:\r
                 Token = self._GetToken()\r
             try:\r
                 Token = self._GetToken()\r
-                if type(Token) == type('') and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len:\r
-                    return self._Expr\r
             except BadExpression:\r
                 pass\r
             except BadExpression:\r
                 pass\r
+            if type(Token) == type('') and Token.startswith('{') and Token.endswith('}') and self._Idx >= self._Len:\r
+                if len(Token) != len(self._Expr.replace(' ', '')):\r
+                    raise BadExpression\r
+                return self._Expr\r
 \r
             self._Idx = 0\r
             self._Token = ''\r
 \r
             self._Idx = 0\r
             self._Token = ''\r
@@ -454,13 +453,20 @@ class ValueExpression(object):
         Radix = 10\r
         if self._Token.lower()[0:2] == '0x' and len(self._Token) > 2:\r
             Radix = 16\r
         Radix = 10\r
         if self._Token.lower()[0:2] == '0x' and len(self._Token) > 2:\r
             Radix = 16\r
-        if self._Token.startswith('"') or self._Token.startswith("'")\\r
-            or self._Token.startswith("L'") or self._Token.startswith('L"'):\r
+        if self._Token.startswith('"') or self._Token.startswith('L"'):\r
+            Flag = 0\r
+            for Index in range(len(self._Token)):\r
+                if self._Token[Index] in ['"']:\r
+                    Flag += 1\r
+            if Flag == 2 and self._Token.endswith('"'):\r
+                self._Token = ParseFieldValue(self._Token)[0]\r
+                return True\r
+        if self._Token.startswith("'") or self._Token.startswith("L'"):\r
             Flag = 0\r
             for Index in range(len(self._Token)):\r
             Flag = 0\r
             for Index in range(len(self._Token)):\r
-                if self._Token[Index] in ['"', "'"]:\r
+                if self._Token[Index] in ["'"]:\r
                     Flag += 1\r
                     Flag += 1\r
-            if Flag == 2:\r
+            if Flag == 2 and self._Token.endswith("'"):\r
                 self._Token = ParseFieldValue(self._Token)[0]\r
                 return True\r
         try:\r
                 self._Token = ParseFieldValue(self._Token)[0]\r
                 return True\r
         try:\r
@@ -593,11 +599,10 @@ class ValueExpression(object):
 \r
         if self.HexPattern.match(self._LiteralToken):\r
             Token = self._LiteralToken[2:]\r
 \r
         if self.HexPattern.match(self._LiteralToken):\r
             Token = self._LiteralToken[2:]\r
-            Token = Token.lstrip('0')\r
             if not Token:\r
                 self._LiteralToken = '0x0'\r
             else:\r
             if not Token:\r
                 self._LiteralToken = '0x0'\r
             else:\r
-                self._LiteralToken = '0x' + Token.lower()\r
+                self._LiteralToken = '0x' + Token\r
             return True\r
         return False\r
 \r
             return True\r
         return False\r
 \r
@@ -734,145 +739,159 @@ class ValueExpressionEx(ValueExpression):
         PcdValue = self.PcdValue\r
         try:\r
             PcdValue = ValueExpression.__call__(self, RealValue, Depth)\r
         PcdValue = self.PcdValue\r
         try:\r
             PcdValue = ValueExpression.__call__(self, RealValue, Depth)\r
+            if self.PcdType == 'VOID*' and (PcdValue.startswith("'") or PcdValue.startswith("L'")):\r
+                raise BadExpression\r
+            elif self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN'] and (PcdValue.startswith("'") or \\r
+                      PcdValue.startswith('"') or PcdValue.startswith("L'") or PcdValue.startswith('L"') or PcdValue.startswith('{')):\r
+                raise BadExpression\r
         except WrnExpression, Value:\r
             PcdValue = Value.result\r
         except WrnExpression, Value:\r
             PcdValue = Value.result\r
-\r
-        if PcdValue == 'True':\r
-            PcdValue = '1'\r
-        if PcdValue == 'False':\r
-            PcdValue = '0'\r
-        if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
-            PcdValue = PcdValue.strip()\r
-            if type(PcdValue) == type('') and PcdValue.startswith('{') and PcdValue.endswith('}'):\r
-                PcdValue = PcdValue[1:-1].split(',')\r
-            if type(PcdValue) == type([]):\r
-                TmpValue = 0\r
-                Size = 0\r
-                for Item in PcdValue:\r
-                    if Item.startswith('UINT16'):\r
-                        ItemSize = 2\r
-                    elif Item.startswith('UINT32'):\r
-                        ItemSize = 4\r
-                    elif Item.startswith('UINT64'):\r
-                        ItemSize = 8\r
-                    else:\r
-                        ItemSize = 0\r
-                    Item = ValueExpressionEx(Item, self.PcdType, self._Symb)(True)\r
-\r
-                    if ItemSize == 0:\r
-                        ItemValue, ItemSize = ParseFieldValue(Item)\r
-                    else:\r
-                        ItemValue = ParseFieldValue(Item)[0]\r
-\r
-                    if type(ItemValue) == type(''):\r
-                        ItemValue = int(ItemValue, 16) if ItemValue.startswith('0x') else int(ItemValue)\r
-\r
-                    TmpValue = (ItemValue << (Size * 8)) | TmpValue\r
-                    Size = Size + ItemSize\r
-            else:\r
-                TmpValue, Size = ParseFieldValue(PcdValue)\r
-            if type(TmpValue) == type(''):\r
-                TmpValue = int(TmpValue)\r
-            else:\r
-                PcdValue = '0x%0{}X'.format(Size) % (TmpValue)\r
-            if TmpValue < 0:\r
-                raise  BadExpression('Type %s PCD Value is negative' % self.PcdType)\r
-            if self.PcdType == 'UINT8' and Size > 1:\r
-                raise BadExpression('Type %s PCD Value Size is Larger than 1 byte' % self.PcdType)\r
-            if self.PcdType == 'UINT16' and Size > 2:\r
-                raise BadExpression('Type %s PCD Value Size is Larger than 2 byte' % self.PcdType)\r
-            if self.PcdType == 'UINT32' and Size > 4:\r
-                raise BadExpression('Type %s PCD Value Size is Larger than 4 byte' % self.PcdType)\r
-            if self.PcdType == 'UINT64' and Size > 8:\r
-                raise BadExpression('Type %s PCD Value Size is Larger than 8 byte' % self.PcdType)\r
-        if self.PcdType in ['VOID*']:\r
-            try:\r
-                TmpValue = long(PcdValue)\r
-                TmpList = []\r
-                if TmpValue.bit_length() == 0:\r
-                    PcdValue = '{0x00}'\r
-                else:\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
-                if PcdValue.strip().startswith('{'):\r
-                    PcdValue = PcdValue.strip()[1:-1].strip()\r
+        except BadExpression:\r
+            if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+                PcdValue = PcdValue.strip()\r
+                if type(PcdValue) == type('') and PcdValue.startswith('{') and PcdValue.endswith('}'):\r
+                    PcdValue = PcdValue[1:-1].split(',')\r
+                if type(PcdValue) == type([]):\r
+                    TmpValue = 0\r
                     Size = 0\r
                     Size = 0\r
-                    ValueStr = ''\r
-                    TokenSpaceGuidName = ''\r
-                    if PcdValue.startswith('GUID') and PcdValue.endswith(')'):\r
-                        try:\r
-                            TokenSpaceGuidName = re.search('GUID\((\w+)\)', PcdValue).group(1)\r
-                        except:\r
-                            pass\r
-                        if TokenSpaceGuidName and TokenSpaceGuidName in self._Symb:\r
-                            PcdValue = 'GUID(' + self._Symb[TokenSpaceGuidName] + ')'\r
-                        elif TokenSpaceGuidName:\r
-                            raise BadExpression('%s not found in DEC file' % TokenSpaceGuidName)\r
-\r
-                        ListItem, Size = ParseFieldValue(PcdValue)\r
-                    elif PcdValue.startswith('DEVICE_PATH') and PcdValue.endswith(')'):\r
-                        ListItem, Size = ParseFieldValue(PcdValue)\r
-                    else:\r
-                        ListItem = PcdValue.split(',')\r
-\r
-                    if type(ListItem) == type(0) or type(ListItem) == type(0L):\r
-                        for Index in range(0, Size):\r
-                            ValueStr += '0x%02X' % (int(ListItem) & 255)\r
-                            ListItem >>= 8\r
-                            ValueStr += ', '\r
-                            PcdValue = '{' + ValueStr[:-2] + '}'\r
-                    elif type(ListItem) == type(''):\r
-                        if ListItem.startswith('{') and ListItem.endswith('}'):\r
-                            PcdValue = ListItem\r
+                    for Item in PcdValue:\r
+                        if Item.startswith('UINT16'):\r
+                            ItemSize = 2\r
+                        elif Item.startswith('UINT32'):\r
+                            ItemSize = 4\r
+                        elif Item.startswith('UINT64'):\r
+                            ItemSize = 8\r
+                        else:\r
+                            ItemSize = 0\r
+                        Item = ValueExpressionEx(Item, self.PcdType, self._Symb)(True)\r
+\r
+                        if ItemSize == 0:\r
+                            ItemValue, ItemSize = ParseFieldValue(Item)\r
+                        else:\r
+                            ItemValue = ParseFieldValue(Item)[0]\r
+\r
+                        if type(ItemValue) == type(''):\r
+                            ItemValue = int(ItemValue, 16) if ItemValue.startswith('0x') else int(ItemValue)\r
+\r
+                        TmpValue = (ItemValue << (Size * 8)) | TmpValue\r
+                        Size = Size + ItemSize\r
+                else:\r
+                    TmpValue, Size = ParseFieldValue(PcdValue)\r
+                if type(TmpValue) == type(''):\r
+                    TmpValue = int(TmpValue)\r
+                else:\r
+                    PcdValue = '0x%0{}X'.format(Size) % (TmpValue)\r
+                if TmpValue < 0:\r
+                    raise  BadExpression('Type %s PCD Value is negative' % self.PcdType)\r
+                if self.PcdType == 'UINT8' and Size > 1:\r
+                    raise BadExpression('Type %s PCD Value Size is Larger than 1 byte' % self.PcdType)\r
+                if self.PcdType == 'UINT16' and Size > 2:\r
+                    raise BadExpression('Type %s PCD Value Size is Larger than 2 byte' % self.PcdType)\r
+                if self.PcdType == 'UINT32' and Size > 4:\r
+                    raise BadExpression('Type %s PCD Value Size is Larger than 4 byte' % self.PcdType)\r
+                if self.PcdType == 'UINT64' and Size > 8:\r
+                    raise BadExpression('Type %s PCD Value Size is Larger than 8 byte' % self.PcdType)\r
+            if self.PcdType in ['VOID*']:\r
+                try:\r
+                    TmpValue = long(PcdValue)\r
+                    TmpList = []\r
+                    if TmpValue.bit_length() == 0:\r
+                        PcdValue = '{0x00}'\r
                     else:\r
                     else:\r
-                        LabelDict = {}\r
-                        ReLabel = re.compile('LABEL\((\w+)\)')\r
-                        ReOffset = re.compile('OFFSET_OF\((\w+)\)')\r
-                        for Index, Item in enumerate(ListItem):\r
-                            # for LABEL parse\r
-                            Item = Item.strip()\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
+                    if PcdValue.strip().startswith('{'):\r
+                        PcdValue = PcdValue.strip()[1:-1].strip()\r
+                        Size = 0\r
+                        ValueStr = ''\r
+                        TokenSpaceGuidName = ''\r
+                        if PcdValue.startswith('GUID') and PcdValue.endswith(')'):\r
                             try:\r
                             try:\r
-                                LabelList = ReLabel.findall(Item)\r
-                                for Label in LabelList:\r
-                                    if Label not in LabelDict.keys():\r
-                                        LabelDict[Label] = str(Index)\r
-                                Item = ReLabel.sub('', Item)\r
+                                TokenSpaceGuidName = re.search('GUID\((\w+)\)', PcdValue).group(1)\r
                             except:\r
                                 pass\r
                             except:\r
                                 pass\r
-                            try:\r
-                                OffsetList = ReOffset.findall(Item)\r
-                            except:\r
-                                pass\r
-                            for Offset in OffsetList:\r
-                                if Offset in LabelDict.keys():\r
-                                    Re = re.compile('OFFSET_OF\(%s\)'% Offset)\r
-                                    Item = Re.sub(LabelDict[Offset], Item)\r
-                                else:\r
-                                    raise BadExpression('%s not defined before use' % Offset)\r
-                            if Item.startswith('UINT16'):\r
-                                ItemSize = 2\r
-                            elif Item.startswith('UINT32'):\r
-                                ItemSize = 4\r
-                            elif Item.startswith('UINT64'):\r
-                                ItemSize = 8\r
-                            else:\r
-                                ItemSize = 0\r
-                            TmpValue = ValueExpressionEx(Item, self.PcdType, self._Symb)(True)\r
-                            Item = '0x%x' % TmpValue if type(TmpValue) != type('') else TmpValue\r
-                            if ItemSize == 0:\r
-                                ItemValue, ItemSize = ParseFieldValue(Item)\r
-                            else:\r
-                                ItemValue = ParseFieldValue(Item)[0]\r
-                            for I in range(0, ItemSize):\r
-                                ValueStr += '0x%02X' % (int(ItemValue) & 255)\r
-                                ItemValue >>= 8\r
+                            if TokenSpaceGuidName and TokenSpaceGuidName in self._Symb:\r
+                                PcdValue = 'GUID(' + self._Symb[TokenSpaceGuidName] + ')'\r
+                            elif TokenSpaceGuidName:\r
+                                raise BadExpression('%s not found in DEC file' % TokenSpaceGuidName)\r
+\r
+                            ListItem, Size = ParseFieldValue(PcdValue)\r
+                        elif PcdValue.startswith('DEVICE_PATH') and PcdValue.endswith(')'):\r
+                            ListItem, Size = ParseFieldValue(PcdValue)\r
+                        else:\r
+                            ListItem = PcdValue.split(',')\r
+\r
+                        if type(ListItem) == type(0) or type(ListItem) == type(0L):\r
+                            for Index in range(0, Size):\r
+                                ValueStr += '0x%02X' % (int(ListItem) & 255)\r
+                                ListItem >>= 8\r
                                 ValueStr += ', '\r
                                 ValueStr += ', '\r
-                            Size += ItemSize\r
+                                PcdValue = '{' + ValueStr[:-2] + '}'\r
+                        elif type(ListItem) == type(''):\r
+                            if ListItem.startswith('{') and ListItem.endswith('}'):\r
+                                PcdValue = ListItem\r
+                        else:\r
+                            LabelDict = {}\r
+                            ReLabel = re.compile('LABEL\((\w+)\)')\r
+                            ReOffset = re.compile('OFFSET_OF\((\w+)\)')\r
+                            for Index, Item in enumerate(ListItem):\r
+                                # for LABEL parse\r
+                                Item = Item.strip()\r
+                                try:\r
+                                    LabelList = ReLabel.findall(Item)\r
+                                    for Label in LabelList:\r
+                                        if Label not in LabelDict.keys():\r
+                                            LabelDict[Label] = str(Index)\r
+                                    Item = ReLabel.sub('', Item)\r
+                                except:\r
+                                    pass\r
+                                try:\r
+                                    OffsetList = ReOffset.findall(Item)\r
+                                except:\r
+                                    pass\r
+                                for Offset in OffsetList:\r
+                                    if Offset in LabelDict.keys():\r
+                                        Re = re.compile('OFFSET_OF\(%s\)'% Offset)\r
+                                        Item = Re.sub(LabelDict[Offset], Item)\r
+                                    else:\r
+                                        raise BadExpression('%s not defined before use' % Offset)\r
+                                ValueType = ""\r
+                                if Item.startswith('UINT16'):\r
+                                    ItemSize = 1\r
+                                    ValueType = "UINT8"\r
+                                elif Item.startswith('UINT16'):\r
+                                    ItemSize = 2\r
+                                    ValueType = "UINT16"\r
+                                elif Item.startswith('UINT32'):\r
+                                    ItemSize = 4\r
+                                elif Item.startswith('UINT64'):\r
+                                    ItemSize = 8\r
+                                else:\r
+                                    ItemSize = 0\r
+                                if ValueType:\r
+                                    TmpValue = ValueExpressionEx(Item, ValueType, self._Symb)(True)\r
+                                else:\r
+                                    TmpValue = ValueExpressionEx(Item, self.PcdType, self._Symb)(True)\r
+                                Item = '0x%x' % TmpValue if type(TmpValue) != type('') else TmpValue\r
+                                if ItemSize == 0:\r
+                                    ItemValue, ItemSize = ParseFieldValue(Item)\r
+                                else:\r
+                                    ItemValue = ParseFieldValue(Item)[0]\r
+                                for I in range(0, ItemSize):\r
+                                    ValueStr += '0x%02X' % (int(ItemValue) & 255)\r
+                                    ItemValue >>= 8\r
+                                    ValueStr += ', '\r
+                                Size += ItemSize\r
+\r
+                            if Size > 0:\r
+                                PcdValue = '{' + ValueStr[:-2] + '}'\r
+        if PcdValue == 'True':\r
+            PcdValue = '1'\r
+        if PcdValue == 'False':\r
+            PcdValue = '0'\r
 \r
 \r
-                        if Size > 0:\r
-                            PcdValue = '{' + ValueStr[:-2] + '}'\r
         if RealValue:\r
             return PcdValue\r
 \r
         if RealValue:\r
             return PcdValue\r
 \r
index f30d3f7e732eb9607cd28d25e44c60b4631515e0..012e16a4884a70d4e15a60b9dec242772ab0159e 100644 (file)
@@ -825,13 +825,14 @@ class DscBuildData(PlatformBuildClassObject):
                 if ValueList[2] == '-1':\r
                     EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,\r
                                 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))\r
                 if ValueList[2] == '-1':\r
                     EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,\r
                                 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))\r
-        if ValueList[Index] and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:\r
+        if ValueList[Index]:\r
+            DatumType = self._DecPcds[PcdCName, TokenSpaceGuid].DatumType\r
             try:\r
             try:\r
-                ValueList[Index] = ValueExpression(ValueList[Index], GlobalData.gPlatformPcds)(True)\r
-            except WrnExpression, Value:\r
-                ValueList[Index] = Value.result\r
+                ValueList[Index] = ValueExpressionEx(ValueList[Index], DatumType, self._GuidDict)(True)\r
             except BadExpression, Value:\r
             except BadExpression, Value:\r
-                EdkLogger.error('Parser', FORMAT_INVALID, Value, File=self.MetaFile, Line=self._LineIndex + 1)\r
+                EdkLogger.error('Parser', FORMAT_INVALID, Value, File=self.MetaFile, Line=LineNo,\r
+                                ExtraData="PCD [%s.%s] Value \"%s\" " % (\r
+                                TokenSpaceGuid, PcdCName, ValueList[Index]))\r
             except EvaluationException, Excpt:\r
                 if hasattr(Excpt, 'Pcd'):\r
                     if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r
             except EvaluationException, Excpt:\r
                 if hasattr(Excpt, 'Pcd'):\r
                     if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r
@@ -845,13 +846,8 @@ class DscBuildData(PlatformBuildClassObject):
                 else:\r
                     EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),\r
                                     File=self.MetaFile, Line=LineNo)\r
                 else:\r
                     EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),\r
                                     File=self.MetaFile, Line=LineNo)\r
+\r
         if ValueList[Index]:\r
         if ValueList[Index]:\r
-            DatumType = self._DecPcds[PcdCName, TokenSpaceGuid].DatumType\r
-            try:\r
-                ValueList[Index] = ValueExpressionEx(ValueList[Index], DatumType, self._GuidDict)(True)\r
-            except BadExpression, Value:\r
-                EdkLogger.error('Parser', FORMAT_INVALID, Value, File=self.MetaFile, Line=LineNo,\r
-                                ExtraData="PCD [%s.%s] Value \"%s\" " % (TokenSpaceGuid, PcdCName, ValueList[Index]))\r
             Valid, ErrStr = CheckPcdDatum(self._DecPcds[PcdCName, TokenSpaceGuid].DatumType, ValueList[Index])\r
             if not Valid:\r
                 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,\r
             Valid, ErrStr = CheckPcdDatum(self._DecPcds[PcdCName, TokenSpaceGuid].DatumType, ValueList[Index])\r
             if not Valid:\r
                 EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,\r
@@ -860,6 +856,9 @@ class DscBuildData(PlatformBuildClassObject):
                 if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() != ValueList[1].strip():\r
                     EdkLogger.error('build', FORMAT_INVALID, ErrStr , File=self.MetaFile, Line=LineNo,\r
                                 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))\r
                 if self._DecPcds[PcdCName, TokenSpaceGuid].DatumType.strip() != ValueList[1].strip():\r
                     EdkLogger.error('build', FORMAT_INVALID, ErrStr , File=self.MetaFile, Line=LineNo,\r
                                 ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))\r
+        if (TokenSpaceGuid + '.' + PcdCName) in GlobalData.gPlatformPcds:\r
+            if GlobalData.gPlatformPcds[TokenSpaceGuid + '.' + PcdCName] != ValueList[Index]:\r
+                GlobalData.gPlatformPcds[TokenSpaceGuid + '.' + PcdCName] = ValueList[Index]\r
         return ValueList\r
 \r
     def _FilterPcdBySkuUsage(self,Pcds):\r
         return ValueList\r
 \r
     def _FilterPcdBySkuUsage(self,Pcds):\r
index 8f4b5e5cc1ca6c6292e808c7e40251be80dffa2e..c928cef70f15eeee99a8e5d240d02765c686e7be 100644 (file)
@@ -1593,6 +1593,8 @@ class DscParser(MetaFileParser):
                 ValList[Index] = ValueExpression(PcdValue, self._Macros)(True)\r
             except WrnExpression, Value:\r
                 ValList[Index] = Value.result\r
                 ValList[Index] = ValueExpression(PcdValue, self._Macros)(True)\r
             except WrnExpression, Value:\r
                 ValList[Index] = Value.result\r
+            except:\r
+                pass\r
 \r
         if ValList[Index] == 'True':\r
             ValList[Index] = '1'\r
 \r
         if ValList[Index] == 'True':\r
             ValList[Index] = '1'\r
@@ -1989,14 +1991,6 @@ class DecParser(MetaFileParser):
 \r
             PcdValue = ValueList[0]\r
             if PcdValue:\r
 \r
             PcdValue = ValueList[0]\r
             if PcdValue:\r
-                try:\r
-                    ValueList[0] = ValueExpression(PcdValue, self._AllPcdDict)(True)\r
-                except WrnExpression, Value:\r
-                    ValueList[0] = Value.result\r
-                except BadExpression, Value:\r
-                    EdkLogger.error('Parser', FORMAT_INVALID, Value, File=self.MetaFile, Line=self._LineIndex + 1)\r
-\r
-            if ValueList[0]:\r
                 try:\r
                     ValueList[0] = ValueExpressionEx(ValueList[0], ValueList[1], self._GuidDict)(True)\r
                 except BadExpression, Value:\r
                 try:\r
                     ValueList[0] = ValueExpressionEx(ValueList[0], ValueList[1], self._GuidDict)(True)\r
                 except BadExpression, Value:\r
index f2a6e6d87eced2e072fe931cd8479ecd9180de37..53d0039c51495fccd7032bafd771f8c8289dc52a 100644 (file)
@@ -37,6 +37,7 @@ from Common.InfClassObject import gComponentType2ModuleType
 from Common.BuildToolError import FILE_WRITE_FAILURE\r
 from Common.BuildToolError import CODE_ERROR\r
 from Common.BuildToolError import COMMAND_FAILURE\r
 from Common.BuildToolError import FILE_WRITE_FAILURE\r
 from Common.BuildToolError import CODE_ERROR\r
 from Common.BuildToolError import COMMAND_FAILURE\r
+from Common.BuildToolError import FORMAT_INVALID\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 import Common.GlobalData as GlobalData\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 import Common.GlobalData as GlobalData\r
@@ -45,7 +46,7 @@ from Common.Misc import PathClass
 from Common.String import NormPath\r
 from Common.DataType import *\r
 import collections\r
 from Common.String import NormPath\r
 from Common.DataType import *\r
 import collections\r
-from Common.Expression import ValueExpressionEx\r
+from Common.Expression import *\r
 \r
 ## Pattern to extract contents in EDK DXS files\r
 gDxsDependencyPattern = re.compile(r"DEPENDENCY_START(.+)DEPENDENCY_END", re.DOTALL)\r
 \r
 ## Pattern to extract contents in EDK DXS files\r
 gDxsDependencyPattern = re.compile(r"DEPENDENCY_START(.+)DEPENDENCY_END", re.DOTALL)\r
@@ -955,7 +956,11 @@ class PcdReport(object):
                     DscDefaultValBak = DscDefaultValue\r
                     DscDefaultValue = self.FdfPcdSet.get((Pcd.TokenCName, Key), DscDefaultValue)\r
                     if DscDefaultValue != DscDefaultValBak:\r
                     DscDefaultValBak = DscDefaultValue\r
                     DscDefaultValue = self.FdfPcdSet.get((Pcd.TokenCName, Key), DscDefaultValue)\r
                     if DscDefaultValue != DscDefaultValBak:\r
-                        DscDefaultValue = ValueExpressionEx(DscDefaultValue, Pcd.DatumType, self._GuidDict)(True)\r
+                        try:\r
+                            DscDefaultValue = ValueExpressionEx(DscDefaultValue, Pcd.DatumType, self._GuidDict)(True)\r
+                        except BadExpression, Value:\r
+                            EdkLogger.error('BuildReport', FORMAT_INVALID, "PCD Value: %s, Type: %s" %(DscDefaultValue, Pcd.DatumType))\r
+\r
                     InfDefaultValue = None\r
                     \r
                     PcdValue = DecDefaultValue\r
                     InfDefaultValue = None\r
                     \r
                     PcdValue = DecDefaultValue\r