mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
provisional API for Control Flow Graph
This commit is contained in:
parent
55d9c94968
commit
dc4a320192
13 changed files with 265 additions and 0 deletions
|
@ -0,0 +1,29 @@
|
|||
package org.eclipse.cdt.codan.internal.core.cfg;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.provisional.core.model.cfg.IBasicBlock;
|
||||
|
||||
public abstract class AbstarctBasicBlock implements IBasicBlock {
|
||||
static class OneElementIterator<T> implements Iterator<T> {
|
||||
private T o;
|
||||
|
||||
public OneElementIterator(T o) {
|
||||
this.o = o;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return o != null;
|
||||
}
|
||||
|
||||
public T next() {
|
||||
T x = o;
|
||||
o = null;
|
||||
return x;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package org.eclipse.cdt.codan.internal.core.cfg;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.provisional.core.model.cfg.IBasicBlock;
|
||||
import org.eclipse.cdt.codan.provisional.core.model.cfg.IConnectorNode;
|
||||
import org.eclipse.cdt.codan.provisional.core.model.cfg.IJumpNode;
|
||||
|
||||
/**
|
||||
* Plain node has one prev one jump
|
||||
*
|
||||
*/
|
||||
public class JumpNode extends AbstarctBasicBlock implements IJumpNode {
|
||||
final private IBasicBlock entry;
|
||||
private IBasicBlock jump;
|
||||
private boolean backward;
|
||||
|
||||
public JumpNode(IBasicBlock entry, IBasicBlock jump, boolean backward) {
|
||||
super();
|
||||
this.entry = entry;
|
||||
this.jump = jump;
|
||||
this.backward = backward;
|
||||
}
|
||||
|
||||
public Iterator<IBasicBlock> getIncomingIterator() {
|
||||
return new OneElementIterator<IBasicBlock>(entry);
|
||||
}
|
||||
|
||||
public Iterator<IBasicBlock> getOutgoingIterator() {
|
||||
return new OneElementIterator<IBasicBlock>(jump);
|
||||
}
|
||||
|
||||
public int getIncomingSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getOutgoingSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public IBasicBlock getIncoming() {
|
||||
return entry;
|
||||
}
|
||||
|
||||
public IBasicBlock getOutgoing() {
|
||||
return jump;
|
||||
}
|
||||
|
||||
public boolean isBackwardArc() {
|
||||
return backward;
|
||||
}
|
||||
|
||||
public void setJump(IBasicBlock jump) {
|
||||
if (!(jump instanceof IConnectorNode))
|
||||
throw new IllegalArgumentException("Jump target must be a connection node"); //$NON-NLS-1$
|
||||
this.jump = jump;
|
||||
}
|
||||
|
||||
public void setBackward(boolean backward) {
|
||||
this.backward = backward;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.eclipse.cdt.codan.internal.core.cfg;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.cdt.codan.provisional.core.model.cfg.IBasicBlock;
|
||||
import org.eclipse.cdt.codan.provisional.core.model.cfg.IPlainNode;
|
||||
|
||||
/**
|
||||
* Plain node has one prev one jump
|
||||
*
|
||||
*/
|
||||
public class PlainNode extends AbstarctBasicBlock implements IPlainNode {
|
||||
final IBasicBlock prev;
|
||||
IBasicBlock next;
|
||||
|
||||
public PlainNode(IBasicBlock entry, IBasicBlock exit) {
|
||||
super();
|
||||
this.prev = entry;
|
||||
this.next = exit;
|
||||
}
|
||||
|
||||
public Iterator<IBasicBlock> getIncomingIterator() {
|
||||
return new OneElementIterator<IBasicBlock>(prev);
|
||||
}
|
||||
|
||||
public Iterator<IBasicBlock> getOutgoingIterator() {
|
||||
return new OneElementIterator<IBasicBlock>(next);
|
||||
}
|
||||
|
||||
public int getIncomingSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getOutgoingSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public IBasicBlock getIncoming() {
|
||||
return prev;
|
||||
}
|
||||
|
||||
public IBasicBlock getOutgoing() {
|
||||
return next;
|
||||
}
|
||||
|
||||
public void setOutgoing(IBasicBlock exit) {
|
||||
if (this.next != null) throw new IllegalArgumentException("Cannot modify already exiting connector"); //$NON-NLS-1$
|
||||
this.next = exit;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package org.eclipse.cdt.codan.internal.core.cfg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.codan.provisional.core.model.cfg.IBasicBlock;
|
||||
import org.eclipse.cdt.codan.provisional.core.model.cfg.IStartNode;
|
||||
|
||||
/**
|
||||
* Start node has no prev, one jump and it is connect to function exits
|
||||
*
|
||||
*/
|
||||
public class StartNode extends AbstarctBasicBlock implements IStartNode {
|
||||
private IBasicBlock next;
|
||||
private List<IBasicBlock> exitNodes;
|
||||
|
||||
public StartNode(IBasicBlock next, Collection<IBasicBlock> exitNodes) {
|
||||
super();
|
||||
this.next = next;
|
||||
if (exitNodes != null) this.exitNodes = Collections.unmodifiableList(new ArrayList<IBasicBlock>(exitNodes));
|
||||
else this.exitNodes = null; // incomplete node
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Iterator<IBasicBlock> getIncomingIterator() {
|
||||
return Collections.EMPTY_LIST.iterator();
|
||||
}
|
||||
|
||||
public Iterator<IBasicBlock> getOutgoingIterator() {
|
||||
return new OneElementIterator<IBasicBlock>(next);
|
||||
}
|
||||
|
||||
public int getIncomingSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getOutgoingSize() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public IBasicBlock getOutgoing() {
|
||||
return next;
|
||||
}
|
||||
|
||||
public Iterator<IBasicBlock> getExitNodeIterator() {
|
||||
return exitNodes.iterator();
|
||||
}
|
||||
|
||||
public int getExitNodeSize() {
|
||||
return exitNodes.size();
|
||||
}
|
||||
|
||||
public void setOutgoing(IBasicBlock next) {
|
||||
if (this.next != null) throw new IllegalArgumentException("Cannot modify already exiting connector"); //$NON-NLS-1$
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
public void setExitNodes(Collection<IBasicBlock> exitNodes) {
|
||||
if (this.exitNodes != null) throw new IllegalArgumentException("Cannot modify already exiting connector"); //$NON-NLS-1$
|
||||
this.exitNodes = Collections.unmodifiableList(new ArrayList<IBasicBlock>(exitNodes));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface IBasicBlock {
|
||||
Iterator<IBasicBlock> getIncomingIterator();
|
||||
|
||||
Iterator<IBasicBlock> getOutgoingIterator();
|
||||
|
||||
int getIncomingSize();
|
||||
|
||||
int getOutgoingSize();
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
public interface IConnectorNode extends IBasicBlock {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
public interface IDecisionArc {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
public interface IDecisionNode extends IBasicBlock {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
public interface IJumpNode extends IBasicBlock {
|
||||
boolean isBackwardArc();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
public interface IPlainNode extends IBasicBlock, ISingleOutgoing, ISingleIncoming {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
public interface ISingleIncoming {
|
||||
IBasicBlock getIncoming();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
public interface ISingleOutgoing {
|
||||
IBasicBlock getOutgoing();
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.eclipse.cdt.codan.provisional.core.model.cfg;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public interface IStartNode extends IBasicBlock, ISingleOutgoing {
|
||||
Iterator<IBasicBlock> getExitNodeIterator();
|
||||
|
||||
int getExitNodeSize();
|
||||
}
|
Loading…
Add table
Reference in a new issue