Handle fault messages in duplex callback channel.
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / GroupingCollection.cs
index f3f9e31df86f771e9334491c6d7c5849ef702ef5..0ebb654aa25912f25c14345767dbfc7beb041865 100644 (file)
@@ -28,6 +28,7 @@
 
 #if NET_2_0
 
+using System;
 using System.Collections;
 using System.Collections.Generic;
 
@@ -142,18 +143,34 @@ namespace Microsoft.Build.BuildEngine {
                        }
                }
 
+               internal void Remove (BuildItemGroup big)
+               {
+                       if (big.ParentProject != project)
+                               throw new InvalidOperationException (
+                                       "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.");
+
+                       big.Detach ();
+                       list.Remove (big);
+               }
+
+               internal void Remove (BuildPropertyGroup bpg)
+               {
+                       // FIXME: add bpg.Detach ();
+                       bpg.XmlElement.ParentNode.RemoveChild (bpg.XmlElement);
+                       list.Remove (bpg);
+               }
+
                internal void Evaluate ()
                {
                        Evaluate (EvaluationType.Property);
-
                        Evaluate (EvaluationType.Item);
+                       Evaluate (EvaluationType.Choose);
                }
 
-               void Evaluate (EvaluationType type)
+               internal void Evaluate (EvaluationType type)
                {
                        BuildItemGroup big;
                        BuildPropertyGroup bpg;
-                       Import import;
                        LinkedListNode <object> evaluate_iterator;
 
                        if (type == EvaluationType.Property) {
@@ -163,12 +180,13 @@ namespace Microsoft.Build.BuildEngine {
                                while (evaluate_iterator != null) {
                                        if (evaluate_iterator.Value is BuildPropertyGroup) {
                                                bpg = (BuildPropertyGroup) evaluate_iterator.Value;
-                                               if (ConditionParser.ParseAndEvaluate (bpg.Condition, project))
-                                                       bpg.Evaluate ();
-                                       } else if (evaluate_iterator.Value is Import) {
-                                               import = (Import) evaluate_iterator.Value;
-                                               if (ConditionParser.ParseAndEvaluate (import.Condition, project))
-                                                       import.Evaluate ();
+                                               project.PushThisFileProperty (bpg.DefinedInFileName);
+                                               try {
+                                                       if (ConditionParser.ParseAndEvaluate (bpg.Condition, project))
+                                                               bpg.Evaluate ();
+                                               } finally {
+                                                       project.PopThisFileProperty ();
+                                               }
                                        }
 
                                        // if it wasn't moved by adding anything because of evaluating a Import shift it
@@ -177,20 +195,55 @@ namespace Microsoft.Build.BuildEngine {
 
                                        evaluate_iterator = evaluate_iterator.Next;
                                }
-                       } else {
+                       } else if (type == EvaluationType.Item) {
                                evaluate_iterator = list.First;
                                add_iterator = list.First;
 
                                while (evaluate_iterator != null) {
                                        if (evaluate_iterator.Value is BuildItemGroup) {
                                                big = (BuildItemGroup) evaluate_iterator.Value;
-                                               if (ConditionParser.ParseAndEvaluate (big.Condition, project))
-                                                       big.Evaluate ();
+                                               project.PushThisFileProperty (big.DefinedInFileName);
+                                               try {
+                                                       if (ConditionParser.ParseAndEvaluate (big.Condition, project))
+                                                               big.Evaluate ();
+                                               } finally {
+                                                       project.PopThisFileProperty ();
+                                               }
+                                       }
+
+                                       evaluate_iterator = evaluate_iterator.Next;
+                               }
+                       } else if (type == EvaluationType.Choose) {
+                               evaluate_iterator = list.First;
+                               add_iterator = list.First;
+
+                               while (evaluate_iterator != null) {
+                                       if (evaluate_iterator.Value is BuildChoose) {
+                                               BuildChoose bc = (BuildChoose)evaluate_iterator.Value;
+                                               project.PushThisFileProperty (bc.DefinedInFileName);
+                                               try {
+                                                       bool whenUsed = false;
+                                                       foreach (BuildWhen bw in bc.Whens) {
+                                                               if (ConditionParser.ParseAndEvaluate (bw.Condition, project)) {
+                                                                       bw.Evaluate ();
+                                                                       whenUsed = true;
+                                                                       break;
+                                                               }
+                                                       }
+                                                       if (!whenUsed && bc.Otherwise != null &&
+                                                               ConditionParser.ParseAndEvaluate (bc.Otherwise.Condition, project)) {
+                                                               bc.Otherwise.Evaluate ();
+                                                       }
+                                               } finally {
+                                                       project.PopThisFileProperty ();
+                                               }
                                        }
 
                                        evaluate_iterator = evaluate_iterator.Next;
                                }
                        }
+
+                       add_iterator = null;
                }
 
                internal int Imports {
@@ -212,7 +265,8 @@ namespace Microsoft.Build.BuildEngine {
 
        enum EvaluationType {
                Property,
-               Item
+               Item,
+               Choose
        }
 }