summaryrefslogtreecommitdiffstats
path: root/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg')
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractBasicBlock.java61
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractSingleIncomingNode.java56
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractSingleOutgoingNode.java56
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/BranchNode.java36
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Entries12
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Repository1
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Root1
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Tag1
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ConnectorNode.java69
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java147
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/DecisionNode.java74
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ExitNode.java48
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/JumpNode.java71
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/NodeFactory.java101
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/PlainNode.java54
-rw-r--r--org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/StartNode.java42
16 files changed, 830 insertions, 0 deletions
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractBasicBlock.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractBasicBlock.java
new file mode 100644
index 0000000..15a191a
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractBasicBlock.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.ICfgData;
+
+/**
+ * Abstract Basic Block for control flow graph.
+ */
+public abstract class AbstractBasicBlock implements IBasicBlock, ICfgData {
+ /**
+ * Empty array of basic blocks
+ */
+ public final static IBasicBlock[] EMPTY_LIST = new IBasicBlock[0];
+ private Object data;
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ /**
+ * Add a node to list of outgoing nodes of this node
+ *
+ * @param node - node to add
+ */
+ public abstract void addOutgoing(IBasicBlock node);
+
+ /**
+ * Add a node to list of incoming nodes of this node
+ *
+ * @param node - node to add
+ */
+ public abstract void addIncoming(IBasicBlock node);
+
+ /**
+ * @return toString for data object
+ */
+ public String toStringData() {
+ if (getData() == null)
+ return "0x" + Integer.toHexString(System.identityHashCode(this)); //$NON-NLS-1$
+ return getData().toString();
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": " + toStringData(); //$NON-NLS-1$
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractSingleIncomingNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractSingleIncomingNode.java
new file mode 100644
index 0000000..9054f2a
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractSingleIncomingNode.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.ISingleIncoming;
+
+/**
+ * Abstract node with one incoming arc (node)
+ *
+ */
+public abstract class AbstractSingleIncomingNode extends AbstractBasicBlock
+ implements ISingleIncoming {
+ private IBasicBlock prev;
+
+ /**
+ * Default constructor
+ */
+ public AbstractSingleIncomingNode() {
+ super();
+ }
+
+ public IBasicBlock[] getIncomingNodes() {
+ return new IBasicBlock[] { prev };
+ }
+
+ public int getIncomingSize() {
+ return 1;
+ }
+
+ public IBasicBlock getIncoming() {
+ return prev;
+ }
+
+ /**
+ * Sets the incoming node
+ *
+ * @param prev
+ */
+ public void setIncoming(IBasicBlock prev) {
+ this.prev = prev;
+ }
+
+ @Override
+ public void addIncoming(IBasicBlock node) {
+ setIncoming(node);
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractSingleOutgoingNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractSingleOutgoingNode.java
new file mode 100644
index 0000000..e4f7fcf
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/AbstractSingleOutgoingNode.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.ISingleOutgoing;
+
+/**
+ * Abstract implementation of basic block with single outgoing arc (node)
+ *
+ */
+public abstract class AbstractSingleOutgoingNode extends AbstractBasicBlock
+ implements ISingleOutgoing {
+ private IBasicBlock next;
+
+ /**
+ * Default constructor
+ */
+ public AbstractSingleOutgoingNode() {
+ super();
+ }
+
+ public IBasicBlock[] getOutgoingNodes() {
+ return new IBasicBlock[] { next };
+ }
+
+ public int getOutgoingSize() {
+ return 1;
+ }
+
+ public IBasicBlock getOutgoing() {
+ return next;
+ }
+
+ /**
+ * Sets outgoing node
+ *
+ * @param node
+ */
+ public void setOutgoing(IBasicBlock node) {
+ this.next = node;
+ }
+
+ @Override
+ public void addOutgoing(IBasicBlock node) {
+ setOutgoing(node);
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/BranchNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/BranchNode.java
new file mode 100644
index 0000000..ecd99e1
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/BranchNode.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBranchNode;
+
+/**
+ * Branch node is a node with on incoming arc, one outgoing arc and a "string"
+ * label. Can be used to represent branches of if, switch and labelled
+ * statements.
+ */
+public class BranchNode extends PlainNode implements IBranchNode {
+ protected String label;
+
+ protected BranchNode(String label) {
+ super();
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ @Override
+ public String toStringData() {
+ return label;
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Entries
new file mode 100644
index 0000000..bd763ef
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Entries
@@ -0,0 +1,12 @@
+/AbstractBasicBlock.java/1.10/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/AbstractSingleIncomingNode.java/1.6/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/AbstractSingleOutgoingNode.java/1.6/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/BranchNode.java/1.5/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/ConnectorNode.java/1.7/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/ControlFlowGraph.java/1.11/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/DecisionNode.java/1.9/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/ExitNode.java/1.6/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/JumpNode.java/1.9/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/NodeFactory.java/1.2/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/PlainNode.java/1.8/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
+/StartNode.java/1.8/Thu Jun 3 17:01:52 2010//TCDT_7_0_0
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Repository b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Repository
new file mode 100644
index 0000000..34bede2
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Repository
@@ -0,0 +1 @@
+org.eclipse.cdt/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Root b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Root
new file mode 100644
index 0000000..04efa23
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Root
@@ -0,0 +1 @@
+:pserver:anonymous@dev.eclipse.org:/cvsroot/tools
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Tag b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Tag
new file mode 100644
index 0000000..49a449a
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/CVS/Tag
@@ -0,0 +1 @@
+NCDT_7_0_0
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ConnectorNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ConnectorNode.java
new file mode 100644
index 0000000..7c91818
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ConnectorNode.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import java.util.ArrayList;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.IConnectorNode;
+import org.eclipse.cdt.codan.core.model.cfg.IJumpNode;
+
+/**
+ * TODO: add description
+ */
+public class ConnectorNode extends AbstractSingleOutgoingNode implements
+ IConnectorNode {
+ protected ArrayList<IBasicBlock> incoming = new ArrayList<IBasicBlock>(2);
+
+ protected ConnectorNode() {
+ super();
+ }
+
+ @Override
+ public void addIncoming(IBasicBlock node) {
+ incoming.add(node);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.IBasicBlock#
+ * getIncomingIterator()
+ */
+ public IBasicBlock[] getIncomingNodes() {
+ return incoming.toArray(new IBasicBlock[incoming.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.cfg.IBasicBlock#getIncomingSize ()
+ */
+ public int getIncomingSize() {
+ return incoming.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.IConnectorNode#
+ * hasBackwardIncoming()
+ */
+ public boolean hasBackwardIncoming() {
+ for (IBasicBlock node : incoming) {
+ if (node instanceof IJumpNode) {
+ if (((IJumpNode) node).isBackwardArc())
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java
new file mode 100644
index 0000000..8133e8c
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ControlFlowGraph.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+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.LinkedHashSet;
+import java.util.List;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.IBranchNode;
+import org.eclipse.cdt.codan.core.model.cfg.IConnectorNode;
+import org.eclipse.cdt.codan.core.model.cfg.IControlFlowGraph;
+import org.eclipse.cdt.codan.core.model.cfg.IDecisionNode;
+import org.eclipse.cdt.codan.core.model.cfg.IExitNode;
+import org.eclipse.cdt.codan.core.model.cfg.ISingleOutgoing;
+import org.eclipse.cdt.codan.core.model.cfg.IStartNode;
+
+/**
+ * Implementation of control flow graph
+ */
+public class ControlFlowGraph implements IControlFlowGraph {
+ private List<IExitNode> exitNodes;
+ private List<IBasicBlock> deadNodes = new ArrayList<IBasicBlock>();
+ private IStartNode start;
+
+ public ControlFlowGraph(IStartNode start, Collection<IExitNode> exitNodes) {
+ setExitNodes(exitNodes);
+ this.start = start;
+ }
+
+ public Iterator<IExitNode> getExitNodeIterator() {
+ return exitNodes.iterator();
+ }
+
+ public int getExitNodeSize() {
+ return exitNodes.size();
+ }
+
+ public void setExitNodes(Collection<IExitNode> exitNodes) {
+ if (this.exitNodes != null)
+ throw new IllegalArgumentException(
+ "Cannot modify already exiting connector"); //$NON-NLS-1$
+ this.exitNodes = Collections.unmodifiableList(new ArrayList<IExitNode>(
+ exitNodes));
+ }
+
+ public void setUnconnectedNodes(Collection<IBasicBlock> nodes) {
+ this.deadNodes = Collections
+ .unmodifiableList(new ArrayList<IBasicBlock>(nodes));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.IControlFlowGraph#
+ * getStartNode()
+ */
+ public IStartNode getStartNode() {
+ return start;
+ }
+
+ void setStartNode(IStartNode start) {
+ this.start = start;
+ }
+
+ public void print(IBasicBlock node) {
+ System.out.println(node.getClass().getSimpleName() + ": " //$NON-NLS-1$
+ + ((AbstractBasicBlock) node).toStringData());
+ if (node instanceof IDecisionNode) {
+ // todo
+ IBasicBlock[] branches = ((IDecisionNode) node).getOutgoingNodes();
+ for (int i = 0; i < branches.length; i++) {
+ IBasicBlock brNode = branches[i];
+ System.out.println("{"); //$NON-NLS-1$
+ print(brNode);
+ System.out.println("}"); //$NON-NLS-1$
+ }
+ print(((IDecisionNode) node).getMergeNode());
+ } else if (node instanceof ISingleOutgoing) {
+ IBasicBlock next = ((ISingleOutgoing) node).getOutgoing();
+ if (!(next instanceof IConnectorNode && !(next instanceof IBranchNode)))
+ print(next);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.IControlFlowGraph#
+ * getUnconnectedNodeIterator()
+ */
+ public Iterator<IBasicBlock> getUnconnectedNodeIterator() {
+ return deadNodes.iterator();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.IControlFlowGraph#
+ * getUnconnectedNodeSize()
+ */
+ public int getUnconnectedNodeSize() {
+ return deadNodes.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.cfg.IControlFlowGraph#getNodes ()
+ */
+ public Collection<IBasicBlock> getNodes() {
+ Collection<IBasicBlock> result = new LinkedHashSet<IBasicBlock>();
+ getNodes(getStartNode(), result);
+ for (Iterator<IBasicBlock> iterator = deadNodes.iterator(); iterator
+ .hasNext();) {
+ IBasicBlock d = iterator.next();
+ getNodes(d, result);
+ }
+ return result;
+ }
+
+ /**
+ * @param d
+ * @param result
+ */
+ private void getNodes(IBasicBlock start, Collection<IBasicBlock> result) {
+ if (result.contains(start))
+ return;
+ result.add(start);
+ IBasicBlock[] outgoingNodes = start.getOutgoingNodes();
+ for (int i = 0; i < outgoingNodes.length; i++) {
+ IBasicBlock b = outgoingNodes[i];
+ getNodes(b, result);
+ }
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/DecisionNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/DecisionNode.java
new file mode 100644
index 0000000..df0da9c
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/DecisionNode.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.IBranchNode;
+import org.eclipse.cdt.codan.core.model.cfg.IConnectorNode;
+import org.eclipse.cdt.codan.core.model.cfg.IDecisionNode;
+
+/**
+ * @see {@link IDecisionNode}
+ */
+public class DecisionNode extends AbstractSingleIncomingNode implements
+ IDecisionNode {
+ private List<IBasicBlock> next = new ArrayList<IBasicBlock>(2);
+ private IConnectorNode conn;
+
+ /**
+ * @param prev
+ */
+ protected DecisionNode() {
+ super();
+ }
+
+ @Override
+ public void addOutgoing(IBasicBlock node) {
+ IBranchNode cnode = (IBranchNode) node; // cast to throw CCE
+ next.add(cnode);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.IBasicBlock#
+ * getOutgoingIterator()
+ */
+ public IBasicBlock[] getOutgoingNodes() {
+ return next.toArray(new IBasicBlock[next.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.cfg.IBasicBlock#getOutgoingSize ()
+ */
+ public int getOutgoingSize() {
+ return next.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.IDecisionNode#
+ * getConnectionNode()
+ */
+ public IConnectorNode getMergeNode() {
+ return conn;
+ }
+
+ public void setMergeNode(IConnectorNode conn) {
+ this.conn = conn;
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ExitNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ExitNode.java
new file mode 100644
index 0000000..7bd9848
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/ExitNode.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.IExitNode;
+import org.eclipse.cdt.codan.core.model.cfg.IStartNode;
+
+/**
+ * Plain node has one prev one jump
+ *
+ */
+public class ExitNode extends AbstractSingleIncomingNode implements IExitNode {
+ private IStartNode start;
+
+ protected ExitNode() {
+ super();
+ }
+
+ public IBasicBlock[] getOutgoingNodes() {
+ return EMPTY_LIST;
+ }
+
+ public int getOutgoingSize() {
+ return 0;
+ }
+
+ public IStartNode getStartNode() {
+ return start;
+ }
+
+ public void setStartNode(IStartNode start) {
+ this.start = start;
+ }
+
+ @Override
+ public void addOutgoing(IBasicBlock node) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/JumpNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/JumpNode.java
new file mode 100644
index 0000000..b5198d0
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/JumpNode.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.IConnectorNode;
+import org.eclipse.cdt.codan.core.model.cfg.IJumpNode;
+
+/**
+ * Jump node is node that connects unusual control pass, such as goto, break and
+ * continue
+ *
+ */
+public class JumpNode extends AbstractSingleIncomingNode implements IJumpNode {
+ private IConnectorNode jump;
+ private boolean backward;
+
+ protected JumpNode() {
+ super();
+ }
+
+ public IBasicBlock[] getOutgoingNodes() {
+ return new IBasicBlock[] { jump };
+ }
+
+ public int getOutgoingSize() {
+ return 1;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.cfg.IJumpNode#getJumpNode()
+ */
+ public IConnectorNode getJumpNode() {
+ return jump;
+ }
+
+ public IBasicBlock getOutgoing() {
+ return jump;
+ }
+
+ public boolean isBackwardArc() {
+ return backward;
+ }
+
+ public void setJump(IConnectorNode jump, boolean backward) {
+ if (this.jump != null && this.jump != jump)
+ throw new IllegalArgumentException(
+ "Cannot modify exiting connector"); //$NON-NLS-1$
+ this.jump = jump;
+ this.backward = backward;
+ }
+
+ public void setBackward(boolean backward) {
+ this.backward = backward;
+ }
+
+ @Override
+ public void addOutgoing(IBasicBlock node) {
+ setJump((IConnectorNode) node, backward);
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/NodeFactory.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/NodeFactory.java
new file mode 100644
index 0000000..0de0734
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/NodeFactory.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Alena Laskavaia
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBranchNode;
+import org.eclipse.cdt.codan.core.model.cfg.IConnectorNode;
+import org.eclipse.cdt.codan.core.model.cfg.IControlFlowGraph;
+import org.eclipse.cdt.codan.core.model.cfg.IDecisionNode;
+import org.eclipse.cdt.codan.core.model.cfg.IExitNode;
+import org.eclipse.cdt.codan.core.model.cfg.IJumpNode;
+import org.eclipse.cdt.codan.core.model.cfg.INodeFactory;
+import org.eclipse.cdt.codan.core.model.cfg.IPlainNode;
+import org.eclipse.cdt.codan.core.model.cfg.IStartNode;
+
+/**
+ * Factory that creates cfg nodes
+ */
+public class NodeFactory implements INodeFactory {
+ IControlFlowGraph graph;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.INodeFactory#
+ * getControlFlowGraph()
+ */
+ public IControlFlowGraph getControlFlowGraph() {
+ return graph;
+ }
+
+ public NodeFactory() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createPlainNode ()
+ */
+ public IPlainNode createPlainNode() {
+ return new PlainNode();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createJumpNode ()
+ */
+ public IJumpNode createJumpNode() {
+ return new JumpNode();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.INodeFactory#
+ * createDecisionNode()
+ */
+ public IDecisionNode createDecisionNode() {
+ return new DecisionNode();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.cdt.codan.provisional.core.model.cfg.INodeFactory#
+ * createConnectiorNode()
+ */
+ public IConnectorNode createConnectorNode() {
+ return new ConnectorNode();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createStartNode ()
+ */
+ public IStartNode createStartNode() {
+ return new StartNode();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createExitNode ()
+ */
+ public IExitNode createExitNode() {
+ return new ExitNode();
+ }
+
+ public IBranchNode createBranchNode(String label) {
+ return new BranchNode(label);
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/PlainNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/PlainNode.java
new file mode 100644
index 0000000..d382fb4
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/PlainNode.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.IPlainNode;
+
+/**
+ * Plain node has one incoming arc and one outgoing arc
+ *
+ */
+public class PlainNode extends AbstractSingleIncomingNode implements IPlainNode {
+ protected IBasicBlock next;
+
+ protected PlainNode() {
+ super();
+ }
+
+ public IBasicBlock[] getOutgoingNodes() {
+ return new IBasicBlock[] { next };
+ }
+
+ public int getOutgoingSize() {
+ return 1;
+ }
+
+ public IBasicBlock getOutgoing() {
+ return next;
+ }
+
+ public void setOutgoing(IBasicBlock exit) {
+ this.next = exit;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.cdt.codan.internal.core.cfg.AbstractBasicBlock#addOutgoing
+ * (org.eclipse.cdt.codan.core.model.cfg.IBasicBlock)
+ */
+ @Override
+ public void addOutgoing(IBasicBlock node) {
+ setOutgoing(node);
+ }
+}
diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/StartNode.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/StartNode.java
new file mode 100644
index 0000000..4d64bad
--- /dev/null
+++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/cfg/StartNode.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Alena Laskavaia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alena Laskavaia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.internal.core.cfg;
+
+import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
+import org.eclipse.cdt.codan.core.model.cfg.IStartNode;
+
+/**
+ * Start node has no incoming, one outgoing and it is connect to function exits
+ *
+ */
+public class StartNode extends AbstractSingleOutgoingNode implements IStartNode {
+ protected StartNode() {
+ super();
+ }
+
+ public IBasicBlock[] getIncomingNodes() {
+ return EMPTY_LIST;
+ }
+
+ public int getIncomingSize() {
+ return 0;
+ }
+
+ @Override
+ public void addOutgoing(IBasicBlock node) {
+ setOutgoing(node);
+ }
+
+ @Override
+ public void addIncoming(IBasicBlock node) {
+ throw new UnsupportedOperationException();
+ }
+}