3 VfrCompiler error handler.
5 Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "EfiUtilityMsgs.h"
22 static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE
[] = {
23 { VFR_RETURN_SUCCESS
, NULL
},
24 { VFR_RETURN_ERROR_SKIPED
, NULL
},
25 { VFR_RETURN_FATAL_ERROR
, ": fatal error!!" },
27 { VFR_RETURN_MISMATCHED
, ": unexpected token" },
28 { VFR_RETURN_INVALID_PARAMETER
, ": invalid parameter" },
29 { VFR_RETURN_OUT_FOR_RESOURCES
, ": system out of memory" },
30 { VFR_RETURN_UNSUPPORTED
, ": unsupported" },
31 { VFR_RETURN_REDEFINED
, ": already defined" },
32 { VFR_RETURN_FORMID_REDEFINED
, ": form id already defined" },
33 { VFR_RETURN_QUESTIONID_REDEFINED
, ": question id already defined" },
34 { VFR_RETURN_VARSTOREID_REDEFINED
, ": varstore id already defined" },
35 { VFR_RETURN_UNDEFINED
, ": undefined" },
36 { VFR_RETURN_VAR_NOTDEFINED_BY_QUESTION
, ": some variable has not defined by a question"},
37 { 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."},
38 { VFR_RETURN_GET_EFIVARSTORE_ERROR
, ": get efi varstore error"},
39 { VFR_RETURN_EFIVARSTORE_USE_ERROR
, ": can not use the efi varstore like this" },
40 { VFR_RETURN_EFIVARSTORE_SIZE_ERROR
, ": unsupport efi varstore size should be <= 8 bytes" },
41 { VFR_RETURN_GET_NVVARSTORE_ERROR
, ": get name value varstore error" },
42 { VFR_RETURN_QVAR_REUSE
, ": variable reused by more than one question" },
43 { VFR_RETURN_FLAGS_UNSUPPORTED
, ": flags unsupported" },
44 { VFR_RETURN_ERROR_ARRARY_NUM
, ": array number error, the valid value is in (0 ~ MAX_INDEX-1) for UEFI vfr and in (1 ~ MAX_INDEX) for Framework Vfr" },
45 { VFR_RETURN_DATA_STRING_ERROR
, ": data field string error or not support"},
46 { VFR_RETURN_DEFAULT_VALUE_REDEFINED
, ": default value re-defined with different value"},
47 { VFR_RETURN_CONSTANT_ONLY
, ": only constant is allowed in the expression"},
48 { 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."},
49 { VFR_RETURN_CODEUNDEFINED
, ": undefined Error Code" }
52 static SVFR_WARNING_HANDLE VFR_WARNING_HANDLE_TABLE
[] = {
53 { VFR_WARNING_DEFAULT_VALUE_REDEFINED
, ": default value re-defined with different value"},
54 { VFR_WARNING_STRING_TO_UINT_OVERFLOW
, ": String to UINT* Overflow"},
55 { VFR_WARNING_CODEUNDEFINED
, ": undefined Warning Code" }
58 CVfrErrorHandle::CVfrErrorHandle (
62 mInputFileName
= NULL
;
63 mScopeRecordListHead
= NULL
;
64 mScopeRecordListTail
= NULL
;
65 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
66 mVfrWarningHandleTable
= VFR_WARNING_HANDLE_TABLE
;
69 CVfrErrorHandle::~CVfrErrorHandle (
73 SVfrFileScopeRecord
*pNode
= NULL
;
75 if (mInputFileName
!= NULL
) {
76 delete mInputFileName
;
79 while (mScopeRecordListHead
!= NULL
) {
80 pNode
= mScopeRecordListHead
;
81 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
85 mScopeRecordListHead
= NULL
;
86 mScopeRecordListTail
= NULL
;
87 mVfrErrorHandleTable
= NULL
;
88 mVfrWarningHandleTable
= NULL
;
92 CVfrErrorHandle::SetWarningAsError (
93 IN BOOLEAN WarningAsError
96 mWarningAsError
= WarningAsError
;
100 CVfrErrorHandle::SetInputFile (
104 if (InputFile
!= NULL
) {
105 mInputFileName
= new CHAR8
[strlen(InputFile
) + 1];
106 strcpy (mInputFileName
, InputFile
);
110 SVfrFileScopeRecord::SVfrFileScopeRecord (
116 CHAR8
*FileName
= NULL
;
119 mWholeScopeLine
= LineNum
;
122 Str
= strchr (Record
, ' ');
123 mScopeLineStart
= atoi (++Str
);
125 Str
= strchr (Str
, '\"');
128 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
131 if ((mFileName
= new CHAR8
[strlen(FileName
)]) != NULL
) {
132 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
133 mFileName
[Index
] = FileName
[Index
];
135 mFileName
[Index
] = '\0';
141 SVfrFileScopeRecord::~SVfrFileScopeRecord (
145 if (mFileName
!= NULL
) {
151 CVfrErrorHandle::ParseFileScopeRecord (
153 IN UINT32 WholeScopeLine
156 SVfrFileScopeRecord
*pNode
= NULL
;
158 if (Record
== NULL
) {
162 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
166 if (mScopeRecordListHead
== NULL
) {
167 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
169 mScopeRecordListTail
->mNext
= pNode
;
170 mScopeRecordListTail
= pNode
;
175 CVfrErrorHandle::GetFileNameLineNum (
177 OUT CHAR8
**FileName
,
181 SVfrFileScopeRecord
*pNode
= NULL
;
183 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
188 *FileLine
= 0xFFFFFFFF;
191 // Some errors occur before scope record list been built.
193 if (mScopeRecordListHead
== NULL
) {
195 *FileName
= mInputFileName
;
199 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
200 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
201 *FileName
= pNode
->mFileName
;
202 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
207 *FileName
= pNode
->mFileName
;
208 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
212 CVfrErrorHandle::PrintMsg (
215 IN CONST CHAR8
*MsgType
,
216 IN CONST CHAR8
*ErrorMsg
219 CHAR8
*FileName
= NULL
;
222 if (strncmp ("Warning", MsgType
, strlen ("Warning")) == 0) {
223 VerboseMsg ((CHAR8
*) ErrorMsg
);
226 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
227 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
231 CVfrErrorHandle::HandleError (
232 IN EFI_VFR_RETURN_CODE ErrorCode
,
238 CHAR8
*FileName
= NULL
;
240 CONST CHAR8
*ErrorMsg
= NULL
;
242 if (mVfrErrorHandleTable
== NULL
) {
246 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
247 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
248 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
253 if (ErrorMsg
!= NULL
) {
254 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
255 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
263 CVfrErrorHandle::HandleWarning (
264 IN EFI_VFR_WARNING_CODE WarningCode
,
270 CHAR8
*FileName
= NULL
;
272 CONST CHAR8
*WarningMsg
= NULL
;
274 if (mVfrWarningHandleTable
== NULL
) {
278 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
280 if (mWarningAsError
) {
281 Error (FileName
, FileLine
, 0x2220, "warning treated as error", NULL
);
284 for (Index
= 0; mVfrWarningHandleTable
[Index
].mWarningCode
!= VFR_WARNING_CODEUNDEFINED
; Index
++) {
285 if (WarningCode
== mVfrWarningHandleTable
[Index
].mWarningCode
) {
286 WarningMsg
= mVfrWarningHandleTable
[Index
].mWarningMsg
;
291 if (WarningMsg
!= NULL
) {
292 Warning (FileName
, FileLine
, 0, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) WarningMsg
);
299 CVfrErrorHandle gCVfrErrorHandle
;