3 VfrCompiler error handler.
5 Copyright (c) 2004 - 2008, 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_GET_EFIVARSTORE_ERROR
, ": get efi varstore error"},
38 { VFR_RETURN_EFIVARSTORE_USE_ERROR
, ": can not use the efi varstore like this" },
39 { VFR_RETURN_EFIVARSTORE_SIZE_ERROR
, ": unsupport efi varstore size should be <= 8 bytes" },
40 { VFR_RETURN_GET_NVVARSTORE_ERROR
, ": get name value varstore error" },
41 { VFR_RETURN_QVAR_REUSE
, ": variable reused by more than one question" },
42 { VFR_RETURN_FLAGS_UNSUPPORTED
, ": flags unsupported" },
43 { 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" },
44 { VFR_RETURN_DATA_STRING_ERROR
, ": data field string error or not support"},
45 { VFR_RETURN_DEFAULT_VALUE_REDEFINED
, ": default value re-defined with different value"},
46 { VFR_RETURN_CONSTANT_ONLY
, ": only constant is allowed in the expression"},
47 { VFR_RETURN_CODEUNDEFINED
, ": undefined Error Code" }
50 CVfrErrorHandle::CVfrErrorHandle (
54 mInputFileName
= NULL
;
55 mScopeRecordListHead
= NULL
;
56 mScopeRecordListTail
= NULL
;
57 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
60 CVfrErrorHandle::~CVfrErrorHandle (
64 SVfrFileScopeRecord
*pNode
= NULL
;
66 if (mInputFileName
!= NULL
) {
67 delete mInputFileName
;
70 while (mScopeRecordListHead
!= NULL
) {
71 pNode
= mScopeRecordListHead
;
72 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
76 mScopeRecordListHead
= NULL
;
77 mScopeRecordListTail
= NULL
;
78 mVfrErrorHandleTable
= NULL
;
82 CVfrErrorHandle::SetInputFile (
86 if (InputFile
!= NULL
) {
87 mInputFileName
= new CHAR8
[strlen(InputFile
) + 1];
88 strcpy (mInputFileName
, InputFile
);
92 SVfrFileScopeRecord::SVfrFileScopeRecord (
98 CHAR8
*FileName
= NULL
;
101 mWholeScopeLine
= LineNum
;
104 Str
= strchr (Record
, ' ');
105 mScopeLineStart
= atoi (++Str
);
107 Str
= strchr (Str
, '\"');
110 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
113 if ((mFileName
= new CHAR8
[strlen(FileName
)]) != NULL
) {
114 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
115 mFileName
[Index
] = FileName
[Index
];
117 mFileName
[Index
] = '\0';
123 SVfrFileScopeRecord::~SVfrFileScopeRecord (
127 if (mFileName
!= NULL
) {
133 CVfrErrorHandle::ParseFileScopeRecord (
135 IN UINT32 WholeScopeLine
138 SVfrFileScopeRecord
*pNode
= NULL
;
140 if (Record
== NULL
) {
144 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
148 if (mScopeRecordListHead
== NULL
) {
149 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
151 mScopeRecordListTail
->mNext
= pNode
;
152 mScopeRecordListTail
= pNode
;
157 CVfrErrorHandle::GetFileNameLineNum (
159 OUT CHAR8
**FileName
,
163 SVfrFileScopeRecord
*pNode
= NULL
;
165 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
170 *FileLine
= 0xFFFFFFFF;
173 // Some errors occur before scope record list been built.
175 if (mScopeRecordListHead
== NULL
) {
177 *FileName
= mInputFileName
;
181 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
182 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
183 *FileName
= pNode
->mFileName
;
184 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
189 *FileName
= pNode
->mFileName
;
190 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
194 CVfrErrorHandle::PrintMsg (
197 IN CONST CHAR8
*MsgType
,
198 IN CONST CHAR8
*ErrorMsg
201 CHAR8
*FileName
= NULL
;
204 if (strncmp ("Warning", MsgType
, strlen ("Warning")) == 0) {
205 VerboseMsg ((CHAR8
*) ErrorMsg
);
208 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
209 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
213 CVfrErrorHandle::HandleError (
214 IN EFI_VFR_RETURN_CODE ErrorCode
,
220 CHAR8
*FileName
= NULL
;
222 CONST CHAR8
*ErrorMsg
= NULL
;
224 if (mVfrErrorHandleTable
== NULL
) {
228 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
229 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
230 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
235 if (ErrorMsg
!= NULL
) {
236 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
237 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
244 CVfrErrorHandle gCVfrErrorHandle
;