Hi liming, Gentle reminder, we have removed the whitespace. Please help review the patch~
Thanks, Yuting -----Original Message----- From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Yuting Yang Sent: Thursday, March 21, 2024 3:30 PM To: devel@edk2.groups.io Cc: Rebecca Cran <rebe...@bsdio.com>; Liming Gao <gaolim...@byosoft.com.cn>; Feng, Bob C <bob.c.f...@intel.com>; Chen, Christine <yuwei.c...@intel.com>; Zhang, Zifeng <zifeng.zh...@intel.com> Subject: [edk2-devel] [Patch V4] BaseTools: VfrCompiler Adds DefaultValueError Add --catch_default option Raise a DefaultValueError when encountering VFR default definitions to help remove default variables. Signed-off-by: Yuting Yang <yuting2.y...@intel.com> Cc: Rebecca Cran <rebe...@bsdio.com> Cc: Liming Gao <gaolim...@byosoft.com.cn> Cc: Bob Feng <bob.c.f...@intel.com> Cc: Christine Chen <yuwei.c...@intel.com> Cc: Zifeng Zhang <zifeng.zh...@intel.com> --- BaseTools/Source/C/VfrCompile/VfrCompiler.cpp | 8 ++++---- BaseTools/Source/C/VfrCompile/VfrCompiler.h | 1 + BaseTools/Source/C/VfrCompile/VfrError.cpp | 3 ++- BaseTools/Source/C/VfrCompile/VfrError.h | 3 ++- BaseTools/Source/C/VfrCompile/VfrFormPkg.h | 1 + BaseTools/Source/C/VfrCompile/VfrSyntax.g | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 6 files changed, 60 insertions(+), 14 deletions(-) diff --git a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp index 5f4d262d85..4031af6e39 100644 --- a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp @@ -78,6 +78,7 @@ CVfrCompiler::OptionInitialization ( mOptions.WarningAsError = FALSE; mOptions.AutoDefault = FALSE; mOptions.CheckDefault = FALSE;+ mOptions.IsCatchDefaultEnable = FALSE; memset (&mOptions.OverrideClassGuid, 0, sizeof (EFI_GUID)); if (Argc == 1) {@@ -95,6 +96,8 @@ CVfrCompiler::OptionInitialization ( Version (); SET_RUN_STATUS (STATUS_DEAD); return;+ } else if (stricmp(Argv[Index], "--catch_default") == 0){+ mOptions.IsCatchDefaultEnable = TRUE; } else if (stricmp(Argv[Index], "-l") == 0) { mOptions.CreateRecordListFile = TRUE; gCIfrRecordInfoDB.TurnOn ();@@ -179,7 +182,6 @@ CVfrCompiler::OptionInitialization ( goto Fail; } strcpy (mOptions.VfrFileName, Argv[Index]);- if (mOptions.OutputDirectory == NULL) { mOptions.OutputDirectory = (CHAR8 *) malloc (1); if (mOptions.OutputDirectory == NULL) {@@ -679,7 +681,7 @@ CVfrCompiler::Compile ( DebugError (NULL, 0, 0001, "Error opening the input file", "%s", InFileName); goto Fail; }-+ InputInfo.IsCatchDefaultEnable = mOptions.IsCatchDefaultEnable; if (mOptions.HasOverrideClassGuid) { InputInfo.OverrideClassGuid = &mOptions.OverrideClassGuid; } else {@@ -937,5 +939,3 @@ main ( return GetUtilityStatus (); }--diff --git a/BaseTools/Source/C/VfrCompile/VfrCompiler.h b/BaseTools/Source/C/VfrCompile/VfrCompiler.h index b6e207d2ce..974f37c4eb 100644 --- a/BaseTools/Source/C/VfrCompile/VfrCompiler.h +++ b/BaseTools/Source/C/VfrCompile/VfrCompiler.h @@ -52,6 +52,7 @@ typedef struct { BOOLEAN WarningAsError; BOOLEAN AutoDefault; BOOLEAN CheckDefault;+ BOOLEAN IsCatchDefaultEnable; } OPTIONS; typedef enum {diff --git a/BaseTools/Source/C/VfrCompile/VfrError.cpp b/BaseTools/Source/C/VfrCompile/VfrError.cpp index 65bb8e34fd..8a706f929b 100644 --- a/BaseTools/Source/C/VfrCompile/VfrError.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrError.cpp @@ -49,7 +49,8 @@ static SVFR_WARNING_HANDLE VFR_WARNING_HANDLE_TABLE [] = { { VFR_WARNING_DEFAULT_VALUE_REDEFINED, ": default value re-defined with different value"}, { VFR_WARNING_ACTION_WITH_TEXT_TWO, ": Action opcode should not have TextTwo part"}, { VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE, ": Not recommend to use obsoleted framework opcode"},- { VFR_WARNING_CODEUNDEFINED, ": undefined Warning Code" }+ { VFR_WARNING_CODEUNDEFINED, ": undefined Warning Code" },+ { VFR_WARNING_UNSUPPORTED, ": pls remove the default values if necessary" } }; CVfrErrorHandle::CVfrErrorHandle (diff --git a/BaseTools/Source/C/VfrCompile/VfrError.h b/BaseTools/Source/C/VfrCompile/VfrError.h index 7d16bd5f74..1b4bc173d2 100644 --- a/BaseTools/Source/C/VfrCompile/VfrError.h +++ b/BaseTools/Source/C/VfrCompile/VfrError.h @@ -47,7 +47,8 @@ typedef enum { VFR_WARNING_DEFAULT_VALUE_REDEFINED = 0, VFR_WARNING_ACTION_WITH_TEXT_TWO, VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE,- VFR_WARNING_CODEUNDEFINED+ VFR_WARNING_CODEUNDEFINED,+ VFR_WARNING_UNSUPPORTED } EFI_VFR_WARNING_CODE; typedef struct _SVFR_ERROR_HANDLE {diff --git a/BaseTools/Source/C/VfrCompile/VfrFormPkg.h b/BaseTools/Source/C/VfrCompile/VfrFormPkg.h index 9ef6f07787..d8fada3bcb 100644 --- a/BaseTools/Source/C/VfrCompile/VfrFormPkg.h +++ b/BaseTools/Source/C/VfrCompile/VfrFormPkg.h @@ -96,6 +96,7 @@ struct SBufferNode { typedef struct { EFI_GUID *OverrideClassGuid;+ BOOLEAN IsCatchDefaultEnable; } INPUT_INFO_TO_SYNTAX; class CFormPkg {diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g b/BaseTools/Source/C/VfrCompile/VfrSyntax.g index 55fd067f8a..d7376122d8 100644 --- a/BaseTools/Source/C/VfrCompile/VfrSyntax.g +++ b/BaseTools/Source/C/VfrCompile/VfrSyntax.g @@ -50,6 +50,7 @@ VfrParserStart ( { ParserBlackBox<CVfrDLGLexer, EfiVfrParser, ANTLRToken> VfrParser(File); VfrParser.parser()->SetOverrideClassGuid (InputInfo->OverrideClassGuid);+ VfrParser.parser()->SetIsCatchDefaultEnable(InputInfo->IsCatchDefaultEnable); return VfrParser.parser()->vfrProgram(); } >>@@ -975,7 +976,15 @@ vfrExtensionData[UINT8 *DataBuff, UINT32 Size, CHAR8 *TypeName, UINT32 TypeSize, vfrStatementDefaultStore : << UINT16 DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; >>- D:DefaultStore N:StringIdentifier ","+ D:DefaultStore N:StringIdentifier "," <<+ if (mIsCatchDefaultEnable) {+ gCVfrErrorHandle.HandleWarning (+ VFR_WARNING_UNSUPPORTED,+ D->getLine(),+ D->getText()+ );+ }+ >> Prompt "=" "STRING_TOKEN" "\(" S:Number "\)" { "," Attribute "=" A:Number << DefaultId = _STOU16(A->getText(), A->getLine()); >>@@ -1775,7 +1784,11 @@ vfrStatementDefault : CIfrNumeric *NumericQst = NULL; >>- D:Default + D:Default <<+ if (mIsCatchDefaultEnable) {+ DefaultValueError(VFR_RETURN_UNSUPPORTED, D->getLine());+ }+ >> ( ( "=" vfrConstantValueField[_GET_CURRQEST_DATATYPE(), *Val, ArrayType] "," @@ -1970,11 +1983,15 @@ vfrStatementInvalid : ; flagsField :- Number - | InteractiveFlag - | ManufacturingFlag - | DefaultFlag - | ResetRequiredFlag + Number+ | InteractiveFlag+ | ManufacturingFlag+ | D:DefaultFlag <<+ if (mIsCatchDefaultEnable) {+ DefaultValueError(VFR_RETURN_UNSUPPORTED, D->getLine());+ }+ >>+ | ResetRequiredFlag | ReconnectRequiredFlag | N:NVAccessFlag << gCVfrErrorHandle.HandleWarning (@@ -3790,7 +3807,12 @@ oneofoptionFlagsField [UINT8 & HFlags, UINT8 & LFlags] : | RestStyleFlag << $HFlags |= 0x20; >> | ReconnectRequiredFlag << $HFlags |= 0x40; >> | ManufacturingFlag << $LFlags |= 0x20; >>- | DefaultFlag << $LFlags |= 0x10; >>+ | D:DefaultFlag <<+ $LFlags |= 0x10;+ if (mIsCatchDefaultEnable) {+ DefaultValueError(VFR_RETURN_UNSUPPORTED, D->getLine());+ }+ >> | A:NVAccessFlag << gCVfrErrorHandle.HandleWarning ( VFR_WARNING_OBSOLETED_FRAMEWORK_OPCODE,@@ -4837,6 +4859,7 @@ spanFlags [UINT8 & Flags] : class EfiVfrParser { << private:+ BOOLEAN mIsCatchDefaultEnable; UINT8 mParserStatus; BOOLEAN mConstantOnlyInExpression; @@ -4880,6 +4903,7 @@ public: VOID _PCATCH (IN EFI_VFR_RETURN_CODE, IN ANTLRTokenPtr); VOID _PCATCH (IN EFI_VFR_RETURN_CODE, IN UINT32); VOID _PCATCH (IN EFI_VFR_RETURN_CODE, IN UINT32, IN CONST CHAR8 *);+ VOID DefaultValueError (IN EFI_VFR_RETURN_CODE, IN UINT32); VOID syn (ANTLRAbstractToken *, ANTLRChar *, SetWordType *, ANTLRTokenType, INT32); @@ -4909,6 +4933,7 @@ public: VOID IdEqIdDoSpecial (IN UINT32 &, IN UINT32, IN EFI_QUESTION_ID, IN CHAR8 *, IN UINT32, IN EFI_QUESTION_ID, IN CHAR8 *, IN UINT32, IN EFI_COMPARE_TYPE); VOID IdEqListDoSpecial (IN UINT32 &, IN UINT32, IN EFI_QUESTION_ID, IN CHAR8 *, IN UINT32, IN UINT16, IN UINT16 *); VOID SetOverrideClassGuid (IN EFI_GUID *);+ VOID SetIsCatchDefaultEnable (BOOLEAN IsCatchDefaultEnable); >> } @@ -5086,6 +5111,17 @@ EfiVfrParser::_PCATCH ( mParserStatus = mParserStatus + gCVfrErrorHandle.HandleError (ReturnCode, LineNum, (CHAR8 *) ErrorMsg); } +VOID+EfiVfrParser::DefaultValueError (+ IN EFI_VFR_RETURN_CODE ReturnCode,+ IN UINT32 LineNum+ )+{+ CHAR8 ErrorMsg[100];+ sprintf(ErrorMsg, "please remove the default value / defaultstore in line %d", LineNum);+ mParserStatus = mParserStatus + gCVfrErrorHandle.HandleError (ReturnCode, LineNum, ErrorMsg);+}+ VOID EfiVfrParser::syn ( ANTLRAbstractToken *Tok,@@ -5688,6 +5724,12 @@ EfiVfrParser::SetOverrideClassGuid (IN EFI_GUID *OverrideClassGuid) mOverrideClassGuid = OverrideClassGuid; } +VOID+EfiVfrParser::SetIsCatchDefaultEnable (BOOLEAN IsCatchDefaultEnable)+{+ mIsCatchDefaultEnable = IsCatchDefaultEnable;+}+ VOID EfiVfrParser::CheckDuplicateDefaultValue ( IN EFI_DEFAULT_ID DefaultId,-- 2.39.1.windows.1 -=-=-=-=-=-= Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116948): https://edk2.groups.io/g/devel/message/116948 Mute This Topic: https://groups.io/mt/105061128/7976666 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [yuting2.y...@intel.com] -=-=-=-=-=-= -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116949): https://edk2.groups.io/g/devel/message/116949 Mute This Topic: https://groups.io/mt/105061128/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-