]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java
Abstract the logic of Platform pcd preprocess according to FPD file to a class. And...
[mirror_edk2.git] / Tools / Source / PcdTools / org / tianocore / pcd / entity / Token.java
index 2e2a297aa025c591566fa339eaaa6518d93baaf9..8429dfd0036ca8ee114f02739370739b4c7f954a 100644 (file)
@@ -2,17 +2,17 @@
   Token class.\r
 \r
   This module contains all classes releted to PCD token.\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
-**/  \r
+**/\r
 package org.tianocore.pcd.entity;\r
 \r
 import java.math.BigInteger;\r
@@ -20,25 +20,24 @@ import java.util.ArrayList;
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
-import java.util.UUID;\r
 \r
 import org.tianocore.pcd.entity.UsageIdentification;\r
 import org.tianocore.pcd.exception.EntityException;\r
 \r
-/** This class is to descript a PCD token object. The information of a token mainly \r
-    comes from MSA, SPD and setting produced by platform developer. \r
+/**\r
+   This class is to descript a PCD token object. The information of a token mainly\r
+   comes from MSA, SPD and setting produced by platform developer.\r
 **/\r
 public class Token {\r
     ///\r
     /// Enumeration macro defintion for PCD type.\r
-    /// BUGBUG: Not use upcase charater is to facility for reading. It may be changed\r
-    ///         in coding review.\r
-    public enum             PCD_TYPE {FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODULE, DYNAMIC, \r
+    ///\r
+    public enum             PCD_TYPE {FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODULE, DYNAMIC,\r
                                       DYNAMIC_EX, UNKNOWN}\r
 \r
     ///\r
     /// Enumeration macro definition for datum type. All type mainly comes from ProcessBind.h.\r
-    /// Wizard maybe expand this type as "int, unsigned int, short, unsigned short etc" in \r
+    /// Wizard maybe expand this type as "int, unsigned int, short, unsigned short etc" in\r
     /// prompt dialog.\r
     ///\r
     public enum             DATUM_TYPE {UINT8, UINT16, UINT32, UINT64, BOOLEAN, POINTER, UNKNOWN}\r
@@ -57,7 +56,7 @@ public class Token {
 \r
     ///\r
     /// Token space name is the guid defined by token itself in package or module level. This\r
-    /// name mainly for DynamicEx type. For other PCD type token, his token space name is the \r
+    /// name mainly for DynamicEx type. For other PCD type token, his token space name is the\r
     /// assignedtokenSpaceName as follows.\r
     /// tokenSpaceName is defined in MSA, SPD, FPD, can be regarded as primary key with cName.\r
     ///\r
@@ -71,24 +70,24 @@ public class Token {
     public long             tokenNumber;\r
 \r
     ///\r
-    /// This token number is retrieved from FPD file for DynamicEx type. \r
-    /// \r
+    /// This token number is retrieved from FPD file for DynamicEx type.\r
+    ///\r
     public long             dynamicExTokenNumber;\r
 \r
     ///\r
     /// All supported PCD type, this value can be retrieved from SPD\r
     /// Currently, only record all PCD type for this token in FPD file.\r
-    /// \r
+    ///\r
     public List<PCD_TYPE>   supportedPcdType;\r
 \r
     ///\r
     /// If the token's item type is Dynamic or DynamicEx type, isDynamicPCD\r
     /// is true.\r
-    /// \r
+    ///\r
     public boolean          isDynamicPCD;\r
 \r
     ///\r
-    /// datumSize is to descript the fix size or max size for this token. \r
+    /// datumSize is to descript the fix size or max size for this token.\r
     /// datumSize is defined in SPD.\r
     ///\r
     public int              datumSize;\r
@@ -102,7 +101,7 @@ public class Token {
 \r
     ///\r
     /// skuData contains all value for SkuNumber of token.\r
-    /// This field is for Dynamic or DynamicEx type PCD, \r
+    /// This field is for Dynamic or DynamicEx type PCD,\r
     ///\r
     public List<SkuInstance> skuData;\r
 \r
@@ -113,7 +112,7 @@ public class Token {
 \r
     /**\r
        Constructure function for Token class\r
-       \r
+\r
        @param cName             The name of token\r
        @param tokenSpaceName    The name of token space, it is a guid string\r
     **/\r
@@ -131,10 +130,10 @@ public class Token {
 \r
     /**\r
       updateSupportPcdType\r
-      \r
+\r
       SupportPcdType should be gotten from SPD file actually, but now it just\r
       record all PCD type for this token in FPD file.\r
-      \r
+\r
       @param pcdType    new PCD type found in FPD file for this token.\r
     **/\r
     public void updateSupportPcdType(PCD_TYPE pcdType) {\r
@@ -146,16 +145,16 @@ public class Token {
 \r
         //\r
         // If not found, add the pcd type to member variable supportedPcdType\r
-        // \r
+        //\r
         supportedPcdType.add(pcdType);\r
     }\r
 \r
     /**\r
        Judge whether pcdType is belong to dynamic type. Dynamic type includes\r
        DYNAMIC and DYNAMIC_EX.\r
-       \r
+\r
        @param pcdType       the judged pcd type\r
-       \r
+\r
        @return boolean\r
      */\r
     public static boolean isDynamic(PCD_TYPE pcdType) {\r
@@ -173,16 +172,16 @@ public class Token {
                 return true;\r
             }\r
         }\r
-        \r
+\r
         return false;\r
     }\r
 \r
     /**\r
       Use "TokencName + "-" + SpaceTokenName" as primary key when adding token into database\r
-      \r
+\r
       @param   cName                     Token name.\r
       @param   tokenSpaceName            The token space guid string defined in MSA or SPD\r
-      \r
+\r
       @retval  primary key for this token in token database.\r
     **/\r
     public static String getPrimaryKeyString(String cName, String tokenSpaceName) {\r
@@ -195,7 +194,7 @@ public class Token {
 \r
     /**\r
        If skudata list contains more than one data, then Sku mechanism is enable.\r
-       \r
+\r
        @retval boolean  if the number of sku data exceed to 1\r
      */\r
     public boolean isSkuEnable() {\r
@@ -207,7 +206,7 @@ public class Token {
 \r
     /**\r
        If Hii type for value of token\r
-       \r
+\r
        @return boolean\r
     **/\r
     public boolean isHiiEnable() {\r
@@ -219,7 +218,7 @@ public class Token {
 \r
     /**\r
        If Vpd type for value of token\r
-       \r
+\r
        @return boolean\r
     **/\r
     public boolean isVpdEnable() {\r
@@ -231,7 +230,7 @@ public class Token {
 \r
     /**\r
        Get the token primary key in token database.\r
-       \r
+\r
        @return String\r
      */\r
     public String getPrimaryKeyString () {\r
@@ -240,14 +239,14 @@ public class Token {
 \r
     /**\r
       Judge datumType is valid\r
-      \r
+\r
       @param type  The datumType want to be judged.\r
-      \r
+\r
       @retval TRUE  - The type is valid.\r
       @retval FALSE - The type is invalid.\r
     **/\r
     public static boolean isValiddatumType(DATUM_TYPE type) {\r
-        if ((type.ordinal() < DATUM_TYPE.UINT8.ordinal() ) || \r
+        if ((type.ordinal() < DATUM_TYPE.UINT8.ordinal() ) ||\r
             (type.ordinal() > DATUM_TYPE.POINTER.ordinal())) {\r
             return false;\r
         }\r
@@ -256,14 +255,14 @@ public class Token {
 \r
     /**\r
       Judge pcdType is valid\r
-      \r
+\r
       @param  type The PCdType want to be judged.\r
-      \r
+\r
       @retval TRUE  - The type is valid.\r
       @retval FALSE - The type is invalid.\r
     **/\r
     public static boolean isValidpcdType(PCD_TYPE  type) {\r
-        if ((type.ordinal() < PCD_TYPE.FEATURE_FLAG.ordinal() ) || \r
+        if ((type.ordinal() < PCD_TYPE.FEATURE_FLAG.ordinal() ) ||\r
             (type.ordinal() > PCD_TYPE.DYNAMIC_EX.ordinal())) {\r
             return false;\r
         }\r
@@ -272,9 +271,9 @@ public class Token {
 \r
     /**\r
       Add an usage instance for token\r
-      \r
+\r
       @param usageInstance   The usage instance\r
-     \r
+\r
       @retval TRUE  - Success to add usage instance.\r
       @retval FALSE - Fail to add usage instance\r
     **/\r
@@ -292,7 +291,7 @@ public class Token {
 \r
         //\r
         // Put usage instance into usage instance database of this PCD token.\r
-        // \r
+        //\r
         consumers.put(usageInstance.getPrimaryKey(), usageInstance);\r
 \r
         return true;\r
@@ -300,9 +299,9 @@ public class Token {
 \r
     /**\r
        Judge whether exist an usage instance for this token\r
-       \r
+\r
        @param usageId       The UsageInstance identification for usage instance\r
-       \r
+\r
        @return boolean      whether exist an usage instance for this token.\r
      */\r
     public boolean isUsageInstanceExist(UsageIdentification usageId) {\r
@@ -313,9 +312,9 @@ public class Token {
 \r
     /**\r
       Get the PCD_TYPE according to the string of PCD_TYPE\r
-      \r
+\r
       @param pcdTypeStr    The string of PCD_TYPE\r
-      \r
+\r
       @return PCD_TYPE\r
     **/\r
     public static PCD_TYPE getpcdTypeFromString(String pcdTypeStr) {\r
@@ -340,9 +339,9 @@ public class Token {
 \r
     /**\r
       Get the string of given datumType. This string will be used for generating autogen files\r
-     \r
+\r
       @param datumType   Given datumType\r
-     \r
+\r
       @return The string of datum type.\r
     **/\r
     public static String getStringOfdatumType(DATUM_TYPE  datumType) {\r
@@ -365,9 +364,9 @@ public class Token {
 \r
     /**\r
       Get the datumType according to a string.\r
-      \r
+\r
       @param datumTypeStr    The string of datumType\r
-     \r
+\r
       @return DATUM_TYPE\r
     **/\r
     public static DATUM_TYPE getdatumTypeFromString(String datumTypeStr) {\r
@@ -389,9 +388,9 @@ public class Token {
 \r
     /**\r
       Get string of given pcdType\r
-      \r
+\r
       @param pcdType  The given PcdType\r
-      \r
+\r
       @return The string of PCD_TYPE.\r
     **/\r
     public static String getStringOfpcdType(PCD_TYPE pcdType) {\r
@@ -412,9 +411,9 @@ public class Token {
 \r
     /**\r
       Get the PCD_USAGE according to a string\r
-      \r
+\r
       @param usageStr  The string of PCD_USAGE\r
-      \r
+\r
       @return The PCD_USAGE\r
     **/\r
     public static PCD_USAGE getUsageFromString(String usageStr) {\r
@@ -437,9 +436,9 @@ public class Token {
 \r
     /**\r
       Get the string of given PCD_USAGE\r
-      \r
+\r
       @param   usage   The given PCD_USAGE\r
-      \r
+\r
       @return The string of PDC_USAGE.\r
     **/\r
     public static String getStringOfUsage(PCD_USAGE usage) {\r
@@ -458,14 +457,14 @@ public class Token {
 \r
     /**\r
       Get the Defined datumType string for autogen. The string is for generating some MACROs in Autogen.h\r
-      \r
+\r
       @param datumType The given datumType\r
 \r
       @return string of datum type for autogen.\r
     **/\r
     public static String GetAutogenDefinedatumTypeString(DATUM_TYPE datumType) {\r
         switch (datumType) {\r
-        \r
+\r
         case UINT8:\r
             return "8";\r
         case UINT16:\r
@@ -485,7 +484,7 @@ public class Token {
 \r
     /**\r
       Get the datumType String for Autogen. This string will be used for generating defintions of PCD token in autogen\r
-      \r
+\r
       @param datumType   The given datumType\r
 \r
       @return string of datum type.\r
@@ -511,7 +510,7 @@ public class Token {
 \r
     /**\r
       Get the datumType string for generating some MACROs in autogen file of Library\r
-      \r
+\r
       @param   datumType  The given datumType\r
 \r
       @return String of datum for genrating bit charater.\r
@@ -537,11 +536,10 @@ public class Token {
 \r
     /**\r
        Get the sku data who id is 0.\r
-       \r
+\r
        @retval DynamicTokenValue    the value of this dyanmic token.\r
     **/\r
     public DynamicTokenValue getDefaultSku() {\r
-        DynamicTokenValue dynamicData;\r
         int               index;\r
 \r
         for (index = 0; index < this.skuData.size(); index ++) {\r
@@ -555,7 +553,7 @@ public class Token {
 \r
     /**\r
        Get the number of Sku data for this token\r
-       \r
+\r
        @retval int the number of sku data\r
     **/\r
     public int getSkuIdCount () {\r
@@ -564,9 +562,9 @@ public class Token {
 \r
     /**\r
        Get the size of PCD value, this PCD is POINTER type.\r
-       \r
+\r
        @param str   the string of the value\r
-       @param al    \r
+       @param al\r
     **/\r
     private void getCurrentSizeFromDefaultValue (String str, ArrayList<Integer> al) {\r
         if (isValidNullValue(str)) {\r
@@ -590,11 +588,11 @@ public class Token {
             } else if (str.startsWith("{")) {\r
                 //\r
                 // We count the number of "," in the string.\r
-                // The number of byte is one plus the number of \r
+                // The number of byte is one plus the number of\r
                 // comma.\r
                 //\r
                 String str2 = str;\r
-                \r
+\r
                 int cnt = 0;\r
                 int pos = 0;\r
                 pos = str2.indexOf(",", 0);\r
@@ -612,17 +610,17 @@ public class Token {
     /**\r
        This method can be used to get the MAX and current size\r
        for pointer type dynamic(ex) PCD entry\r
-    **/ \r
+    **/\r
     public ArrayList<Integer> getPointerTypeSize () {\r
         ArrayList<Integer> al = new ArrayList<Integer>();\r
-        \r
+\r
         //\r
         // For VPD_enabled and HII_enabled, we can only return the MAX size.\r
         // For the default DATA type dynamic PCD entry, we will return\r
         // the MAX size and current size for each SKU_ID.\r
         //\r
         al.add(new Integer(this.datumSize));\r
-        \r
+\r
         if (!this.isVpdEnable()) {\r
             int idx;\r
             if (this.isHiiEnable()){\r
@@ -637,7 +635,7 @@ public class Token {
                 }\r
             }\r
         }\r
-        \r
+\r
         return al;\r
     }\r
 \r
@@ -645,7 +643,7 @@ public class Token {
        Get default value for a token, For HII type, HiiDefaultValue of default\r
        SKU 0 will be returned; For Default type, the defaultvalue of default SKU\r
        0 will be returned.\r
-       \r
+\r
        @return String\r
      */\r
     public String getDynamicDefaultValue() {\r
@@ -665,14 +663,12 @@ public class Token {
     //          to support no default value.\r
     //\r
     public boolean hasDefaultValue () {\r
-        int               value         = 0;\r
-        boolean           isInteger     = true;\r
         DynamicTokenValue dynamicValue  = null;\r
 \r
         if (isSkuEnable()) {\r
             return true;\r
         }\r
-        \r
+\r
         if (this.isDynamicPCD) {\r
             dynamicValue = getDefaultSku();\r
             switch (dynamicValue.type) {\r
@@ -690,9 +686,9 @@ public class Token {
 \r
     /**\r
        Judge the value is NULL value. NULL value means the value is uninitialized value\r
-       \r
+\r
        @param judgedValue\r
-       \r
+\r
        @return boolean\r
      */\r
     public boolean isValidNullValue(String judgedValue) {\r
@@ -704,7 +700,7 @@ public class Token {
         case UINT16:\r
         case UINT32:\r
             if (judgedValue.length() > 2) {\r
-                if ((judgedValue.charAt(0) == '0')        && \r
+                if ((judgedValue.charAt(0) == '0')        &&\r
                     ((judgedValue.charAt(1) == 'x') || (judgedValue.charAt(1) == 'X'))){\r
                     subStr      = judgedValue.substring(2, judgedValue.length());\r
                     bigIntValue = new BigInteger(subStr, 16);\r
@@ -720,7 +716,7 @@ public class Token {
             break;\r
         case UINT64:\r
             if (judgedValue.length() > 2){\r
-                if ((judgedValue.charAt(0) == '0') && \r
+                if ((judgedValue.charAt(0) == '0') &&\r
                     ((judgedValue.charAt(1) == 'x') ||\r
                      (judgedValue.charAt(1) == 'X'))) {\r
                     bigIntValue = new BigInteger(judgedValue.substring(2, judgedValue.length()),  16);\r
@@ -759,34 +755,34 @@ public class Token {
 \r
     /**\r
        Is the string value in Unicode\r
-       \r
+\r
        @return boolean\r
     **/\r
     public boolean isHiiDefaultValueUnicodeStringType() {\r
         DynamicTokenValue dynamicData = getDefaultSku();\r
-        \r
+\r
         if (dynamicData == null)\r
             return false;\r
-        \r
+\r
         return dynamicData.hiiDefaultValue.startsWith("L\"")\r
                 && dynamicData.hiiDefaultValue.endsWith("\"");\r
     }\r
 \r
     /**\r
        Is the string value in ANSCI\r
-       \r
+\r
        @return boolean\r
     **/\r
     public boolean isHiiDefaultValueASCIIStringType() {\r
         DynamicTokenValue dynamicData = getDefaultSku();\r
-    \r
+\r
         if (dynamicData == null)\r
             return false;\r
-        \r
+\r
         return dynamicData.hiiDefaultValue.startsWith("\"")\r
         && dynamicData.hiiDefaultValue.endsWith("\"");\r
     }\r
-    \r
+\r
     /**\r
        Judege whether current value is UNICODE string type.\r
        @return boolean\r
@@ -799,14 +795,14 @@ public class Token {
         }\r
 \r
         if (datumType == Token.DATUM_TYPE.POINTER &&\r
-            str.startsWith("L\"") && \r
+            str.startsWith("L\"") &&\r
             str.endsWith("\"")) {\r
             return true;\r
         }\r
 \r
         return false;\r
     }\r
-    \r
+\r
     public boolean isASCIIStringType () {\r
         String str = getDynamicDefaultValue();\r
 \r
@@ -815,7 +811,7 @@ public class Token {
         }\r
 \r
         if (datumType == Token.DATUM_TYPE.POINTER &&\r
-            str.startsWith("\"") && \r
+            str.startsWith("\"") &&\r
             str.endsWith("\"")) {\r
             return true;\r
         }\r
@@ -831,16 +827,16 @@ public class Token {
         }\r
 \r
         if (datumType == Token.DATUM_TYPE.POINTER &&\r
-            str.startsWith("{") && \r
+            str.startsWith("{") &&\r
             str.endsWith("}")) {\r
             return true;\r
         }\r
 \r
         return false;\r
-        \r
+\r
     }\r
 \r
-    public String getStringTypeString () {                       \r
+    public String getStringTypeString () {\r
         return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1);\r
     }\r
 }\r