3 VfrCompiler error handler.
5 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include "EfiUtilityMsgs.h"
16 static SVFR_ERROR_HANDLE VFR_ERROR_HANDLE_TABLE
[] = {
17 { VFR_RETURN_SUCCESS
, NULL
},
18 { VFR_RETURN_ERROR_SKIPED
, NULL
},
19 { VFR_RETURN_FATAL_ERROR
, ": fatal error!!" },
21 { VFR_RETURN_MISMATCHED
, ": unexpected token" },
22 { VFR_RETURN_INVALID_PARAMETER
, ": invalid parameter" },
23 { VFR_RETURN_OUT_FOR_RESOURCES
, ": system out of memory" },
24 { VFR_RETURN_UNSUPPORTED
, ": unsupported" },
25 { VFR_RETURN_REDEFINED
, ": already defined" },
26 { VFR_RETURN_FORMID_REDEFINED
, ": form id already defined" },
27 { VFR_RETURN_QUESTIONID_REDEFINED
, ": question id already defined" },
28 { VFR_RETURN_VARSTOREID_REDEFINED
, ": varstore id already defined" },
29 { VFR_RETURN_UNDEFINED
, ": undefined" },
30 { VFR_RETURN_VAR_NOTDEFINED_BY_QUESTION
, ": some variable has not defined by a question"},
31 { 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."},
32 { VFR_RETURN_GET_EFIVARSTORE_ERROR
, ": get efi varstore error"},
33 { VFR_RETURN_EFIVARSTORE_USE_ERROR
, ": can not use the efi varstore like this" },
34 { VFR_RETURN_EFIVARSTORE_SIZE_ERROR
, ": unsupport efi varstore size should be <= 8 bytes" },
35 { VFR_RETURN_GET_NVVARSTORE_ERROR
, ": get name value varstore error" },
36 { VFR_RETURN_QVAR_REUSE
, ": variable reused by more than one question" },
37 { VFR_RETURN_FLAGS_UNSUPPORTED
, ": flags unsupported" },
38 { 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" },
39 { VFR_RETURN_DATA_STRING_ERROR
, ": data field string error or not support"},
40 { VFR_RETURN_DEFAULT_VALUE_REDEFINED
, ": default value re-defined with different value"},
41 { VFR_RETURN_CONSTANT_ONLY
, ": only constant is allowed in the expression"},
42 { VFR_RETURN_VARSTORE_NAME_REDEFINED_ERROR
, ": Varstore name is defined by more than one varstores, it can't be referred as varstore, only varstore structure name could be used."},
43 { VFR_RETURN_BIT_WIDTH_ERROR
, ": bit width must be <= sizeof (type) * 8 and the max width can not > 32" },
44 { VFR_RETURN_STRING_TO_UINT_OVERFLOW
, ": String to UINT* Overflow"},
45 { VFR_RETURN_CODEUNDEFINED
, ": undefined Error Code" }
48 static SVFR_WARNING_HANDLE VFR_WARNING_HANDLE_TABLE
[] = {
49 { VFR_WARNING_DEFAULT_VALUE_REDEFINED
, ": default value re-defined with different value"},
50 { VFR_WARNING_ACTION_WITH_TEXT_TWO
, ": Action opcode should not have TextTwo part"},
51 { VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE
, ": Not recommend to use obsoleted framework opcode"},
52 { VFR_WARNING_CODEUNDEFINED
, ": undefined Warning Code" }
55 CVfrErrorHandle::CVfrErrorHandle (
59 mInputFileName
= NULL
;
60 mScopeRecordListHead
= NULL
;
61 mScopeRecordListTail
= NULL
;
62 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
63 mVfrWarningHandleTable
= VFR_WARNING_HANDLE_TABLE
;
64 mWarningAsError
= FALSE
;
67 CVfrErrorHandle::~CVfrErrorHandle (
71 SVfrFileScopeRecord
*pNode
= NULL
;
73 if (mInputFileName
!= NULL
) {
74 delete[] mInputFileName
;
77 while (mScopeRecordListHead
!= NULL
) {
78 pNode
= mScopeRecordListHead
;
79 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
83 mScopeRecordListHead
= NULL
;
84 mScopeRecordListTail
= NULL
;
85 mVfrErrorHandleTable
= NULL
;
86 mVfrWarningHandleTable
= NULL
;
90 CVfrErrorHandle::SetWarningAsError (
91 IN BOOLEAN WarningAsError
94 mWarningAsError
= WarningAsError
;
98 CVfrErrorHandle::SetInputFile (
102 if (InputFile
!= NULL
) {
103 mInputFileName
= new CHAR8
[strlen(InputFile
) + 1];
104 strcpy (mInputFileName
, InputFile
);
108 SVfrFileScopeRecord::SVfrFileScopeRecord (
114 CHAR8
*FileName
= NULL
;
117 mWholeScopeLine
= LineNum
;
120 Str
= strchr (Record
, ' ');
121 mScopeLineStart
= atoi (++Str
);
123 Str
= strchr (Str
, '\"');
126 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
129 if ((mFileName
= new CHAR8
[strlen(FileName
)]) != NULL
) {
130 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
131 mFileName
[Index
] = FileName
[Index
];
133 mFileName
[Index
] = '\0';
139 SVfrFileScopeRecord::~SVfrFileScopeRecord (
143 if (mFileName
!= NULL
) {
149 CVfrErrorHandle::ParseFileScopeRecord (
151 IN UINT32 WholeScopeLine
154 SVfrFileScopeRecord
*pNode
= NULL
;
156 if (Record
== NULL
) {
160 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
164 if (mScopeRecordListHead
== NULL
) {
165 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
167 mScopeRecordListTail
->mNext
= pNode
;
168 mScopeRecordListTail
= pNode
;
173 CVfrErrorHandle::GetFileNameLineNum (
175 OUT CHAR8
**FileName
,
179 SVfrFileScopeRecord
*pNode
= NULL
;
181 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
186 *FileLine
= 0xFFFFFFFF;
189 // Some errors occur before scope record list been built.
191 if (mScopeRecordListHead
== NULL
) {
193 *FileName
= mInputFileName
;
197 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
198 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
199 *FileName
= pNode
->mFileName
;
200 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
205 *FileName
= pNode
->mFileName
;
206 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
210 CVfrErrorHandle::PrintMsg (
213 IN CONST CHAR8
*MsgType
,
214 IN CONST CHAR8
*ErrorMsg
217 CHAR8
*FileName
= NULL
;
220 if (strncmp ("Warning", MsgType
, strlen ("Warning")) == 0) {
221 VerboseMsg ((CHAR8
*) ErrorMsg
);
224 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
225 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
229 CVfrErrorHandle::HandleError (
230 IN EFI_VFR_RETURN_CODE ErrorCode
,
236 CHAR8
*FileName
= NULL
;
238 CONST CHAR8
*ErrorMsg
= NULL
;
240 if (mVfrErrorHandleTable
== NULL
) {
244 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
245 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
246 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
251 if (ErrorMsg
!= NULL
) {
252 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
253 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
261 CVfrErrorHandle::HandleWarning (
262 IN EFI_VFR_WARNING_CODE WarningCode
,
268 CHAR8
*FileName
= NULL
;
270 CONST CHAR8
*WarningMsg
= NULL
;
272 if (mVfrWarningHandleTable
== NULL
) {
276 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
278 if (mWarningAsError
) {
279 Error (FileName
, FileLine
, 0x2220, (CHAR8
*) "warning treated as error", NULL
);
282 for (Index
= 0; mVfrWarningHandleTable
[Index
].mWarningCode
!= VFR_WARNING_CODEUNDEFINED
; Index
++) {
283 if (WarningCode
== mVfrWarningHandleTable
[Index
].mWarningCode
) {
284 WarningMsg
= mVfrWarningHandleTable
[Index
].mWarningMsg
;
289 if (WarningMsg
!= NULL
) {
290 Warning (FileName
, FileLine
, 0, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) WarningMsg
);
297 CVfrErrorHandle gCVfrErrorHandle
;