]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
Enable nest for suppressif/grayoutif/diableif for form/question/option.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / IfrParse.c
index 87924792a7d57cd3c8e254943f7d027ba861a1e7..2cd666fc707180a3c73f5660479939451ddaeef8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Parser for IFR binary encoding.\r
 \r
-Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -18,13 +18,6 @@ UINT16           mStatementIndex;
 UINT16           mExpressionOpCodeIndex;\r
 \r
 BOOLEAN          mInScopeSubtitle;\r
-BOOLEAN          mInScopeSuppress;\r
-BOOLEAN          mInScopeGrayOut;\r
-BOOLEAN          mInScopeDisable;\r
-FORM_EXPRESSION  *mSuppressExpression;\r
-FORM_EXPRESSION  *mGrayOutExpression;\r
-FORM_EXPRESSION  *mDisableExpression;\r
-\r
 /**\r
   Initialize Statement header members.\r
 \r
@@ -44,6 +37,7 @@ CreateStatement (
 {\r
   FORM_BROWSER_STATEMENT    *Statement;\r
   EFI_IFR_STATEMENT_HEADER  *StatementHdr;\r
+  INTN                      ConditionalExprCount; \r
 \r
   if (Form == NULL) {\r
     //\r
@@ -68,17 +62,18 @@ CreateStatement (
   CopyMem (&Statement->Prompt, &StatementHdr->Prompt, sizeof (EFI_STRING_ID));\r
   CopyMem (&Statement->Help, &StatementHdr->Help, sizeof (EFI_STRING_ID));\r
 \r
-  if (mInScopeSuppress) {\r
-    Statement->SuppressExpression = mSuppressExpression;\r
-  }\r
-\r
-  if (mInScopeGrayOut) {\r
-    Statement->GrayOutExpression = mGrayOutExpression;\r
-  }\r
-\r
-\r
-  if (mInScopeDisable) {\r
-    Statement->DisableExpression = mDisableExpression;\r
+  ConditionalExprCount = GetConditionalExpressionCount(ExpressStatement);\r
+  if (ConditionalExprCount > 0) {\r
+    //\r
+    // Form is inside of suppressif\r
+    //\r
+    \r
+    Statement->Expression = (FORM_EXPRESSION_LIST *) AllocatePool( \r
+                                             (UINTN) (sizeof(FORM_EXPRESSION_LIST) + ((ConditionalExprCount -1) * sizeof(FORM_EXPRESSION *))));\r
+    ASSERT (Statement->Expression != NULL);\r
+    Statement->Expression->Count     = (UINTN) ConditionalExprCount;\r
+    Statement->Expression->Signature = FORM_EXPRESSION_LIST_SIGNATURE;\r
+    CopyMem (Statement->Expression->Expression, GetConditionalExpressionList(ExpressStatement), (UINTN) (sizeof (FORM_EXPRESSION *) * ConditionalExprCount));\r
   }\r
 \r
   Statement->InSubtitle = mInScopeSubtitle;\r
@@ -629,6 +624,9 @@ DestroyStatement (
   while (!IsListEmpty (&Statement->OptionListHead)) {\r
     Link = GetFirstNode (&Statement->OptionListHead);\r
     Option = QUESTION_OPTION_FROM_LINK (Link);\r
+    if (Option->SuppressExpression != NULL) {\r
+      FreePool (Option->SuppressExpression);\r
+    }\r
     RemoveEntryList (&Option->Link);\r
 \r
     FreePool (Option);\r
@@ -656,6 +654,10 @@ DestroyStatement (
     DestroyExpression (Expression);\r
   }\r
 \r
+  if (Statement->Expression != NULL) {\r
+    FreePool (Statement->Expression);\r
+  }\r
+\r
   if (Statement->VariableName != NULL) {\r
     FreePool (Statement->VariableName);\r
   }\r
@@ -723,6 +725,10 @@ DestroyForm (
     FreePool (ConfigInfo);\r
   }\r
 \r
+  if (Form->SuppressExpression != NULL) {\r
+    FreePool (Form->SuppressExpression);\r
+  }\r
+\r
   //\r
   // Free this Form\r
   //\r
@@ -931,10 +937,6 @@ ParseOpCodes (
   EFI_IMAGE_ID            *ImageId;\r
   BOOLEAN                 SuppressForQuestion;\r
   BOOLEAN                 SuppressForOption;\r
-  BOOLEAN                 InScopeOptionSuppress;\r
-  FORM_EXPRESSION         *OptionSuppressExpression;\r
-  BOOLEAN                 InScopeFormSuppress;\r
-  FORM_EXPRESSION         *FormSuppressExpression;\r
   UINT16                  DepthOfDisable;\r
   BOOLEAN                 OpCodeDisabled;\r
   BOOLEAN                 SingleOpCodeExpression;\r
@@ -946,15 +948,13 @@ ParseOpCodes (
   FORMSET_STORAGE         *VarStorage;\r
   LIST_ENTRY              *MapExpressionList;\r
   EFI_VARSTORE_ID         TempVarstoreId;\r
+  BOOLEAN                 InScopeDisable;\r
+  INTN                    ConditionalExprCount;\r
 \r
   mInScopeSubtitle         = FALSE;\r
   SuppressForQuestion      = FALSE;\r
   SuppressForOption        = FALSE;\r
-  InScopeFormSuppress      = FALSE;\r
-  mInScopeSuppress         = FALSE;\r
-  InScopeOptionSuppress    = FALSE;\r
-  mInScopeGrayOut          = FALSE;\r
-  mInScopeDisable          = FALSE;\r
+  InScopeDisable           = FALSE;\r
   DepthOfDisable           = 0;\r
   OpCodeDisabled           = FALSE;\r
   SingleOpCodeExpression   = FALSE;\r
@@ -962,8 +962,6 @@ ParseOpCodes (
   CurrentExpression        = NULL;\r
   CurrentDefault           = NULL;\r
   CurrentOption            = NULL;\r
-  OptionSuppressExpression = NULL;\r
-  FormSuppressExpression   = NULL;\r
   ImageId                  = NULL;\r
   MapMethod                = NULL;\r
   MapScopeDepth            = 0;\r
@@ -971,6 +969,7 @@ ParseOpCodes (
   VarStorage               = NULL;\r
   MapExpressionList        = NULL;\r
   TempVarstoreId           = 0;\r
+  ConditionalExprCount     = 0;\r
 \r
   //\r
   // Get the number of Statements and Expressions\r
@@ -1032,7 +1031,7 @@ ParseOpCodes (
 \r
         if (ScopeOpCode == EFI_IFR_DISABLE_IF_OP) {\r
           if (DepthOfDisable == 0) {\r
-            mInScopeDisable = FALSE;\r
+            InScopeDisable = FALSE;\r
             OpCodeDisabled = FALSE;\r
           } else {\r
             DepthOfDisable--;\r
@@ -1063,7 +1062,7 @@ ParseOpCodes (
         CopyMem (&ExpressionOpCode->QuestionId2, &((EFI_IFR_EQ_ID_ID *) OpCodeData)->QuestionId2, sizeof (EFI_QUESTION_ID));\r
         break;\r
 \r
-      case EFI_IFR_EQ_ID_LIST_OP:\r
+      case EFI_IFR_EQ_ID_VAL_LIST_OP:\r
         CopyMem (&ExpressionOpCode->QuestionId, &((EFI_IFR_EQ_ID_VAL_LIST *) OpCodeData)->QuestionId, sizeof (EFI_QUESTION_ID));\r
         CopyMem (&ExpressionOpCode->ListLength, &((EFI_IFR_EQ_ID_VAL_LIST *) OpCodeData)->ListLength, sizeof (UINT16));\r
         ExpressionOpCode->ValueList = AllocateCopyPool (ExpressionOpCode->ListLength * sizeof (UINT16), &((EFI_IFR_EQ_ID_VAL_LIST *) OpCodeData)->ValueList);\r
@@ -1288,7 +1287,7 @@ ParseOpCodes (
         //\r
         SingleOpCodeExpression = FALSE;\r
 \r
-        if (mInScopeDisable && CurrentForm == NULL) {\r
+        if (InScopeDisable && CurrentForm == NULL) {\r
           //\r
           // This is DisableIf expression for Form, it should be a constant expression\r
           //\r
@@ -1351,11 +1350,17 @@ ParseOpCodes (
       CopyMem (&CurrentForm->FormId,    &((EFI_IFR_FORM *) OpCodeData)->FormId,    sizeof (UINT16));\r
       CopyMem (&CurrentForm->FormTitle, &((EFI_IFR_FORM *) OpCodeData)->FormTitle, sizeof (EFI_STRING_ID));\r
 \r
-      if (InScopeFormSuppress) {\r
+      ConditionalExprCount = GetConditionalExpressionCount(ExpressForm);\r
+      if ( ConditionalExprCount > 0) {\r
         //\r
         // Form is inside of suppressif\r
         //\r
-        CurrentForm->SuppressExpression = FormSuppressExpression;\r
+        CurrentForm->SuppressExpression = (FORM_EXPRESSION_LIST *) AllocatePool( \r
+                                                 (UINTN) (sizeof(FORM_EXPRESSION_LIST) + ((ConditionalExprCount -1) * sizeof(FORM_EXPRESSION *))));\r
+        ASSERT (CurrentForm->SuppressExpression != NULL);\r
+        CurrentForm->SuppressExpression->Count     = (UINTN) ConditionalExprCount;\r
+        CurrentForm->SuppressExpression->Signature = FORM_EXPRESSION_LIST_SIGNATURE;\r
+        CopyMem (CurrentForm->SuppressExpression->Expression, GetConditionalExpressionList(ExpressForm), (UINTN) (sizeof (FORM_EXPRESSION *) * ConditionalExprCount));\r
       }\r
 \r
       if (Scope != 0) {\r
@@ -1410,11 +1415,17 @@ ParseOpCodes (
         CopyMem (&CurrentForm->FormTitle, &MapMethod->MethodTitle, sizeof (EFI_STRING_ID));\r
       }\r
 \r
-      if (InScopeFormSuppress) {\r
+      ConditionalExprCount = GetConditionalExpressionCount(ExpressForm);\r
+      if ( ConditionalExprCount > 0) {\r
         //\r
         // Form is inside of suppressif\r
         //\r
-        CurrentForm->SuppressExpression = FormSuppressExpression;\r
+        CurrentForm->SuppressExpression = (FORM_EXPRESSION_LIST *) AllocatePool( \r
+                                                 (UINTN) (sizeof(FORM_EXPRESSION_LIST) + ((ConditionalExprCount -1) * sizeof(FORM_EXPRESSION *))));\r
+        ASSERT (CurrentForm->SuppressExpression != NULL);\r
+        CurrentForm->SuppressExpression->Count     = (UINTN) ConditionalExprCount;\r
+        CurrentForm->SuppressExpression->Signature = FORM_EXPRESSION_LIST_SIGNATURE;\r
+        CopyMem (CurrentForm->SuppressExpression->Expression, GetConditionalExpressionList(ExpressForm), (UINTN) (sizeof (FORM_EXPRESSION *) * ConditionalExprCount));\r
       }\r
 \r
       if (Scope != 0) {\r
@@ -1799,8 +1810,17 @@ ParseOpCodes (
       CopyMem (&CurrentOption->Value.Value, &((EFI_IFR_ONE_OF_OPTION *) OpCodeData)->Value, sizeof (EFI_IFR_TYPE_VALUE));\r
       ExtendValueToU64 (&CurrentOption->Value);\r
 \r
-      if (InScopeOptionSuppress) {\r
-        CurrentOption->SuppressExpression = OptionSuppressExpression;\r
+      ConditionalExprCount = GetConditionalExpressionCount(ExpressOption);\r
+      if ( ConditionalExprCount > 0) {\r
+        //\r
+        // Form is inside of suppressif\r
+        //\r
+        CurrentOption->SuppressExpression = (FORM_EXPRESSION_LIST *) AllocatePool( \r
+                                                 (UINTN) (sizeof(FORM_EXPRESSION_LIST) + ((ConditionalExprCount -1) * sizeof(FORM_EXPRESSION *))));\r
+        ASSERT (CurrentOption->SuppressExpression != NULL);\r
+        CurrentOption->SuppressExpression->Count     = (UINTN) ConditionalExprCount;\r
+        CurrentOption->SuppressExpression->Signature = FORM_EXPRESSION_LIST_SIGNATURE;\r
+        CopyMem (CurrentOption->SuppressExpression->Expression, GetConditionalExpressionList(ExpressOption), (UINTN) (sizeof (FORM_EXPRESSION *) * ConditionalExprCount));\r
       }\r
 \r
       //\r
@@ -1841,6 +1861,10 @@ ParseOpCodes (
         CurrentStatement->StorageWidth = (UINT16) (CurrentStatement->MaxContainers * Width);\r
         CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth);\r
         CurrentStatement->ValueType = CurrentOption->Value.Type;\r
+        if (CurrentStatement->HiiValue.Type == EFI_IFR_TYPE_BUFFER) {\r
+          CurrentStatement->HiiValue.Buffer = CurrentStatement->BufferValue;\r
+          CurrentStatement->HiiValue.BufferLen = CurrentStatement->StorageWidth;\r
+        }\r
 \r
         InitializeRequestElement (FormSet, CurrentStatement, CurrentForm);\r
       }\r
@@ -1888,14 +1912,11 @@ ParseOpCodes (
       }\r
 \r
       if (SuppressForOption) {\r
-        InScopeOptionSuppress = TRUE;\r
-        OptionSuppressExpression = CurrentExpression;\r
+        PushConditionalExpression(CurrentExpression, ExpressOption);       \r
       } else if (SuppressForQuestion) {\r
-        mInScopeSuppress = TRUE;\r
-        mSuppressExpression = CurrentExpression;\r
+        PushConditionalExpression(CurrentExpression, ExpressStatement);  \r
       } else {\r
-        InScopeFormSuppress = TRUE;\r
-        FormSuppressExpression = CurrentExpression;\r
+        PushConditionalExpression(CurrentExpression, ExpressForm);  \r
       }\r
 \r
       //\r
@@ -1914,9 +1935,7 @@ ParseOpCodes (
       CurrentExpression = CreateExpression (CurrentForm);\r
       CurrentExpression->Type = EFI_HII_EXPRESSION_GRAY_OUT_IF;\r
       InsertTailList (&CurrentForm->ExpressionListHead, &CurrentExpression->Link);\r
-\r
-      mInScopeGrayOut = TRUE;\r
-      mGrayOutExpression = CurrentExpression;\r
+      PushConditionalExpression(CurrentExpression, ExpressStatement);\r
 \r
       //\r
       // Take a look at next OpCode to see whether current expression consists\r
@@ -1943,12 +1962,11 @@ ParseOpCodes (
         // This is DisableIf for Question, enqueue it to Form expression list\r
         //\r
         InsertTailList (&CurrentForm->ExpressionListHead, &CurrentExpression->Link);\r
+        PushConditionalExpression(CurrentExpression, ExpressStatement);\r
       }\r
 \r
-      mDisableExpression = CurrentExpression;\r
-      mInScopeDisable    = TRUE;\r
-      OpCodeDisabled     = FALSE;\r
-\r
+      OpCodeDisabled  = FALSE;\r
+      InScopeDisable  = TRUE;\r
       //\r
       // Take a look at next OpCode to see whether current expression consists\r
       // of single OpCode\r
@@ -2231,20 +2249,23 @@ ParseOpCodes (
 \r
       case EFI_IFR_SUPPRESS_IF_OP:\r
         if (SuppressForOption) {\r
-          InScopeOptionSuppress = FALSE;\r
+          PopConditionalExpression(ExpressOption);      \r
         } else if (SuppressForQuestion) {\r
-          mInScopeSuppress = FALSE;\r
+          PopConditionalExpression(ExpressStatement);\r
         } else {\r
-          InScopeFormSuppress = FALSE;\r
+          PopConditionalExpression(ExpressForm);\r
         }\r
         break;\r
 \r
       case EFI_IFR_GRAY_OUT_IF_OP:\r
-        mInScopeGrayOut = FALSE;\r
+        PopConditionalExpression(ExpressStatement);\r
         break;\r
 \r
       case EFI_IFR_DISABLE_IF_OP:\r
-        mInScopeDisable = FALSE;\r
+        if (CurrentForm != NULL) {\r
+          PopConditionalExpression(ExpressStatement);\r
+        }\r
+        InScopeDisable = FALSE;\r
         OpCodeDisabled = FALSE;\r
         break;\r
 \r
@@ -2276,7 +2297,7 @@ ParseOpCodes (
 \r
       default:\r
         if (IsExpressionOpCode (ScopeOpCode)) {\r
-          if (mInScopeDisable && CurrentForm == NULL) {\r
+          if (InScopeDisable && CurrentForm == NULL) {\r
             //\r
             // This is DisableIf expression for Form, it should be a constant expression\r
             //\r