3 VfrCompiler error handler.
5 Copyright (c) 2004 - 2011, 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_CODEUNDEFINED
, ": undefined Error Code" }
51 CVfrErrorHandle::CVfrErrorHandle (
55 mInputFileName
= NULL
;
56 mScopeRecordListHead
= NULL
;
57 mScopeRecordListTail
= NULL
;
58 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
61 CVfrErrorHandle::~CVfrErrorHandle (
65 SVfrFileScopeRecord
*pNode
= NULL
;
67 if (mInputFileName
!= NULL
) {
68 delete mInputFileName
;
71 while (mScopeRecordListHead
!= NULL
) {
72 pNode
= mScopeRecordListHead
;
73 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
77 mScopeRecordListHead
= NULL
;
78 mScopeRecordListTail
= NULL
;
79 mVfrErrorHandleTable
= NULL
;
83 CVfrErrorHandle::SetInputFile (
87 if (InputFile
!= NULL
) {
88 mInputFileName
= new CHAR8
[strlen(InputFile
) + 1];
89 strcpy (mInputFileName
, InputFile
);
93 SVfrFileScopeRecord::SVfrFileScopeRecord (
99 CHAR8
*FileName
= NULL
;
102 mWholeScopeLine
= LineNum
;
105 Str
= strchr (Record
, ' ');
106 mScopeLineStart
= atoi (++Str
);
108 Str
= strchr (Str
, '\"');
111 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
114 if ((mFileName
= new CHAR8
[strlen(FileName
)]) != NULL
) {
115 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
116 mFileName
[Index
] = FileName
[Index
];
118 mFileName
[Index
] = '\0';
124 SVfrFileScopeRecord::~SVfrFileScopeRecord (
128 if (mFileName
!= NULL
) {
134 CVfrErrorHandle::ParseFileScopeRecord (
136 IN UINT32 WholeScopeLine
139 SVfrFileScopeRecord
*pNode
= NULL
;
141 if (Record
== NULL
) {
145 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
149 if (mScopeRecordListHead
== NULL
) {
150 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
152 mScopeRecordListTail
->mNext
= pNode
;
153 mScopeRecordListTail
= pNode
;
158 CVfrErrorHandle::GetFileNameLineNum (
160 OUT CHAR8
**FileName
,
164 SVfrFileScopeRecord
*pNode
= NULL
;
166 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
171 *FileLine
= 0xFFFFFFFF;
174 // Some errors occur before scope record list been built.
176 if (mScopeRecordListHead
== NULL
) {
178 *FileName
= mInputFileName
;
182 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
183 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
184 *FileName
= pNode
->mFileName
;
185 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
190 *FileName
= pNode
->mFileName
;
191 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
195 CVfrErrorHandle::PrintMsg (
198 IN CONST CHAR8
*MsgType
,
199 IN CONST CHAR8
*ErrorMsg
202 CHAR8
*FileName
= NULL
;
205 if (strncmp ("Warning", MsgType
, strlen ("Warning")) == 0) {
206 VerboseMsg ((CHAR8
*) ErrorMsg
);
209 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
210 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
214 CVfrErrorHandle::HandleError (
215 IN EFI_VFR_RETURN_CODE ErrorCode
,
221 CHAR8
*FileName
= NULL
;
223 CONST CHAR8
*ErrorMsg
= NULL
;
225 if (mVfrErrorHandleTable
== NULL
) {
229 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
230 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
231 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
236 if (ErrorMsg
!= NULL
) {
237 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
238 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
245 CVfrErrorHandle gCVfrErrorHandle
;