This patch make sure that Pcd Dynamic database generation tool is able to handle the VariableName of type HexWordArrayType in DynamicPcdBuildDefinitions section in FPD file. The HexWorldArrayType (UINT16 in C concept) is printed directly into the dynamic PCD database.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1329 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2006-08-21 05:53:51 +00:00
parent eeb1cd5af3
commit d73557df24
2 changed files with 84 additions and 38 deletions

View File

@ -53,16 +53,42 @@ class CStructTypeDeclaration {
**/ **/
class StringTable { class StringTable {
private ArrayList<String> al; class UnicodeString {
//
// In Schema, we define VariableName in DynamicPcdBuildDefinitions in FPD
// file to be HexWordArrayType. For example, Unicode String L"Setup" is
// <VariableName>0x0053 0x0065 0x0074 0x0075 0x0070</VariableName>.
// We use raw to differentiate if the String is in form of L"Setup" (raw is false) or
// in form of {0x0053, 0x0065, 0x0074, 0x0075, 0x0070}
//
// This str is the string that can be pasted directly into the C structure.
// For example, this str can be two forms:
//
// L"Setup",
// {0x0053, 0065, 0x0074, 0x0075, 0x0070, 0x0000}, //This is another form of L"Setup"
//
public String str;
//
// This len includes the NULL character at the end of the String.
//
public int len;
public UnicodeString (String str, int len) {
this.str = str;
this.len = len;
}
}
private ArrayList<UnicodeString> al;
private ArrayList<String> alComments; private ArrayList<String> alComments;
private String phase; private String phase;
int len; int stringTableCharNum;
public StringTable (String phase) { public StringTable (String phase) {
this.phase = phase; this.phase = phase;
al = new ArrayList<String>(); al = new ArrayList<UnicodeString>();
alComments = new ArrayList<String>(); alComments = new ArrayList<String>();
len = 0; stringTableCharNum = 0;
} }
public String getSizeMacro () { public String getSizeMacro () {
@ -73,7 +99,7 @@ class StringTable {
// //
// We have at least one Unicode Character in the table. // We have at least one Unicode Character in the table.
// //
return len == 0 ? 1 : len; return stringTableCharNum == 0 ? 1 : stringTableCharNum;
} }
public String getExistanceMacro () { public String getExistanceMacro () {
@ -112,7 +138,7 @@ class StringTable {
// If there is any String in the StringTable // If there is any String in the StringTable
// //
for (int i = 0; i < al.size(); i++) { for (int i = 0; i < al.size(); i++) {
String str = al.get(i); UnicodeString uStr = al.get(i);
String stringTableName; String stringTableName;
if (i == 0) { if (i == 0) {
@ -126,7 +152,7 @@ class StringTable {
cDeclCode += tab; cDeclCode += tab;
} }
cDeclCode += String.format("%-20s%s[%d]; /* %s */", "UINT16", cDeclCode += String.format("%-20s%s[%d]; /* %s */", "UINT16",
stringTableName, str.length() + 1, stringTableName, uStr.len,
alComments.get(i)) alComments.get(i))
+ newLine; + newLine;
@ -134,7 +160,7 @@ class StringTable {
cInstCode = "/* StringTable */" + newLine; cInstCode = "/* StringTable */" + newLine;
} }
cInstCode += tab + String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i)); cInstCode += tab + String.format("%s /* %s */", uStr.str, alComments.get(i));
if (i != al.size() - 1) { if (i != al.size() - 1) {
cInstCode += commaNewLine; cInstCode += commaNewLine;
} }
@ -152,10 +178,27 @@ class StringTable {
} }
} }
public int add (String inputStr, Token token) { public int add (List inputStr, Token token) {
int i; String str;
int pos;
str = "{";
for (int i = 0; i < inputStr.size(); i++) {
str += " " + inputStr.get(i) + ",";
}
str += " 0x0000";
str += "}";
//
// This is a raw Unicode String
//
return addToTable (str, inputStr.size() + 1, token);
}
public int add (String inputStr, Token token) {
int len;
String str = inputStr; String str = inputStr;
// //
@ -163,27 +206,48 @@ class StringTable {
// "L\"Bootmode\"" or "Bootmode". // "L\"Bootmode\"" or "Bootmode".
// We drop the L\" and \" for the first type. // We drop the L\" and \" for the first type.
if (str.startsWith("L\"") && str.endsWith("\"")) { if (str.startsWith("L\"") && str.endsWith("\"")) {
str = str.substring(2, str.length() - 1); //
// Substract the character of "L", """, """.
// and add in the NULL character. So it is 2.
//
len = str.length() - 2;
} else {
//
// Include the NULL character.
//
len = str.length() + 1;
str = "L\"" + str + "\"";
} }
//
// After processing, this is L"A String Sample" type of string.
//
return addToTable (str, len, token);
}
private int addToTable (String inputStr, int len, Token token) {
int i;
int pos;
// //
// Check if StringTable has this String already. // Check if StringTable has this String already.
// If so, return the current pos. // If so, return the current pos.
// //
for (i = 0, pos = 0; i < al.size(); i++) { for (i = 0, pos = 0; i < al.size(); i++) {
String s = al.get(i);; UnicodeString s = al.get(i);;
if (str.equals(s)) { if (inputStr.equals(s.str)) {
return pos; return pos;
} }
pos = s.length() + 1; pos += s.len;
} }
i = len; i = stringTableCharNum;
// //
// Include the NULL character at the end of String // Include the NULL character at the end of String
// //
len += str.length() + 1; stringTableCharNum += len;
al.add(str); al.add(new UnicodeString(inputStr, len));
alComments.add(token.getPrimaryKeyString()); alComments.add(token.getPrimaryKeyString());
return i; return i;

View File

@ -125,30 +125,12 @@ public class DynamicTokenValue {
} }
/** /**
Get the string like L"xxx" for a variable Name. Get the variable Name.
BUGBUG: In fact, it is not correctly, variable name should be
treated as unicode UINT16 array.
@return String @return String
**/ **/
public String getStringOfVariableName() public List getStringOfVariableName() {
throws EntityException { return variableName;
String str;
int index, num;
int size;
str = "";
size = variableName.size();
for (index = 0; index < size; index++) {
num = Integer.decode(variableName.get(index).toString());
if ((num > 127 ) || (num < 0)) {
throw new EntityException(String.format("The variable name contains more than 0x80 characters; this is not supported at thist time!"));
}
str += (char)num;
}
return str;
} }
/** /**