diff options
author | klu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-06-16 09:11:15 +0000 |
---|---|---|
committer | klu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-06-16 09:11:15 +0000 |
commit | f63ef4b2711b5d6255eca5f6e81e9c7454028803 (patch) | |
tree | b83161a0b2585d2ce4da8df5113f080fea74b8a8 | |
parent | 7c3e99c36eef533657b63e49f2272c1312409ae7 (diff) | |
download | edk2-f63ef4b2711b5d6255eca5f6e81e9c7454028803.zip edk2-f63ef4b2711b5d6255eca5f6e81e9c7454028803.tar.gz edk2-f63ef4b2711b5d6255eca5f6e81e9c7454028803.tar.bz2 |
1) Add byte element checking for a PCD who using byte array type datum.
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
-rw-r--r-- | Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java | 47 | ||||
-rw-r--r-- | Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java | 41 |
2 files changed, 72 insertions, 16 deletions
diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java index c9d9050..0ba5ec4 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java @@ -514,7 +514,7 @@ class LocalTokenNumberTable { str = String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString());
- if (token.isStringType()) {
+ if (token.isUnicodeStringType()) {
str += " | PCD_TYPE_STRING";
}
@@ -733,7 +733,7 @@ class PcdDatabase { return 4;
}
- if (token.isStringType()) {
+ if (token.isUnicodeStringType()) {
return 2;
}
@@ -965,7 +965,7 @@ class PcdDatabase { } else if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {
decl.add(getVpdEnableTypeDeclaration(token));
inst.add(getVpdEnableTypeInstantiation(token));
- } else if (token.isStringType()) {
+ } else if (token.isUnicodeStringType()) {
decl.add(getStringTypeDeclaration(token));
inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token));
}
@@ -1725,6 +1725,7 @@ public class CollectPCDAction { int value;
BigInteger value64;
String subStr;
+ int index;
if (moduleName == null) {
moduleName = "section <DynamicPcdBuildDefinitions>";
@@ -1923,7 +1924,7 @@ public class CollectPCDAction { if ((start > end) ||
(end > datum.length())||
((start == end) && (datum.length() > 0))) {
- exceptionString = String.format("The datum type of PCD %s in %s is VOID* and datum is "+
+ exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+
"a UNICODE string because start with L\", but format maybe"+
"is not right, correct UNICODE string is L\"...\"!",
cName,
@@ -1933,7 +1934,7 @@ public class CollectPCDAction { strValue = datum.substring(start + 1, end);
if ((strValue.length() * 2) > maxDatumSize) {
- exceptionString = String.format("The datum type of PCD %s in %s is VOID*, and datum is "+
+ exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+
"a UNICODE string, but the datum size is %d exceed to <MaxDatumSize> : %d",
cName,
moduleName,
@@ -1947,7 +1948,7 @@ public class CollectPCDAction { if ((start > end) ||
(end > datum.length())||
((start == end) && (datum.length() > 0))) {
- exceptionString = String.format("The datum type of PCD %s in %s is VOID* and datum is "+
+ exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID* and datum is "+
"a ANSCII string because start with \", but format maybe"+
"is not right, correct ANSIC string is \"...\"!",
cName,
@@ -1956,7 +1957,7 @@ public class CollectPCDAction { }
strValue = datum.substring(start + 1, end);
if ((strValue.length()) > maxDatumSize) {
- exceptionString = String.format("The datum type of PCD %s in %s is VOID*, and datum is "+
+ exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is "+
"a ANSCI string, but the datum size is %d which exceed to <MaxDatumSize> : %d",
cName,
moduleName,
@@ -1969,10 +1970,36 @@ public class CollectPCDAction { start = datum.indexOf('{');
end = datum.lastIndexOf('}');
- strValue = datum.substring(start, end);
+ strValue = datum.substring(start + 1, end);
+ strValue = strValue.trim();
+ if (strValue.length() == 0) {
+ break;
+ }
strValueArray = strValue.split(",");
+ for (index = 0; index < strValueArray.length; index ++) {
+ try{
+ value = Integer.decode(strValueArray[index]);
+ } catch (NumberFormatException nfeEx) {
+ exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and "+
+ "it is byte array in fact. For every byte in array should be a valid"+
+ "byte digital, but element %s is not a valid byte digital!",
+ cName,
+ moduleName,
+ strValueArray[index]);
+ return exceptionString;
+ }
+ if (value > 0xFF) {
+ exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, "+
+ "it is byte array in fact. But the element of %s exceed the byte range",
+ cName,
+ moduleName,
+ strValueArray[index]);
+ return exceptionString;
+ }
+ }
+
if (strValueArray.length > maxDatumSize) {
- exceptionString = String.format("The datum type of PCD %s in %s is VOID*, and datum is byte"+
+ exceptionString = String.format("[FPD file error] The datum type of PCD %s in %s is VOID*, and datum is byte"+
"array, but the number of bytes is %d which exceed to <MaxDatumSzie> : %d!",
cName,
moduleName,
@@ -1981,7 +2008,7 @@ public class CollectPCDAction { return exceptionString;
}
} else {
- exceptionString = String.format("The datum type of PCD %s in %s is VOID*. For VOID* type, you have three format choise:\n "+
+ 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 "+
"1) UNICODE string: like L\"xxxx\";\r\n"+
"2) ANSIC string: like \"xxx\";\r\n"+
"3) Byte array: like {0x2, 0x45, 0x23}\r\n"+
diff --git a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java index f5765e1..bce2ec9 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java +++ b/Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java @@ -540,6 +540,28 @@ public class Token { return null;
}
+
+ /**
+ Get default value for a token, For HII type, HiiDefaultValue of default
+ SKU 0 will be returned; For Default type, the defaultvalue of default SKU
+ 0 will be returned.
+
+ @return String
+ */
+ public String getDynamicDefaultValue() {
+ DynamicTokenValue dynamicData = getDefaultSku();
+ if (hasDefaultValue()) {
+ switch (dynamicData.type) {
+ case HII_TYPE:
+ return dynamicData.hiiDefaultValue;
+ case DEFAULT_TYPE:
+ return dynamicData.value;
+ }
+ }
+
+ return null;
+ }
+
//
// BugBug: We need change this algorithm accordingly when schema is updated
// to support no default value.
@@ -616,13 +638,20 @@ public class Token { return false;
}
- public boolean isStringType () {
- String str = getDefaultSku().value;
+ /**
+ Judege whether current value is UNICODE string type.
+ @return boolean
+ */
+ public boolean isUnicodeStringType () {
+ String str = getDynamicDefaultValue();
+
+ if (str == null) {
+ return false;
+ }
- //
- // BUGBUG: need scott confirmation.
- //
- if (datumType == Token.DATUM_TYPE.POINTER) {
+ if (datumType == Token.DATUM_TYPE.POINTER &&
+ str.startsWith("L\"") &&
+ str.endsWith("\"")) {
return true;
}
|