1. FormID can't be set to zero.
authorlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 7 Sep 2009 03:31:10 +0000 (03:31 +0000)
committerlgao4 <lgao4@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 7 Sep 2009 03:31:10 +0000 (03:31 +0000)
2. Check the default value for Numeric and OneOf opcode.
3. Support #pragma Pack(show)

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1697 7335b38e-4728-0410-8992-fb3ffe349368

Source/C/VfrCompile/VfrError.cpp
Source/C/VfrCompile/VfrFormPkg.cpp
Source/C/VfrCompile/VfrFormPkg.h
Source/C/VfrCompile/VfrSyntax.g
Source/C/VfrCompile/VfrUtilityLib.cpp

index b24cc72..4e7a4f6 100644 (file)
@@ -201,7 +201,11 @@ CVfrErrorHandle::PrintMsg (
 {\r
   CHAR8                  *FileName = NULL;\r
   UINT32                 FileLine;\r
-\r
+  \r
+  if (strnicmp ("Warning", MsgType, strlen ("Warning")) == 0) {\r
+    VerboseMsg (ErrorMsg);\r
+    return;\r
+  }\r
   GetFileNameLineNum (LineNum, &FileName, &FileLine);\r
   Error (FileName, FileLine, 0x3000, TokName, "\t%s\n", ErrorMsg);\r
 }\r
index 654daed..298eb02 100644 (file)
@@ -787,11 +787,22 @@ CIfrRecordInfoDB::IfrRecordInfoUpdate (
   )\r
 {\r
   SIfrRecord *pNode;\r
+  SIfrRecord *Prev;\r
 \r
   if ((pNode = GetRecordInfoFromIdx (RecordIdx)) == NULL) {\r
     return;\r
   }\r
 \r
+  if (LineNo == 0) {\r
+    //\r
+    // Line number is not specified explicitly, try to use line number of previous opcode\r
+    //\r
+    Prev = GetRecordInfoFromIdx (RecordIdx - 1);\r
+    if (Prev != NULL) {\r
+      LineNo = Prev->mLineNo;\r
+    }\r
+  }\r
+\r
   pNode->mLineNo    = LineNo;\r
   pNode->mOffset    = Offset;\r
   pNode->mBinBufLen = BinBufLen;\r
index c0171db..fa671c1 100644 (file)
@@ -254,7 +254,7 @@ public:
 \r
   VOID DecLength (UINT8 Size) {\r
     if (mHeader->Length >= Size) {\r
-         mHeader -= Size;\r
+      mHeader -= Size;\r
     }\r
   }\r
 \r
@@ -358,7 +358,7 @@ public:
 \r
   VOID SetVarStoreInfo (IN EFI_VARSTORE_INFO *Info) {\r
     mHeader->VarStoreId             = Info->mVarStoreId;\r
-         mHeader->VarStoreInfo.VarName   = Info->mInfo.mVarName;\r
+    mHeader->VarStoreInfo.VarName   = Info->mInfo.mVarName;\r
     mHeader->VarStoreInfo.VarOffset = Info->mInfo.mVarOffset;\r
   }\r
 \r
@@ -398,7 +398,8 @@ public:
   }\r
 };\r
 \r
-static CIfrQuestionHeader *gCurrentQuestion = NULL;\r
+static CIfrQuestionHeader *gCurrentQuestion  = NULL;\r
+static CIfrObj            *gCurrentIfrOpcode = NULL;\r
 \r
 /*\r
  * The definition of CIfrMinMaxStepData\r
@@ -537,6 +538,12 @@ public:
   }\r
 \r
   EFI_VFR_RETURN_CODE SetFormId (IN EFI_FORM_ID FormId) {\r
+    if (FormId == 0) {\r
+      //\r
+      // FormId can't be 0.\r
+      //\r
+      return VFR_RETURN_INVALID_PARAMETER;\r
+    }\r
     if (CIfrForm::ChekFormIdFree (FormId) == FALSE) {\r
       return VFR_RETURN_FORMID_REDEFINED;\r
     }\r
@@ -688,7 +695,7 @@ public:
     ) : CIfrObj (EFI_IFR_DEFAULT_OP, (CHAR8 **)&mDefault),\r
         CIfrOpHeader (EFI_IFR_DEFAULT_OP, &mDefault->Header) {\r
     mDefault->Type      = Type;\r
-         mDefault->Value     = Value;\r
+    mDefault->Value     = Value;\r
     mDefault->DefaultId = DefaultId;\r
   }\r
 \r
@@ -722,7 +729,7 @@ private:
 public:\r
   CIfrSubtitle () : CIfrObj (EFI_IFR_SUBTITLE_OP, (CHAR8 **)&mSubtitle),\r
                   CIfrOpHeader (EFI_IFR_SUBTITLE_OP, &mSubtitle->Header),\r
-                                 CIfrStatementHeader (&mSubtitle->Statement) {\r
+  CIfrStatementHeader (&mSubtitle->Statement) {\r
     mSubtitle->Flags = 0;\r
   }\r
 \r
@@ -856,7 +863,7 @@ private:
 public:\r
   CIfrResetButton () : CIfrObj (EFI_IFR_RESET_BUTTON_OP, (CHAR8 **)&mResetButton),\r
                        CIfrOpHeader (EFI_IFR_RESET_BUTTON_OP, &mResetButton->Header), \r
-                                          CIfrStatementHeader (&mResetButton->Statement) {\r
+  CIfrStatementHeader (&mResetButton->Statement) {\r
     mResetButton->DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
   }\r
 \r
@@ -874,11 +881,11 @@ public:
                      CIfrOpHeader (EFI_IFR_CHECKBOX_OP, &mCheckBox->Header), \r
                      CIfrQuestionHeader (&mCheckBox->Question) {\r
     mCheckBox->Flags = 0;\r
-    gCurrentQuestion = this;\r
+    gCurrentQuestion  = this;\r
   }\r
 \r
   ~CIfrCheckBox () {\r
-    gCurrentQuestion = NULL;\r
+    gCurrentQuestion  = NULL;\r
   }\r
 \r
   EFI_VFR_RETURN_CODE SetFlags (IN UINT8 HFlags, UINT8 LFlags) {\r
@@ -974,11 +981,13 @@ public:
                    CIfrQuestionHeader (&mNumeric->Question),\r
                    CIfrMinMaxStepData (&mNumeric->data) {\r
     mNumeric->Flags  = EFI_IFR_NUMERIC_SIZE_1 | EFI_IFR_DISPLAY_UINT_DEC;\r
-    gCurrentQuestion = this;\r
+    gCurrentQuestion  = this;\r
+    gCurrentIfrOpcode = this;\r
   }\r
 \r
   ~CIfrNumeric () {\r
-    gCurrentQuestion = NULL;\r
+    gCurrentQuestion  = NULL;\r
+    gCurrentIfrOpcode = NULL;\r
   }\r
 \r
   EFI_VFR_RETURN_CODE SetFlags (IN UINT8 HFlags, IN UINT8 LFlags) {\r
@@ -1008,11 +1017,13 @@ public:
                  CIfrQuestionHeader (&mOneOf->Question),\r
                  CIfrMinMaxStepData (&mOneOf->data) {\r
     mOneOf->Flags    = 0;\r
-    gCurrentQuestion = this;\r
+    gCurrentQuestion  = this;\r
+    gCurrentIfrOpcode = this;\r
   }\r
 \r
   ~CIfrOneOf () {\r
-    gCurrentQuestion = NULL;\r
+    gCurrentQuestion  = NULL;\r
+    gCurrentIfrOpcode = NULL;\r
   }\r
 \r
   EFI_VFR_RETURN_CODE SetFlags (IN UINT8 HFlags, IN UINT8 LFlags) {\r
index 9abbe15..c01f16e 100644 (file)
@@ -1078,7 +1078,7 @@ vfrStatementRules :
 vfrStatementDefault :\r
   <<\r
      BOOLEAN               IsExp         = FALSE;\r
-     EFI_IFR_TYPE_VALUE    Val = gZeroEfiIfrTypeValue;\r
+     EFI_IFR_TYPE_VALUE    Val           = gZeroEfiIfrTypeValue;\r
      CIfrDefault           DObj;\r
      EFI_DEFAULT_ID        DefaultId     = EFI_HII_DEFAULT_CLASS_STANDARD;\r
      CHAR8                 *VarStoreName = NULL;\r
@@ -1088,8 +1088,72 @@ vfrStatementDefault :
   (\r
     (\r
         vfrStatementValue ","                       << IsExp = TRUE; DObj.SetScope (1); CIfrEnd EndObj1; EndObj1.SetLineNo(D->getLine()); >>\r
-      | "=" vfrConstantValueField[_GET_CURRQEST_DATATYPE()] > [Val] ","\r
-                                                    << DObj.SetType (_GET_CURRQEST_DATATYPE()); DObj.SetValue(Val); >>\r
+      | "=" vfrConstantValueField[_GET_CURRQEST_DATATYPE()] > [Val] ","  << \r
+\r
+                                                        if (gCurrentIfrOpcode != NULL && gCurrentIfrOpcode->GetObjBinAddr() != NULL) {\r
+                                                          EFI_IFR_OP_HEADER *TempOpCode;\r
+                                                          TempOpCode = (EFI_IFR_OP_HEADER *) gCurrentIfrOpcode->GetObjBinAddr();\r
+                                                          switch (TempOpCode->OpCode) {\r
+                                                          case EFI_IFR_NUMERIC_OP:\r
+                                                            EFI_IFR_NUMERIC *TempNumricCode;\r
+                                                            TempNumricCode = (EFI_IFR_NUMERIC *) TempOpCode;\r
+                                                            switch (_GET_CURRQEST_DATATYPE()) {\r
+                                                            case EFI_IFR_TYPE_NUM_SIZE_64:\r
+                                                              if (Val.u64 < TempNumricCode->data.u64.MinValue || Val.u64 > TempNumricCode->data.u64.MaxValue) {\r
+                                                                _PCATCH (VFR_RETURN_INVALID_PARAMETER, D->getLine(), "Numeric default value must be between MinValue and MaxValue.");\r
+                                                              }\r
+                                                              break;\r
+                                                            case EFI_IFR_TYPE_NUM_SIZE_32:\r
+                                                              if (Val.u32 < TempNumricCode->data.u32.MinValue || Val.u32 > TempNumricCode->data.u32.MaxValue) {\r
+                                                                _PCATCH (VFR_RETURN_INVALID_PARAMETER, D->getLine(), "Numeric default value must be between MinValue and MaxValue.");\r
+                                                              }\r
+                                                              break;\r
+                                                            case EFI_IFR_TYPE_NUM_SIZE_16:\r
+                                                              if (Val.u16 < TempNumricCode->data.u16.MinValue || Val.u16 > TempNumricCode->data.u16.MaxValue) {\r
+                                                                _PCATCH (VFR_RETURN_INVALID_PARAMETER, D->getLine(), "Numeric default value must be between MinValue and MaxValue.");\r
+                                                              }\r
+                                                              break;\r
+                                                            case EFI_IFR_TYPE_NUM_SIZE_8:\r
+                                                              if (Val.u8 < TempNumricCode->data.u8.MinValue || Val.u8 > TempNumricCode->data.u8.MaxValue) {\r
+                                                                _PCATCH (VFR_RETURN_INVALID_PARAMETER, D->getLine(), "Numeric default value must be between MinValue and MaxValue.");\r
+                                                              }\r
+                                                              break;\r
+                                                            }\r
+                                                            break;\r
+                                                          case EFI_IFR_ONE_OF_OP:\r
+                                                            EFI_IFR_ONE_OF *TempOneOfCode;\r
+                                                            TempOneOfCode = (EFI_IFR_ONE_OF *) TempOpCode;\r
+                                                            if (TempOneOfCode->data.u64.MinValue != 0 || TempOneOfCode->data.u64.MaxValue != 0 || TempOneOfCode->data.u64.Step != 0) {\r
+                                                              //OneOf MinMaxStep Data is set, Val value will be checked for MinMaxStep.\r
+                                                              switch (_GET_CURRQEST_DATATYPE()) {\r
+                                                              case EFI_IFR_TYPE_NUM_SIZE_64:\r
+                                                                if (Val.u64 < TempOneOfCode->data.u64.MinValue || Val.u64 > TempOneOfCode->data.u64.MaxValue) {\r
+                                                                  _PCATCH (VFR_RETURN_INVALID_PARAMETER, D->getLine(), "OneOf default value must be between MinValue and MaxValue.");\r
+                                                                }\r
+                                                                break;\r
+                                                              case EFI_IFR_TYPE_NUM_SIZE_32:\r
+                                                                if (Val.u32 < TempOneOfCode->data.u32.MinValue || Val.u32 > TempOneOfCode->data.u32.MaxValue) {\r
+                                                                  _PCATCH (VFR_RETURN_INVALID_PARAMETER, D->getLine(), "OneOf default value must be between MinValue and MaxValue.");\r
+                                                                }\r
+                                                                break;\r
+                                                              case EFI_IFR_TYPE_NUM_SIZE_16:\r
+                                                                if (Val.u16 < TempOneOfCode->data.u16.MinValue || Val.u16 > TempOneOfCode->data.u16.MaxValue) {\r
+                                                                  _PCATCH (VFR_RETURN_INVALID_PARAMETER, D->getLine(), "OneOf default value must be between MinValue and MaxValue.");\r
+                                                                }\r
+                                                                break;\r
+                                                              case EFI_IFR_TYPE_NUM_SIZE_8:\r
+                                                                if (Val.u8 < TempOneOfCode->data.u8.MinValue || Val.u8 > TempOneOfCode->data.u8.MaxValue) {\r
+                                                                  _PCATCH (VFR_RETURN_INVALID_PARAMETER, D->getLine(), "OneOf default value must be between MinValue and MaxValue.");\r
+                                                                }\r
+                                                                break;\r
+                                                              }\r
+                                                            }\r
+                                                            break;\r
+                                                          }\r
+                                                        }\r
+                                                        DObj.SetType (_GET_CURRQEST_DATATYPE()); \r
+                                                        DObj.SetValue(Val);\r
+                                                    >>\r
     )\r
     {\r
       DefaultStore "=" SN:StringIdentifier ","      << _PCATCH(mCVfrDefaultStore.GetDefaultId (SN->getText(), &DefaultId), SN); DObj.SetDefaultId (DefaultId); >>\r
@@ -1588,15 +1652,30 @@ vfrStatementDate :
   ;\r
 \r
 minMaxDateStepDefault[EFI_HII_DATE & D, UINT8 KeyValue] :\r
-  Minimum   "=" Number ","\r
-  Maximum   "=" Number ","\r
+  Minimum   "=" MinN:Number ","\r
+  Maximum   "=" MaxN:Number ","\r
   { "step"    "=" Number "," }\r
   {\r
     "default" "=" N:Number ","                         <<\r
                                                           switch (KeyValue) {\r
-                                                          case 0: D.Year  = _STOU16(N->getText()); break;\r
-                                                          case 1: D.Month = _STOU8(N->getText()); break;\r
-                                                          case 2: D.Day   = _STOU8(N->getText()); break;\r
+                                                          case 0: \r
+                                                            D.Year  = _STOU16(N->getText());\r
+                                                            if (D.Year < _STOU16 (MinN->getText()) || D.Year > _STOU16 (MaxN->getText())) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, N->getLine(), "Year default value must be between Min year and Max year.");\r
+                                                            }\r
+                                                            break;\r
+                                                          case 1: \r
+                                                            D.Month = _STOU8(N->getText()); \r
+                                                            if (D.Month < 1 || D.Month > 12) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, N->getLine(), "Month default value must be between 1 and 12.");\r
+                                                            }\r
+                                                            break;\r
+                                                          case 2: \r
+                                                            D.Day = _STOU8(N->getText()); \r
+                                                            if (D.Day < 1 || D.Day > 31) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, N->getLine(), "Day default value must be between 1 and 31.");\r
+                                                            }\r
+                                                            break;\r
                                                           }\r
                                                        >>\r
   }\r
@@ -1642,10 +1721,30 @@ vfrSetMinMaxStep[CIfrMinMaxStepData & MMSDObj] :
   Maximum   "=" A:Number ","\r
                                                        <<\r
                                                           switch (_GET_CURRQEST_DATATYPE ()) {\r
-                                                          case EFI_IFR_TYPE_NUM_SIZE_64 : MaxU8 = _STOU64(A->getText()); break;\r
-                                                          case EFI_IFR_TYPE_NUM_SIZE_32 : MaxU4 = _STOU32(A->getText()); break;\r
-                                                          case EFI_IFR_TYPE_NUM_SIZE_16 : MaxU2 = _STOU16(A->getText()); break;\r
-                                                          case EFI_IFR_TYPE_NUM_SIZE_8 :  MaxU1 = _STOU8(A->getText());  break;\r
+                                                          case EFI_IFR_TYPE_NUM_SIZE_64 : \r
+                                                            MaxU8 = _STOU64(A->getText()); \r
+                                                            if (MaxU8 < MinU8) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, A->getLine(), "Maximum can't be less than Minimum");\r
+                                                            }\r
+                                                            break;\r
+                                                          case EFI_IFR_TYPE_NUM_SIZE_32 : \r
+                                                            MaxU4 = _STOU32(A->getText()); \r
+                                                            if (MaxU4 < MinU4) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, A->getLine(), "Maximum can't be less than Minimum");\r
+                                                            }\r
+                                                            break;\r
+                                                          case EFI_IFR_TYPE_NUM_SIZE_16 : \r
+                                                            MaxU2 = _STOU16(A->getText()); \r
+                                                            if (MaxU2 < MinU2) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, A->getLine(), "Maximum can't be less than Minimum");\r
+                                                            }\r
+                                                            break;\r
+                                                          case EFI_IFR_TYPE_NUM_SIZE_8 :  \r
+                                                            MaxU1 = _STOU8(A->getText());  \r
+                                                            if (MaxU1 < MinU1) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, A->getLine(), "Maximum can't be less than Minimum");\r
+                                                            }\r
+                                                            break;\r
                                                           }\r
                                                        >>\r
   {\r
@@ -1894,9 +1993,24 @@ minMaxTimeStepDefault[EFI_HII_TIME & T, UINT8 KeyValue] :
   {\r
     "default" "=" N:Number ","                         <<\r
                                                           switch (KeyValue) {\r
-                                                          case 0: T.Hour   = _STOU8(N->getText()); break;\r
-                                                          case 1: T.Minute = _STOU8(N->getText()); break;\r
-                                                          case 2: T.Second = _STOU8(N->getText()); break;\r
+                                                          case 0: \r
+                                                            T.Hour   = _STOU8(N->getText()); \r
+                                                            if (T.Hour > 23) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, N->getLine(), "Hour default value must be between 0 and 23.");\r
+                                                            }\r
+                                                            break;\r
+                                                          case 1: \r
+                                                            T.Minute = _STOU8(N->getText()); \r
+                                                            if (T.Minute > 59) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, N->getLine(), "Minute default value must be between 0 and 59.");\r
+                                                            }\r
+                                                            break;\r
+                                                          case 2: \r
+                                                            T.Second = _STOU8(N->getText());\r
+                                                            if (T.Second > 59) {\r
+                                                              _PCATCH (VFR_RETURN_INVALID_PARAMETER, N->getLine(), "Second default value must be between 0 and 59.");\r
+                                                            }\r
+                                                            break;\r
                                                           }\r
                                                        >>\r
   }\r
@@ -3090,7 +3204,6 @@ public:
 \r
   VOID                _STRCAT (IN OUT CHAR8 **, IN CHAR8 *);\r
 \r
-  VOID                _CRGUID (EFI_GUID *, CHAR8 *, CHAR8 *, CHAR8 *, CHAR8 *, CHAR8 *, CHAR8 *, CHAR8 *, CHAR8 *, CHAR8 *, CHAR8 *, CHAR8 *);\r
   VOID                _DeclareDefaultLinearVarStore (IN UINT32);\r
   VOID                _DeclareStandardDefaultStorage (IN UINT32);\r
   VOID                _DeclareDefaultFrameworkVarStore (IN UINT32);\r
@@ -3490,35 +3603,6 @@ EfiVfrParser::_STRCAT (
   *Dest = NewStr;\r
 }\r
 \r
-VOID\r
-EfiVfrParser::_CRGUID (\r
-  IN EFI_GUID *Guid,\r
-  IN CHAR8    *G1,\r
-  IN CHAR8    *G2,\r
-  IN CHAR8    *G3,\r
-  IN CHAR8    *G4,\r
-  IN CHAR8    *G5,\r
-  IN CHAR8    *G6,\r
-  IN CHAR8    *G7,\r
-  IN CHAR8    *G8,\r
-  IN CHAR8    *G9,\r
-  IN CHAR8    *G10,\r
-  IN CHAR8    *G11\r
-  )\r
-{\r
-  Guid->Data1 = _STOU32 (G1);\r
-  Guid->Data2 = _STOU16 (G2);\r
-  Guid->Data3 = _STOU16 (G3);\r
-  Guid->Data4[0] = _STOU8(G4);\r
-  Guid->Data4[1] = _STOU8(G5);\r
-  Guid->Data4[2] = _STOU8(G6);\r
-  Guid->Data4[3] = _STOU8(G7);\r
-  Guid->Data4[4] = _STOU8(G8);\r
-  Guid->Data4[5] = _STOU8(G9);\r
-  Guid->Data4[6] = _STOU8(G10);\r
-  Guid->Data4[7] = _STOU8(G11);\r
-}\r
-\r
 //\r
 // framework vfr to default declare varstore for each structure\r
 //\r
index e59fbb7..f047b2c 100644 (file)
@@ -870,7 +870,7 @@ CVfrVarDataTypeDB::Pack (
     SVfrPackStackNode *pNode = NULL;\r
 \r
     if (mPackStack == NULL) {\r
-      gCVfrErrorHandle.PrintMsg (LineNum, "", "Warning", "#pragma pack(pop...) : more pops than pushes");\r
+      gCVfrErrorHandle.PrintMsg (LineNum, "", "Error", "#pragma pack(pop...) : more pops than pushes");\r
     }\r
 \r
     for (pNode = mPackStack; pNode != NULL; pNode = pNode->mNext) {\r
@@ -884,7 +884,7 @@ CVfrVarDataTypeDB::Pack (
   if (Action & VFR_PACK_ASSIGN) {\r
     PackAlign = (Number > 1) ? Number + Number % 2 : Number;\r
     if ((PackAlign == 0) || (PackAlign > 16)) {\r
-      gCVfrErrorHandle.PrintMsg (LineNum, "", "Warning", "expected pragma parameter to be '1', '2', '4', '8', or '16'");\r
+      gCVfrErrorHandle.PrintMsg (LineNum, "", "Error", "expected pragma parameter to be '1', '2', '4', '8', or '16'");\r
     } else {\r
       mPackAlign = PackAlign;\r
     }\r