3 VfrCompiler error handler.
5 Copyright (c) 2004 - 2016, 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_STRING_TO_UINT_OVERFLOW
, ": String to UINT* Overflow"},
55 { VFR_WARNING_ACTION_WITH_TEXT_TWO
, ": Action opcode should not have TextTwo part"},
56 { VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE
, ": Not recommend to use obsoleted framework opcode"},
57 { VFR_WARNING_CODEUNDEFINED
, ": undefined Warning Code" }
60 CVfrErrorHandle::CVfrErrorHandle (
64 mInputFileName
= NULL
;
65 mScopeRecordListHead
= NULL
;
66 mScopeRecordListTail
= NULL
;
67 mVfrErrorHandleTable
= VFR_ERROR_HANDLE_TABLE
;
68 mVfrWarningHandleTable
= VFR_WARNING_HANDLE_TABLE
;
71 CVfrErrorHandle::~CVfrErrorHandle (
75 SVfrFileScopeRecord
*pNode
= NULL
;
77 if (mInputFileName
!= NULL
) {
78 delete mInputFileName
;
81 while (mScopeRecordListHead
!= NULL
) {
82 pNode
= mScopeRecordListHead
;
83 mScopeRecordListHead
= mScopeRecordListHead
->mNext
;
87 mScopeRecordListHead
= NULL
;
88 mScopeRecordListTail
= NULL
;
89 mVfrErrorHandleTable
= NULL
;
90 mVfrWarningHandleTable
= NULL
;
94 CVfrErrorHandle::SetWarningAsError (
95 IN BOOLEAN WarningAsError
98 mWarningAsError
= WarningAsError
;
102 CVfrErrorHandle::SetInputFile (
106 if (InputFile
!= NULL
) {
107 mInputFileName
= new CHAR8
[strlen(InputFile
) + 1];
108 strcpy (mInputFileName
, InputFile
);
112 SVfrFileScopeRecord::SVfrFileScopeRecord (
118 CHAR8
*FileName
= NULL
;
121 mWholeScopeLine
= LineNum
;
124 Str
= strchr (Record
, ' ');
125 mScopeLineStart
= atoi (++Str
);
127 Str
= strchr (Str
, '\"');
130 while((Str
= strstr (FileName
, "\\\\")) != NULL
) {
133 if ((mFileName
= new CHAR8
[strlen(FileName
)]) != NULL
) {
134 for (Index
= 0; FileName
[Index
] != '\"'; Index
++) {
135 mFileName
[Index
] = FileName
[Index
];
137 mFileName
[Index
] = '\0';
143 SVfrFileScopeRecord::~SVfrFileScopeRecord (
147 if (mFileName
!= NULL
) {
153 CVfrErrorHandle::ParseFileScopeRecord (
155 IN UINT32 WholeScopeLine
158 SVfrFileScopeRecord
*pNode
= NULL
;
160 if (Record
== NULL
) {
164 if ((pNode
= new SVfrFileScopeRecord(Record
, WholeScopeLine
)) == NULL
) {
168 if (mScopeRecordListHead
== NULL
) {
169 mScopeRecordListTail
= mScopeRecordListHead
= pNode
;
171 mScopeRecordListTail
->mNext
= pNode
;
172 mScopeRecordListTail
= pNode
;
177 CVfrErrorHandle::GetFileNameLineNum (
179 OUT CHAR8
**FileName
,
183 SVfrFileScopeRecord
*pNode
= NULL
;
185 if ((FileName
== NULL
) || (FileLine
== NULL
)) {
190 *FileLine
= 0xFFFFFFFF;
193 // Some errors occur before scope record list been built.
195 if (mScopeRecordListHead
== NULL
) {
197 *FileName
= mInputFileName
;
201 for (pNode
= mScopeRecordListHead
; pNode
->mNext
!= NULL
; pNode
= pNode
->mNext
) {
202 if ((LineNum
> pNode
->mWholeScopeLine
) && (pNode
->mNext
->mWholeScopeLine
> LineNum
)) {
203 *FileName
= pNode
->mFileName
;
204 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
209 *FileName
= pNode
->mFileName
;
210 *FileLine
= LineNum
- pNode
->mWholeScopeLine
+ pNode
->mScopeLineStart
- 1;
214 CVfrErrorHandle::PrintMsg (
217 IN CONST CHAR8
*MsgType
,
218 IN CONST CHAR8
*ErrorMsg
221 CHAR8
*FileName
= NULL
;
224 if (strncmp ("Warning", MsgType
, strlen ("Warning")) == 0) {
225 VerboseMsg ((CHAR8
*) ErrorMsg
);
228 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
229 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
233 CVfrErrorHandle::HandleError (
234 IN EFI_VFR_RETURN_CODE ErrorCode
,
240 CHAR8
*FileName
= NULL
;
242 CONST CHAR8
*ErrorMsg
= NULL
;
244 if (mVfrErrorHandleTable
== NULL
) {
248 for (Index
= 0; mVfrErrorHandleTable
[Index
].mErrorCode
!= VFR_RETURN_CODEUNDEFINED
; Index
++) {
249 if (ErrorCode
== mVfrErrorHandleTable
[Index
].mErrorCode
) {
250 ErrorMsg
= mVfrErrorHandleTable
[Index
].mErrorMsg
;
255 if (ErrorMsg
!= NULL
) {
256 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
257 Error (FileName
, FileLine
, 0x3000, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) ErrorMsg
);
265 CVfrErrorHandle::HandleWarning (
266 IN EFI_VFR_WARNING_CODE WarningCode
,
272 CHAR8
*FileName
= NULL
;
274 CONST CHAR8
*WarningMsg
= NULL
;
276 if (mVfrWarningHandleTable
== NULL
) {
280 GetFileNameLineNum (LineNum
, &FileName
, &FileLine
);
282 if (mWarningAsError
) {
283 Error (FileName
, FileLine
, 0x2220, (CHAR8
*) "warning treated as error", NULL
);
286 for (Index
= 0; mVfrWarningHandleTable
[Index
].mWarningCode
!= VFR_WARNING_CODEUNDEFINED
; Index
++) {
287 if (WarningCode
== mVfrWarningHandleTable
[Index
].mWarningCode
) {
288 WarningMsg
= mVfrWarningHandleTable
[Index
].mWarningMsg
;
293 if (WarningMsg
!= NULL
) {
294 Warning (FileName
, FileLine
, 0, TokName
, (CHAR8
*) "\t%s\n", (CHAR8
*) WarningMsg
);
301 CVfrErrorHandle gCVfrErrorHandle
;