X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FPcdTools%2Forg%2Ftianocore%2Fpcd%2Fentity%2FToken.java;h=74f55ddec31748b75e9528c4f07496757e775739;hp=d1867fba5bc76df5514f45f4ad33e72f644a0345;hb=a3222f6a718e983f319e327841cdcfbe624c27e9;hpb=f28c0830515daafb80e7b266df52b698b06b5079 diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java b/Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java index d1867fba5b..74f55ddec3 100644 --- a/Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java +++ b/Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java @@ -21,9 +21,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.tianocore.pcd.entity.UsageIdentification; -import org.tianocore.pcd.exception.EntityException; - /** This class is to descript a PCD token object. The information of a token mainly comes from MSA, SPD and setting produced by platform developer. @@ -32,7 +29,7 @@ public class Token { /// /// Enumeration macro defintion for PCD type. /// - public enum PCD_TYPE {FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODULE, DYNAMIC, + public static enum PCD_TYPE {FEATURE_FLAG, FIXED_AT_BUILD, PATCHABLE_IN_MODULE, DYNAMIC, DYNAMIC_EX, UNKNOWN} /// @@ -40,12 +37,12 @@ public class Token { /// Wizard maybe expand this type as "int, unsigned int, short, unsigned short etc" in /// prompt dialog. /// - public enum DATUM_TYPE {UINT8, UINT16, UINT32, UINT64, BOOLEAN, POINTER, UNKNOWN} + public static enum DATUM_TYPE {UINT8, UINT16, UINT32, UINT64, BOOLEAN, POINTER, UNKNOWN} /// /// Enumeration macor defintion for usage of PCD /// - public enum PCD_USAGE {ALWAYS_PRODUCED, ALWAYS_CONSUMED, SOMETIMES_PRODUCED, + public static enum PCD_USAGE {ALWAYS_PRODUCED, ALWAYS_CONSUMED, SOMETIMES_PRODUCED, SOMETIMES_CONSUMED, UNKNOWN} /// @@ -169,7 +166,7 @@ public class Token { /** The pcd type is DynamicEx? - + @retval true Is DynamicEx type @retval false not DynamicEx type **/ @@ -196,7 +193,7 @@ public class Token { if (tokenSpaceName == null) { return cName + "_nullTokenSpaceGuid"; } else { - return cName + "_" + tokenSpaceName.toString().replace('-', '_'); + return cName + "_" + tokenSpaceName.toString().replace('-', '_').toLowerCase(); } } @@ -285,16 +282,9 @@ public class Token { @retval TRUE - Success to add usage instance. @retval FALSE - Fail to add usage instance **/ - public boolean addUsageInstance(UsageInstance usageInstance) throws EntityException { - String exceptionStr; - + public boolean addUsageInstance(UsageInstance usageInstance) { if (isUsageInstanceExist(usageInstance.usageId)) { - exceptionStr = String.format("[PCD Collection Tool Exception] PCD %s for module %s has already exist in database, Please check all PCD build entries "+ - "in modules %s in to make sure no duplicated definitions in FPD file!", - usageInstance.parentToken.cName, - usageInstance.usageId.moduleName, - usageInstance.usageId.moduleName); - throw new EntityException(exceptionStr); + return false; } // @@ -631,7 +621,7 @@ public class Token { } /** - Judge whether a DYNAMIC PCD has default value. + Judge whether a DYNAMIC PCD has default value. @return whether a DYNAMIC PCD has default value. **/ @@ -832,12 +822,137 @@ public class Token { /** Get string value for ANSIC string type - + @return String the string value **/ public String getStringTypeString () { return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1); } + + /** + Judge whether a datum string is byte array. + + @param datum datum string + + @return boolean true - is byte array, false - not byte array + **/ + public static boolean isByteArrayDatum(String datum) { + if (datum == null) { + return false; + } + + String trimedStr = datum.trim(); + + if (trimedStr.length() == 0) { + return false; + } + + if (trimedStr.startsWith("{") && + trimedStr.endsWith("}")) { + return true; + } + + return false; + } + + /** + Judge whether a datum string is unicode. + + @param datum datum string + + @return boolean true - is unicode, false - not unicode + **/ + public static boolean isUnicodeDatum(String datum) { + if (datum == null) { + return false; + } + + String trimedStr = datum.trim(); + if (trimedStr.length() == 0) { + return false; + } + + if (trimedStr.startsWith("L") && + trimedStr.charAt(1) == '"' && + trimedStr.endsWith("\"")) { + return true; + } + + return false; + } + + /** + Judge whether a datum string is ANSCI string. + + @param datum datum string + + @return boolean true - is ANSIC, false - not ANSIC + **/ + public static boolean isAnsciDatum(String datum) { + if (datum == null) { + return false; + } + + String trimedStr = datum.trim(); + + if (trimedStr.length() == 0) { + return false; + } + + if (datum.startsWith("\"") && + datum.endsWith("\"")) { + return true; + } + + return false; + } + + /** + Get byte array string for POINTER type Datum. + + @param datum the datum whose type is POINTER + + @return String the byte array string + **/ + public String getByteArrayForPointerDatum(String datum) { + String byteArray = "{"; + + if (datumType != Token.DATUM_TYPE.POINTER) { + return null; + } + + if (Token.isAnsciDatum(datum)) { + String trimedStr = datum.trim(); + trimedStr = trimedStr.substring(1, trimedStr.length() - 1); + char charArray[] = trimedStr.toCharArray(); + for (int index = 0; index < charArray.length; index++) { + byteArray += String.format("0x%02x ", (byte)charArray[index]); + if (index != (charArray.length - 1)) { + byteArray += ","; + } + } + } else if (Token.isUnicodeDatum(datum)) { + String trimedStr = datum.trim(); + trimedStr = trimedStr.substring(2, trimedStr.length() - 1); + for (int index = 0; index < trimedStr.length(); index++) { + short unicodeVal = (short)trimedStr.codePointAt(index); + byteArray += String.format("0x%02x, 0x%02x", + (byte)unicodeVal, + (byte)((unicodeVal & 0xFF00) >> 8)); + if (index != (trimedStr.length() - 1)) { + byteArray += " ,"; + } + } + } else if (Token.isByteArrayDatum(datum)){ + return datum; + } else { + return null; + } + + byteArray += "}"; + + return byteArray; + } }