BaseTools: Enable structure pcd in FDF file
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FdfParser.py
index 67217c3..e2e6df7 100644 (file)
@@ -83,13 +83,12 @@ T_CHAR_BACKSLASH, T_CHAR_DOUBLE_QUOTE, T_CHAR_SINGLE_QUOTE, T_CHAR_STAR, T_CHAR_
 SEPERATOR_TUPLE = ('=', '|', ',', '{', '}')\r
 \r
 RegionSizePattern = re.compile("\s*(?P<base>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<size>(?:0x|0X)?[a-fA-F0-9]+)\s*")\r
-RegionSizeGuidPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*\|\s*(?P<size>\w+\.\w+)\s*")\r
-RegionOffsetPcdPattern = re.compile("\s*(?P<base>\w+\.\w+)\s*$")\r
+RegionSizeGuidPattern = re.compile("\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*\|\s*(?P<size>\w+\.\w+[\.\w\[\]]*)\s*")\r
+RegionOffsetPcdPattern = re.compile("\s*(?P<base>\w+\.\w+[\.\w\[\]]*)\s*$")\r
 ShortcutPcdPattern = re.compile("\s*\w+\s*=\s*(?P<value>(?:0x|0X)?[a-fA-F0-9]+)\s*\|\s*(?P<name>\w+\.\w+)\s*")\r
 BaseAddrValuePattern = re.compile('^0[xX][0-9a-fA-F]+')\r
 FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
 TokenFindPattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
-\r
 AllIncludeFileList = []\r
 \r
 # Get the closest parent\r
@@ -226,8 +225,9 @@ class FileProfile :
         except:\r
             EdkLogger.error("FdfParser", FILE_OPEN_FAILURE, ExtraData=FileName)\r
 \r
-\r
+        self.FileName = FileName\r
         self.PcdDict = {}\r
+        self.PcdLocalDict = {}\r
         self.InfList = []\r
         self.InfDict = {'ArchTBD':[]}\r
         # ECC will use this Dict and List information\r
@@ -787,7 +787,7 @@ class FdfParser:
                     continue\r
                 SetLine = self.CurrentLineNumber - 1\r
                 SetOffset = self.CurrentOffsetWithinLine - len('SET')\r
-                PcdPair = self.__GetNextPcdName()\r
+                PcdPair = self.__GetNextPcdSettings()\r
                 PcdName = "%s.%s" % (PcdPair[1], PcdPair[0])\r
                 if not self.__IsToken( "="):\r
                     raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
@@ -798,6 +798,7 @@ class FdfParser:
                 self.__PcdDict[PcdName] = Value\r
 \r
                 self.Profile.PcdDict[PcdPair] = Value\r
+                self.SetPcdLocalation(PcdPair)\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
 \r
@@ -1049,6 +1050,29 @@ class FdfParser:
 \r
         return False\r
 \r
+    def __GetNextPcdWord(self):\r
+        self.__SkipWhiteSpace()\r
+        if self.__EndOfFile():\r
+            return False\r
+\r
+        TempChar = self.__CurrentChar()\r
+        StartPos = self.CurrentOffsetWithinLine\r
+        if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') or TempChar == '_' or TempChar == '[' or TempChar == ']':\r
+            self.__GetOneChar()\r
+            while not self.__EndOfLine():\r
+                TempChar = self.__CurrentChar()\r
+                if (TempChar >= 'a' and TempChar <= 'z') or (TempChar >= 'A' and TempChar <= 'Z') \\r
+                or (TempChar >= '0' and TempChar <= '9') or TempChar == '_' or TempChar == '-' or TempChar == '[' or TempChar == ']':\r
+                    self.__GetOneChar()\r
+\r
+                else:\r
+                    break\r
+\r
+            self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
+            return True\r
+\r
+        return False\r
+\r
     ## __GetNextToken() method\r
     #\r
     #   Get next token unit before a seperator\r
@@ -1240,6 +1264,26 @@ class FdfParser:
 \r
         return (pcdCName, pcdTokenSpaceCName)\r
 \r
+    def __GetNextPcdSettings(self):\r
+        if not self.__GetNextWord():\r
+            raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
+        pcdTokenSpaceCName = self.__Token\r
+\r
+        if not self.__IsToken( "."):\r
+            raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
+\r
+        if not self.__GetNextWord():\r
+            raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
+        pcdCName = self.__Token\r
+\r
+        Fields = []\r
+        while self.__IsToken("."):\r
+            if not self.__GetNextPcdWord():\r
+                raise Warning("expected format of <PcdTokenSpaceCName>.<PcdCName>", self.FileName, self.CurrentLineNumber)\r
+            Fields.append(self.__Token)\r
+\r
+        return (pcdCName, pcdTokenSpaceCName,".".join(Fields))\r
+\r
     ## __GetStringData() method\r
     #\r
     #   Get string contents quoted in ""\r
@@ -1567,6 +1611,9 @@ class FdfParser:
 \r
         return True\r
 \r
+    def SetPcdLocalation(self,pcdpair):\r
+        self.Profile.PcdLocalDict[pcdpair] = (self.Profile.FileName,self.CurrentLineNumber)\r
+\r
     ## __GetTokenStatements() method\r
     #\r
     #   Get token statements\r
@@ -1585,9 +1632,10 @@ class FdfParser:
             Obj.BaseAddress = self.__Token\r
 \r
             if self.__IsToken( "|"):\r
-                pcdPair = self.__GetNextPcdName()\r
+                pcdPair = self.__GetNextPcdSettings()\r
                 Obj.BaseAddressPcd = pcdPair\r
                 self.Profile.PcdDict[pcdPair] = Obj.BaseAddress\r
+                self.SetPcdLocalation(pcdPair)\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
             return True\r
@@ -1601,9 +1649,10 @@ class FdfParser:
 \r
             Size = self.__Token\r
             if self.__IsToken( "|"):\r
-                pcdPair = self.__GetNextPcdName()\r
+                pcdPair = self.__GetNextPcdSettings()\r
                 Obj.SizePcd = pcdPair\r
                 self.Profile.PcdDict[pcdPair] = Size\r
+                self.SetPcdLocalation(pcdPair)\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[pcdPair] = FileLineTuple\r
             Obj.Size = long(Size, 0)\r
@@ -1694,9 +1743,10 @@ class FdfParser:
         BlockSize = self.__Token\r
         BlockSizePcd = None\r
         if self.__IsToken( "|"):\r
-            PcdPair = self.__GetNextPcdName()\r
+            PcdPair = self.__GetNextPcdSettings()\r
             BlockSizePcd = PcdPair\r
             self.Profile.PcdDict[PcdPair] = BlockSize\r
+            self.SetPcdLocalation(PcdPair)\r
             FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
             self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
         BlockSize = long(BlockSize, 0)\r
@@ -1777,7 +1827,7 @@ class FdfParser:
     #\r
     def __GetSetStatement(self, Obj):\r
         if self.__IsKeyword("SET"):\r
-            PcdPair = self.__GetNextPcdName()\r
+            PcdPair = self.__GetNextPcdSettings()\r
 \r
             if not self.__IsToken( "="):\r
                 raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
@@ -1788,6 +1838,7 @@ class FdfParser:
             if Obj:\r
                 Obj.SetVarDict[PcdPair] = Value\r
             self.Profile.PcdDict[PcdPair] = Value\r
+            self.SetPcdLocalation(PcdPair)\r
             FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
             self.Profile.PcdFileLineDict[PcdPair] = FileLineTuple\r
             return True\r
@@ -1864,14 +1915,16 @@ class FdfParser:
             IsRegionPcd = (RegionSizeGuidPattern.match(self.__CurrentLine()[self.CurrentOffsetWithinLine:]) or\r
                            RegionOffsetPcdPattern.match(self.__CurrentLine()[self.CurrentOffsetWithinLine:]))\r
             if IsRegionPcd:\r
-                RegionObj.PcdOffset = self.__GetNextPcdName()\r
+                RegionObj.PcdOffset = self.__GetNextPcdSettings()\r
                 self.Profile.PcdDict[RegionObj.PcdOffset] = "0x%08X" % (RegionObj.Offset + long(Fd.BaseAddress, 0))\r
+                self.SetPcdLocalation(RegionObj.PcdOffset)\r
                 self.__PcdDict['%s.%s' % (RegionObj.PcdOffset[1], RegionObj.PcdOffset[0])] = "0x%x" % RegionObj.Offset\r
                 FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                 self.Profile.PcdFileLineDict[RegionObj.PcdOffset] = FileLineTuple\r
                 if self.__IsToken( "|"):\r
-                    RegionObj.PcdSize = self.__GetNextPcdName()\r
+                    RegionObj.PcdSize = self.__GetNextPcdSettings()\r
                     self.Profile.PcdDict[RegionObj.PcdSize] = "0x%08X" % RegionObj.Size\r
+                    self.SetPcdLocalation(RegionObj.PcdSize)\r
                     self.__PcdDict['%s.%s' % (RegionObj.PcdSize[1], RegionObj.PcdSize[0])] = "0x%x" % RegionObj.Size\r
                     FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
                     self.Profile.PcdFileLineDict[RegionObj.PcdSize] = FileLineTuple\r
@@ -2609,7 +2662,7 @@ class FdfParser:
             if self.__Token == 'PCD':\r
                 if not self.__IsToken( "("):\r
                     raise Warning("expected '('", self.FileName, self.CurrentLineNumber)\r
-                PcdPair = self.__GetNextPcdName()\r
+                PcdPair = self.__GetNextPcdSettings()\r
                 if not self.__IsToken( ")"):\r
                     raise Warning("expected ')'", self.FileName, self.CurrentLineNumber)\r
                 self.__Token = 'PCD('+PcdPair[1]+'.'+PcdPair[0]+')'\r
@@ -3697,7 +3750,7 @@ class FdfParser:
             if self.__Token == 'PCD':\r
                 if not self.__IsToken( "("):\r
                     raise Warning("expected '('", self.FileName, self.CurrentLineNumber)\r
-                PcdPair = self.__GetNextPcdName()\r
+                PcdPair = self.__GetNextPcdSettings()\r
                 if not self.__IsToken( ")"):\r
                     raise Warning("expected ')'", self.FileName, self.CurrentLineNumber)\r
                 self.__Token = 'PCD('+PcdPair[1]+'.'+PcdPair[0]+')'\r
@@ -3971,7 +4024,7 @@ class FdfParser:
                     if self.__Token == 'PCD':\r
                         if not self.__IsToken( "("):\r
                             raise Warning("expected '('", self.FileName, self.CurrentLineNumber)\r
-                        PcdPair = self.__GetNextPcdName()\r
+                        PcdPair = self.__GetNextPcdSettings()\r
                         if not self.__IsToken( ")"):\r
                             raise Warning("expected ')'", self.FileName, self.CurrentLineNumber)\r
                         self.__Token = 'PCD('+PcdPair[1]+'.'+PcdPair[0]+')'\r