]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1) Add byte element checking for a PCD who using byte array type datum.
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 16 Jun 2006 09:11:15 +0000 (09:11 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 16 Jun 2006 09:11:15 +0000 (09:11 +0000)
2) Fix a bug for judging whether datum is Unicode string.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@537 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java

index c9d905047640e9af607358cdc191bf62a69711f8..0ba5ec4a7f3c9958d8b722c1f9aad102013434f5 100644 (file)
@@ -514,7 +514,7 @@ class LocalTokenNumberTable {
 \r
         str =  String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString());\r
 \r
-        if (token.isStringType()) {\r
+        if (token.isUnicodeStringType()) {\r
             str += " | PCD_TYPE_STRING";\r
         }\r
 \r
@@ -733,7 +733,7 @@ class PcdDatabase {
             return 4;\r
         }\r
 \r
-        if (token.isStringType()) {\r
+        if (token.isUnicodeStringType()) {\r
             return 2;\r
         }\r
 \r
@@ -965,7 +965,7 @@ class PcdDatabase {
                 } else if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {\r
                     decl.add(getVpdEnableTypeDeclaration(token));\r
                     inst.add(getVpdEnableTypeInstantiation(token));\r
-                } else if (token.isStringType()) {\r
+                } else if (token.isUnicodeStringType()) {\r
                     decl.add(getStringTypeDeclaration(token));\r
                     inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token));\r
                 }\r
@@ -1725,6 +1725,7 @@ public class CollectPCDAction {
         int         value;\r
         BigInteger  value64;\r
         String      subStr;\r
+        int         index;\r
 \r
         if (moduleName == null) {\r
             moduleName = "section <DynamicPcdBuildDefinitions>";\r
@@ -1923,7 +1924,7 @@ public class CollectPCDAction {
                 if ((start > end)           || \r
                     (end   > datum.length())||\r
                     ((start == end) && (datum.length() > 0))) {\r
-                    exceptionString = String.format("The datum type of PCD %s in %s is VOID* and datum is "+\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
@@ -1933,7 +1934,7 @@ public class CollectPCDAction {
 \r
                 strValue    = datum.substring(start + 1, end);\r
                 if ((strValue.length() * 2) > maxDatumSize) {\r
-                    exceptionString = String.format("The datum type of PCD %s in %s is VOID*, and datum is "+\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
@@ -1947,7 +1948,7 @@ public class CollectPCDAction {
                 if ((start > end)           || \r
                     (end   > datum.length())||\r
                     ((start == end) && (datum.length() > 0))) {\r
-                    exceptionString = String.format("The datum type of PCD %s in %s is VOID* and datum is "+\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
@@ -1956,7 +1957,7 @@ public class CollectPCDAction {
                 }\r
                 strValue    = datum.substring(start + 1, end);\r
                 if ((strValue.length()) > maxDatumSize) {\r
-                    exceptionString = String.format("The datum type of PCD %s in %s is VOID*, and datum is "+\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
@@ -1969,10 +1970,36 @@ public class CollectPCDAction {
 \r
                 start           = datum.indexOf('{');\r
                 end             = datum.lastIndexOf('}');\r
-                strValue        = datum.substring(start, end);\r
+                strValue        = datum.substring(start + 1, end);\r
+                strValue        = strValue.trim();\r
+                if (strValue.length() == 0) {\r
+                    break;\r
+                }\r
                 strValueArray   = strValue.split(",");\r
+                for (index = 0; index < strValueArray.length; index ++) {\r
+                    try{\r
+                        value = Integer.decode(strValueArray[index]);\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("The datum type of PCD %s in %s is VOID*, and datum is byte"+\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
@@ -1981,7 +2008,7 @@ public class CollectPCDAction {
                     return exceptionString;\r
                 }\r
             } else {\r
-                exceptionString = String.format("The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+\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
index f5765e1d408fa1e9b7ef2ffc8452235bed26f34d..bce2ec9ad21ecea6119a3d6e1a5de986b5b67b5e 100644 (file)
@@ -540,6 +540,28 @@ public class Token {
 \r
         return null;\r
     }\r
+\r
+    /**\r
+       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
+       @return String\r
+     */\r
+    public String getDynamicDefaultValue() {\r
+        DynamicTokenValue dynamicData = getDefaultSku();\r
+        if (hasDefaultValue()) {\r
+            switch (dynamicData.type) {\r
+            case HII_TYPE:\r
+                return dynamicData.hiiDefaultValue;\r
+            case DEFAULT_TYPE:\r
+                return dynamicData.value;\r
+            }\r
+        }\r
+\r
+        return null;\r
+    }\r
+\r
     //\r
     // BugBug: We need change this algorithm accordingly when schema is updated\r
     //          to support no default value.\r
@@ -616,13 +638,20 @@ public class Token {
         return false;\r
     }\r
 \r
-    public boolean isStringType () {\r
-        String str = getDefaultSku().value;\r
+    /**\r
+       Judege whether current value is UNICODE string type.\r
+       @return boolean\r
+     */\r
+    public boolean isUnicodeStringType () {\r
+        String str = getDynamicDefaultValue();\r
+\r
+        if (str == null) {\r
+            return false;\r
+        }\r
 \r
-        //\r
-        // BUGBUG: need scott confirmation.\r
-        // \r
-        if (datumType == Token.DATUM_TYPE.POINTER) {\r
+        if (datumType == Token.DATUM_TYPE.POINTER &&\r
+            str.startsWith("L\"") && \r
+            str.endsWith("\"")) {\r
             return true;\r
         }\r
 \r