Simplify ast implementation

Change-Id: I0e61cde0e8551103e362a14de880d77fc9315807
diff --git a/ast/ast.go b/ast/ast.go
index 0f1c858..6461a7b 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -356,6 +356,17 @@
 //   - (a & b & (c | d) & e) -> (a & b & e) (OR-relation removed)
 //   - (a | b) -> nil (completely optional)
 func RestrictToObligatory(node Node, foundry, layer string) Node {
+	return restrictToObligatoryWithOverrides(node, foundry, layer, false)
+}
+
+// RestrictToObligatoryWithPrecedence is like RestrictToObligatory but respects precedence rules
+// when applying foundry and layer overrides
+func RestrictToObligatoryWithPrecedence(node Node, foundry, layer string) Node {
+	return restrictToObligatoryWithOverrides(node, foundry, layer, true)
+}
+
+// restrictToObligatoryWithOverrides performs the restriction and applies overrides with optional precedence
+func restrictToObligatoryWithOverrides(node Node, foundry, layer string, withPrecedence bool) Node {
 	if node == nil {
 		return nil
 	}
@@ -366,26 +377,11 @@
 
 	// Then apply foundry and layer overrides to the smaller, restricted tree
 	if restricted != nil {
-		ApplyFoundryAndLayerOverrides(restricted, foundry, layer)
-	}
-
-	return restricted
-}
-
-// RestrictToObligatoryWithPrecedence is like RestrictToObligatory but respects precedence rules
-// when applying foundry and layer overrides
-func RestrictToObligatoryWithPrecedence(node Node, foundry, layer string) Node {
-	if node == nil {
-		return nil
-	}
-
-	// First, clone and restrict to obligatory operations
-	cloned := node.Clone()
-	restricted := restrictToObligatoryRecursive(cloned)
-
-	// Then apply foundry and layer overrides with precedence to the smaller, restricted tree
-	if restricted != nil {
-		ApplyFoundryAndLayerOverridesWithPrecedence(restricted, foundry, layer)
+		if withPrecedence {
+			ApplyFoundryAndLayerOverridesWithPrecedence(restricted, foundry, layer)
+		} else {
+			ApplyFoundryAndLayerOverrides(restricted, foundry, layer)
+		}
 	}
 
 	return restricted
@@ -420,7 +416,9 @@
 		if n.Relation == OrRelation {
 			// OR-relations are optional, so remove them
 			return nil
-		} else if n.Relation == AndRelation {
+		}
+
+		if n.Relation == AndRelation {
 			// AND-relations are obligatory, but we need to process operands
 			var obligatoryOperands []Node
 			for _, operand := range n.Operands {