Fix track EDKT213: PCD value size should be specificed when generate const variable...
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 29 Aug 2006 05:28:36 +0000 (05:28 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 29 Aug 2006 05:28:36 +0000 (05:28 +0000)
The fixing work is translate the ANSIC string or Unicode string to byte array for PATCHABLE_IN_MODULE PCD.

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

Tools/Source/PcdTools/org/tianocore/pcd/entity/Token.java
Tools/Source/PcdTools/org/tianocore/pcd/entity/UsageInstance.java

index ed71742..74f55dd 100644 (file)
@@ -828,6 +828,131 @@ public class Token {
     public String getStringTypeString () {\r
         return getDefaultSku().value.substring(2, getDefaultSku().value.length() - 1);\r
     }\r
+\r
+    /**\r
+       Judge whether a datum string is byte array.\r
+       \r
+       @param datum             datum string\r
+       \r
+       @return boolean          true - is byte array, false - not byte array\r
+    **/\r
+    public static boolean isByteArrayDatum(String datum) {\r
+        if (datum == null) {\r
+            return false;\r
+        }\r
+\r
+        String trimedStr = datum.trim();\r
+\r
+        if (trimedStr.length() == 0) {\r
+            return false;\r
+        }\r
+\r
+        if (trimedStr.startsWith("{") && \r
+            trimedStr.endsWith("}")) {\r
+            return true;\r
+        }\r
+\r
+        return false;\r
+    }\r
+\r
+    /**\r
+       Judge whether a datum string is unicode.\r
+       \r
+       @param datum             datum string\r
+       \r
+       @return boolean          true - is unicode, false - not unicode\r
+    **/\r
+    public static boolean isUnicodeDatum(String datum) {\r
+        if (datum  == null) {\r
+            return false;\r
+        }\r
+\r
+        String trimedStr = datum.trim();\r
+        if (trimedStr.length() == 0) {\r
+            return false;\r
+        }\r
+\r
+        if (trimedStr.startsWith("L")  &&\r
+            trimedStr.charAt(1) == '"' &&\r
+            trimedStr.endsWith("\"")) {\r
+            return true;\r
+        }\r
+\r
+        return false;\r
+    }\r
+\r
+    /**\r
+       Judge whether a datum string is ANSCI string.\r
+       \r
+       @param datum             datum string\r
+       \r
+       @return boolean          true - is ANSIC, false - not ANSIC\r
+    **/\r
+    public static boolean isAnsciDatum(String datum) {\r
+        if (datum == null) {\r
+            return false;\r
+        }\r
+\r
+        String trimedStr = datum.trim();\r
+\r
+        if (trimedStr.length() == 0) {\r
+            return false;\r
+        }\r
+\r
+        if (datum.startsWith("\"") &&\r
+            datum.endsWith("\"")) {\r
+            return true;\r
+        }\r
+\r
+        return false;\r
+    }\r
+\r
+    /**\r
+       Get byte array string for POINTER type Datum.\r
+       \r
+       @param datum         the datum whose type is POINTER\r
+       \r
+       @return String       the byte array string\r
+    **/\r
+    public String getByteArrayForPointerDatum(String datum) {\r
+        String byteArray = "{";\r
+\r
+        if (datumType != Token.DATUM_TYPE.POINTER) {\r
+            return null;\r
+        }\r
+\r
+        if (Token.isAnsciDatum(datum)) {\r
+            String trimedStr = datum.trim();\r
+            trimedStr = trimedStr.substring(1, trimedStr.length() - 1);\r
+            char charArray[] = trimedStr.toCharArray();\r
+            for (int index = 0; index < charArray.length; index++) {\r
+                byteArray += String.format("0x%02x ", (byte)charArray[index]);\r
+                if (index != (charArray.length - 1)) {\r
+                    byteArray += ",";\r
+                }\r
+            }\r
+        } else if (Token.isUnicodeDatum(datum)) {\r
+            String trimedStr = datum.trim();\r
+            trimedStr = trimedStr.substring(2, trimedStr.length() - 1);\r
+            for (int index = 0; index < trimedStr.length(); index++) {\r
+                short unicodeVal = (short)trimedStr.codePointAt(index);\r
+                byteArray += String.format("0x%02x, 0x%02x", \r
+                                           (byte)unicodeVal,\r
+                                           (byte)((unicodeVal & 0xFF00) >> 8));\r
+                if (index != (trimedStr.length() - 1)) {\r
+                    byteArray += " ,";\r
+                }\r
+            }\r
+        } else if (Token.isByteArrayDatum(datum)){\r
+            return datum;\r
+        } else {\r
+            return null;\r
+        }\r
+\r
+        byteArray += "}";\r
+\r
+        return byteArray;\r
+    }\r
 }\r
 \r
 \r
index 03499e6..2484453 100644 (file)
@@ -327,7 +327,7 @@ public class UsageInstance {
             }\r
             break;\r
         case PATCHABLE_IN_MODULE:\r
-            if (isByteArray) {\r
+            if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
                 //\r
                 // Example autogen string for following generation:\r
                 // "extern UINT8 _gPcd_BinaryPatch_PcdSampleToken[];"\r
@@ -342,6 +342,21 @@ public class UsageInstance {
                                              Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
                                              parentToken.cName,\r
                                              parentToken.cName);\r
+                //\r
+                // Example autogen string for following generation:\r
+                // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_PcdSampleToken, (Buffer), (SizeOfBuffer))"\r
+                // \r
+                hAutogenStr += String.format("#define _PCD_PATCHABLE_%s_SIZE %d\r\n",\r
+                                             parentToken.cName,\r
+                                             parentToken.datumSize);\r
+                hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) "+\r
+                                             "LibPatchPcdSetPtr (_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, "+\r
+                                             "(SizeOfBuffer), (Buffer))\r\n",\r
+                                             Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
+                                             parentToken.cName,\r
+                                             parentToken.cName,\r
+                                             parentToken.cName);\r
+\r
             } else {\r
                 //\r
                 // Example autogen string for following generation:\r
@@ -358,27 +373,6 @@ public class UsageInstance {
                                              Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
                                              parentToken.cName,\r
                                              parentToken.cName);\r
-            }\r
-\r
-            //\r
-            // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro\r
-            //\r
-            if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
-                //\r
-                // Example autogen string for following generation:\r
-                // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_PcdSampleToken, (Buffer), (SizeOfBuffer))"\r
-                // \r
-                hAutogenStr += String.format("#define _PCD_PATCHABLE_%s_SIZE %d\r\n",\r
-                                             parentToken.cName,\r
-                                             parentToken.datumSize);\r
-                hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) "+\r
-                                             "LibPatchPcdSetPtr (_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, "+\r
-                                             "(SizeOfBuffer), (Buffer))\r\n",\r
-                                             Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
-                                             parentToken.cName,\r
-                                             parentToken.cName,\r
-                                             parentToken.cName);\r
-            } else {\r
                 //\r
                 // Example autogen string for following generation:\r
                 // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) (_gPcd_BinaryPatch_PcdSampleToken = (Value))"\r
@@ -390,6 +384,9 @@ public class UsageInstance {
             }\r
 \r
             if (!isBuildUsedLibrary) {\r
+                if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
+                    printDatum = parentToken.getByteArrayForPointerDatum(printDatum);\r
+                }\r
                 //\r
                 // Example autogen string for following generation:\r
                 // "#define _PCD_VALUE_PcdSampleToken   0x111"\r
@@ -397,7 +394,7 @@ public class UsageInstance {
                 hAutogenStr += String.format("#define _PCD_VALUE_%s   %s\r\n",\r
                                              parentToken.cName,\r
                                              printDatum);\r
-                if (isByteArray) {\r
+                if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
                     //\r
                     // Example autogen string for following generation:\r
                     // "GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"\r