]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VfrCompile/VfrError.cpp
BaseTools: resolve initialization order errors in VfrFormPkg.h
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrError.cpp
index b24cc725f047274ba7f2791548b0f572f7762ef4..2366fac5a760bb6565cd72b96f4effb91d3b466e 100644 (file)
@@ -2,8 +2,8 @@
   \r
   VfrCompiler error handler.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
 http://opensource.org/licenses/bsd-license.php                                            \r
@@ -34,6 +34,7 @@ static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE [] = {
   { VFR_RETURN_VARSTOREID_REDEFINED, ": varstore id already defined" },\r
   { VFR_RETURN_UNDEFINED, ": undefined" },\r
   { VFR_RETURN_VAR_NOTDEFINED_BY_QUESTION, ": some variable has not defined by a question"},\r
+  { VFR_RETURN_VARSTORE_DATATYPE_REDEFINED_ERROR, ": Data Structure is defined by more than one varstores, it can't be referred as varstore, only varstore name could be used."},\r
   { VFR_RETURN_GET_EFIVARSTORE_ERROR, ": get efi varstore error"},\r
   { VFR_RETURN_EFIVARSTORE_USE_ERROR, ": can not use the efi varstore like this" },\r
   { VFR_RETURN_EFIVARSTORE_SIZE_ERROR, ": unsupport efi varstore size should be <= 8 bytes" },\r
@@ -44,17 +45,29 @@ static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE [] = {
   { VFR_RETURN_DATA_STRING_ERROR, ": data field string error or not support"},\r
   { VFR_RETURN_DEFAULT_VALUE_REDEFINED, ": default value re-defined with different value"},\r
   { VFR_RETURN_CONSTANT_ONLY, ": only constant is allowed in the expression"},\r
+  { VFR_RETURN_VARSTORE_NAME_REDEFINED_ERROR, ": Varstore name is defined by more than one varstores, it can't be referred as varstore, only varstore strucure name could be used."},\r
+  { VFR_RETURN_BIT_WIDTH_ERROR, ": bit width must be <= sizeof (type) * 8 and the max width can not > 32" },\r
   { VFR_RETURN_CODEUNDEFINED, ": undefined Error Code" }\r
 };\r
 \r
+static SVFR_WARNING_HANDLE VFR_WARNING_HANDLE_TABLE [] = {\r
+  { VFR_WARNING_DEFAULT_VALUE_REDEFINED, ": default value re-defined with different value"},\r
+  { VFR_WARNING_STRING_TO_UINT_OVERFLOW, ": String to UINT* Overflow"},\r
+  { VFR_WARNING_ACTION_WITH_TEXT_TWO, ": Action opcode should not have TextTwo part"},\r
+  { VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE, ": Not recommend to use obsoleted framework opcode"},\r
+  { VFR_WARNING_CODEUNDEFINED, ": undefined Warning Code" }\r
+};\r
+\r
 CVfrErrorHandle::CVfrErrorHandle (\r
   VOID\r
   )\r
 {\r
-  mInputFileName       = NULL;\r
-  mScopeRecordListHead = NULL;\r
-  mScopeRecordListTail = NULL;\r
-  mVfrErrorHandleTable = VFR_ERROR_HANDLE_TABLE;\r
+  mInputFileName         = NULL;\r
+  mScopeRecordListHead   = NULL;\r
+  mScopeRecordListTail   = NULL;\r
+  mVfrErrorHandleTable   = VFR_ERROR_HANDLE_TABLE;\r
+  mVfrWarningHandleTable = VFR_WARNING_HANDLE_TABLE;\r
+  mWarningAsError        = FALSE;\r
 }\r
 \r
 CVfrErrorHandle::~CVfrErrorHandle (\r
@@ -73,9 +86,18 @@ CVfrErrorHandle::~CVfrErrorHandle (
     delete pNode;\r
   }\r
 \r
-  mScopeRecordListHead = NULL;\r
-  mScopeRecordListTail = NULL;\r
-  mVfrErrorHandleTable = NULL;\r
+  mScopeRecordListHead   = NULL;\r
+  mScopeRecordListTail   = NULL;\r
+  mVfrErrorHandleTable   = NULL;\r
+  mVfrWarningHandleTable = NULL;\r
+}\r
+\r
+VOID\r
+CVfrErrorHandle::SetWarningAsError (\r
+  IN BOOLEAN  WarningAsError\r
+  )\r
+{\r
+  mWarningAsError = WarningAsError;\r
 }\r
 \r
 VOID\r
@@ -125,7 +147,7 @@ SVfrFileScopeRecord::~SVfrFileScopeRecord (
   )\r
 {\r
   if (mFileName != NULL) {\r
-    delete mFileName;\r
+    delete[] mFileName;\r
   }\r
 }\r
 \r
@@ -135,7 +157,6 @@ CVfrErrorHandle::ParseFileScopeRecord (
   IN UINT32    WholeScopeLine\r
   )\r
 {\r
-  CHAR8               *FullPathName = NULL;\r
   SVfrFileScopeRecord *pNode        = NULL;\r
 \r
   if (Record == NULL) {\r
@@ -195,15 +216,19 @@ VOID
 CVfrErrorHandle::PrintMsg (\r
   IN UINT32               LineNum,\r
   IN CHAR8                *TokName,\r
-  IN CHAR8                *MsgType,\r
-  IN CHAR8                *ErrorMsg\r
+  IN CONST CHAR8          *MsgType,\r
+  IN CONST CHAR8          *ErrorMsg\r
   )\r
 {\r
   CHAR8                  *FileName = NULL;\r
   UINT32                 FileLine;\r
-\r
+  \r
+  if (strncmp ("Warning", MsgType, strlen ("Warning")) == 0) {\r
+    VerboseMsg ((CHAR8 *) ErrorMsg);\r
+    return;\r
+  }\r
   GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
-  Error (FileName, FileLine, 0x3000, TokName, "\t%s\n", ErrorMsg);\r
+  Error (FileName, FileLine, 0x3000, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) ErrorMsg);\r
 }\r
 \r
 UINT8\r
@@ -216,7 +241,7 @@ CVfrErrorHandle::HandleError (
   UINT32                 Index;\r
   CHAR8                  *FileName = NULL;\r
   UINT32                 FileLine;\r
-  CHAR8                  *ErrorMsg = NULL;\r
+  CONST CHAR8            *ErrorMsg = NULL;\r
 \r
   if (mVfrErrorHandleTable == NULL) {\r
     return 1;\r
@@ -231,7 +256,44 @@ CVfrErrorHandle::HandleError (
 \r
   if (ErrorMsg != NULL) {\r
     GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
-    Error (FileName, FileLine, 0x3000, TokName, "\t%s\n", ErrorMsg);\r
+    Error (FileName, FileLine, 0x3000, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) ErrorMsg);\r
+    return 1;\r
+  } else {\r
+    return 0;\r
+  }\r
+}\r
+\r
+UINT8\r
+CVfrErrorHandle::HandleWarning (\r
+  IN EFI_VFR_WARNING_CODE WarningCode,\r
+  IN UINT32               LineNum,\r
+  IN CHAR8                *TokName\r
+  )\r
+{\r
+  UINT32                 Index;\r
+  CHAR8                  *FileName = NULL;\r
+  UINT32                 FileLine;\r
+  CONST CHAR8            *WarningMsg = NULL;\r
+\r
+  if (mVfrWarningHandleTable == NULL) {\r
+    return 1;\r
+  }\r
+\r
+  GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
+\r
+  if (mWarningAsError) {\r
+    Error (FileName, FileLine, 0x2220, (CHAR8 *) "warning treated as error", NULL);\r
+  }\r
+\r
+  for (Index = 0; mVfrWarningHandleTable[Index].mWarningCode != VFR_WARNING_CODEUNDEFINED; Index++) {\r
+    if (WarningCode == mVfrWarningHandleTable[Index].mWarningCode) {\r
+      WarningMsg = mVfrWarningHandleTable[Index].mWarningMsg;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (WarningMsg != NULL) {\r
+    Warning (FileName, FileLine, 0, TokName, (CHAR8 *) "\t%s\n", (CHAR8 *) WarningMsg);\r
     return 1;\r
   } else {\r
     return 0;\r