1) correct the assert condition for LibPcdSetPtr and LibPcdSetExPtr

2) make sure VOID* type dynamic PCD entry can handle ASCII string correctly.
3) correct one bug where if StringTable is empty the autogen.c won't compile.


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@630 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2006-06-26 13:41:23 +00:00
parent 923e598702
commit 3534cbb7a3
5 changed files with 72 additions and 31 deletions

View File

@ -461,7 +461,9 @@ LibPcdSetPtr (
IN VOID *Buffer IN VOID *Buffer
) )
{ {
if (*SizeOfBuffer > 0) {
ASSERT (Buffer != NULL); ASSERT (Buffer != NULL);
}
return Buffer; return Buffer;
} }
@ -630,7 +632,10 @@ LibPcdSetExPtr (
) )
{ {
ASSERT (Guid != NULL); ASSERT (Guid != NULL);
if (*SizeOfBuffer > 0) {
ASSERT (Buffer != NULL); ASSERT (Buffer != NULL);
}
return Buffer; return Buffer;
} }

View File

@ -514,7 +514,9 @@ LibPcdSetPtr (
EFI_STATUS Status; EFI_STATUS Status;
UINTN Size; UINTN Size;
ASSERT ((*SizeOfBuffer > 0) && Buffer == NULL); if (*SizeOfBuffer > 0) {
ASSERT (Buffer != NULL);
}
Size = LibPcdGetSize (TokenNumber); Size = LibPcdGetSize (TokenNumber);
@ -726,8 +728,9 @@ LibPcdSetExPtr (
EFI_STATUS Status; EFI_STATUS Status;
UINTN Size; UINTN Size;
ASSERT (Guid != NULL); if (*SizeOfBuffer > 0) {
ASSERT (Buffer != NULL); ASSERT (Buffer != NULL);
}
Size = LibPcdGetExSize (Guid, TokenNumber); Size = LibPcdGetExSize (Guid, TokenNumber);
if (*SizeOfBuffer > Size) { if (*SizeOfBuffer > Size) {

View File

@ -586,9 +586,11 @@ LibPcdSetPtr (
PCD_PPI *PcdPpi; PCD_PPI *PcdPpi;
UINTN Size; UINTN Size;
PcdPpi = GetPcdPpiPtr (); if (*SizeOfBuffer > 0) {
ASSERT (Buffer != NULL);
}
ASSERT ((*SizeOfBuffer > 0) && Buffer == NULL); PcdPpi = GetPcdPpiPtr ();
Size = LibPcdGetSize (TokenNumber); Size = LibPcdGetSize (TokenNumber);
@ -813,6 +815,10 @@ LibPcdSetExPtr (
PCD_PPI *PcdPpi; PCD_PPI *PcdPpi;
UINTN Size; UINTN Size;
if (*SizeOfBuffer > 0) {
ASSERT (Buffer != NULL);
}
PcdPpi = GetPcdPpiPtr (); PcdPpi = GetPcdPpiPtr ();
Size = LibPcdGetExSize (Guid, TokenNumber); Size = LibPcdGetExSize (Guid, TokenNumber);

View File

@ -107,7 +107,7 @@ class StringTable {
// If we have a empty StringTable // If we have a empty StringTable
// //
if (al.size() == 0) { if (al.size() == 0) {
cDeclCode += tab + String.format("UINT16 %s[1]; /* StringTable is Empty */", stringTable) + newLine; cDeclCode += String.format("%-20s%s[1]; /* StringTable is empty */", "UINT16", stringTable) + newLine;
decl = new CStructTypeDeclaration ( decl = new CStructTypeDeclaration (
stringTable, stringTable,
2, 2,
@ -116,7 +116,7 @@ class StringTable {
); );
declaList.add(decl); declaList.add(decl);
cInstCode = " { 0 } " + String.format("/* %s */", stringTable); cInstCode = String.format("/* %s */", stringTable) + newLine + tab + "{ 0 }";
instTable.put(stringTable, cInstCode); instTable.put(stringTable, cInstCode);
} else { } else {
@ -137,7 +137,7 @@ class StringTable {
stringTableName = String.format("%s_%d", stringTable, i); stringTableName = String.format("%s_%d", stringTable, i);
cDeclCode += tab; cDeclCode += tab;
} }
cDeclCode += String.format("UINT16 %s[%d]; /* %s */", stringTableName, str.length() + 1, alComments.get(i)) + newLine; cDeclCode += String.format("%-20s%s[%d]; /* %s */", "UINT16", stringTableName, str.length() + 1, alComments.get(i)) + newLine;
if (i == 0) { if (i == 0) {
cInstCode = "/* StringTable */" + newLine; cInstCode = "/* StringTable */" + newLine;
@ -295,7 +295,7 @@ class SizeTable {
Output.add("/* SizeTable */"); Output.add("/* SizeTable */");
Output.add("{"); Output.add("{");
if (al.size() == 0) { if (al.size() == 0) {
Output.add("0"); Output.add("\t0");
} else { } else {
for (int index = 0; index < al.size(); index++) { for (int index = 0; index < al.size(); index++) {
Integer n = al.get(index); Integer n = al.get(index);
@ -387,7 +387,7 @@ class GuidTable {
guidStrArray =(uuid.toString()).split("-"); guidStrArray =(uuid.toString()).split("-");
return String.format("{ 0x%s, 0x%s, 0x%s, { 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s } }", return String.format("{0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",
guidStrArray[0], guidStrArray[0],
guidStrArray[1], guidStrArray[1],
guidStrArray[2], guidStrArray[2],
@ -408,7 +408,7 @@ class GuidTable {
Output.add("/* GuidTable */"); Output.add("/* GuidTable */");
Output.add("{"); Output.add("{");
if (al.size() == 0) { if (al.size() == 0) {
Output.add(getUuidCString(new UUID(0, 0))); Output.add("\t" + getUuidCString(new UUID(0, 0)));
} }
for (int i = 0; i < al.size(); i++) { for (int i = 0; i < al.size(); i++) {
@ -505,7 +505,7 @@ class SkuIdTable {
decl = new CStructTypeDeclaration ( decl = new CStructTypeDeclaration (
"SystemSkuId", "SystemSkuId",
1, 1,
"SKU_ID SystemSkuId;\r\n", String.format("%-20sSystemSkuId;\r\n", "SKU_ID"),
true true
); );
declaList.add(decl); declaList.add(decl);
@ -662,7 +662,7 @@ class LocalTokenNumberTable {
output.add("{"); output.add("{");
if (al.size() == 0) { if (al.size() == 0) {
output.add("0"); output.add("\t0");
} }
for (int index = 0; index < al.size(); index++) { for (int index = 0; index < al.size(); index++) {
@ -1206,7 +1206,8 @@ class PcdDatabase {
// //
// We made a assumption that both PEI_PCD_DATABASE and DXE_PCD_DATABASE // We made a assumption that both PEI_PCD_DATABASE and DXE_PCD_DATABASE
// has a least one data memember with alignment size of 1. So we can // has a least one data memember with alignment size of 1. So we can
// remove the last "," in the C structure instantiation string. // remove the last "," in the C structure instantiation string. Luckily,
// this is true as both data structure has SKUID_TABLE anyway.
// //
if ((align == 1) && (i == declaListBasedOnAlignment.size() - 1)) { if ((align == 1) && (i == declaListBasedOnAlignment.size() - 1)) {
initInstStr += newLine; initInstStr += newLine;
@ -1228,7 +1229,7 @@ class PcdDatabase {
} }
if (uinitDatabaseEmpty) { if (uinitDatabaseEmpty) {
uninitDeclStr += tab + " UINT8 dummy; /* PCD_DATABASE_UNINIT is emptry */\r\n"; uninitDeclStr += tab + String.format("%-20sdummy; /* PCD_DATABASE_UNINIT is emptry */\r\n", "UINT8");
} }
initDeclStr += String.format("} %s_PCD_DATABASE_INIT;", phase) + newLine + newLine; initDeclStr += String.format("} %s_PCD_DATABASE_INIT;", phase) + newLine + newLine;
@ -1475,7 +1476,7 @@ class PcdDatabase {
} }
private String getSkuEnabledTypeDeclaration (Token token) { private String getSkuEnabledTypeDeclaration (Token token) {
return String.format("SKU_HEAD %s;\r\n", token.getPrimaryKeyString()); return String.format("%-20s%s;\r\n", "SKU_HEAD", token.getPrimaryKeyString());
} }
private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) { private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) {
@ -1581,20 +1582,29 @@ class PcdDatabase {
} }
if (t.isUnicodeStringType()) { if (t.isUnicodeStringType()) {
privateGlobalCCode = String.format("STRING_HEAD %s[%d];\r\n", t.getPrimaryKeyString(), t.getSkuIdCount()); privateGlobalCCode = String.format("%-20s%s[%d];\r\n", "STRING_HEAD", t.getPrimaryKeyString(), t.getSkuIdCount());
} else { } else {
String type = getCType(t); String type = getCType(t);
if (t.datumType == Token.DATUM_TYPE.POINTER) { if (t.datumType == Token.DATUM_TYPE.POINTER) {
privateGlobalCCode = String.format("%s %s[%d][%d];\r\n", type, privateGlobalName, t.getSkuIdCount(), t.datumSize); int bufferSize;
if (t.isASCIIStringType()) {
//
// Build tool will add a NULL string at the end of the ASCII string
//
bufferSize = t.datumSize + 1;
} else { } else {
privateGlobalCCode = String.format("%s %s[%d];\r\n", type, privateGlobalName, t.getSkuIdCount()); bufferSize = t.datumSize;
}
privateGlobalCCode = String.format("%-20s%s[%d][%d];\r\n", type, privateGlobalName, t.getSkuIdCount(), bufferSize);
} else {
privateGlobalCCode = String.format("%-20s%s[%d];\r\n", type, privateGlobalName, t.getSkuIdCount());
} }
} }
} }
private String getDataTypeDeclarationForVariableDefault_new (Token token, String cName, int skuId) { private String getDataTypeDeclarationForVariableDefault_new (Token token, String cName, int skuId) {
String typeStr = ""; String typeStr;
if (token.datumType == Token.DATUM_TYPE.UINT8) { if (token.datumType == Token.DATUM_TYPE.UINT8) {
typeStr = "UINT8"; typeStr = "UINT8";
@ -1607,11 +1617,12 @@ class PcdDatabase {
} else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) { } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {
typeStr = "BOOLEAN"; typeStr = "BOOLEAN";
} else if (token.datumType == Token.DATUM_TYPE.POINTER) { } else if (token.datumType == Token.DATUM_TYPE.POINTER) {
return String.format("UINT8 %s[%d]", cName, token.datumSize); return String.format("%-20s%s[%d];\r\n", cName, token.datumSize);
} else { } else {
typeStr = "";
} }
return String.format("%s %s;\r\n", typeStr, cName); return String.format("%-20s%s;\r\n", typeStr, cName);
} }
private String getDataTypeDeclaration (Token token) { private String getDataTypeDeclaration (Token token) {

View File

@ -708,6 +708,22 @@ public class Token {
return false; return false;
} }
public boolean isASCIIStringType () {
String str = getDynamicDefaultValue();
if (str == null) {
return false;
}
if (datumType == Token.DATUM_TYPE.POINTER &&
str.startsWith("\"") &&
str.endsWith("\"")) {
return true;
}
return false;
}
public boolean isByteStreamType () { public boolean isByteStreamType () {
String str = getDynamicDefaultValue(); String str = getDynamicDefaultValue();