Abstract the logic of Platform pcd preprocess according to FPD file to a class. And...
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 1 Aug 2006 14:51:46 +0000 (14:51 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 1 Aug 2006 14:51:46 +0000 (14:51 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1169 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/GenBuild/org/tianocore/build/fpd/FpdParserTask.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java [deleted file]
Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/PcdDatabase.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java [new file with mode: 0644]

index bd87b6e..ea28781 100644 (file)
@@ -40,7 +40,7 @@ import org.tianocore.build.id.FpdModuleIdentification;
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.build.id.PlatformIdentification;\r
 import org.tianocore.pcd.action.ActionMessage;\r
-import org.tianocore.build.pcd.action.CollectPCDAction;\r
+import org.tianocore.build.pcd.action.PlatformPcdPreprocessActionForBuilding;\r
 import org.tianocore.build.toolchain.ToolChainAttribute;\r
 import org.tianocore.build.toolchain.ToolChainElement;\r
 import org.tianocore.build.toolchain.ToolChainMap;\r
@@ -386,7 +386,7 @@ public class FpdParserTask extends Task {
             // Pcd Collection. Call CollectPCDAction to collect pcd info.\r
             //\r
             try {\r
-                CollectPCDAction ca = new CollectPCDAction();\r
+                PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();\r
                 ca.perform(GlobalData.getWorkspacePath(),platformId.getFpdFile().getPath(),ActionMessage.NULL_MESSAGE_LEVEL);\r
             } catch (Exception e){\r
                 throw new BuildException(e.getMessage());\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
deleted file mode 100644 (file)
index 39372a2..0000000
+++ /dev/null
@@ -1,1535 +0,0 @@
-/** @file\r
-  CollectPCDAction class.\r
-\r
-  This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
-  This class will be used for wizard and build tools, So it can *not* inherit\r
-  from buildAction or wizardAction.\r
\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. 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
-\r
-**/\r
-package org.tianocore.build.pcd.action;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.math.BigInteger;\r
-import java.util.ArrayList;\r
-import java.util.Comparator;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.UUID;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
-\r
-import org.apache.xmlbeans.XmlException;\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
-import org.tianocore.FrameworkModulesDocument;\r
-import org.tianocore.ModuleSADocument;\r
-import org.tianocore.PcdBuildDefinitionDocument;\r
-import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;\r
-import org.tianocore.PlatformSurfaceAreaDocument;\r
-import org.tianocore.build.fpd.FpdParserTask;\r
-import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.id.FpdModuleIdentification;\r
-import org.tianocore.build.id.ModuleIdentification;\r
-import org.tianocore.pcd.action.ActionMessage;\r
-import org.tianocore.pcd.entity.CommonDefinition;\r
-import org.tianocore.pcd.entity.DynamicTokenValue;\r
-import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
-import org.tianocore.pcd.entity.SkuInstance;\r
-import org.tianocore.pcd.entity.Token;\r
-import org.tianocore.pcd.entity.UsageIdentification;\r
-import org.tianocore.pcd.entity.UsageInstance;\r
-import org.tianocore.pcd.exception.EntityException;\r
-\r
-/** Module Info class is the data structure to hold information got from GlobalData.\r
-*/\r
-class ModuleInfo {\r
-    ///\r
-    /// Module's ID for a <ModuleSA>\r
-    /// \r
-    private FpdModuleIdentification                       moduleId;\r
-    ///\r
-    /// <PcdBuildDefinition> xmlobject in FPD file for a <ModuleSA>\r
-    /// \r
-    private PcdBuildDefinitionDocument.PcdBuildDefinition pcdBuildDef;\r
-\r
-    public ModuleInfo (FpdModuleIdentification moduleId, XmlObject pcdDef) {\r
-        this.moduleId       = moduleId;\r
-        this.pcdBuildDef    = ((PcdBuildDefinitionDocument)pcdDef).getPcdBuildDefinition();\r
-    }\r
-\r
-    public FpdModuleIdentification getModuleId (){\r
-       return moduleId;\r
-    }\r
-\r
-    public PcdBuildDefinitionDocument.PcdBuildDefinition getPcdBuildDef(){\r
-       return pcdBuildDef;\r
-    }\r
-}\r
-\r
-/** This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
-    This class will be used for wizard and build tools, So it can *not* inherit\r
-    from buildAction or UIAction.\r
-**/\r
-public class CollectPCDAction {\r
-    ///\r
-    /// memoryDatabase hold all PCD information collected from SPD, MSA, FPD.\r
-    /// \r
-    private MemoryDatabaseManager dbManager;\r
-    ///\r
-    /// Workspacepath hold the workspace information.\r
-    /// \r
-    private String                workspacePath;\r
-    ///\r
-    /// FPD file is the root file. \r
-    /// \r
-    private String                fpdFilePath;\r
-    ///\r
-    /// Message level for CollectPCDAction.\r
-    /// \r
-    private int                   originalMessageLevel;\r
-    ///\r
-    /// Cache the fpd docment instance for private usage.\r
-    /// \r
-    private PlatformSurfaceAreaDocument fpdDocInstance;\r
-    ///\r
-    /// xmlObject name\r
-    /// \r
-    private static String xmlObjectName = "PcdBuildDefinition"; \r
-       \r
-    /**\r
-      Set WorkspacePath parameter for this action class.\r
-\r
-      @param workspacePath parameter for this action\r
-    **/\r
-    public void setWorkspacePath(String workspacePath) {\r
-        this.workspacePath = workspacePath;\r
-    }\r
-\r
-    /**\r
-      Set action message level for CollectPcdAction tool.\r
-\r
-      The message should be restored when this action exit.\r
-\r
-      @param actionMessageLevel parameter for this action\r
-    **/\r
-    public void setActionMessageLevel(int actionMessageLevel) {\r
-        originalMessageLevel       = ActionMessage.messageLevel;\r
-        ActionMessage.messageLevel = actionMessageLevel;\r
-    }\r
-\r
-    /**\r
-      Set FPDFileName parameter for this action class.\r
-\r
-      @param fpdFilePath    fpd file path\r
-    **/\r
-    public void setFPDFilePath(String fpdFilePath) {\r
-        this.fpdFilePath = fpdFilePath;\r
-    }\r
-\r
-    /**\r
-      Common function interface for outer.\r
-      \r
-      @param workspacePath The path of workspace of current build or analysis.\r
-      @param fpdFilePath   The fpd file path of current build or analysis.\r
-      @param messageLevel  The message level for this Action.\r
-      \r
-      @throws  Exception The exception of this function. Because it can *not* be predict\r
-                         where the action class will be used. So only Exception can be throw.\r
-      \r
-    **/\r
-    public void perform(String workspacePath, String fpdFilePath, \r
-                        int messageLevel) throws Exception {\r
-        setWorkspacePath(workspacePath);\r
-        setFPDFilePath(fpdFilePath);\r
-        setActionMessageLevel(messageLevel);\r
-        checkParameter();\r
-        execute();\r
-        ActionMessage.messageLevel = originalMessageLevel;\r
-    }\r
-\r
-    /**\r
-      Core execution function for this action class.\r
-     \r
-      This function work flows will be:\r
-      1) Collect and prepocess PCD information from FPD file, all PCD\r
-      information will be stored into memory database.\r
-      2) Generate 3 strings for\r
-        a) All modules using Dynamic(Ex) PCD entry.(Token Number)\r
-        b) PEI PCDDatabase (C Structure) for PCD Service PEIM.\r
-        c) DXE PCD Database (C structure) for PCD Service DXE.\r
-                                \r
-      \r
-      @throws  EntityException Exception indicate failed to execute this action.\r
-      \r
-    **/\r
-    public void execute() throws EntityException {\r
-        //\r
-        // Get memoryDatabaseManager instance from GlobalData.\r
-        // The memoryDatabaseManager should be initialized for whatever build\r
-        // tools or wizard tools\r
-        //\r
-        if((dbManager = GlobalData.getPCDMemoryDBManager()) == null) {\r
-            throw new EntityException("The instance of PCD memory database manager is null");\r
-        }\r
-\r
-        //\r
-        // Collect all PCD information defined in FPD file.\r
-        // Evenry token defind in FPD will be created as an token into \r
-        // memory database.\r
-        //\r
-        createTokenInDBFromFPD();\r
-        \r
-        //\r
-        // Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
-        //\r
-        genPcdDatabaseSourceCode ();\r
-        \r
-    }\r
-\r
-    /**\r
-      This function generates source code for PCD Database.\r
-     \r
-      @param void\r
-      @throws EntityException  If the token does *not* exist in memory database.\r
-\r
-    **/\r
-    private void genPcdDatabaseSourceCode()\r
-        throws EntityException {\r
-        String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions();\r
-\r
-        ArrayList<Token> alPei = new ArrayList<Token> ();\r
-        ArrayList<Token> alDxe = new ArrayList<Token> ();\r
-\r
-        dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
-        PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
-        pcdPeiDatabase.genCode();\r
-        MemoryDatabaseManager.PcdPeimHString        = PcdCommonHeaderString + pcdPeiDatabase.getHString() + \r
-                                                      PcdDatabase.getPcdPeiDatabaseDefinitions();\r
-        MemoryDatabaseManager.PcdPeimCString        = pcdPeiDatabase.getCString();\r
-\r
-        PcdDatabase pcdDxeDatabase = new PcdDatabase(alDxe, "DXE", alPei.size());\r
-        pcdDxeDatabase.genCode();\r
-        MemoryDatabaseManager.PcdDxeHString   = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() + \r
-                                                PcdDatabase.getPcdDxeDatabaseDefinitions();\r
-        MemoryDatabaseManager.PcdDxeCString   = pcdDxeDatabase.getCString();\r
-    }\r
-\r
-    /**\r
-      Get component array from FPD.\r
-      \r
-      This function maybe provided by some Global class.\r
-      \r
-      @return List<ModuleInfo> the component array.\r
-      \r
-     */\r
-    private List<ModuleInfo> getComponentsFromFPD() \r
-        throws EntityException {\r
-        List<ModuleInfo>                            allModules          = new ArrayList<ModuleInfo>();\r
-        FrameworkModulesDocument.FrameworkModules   fModules            = null;\r
-        ModuleSADocument.ModuleSA[]                 modules             = null;\r
-        Map<FpdModuleIdentification, XmlObject>     pcdBuildDefinitions = null;\r
-\r
-        pcdBuildDefinitions = GlobalData.getFpdPcdBuildDefinitions();\r
-        if (pcdBuildDefinitions == null) {\r
-            return null;\r
-        }\r
-\r
-        //\r
-        // Loop map to retrieve all PCD build definition and Module id \r
-        // \r
-        Iterator item = pcdBuildDefinitions.keySet().iterator();\r
-        while (item.hasNext()){\r
-            FpdModuleIdentification id = (FpdModuleIdentification) item.next();\r
-            allModules.add(new ModuleInfo(id, pcdBuildDefinitions.get(id)));    \r
-        }\r
-        \r
-        return allModules;\r
-    }\r
-\r
-    /**\r
-      Create token instance object into memory database, the token information\r
-      comes for FPD file. Normally, FPD file will contain all token platform \r
-      informations.\r
-      \r
-      @return FrameworkPlatformDescriptionDocument   The FPD document instance for furture usage.\r
-      \r
-      @throws EntityException                        Failed to parse FPD xml file.\r
-      \r
-    **/\r
-    private void createTokenInDBFromFPD() \r
-        throws EntityException {\r
-        int                                 index             = 0;\r
-        int                                 index2            = 0;\r
-        int                                 pcdIndex          = 0;\r
-        List<PcdBuildDefinition.PcdData>    pcdBuildDataArray = new ArrayList<PcdBuildDefinition.PcdData>();\r
-        PcdBuildDefinition.PcdData          pcdBuildData      = null;\r
-        Token                               token             = null;\r
-        List<ModuleInfo>                    modules           = null;\r
-        String                              primaryKey        = null;\r
-        String                              exceptionString   = null;\r
-        UsageInstance                       usageInstance     = null;\r
-        String                              primaryKey1       = null;\r
-        String                              primaryKey2       = null;\r
-        boolean                             isDuplicate       = false;\r
-        Token.PCD_TYPE                      pcdType           = Token.PCD_TYPE.UNKNOWN;\r
-        Token.DATUM_TYPE                    datumType         = Token.DATUM_TYPE.UNKNOWN;\r
-        long                                tokenNumber       = 0;\r
-        String                              moduleName        = null;\r
-        String                              datum             = null;\r
-        int                                 maxDatumSize      = 0;\r
-        String[]                            tokenSpaceStrRet  = null;\r
-        UsageIdentification                 usageId           = null;\r
-        ModuleIdentification                moduleId          = null;\r
-\r
-        //\r
-        // ----------------------------------------------\r
-        // 1), Get all <ModuleSA> from FPD file.\r
-        // ----------------------------------------------\r
-        // \r
-        modules = getComponentsFromFPD();\r
-\r
-        if (modules == null) {\r
-            throw new EntityException("[FPD file error] No modules in FPD file, Please check whether there are elements in <FrameworkModules> in FPD file!");\r
-        }\r
-\r
-        //\r
-        // -------------------------------------------------------------------\r
-        // 2), Loop all modules to process <PcdBuildDeclarations> for each module.\r
-        // -------------------------------------------------------------------\r
-        // \r
-        for (index = 0; index < modules.size(); index ++) {\r
-           //\r
-           // It is legal for a module does not contains ANY pcd build definitions.\r
-           // \r
-           if (modules.get(index).getPcdBuildDef() == null) {\r
-                continue;\r
-           }\r
-    \r
-            pcdBuildDataArray = modules.get(index).getPcdBuildDef().getPcdDataList();\r
-\r
-            moduleName = modules.get(index).getModuleId().getModule().getName();\r
-\r
-            //\r
-            // ----------------------------------------------------------------------\r
-            // 2.1), Loop all Pcd entry for a module and add it into memory database.\r
-            // ----------------------------------------------------------------------\r
-            // \r
-            for (pcdIndex = 0; pcdIndex < pcdBuildDataArray.size(); pcdIndex ++) {\r
-                pcdBuildData = pcdBuildDataArray.get(pcdIndex);\r
-                \r
-                try {\r
-                    tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(pcdBuildData.getTokenSpaceGuidCName());\r
-                } catch ( Exception e ) {\r
-                    throw new EntityException ("Faile get Guid for token " + pcdBuildData.getCName() + ":" + e.getMessage());\r
-                }\r
-\r
-                if (tokenSpaceStrRet == null) {\r
-                    throw new EntityException ("Fail to get Token space guid for token" + pcdBuildData.getCName());\r
-                } \r
-\r
-                primaryKey   = Token.getPrimaryKeyString(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
-                pcdType      = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
-                datumType    = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
-                tokenNumber  = Long.decode(pcdBuildData.getToken().toString());\r
-                if (pcdBuildData.getValue() != null) {\r
-                    datum = pcdBuildData.getValue().toString();\r
-                } else {\r
-                    datum = null;\r
-                }\r
-                maxDatumSize = pcdBuildData.getMaxDatumSize();\r
-\r
-                if ((pcdType    == Token.PCD_TYPE.FEATURE_FLAG) &&\r
-                    (datumType  != Token.DATUM_TYPE.BOOLEAN)){\r
-                    exceptionString = String.format("[FPD file error] For PCD %s in module %s, the PCD type is FEATRUE_FLAG but "+\r
-                                                    "datum type of this PCD entry is not BOOLEAN!",\r
-                                                    pcdBuildData.getCName(),\r
-                                                    moduleName);\r
-                    throw new EntityException(exceptionString);\r
-                }\r
-\r
-                //\r
-                // -------------------------------------------------------------------------------------------\r
-                // 2.1.1), Do some necessary checking work for FixedAtBuild, FeatureFlag and PatchableInModule\r
-                // -------------------------------------------------------------------------------------------\r
-                // \r
-                if (!Token.isDynamic(pcdType)) {\r
-                     //\r
-                     // Value is required.\r
-                     // \r
-                     if (datum == null) {\r
-                         exceptionString = String.format("[FPD file error] There is no value for PCD entry %s in module %s!",\r
-                                                         pcdBuildData.getCName(),\r
-                                                         moduleName);\r
-                         throw new EntityException(exceptionString);\r
-                     }\r
-\r
-                     //\r
-                     // Check whether the datum size is matched datum type.\r
-                     // \r
-                     if ((exceptionString = verifyDatum(pcdBuildData.getCName(), \r
-                                                        moduleName,\r
-                                                        datum,\r
-                                                        datumType,\r
-                                                        maxDatumSize)) != null) {\r
-                         throw new EntityException(exceptionString);\r
-                     }\r
-                }\r
-\r
-                //\r
-                // ---------------------------------------------------------------------------------\r
-                // 2.1.2), Create token or update token information for current anaylized PCD data.\r
-                // ---------------------------------------------------------------------------------\r
-                // \r
-                if (dbManager.isTokenInDatabase(primaryKey)) {\r
-                    //\r
-                    // If the token is already exist in database, do some necessary checking\r
-                    // and add a usage instance into this token in database\r
-                    // \r
-                    token = dbManager.getTokenByKey(primaryKey);\r
-    \r
-                    //\r
-                    // checking for DatumType, DatumType should be unique for one PCD used in different\r
-                    // modules.\r
-                    // \r
-                    if (token.datumType != datumType) {\r
-                        exceptionString = String.format("[FPD file error] The datum type of PCD entry %s is %s, which is different with  %s defined in before!",\r
-                                                        pcdBuildData.getCName(), \r
-                                                        pcdBuildData.getDatumType().toString(), \r
-                                                        Token.getStringOfdatumType(token.datumType));\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-\r
-                    //\r
-                    // Check token number is valid\r
-                    // \r
-                    if (tokenNumber != token.tokenNumber) {\r
-                        exceptionString = String.format("[FPD file error] The token number of PCD entry %s in module %s is different with same PCD entry in other modules!",\r
-                                                        pcdBuildData.getCName(),\r
-                                                        moduleName);\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-\r
-                    //\r
-                    // For same PCD used in different modules, the PCD type should all be dynamic or non-dynamic.\r
-                    // \r
-                    if (token.isDynamicPCD != Token.isDynamic(pcdType)) {\r
-                        exceptionString = String.format("[FPD file error] For PCD entry %s in module %s, you define dynamic or non-dynamic PCD type which"+\r
-                                                        "is different with others module's",\r
-                                                        token.cName,\r
-                                                        moduleName);\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-\r
-                    if (token.isDynamicPCD) {\r
-                        //\r
-                        // Check datum is equal the datum in dynamic information.\r
-                        // For dynamic PCD, you can do not write <Value> in sperated every <PcdBuildDefinition> in different <ModuleSA>,\r
-                        // But if you write, the <Value> must be same as the value in <DynamicPcdBuildDefinitions>.\r
-                        // \r
-                        if (!token.isSkuEnable() && \r
-                            (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.DEFAULT_TYPE) &&\r
-                            (datum != null)) {\r
-                            if (!datum.equalsIgnoreCase(token.getDefaultSku().value)) {\r
-                                exceptionString = String.format("[FPD file error] For dynamic PCD %s in module %s, the datum in <ModuleSA> is "+\r
-                                                                "not equal to the datum in <DynamicPcdBuildDefinitions>, it is "+\r
-                                                                "illega! You could no set <Value> in <ModuleSA> for a dynamic PCD!",\r
-                                                                token.cName,\r
-                                                                moduleName);\r
-                                throw new EntityException(exceptionString);\r
-                            }\r
-                        }\r
-\r
-                        if ((maxDatumSize != 0) &&\r
-                            (maxDatumSize != token.datumSize)){\r
-                            exceptionString = String.format("[FPD file error] For dynamic PCD %s in module %s, the max datum size is %d which "+\r
-                                                            "is different with <MaxDatumSize> %d defined in <DynamicPcdBuildDefinitions>!",\r
-                                                            token.cName,\r
-                                                            moduleName,\r
-                                                            maxDatumSize,\r
-                                                            token.datumSize);\r
-                            throw new EntityException(exceptionString);\r
-                        }\r
-                    }\r
-                    \r
-                } else {\r
-                    //\r
-                    // If the token is not in database, create a new token instance and add\r
-                    // a usage instance into this token in database.\r
-                    // \r
-                    try {\r
-                        tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(pcdBuildData.getTokenSpaceGuidCName());\r
-                    } catch (Exception e) {\r
-                        throw new EntityException("Fail to get token space guid for token " + token.cName);\r
-                    }\r
-\r
-                    if (tokenSpaceStrRet == null) {\r
-                        throw new EntityException("Fail to get token space guid for token " + token.cName);\r
-                    }\r
-\r
-                    token = new Token(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
-    \r
-                    token.datumType     = datumType;\r
-                    token.tokenNumber   = tokenNumber;\r
-                    token.isDynamicPCD  = Token.isDynamic(pcdType);\r
-                    token.datumSize     = maxDatumSize;\r
-                    \r
-                    if (token.isDynamicPCD) {\r
-                        //\r
-                        // For Dynamic and Dynamic Ex type, need find the dynamic information\r
-                        // in <DynamicPcdBuildDefinition> section in FPD file.\r
-                        // \r
-                        updateDynamicInformation(moduleName, \r
-                                                 token,\r
-                                                 datum,\r
-                                                 maxDatumSize);\r
-                    }\r
-    \r
-                    dbManager.addTokenToDatabase(primaryKey, token);\r
-                }\r
-\r
-                //\r
-                // -----------------------------------------------------------------------------------\r
-                // 2.1.3), Add the PcdType in current module into this Pcd token's supported PCD type.\r
-                // -----------------------------------------------------------------------------------\r
-                // \r
-                token.updateSupportPcdType(pcdType);\r
-\r
-                //\r
-                // ------------------------------------------------\r
-                // 2.1.4), Create an usage instance for this token.\r
-                // ------------------------------------------------\r
-                // \r
-                moduleId = modules.get(index).getModuleId().getModule();\r
-                usageId = new UsageIdentification (moduleId.getName(), \r
-                                                   moduleId.getGuid(), \r
-                                                   moduleId.getPackage().getName(), \r
-                                                   moduleId.getPackage().getGuid(), \r
-                                                   modules.get(index).getModuleId().getArch(),\r
-                                                   moduleId.getVersion(),\r
-                                                   moduleId.getModuleType());\r
-                usageInstance = new UsageInstance(token, \r
-                                                  usageId,\r
-                                                  pcdType,\r
-                                                  datum,\r
-                                                  maxDatumSize);\r
-                token.addUsageInstance(usageInstance);\r
-            }\r
-        }\r
-\r
-        //\r
-        // ------------------------------------------------\r
-        // 3), Add unreference dynamic_Ex pcd token into Pcd database.\r
-        // ------------------------------------------------\r
-        // \r
-        List<Token> tokenArray = getUnreferencedDynamicPcd();\r
-        if (tokenArray != null) {\r
-            for (index = 0; index < tokenArray.size(); index ++) {\r
-                dbManager.addTokenToDatabase(tokenArray.get(index).getPrimaryKeyString(), \r
-                                             tokenArray.get(index));\r
-            }\r
-        }\r
-    }\r
-\r
-    private List<Token> getUnreferencedDynamicPcd () throws EntityException {\r
-        List<Token>                                   tokenArray                 = new ArrayList<Token>();\r
-        Token                                         token                      = null;\r
-        DynamicPcdBuildDefinitions                    dynamicPcdBuildDefinitions = null;\r
-        List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray   = null;\r
-        DynamicPcdBuildDefinitions.PcdBuildData       pcdBuildData               = null;\r
-        List<DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo>   skuInfoList      = null;\r
-        Token.PCD_TYPE                                pcdType;\r
-        SkuInstance                                   skuInstance                = null;\r
-        String  primaryKey = null;\r
-        boolean hasSkuId0  = false;\r
-        int     index, offset, index2;\r
-        String  temp;\r
-        String  exceptionString;\r
-        String  hiiDefaultValue;\r
-        String  tokenSpaceStrRet[];\r
-        String  variableGuidString[];\r
-\r
-        //\r
-        // Open fpd document to get <DynamicPcdBuildDefinition> Section.\r
-        // BUGBUG: the function should be move GlobalData in furture.\r
-        // \r
-        if (fpdDocInstance == null) {\r
-            try {\r
-                fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
-            } catch(IOException ioE) {\r
-                throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
-            } catch(XmlException xmlE) {\r
-                throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
-            }\r
-        }\r
-\r
-        dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
-        if (dynamicPcdBuildDefinitions == null) {\r
-            return null;\r
-        }\r
-\r
-        dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
-        for (index2 = 0; index2 < dynamicPcdBuildDataArray.size(); index2 ++) {\r
-            pcdBuildData = dynamicPcdBuildDataArray.get(index2);\r
-            try {\r
-                tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(pcdBuildData.getTokenSpaceGuidCName());\r
-            } catch ( Exception e ) {\r
-                throw new EntityException ("Faile get Guid for token " + pcdBuildData.getCName() + ":" + e.getMessage());\r
-            }\r
-\r
-            if (tokenSpaceStrRet == null) {\r
-                throw new EntityException ("Fail to get Token space guid for token" + pcdBuildData.getCName());\r
-            } \r
-\r
-            primaryKey = Token.getPrimaryKeyString(pcdBuildData.getCName(),\r
-                                                   tokenSpaceStrRet[1]);\r
-\r
-            if (dbManager.isTokenInDatabase(primaryKey)) {\r
-                continue;\r
-            }\r
-\r
-            pcdType = Token.getpcdTypeFromString(pcdBuildData.getItemType().toString());\r
-            if (pcdType != Token.PCD_TYPE.DYNAMIC_EX) {\r
-                throw new EntityException (String.format("[FPD file error] It not allowed for DYNAMIC PCD %s who is no used by any module",\r
-                                                         pcdBuildData.getCName()));\r
-            }\r
-\r
-            //\r
-            // Create new token for unreference dynamic PCD token\r
-            // \r
-            token           = new Token(pcdBuildData.getCName(), tokenSpaceStrRet[1]);\r
-            token.datumSize = pcdBuildData.getMaxDatumSize();\r
-            \r
-\r
-            token.datumType     = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
-            token.tokenNumber   = Long.decode(pcdBuildData.getToken().toString());\r
-            token.dynamicExTokenNumber = token.tokenNumber;\r
-            token.isDynamicPCD  = true; \r
-            token.updateSupportPcdType(pcdType);\r
-\r
-            exceptionString = verifyDatum(token.cName, \r
-                                          null,\r
-                                          null, \r
-                                          token.datumType, \r
-                                          token.datumSize);\r
-            if (exceptionString != null) {\r
-                throw new EntityException(exceptionString);\r
-            }\r
-\r
-            skuInfoList = pcdBuildData.getSkuInfoList();\r
-\r
-            //\r
-            // Loop all sku data \r
-            // \r
-            for (index = 0; index < skuInfoList.size(); index ++) {\r
-                skuInstance = new SkuInstance();\r
-                //\r
-                // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.\r
-                // \r
-                temp = skuInfoList.get(index).getSkuId().toString();\r
-                skuInstance.id = Integer.decode(temp);\r
-                if (skuInstance.id == 0) {\r
-                    hasSkuId0 = true;\r
-                }\r
-                //\r
-                // Judge whether is DefaultGroup at first, because most case is DefautlGroup.\r
-                // \r
-                if (skuInfoList.get(index).getValue() != null) {\r
-                    skuInstance.value.setValue(skuInfoList.get(index).getValue().toString());\r
-                    if ((exceptionString = verifyDatum(token.cName, \r
-                                                       null, \r
-                                                       skuInfoList.get(index).getValue().toString(), \r
-                                                       token.datumType, \r
-                                                       token.datumSize)) != null) {\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-\r
-                    token.skuData.add(skuInstance);\r
-\r
-                    continue;\r
-                }\r
-\r
-                //\r
-                // Judge whether is HII group case.\r
-                // \r
-                if (skuInfoList.get(index).getVariableName() != null) {\r
-                    exceptionString = null;\r
-                    if (skuInfoList.get(index).getVariableGuid() == null) {\r
-                        exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
-                                                        "file, who use HII, but there is no <VariableGuid> defined for Sku %d data!",\r
-                                                        token.cName,\r
-                                                        index);\r
-                        if (exceptionString != null) {\r
-                            throw new EntityException(exceptionString);\r
-                        }                                                    \r
-                    }\r
-\r
-                    if (skuInfoList.get(index).getVariableOffset() == null) {\r
-                        exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
-                                                        "file, who use HII, but there is no <VariableOffset> defined for Sku %d data!",\r
-                                                        token.cName,\r
-                                                        index);\r
-                        if (exceptionString != null) {\r
-                            throw new EntityException(exceptionString);\r
-                        }\r
-                    }\r
-\r
-                    if (skuInfoList.get(index).getHiiDefaultValue() == null) {\r
-                        exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
-                                                        "file, who use HII, but there is no <HiiDefaultValue> defined for Sku %d data!",\r
-                                                        token.cName,\r
-                                                        index);\r
-                        if (exceptionString != null) {\r
-                            throw new EntityException(exceptionString);\r
-                        }\r
-                    }\r
-\r
-                    if (skuInfoList.get(index).getHiiDefaultValue() != null) {\r
-                        hiiDefaultValue = skuInfoList.get(index).getHiiDefaultValue().toString();\r
-                    } else {\r
-                        hiiDefaultValue = null;\r
-                    }\r
-\r
-                    if ((exceptionString = verifyDatum(token.cName, \r
-                                                       null, \r
-                                                       hiiDefaultValue, \r
-                                                       token.datumType, \r
-                                                       token.datumSize)) != null) {\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-\r
-                    offset = Integer.decode(skuInfoList.get(index).getVariableOffset());\r
-                    if (offset > 0xFFFF) {\r
-                        throw new EntityException(String.format("[FPD file error] For dynamic PCD %s ,  the variable offset defined in sku %d data "+\r
-                                                                "exceed 64K, it is not allowed!",\r
-                                                                token.cName,\r
-                                                                index));\r
-                    }\r
-\r
-                    //\r
-                    // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file.\r
-                    // \r
-                    variableGuidString = GlobalData.getGuidInfoFromCname(skuInfoList.get(index).getVariableGuid().toString());\r
-                    if (variableGuidString == null) {\r
-                        throw new EntityException(String.format("[GUID Error] For dynamic PCD %s,  the variable guid %s can be found in all SPD file!",\r
-                                                                token.cName, \r
-                                                                skuInfoList.get(index).getVariableGuid().toString()));\r
-                    }\r
-                    String variableStr = skuInfoList.get(index).getVariableName();\r
-                    Pattern pattern = Pattern.compile("0x([a-fA-F0-9]){4}");\r
-                    Matcher matcher = pattern.matcher(variableStr);\r
-                    List<String> varNameList = new ArrayList<String>();\r
-                    while (matcher.find()){\r
-                            String str = variableStr.substring(matcher.start(),matcher.end());\r
-                            varNameList.add(str);\r
-                    }\r
-\r
-                    skuInstance.value.setHiiData(varNameList,\r
-                                                 translateSchemaStringToUUID(variableGuidString[1]),\r
-                                                 skuInfoList.get(index).getVariableOffset(),\r
-                                                 skuInfoList.get(index).getHiiDefaultValue().toString());\r
-                    token.skuData.add(skuInstance);\r
-                    continue;\r
-                }\r
-\r
-                if (skuInfoList.get(index).getVpdOffset() != null) {\r
-                    skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset());\r
-                    token.skuData.add(skuInstance);\r
-                    continue;\r
-                }\r
-\r
-                exceptionString = String.format("[FPD file error] For dynamic PCD %s, the dynamic info must "+\r
-                                                "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",\r
-                                                token.cName);\r
-                throw new EntityException(exceptionString);\r
-            }\r
-\r
-            if (!hasSkuId0) {\r
-                exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions>, there are "+\r
-                                                "no sku id = 0 data, which is required for every dynamic PCD",\r
-                                                token.cName);\r
-                throw new EntityException(exceptionString);\r
-            }\r
-\r
-            tokenArray.add(token);\r
-        }\r
-\r
-        return tokenArray;\r
-    }\r
-\r
-    /**\r
-       Verify the datum value according its datum size and datum type, this\r
-       function maybe moved to FPD verification tools in future.\r
-       \r
-       @param cName\r
-       @param moduleName\r
-       @param datum\r
-       @param datumType\r
-       @param maxDatumSize\r
-       \r
-       @return String\r
-     */\r
-    /***/\r
-    public String verifyDatum(String            cName,\r
-                              String            moduleName,\r
-                              String            datum, \r
-                              Token.DATUM_TYPE  datumType, \r
-                              int               maxDatumSize) {\r
-        String      exceptionString = null;\r
-        int         value;\r
-        BigInteger  value64;\r
-        String      subStr;\r
-        int         index;\r
-\r
-        if (moduleName == null) {\r
-            moduleName = "section <DynamicPcdBuildDefinitions>";\r
-        } else {\r
-            moduleName = "module " + moduleName;\r
-        }\r
-\r
-        if (maxDatumSize == 0) {\r
-            exceptionString = String.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in %s",\r
-                                            cName,\r
-                                            moduleName);\r
-            return exceptionString;\r
-        }\r
-\r
-        switch (datumType) {\r
-        case UINT8:\r
-            if (maxDatumSize != 1) {\r
-                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
-                                                "is UINT8, but datum size is %d, they are not matched!",\r
-                                                 cName,\r
-                                                 moduleName,\r
-                                                 maxDatumSize);\r
-                return exceptionString;\r
-            }\r
-\r
-            if (datum != null) {\r
-                try {\r
-                    value = Integer.decode(datum);\r
-                } catch (NumberFormatException nfeExp) {\r
-                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid "+\r
-                                                    "digital format of UINT8",\r
-                                                    cName,\r
-                                                    moduleName);\r
-                    return exceptionString;\r
-                }\r
-                if (value > 0xFF) {\r
-                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s exceed"+\r
-                                                    " the max size of UINT8 - 0xFF",\r
-                                                    cName, \r
-                                                    moduleName,\r
-                                                    datum);\r
-                    return exceptionString;\r
-                }\r
-            }\r
-            break;\r
-        case UINT16:\r
-            if (maxDatumSize != 2) {\r
-                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
-                                                "is UINT16, but datum size is %d, they are not matched!",\r
-                                                 cName,\r
-                                                 moduleName,\r
-                                                 maxDatumSize);\r
-                return exceptionString;\r
-            }\r
-            if (datum != null) {\r
-                try {\r
-                    value = Integer.decode(datum);\r
-                } catch (NumberFormatException nfeExp) {\r
-                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is "+\r
-                                                    "not valid digital of UINT16",\r
-                                                    cName,\r
-                                                    moduleName);\r
-                    return exceptionString;\r
-                }\r
-                if (value > 0xFFFF) {\r
-                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
-                                                    "which exceed the range of UINT16 - 0xFFFF",\r
-                                                    cName, \r
-                                                    moduleName,\r
-                                                    datum);\r
-                    return exceptionString;\r
-                }\r
-            }\r
-            break;\r
-        case UINT32:\r
-            if (maxDatumSize != 4) {\r
-                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
-                                                "is UINT32, but datum size is %d, they are not matched!",\r
-                                                 cName,\r
-                                                 moduleName,\r
-                                                 maxDatumSize);\r
-                return exceptionString;\r
-            }\r
-\r
-            if (datum != null) {\r
-                try {\r
-                    if (datum.length() > 2) {\r
-                        if ((datum.charAt(0) == '0')        && \r
-                            ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
-                            subStr = datum.substring(2, datum.length());\r
-                            value64 = new BigInteger(subStr, 16);\r
-                        } else {\r
-                            value64 = new BigInteger(datum);\r
-                        }\r
-                    } else {\r
-                        value64 = new BigInteger(datum);\r
-                    }\r
-                } catch (NumberFormatException nfeExp) {\r
-                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not "+\r
-                                                    "valid digital of UINT32",\r
-                                                    cName,\r
-                                                    moduleName);\r
-                    return exceptionString;\r
-                }\r
-\r
-                if (value64.bitLength() > 32) {\r
-                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s which "+\r
-                                                    "exceed the range of UINT32 - 0xFFFFFFFF",\r
-                                                    cName, \r
-                                                    moduleName,\r
-                                                    datum);\r
-                    return exceptionString;\r
-                }\r
-            }\r
-            break;\r
-        case UINT64:\r
-            if (maxDatumSize != 8) {\r
-                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
-                                                "is UINT64, but datum size is %d, they are not matched!",\r
-                                                 cName,\r
-                                                 moduleName,\r
-                                                 maxDatumSize);\r
-                return exceptionString;\r
-            }\r
-\r
-            if (datum != null) {\r
-                try {\r
-                    if (datum.length() > 2) {\r
-                        if ((datum.charAt(0) == '0')        && \r
-                            ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
-                            subStr = datum.substring(2, datum.length());\r
-                            value64 = new BigInteger(subStr, 16);\r
-                        } else {\r
-                            value64 = new BigInteger(datum);\r
-                        }\r
-                    } else {\r
-                        value64 = new BigInteger(datum);\r
-                    }\r
-                } catch (NumberFormatException nfeExp) {\r
-                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid"+\r
-                                                    " digital of UINT64",\r
-                                                    cName,\r
-                                                    moduleName);\r
-                    return exceptionString;\r
-                }\r
-\r
-                if (value64.bitLength() > 64) {\r
-                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
-                                                    "exceed the range of UINT64 - 0xFFFFFFFFFFFFFFFF",\r
-                                                    cName, \r
-                                                    moduleName,\r
-                                                    datum);\r
-                    return exceptionString;\r
-                }\r
-            }\r
-            break;\r
-        case BOOLEAN:\r
-            if (maxDatumSize != 1) {\r
-                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
-                                                "is BOOLEAN, but datum size is %d, they are not matched!",\r
-                                                 cName,\r
-                                                 moduleName,\r
-                                                 maxDatumSize);\r
-                return exceptionString;\r
-            }\r
-\r
-            if (datum != null) {\r
-                if (!(datum.equalsIgnoreCase("TRUE") ||\r
-                     datum.equalsIgnoreCase("FALSE"))) {\r
-                    exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
-                                                    "is BOOELAN, but value is not 'true'/'TRUE' or 'FALSE'/'false'",\r
-                                                    cName,\r
-                                                    moduleName);\r
-                    return exceptionString;\r
-                }\r
-\r
-            }\r
-            break;\r
-        case POINTER:\r
-            if (datum == null) {\r
-                break;\r
-            }\r
-\r
-            char    ch     = datum.charAt(0);\r
-            int     start, end;\r
-            String  strValue;\r
-            //\r
-            // For void* type PCD, only three datum is support:\r
-            // 1) Unicode: string with start char is "L"\r
-            // 2) Ansci: String start char is ""\r
-            // 3) byte array: String start char "{"\r
-            // \r
-            if (ch == 'L') {\r
-                start       = datum.indexOf('\"');\r
-                end         = datum.lastIndexOf('\"');\r
-                if ((start > end)           || \r
-                    (end   > datum.length())||\r
-                    ((start == end) && (datum.length() > 0))) {\r
-                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+\r
-                                                    "a UNICODE string because start with L\", but format maybe"+\r
-                                                    "is not right, correct UNICODE string is L\"...\"!",\r
-                                                    cName,\r
-                                                    moduleName);\r
-                    return exceptionString;\r
-                }\r
-\r
-                strValue    = datum.substring(start + 1, end);\r
-                if ((strValue.length() * 2) > maxDatumSize) {\r
-                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+\r
-                                                    "a UNICODE string, but the datum size is %d exceed to <MaxDatumSize> : %d",\r
-                                                    cName,\r
-                                                    moduleName,\r
-                                                    strValue.length() * 2, \r
-                                                    maxDatumSize);\r
-                    return exceptionString;\r
-                }\r
-            } else if (ch == '\"'){\r
-                start       = datum.indexOf('\"');\r
-                end         = datum.lastIndexOf('\"');\r
-                if ((start > end)           || \r
-                    (end   > datum.length())||\r
-                    ((start == end) && (datum.length() > 0))) {\r
-                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+\r
-                                                    "a ANSCII string because start with \", but format maybe"+\r
-                                                    "is not right, correct ANSIC string is \"...\"!",\r
-                                                    cName,\r
-                                                    moduleName);\r
-                    return exceptionString;\r
-                }\r
-                strValue    = datum.substring(start + 1, end);\r
-                if ((strValue.length()) > maxDatumSize) {\r
-                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+\r
-                                                    "a ANSCI string, but the datum size is %d which exceed to <MaxDatumSize> : %d",\r
-                                                    cName,\r
-                                                    moduleName,\r
-                                                    strValue.length(),\r
-                                                    maxDatumSize);\r
-                    return exceptionString;\r
-                }\r
-            } else if (ch =='{') {\r
-                String[]  strValueArray;\r
-\r
-                start           = datum.indexOf('{');\r
-                end             = datum.lastIndexOf('}');\r
-                strValue        = datum.substring(start + 1, end);\r
-                strValue        = strValue.trim();\r
-                if (strValue.length() == 0) {\r
-                    exceptionString = String.format ("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
-                                                     "it is byte array in fact, but '{}' is not valid for NULL datam but"+\r
-                                                     " need use '{0}'",\r
-                                                     cName,\r
-                                                     moduleName);\r
-                    return exceptionString;\r
-                }\r
-                strValueArray   = strValue.split(",");\r
-                for (index = 0; index < strValueArray.length; index ++) {\r
-                    try{\r
-                        value = Integer.decode(strValueArray[index].trim());\r
-                    } catch (NumberFormatException nfeEx) {\r
-                        exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
-                                                         "it is byte array in fact. For every byte in array should be a valid"+\r
-                                                         "byte digital, but element %s is not a valid byte digital!",\r
-                                                         cName,\r
-                                                         moduleName,\r
-                                                         strValueArray[index]);\r
-                        return exceptionString;\r
-                    }\r
-                    if (value > 0xFF) {\r
-                        exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r
-                                                        "it is byte array in fact. But the element of %s exceed the byte range",\r
-                                                        cName,\r
-                                                        moduleName,\r
-                                                        strValueArray[index]);\r
-                        return exceptionString;\r
-                    }\r
-                }\r
-\r
-                if (strValueArray.length > maxDatumSize) {\r
-                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is byte"+\r
-                                                    "array, but the number of bytes is %d which exceed to <MaxDatumSzie> : %d!",\r
-                                                    cName,\r
-                                                    moduleName,\r
-                                                    strValueArray.length,\r
-                                                    maxDatumSize);\r
-                    return exceptionString;\r
-                }\r
-            } else {\r
-                exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r
-                                                "1) UNICODE string: like L\"xxxx\";\r\n"+\r
-                                                "2) ANSIC string: like \"xxx\";\r\n"+\r
-                                                "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r
-                                                "But the datum in seems does not following above format!",\r
-                                                cName, \r
-                                                moduleName);\r
-                return exceptionString;\r
-            }\r
-            break;\r
-        default:\r
-            exceptionString = String.format("[FPD file error] For PCD entry %s in %s, datum type is unknown, it should be one of "+\r
-                                            "UINT8, UINT16, UINT32, UINT64, VOID*, BOOLEAN",\r
-                                            cName,\r
-                                            moduleName);\r
-            return exceptionString;\r
-        }\r
-        return null;\r
-    }\r
-\r
-    /**\r
-       Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.\r
-       \r
-       This function should be implemented in GlobalData in future.\r
-       \r
-       @param token         The token instance which has hold module's PCD information\r
-       @param moduleName    The name of module who will use this Dynamic PCD.\r
-       \r
-       @return DynamicPcdBuildDefinitions.PcdBuildData\r
-     */\r
-    /***/\r
-    private DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFPD(Token     token,\r
-                                                                          String    moduleName)\r
-        throws EntityException {\r
-        int    index             = 0;\r
-        String exceptionString   = null;\r
-        String dynamicPrimaryKey = null;\r
-        DynamicPcdBuildDefinitions                    dynamicPcdBuildDefinitions = null;\r
-        List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray   = null;\r
-        String[]                                      tokenSpaceStrRet           = null;\r
-\r
-        //\r
-        // If FPD document is not be opened, open and initialize it.\r
-        // BUGBUG: The code should be moved into GlobalData in future.\r
-        // \r
-        if (fpdDocInstance == null) {\r
-            try {\r
-                fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
-            } catch(IOException ioE) {\r
-                throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
-            } catch(XmlException xmlE) {\r
-                throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
-            }\r
-        }\r
-        \r
-        dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
-        if (dynamicPcdBuildDefinitions == null) {\r
-            exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
-                                            "PCD entry %s in module %s!",\r
-                                            token.cName,\r
-                                            moduleName);\r
-            throw new EntityException(exceptionString);\r
-        }\r
-\r
-        dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
-        for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r
-            //String tokenSpaceGuidString = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName())[1];\r
-            String tokenSpaceGuidString = null;\r
-            try {\r
-                tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName());\r
-            } catch (Exception e) {\r
-                throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
-            }\r
-            \r
-            if (tokenSpaceStrRet == null) {\r
-                throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
-            }\r
-\r
-            dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
-                                                          tokenSpaceStrRet[1]);\r
-            if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
-                return dynamicPcdBuildDataArray.get(index);\r
-            }\r
-        }\r
-\r
-        return null;\r
-    }\r
-\r
-    /**\r
-       Update dynamic information for PCD entry.\r
-       \r
-       Dynamic information is retrieved from <PcdDynamicBuildDeclarations> in\r
-       FPD file.\r
-       \r
-       @param moduleName        The name of the module who use this PCD\r
-       @param token             The token instance\r
-       @param datum             The <datum> in module's PCD information\r
-       @param maxDatumSize      The <maxDatumSize> in module's PCD information\r
-       \r
-       @return Token\r
-     */\r
-    private Token updateDynamicInformation(String   moduleName, \r
-                                           Token    token,\r
-                                           String   datum,\r
-                                           int      maxDatumSize) \r
-        throws EntityException {\r
-        int                 index           = 0;\r
-        int                 offset;\r
-        String              exceptionString = null;\r
-        DynamicTokenValue   dynamicValue;\r
-        SkuInstance         skuInstance     = null;\r
-        String              temp;\r
-        boolean             hasSkuId0       = false;\r
-        Token.PCD_TYPE      pcdType         = Token.PCD_TYPE.UNKNOWN;\r
-        long                tokenNumber     = 0;\r
-        String              hiiDefaultValue = null;\r
-        String[]            variableGuidString = null;\r
-\r
-        List<DynamicPcdBuildDefinitions.PcdBuildData.SkuInfo>   skuInfoList = null;\r
-        DynamicPcdBuildDefinitions.PcdBuildData                 dynamicInfo = null;\r
-\r
-        dynamicInfo = getDynamicInfoFromFPD(token, moduleName);\r
-        if (dynamicInfo == null) {\r
-            exceptionString = String.format("[FPD file error] For Dynamic PCD %s used by module %s, "+\r
-                                            "there is no dynamic information in <DynamicPcdBuildDefinitions> "+\r
-                                            "in FPD file, but it is required!",\r
-                                            token.cName,\r
-                                            moduleName);\r
-            throw new EntityException(exceptionString);\r
-        }\r
-\r
-        token.datumSize = dynamicInfo.getMaxDatumSize();\r
-\r
-        exceptionString = verifyDatum(token.cName, \r
-                                      moduleName,\r
-                                      null, \r
-                                      token.datumType, \r
-                                      token.datumSize);\r
-        if (exceptionString != null) {\r
-            throw new EntityException(exceptionString);\r
-        }\r
-\r
-        if ((maxDatumSize != 0) && \r
-            (maxDatumSize != token.datumSize)) {\r
-            exceptionString = String.format("FPD file error] For dynamic PCD %s, the datum size in module %s is %d, but "+\r
-                                            "the datum size in <DynamicPcdBuildDefinitions> is %d, they are not match!",\r
-                                            token.cName,\r
-                                            moduleName, \r
-                                            maxDatumSize,\r
-                                            dynamicInfo.getMaxDatumSize());\r
-            throw new EntityException(exceptionString);\r
-        }\r
-        tokenNumber = Long.decode(dynamicInfo.getToken().toString());\r
-        if (tokenNumber != token.tokenNumber) {\r
-            exceptionString = String.format("[FPD file error] For dynamic PCD %s, the token number in module %s is 0x%x, but"+\r
-                                            "in <DynamicPcdBuildDefinictions>, the token number is 0x%x, they are not match!",\r
-                                            token.cName,\r
-                                            moduleName,\r
-                                            token.tokenNumber,\r
-                                            tokenNumber);\r
-            throw new EntityException(exceptionString);\r
-        }\r
-\r
-        pcdType = Token.getpcdTypeFromString(dynamicInfo.getItemType().toString());\r
-        token.dynamicExTokenNumber = tokenNumber;\r
-\r
-        skuInfoList = dynamicInfo.getSkuInfoList();\r
-\r
-        //\r
-        // Loop all sku data \r
-        // \r
-        for (index = 0; index < skuInfoList.size(); index ++) {\r
-            skuInstance = new SkuInstance();\r
-            //\r
-            // Although SkuId in schema is BigInteger, but in fact, sku id is 32 bit value.\r
-            // \r
-            temp = skuInfoList.get(index).getSkuId().toString();\r
-            skuInstance.id = Integer.decode(temp);\r
-            if (skuInstance.id == 0) {\r
-                hasSkuId0 = true;\r
-            }\r
-            //\r
-            // Judge whether is DefaultGroup at first, because most case is DefautlGroup.\r
-            // \r
-            if (skuInfoList.get(index).getValue() != null) {\r
-                skuInstance.value.setValue(skuInfoList.get(index).getValue().toString());\r
-                if ((exceptionString = verifyDatum(token.cName, \r
-                                                   null, \r
-                                                   skuInfoList.get(index).getValue().toString(), \r
-                                                   token.datumType, \r
-                                                   token.datumSize)) != null) {\r
-                    throw new EntityException(exceptionString);\r
-                }\r
-\r
-                token.skuData.add(skuInstance);\r
-\r
-                //\r
-                // Judege wether is same of datum between module's information\r
-                // and dynamic information.\r
-                // \r
-                if (datum != null) {\r
-                    if ((skuInstance.id == 0)                                   &&\r
-                        !datum.toString().equalsIgnoreCase(skuInfoList.get(index).getValue().toString())) {\r
-                        exceptionString = "[FPD file error] For dynamic PCD " + token.cName + ", the value in module " + moduleName + " is " + datum.toString() + " but the "+\r
-                                          "value of sku 0 data in <DynamicPcdBuildDefinition> is " + skuInstance.value.value + ". They are must be same!"+\r
-                                          " or you could not define value for a dynamic PCD in every <ModuleSA>!"; \r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-                }\r
-                continue;\r
-            }\r
-\r
-            //\r
-            // Judge whether is HII group case.\r
-            // \r
-            if (skuInfoList.get(index).getVariableName() != null) {\r
-                exceptionString = null;\r
-                if (skuInfoList.get(index).getVariableGuid() == null) {\r
-                    exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
-                                                    "file, who use HII, but there is no <VariableGuid> defined for Sku %d data!",\r
-                                                    token.cName,\r
-                                                    index);\r
-                    if (exceptionString != null) {\r
-                        throw new EntityException(exceptionString);\r
-                    }                                                    \r
-                }\r
-\r
-                if (skuInfoList.get(index).getVariableOffset() == null) {\r
-                    exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
-                                                    "file, who use HII, but there is no <VariableOffset> defined for Sku %d data!",\r
-                                                    token.cName,\r
-                                                    index);\r
-                    if (exceptionString != null) {\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-                }\r
-\r
-                if (skuInfoList.get(index).getHiiDefaultValue() == null) {\r
-                    exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions> section in FPD "+\r
-                                                    "file, who use HII, but there is no <HiiDefaultValue> defined for Sku %d data!",\r
-                                                    token.cName,\r
-                                                    index);\r
-                    if (exceptionString != null) {\r
-                        throw new EntityException(exceptionString);\r
-                    }\r
-                }\r
-\r
-                if (skuInfoList.get(index).getHiiDefaultValue() != null) {\r
-                    hiiDefaultValue = skuInfoList.get(index).getHiiDefaultValue().toString();\r
-                } else {\r
-                    hiiDefaultValue = null;\r
-                }\r
-\r
-                if ((exceptionString = verifyDatum(token.cName, \r
-                                                   null, \r
-                                                   hiiDefaultValue, \r
-                                                   token.datumType, \r
-                                                   token.datumSize)) != null) {\r
-                    throw new EntityException(exceptionString);\r
-                }\r
-\r
-                offset = Integer.decode(skuInfoList.get(index).getVariableOffset());\r
-                if (offset > 0xFFFF) {\r
-                    throw new EntityException(String.format("[FPD file error] For dynamic PCD %s ,  the variable offset defined in sku %d data "+\r
-                                                            "exceed 64K, it is not allowed!",\r
-                                                            token.cName,\r
-                                                            index));\r
-                }\r
-\r
-                //\r
-                // Get variable guid string according to the name of guid which will be mapped into a GUID in SPD file.\r
-                // \r
-                variableGuidString = GlobalData.getGuidInfoFromCname(skuInfoList.get(index).getVariableGuid().toString());\r
-                if (variableGuidString == null) {\r
-                    throw new EntityException(String.format("[GUID Error] For dynamic PCD %s,  the variable guid %s can be found in all SPD file!",\r
-                                                            token.cName, \r
-                                                            skuInfoList.get(index).getVariableGuid().toString()));\r
-                }\r
-                String variableStr = skuInfoList.get(index).getVariableName();\r
-                Pattern pattern = Pattern.compile("0x([a-fA-F0-9]){4}");\r
-                Matcher matcher = pattern.matcher(variableStr);\r
-                List<String> varNameList = new ArrayList<String>();\r
-                while (matcher.find()){\r
-                       String str = variableStr.substring(matcher.start(),matcher.end());\r
-                       varNameList.add(str);\r
-                }\r
-                \r
-                skuInstance.value.setHiiData(varNameList,\r
-                                             translateSchemaStringToUUID(variableGuidString[1]),\r
-                                             skuInfoList.get(index).getVariableOffset(),\r
-                                             skuInfoList.get(index).getHiiDefaultValue().toString());\r
-                token.skuData.add(skuInstance);\r
-                continue;\r
-            }\r
-\r
-            if (skuInfoList.get(index).getVpdOffset() != null) {\r
-                skuInstance.value.setVpdData(skuInfoList.get(index).getVpdOffset());\r
-                token.skuData.add(skuInstance);\r
-                continue;\r
-            }\r
-\r
-            exceptionString = String.format("[FPD file error] For dynamic PCD %s, the dynamic info must "+\r
-                                            "be one of 'DefaultGroup', 'HIIGroup', 'VpdGroup'.",\r
-                                            token.cName);\r
-            throw new EntityException(exceptionString);\r
-        }\r
-\r
-        if (!hasSkuId0) {\r
-            exceptionString = String.format("[FPD file error] For dynamic PCD %s in <DynamicPcdBuildDefinitions>, there are "+\r
-                                            "no sku id = 0 data, which is required for every dynamic PCD",\r
-                                            token.cName);\r
-            throw new EntityException(exceptionString);\r
-        }\r
-\r
-        return token;\r
-    }\r
-\r
-    /**\r
-       Translate the schema string to UUID instance.\r
-       \r
-       In schema, the string of UUID is defined as following two types string:\r
-        1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(\r
-        )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?\r
-       \r
-        2) GuidNamingConvention: pattern =\r
-        [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\r
-       \r
-       This function will convert string and create uuid instance.\r
-       \r
-       @param uuidString    UUID string in XML file\r
-       \r
-       @return UUID         UUID instance\r
-    **/\r
-    private UUID translateSchemaStringToUUID(String uuidString) \r
-        throws EntityException {\r
-        String      temp;\r
-        String[]    splitStringArray;\r
-        int         index;\r
-        int         chIndex;\r
-        int         chLen;\r
-\r
-        if (uuidString == null) {\r
-            return null;\r
-        }\r
-\r
-        if (uuidString.length() == 0) {\r
-            return null;\r
-        }\r
-\r
-        if (uuidString.equals("0") ||\r
-            uuidString.equalsIgnoreCase("0x0")) {\r
-            return new UUID(0, 0);\r
-        }\r
-\r
-        uuidString = uuidString.replaceAll("\\{", "");\r
-        uuidString = uuidString.replaceAll("\\}", "");\r
-\r
-        //\r
-        // If the UUID schema string is GuidArrayType type then need translate \r
-        // to GuidNamingConvention type at first.\r
-        // \r
-        if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {\r
-            splitStringArray = uuidString.split("," );\r
-            if (splitStringArray.length != 11) {\r
-                throw new EntityException ("[FPD file error] Wrong format for UUID string: " + uuidString);\r
-            }\r
-\r
-            //\r
-            // Remove blank space from these string and remove header string "0x"\r
-            // \r
-            for (index = 0; index < 11; index ++) {\r
-                splitStringArray[index] = splitStringArray[index].trim();\r
-                splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());\r
-            }\r
-\r
-            //\r
-            // Add heading '0' to normalize the string length\r
-            // \r
-            for (index = 3; index < 11; index ++) {\r
-                chLen = splitStringArray[index].length();\r
-                for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) {\r
-                    splitStringArray[index] = "0" + splitStringArray[index];\r
-                }\r
-            }\r
-\r
-            //\r
-            // construct the final GuidNamingConvention string\r
-            // \r
-            temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",\r
-                                 splitStringArray[0],\r
-                                 splitStringArray[1],\r
-                                 splitStringArray[2],\r
-                                 splitStringArray[3],\r
-                                 splitStringArray[4],\r
-                                 splitStringArray[5],\r
-                                 splitStringArray[6],\r
-                                 splitStringArray[7],\r
-                                 splitStringArray[8],\r
-                                 splitStringArray[9],\r
-                                 splitStringArray[10]);\r
-            uuidString = temp;\r
-        }\r
-\r
-        return UUID.fromString(uuidString);\r
-    }\r
-\r
-    /**\r
-      check parameter for this action.\r
-      \r
-      @throws EntityException  Bad parameter.\r
-    **/\r
-    private void checkParameter() throws EntityException {\r
-        File file = null;\r
-\r
-        if((fpdFilePath    == null) ||(workspacePath  == null)) {\r
-            throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
-        }\r
-\r
-        if(fpdFilePath.length() == 0 || workspacePath.length() == 0) {\r
-            throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
-        }\r
-\r
-        file = new File(workspacePath);\r
-        if(!file.exists()) {\r
-            throw new EntityException("WorkpacePath " + workspacePath + " does not exist!");\r
-        }\r
-\r
-        file = new File(fpdFilePath);\r
-\r
-        if(!file.exists()) {\r
-            throw new EntityException("FPD File " + fpdFilePath + " does not exist!");\r
-        }\r
-    }\r
-\r
-    /**\r
-      Test case function\r
-\r
-      @param argv  parameter from command line\r
-    **/\r
-    public static void main(String argv[]) throws EntityException {\r
-        CollectPCDAction ca = new CollectPCDAction();\r
-        String projectDir = "x:/edk2";\r
-        ca.setWorkspacePath(projectDir);\r
-        ca.setFPDFilePath(projectDir + "/EdkNt32Pkg/Nt32.fpd");\r
-        ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
-        GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
-                            projectDir,\r
-                            "tools_def.txt");\r
-        System.out.println("After initInfo!");\r
-        FpdParserTask fpt = new FpdParserTask();\r
-        fpt.parseFpdFile(new File(projectDir + "/EdkNt32Pkg/Nt32.fpd"));\r
-        ca.execute();\r
-    }\r
-}\r
index 40d2b32..5a429e4 100644 (file)
@@ -3,13 +3,13 @@
 \r
   This class is to manage how to generate the PCD information into Autogen.c and\r
   Autogen.h.\r
\r
+\r
 Copyright (c) 2006, Intel Corporation\r
 All rights reserved. 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
+\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
 \r
@@ -19,21 +19,15 @@ package org.tianocore.build.pcd.action;
 import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.UUID;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
 \r
-import org.apache.xmlbeans.XmlObject;\r
 import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.global.SurfaceAreaQuery;\r
 import org.tianocore.build.id.ModuleIdentification;\r
 import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
 import org.tianocore.pcd.entity.Token;\r
 import org.tianocore.pcd.entity.UsageInstance;\r
 import org.tianocore.pcd.exception.BuildActionException;\r
-import org.tianocore.pcd.exception.EntityException;\r
 import org.tianocore.pcd.entity.UsageIdentification;\r
 import org.tianocore.pcd.action.BuildAction;\r
 import org.tianocore.pcd.action.ActionMessage;\r
@@ -46,33 +40,35 @@ public class PCDAutoGenAction extends BuildAction {
     /// The reference of DBManager in GlobalData class.\r
     ///\r
     private MemoryDatabaseManager dbManager;\r
+\r
     ///\r
     /// The identification for a UsageInstance.\r
-    /// \r
-    private UsageIdentification   usageId;\r
     ///\r
-    /// The arch of current module\r
-    /// \r
-    private String                arch;\r
+    private UsageIdentification   usageId;\r
+\r
     ///\r
     /// Whether current autogen is for building library used by current module.\r
-    /// \r
+    ///\r
     private boolean               isBuildUsedLibrary;\r
+\r
     ///\r
     /// The generated string for header file.\r
     ///\r
     private String                hAutoGenString;\r
+\r
     ///\r
     /// The generated string for C code file.\r
     ///\r
     private String                cAutoGenString;\r
+\r
     ///\r
     /// The name array of <PcdCoded> in a module.\r
-    /// \r
+    ///\r
     private String[]              pcdNameArrayInMsa;\r
+\r
     /**\r
       Set parameter moduleId\r
-  \r
+\r
       @param moduleName   the module name parameter.\r
     **/\r
     public void setUsageId(UsageIdentification usageId) {\r
@@ -81,7 +77,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
        set isBuildUsedLibrary parameter.\r
-       \r
+\r
        @param isBuildUsedLibrary\r
     **/\r
     public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary) {\r
@@ -90,7 +86,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
        set pcdNameArrayInMsa parameter.\r
-       \r
+\r
        @param pcdNameArrayInMsa\r
      */\r
     public void setPcdNameArrayInMsa(String[] pcdNameArrayInMsa) {\r
@@ -99,7 +95,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
       Get the output of generated string for header file.\r
-  \r
+\r
       @return the string of header file for PCD\r
     **/\r
     public String OutputH() {\r
@@ -108,65 +104,63 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
       Get the output of generated string for C Code file.\r
-  \r
+\r
       @return the string of C code file for PCD\r
     **/\r
     public String OutputC() {\r
         return cAutoGenString;\r
     }\r
 \r
-   \r
+\r
     /**\r
         Construct function\r
 \r
         This function mainly initialize some member variable.\r
-   \r
+\r
         @param moduleId             the identification for module\r
         @param arch                 the architecture for module\r
         @param isBuildUsedLibary    Is the current module library.\r
         @param pcdNameArrayInMsa    the pcd name array got from MSA file.\r
     **/\r
-    public PCDAutoGenAction(ModuleIdentification moduleId, \r
+    public PCDAutoGenAction(ModuleIdentification moduleId,\r
                             String               arch,\r
                             boolean              isBuildUsedLibrary,\r
                             String[]             pcdNameArrayInMsa) {\r
-        UsageIdentification usageId = new UsageIdentification(moduleId.getName(), \r
-                                                              moduleId.getGuid(), \r
-                                                              moduleId.getPackage().getName(), \r
-                                                              moduleId.getPackage().getGuid(), \r
-                                                              arch, \r
-                                                              moduleId.getVersion(), \r
-                                                              moduleId.getModuleType());\r
         dbManager       = null;\r
         hAutoGenString  = "";\r
         cAutoGenString  = "";\r
 \r
-        setUsageId(usageId);\r
+        setUsageId(new UsageIdentification(moduleId.getName(),\r
+                                           moduleId.getGuid(),\r
+                                           moduleId.getPackage().getName(),\r
+                                           moduleId.getPackage().getGuid(),\r
+                                           arch,\r
+                                           moduleId.getVersion(),\r
+                                           moduleId.getModuleType()));\r
         setIsBuildUsedLibrary(isBuildUsedLibrary);\r
         setPcdNameArrayInMsa(pcdNameArrayInMsa);\r
     }\r
 \r
     /**\r
       check the parameter for action class.\r
-      \r
+\r
       @throws BuildActionException Bad parameter.\r
     **/\r
-    public void checkParameter() throws BuildActionException {\r
-        \r
+    public void checkParameter() {\r
     }\r
 \r
     /**\r
       Core execution function for this action class.\r
-     \r
+\r
       All PCD information of this module comes from memory dabase. The collection\r
       work should be done before this action execution.\r
-      Currently, we should generated all PCD information(maybe all dynamic) as array \r
-      in Pei emulated driver for simulating PCD runtime database. \r
-      \r
+      Currently, we should generated all PCD information(maybe all dynamic) as array\r
+      in Pei emulated driver for simulating PCD runtime database.\r
+\r
       @throws BuildActionException Failed to execute this aciton class.\r
     **/\r
-    public void performAction() throws BuildActionException {\r
-        ActionMessage.debug(this, \r
+    public void performAction() {\r
+        ActionMessage.debug(this,\r
                             "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r
         //\r
         // Check the PCD memory database manager is valid.\r
@@ -189,7 +183,7 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     /**\r
       Generate the autogen string for a common module.\r
-     \r
+\r
       All PCD information of this module comes from memory dabase. The collection\r
       work should be done before this action execution.\r
     **/\r
@@ -207,23 +201,23 @@ public class PCDAutoGenAction extends BuildAction {
         usageInstanceArray = null;\r
         if (!isBuildUsedLibrary) {\r
             usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(usageId);\r
-            dbManager.UsageInstanceContext = usageInstanceArray;\r
-            dbManager.CurrentModuleName    = moduleName; \r
+            MemoryDatabaseManager.UsageInstanceContext = usageInstanceArray;\r
+            MemoryDatabaseManager.CurrentModuleName    = moduleName;\r
         } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r
-            usageContext = dbManager.UsageInstanceContext;\r
+            usageContext = MemoryDatabaseManager.UsageInstanceContext;\r
             //\r
-            // For building library package, although all module are library, but PCD entries of \r
+            // For building library package, although all module are library, but PCD entries of\r
             // these library should be used to autogen.\r
-            // \r
+            //\r
             if (usageContext == null) {\r
                 usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(usageId);\r
             } else {\r
                 usageInstanceArray = new ArrayList<UsageInstance>();\r
 \r
                 //\r
-                // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's \r
+                // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's\r
                 // <ModuleSA> in FPD file.\r
-                // \r
+                //\r
                 for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r
                     found = false;\r
                     for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r
@@ -238,14 +232,14 @@ public class PCDAutoGenAction extends BuildAction {
                         //\r
                         // All library's PCD should instanted in module's <ModuleSA> who\r
                         // use this library instance. If not, give errors.\r
-                        // \r
+                        //\r
                         throw new BuildActionException (String.format("[PCD Autogen Error] Module %s use library instance %s, the PCD %s " +\r
                                                                       "is required by this library instance, but can not find " +\r
                                                                       "it in the %s's <ModuleSA> in FPD file!",\r
-                                                                      dbManager.CurrentModuleName,\r
+                                                                      MemoryDatabaseManager.CurrentModuleName,\r
                                                                       moduleName,\r
                                                                       pcdNameArrayInMsa[index],\r
-                                                                      dbManager.CurrentModuleName\r
+                                                                      MemoryDatabaseManager.CurrentModuleName\r
                                                                       ));\r
                     }\r
                 }\r
@@ -258,18 +252,18 @@ public class PCDAutoGenAction extends BuildAction {
 \r
         //\r
         // Generate all PCD entry for a module.\r
-        // \r
+        //\r
         for(index = 0; index < usageInstanceArray.size(); index ++) {\r
             usageInstance = usageInstanceArray.get(index);\r
             //\r
             // Before generate any PCD information into autogen.h/autogen.c for a module,\r
             // generate TokenSpaceGuid array variable firstly. For every dynamicEx type\r
-            // PCD in this module the token, they are all reference to TokenSpaceGuid \r
+            // PCD in this module the token, they are all reference to TokenSpaceGuid\r
             // array.\r
-            // \r
+            //\r
             if (usageInstanceArray.get(index).modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
                 guidStringArray = usageInstance.parentToken.tokenSpaceName.split("-");\r
-                guidStringCName = "_gPcd_TokenSpaceGuid_" + \r
+                guidStringCName = "_gPcd_TokenSpaceGuid_" +\r
                                   usageInstance.parentToken.tokenSpaceName.replaceAll("-", "_");\r
                 guidString      = String.format("{ 0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",\r
                                                 guidStringArray[0],\r
@@ -283,22 +277,21 @@ public class PCDAutoGenAction extends BuildAction {
                                                 (guidStringArray[4].substring(6, 8)),\r
                                                 (guidStringArray[4].substring(8, 10)),\r
                                                 (guidStringArray[4].substring(10, 12)));\r
-                \r
+\r
                 Pattern pattern = Pattern.compile("(" + guidStringCName + ")+?");\r
                 Matcher matcher = pattern.matcher(cAutoGenString + " ");\r
                 //\r
                 // Find whether this guid array variable has been generated into autogen.c\r
                 // For different DyanmicEx pcd token who use same token space guid, the token space\r
                 // guid array should be only generated once.\r
-                // \r
+                //\r
                 if (!matcher.find()) {\r
-                    hAutoGenString += String.format("extern EFI_GUID %s;\r\n",\r
-                                                    guidStringCName);\r
+                    hAutoGenString += String.format("extern EFI_GUID %s;\r\n", guidStringCName);\r
                     if (!isBuildUsedLibrary) {\r
                         cAutoGenString += String.format("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID %s = %s;\r\n",\r
                                                         guidStringCName,\r
                                                         guidString);\r
-                    } \r
+                    }\r
                 }\r
             }\r
 \r
@@ -306,21 +299,21 @@ public class PCDAutoGenAction extends BuildAction {
             //\r
             // For every PCD entry for this module(usage instance), autogen string would\r
             // be appand.\r
-            // \r
+            //\r
             hAutoGenString += usageInstance.getHAutogenStr() + "\r\n";\r
             cAutoGenString += usageInstance.getCAutogenStr();\r
         }\r
 \r
         //\r
-        // Work around code, In furture following code should be modified that get \r
+        // Work around code, In furture following code should be modified that get\r
         // these information from Uplevel Autogen tools.\r
-        // \r
+        //\r
         if (moduleName.equalsIgnoreCase("PcdPeim")) {\r
-            hAutoGenString += dbManager.PcdPeimHString;\r
-            cAutoGenString += dbManager.PcdPeimCString;\r
+            hAutoGenString += MemoryDatabaseManager.PcdPeimHString;\r
+            cAutoGenString += MemoryDatabaseManager.PcdPeimCString;\r
         } else if (moduleName.equalsIgnoreCase("PcdDxe")) {\r
-            hAutoGenString += dbManager.PcdDxeHString;\r
-            cAutoGenString += dbManager.PcdDxeCString;\r
+            hAutoGenString += MemoryDatabaseManager.PcdDxeHString;\r
+            cAutoGenString += MemoryDatabaseManager.PcdDxeCString;\r
         }\r
     }\r
 \r
@@ -333,18 +326,17 @@ public class PCDAutoGenAction extends BuildAction {
 \r
         String WorkSpace = "X:/edk2";\r
         String logFilePath = WorkSpace  + "/EdkNt32Pkg/Nt32.fpd";\r
-        String[] nameArray = null;\r
 \r
         //\r
         // At first, CollectPCDAction should be invoked to collect\r
         // all PCD information from SPD, MSA, FPD.\r
         //\r
-        CollectPCDAction collectionAction = new CollectPCDAction();\r
+        PlatformPcdPreprocessActionForBuilding collectionAction = new PlatformPcdPreprocessActionForBuilding();\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
                             WorkSpace,null);\r
 \r
         try {\r
-            collectionAction.perform(WorkSpace, \r
+            collectionAction.perform(WorkSpace,\r
                                      logFilePath,\r
                                      ActionMessage.MAX_MESSAGE_LEVEL);\r
         } catch(Exception e) {\r
index 9a8699c..a42ef92 100644 (file)
@@ -6,56 +6,32 @@ All rights reserved. This program and the accompanying materials
 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
+\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
 \r
 **/\r
 package org.tianocore.build.pcd.action;\r
 \r
-import java.io.BufferedReader;                                                    \r
+import java.io.BufferedReader;\r
 import java.io.File;\r
 import java.io.FileReader;\r
-import java.io.IOException;\r
-import java.math.BigInteger;\r
 import java.util.ArrayList;\r
 import java.util.Comparator;\r
 import java.util.HashMap;\r
-import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Map;\r
-import java.util.Set;\r
 import java.util.UUID;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
-\r
-import org.apache.xmlbeans.XmlException;\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
-import org.tianocore.FrameworkModulesDocument;\r
-import org.tianocore.ModuleSADocument;\r
-import org.tianocore.PcdBuildDefinitionDocument;\r
-import org.tianocore.PcdBuildDefinitionDocument.PcdBuildDefinition;\r
-import org.tianocore.PlatformSurfaceAreaDocument;\r
-import org.tianocore.build.fpd.FpdParserTask;\r
 import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.id.FpdModuleIdentification;\r
-import org.tianocore.build.id.ModuleIdentification;\r
-import org.tianocore.pcd.action.ActionMessage;\r
-import org.tianocore.pcd.entity.CommonDefinition;\r
 import org.tianocore.pcd.entity.DynamicTokenValue;\r
-import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
-import org.tianocore.pcd.entity.SkuInstance;\r
 import org.tianocore.pcd.entity.Token;\r
-import org.tianocore.pcd.entity.UsageIdentification;\r
-import org.tianocore.pcd.entity.UsageInstance;\r
 import org.tianocore.pcd.exception.EntityException;\r
 \r
 /**\r
-    CStructTypeDeclaration   \r
-    \r
+    CStructTypeDeclaration\r
+\r
     This class is used to store the declaration string, such as\r
-    "UINT32 PcdPlatformFlashBaseAddress", of \r
+    "UINT32 PcdPlatformFlashBaseAddress", of\r
     each memember in the C structure, which is a standard C language\r
     feature used to implement a simple and efficient database for\r
     dynamic(ex) type PCD entry.\r
@@ -65,7 +41,7 @@ class CStructTypeDeclaration {
     int alignmentSize;\r
     String cCode;\r
     boolean initTable;\r
-    \r
+\r
     public CStructTypeDeclaration (String key, int alignmentSize, String cCode, boolean initTable) {\r
         this.key = key;\r
         this.alignmentSize = alignmentSize;\r
@@ -75,16 +51,16 @@ class CStructTypeDeclaration {
 }\r
 \r
 /**\r
-    StringTable   \r
-    \r
+    StringTable\r
+\r
     This class is used to store the String in a PCD database.\r
-    \r
+\r
 **/\r
 class StringTable {\r
-    private ArrayList<String>   al; \r
+    private ArrayList<String>   al;\r
     private ArrayList<String>   alComments;\r
     private String              phase;\r
-    int                         len; \r
+    int                         len;\r
 \r
     public StringTable (String phase) {\r
         this.phase = phase;\r
@@ -107,13 +83,13 @@ class StringTable {
     public String getExistanceMacro () {\r
         return String.format(PcdDatabase.StringTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
     }\r
-    \r
+\r
     public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable) {\r
         final String stringTable = "StringTable";\r
         final String tab         = "\t";\r
         final String newLine     = "\r\n";\r
         final String commaNewLine = ",\r\n";\r
-        \r
+\r
         CStructTypeDeclaration decl;\r
 \r
         String cDeclCode = "";\r
@@ -123,13 +99,13 @@ class StringTable {
         // If we have a empty StringTable\r
         //\r
         if (al.size() == 0) {\r
-            cDeclCode += String.format("%-20s%s[1]; /* StringTable is empty */", "UINT16", stringTable) + newLine; \r
+            cDeclCode += String.format("%-20s%s[1]; /* StringTable is empty */", "UINT16", stringTable) + newLine;\r
             decl = new CStructTypeDeclaration (\r
                                                 stringTable,\r
                                                 2,\r
                                                 cDeclCode,\r
                                                 true\r
-                                        );  \r
+                                        );\r
             declaList.add(decl);\r
 \r
             cInstCode = String.format("/* %s */", stringTable) + newLine + tab + "{ 0 }";\r
@@ -142,40 +118,40 @@ class StringTable {
             for (int i = 0; i < al.size(); i++) {\r
                 String str = al.get(i);\r
                 String stringTableName;\r
-                \r
+\r
                 if (i == 0) {\r
                     //\r
                     // StringTable is a well-known name in the PCD DXE driver\r
                     //\r
                     stringTableName = stringTable;\r
-    \r
+\r
                 } else {\r
                     stringTableName = String.format("%s_%d", stringTable, i);\r
                     cDeclCode += tab;\r
                 }\r
-                cDeclCode += String.format("%-20s%s[%d]; /* %s */", "UINT16", \r
-                                           stringTableName, str.length() + 1, \r
-                                           alComments.get(i)) \r
+                cDeclCode += String.format("%-20s%s[%d]; /* %s */", "UINT16",\r
+                                           stringTableName, str.length() + 1,\r
+                                           alComments.get(i))\r
                              + newLine;\r
-                \r
+\r
                 if (i == 0) {\r
                     cInstCode = "/* StringTable */" + newLine;\r
                 }\r
-                \r
+\r
                 cInstCode += tab + String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i));\r
                 if (i != al.size() - 1) {\r
                     cInstCode += commaNewLine;\r
                 }\r
             }\r
-            \r
+\r
             decl = new CStructTypeDeclaration (\r
                     stringTable,\r
                     2,\r
                     cDeclCode,\r
                     true\r
-            );  \r
+            );\r
             declaList.add(decl);\r
-    \r
+\r
             instTable.put(stringTable, cInstCode);\r
         }\r
     }\r
@@ -185,11 +161,11 @@ class StringTable {
         int pos;\r
 \r
         String str = inputStr;\r
-        \r
+\r
         //\r
         // The input can be two types:\r
-        // "L\"Bootmode\"" or "Bootmode". \r
-        // We drop the L\" and \" for the first type. \r
+        // "L\"Bootmode\"" or "Bootmode".\r
+        // We drop the L\" and \" for the first type.\r
         if (str.startsWith("L\"") && str.endsWith("\"")) {\r
             str = str.substring(2, str.length() - 1);\r
         }\r
@@ -205,12 +181,12 @@ class StringTable {
             }\r
             pos = s.length() + 1;\r
         }\r
-        \r
+\r
         i = len;\r
         //\r
         // Include the NULL character at the end of String\r
         //\r
-        len += str.length() + 1; \r
+        len += str.length() + 1;\r
         al.add(str);\r
         alComments.add(token.getPrimaryKeyString());\r
 \r
@@ -219,8 +195,8 @@ class StringTable {
 }\r
 \r
 /**\r
-    SizeTable   \r
-    \r
+    SizeTable\r
+\r
     This class is used to store the Size information for\r
     POINTER TYPE PCD entry in a PCD database.\r
 \r
@@ -230,7 +206,7 @@ class SizeTable {
     private ArrayList<String>   alComments;\r
     private int                 len;\r
     private String              phase;\r
-    \r
+\r
     public SizeTable (String phase) {\r
         al = new ArrayList<ArrayList<Integer>>();\r
         alComments = new ArrayList<String>();\r
@@ -241,24 +217,24 @@ class SizeTable {
     public String getSizeMacro () {\r
         return String.format(PcdDatabase.SizeTableSizeMacro, phase, getSize());\r
     }\r
-    \r
+\r
     private int getSize() {\r
         return len == 0 ? 1 : len;\r
     }\r
 \r
     public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
         final String name = "SizeTable";\r
-        \r
+\r
         CStructTypeDeclaration decl;\r
         String cCode;\r
 \r
-        cCode = String.format(PcdDatabase.SizeTableDeclaration, phase); \r
+        cCode = String.format(PcdDatabase.SizeTableDeclaration, phase);\r
         decl = new CStructTypeDeclaration (\r
                                             name,\r
                                             2,\r
                                             cCode,\r
                                             true\r
-                                           );  \r
+                                           );\r
         declaList.add(decl);\r
 \r
 \r
@@ -277,9 +253,9 @@ class SizeTable {
         } else {\r
             for (int index = 0; index < al.size(); index++) {\r
                 ArrayList<Integer> ial = al.get(index);\r
-                \r
+\r
                 String str = "\t";\r
-                \r
+\r
                 for (int index2 = 0; index2 < ial.size(); index2++) {\r
                     str += " " + ial.get(index2).toString();\r
                     if (index2 != ial.size() - 1) {\r
@@ -287,14 +263,14 @@ class SizeTable {
                     }\r
                 }\r
 \r
-                str += " /* " + alComments.get(index) + " */"; \r
-                \r
+                str += " /* " + alComments.get(index) + " */";\r
+\r
                 if (index != (al.size() - 1)) {\r
                     str += comma;\r
                 }\r
 \r
                 Output.add(str);\r
-    \r
+\r
             }\r
         }\r
         Output.add("}");\r
@@ -310,22 +286,22 @@ class SizeTable {
         if (token.datumType != Token.DATUM_TYPE.POINTER) {\r
             return;\r
         }\r
-        \r
+\r
         ArrayList<Integer> ial = token.getPointerTypeSize();\r
-        \r
-        len+= ial.size(); \r
+\r
+        len+= ial.size();\r
 \r
         al.add(ial);\r
         alComments.add(token.getPrimaryKeyString());\r
 \r
         return;\r
     }\r
-    \r
+\r
 }\r
 \r
 /**\r
-    GuidTable   \r
-    \r
+    GuidTable\r
+\r
     This class is used to store the GUIDs in a PCD database.\r
 **/\r
 class GuidTable {\r
@@ -357,17 +333,17 @@ class GuidTable {
 \r
     public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
         final String name = "GuidTable";\r
-        \r
+\r
         CStructTypeDeclaration decl;\r
         String cCode = "";\r
 \r
-        cCode += String.format(PcdDatabase.GuidTableDeclaration, phase); \r
+        cCode += String.format(PcdDatabase.GuidTableDeclaration, phase);\r
         decl = new CStructTypeDeclaration (\r
                                             name,\r
                                             4,\r
                                             cCode,\r
                                             true\r
-                                           );  \r
+                                           );\r
         declaList.add(decl);\r
 \r
 \r
@@ -404,7 +380,7 @@ class GuidTable {
         if (al.size() == 0) {\r
             Output.add("\t" + getUuidCString(new UUID(0, 0)));\r
         }\r
-        \r
+\r
         for (int i = 0; i < al.size(); i++) {\r
             String str = "\t" + getUuidCString(al.get(i));\r
 \r
@@ -431,8 +407,8 @@ class GuidTable {
                 return i;\r
             }\r
         }\r
-        \r
-        len++; \r
+\r
+        len++;\r
         al.add(uuid);\r
         alComments.add(name);\r
 \r
@@ -445,8 +421,8 @@ class GuidTable {
 }\r
 \r
 /**\r
-    SkuIdTable   \r
-    \r
+    SkuIdTable\r
+\r
     This class is used to store the SKU IDs in a PCD database.\r
 \r
 **/\r
@@ -477,17 +453,17 @@ class SkuIdTable {
 \r
     public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
         final String name = "SkuIdTable";\r
-        \r
+\r
         CStructTypeDeclaration decl;\r
         String cCode = "";\r
 \r
-        cCode += String.format(PcdDatabase.SkuIdTableDeclaration, phase); \r
+        cCode += String.format(PcdDatabase.SkuIdTableDeclaration, phase);\r
         decl = new CStructTypeDeclaration (\r
                                             name,\r
                                             1,\r
                                             cCode,\r
                                             true\r
-                                           );  \r
+                                           );\r
         declaList.add(decl);\r
 \r
 \r
@@ -505,7 +481,7 @@ class SkuIdTable {
                                                 true\r
                                               );\r
             declaList.add(decl);\r
-            \r
+\r
             instTable.put("SystemSkuId", "0");\r
         }\r
 \r
@@ -520,7 +496,7 @@ class SkuIdTable {
         if (al.size() == 0) {\r
             Output.add("\t0");\r
         }\r
-        \r
+\r
         for (int index = 0; index < al.size(); index++) {\r
             String str;\r
 \r
@@ -551,7 +527,7 @@ class SkuIdTable {
 \r
         int index;\r
         int pos;\r
-        \r
+\r
         //\r
         // Check if this SKU_ID Array is already in the table\r
         //\r
@@ -584,7 +560,7 @@ class SkuIdTable {
 \r
         index = len;\r
 \r
-        len += skuIds.length; \r
+        len += skuIds.length;\r
         al.add(skuIds);\r
         alComment.add(token.getPrimaryKeyString());\r
 \r
@@ -622,17 +598,17 @@ class LocalTokenNumberTable {
 \r
     public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
         final String name = "LocalTokenNumberTable";\r
-        \r
+\r
         CStructTypeDeclaration decl;\r
         String cCode = "";\r
 \r
-        cCode += String.format(PcdDatabase.LocalTokenNumberTableDeclaration, phase); \r
+        cCode += String.format(PcdDatabase.LocalTokenNumberTableDeclaration, phase);\r
         decl = new CStructTypeDeclaration (\r
                                             name,\r
                                             4,\r
                                             cCode,\r
                                             true\r
-                                           );  \r
+                                           );\r
         declaList.add(decl);\r
 \r
         cCode = PcdDatabase.genInstantiationStr(getInstantiation());\r
@@ -648,7 +624,7 @@ class LocalTokenNumberTable {
         if (al.size() == 0) {\r
             output.add("\t0");\r
         }\r
-        \r
+\r
         for (int index = 0; index < al.size(); index++) {\r
             String str;\r
 \r
@@ -674,7 +650,7 @@ class LocalTokenNumberTable {
         int index = len;\r
         String str;\r
 \r
-        len++; \r
+        len++;\r
 \r
         str =  String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString());\r
 \r
@@ -693,7 +669,7 @@ class LocalTokenNumberTable {
         if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {\r
             str += " | PCD_TYPE_VPD";\r
         }\r
-        \r
+\r
         switch (token.datumType) {\r
         case UINT8:\r
         case BOOLEAN:\r
@@ -712,7 +688,7 @@ class LocalTokenNumberTable {
             str += " | PCD_DATUM_TYPE_POINTER";\r
             break;\r
         }\r
-        \r
+\r
         al.add(str);\r
         alComment.add(token.getPrimaryKeyString());\r
 \r
@@ -721,8 +697,8 @@ class LocalTokenNumberTable {
 }\r
 \r
 /**\r
-    ExMapTable   \r
-    \r
+    ExMapTable\r
+\r
     This class is used to store the table of mapping information\r
     between DynamicEX ID pair(Guid, TokenNumber) and\r
     the local token number assigned by PcdDatabase class.\r
@@ -730,8 +706,8 @@ class LocalTokenNumberTable {
 class ExMapTable {\r
 \r
     /**\r
-        ExTriplet   \r
-        \r
+        ExTriplet\r
+\r
         This class is used to store the mapping information\r
         between DynamicEX ID pair(Guid, TokenNumber) and\r
         the local token number assigned by PcdDatabase class.\r
@@ -740,7 +716,7 @@ class ExMapTable {
         public Integer guidTableIdx;\r
         public Long exTokenNumber;\r
         public Long localTokenIdx;\r
-    \r
+\r
         public ExTriplet (int guidTableIdx, long exTokenNumber, long localTokenIdx) {\r
             this.guidTableIdx = new Integer(guidTableIdx);\r
             this.exTokenNumber = new Long(exTokenNumber);\r
@@ -753,7 +729,7 @@ class ExMapTable {
     private String               phase;\r
     private int                  len;\r
     private int                   bodyLineNum;\r
-    \r
+\r
     public ExMapTable (String phase) {\r
         this.phase = phase;\r
         al = new ArrayList<ExTriplet>();\r
@@ -773,26 +749,26 @@ class ExMapTable {
 \r
     public void genCode (ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) {\r
         final String exMapTableName = "ExMapTable";\r
-        \r
+\r
         sortTable();\r
-        \r
+\r
         CStructTypeDeclaration decl;\r
         String cCode = "";\r
 \r
-        cCode += String.format(PcdDatabase.ExMapTableDeclaration, phase); \r
+        cCode += String.format(PcdDatabase.ExMapTableDeclaration, phase);\r
         decl = new CStructTypeDeclaration (\r
                                             exMapTableName,\r
                                             4,\r
                                             cCode,\r
                                             true\r
-                                           );  \r
+                                           );\r
         declaList.add(decl);\r
 \r
 \r
         cCode = PcdDatabase.genInstantiationStr(getInstantiation());\r
         instTable.put(exMapTableName, cCode);\r
     }\r
-    \r
+\r
     private ArrayList<String> getInstantiation () {\r
         ArrayList<String> Output = new ArrayList<String>();\r
 \r
@@ -801,7 +777,7 @@ class ExMapTable {
         if (al.size() == 0) {\r
             Output.add("\t{0, 0, 0}");\r
         }\r
-        \r
+\r
         int index;\r
         for (index = 0; index < al.size(); index++) {\r
             String str;\r
@@ -832,7 +808,7 @@ class ExMapTable {
         int index = len;\r
 \r
         len++;\r
-        ExTriplet et = new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx); \r
+        ExTriplet et = new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx);\r
 \r
         al.add(et);\r
         alComment.put(et, name);\r
@@ -850,7 +826,7 @@ class ExMapTable {
     // following order:\r
     // 1) ExGuid\r
     // 2) ExTokenNumber\r
-    // \r
+    //\r
     class ExTripletComp implements Comparator<ExTriplet> {\r
         public int compare (ExTriplet a, ExTriplet b) {\r
             if (a.guidTableIdx == b.guidTableIdx ) {\r
@@ -865,7 +841,7 @@ class ExMapTable {
                     return -1;\r
                 }\r
             }\r
-            \r
+\r
             return a.guidTableIdx - b.guidTableIdx;\r
         }\r
     }\r
@@ -877,8 +853,8 @@ class ExMapTable {
 }\r
 \r
 /**\r
-    PcdDatabase   \r
-    \r
+    PcdDatabase\r
+\r
     This class is used to generate C code for Autogen.h and Autogen.c of\r
     a PCD service DXE driver and PCD service PEIM.\r
 **/\r
@@ -898,7 +874,7 @@ public class PcdDatabase {
 \r
     public final static String ExMapTableSizeMacro              = "#define %s_EXMAPPING_TABLE_SIZE  %d\r\n";\r
     public final static String ExTokenNumber                    = "#define %s_EX_TOKEN_NUMBER       %d\r\n";\r
-    public final static String GuidTableSizeMacro               = "#define %s_GUID_TABLE_SIZE         %d\r\n"; \r
+    public final static String GuidTableSizeMacro               = "#define %s_GUID_TABLE_SIZE         %d\r\n";\r
     public final static String LocalTokenNumberTableSizeMacro   = "#define %s_LOCAL_TOKEN_NUMBER_TABLE_SIZE            %d\r\n";\r
     public final static String LocalTokenNumberSizeMacro               = "#define %s_LOCAL_TOKEN_NUMBER            %d\r\n";\r
     public final static String SizeTableSizeMacro               = "#define %s_SIZE_TABLE_SIZE            %d\r\n";\r
@@ -906,7 +882,7 @@ public class PcdDatabase {
     public final static String SkuIdTableSizeMacro              = "#define %s_SKUID_TABLE_SIZE        %d\r\n";\r
 \r
 \r
-    public final static String ExMapTableExistenceMacro         = "#define %s_EXMAP_TABLE_EMPTY    %s\r\n"; \r
+    public final static String ExMapTableExistenceMacro         = "#define %s_EXMAP_TABLE_EMPTY    %s\r\n";\r
     public final static String GuidTableExistenceMacro          = "#define %s_GUID_TABLE_EMPTY     %s\r\n";\r
     public final static String DatabaseExistenceMacro           = "#define %s_DATABASE_EMPTY       %s\r\n";\r
     public final static String StringTableExistenceMacro        = "#define %s_STRING_TABLE_EMPTY   %s\r\n";\r
@@ -915,7 +891,7 @@ public class PcdDatabase {
     public final static String offsetOfSkuHeadStrTemplate       = "offsetof(%s_PCD_DATABASE, %s.%s_SkuDataTable)";\r
     public final static String offsetOfVariableEnabledDefault   = "offsetof(%s_PCD_DATABASE, %s.%s_VariableDefault_%d)";\r
     public final static String offsetOfStrTemplate              = "offsetof(%s_PCD_DATABASE, %s.%s)";\r
-    \r
+\r
     private final static String  skuDataTableTemplate           = "SkuDataTable";\r
 \r
 \r
@@ -929,10 +905,10 @@ public class PcdDatabase {
     private ArrayList<Token> alTokens;\r
     private String phase;\r
     private int assignedTokenNumber;\r
-    \r
+\r
     //\r
     // Use two class global variable to store\r
-    // temperary \r
+    // temperary\r
     //\r
     private String      privateGlobalName;\r
     private String      privateGlobalCCode;\r
@@ -949,11 +925,11 @@ public class PcdDatabase {
     private String cString;\r
 \r
     /**\r
-        Constructor for PcdDatabase class. \r
-        \r
+        Constructor for PcdDatabase class.\r
+\r
         <p>We have two PCD dynamic(ex) database for the Framework implementation. One\r
         for PEI phase and the other for DXE phase.  </p>\r
-        \r
+\r
         @param alTokens A ArrayList of Dynamic(EX) PCD entry.\r
         @param exePhase The phase to generate PCD database for: valid input\r
                         is "PEI" or "DXE".\r
@@ -971,11 +947,11 @@ public class PcdDatabase {
        localTokenNumberTable = new LocalTokenNumberTable(phase);\r
        skuIdTable = new SkuIdTable(phase);\r
        sizeTable = new SizeTable(phase);\r
-       exMapTable = new ExMapTable(phase); \r
+       exMapTable = new ExMapTable(phase);\r
 \r
        //\r
        // Local token number 0 is reserved for INVALID_TOKEN_NUMBER.\r
-       // So we will increment 1 for the startLen passed from the \r
+       // So we will increment 1 for the startLen passed from the\r
        // constructor.\r
        //\r
        assignedTokenNumber = startLen + 1;\r
@@ -1013,7 +989,7 @@ public class PcdDatabase {
             return 1;\r
         }\r
     }\r
-    \r
+\r
     private int getHiiPtrTypeAlignmentSize(Token token) {\r
         switch (token.datumType) {\r
         case UINT8:\r
@@ -1037,7 +1013,7 @@ public class PcdDatabase {
             return 1;\r
         }\r
     }\r
-    \r
+\r
     private int getAlignmentSize (Token token) {\r
         if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.HII_TYPE) {\r
             return 2;\r
@@ -1050,7 +1026,7 @@ public class PcdDatabase {
         if (token.isUnicodeStringType()) {\r
             return 2;\r
         }\r
-        \r
+\r
         return getDataTypeAlignmentSize(token);\r
      }\r
 \r
@@ -1061,7 +1037,7 @@ public class PcdDatabase {
     public String getHString () {\r
         return hString;\r
     }\r
-    \r
+\r
     private void genCodeWorker(Token t,\r
             ArrayList<CStructTypeDeclaration> declaList,\r
             HashMap<String, String> instTable, String phase)\r
@@ -1092,48 +1068,48 @@ public class PcdDatabase {
         declaList.add(decl);\r
 \r
         if (t.hasDefaultValue()) {\r
-            instTable.put(privateGlobalName, \r
+            instTable.put(privateGlobalName,\r
                           getTypeInstantiation(t, declaList, instTable, phase)\r
                           );\r
         }\r
 \r
     }\r
 \r
-    private void ProcessTokens (List<Token> tokens, \r
+    private void ProcessTokens (List<Token> tokens,\r
                                    ArrayList<CStructTypeDeclaration> cStructDeclList,\r
                                    HashMap<String, String> cStructInstTable,\r
                                    String phase\r
-                                   ) \r
+                                   )\r
     throws EntityException {\r
-        \r
+\r
         for (int idx = 0; idx < tokens.size(); idx++) {\r
             Token t = tokens.get(idx);\r
-            \r
+\r
             genCodeWorker (t, cStructDeclList, cStructInstTable, phase);\r
-            \r
+\r
             sizeTable.add(t);\r
             localTokenNumberTable.add(t);\r
             t.tokenNumber = assignedTokenNumber++;\r
-            \r
+\r
             //\r
             // Add a mapping if this dynamic PCD entry is a EX type\r
             //\r
             if (t.isDynamicEx()) {\r
-                exMapTable.add((int)t.tokenNumber, \r
-                                t.dynamicExTokenNumber, \r
-                                guidTable.add(translateSchemaStringToUUID(t.tokenSpaceName), t.getPrimaryKeyString()), \r
+                exMapTable.add((int)t.tokenNumber,\r
+                                t.dynamicExTokenNumber,\r
+                                guidTable.add(translateSchemaStringToUUID(t.tokenSpaceName), t.getPrimaryKeyString()),\r
                                 t.getPrimaryKeyString()\r
                                 );\r
             }\r
         }\r
 \r
     }\r
-    \r
+\r
     public void genCode () throws EntityException {\r
-        \r
+\r
         ArrayList<CStructTypeDeclaration> cStructDeclList = new ArrayList<CStructTypeDeclaration>();\r
         HashMap<String, String> cStructInstTable = new HashMap<String, String>();\r
-        \r
+\r
         List<Token> nexTokens = new ArrayList<Token> ();\r
         List<Token> exTokens = new ArrayList<Token> ();\r
 \r
@@ -1141,40 +1117,40 @@ public class PcdDatabase {
 \r
         //\r
         // We have to process Non-Ex type PCD entry first. The reason is\r
-        // that our optimization assumes that the Token Number of Non-Ex \r
+        // that our optimization assumes that the Token Number of Non-Ex\r
         // PCD entry start from 1 (for PEI phase) and grows continously upwards.\r
-        // \r
+        //\r
         // EX type token number starts from the last Non-EX PCD entry and\r
         // grows continously upwards.\r
         //\r
         ProcessTokens (nexTokens, cStructDeclList, cStructInstTable, phase);\r
         ProcessTokens (exTokens, cStructDeclList, cStructInstTable, phase);\r
-        \r
+\r
         stringTable.genCode(cStructDeclList, cStructInstTable);\r
         skuIdTable.genCode(cStructDeclList, cStructInstTable, phase);\r
         exMapTable.genCode(cStructDeclList, cStructInstTable, phase);\r
         localTokenNumberTable.genCode(cStructDeclList, cStructInstTable, phase);\r
         sizeTable.genCode(cStructDeclList, cStructInstTable, phase);\r
         guidTable.genCode(cStructDeclList, cStructInstTable, phase);\r
-        \r
+\r
         hString = genCMacroCode ();\r
-        \r
+\r
         HashMap <String, String> result;\r
-        \r
-        result = genCStructCode(cStructDeclList, \r
-                cStructInstTable, \r
+\r
+        result = genCStructCode(cStructDeclList,\r
+                cStructInstTable,\r
                 phase\r
                 );\r
-        \r
+\r
         hString += result.get("initDeclStr");\r
         hString += result.get("uninitDeclStr");\r
-        \r
+\r
         hString += String.format("#define PCD_%s_SERVICE_DRIVER_VERSION         %d", phase, version);\r
-        \r
+\r
         cString = newLine + newLine + result.get("initInstStr");\r
-        \r
+\r
     }\r
-    \r
+\r
     private String genCMacroCode () {\r
         String macroStr   = "";\r
 \r
@@ -1198,22 +1174,22 @@ public class PcdDatabase {
         macroStr += exMapTable.getExistanceMacro();\r
 \r
         macroStr += newLine;\r
-        \r
+\r
         return macroStr;\r
     }\r
-    \r
+\r
     private HashMap <String, String> genCStructCode(\r
-                                            ArrayList<CStructTypeDeclaration> declaList, \r
-                                            HashMap<String, String> instTable, \r
+                                            ArrayList<CStructTypeDeclaration> declaList,\r
+                                            HashMap<String, String> instTable,\r
                                             String phase\r
                                             ) {\r
-        \r
+\r
         int i;\r
         HashMap <String, String> result = new HashMap<String, String>();\r
         HashMap <Integer, ArrayList<String>>    alignmentInitDecl = new HashMap<Integer, ArrayList<String>>();\r
         HashMap <Integer, ArrayList<String>>    alignmentUninitDecl = new HashMap<Integer, ArrayList<String>>();\r
         HashMap <Integer, ArrayList<String>>    alignmentInitInst = new HashMap<Integer, ArrayList<String>>();\r
-        \r
+\r
         //\r
         // Initialize the storage for each alignment\r
         //\r
@@ -1222,17 +1198,17 @@ public class PcdDatabase {
             alignmentInitInst.put(new Integer(i), new ArrayList<String>());\r
             alignmentUninitDecl.put(new Integer(i), new ArrayList<String>());\r
         }\r
-        \r
+\r
         String initDeclStr   = "typedef struct {" + newLine;\r
         String initInstStr   = String.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase.toUpperCase(), phase.toUpperCase()) + newLine;\r
         String uninitDeclStr = "typedef struct {" + newLine;\r
 \r
         //\r
-        // Sort all C declaration and instantiation base on Alignment Size \r
+        // Sort all C declaration and instantiation base on Alignment Size\r
         //\r
         for (Object d : declaList) {\r
             CStructTypeDeclaration decl = (CStructTypeDeclaration) d;\r
-            \r
+\r
             if (decl.initTable) {\r
                 alignmentInitDecl.get(new Integer(decl.alignmentSize)).add(decl.cCode);\r
                 alignmentInitInst.get(new Integer(decl.alignmentSize)).add(instTable.get(decl.key));\r
@@ -1251,7 +1227,7 @@ public class PcdDatabase {
             for (i = 0; i < declaListBasedOnAlignment.size(); i++) {\r
                 initDeclStr += tab + declaListBasedOnAlignment.get(i);\r
                 initInstStr += tab + instListBasedOnAlignment.get(i);\r
-                \r
+\r
                 //\r
                 // We made a assumption that both PEI_PCD_DATABASE and DXE_PCD_DATABASE\r
                 // has a least one data memember with alignment size of 1. So we can\r
@@ -1264,27 +1240,27 @@ public class PcdDatabase {
                     initInstStr += commaNewLine;\r
                 }\r
             }\r
-            \r
+\r
             declaListBasedOnAlignment = alignmentUninitDecl.get(new Integer(align));\r
-            \r
+\r
             if (declaListBasedOnAlignment.size() != 0) {\r
                 uinitDatabaseEmpty = false;\r
             }\r
-            \r
+\r
             for (Object d : declaListBasedOnAlignment) {\r
                 String s = (String)d;\r
                 uninitDeclStr += tab + s;\r
             }\r
         }\r
-        \r
+\r
         if (uinitDatabaseEmpty) {\r
             uninitDeclStr += tab + String.format("%-20sdummy; /* PCD_DATABASE_UNINIT is emptry */\r\n", "UINT8");\r
         }\r
-        \r
+\r
         initDeclStr += String.format("} %s_PCD_DATABASE_INIT;", phase) + newLine + newLine;\r
         initInstStr += "};" + newLine;\r
         uninitDeclStr += String.format("} %s_PCD_DATABASE_UNINIT;", phase) + newLine + newLine;\r
-        \r
+\r
         result.put("initDeclStr", initDeclStr);\r
         result.put("initInstStr", initInstStr);\r
         result.put("uninitDeclStr", uninitDeclStr);\r
@@ -1321,21 +1297,21 @@ public class PcdDatabase {
         return String.format("%s /* %s */", token.skuData.get(skuId).value.hiiDefaultValue, cName);\r
     }\r
 \r
-    private String getCType (Token t) \r
+    private String getCType (Token t)\r
         throws EntityException {\r
-        \r
+\r
         if (t.isHiiEnable()) {\r
             return "VARIABLE_HEAD";\r
         }\r
-        \r
+\r
         if (t.isVpdEnable()) {\r
             return "VPD_HEAD";\r
         }\r
-        \r
+\r
         if (t.isUnicodeStringType()) {\r
             return "STRING_HEAD";\r
         }\r
-        \r
+\r
         switch (t.datumType) {\r
         case UINT64:\r
             return "UINT64";\r
@@ -1353,13 +1329,13 @@ public class PcdDatabase {
             throw new EntityException("Unknown type in getDataTypeCDeclaration");\r
         }\r
     }\r
-    \r
+\r
     //\r
     // privateGlobalName and privateGlobalCCode is used to pass output to caller of getCDeclarationString\r
     //\r
-    private void getCDeclarationString(Token t) \r
+    private void getCDeclarationString(Token t)\r
         throws EntityException {\r
-        \r
+\r
         if (t.isSkuEnable()) {\r
             privateGlobalName = String.format("%s_%s", t.getPrimaryKeyString(), skuDataTableTemplate);\r
         } else {\r
@@ -1382,8 +1358,8 @@ public class PcdDatabase {
             privateGlobalCCode = String.format("%-20s%s[%d];\r\n", type, privateGlobalName, t.getSkuIdCount());\r
         }\r
     }\r
-    \r
-    private String getDataTypeDeclarationForVariableDefault (Token token, String cName, int skuId) \r
+\r
+    private String getDataTypeDeclarationForVariableDefault (Token token, String cName, int skuId)\r
         throws EntityException {\r
 \r
         String typeStr;\r
@@ -1424,9 +1400,9 @@ public class PcdDatabase {
 \r
         return String.format("%-20s%s;\r\n", typeStr, cName);\r
     }\r
-    \r
+\r
     private String getTypeInstantiation (Token t, ArrayList<CStructTypeDeclaration> declaList, HashMap<String, String> instTable, String phase) throws EntityException {\r
-      \r
+\r
         int     i;\r
 \r
         String s;\r
@@ -1445,8 +1421,8 @@ public class PcdDatabase {
                       UINT16  DefaultValueOffset; // Offset of the Default Value\r
                     } VARIABLE_HEAD  ;\r
                  */\r
-                String variableDefaultName = String.format("%s_VariableDefault_%d", t.getPrimaryKeyString(), i); \r
-                \r
+                String variableDefaultName = String.format("%s_VariableDefault_%d", t.getPrimaryKeyString(), i);\r
+\r
                 s += tab + tab + String.format("{ %d, %d, %s, %s }", guidTable.add(t.skuData.get(i).value.variableGuid, t.getPrimaryKeyString()),\r
                                                           stringTable.add(t.skuData.get(i).value.getStringOfVariableName(), t),\r
                                                           t.skuData.get(i).value.variableOffset,\r
@@ -1460,7 +1436,7 @@ public class PcdDatabase {
                                                         getHiiPtrTypeAlignmentSize(t),\r
                                                         getDataTypeDeclarationForVariableDefault(t, variableDefaultName, i),\r
                                                         true\r
-                                                        ); \r
+                                                        );\r
                 declaList.add(decl);\r
                 instTable.put(variableDefaultName, getDataTypeInstantiationForVariableDefault (t, variableDefaultName, i));\r
             } else if (t.isVpdEnable()) {\r
@@ -1479,7 +1455,7 @@ public class PcdDatabase {
                     s += tab + tab + String.format("{ %s }", t.skuData.get(i).value.value);\r
                 }\r
             }\r
-            \r
+\r
             if (i != t.skuData.size() - 1) {\r
                 s += commaNewLine;\r
             } else {\r
@@ -1487,19 +1463,19 @@ public class PcdDatabase {
             }\r
 \r
         }\r
-        \r
+\r
         s += tab + "}";\r
-        \r
+\r
         return s;\r
     }\r
-    \r
-    public static String getPcdDatabaseCommonDefinitions () \r
+\r
+    public static String getPcdDatabaseCommonDefinitions ()\r
         throws EntityException {\r
 \r
         String retStr = "";\r
         try {\r
-            File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
-                                 "Tools" + File.separator + \r
+            File file = new File(GlobalData.getWorkspacePath() + File.separator +\r
+                                 "Tools" + File.separator +\r
                                  "Conf" + File.separator +\r
                                  "Pcd" + File.separator +\r
                                  "PcdDatabaseCommonDefinitions.sample");\r
@@ -1516,13 +1492,13 @@ public class PcdDatabase {
         return retStr;\r
     }\r
 \r
-    public static String getPcdDxeDatabaseDefinitions () \r
+    public static String getPcdDxeDatabaseDefinitions ()\r
         throws EntityException {\r
 \r
         String retStr = "";\r
         try {\r
-            File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
-                                 "Tools" + File.separator + \r
+            File file = new File(GlobalData.getWorkspacePath() + File.separator +\r
+                                 "Tools" + File.separator +\r
                                  "Conf" + File.separator +\r
                                  "Pcd" + File.separator +\r
                                  "PcdDatabaseDxeDefinitions.sample");\r
@@ -1539,13 +1515,13 @@ public class PcdDatabase {
         return retStr;\r
     }\r
 \r
-    public static String getPcdPeiDatabaseDefinitions () \r
+    public static String getPcdPeiDatabaseDefinitions ()\r
         throws EntityException {\r
 \r
         String retStr = "";\r
         try {\r
-            File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
-                                 "Tools" + File.separator + \r
+            File file = new File(GlobalData.getWorkspacePath() + File.separator +\r
+                                 "Tools" + File.separator +\r
                                  "Conf" + File.separator +\r
                                  "Pcd" + File.separator +\r
                                  "PcdDatabasePeiDefinitions.sample");\r
@@ -1564,21 +1540,21 @@ public class PcdDatabase {
 \r
     /**\r
        Translate the schema string to UUID instance.\r
-       \r
+\r
        In schema, the string of UUID is defined as following two types string:\r
         1) GuidArrayType: pattern = 0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},(\r
         )*0x[a-fA-F0-9]{1,4}(,( )*\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\})?\r
-       \r
+\r
         2) GuidNamingConvention: pattern =\r
         [a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\r
-       \r
+\r
        This function will convert string and create uuid instance.\r
-       \r
+\r
        @param uuidString    UUID string in XML file\r
-       \r
+\r
        @return UUID         UUID instance\r
     **/\r
-    private UUID translateSchemaStringToUUID(String uuidString) \r
+    private UUID translateSchemaStringToUUID(String uuidString)\r
         throws EntityException {\r
         String      temp;\r
         String[]    splitStringArray;\r
@@ -1603,9 +1579,9 @@ public class PcdDatabase {
         uuidString = uuidString.replaceAll("\\}", "");\r
 \r
         //\r
-        // If the UUID schema string is GuidArrayType type then need translate \r
+        // If the UUID schema string is GuidArrayType type then need translate\r
         // to GuidNamingConvention type at first.\r
-        // \r
+        //\r
         if ((uuidString.charAt(0) == '0') && ((uuidString.charAt(1) == 'x') || (uuidString.charAt(1) == 'X'))) {\r
             splitStringArray = uuidString.split("," );\r
             if (splitStringArray.length != 11) {\r
@@ -1614,7 +1590,7 @@ public class PcdDatabase {
 \r
             //\r
             // Remove blank space from these string and remove header string "0x"\r
-            // \r
+            //\r
             for (index = 0; index < 11; index ++) {\r
                 splitStringArray[index] = splitStringArray[index].trim();\r
                 splitStringArray[index] = splitStringArray[index].substring(2, splitStringArray[index].length());\r
@@ -1622,7 +1598,7 @@ public class PcdDatabase {
 \r
             //\r
             // Add heading '0' to normalize the string length\r
-            // \r
+            //\r
             for (index = 3; index < 11; index ++) {\r
                 chLen = splitStringArray[index].length();\r
                 for (chIndex = 0; chIndex < 2 - chLen; chIndex ++) {\r
@@ -1632,7 +1608,7 @@ public class PcdDatabase {
 \r
             //\r
             // construct the final GuidNamingConvention string\r
-            // \r
+            //\r
             temp = String.format("%s-%s-%s-%s%s-%s%s%s%s%s%s",\r
                                  splitStringArray[0],\r
                                  splitStringArray[1],\r
diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/PlatformPcdPreprocessActionForBuilding.java
new file mode 100644 (file)
index 0000000..2e50531
--- /dev/null
@@ -0,0 +1,719 @@
+/** @file\r
+  PlatformPcdPreprocessActionForBuilding class.\r
+\r
+  This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
+  This class will be used for wizard and build tools, So it can *not* inherit\r
+  from buildAction or wizardAction.\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+\r
+**/\r
+package org.tianocore.build.pcd.action;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.math.BigInteger;\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.apache.xmlbeans.XmlException;\r
+import org.apache.xmlbeans.XmlObject;\r
+import org.tianocore.DynamicPcdBuildDefinitionsDocument.DynamicPcdBuildDefinitions;\r
+import org.tianocore.PlatformSurfaceAreaDocument;\r
+import org.tianocore.build.fpd.FpdParserTask;\r
+import org.tianocore.build.global.GlobalData;\r
+import org.tianocore.build.id.FpdModuleIdentification;\r
+import org.tianocore.pcd.action.ActionMessage;\r
+import org.tianocore.pcd.entity.ModulePcdInfoFromFpd;\r
+import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
+import org.tianocore.pcd.entity.Token;\r
+import org.tianocore.pcd.entity.UsageIdentification;\r
+import org.tianocore.pcd.exception.EntityException;\r
+import org.tianocore.pcd.action.PlatformPcdPreprocessAction;\r
+\r
+/**\r
+   This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
+   This class will be used for wizard and build tools, So it can *not* inherit\r
+   from buildAction or UIAction.\r
+**/\r
+public class PlatformPcdPreprocessActionForBuilding extends PlatformPcdPreprocessAction {\r
+    ///\r
+    /// Workspacepath hold the workspace information.\r
+    ///\r
+    private String                      workspacePath;\r
+\r
+    ///\r
+    /// FPD file is the root file.\r
+    ///\r
+    private String                      fpdFilePath;\r
+\r
+    ///\r
+    /// Message level for CollectPCDAction.\r
+    ///\r
+    private int                         originalMessageLevel;\r
+\r
+    ///\r
+    /// Cache the fpd docment instance for private usage.\r
+    ///\r
+    private PlatformSurfaceAreaDocument fpdDocInstance;\r
+\r
+    /**\r
+      Set WorkspacePath parameter for this action class.\r
+\r
+      @param workspacePath parameter for this action\r
+    **/\r
+    public void setWorkspacePath(String workspacePath) {\r
+        this.workspacePath = workspacePath;\r
+    }\r
+\r
+    /**\r
+      Set action message level for CollectPcdAction tool.\r
+\r
+      The message should be restored when this action exit.\r
+\r
+      @param actionMessageLevel parameter for this action\r
+    **/\r
+    public void setActionMessageLevel(int actionMessageLevel) {\r
+        originalMessageLevel       = ActionMessage.messageLevel;\r
+        ActionMessage.messageLevel = actionMessageLevel;\r
+    }\r
+\r
+    /**\r
+      Set FPDFileName parameter for this action class.\r
+\r
+      @param fpdFilePath    fpd file path\r
+    **/\r
+    public void setFPDFilePath(String fpdFilePath) {\r
+        this.fpdFilePath = fpdFilePath;\r
+    }\r
+\r
+    /**\r
+      Common function interface for outer.\r
+\r
+      @param workspacePath The path of workspace of current build or analysis.\r
+      @param fpdFilePath   The fpd file path of current build or analysis.\r
+      @param messageLevel  The message level for this Action.\r
+\r
+      @throws  Exception The exception of this function. Because it can *not* be predict\r
+                         where the action class will be used. So only Exception can be throw.\r
+\r
+    **/\r
+    public void perform(String workspacePath, String fpdFilePath,\r
+                        int messageLevel) throws Exception {\r
+        setWorkspacePath(workspacePath);\r
+        setFPDFilePath(fpdFilePath);\r
+        setActionMessageLevel(messageLevel);\r
+        checkParameter();\r
+        execute();\r
+        ActionMessage.messageLevel = originalMessageLevel;\r
+    }\r
+\r
+    /**\r
+      Core execution function for this action class.\r
+\r
+      This function work flows will be:\r
+      1) Collect and prepocess PCD information from FPD file, all PCD\r
+      information will be stored into memory database.\r
+      2) Generate 3 strings for\r
+        a) All modules using Dynamic(Ex) PCD entry.(Token Number)\r
+        b) PEI PCDDatabase (C Structure) for PCD Service PEIM.\r
+        c) DXE PCD Database (C structure) for PCD Service DXE.\r
+\r
+\r
+      @throws  EntityException Exception indicate failed to execute this action.\r
+\r
+    **/\r
+    public void execute() throws EntityException {\r
+        MemoryDatabaseManager pcdDbManager = null;\r
+\r
+        //\r
+        // Get memoryDatabaseManager instance from GlobalData.\r
+        // The memoryDatabaseManager should be initialized for whatever build\r
+        // tools or wizard tools\r
+        //\r
+        if((pcdDbManager = GlobalData.getPCDMemoryDBManager()) == null) {\r
+            throw new EntityException("The instance of PCD memory database manager is null");\r
+        }\r
+\r
+        this.setPcdDbManager(pcdDbManager);\r
+\r
+        //\r
+        // Collect all PCD information defined in FPD file.\r
+        // Evenry token defind in FPD will be created as an token into\r
+        // memory database.\r
+        //\r
+        initPcdMemoryDbWithPlatformInfo();\r
+\r
+        //\r
+        // Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
+        //\r
+        genPcdDatabaseSourceCode ();\r
+\r
+    }\r
+\r
+    /**\r
+      Override function: implementate the method of get Guid string information from SPD file.\r
+\r
+      @param guidCName      Guid CName string.\r
+\r
+      @return String[]      Guid information from SPD file.\r
+    **/\r
+    public String[] getGuidInfoFromSpd(String guidCName) throws EntityException {\r
+        String[] tokenSpaceStrRet = null;\r
+        try {\r
+            tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(guidCName);\r
+        } catch ( Exception e ) {\r
+            throw new EntityException ("Failed get Guid CName " + guidCName + "from SPD file!");\r
+        }\r
+        return tokenSpaceStrRet;\r
+    }\r
+\r
+    /**\r
+      This function generates source code for PCD Database.\r
+\r
+      @param void\r
+      @throws EntityException  If the token does *not* exist in memory database.\r
+\r
+    **/\r
+    private void genPcdDatabaseSourceCode()\r
+        throws EntityException {\r
+        String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions();\r
+\r
+        ArrayList<Token> alPei = new ArrayList<Token> ();\r
+        ArrayList<Token> alDxe = new ArrayList<Token> ();\r
+\r
+        getPcdDbManager().getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
+        PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
+        pcdPeiDatabase.genCode();\r
+        MemoryDatabaseManager.PcdPeimHString        = PcdCommonHeaderString + pcdPeiDatabase.getHString() +\r
+                                                      PcdDatabase.getPcdPeiDatabaseDefinitions();\r
+        MemoryDatabaseManager.PcdPeimCString        = pcdPeiDatabase.getCString();\r
+\r
+        PcdDatabase pcdDxeDatabase = new PcdDatabase(alDxe, "DXE", alPei.size());\r
+        pcdDxeDatabase.genCode();\r
+        MemoryDatabaseManager.PcdDxeHString   = MemoryDatabaseManager.PcdPeimHString + pcdDxeDatabase.getHString() +\r
+                                                PcdDatabase.getPcdDxeDatabaseDefinitions();\r
+        MemoryDatabaseManager.PcdDxeCString   = pcdDxeDatabase.getCString();\r
+    }\r
+\r
+    /**\r
+      Override function: Get component array from FPD.\r
+\r
+      This function maybe provided by some Global class.\r
+\r
+      @return List<ModuleInfo> the component array.\r
+\r
+     */\r
+    public List<ModulePcdInfoFromFpd> getComponentsFromFpd()\r
+        throws EntityException {\r
+        List<ModulePcdInfoFromFpd>                  allModules          = new ArrayList<ModulePcdInfoFromFpd>();\r
+        Map<FpdModuleIdentification, XmlObject>     pcdBuildDefinitions = null;\r
+        UsageIdentification                         usageId             = null;\r
+\r
+        pcdBuildDefinitions = GlobalData.getFpdPcdBuildDefinitions();\r
+        if (pcdBuildDefinitions == null) {\r
+            return null;\r
+        }\r
+\r
+        //\r
+        // Loop map to retrieve all PCD build definition and Module id\r
+        //\r
+        Iterator item = pcdBuildDefinitions.keySet().iterator();\r
+        while (item.hasNext()){\r
+            FpdModuleIdentification id = (FpdModuleIdentification) item.next();\r
+            usageId                    = new UsageIdentification(id.getModule().getName(),\r
+                                                                 id.getModule().getGuid(),\r
+                                                                 id.getModule().getPackage().getName(),\r
+                                                                 id.getModule().getPackage().getGuid(),\r
+                                                                 id.getArch(),\r
+                                                                 id.getModule().getVersion(),\r
+                                                                 id.getModule().getModuleType());\r
+            allModules.add(new ModulePcdInfoFromFpd(usageId, pcdBuildDefinitions.get(id)));\r
+        }\r
+        return allModules;\r
+    }\r
+\r
+    /**\r
+       Override function: Verify the datum value according its datum size and datum type, this\r
+       function maybe moved to FPD verification tools in future.\r
+\r
+       @param cName\r
+       @param moduleName\r
+       @param datum\r
+       @param datumType\r
+       @param maxDatumSize\r
+\r
+       @return String\r
+     */\r
+    /***/\r
+    public String verifyDatum(String            cName,\r
+                              String            moduleName,\r
+                              String            datum,\r
+                              Token.DATUM_TYPE  datumType,\r
+                              int               maxDatumSize) {\r
+        String      exceptionString = null;\r
+        int         value;\r
+        BigInteger  value64;\r
+        String      subStr;\r
+        int         index;\r
+\r
+        if (moduleName == null) {\r
+            moduleName = "section <DynamicPcdBuildDefinitions>";\r
+        } else {\r
+            moduleName = "module " + moduleName;\r
+        }\r
+\r
+        if (maxDatumSize == 0) {\r
+            exceptionString = String.format("[FPD file error] You maybe miss <MaxDatumSize> for PCD %s in %s",\r
+                                            cName,\r
+                                            moduleName);\r
+            return exceptionString;\r
+        }\r
+\r
+        switch (datumType) {\r
+        case UINT8:\r
+            if (maxDatumSize != 1) {\r
+                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+                                                "is UINT8, but datum size is %d, they are not matched!",\r
+                                                 cName,\r
+                                                 moduleName,\r
+                                                 maxDatumSize);\r
+                return exceptionString;\r
+            }\r
+\r
+            if (datum != null) {\r
+                try {\r
+                    value = Integer.decode(datum);\r
+                } catch (NumberFormatException nfeExp) {\r
+                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid "+\r
+                                                    "digital format of UINT8",\r
+                                                    cName,\r
+                                                    moduleName);\r
+                    return exceptionString;\r
+                }\r
+                if (value > 0xFF) {\r
+                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s exceed"+\r
+                                                    " the max size of UINT8 - 0xFF",\r
+                                                    cName,\r
+                                                    moduleName,\r
+                                                    datum);\r
+                    return exceptionString;\r
+                }\r
+            }\r
+            break;\r
+        case UINT16:\r
+            if (maxDatumSize != 2) {\r
+                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+                                                "is UINT16, but datum size is %d, they are not matched!",\r
+                                                 cName,\r
+                                                 moduleName,\r
+                                                 maxDatumSize);\r
+                return exceptionString;\r
+            }\r
+            if (datum != null) {\r
+                try {\r
+                    value = Integer.decode(datum);\r
+                } catch (NumberFormatException nfeExp) {\r
+                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is "+\r
+                                                    "not valid digital of UINT16",\r
+                                                    cName,\r
+                                                    moduleName);\r
+                    return exceptionString;\r
+                }\r
+                if (value > 0xFFFF) {\r
+                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
+                                                    "which exceed the range of UINT16 - 0xFFFF",\r
+                                                    cName,\r
+                                                    moduleName,\r
+                                                    datum);\r
+                    return exceptionString;\r
+                }\r
+            }\r
+            break;\r
+        case UINT32:\r
+            if (maxDatumSize != 4) {\r
+                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+                                                "is UINT32, but datum size is %d, they are not matched!",\r
+                                                 cName,\r
+                                                 moduleName,\r
+                                                 maxDatumSize);\r
+                return exceptionString;\r
+            }\r
+\r
+            if (datum != null) {\r
+                try {\r
+                    if (datum.length() > 2) {\r
+                        if ((datum.charAt(0) == '0')        &&\r
+                            ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
+                            subStr = datum.substring(2, datum.length());\r
+                            value64 = new BigInteger(subStr, 16);\r
+                        } else {\r
+                            value64 = new BigInteger(datum);\r
+                        }\r
+                    } else {\r
+                        value64 = new BigInteger(datum);\r
+                    }\r
+                } catch (NumberFormatException nfeExp) {\r
+                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not "+\r
+                                                    "valid digital of UINT32",\r
+                                                    cName,\r
+                                                    moduleName);\r
+                    return exceptionString;\r
+                }\r
+\r
+                if (value64.bitLength() > 32) {\r
+                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s which "+\r
+                                                    "exceed the range of UINT32 - 0xFFFFFFFF",\r
+                                                    cName,\r
+                                                    moduleName,\r
+                                                    datum);\r
+                    return exceptionString;\r
+                }\r
+            }\r
+            break;\r
+        case UINT64:\r
+            if (maxDatumSize != 8) {\r
+                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+                                                "is UINT64, but datum size is %d, they are not matched!",\r
+                                                 cName,\r
+                                                 moduleName,\r
+                                                 maxDatumSize);\r
+                return exceptionString;\r
+            }\r
+\r
+            if (datum != null) {\r
+                try {\r
+                    if (datum.length() > 2) {\r
+                        if ((datum.charAt(0) == '0')        &&\r
+                            ((datum.charAt(1) == 'x') || (datum.charAt(1) == 'X'))){\r
+                            subStr = datum.substring(2, datum.length());\r
+                            value64 = new BigInteger(subStr, 16);\r
+                        } else {\r
+                            value64 = new BigInteger(datum);\r
+                        }\r
+                    } else {\r
+                        value64 = new BigInteger(datum);\r
+                    }\r
+                } catch (NumberFormatException nfeExp) {\r
+                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is not valid"+\r
+                                                    " digital of UINT64",\r
+                                                    cName,\r
+                                                    moduleName);\r
+                    return exceptionString;\r
+                }\r
+\r
+                if (value64.bitLength() > 64) {\r
+                    exceptionString = String.format("[FPD file error] The datum for PCD %s in %s is %s "+\r
+                                                    "exceed the range of UINT64 - 0xFFFFFFFFFFFFFFFF",\r
+                                                    cName,\r
+                                                    moduleName,\r
+                                                    datum);\r
+                    return exceptionString;\r
+                }\r
+            }\r
+            break;\r
+        case BOOLEAN:\r
+            if (maxDatumSize != 1) {\r
+                exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+                                                "is BOOLEAN, but datum size is %d, they are not matched!",\r
+                                                 cName,\r
+                                                 moduleName,\r
+                                                 maxDatumSize);\r
+                return exceptionString;\r
+            }\r
+\r
+            if (datum != null) {\r
+                if (!(datum.equalsIgnoreCase("TRUE") ||\r
+                     datum.equalsIgnoreCase("FALSE"))) {\r
+                    exceptionString = String.format("[FPD file error] The datum type of PCD data %s in %s "+\r
+                                                    "is BOOELAN, but value is not 'true'/'TRUE' or 'FALSE'/'false'",\r
+                                                    cName,\r
+                                                    moduleName);\r
+                    return exceptionString;\r
+                }\r
+\r
+            }\r
+            break;\r
+        case POINTER:\r
+            if (datum == null) {\r
+                break;\r
+            }\r
+\r
+            char    ch     = datum.charAt(0);\r
+            int     start, end;\r
+            String  strValue;\r
+            //\r
+            // For void* type PCD, only three datum is support:\r
+            // 1) Unicode: string with start char is "L"\r
+            // 2) Ansci: String start char is ""\r
+            // 3) byte array: String start char "{"\r
+            //\r
+            if (ch == 'L') {\r
+                start       = datum.indexOf('\"');\r
+                end         = datum.lastIndexOf('\"');\r
+                if ((start > end)           ||\r
+                    (end   > datum.length())||\r
+                    ((start == end) && (datum.length() > 0))) {\r
+                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+\r
+                                                    "a UNICODE string because start with L\", but format maybe"+\r
+                                                    "is not right, correct UNICODE string is L\"...\"!",\r
+                                                    cName,\r
+                                                    moduleName);\r
+                    return exceptionString;\r
+                }\r
+\r
+                strValue    = datum.substring(start + 1, end);\r
+                if ((strValue.length() * 2) > maxDatumSize) {\r
+                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+\r
+                                                    "a UNICODE string, but the datum size is %d exceed to <MaxDatumSize> : %d",\r
+                                                    cName,\r
+                                                    moduleName,\r
+                                                    strValue.length() * 2,\r
+                                                    maxDatumSize);\r
+                    return exceptionString;\r
+                }\r
+            } else if (ch == '\"'){\r
+                start       = datum.indexOf('\"');\r
+                end         = datum.lastIndexOf('\"');\r
+                if ((start > end)           ||\r
+                    (end   > datum.length())||\r
+                    ((start == end) && (datum.length() > 0))) {\r
+                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+\r
+                                                    "a ANSCII string because start with \", but format maybe"+\r
+                                                    "is not right, correct ANSIC string is \"...\"!",\r
+                                                    cName,\r
+                                                    moduleName);\r
+                    return exceptionString;\r
+                }\r
+                strValue    = datum.substring(start + 1, end);\r
+                if ((strValue.length()) > maxDatumSize) {\r
+                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+\r
+                                                    "a ANSCI string, but the datum size is %d which exceed to <MaxDatumSize> : %d",\r
+                                                    cName,\r
+                                                    moduleName,\r
+                                                    strValue.length(),\r
+                                                    maxDatumSize);\r
+                    return exceptionString;\r
+                }\r
+            } else if (ch =='{') {\r
+                String[]  strValueArray;\r
+\r
+                start           = datum.indexOf('{');\r
+                end             = datum.lastIndexOf('}');\r
+                strValue        = datum.substring(start + 1, end);\r
+                strValue        = strValue.trim();\r
+                if (strValue.length() == 0) {\r
+                    exceptionString = String.format ("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
+                                                     "it is byte array in fact, but '{}' is not valid for NULL datam but"+\r
+                                                     " need use '{0}'",\r
+                                                     cName,\r
+                                                     moduleName);\r
+                    return exceptionString;\r
+                }\r
+                strValueArray   = strValue.split(",");\r
+                for (index = 0; index < strValueArray.length; index ++) {\r
+                    try{\r
+                        value = Integer.decode(strValueArray[index].trim());\r
+                    } catch (NumberFormatException nfeEx) {\r
+                        exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+\r
+                                                         "it is byte array in fact. For every byte in array should be a valid"+\r
+                                                         "byte digital, but element %s is not a valid byte digital!",\r
+                                                         cName,\r
+                                                         moduleName,\r
+                                                         strValueArray[index]);\r
+                        return exceptionString;\r
+                    }\r
+                    if (value > 0xFF) {\r
+                        exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, "+\r
+                                                        "it is byte array in fact. But the element of %s exceed the byte range",\r
+                                                        cName,\r
+                                                        moduleName,\r
+                                                        strValueArray[index]);\r
+                        return exceptionString;\r
+                    }\r
+                }\r
+\r
+                if (strValueArray.length > maxDatumSize) {\r
+                    exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is byte"+\r
+                                                    "array, but the number of bytes is %d which exceed to <MaxDatumSzie> : %d!",\r
+                                                    cName,\r
+                                                    moduleName,\r
+                                                    strValueArray.length,\r
+                                                    maxDatumSize);\r
+                    return exceptionString;\r
+                }\r
+            } else {\r
+                exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\r
+                                                "1) UNICODE string: like L\"xxxx\";\r\n"+\r
+                                                "2) ANSIC string: like \"xxx\";\r\n"+\r
+                                                "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+\r
+                                                "But the datum in seems does not following above format!",\r
+                                                cName,\r
+                                                moduleName);\r
+                return exceptionString;\r
+            }\r
+            break;\r
+        default:\r
+            exceptionString = String.format("[FPD file error] For PCD entry %s in %s, datum type is unknown, it should be one of "+\r
+                                            "UINT8, UINT16, UINT32, UINT64, VOID*, BOOLEAN",\r
+                                            cName,\r
+                                            moduleName);\r
+            return exceptionString;\r
+        }\r
+        return null;\r
+    }\r
+\r
+    /**\r
+       Override function: Get dynamic information for a dynamic PCD from <DynamicPcdBuildDefinition> seciton in FPD file.\r
+\r
+       This function should be implemented in GlobalData in future.\r
+\r
+       @param token         The token instance which has hold module's PCD information\r
+       @param moduleName    The name of module who will use this Dynamic PCD.\r
+\r
+       @return DynamicPcdBuildDefinitions.PcdBuildData\r
+    **/\r
+    public DynamicPcdBuildDefinitions.PcdBuildData getDynamicInfoFromFpd(Token     token,\r
+                                                                         String    moduleName)\r
+        throws EntityException {\r
+        int    index             = 0;\r
+        String exceptionString   = null;\r
+        String dynamicPrimaryKey = null;\r
+        DynamicPcdBuildDefinitions                    dynamicPcdBuildDefinitions = null;\r
+        List<DynamicPcdBuildDefinitions.PcdBuildData> dynamicPcdBuildDataArray   = null;\r
+        String[]                                      tokenSpaceStrRet           = null;\r
+\r
+        //\r
+        // If FPD document is not be opened, open and initialize it.\r
+        // BUGBUG: The code should be moved into GlobalData in future.\r
+        //\r
+        if (fpdDocInstance == null) {\r
+            try {\r
+                fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
+            } catch(IOException ioE) {\r
+                throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
+            } catch(XmlException xmlE) {\r
+                throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
+            }\r
+        }\r
+\r
+        dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
+        if (dynamicPcdBuildDefinitions == null) {\r
+            exceptionString = String.format("[FPD file error] There are no <PcdDynamicBuildDescriptions> in FPD file but contains Dynamic type "+\r
+                                            "PCD entry %s in module %s!",\r
+                                            token.cName,\r
+                                            moduleName);\r
+            throw new EntityException(exceptionString);\r
+        }\r
+\r
+        dynamicPcdBuildDataArray = dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
+        for (index = 0; index < dynamicPcdBuildDataArray.size(); index ++) {\r
+            try {\r
+                tokenSpaceStrRet = GlobalData.getGuidInfoFromCname(dynamicPcdBuildDataArray.get(index).getTokenSpaceGuidCName());\r
+            } catch (Exception e) {\r
+                throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
+            }\r
+\r
+            if (tokenSpaceStrRet == null) {\r
+                throw new EntityException ("Fail to get token space guid for token " + dynamicPcdBuildDataArray.get(index).getCName());\r
+            }\r
+\r
+            dynamicPrimaryKey = Token.getPrimaryKeyString(dynamicPcdBuildDataArray.get(index).getCName(),\r
+                                                          tokenSpaceStrRet[1]);\r
+            if (dynamicPrimaryKey.equalsIgnoreCase(token.getPrimaryKeyString())) {\r
+                return dynamicPcdBuildDataArray.get(index);\r
+            }\r
+        }\r
+\r
+        return null;\r
+    }\r
+\r
+    /**\r
+       Override function: get all <DynamicPcdBuildDefinition> from FPD file.\r
+\r
+       @return List<DynamicPcdBuildDefinitions.PcdBuildData>\r
+    **/\r
+    public List<DynamicPcdBuildDefinitions.PcdBuildData>\r
+                                            getAllDynamicPcdInfoFromFpd()\r
+        throws EntityException {\r
+        DynamicPcdBuildDefinitions dynamicPcdBuildDefinitions = null;\r
+\r
+        //\r
+        // Open fpd document to get <DynamicPcdBuildDefinition> Section.\r
+        // BUGBUG: the function should be move GlobalData in furture.\r
+        //\r
+        if (fpdDocInstance == null) {\r
+            try {\r
+                fpdDocInstance = (PlatformSurfaceAreaDocument)XmlObject.Factory.parse(new File(fpdFilePath));\r
+            } catch(IOException ioE) {\r
+                throw new EntityException("File IO error for xml file:" + fpdFilePath + "\n" + ioE.getMessage());\r
+            } catch(XmlException xmlE) {\r
+                throw new EntityException("Can't parse the FPD xml fle:" + fpdFilePath + "\n" + xmlE.getMessage());\r
+            }\r
+        }\r
+\r
+        dynamicPcdBuildDefinitions = fpdDocInstance.getPlatformSurfaceArea().getDynamicPcdBuildDefinitions();\r
+        if (dynamicPcdBuildDefinitions == null) {\r
+            return null;\r
+        }\r
+\r
+        return dynamicPcdBuildDefinitions.getPcdBuildDataList();\r
+    }\r
+\r
+    /**\r
+      check parameter for this action.\r
+\r
+      @throws EntityException  Bad parameter.\r
+    **/\r
+    private void checkParameter() throws EntityException {\r
+        File file = null;\r
+\r
+        if((fpdFilePath    == null) ||(workspacePath  == null)) {\r
+            throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
+        }\r
+\r
+        if(fpdFilePath.length() == 0 || workspacePath.length() == 0) {\r
+            throw new EntityException("WorkspacePath and FPDFileName should be blank for CollectPCDAtion!");\r
+        }\r
+\r
+        file = new File(workspacePath);\r
+        if(!file.exists()) {\r
+            throw new EntityException("WorkpacePath " + workspacePath + " does not exist!");\r
+        }\r
+\r
+        file = new File(fpdFilePath);\r
+\r
+        if(!file.exists()) {\r
+            throw new EntityException("FPD File " + fpdFilePath + " does not exist!");\r
+        }\r
+    }\r
+\r
+    /**\r
+      Test case function\r
+\r
+      @param argv  parameter from command line\r
+    **/\r
+    public static void main(String argv[]) throws EntityException {\r
+        PlatformPcdPreprocessActionForBuilding ca = new PlatformPcdPreprocessActionForBuilding();\r
+        String projectDir = "x:/edk2";\r
+        ca.setWorkspacePath(projectDir);\r
+        ca.setFPDFilePath(projectDir + "/EdkNt32Pkg/Nt32.fpd");\r
+        ca.setActionMessageLevel(ActionMessage.MAX_MESSAGE_LEVEL);\r
+        GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
+                            projectDir,\r
+                            "tools_def.txt");\r
+        System.out.println("After initInfo!");\r
+        FpdParserTask fpt = new FpdParserTask();\r
+        fpt.parseFpdFile(new File(projectDir + "/EdkNt32Pkg/Nt32.fpd"));\r
+        ca.execute();\r
+    }\r
+}\r