feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
/**
|
||||
* {@link Expression} that represents the union of two expressions "A|B".
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class Choice extends Expression {
|
||||
/**
|
||||
* "A" of "A|B".
|
||||
*/
|
||||
private final Expression lhs;
|
||||
/**
|
||||
* "B" of "A|B".
|
||||
*/
|
||||
private final Expression rhs;
|
||||
/**
|
||||
* Compute this value eagerly for better performance
|
||||
*/
|
||||
private final boolean isNullable;
|
||||
|
||||
public Choice(Expression lhs, Expression rhs) {
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
this.isNullable = lhs.isNullable() || rhs.isNullable();
|
||||
}
|
||||
|
||||
boolean isNullable() {
|
||||
return isNullable;
|
||||
}
|
||||
|
||||
ElementSet lastSet() {
|
||||
return ElementSets.union(lhs.lastSet(),rhs.lastSet());
|
||||
}
|
||||
|
||||
void buildDAG(ElementSet incoming) {
|
||||
lhs.buildDAG(incoming);
|
||||
rhs.buildDAG(incoming);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return '('+lhs.toString()+'|'+rhs.toString()+')';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents one strongly-connected component
|
||||
* of the {@link Element} graph.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class ConnectedComponent implements Iterable<Element> {
|
||||
/**
|
||||
* {@link Element}s that belong to this component.
|
||||
*/
|
||||
private final List<Element> elements = new ArrayList<Element>();
|
||||
|
||||
/*package*/ boolean isRequired;
|
||||
|
||||
/**
|
||||
* Returns true iff this {@link ConnectedComponent}
|
||||
* can match a substring whose length is greater than 1.
|
||||
*
|
||||
* <p>
|
||||
* That means this property will become a collection property.
|
||||
*/
|
||||
public final boolean isCollection() {
|
||||
assert !elements.isEmpty();
|
||||
|
||||
// a strongly connected component by definition has a cycle,
|
||||
// so if its size is bigger than 1 there must be a cycle.
|
||||
if(elements.size()>1)
|
||||
return true;
|
||||
|
||||
// if size is 1, it might be still forming a self-cycle
|
||||
Element n = elements.get(0);
|
||||
return n.hasSelfLoop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true iff this {@link ConnectedComponent}
|
||||
* forms a cut set of a graph.
|
||||
*
|
||||
* <p>
|
||||
* That means any valid element sequence must have at least
|
||||
* one value for this property.
|
||||
*/
|
||||
public final boolean isRequired() {
|
||||
return isRequired;
|
||||
}
|
||||
|
||||
/*package*/void add(Element e) {
|
||||
assert !elements.contains(e);
|
||||
elements.add(e);
|
||||
}
|
||||
|
||||
public Iterator<Element> iterator() {
|
||||
return elements.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Just produces debug representation
|
||||
*/
|
||||
public String toString() {
|
||||
String s = elements.toString();
|
||||
if(isRequired())
|
||||
s += '!';
|
||||
if(isCollection())
|
||||
s += '*';
|
||||
return s;
|
||||
}
|
||||
}
|
||||
228
jdkSrc/jdk8/com/sun/tools/internal/xjc/reader/gbind/Element.java
Normal file
228
jdkSrc/jdk8/com/sun/tools/internal/xjc/reader/gbind/Element.java
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* {@link Expression} that represents an alphabet of a regular language.
|
||||
*
|
||||
* <p>
|
||||
* Since this package is about a regular expression over element declarations,
|
||||
* this represents an XML element declaration (hence the name.)
|
||||
*
|
||||
* Element needs to be interned, meaning one {@link Element} per one tag name.
|
||||
*
|
||||
* <p>
|
||||
* Implements {@link ElementSet} to represent a self.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public abstract class Element extends Expression implements ElementSet {
|
||||
/**
|
||||
* Once we build a graph from {@link Expression},
|
||||
* we represent an edge e1 -> e2 by {@code e1.foreEdges.contains(e2)}
|
||||
* and {@code e2.backEdges.contains(e1)}.
|
||||
*/
|
||||
final Set<Element> foreEdges = new LinkedHashSet<Element>();
|
||||
final Set<Element> backEdges = new LinkedHashSet<Element>();
|
||||
|
||||
/**
|
||||
* Previous element in the DFS post-order traveral
|
||||
* of the element graph.
|
||||
*
|
||||
* <p>
|
||||
* We use {@code prevPostOrder==null} as a check if the element is visted in DFS,
|
||||
* so this chain terminates by a self-reference, not by having null.
|
||||
*
|
||||
* Set in {@link #assignDfsPostOrder(Element)}
|
||||
*/
|
||||
/*package*/ Element prevPostOrder;
|
||||
|
||||
/**
|
||||
* {@link ConnectedComponent} to which this element belongs.
|
||||
*
|
||||
* Set in {@link #buildStronglyConnectedComponents(List<ConnectedComponent>)}
|
||||
*/
|
||||
private ConnectedComponent cc;
|
||||
|
||||
protected Element() {
|
||||
}
|
||||
|
||||
ElementSet lastSet() {
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean isNullable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if this {@link Element} is {@link SourceNode}.
|
||||
*/
|
||||
boolean isSource() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if this {@link Element} is {@link SinkNode}.
|
||||
*/
|
||||
boolean isSink() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void buildDAG(ElementSet incoming) {
|
||||
incoming.addNext(this);
|
||||
}
|
||||
|
||||
public void addNext(Element element) {
|
||||
foreEdges.add(element);
|
||||
element.backEdges.add(this);
|
||||
}
|
||||
|
||||
public boolean contains(ElementSet rhs) {
|
||||
return this==rhs || rhs==ElementSet.EMPTY_SET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just to satisfy the {@link ElementSet} contract.
|
||||
*
|
||||
* @deprecated
|
||||
* if you statically call this method, there's something wrong.
|
||||
*/
|
||||
public Iterator<Element> iterator() {
|
||||
return Collections.singleton(this).iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses the {@link Element} graph with DFS
|
||||
* and set {@link #prevPostOrder}.
|
||||
*
|
||||
* Should be first invoked on the source node of the graph.
|
||||
*/
|
||||
/*package*/ Element assignDfsPostOrder(Element prev) {
|
||||
if(prevPostOrder!=null)
|
||||
return prev; // already visited
|
||||
|
||||
prevPostOrder = this; // set a dummy value to prepare for cycles
|
||||
|
||||
for (Element next : foreEdges) {
|
||||
prev = next.assignDfsPostOrder(prev);
|
||||
}
|
||||
this.prevPostOrder = prev; // set to the real value
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a set of strongly connected components and puts them
|
||||
* all into the given set.
|
||||
*/
|
||||
public void buildStronglyConnectedComponents(List<ConnectedComponent> ccs) {
|
||||
|
||||
// store visited elements - loop detection
|
||||
List<Element> visitedElements = new ArrayList<Element>();
|
||||
|
||||
for(Element cur=this; cur!=cur.prevPostOrder; cur=cur.prevPostOrder) {
|
||||
|
||||
if(visitedElements.contains(cur)) {
|
||||
// if I've already processed cur element, I'm in a loop
|
||||
break;
|
||||
} else {
|
||||
visitedElements.add(cur);
|
||||
}
|
||||
|
||||
if(cur.belongsToSCC())
|
||||
continue;
|
||||
|
||||
// start a new component
|
||||
ConnectedComponent cc = new ConnectedComponent();
|
||||
ccs.add(cc);
|
||||
|
||||
cur.formConnectedComponent(cc);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean belongsToSCC() {
|
||||
return cc!=null || isSource() || isSink();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms a strongly connected component by doing a reverse DFS.
|
||||
*/
|
||||
private void formConnectedComponent(ConnectedComponent group) {
|
||||
if(belongsToSCC())
|
||||
return;
|
||||
|
||||
this.cc=group;
|
||||
group.add(this);
|
||||
for (Element prev : backEdges)
|
||||
prev.formConnectedComponent(group);
|
||||
}
|
||||
|
||||
public boolean hasSelfLoop() {
|
||||
// if foreEdges have a loop, backEdges must have one. Or vice versa
|
||||
assert foreEdges.contains(this)==backEdges.contains(this);
|
||||
|
||||
return foreEdges.contains(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given {@link ConnectedComponent} forms a cut-set
|
||||
* of a graph.
|
||||
*
|
||||
* @param visited
|
||||
* Used to keep track of visited nodes.
|
||||
* @return
|
||||
* true if it is indeed a cut-set. false if not.
|
||||
*/
|
||||
/*package*/ final boolean checkCutSet(ConnectedComponent cc, Set<Element> visited) {
|
||||
assert belongsToSCC(); // SCC discomposition must be done first
|
||||
|
||||
if(isSink())
|
||||
// the definition of the cut set is that without those nodes
|
||||
// you can't reach from soruce to sink
|
||||
return false;
|
||||
|
||||
if(!visited.add(this))
|
||||
return true;
|
||||
|
||||
if(this.cc==cc)
|
||||
return true;
|
||||
|
||||
for (Element next : foreEdges) {
|
||||
if(!next.checkCutSet(cc,visited))
|
||||
// we've found a path to the sink
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A set over a list of {@link Element}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
interface ElementSet extends Iterable<Element> {
|
||||
/**
|
||||
* For each element in this set, adds an edge to the given element.
|
||||
*/
|
||||
void addNext(Element element);
|
||||
|
||||
public static final ElementSet EMPTY_SET = new ElementSet() {
|
||||
public void addNext(Element element) {
|
||||
// noop
|
||||
}
|
||||
|
||||
public boolean contains(ElementSet element) {
|
||||
return this==element;
|
||||
}
|
||||
|
||||
public Iterator<Element> iterator() {
|
||||
return Collections.<Element>emptySet().iterator();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Doesn't have to be strict (it's OK for this method to return false
|
||||
* when it's actually true) since this is used just for optimization.
|
||||
*
|
||||
* (Erring on the other side is NG)
|
||||
*/
|
||||
boolean contains(ElementSet rhs);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
/**
|
||||
* Factory methods for {@link ElementSet}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class ElementSets {
|
||||
/**
|
||||
* Returns an union of two {@link ElementSet}s.
|
||||
*
|
||||
* This method performs better if lhs is bigger than rhs
|
||||
*/
|
||||
public static ElementSet union(ElementSet lhs, ElementSet rhs) {
|
||||
if(lhs.contains(rhs))
|
||||
return lhs;
|
||||
if(lhs==ElementSet.EMPTY_SET)
|
||||
return rhs;
|
||||
if(rhs==ElementSet.EMPTY_SET)
|
||||
return lhs;
|
||||
return new MultiValueSet(lhs,rhs);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ElementSet} that has multiple {@link Element}s in it.
|
||||
*
|
||||
* This isn't particularly efficient or anything, but it will do for now.
|
||||
*/
|
||||
private static final class MultiValueSet extends LinkedHashSet<Element> implements ElementSet {
|
||||
public MultiValueSet(ElementSet lhs, ElementSet rhs) {
|
||||
addAll(lhs);
|
||||
addAll(rhs);
|
||||
// not that anything will break with size==1 MultiValueSet,
|
||||
// but it does suggest that we are missing an easy optimization
|
||||
assert size()>1;
|
||||
}
|
||||
|
||||
private void addAll(ElementSet lhs) {
|
||||
if(lhs instanceof MultiValueSet) {
|
||||
super.addAll((MultiValueSet)lhs);
|
||||
} else {
|
||||
for (Element e : lhs)
|
||||
add(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(ElementSet rhs) {
|
||||
// this isn't complete but sound
|
||||
return super.contains(rhs) || rhs==ElementSet.EMPTY_SET;
|
||||
}
|
||||
|
||||
public void addNext(Element element) {
|
||||
for (Element e : this)
|
||||
e.addNext(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This builds content models.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public abstract class Expression {
|
||||
|
||||
/**
|
||||
* Computes <tt>LAST(exp)</tt>
|
||||
*/
|
||||
abstract ElementSet lastSet();
|
||||
|
||||
/**
|
||||
* True of <tt>\epsilon \in L(exp)</tt>
|
||||
*/
|
||||
abstract boolean isNullable();
|
||||
|
||||
/**
|
||||
* Builds up a DAG among {@link Element}s in this expression.
|
||||
*/
|
||||
abstract void buildDAG(ElementSet incoming);
|
||||
|
||||
/**
|
||||
* {@link Expression} that represents epsilon, the length-0 string.
|
||||
*/
|
||||
public static final Expression EPSILON = new Expression() {
|
||||
ElementSet lastSet() {
|
||||
return ElementSet.EMPTY_SET;
|
||||
}
|
||||
|
||||
boolean isNullable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void buildDAG(ElementSet incoming) {
|
||||
// noop
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "-";
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Graph of {@link Element}s.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class Graph implements Iterable<ConnectedComponent> {
|
||||
private final Element source = new SourceNode();
|
||||
private final Element sink = new SinkNode();
|
||||
|
||||
/**
|
||||
* Strongly connected components of this graph.
|
||||
*/
|
||||
private final List<ConnectedComponent> ccs = new ArrayList<ConnectedComponent>();
|
||||
|
||||
/**
|
||||
* Builds a {@link Graph} from an {@link Expression} tree.
|
||||
*
|
||||
* {@link Expression} given to the graph will be modified forever,
|
||||
* and it will not be able to create another {@link Graph}.
|
||||
*/
|
||||
public Graph(Expression body) {
|
||||
// attach source and sink
|
||||
Expression whole = new Sequence(new Sequence(source,body),sink);
|
||||
|
||||
// build up a graph
|
||||
whole.buildDAG(ElementSet.EMPTY_SET);
|
||||
|
||||
// decompose into strongly connected components.
|
||||
// the algorithm is standard DFS-based algorithm,
|
||||
// one illustration of this algorithm is available at
|
||||
// http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/GraphAlgor/strongComponent.htm
|
||||
source.assignDfsPostOrder(sink);
|
||||
source.buildStronglyConnectedComponents(ccs);
|
||||
|
||||
// cut-set check
|
||||
Set<Element> visited = new HashSet<Element>();
|
||||
for (ConnectedComponent cc : ccs) {
|
||||
visited.clear();
|
||||
if(source.checkCutSet(cc,visited)) {
|
||||
cc.isRequired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List up {@link ConnectedComponent}s of this graph in an order.
|
||||
*/
|
||||
public Iterator<ConnectedComponent> iterator() {
|
||||
return ccs.iterator();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ccs.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
/**
|
||||
* {@link Expression} that represents kleene-star operation (A+)
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class OneOrMore extends Expression {
|
||||
/**
|
||||
* 'A' of 'A+'.
|
||||
*/
|
||||
private final Expression child;
|
||||
|
||||
public OneOrMore(Expression child) {
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
ElementSet lastSet() {
|
||||
return child.lastSet();
|
||||
}
|
||||
|
||||
boolean isNullable() {
|
||||
return child.isNullable();
|
||||
}
|
||||
|
||||
void buildDAG(ElementSet incoming) {
|
||||
child.buildDAG(ElementSets.union(incoming,child.lastSet()));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return child.toString()+'+';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
/**
|
||||
* {@link Expression} that represents a concatanation of two expressions
|
||||
* "A,B".
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class Sequence extends Expression {
|
||||
/**
|
||||
* 'A' of 'A,B'
|
||||
*/
|
||||
private final Expression lhs;
|
||||
/**
|
||||
* 'B' of 'A,B'
|
||||
*/
|
||||
private final Expression rhs;
|
||||
/**
|
||||
* Compute this value eagerly for better performance
|
||||
*/
|
||||
private final boolean isNullable;
|
||||
|
||||
/**
|
||||
* Cached value of {@link #lastSet()} for better performance.
|
||||
* Sequence tends to be where the recursive lastSet computation occurs.
|
||||
*/
|
||||
private ElementSet lastSet;
|
||||
|
||||
public Sequence(Expression lhs, Expression rhs) {
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
isNullable = lhs.isNullable() && rhs.isNullable();
|
||||
}
|
||||
|
||||
ElementSet lastSet() {
|
||||
if(lastSet==null) {
|
||||
if(rhs.isNullable())
|
||||
lastSet = ElementSets.union(lhs.lastSet(),rhs.lastSet());
|
||||
else
|
||||
lastSet = rhs.lastSet();
|
||||
}
|
||||
return lastSet;
|
||||
}
|
||||
|
||||
boolean isNullable() {
|
||||
return isNullable;
|
||||
}
|
||||
|
||||
void buildDAG(ElementSet incoming) {
|
||||
lhs.buildDAG(incoming);
|
||||
if(lhs.isNullable())
|
||||
rhs.buildDAG(ElementSets.union(incoming,lhs.lastSet()));
|
||||
else
|
||||
rhs.buildDAG(lhs.lastSet());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return '('+lhs.toString()+','+rhs.toString()+')';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
/**
|
||||
* Sink node of a grpah.
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class SinkNode extends Element {
|
||||
public String toString() {
|
||||
return "#sink";
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isSink() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.tools.internal.xjc.reader.gbind;
|
||||
|
||||
/**
|
||||
* Source node of a graph.
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class SourceNode extends Element {
|
||||
public String toString() {
|
||||
return "#source";
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isSource() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user