3 VfrCompiler error handler.
5 Copyright (c) 2004 - 2018, 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_BIT_WIDTH_ERROR
, ": bit width must be <= sizeof (type) * 8 and the max width can not > 32" },
50 { VFR_RETURN_CODEUNDEFINED
, ": undefined Error Code" }
53 static SVFR_WARNING_HANDLE VFR_WARNING_HANDLE_TABLE
[] = {
54 { VFR_WARNING_DEFAULT_VALUE_REDEFINED
, ": default value re-defined with different value"},
55 { VFR_WARNING_STRING_TO_UINT_OVERFLOW
, ": String to UINT* Overflow"},
56 { VFR_WARNING_ACTION_WITH_TEXT_TWO
, ": Action opcode should not have TextTwo part"},
57 { VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE
, ": Not recommend to use obsoleted framework opcode"},
58 { VFR_WARNING_CODEUNDEFINED
, ": undefined Warning Code" }
61 CVfrErrorHandle::CVfrErrorHandle (
65 mInputFileName
= NULL
;
66 mScopeRecordListHead
= NULL
;
67 mScopeRecordListTail
= NULL
;
68 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
69 mVfrWarningHandleTable
= VFR_WARNING_HANDLE_TABLE
;
70 mWarningAsError
= FALSE
;
73 CVfrErrorHandle::~CVfrErrorHandle (
77 SVfrFileScopeRecord
*pNode
= NULL
;
79 if (mInputFileName
!= NULL
) {
80 delete[] mInputFileName
;
83 while (mScopeRecordListHead
!= NULL
) {
84 pNode
= mScopeRecordListHead
;
85 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
89 mScopeRecordListHead
= NULL
;
90 mScopeRecordListTail
= NULL
;
91 mVfrErrorHandleTable
= NULL
;
92 mVfrWarningHandleTable
= NULL
;
96 CVfrErrorHandle::SetWarningAsError (
97 IN BOOLEAN WarningAsError
100 mWarningAsError
= WarningAsError
;
104 CVfrErrorHandle::SetInputFile (
108 if (InputFile
!= NULL
) {
109 mInputFileName
= new CHAR8
[strlen(InputFile
) + 1];
110 strcpy (mInputFileName
, InputFile
);
114 SVfrFileScopeRecord::SVfrFileScopeRecord (
120 CHAR8
*FileName
= NULL
;
123 mWholeScopeLine
= LineNum
;
126 Str
= strchr (Record
, ' ');
127 mScopeLineStart
= atoi (++Str
);
129 Str
= strchr (Str
, '\"');
132 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
135 if ((mFileName
= new CHAR8
[strlen(FileName
)]) != NULL
) {
136 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
137 mFileName
[Index
] = FileName
[Index
];
139 mFileName
[Index
] = '\0';
145 SVfrFileScopeRecord::~SVfrFileScopeRecord (
149 if (mFileName
!= NULL
) {
155 CVfrErrorHandle::ParseFileScopeRecord (
157 IN UINT32 WholeScopeLine
160 SVfrFileScopeRecord
*pNode
= NULL
;
162 if (Record
== NULL
) {
166 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
170 if (mScopeRecordListHead
== NULL
) {
171 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
173 mScopeRecordListTail
->mNext
= pNode
;
174 mScopeRecordListTail
= pNode
;
179 CVfrErrorHandle::GetFileNameLineNum (
181 OUT CHAR8
**FileName
,
185 SVfrFileScopeRecord
*pNode
= NULL
;
187 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
192 *FileLine
= 0xFFFFFFFF;
195 // Some errors occur before scope record list been built.
197 if (mScopeRecordListHead
== NULL
) {
199 *FileName
= mInputFileName
;
203 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
204 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
205 *FileName
= pNode
->mFileName
;
206 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
211 *FileName
= pNode
->mFileName
;
212 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
216 CVfrErrorHandle::PrintMsg (
219 IN CONST CHAR8
*MsgType
,
220 IN CONST CHAR8
*ErrorMsg
223 CHAR8
*FileName
= NULL
;
226 if (strncmp ("Warning", MsgType
, strlen ("Warning")) == 0) {
227 VerboseMsg ((CHAR8
*) ErrorMsg
);
230 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
231 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
235 CVfrErrorHandle::HandleError (
236 IN EFI_VFR_RETURN_CODE ErrorCode
,
242 CHAR8
*FileName
= NULL
;
244 CONST CHAR8
*ErrorMsg
= NULL
;
246 if (mVfrErrorHandleTable
== NULL
) {
250 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
251 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
252 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
257 if (ErrorMsg
!= NULL
) {
258 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
259 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
267 CVfrErrorHandle::HandleWarning (
268 IN EFI_VFR_WARNING_CODE WarningCode
,
274 CHAR8
*FileName
= NULL
;
276 CONST CHAR8
*WarningMsg
= NULL
;
278 if (mVfrWarningHandleTable
== NULL
) {
282 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
284 if (mWarningAsError
) {
285 Error (FileName
, FileLine
, 0x2220, (CHAR8
*) "warning treated as error", NULL
);
288 for (Index
= 0; mVfrWarningHandleTable
[Index
].mWarningCode
!= VFR_WARNING_CODEUNDEFINED
; Index
++) {
289 if (WarningCode
== mVfrWarningHandleTable
[Index
].mWarningCode
) {
290 WarningMsg
= mVfrWarningHandleTable
[Index
].mWarningMsg
;
295 if (WarningMsg
!= NULL
) {
296 Warning (FileName
, FileLine
, 0, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) WarningMsg
);
303 CVfrErrorHandle gCVfrErrorHandle
;