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_CODEUNDEFINED
, ": undefined Warning Code" }
57 CVfrErrorHandle::CVfrErrorHandle (
61 mInputFileName
= NULL
;
62 mScopeRecordListHead
= NULL
;
63 mScopeRecordListTail
= NULL
;
64 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
65 mVfrWarningHandleTable
= VFR_WARNING_HANDLE_TABLE
;
68 CVfrErrorHandle::~CVfrErrorHandle (
72 SVfrFileScopeRecord
*pNode
= NULL
;
74 if (mInputFileName
!= NULL
) {
75 delete mInputFileName
;
78 while (mScopeRecordListHead
!= NULL
) {
79 pNode
= mScopeRecordListHead
;
80 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
84 mScopeRecordListHead
= NULL
;
85 mScopeRecordListTail
= NULL
;
86 mVfrErrorHandleTable
= NULL
;
87 mVfrWarningHandleTable
= NULL
;
91 CVfrErrorHandle::SetWarningAsError (
92 IN BOOLEAN WarningAsError
95 mWarningAsError
= WarningAsError
;
99 CVfrErrorHandle::SetInputFile (
103 if (InputFile
!= NULL
) {
104 mInputFileName
= new CHAR8
[strlen(InputFile
) + 1];
105 strcpy (mInputFileName
, InputFile
);
109 SVfrFileScopeRecord::SVfrFileScopeRecord (
115 CHAR8
*FileName
= NULL
;
118 mWholeScopeLine
= LineNum
;
121 Str
= strchr (Record
, ' ');
122 mScopeLineStart
= atoi (++Str
);
124 Str
= strchr (Str
, '\"');
127 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
130 if ((mFileName
= new CHAR8
[strlen(FileName
)]) != NULL
) {
131 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
132 mFileName
[Index
] = FileName
[Index
];
134 mFileName
[Index
] = '\0';
140 SVfrFileScopeRecord::~SVfrFileScopeRecord (
144 if (mFileName
!= NULL
) {
150 CVfrErrorHandle::ParseFileScopeRecord (
152 IN UINT32 WholeScopeLine
155 SVfrFileScopeRecord
*pNode
= NULL
;
157 if (Record
== NULL
) {
161 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
165 if (mScopeRecordListHead
== NULL
) {
166 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
168 mScopeRecordListTail
->mNext
= pNode
;
169 mScopeRecordListTail
= pNode
;
174 CVfrErrorHandle::GetFileNameLineNum (
176 OUT CHAR8
**FileName
,
180 SVfrFileScopeRecord
*pNode
= NULL
;
182 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
187 *FileLine
= 0xFFFFFFFF;
190 // Some errors occur before scope record list been built.
192 if (mScopeRecordListHead
== NULL
) {
194 *FileName
= mInputFileName
;
198 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
199 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
200 *FileName
= pNode
->mFileName
;
201 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
206 *FileName
= pNode
->mFileName
;
207 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
211 CVfrErrorHandle::PrintMsg (
214 IN CONST CHAR8
*MsgType
,
215 IN CONST CHAR8
*ErrorMsg
218 CHAR8
*FileName
= NULL
;
221 if (strncmp ("Warning", MsgType
, strlen ("Warning")) == 0) {
222 VerboseMsg ((CHAR8
*) ErrorMsg
);
225 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
226 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
230 CVfrErrorHandle::HandleError (
231 IN EFI_VFR_RETURN_CODE ErrorCode
,
237 CHAR8
*FileName
= NULL
;
239 CONST CHAR8
*ErrorMsg
= NULL
;
241 if (mVfrErrorHandleTable
== NULL
) {
245 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
246 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
247 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
252 if (ErrorMsg
!= NULL
) {
253 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
254 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
262 CVfrErrorHandle::HandleWarning (
263 IN EFI_VFR_WARNING_CODE WarningCode
,
269 CHAR8
*FileName
= NULL
;
271 CONST CHAR8
*WarningMsg
= NULL
;
273 if (mVfrWarningHandleTable
== NULL
) {
277 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
279 if (mWarningAsError
) {
280 Error (FileName
, FileLine
, 0x2220, "warning treated as error", NULL
);
283 for (Index
= 0; mVfrWarningHandleTable
[Index
].mWarningCode
!= VFR_WARNING_CODEUNDEFINED
; Index
++) {
284 if (WarningCode
== mVfrWarningHandleTable
[Index
].mWarningCode
) {
285 WarningMsg
= mVfrWarningHandleTable
[Index
].mWarningMsg
;
290 if (WarningMsg
!= NULL
) {
291 Warning (FileName
, FileLine
, 0, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) WarningMsg
);
298 CVfrErrorHandle gCVfrErrorHandle
;