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
This commit is contained in:
klu2 2006-06-16 09:11:15 +00:00
parent 7c3e99c36e
commit f63ef4b271
2 changed files with 72 additions and 16 deletions

View File

@ -514,7 +514,7 @@ class LocalTokenNumberTable {
str = String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString()); str = String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString());
if (token.isStringType()) { if (token.isUnicodeStringType()) {
str += " | PCD_TYPE_STRING"; str += " | PCD_TYPE_STRING";
} }
@ -733,7 +733,7 @@ class PcdDatabase {
return 4; return 4;
} }
if (token.isStringType()) { if (token.isUnicodeStringType()) {
return 2; return 2;
} }
@ -965,7 +965,7 @@ class PcdDatabase {
} else if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) { } else if (token.getDefaultSku().type == DynamicTokenValue.VALUE_TYPE.VPD_TYPE) {
decl.add(getVpdEnableTypeDeclaration(token)); decl.add(getVpdEnableTypeDeclaration(token));
inst.add(getVpdEnableTypeInstantiation(token)); inst.add(getVpdEnableTypeInstantiation(token));
} else if (token.isStringType()) { } else if (token.isUnicodeStringType()) {
decl.add(getStringTypeDeclaration(token)); decl.add(getStringTypeDeclaration(token));
inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token)); inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token));
} }
@ -1725,6 +1725,7 @@ public class CollectPCDAction {
int value; int value;
BigInteger value64; BigInteger value64;
String subStr; String subStr;
int index;
if (moduleName == null) { if (moduleName == null) {
moduleName = "section <DynamicPcdBuildDefinitions>"; moduleName = "section <DynamicPcdBuildDefinitions>";
@ -1923,7 +1924,7 @@ public class CollectPCDAction {
if ((start > end) || if ((start > end) ||
(end > datum.length())|| (end > datum.length())||
((start == end) && (datum.length() > 0))) { ((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"+ "a UNICODE string because start with L\", but format maybe"+
"is not right, correct UNICODE string is L\"...\"!", "is not right, correct UNICODE string is L\"...\"!",
cName, cName,
@ -1933,7 +1934,7 @@ public class CollectPCDAction {
strValue = datum.substring(start + 1, end); strValue = datum.substring(start + 1, end);
if ((strValue.length() * 2) > maxDatumSize) { 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", "a UNICODE string, but the datum size is %d exceed to <MaxDatumSize> : %d",
cName, cName,
moduleName, moduleName,
@ -1947,7 +1948,7 @@ public class CollectPCDAction {
if ((start > end) || if ((start > end) ||
(end > datum.length())|| (end > datum.length())||
((start == end) && (datum.length() > 0))) { ((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"+ "a ANSCII string because start with \", but format maybe"+
"is not right, correct ANSIC string is \"...\"!", "is not right, correct ANSIC string is \"...\"!",
cName, cName,
@ -1956,7 +1957,7 @@ public class CollectPCDAction {
} }
strValue = datum.substring(start + 1, end); strValue = datum.substring(start + 1, end);
if ((strValue.length()) > maxDatumSize) { 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", "a ANSCI string, but the datum size is %d which exceed to <MaxDatumSize> : %d",
cName, cName,
moduleName, moduleName,
@ -1969,10 +1970,36 @@ public class CollectPCDAction {
start = datum.indexOf('{'); start = datum.indexOf('{');
end = datum.lastIndexOf('}'); 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(","); 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) { 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!", "array, but the number of bytes is %d which exceed to <MaxDatumSzie> : %d!",
cName, cName,
moduleName, moduleName,
@ -1981,7 +2008,7 @@ public class CollectPCDAction {
return exceptionString; return exceptionString;
} }
} else { } 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"+ "1) UNICODE string: like L\"xxxx\";\r\n"+
"2) ANSIC string: like \"xxx\";\r\n"+ "2) ANSIC string: like \"xxx\";\r\n"+
"3) Byte array: like {0x2, 0x45, 0x23}\r\n"+ "3) Byte array: like {0x2, 0x45, 0x23}\r\n"+

View File

@ -540,6 +540,28 @@ public class Token {
return null; 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 // BugBug: We need change this algorithm accordingly when schema is updated
// to support no default value. // to support no default value.
@ -616,13 +638,20 @@ public class Token {
return false; 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) {
// BUGBUG: need scott confirmation. return false;
// }
if (datumType == Token.DATUM_TYPE.POINTER) {
if (datumType == Token.DATUM_TYPE.POINTER &&
str.startsWith("L\"") &&
str.endsWith("\"")) {
return true; return true;
} }