X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FUnion.java;h=5ff00d669a165256cd7c8835f0a698c02a756624;hb=0620c2d97d6df986d74dbe13160afb1435096431;hp=204404dc6e8e411d3c5b453889ca763b75ca0578;hpb=b8a597c8d1a29afc24f9b89f726d5b1a9b9aeec1;p=sbp.git diff --git a/src/edu/berkeley/sbp/Union.java b/src/edu/berkeley/sbp/Union.java index 204404d..5ff00d6 100644 --- a/src/edu/berkeley/sbp/Union.java +++ b/src/edu/berkeley/sbp/Union.java @@ -1,3 +1,5 @@ +// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license + package edu.berkeley.sbp; import edu.berkeley.sbp.util.*; import edu.berkeley.sbp.*; @@ -17,8 +19,8 @@ import java.lang.ref.*; */ public class Union extends Element implements Iterable { - private final String name; - private final boolean synthetic; + /*private*/ final String name; + /*private*/ final boolean synthetic; private boolean viewed = false; private final List alternatives = new ArrayList(); @@ -44,6 +46,7 @@ public class Union extends Element implements Iterable { return alternatives.contains(s); } + /** iterator over this Union's Sequences */ public Iterator iterator() { viewed = true; return alternatives.iterator(); @@ -51,24 +54,32 @@ public class Union extends Element implements Iterable { /** adds an alternative */ public void add(Sequence s) { + /* + FIXME if (viewed) - throw new RuntimeException("attempt to add a Sequence to a Union that has already been examined"); + throw new RuntimeException("attempt to add a Sequence to a Union that has already been examined:\n "+this); + */ if (alternatives.contains(s)) return; alternatives.add(s); } + /** adds a one-element sequence */ + public void add(Element e) { + add(Sequence.create(e)); + } + // Epsilon Form ////////////////////////////////////////////////////////////////////////////// // FIXME - private Forest.Many epsilonForm = null; - Forest epsilonForm() { - if (epsilonForm != null) return epsilonForm; - epsilonForm = new Forest.Many(); + //private Forest.Many epsilonForm = null; + Forest epsilonForm(Input.Region loc) { + //if (epsilonForm != null) return epsilonForm; + Forest.Many epsilonForm = new Forest.Many(); for(Sequence s : this) { // FIXME FIXME FIXME if (new Walk.Cache().possiblyEpsilon(s)) - epsilonForm.merge(s.epsilonForm()); + epsilonForm.merge(s.epsilonForm(loc)); } return epsilonForm; }