mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
- added javadoc and visibility refactoring
This commit is contained in:
parent
a54f3f21a7
commit
ecd0453485
15 changed files with 48 additions and 66 deletions
|
@ -22,7 +22,6 @@ import org.eclipse.cdt.codan.core.model.cfg.IJumpNode;
|
||||||
import org.eclipse.cdt.codan.core.model.cfg.IPlainNode;
|
import org.eclipse.cdt.codan.core.model.cfg.IPlainNode;
|
||||||
import org.eclipse.cdt.codan.core.model.cfg.IStartNode;
|
import org.eclipse.cdt.codan.core.model.cfg.IStartNode;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.AbstractBasicBlock;
|
import org.eclipse.cdt.codan.internal.core.cfg.AbstractBasicBlock;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.ConnectorNode;
|
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.DecisionNode;
|
import org.eclipse.cdt.codan.internal.core.cfg.DecisionNode;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.JumpNode;
|
import org.eclipse.cdt.codan.internal.core.cfg.JumpNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||||
|
@ -45,10 +44,9 @@ import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: add description
|
* This class creates C control flow graph
|
||||||
*/
|
*/
|
||||||
public class ControlFlowGraphBuilder {
|
public class ControlFlowGraphBuilder {
|
||||||
CxxStartNode start;
|
CxxStartNode start;
|
||||||
|
@ -152,15 +150,12 @@ public class ControlFlowGraphBuilder {
|
||||||
addOutgoing(prev, gotoNode);
|
addOutgoing(prev, gotoNode);
|
||||||
return gotoNode;
|
return gotoNode;
|
||||||
} else if (body instanceof IASTProblemStatement) {
|
} else if (body instanceof IASTProblemStatement) {
|
||||||
System.err.println("problem");
|
// System.err.println("problem");
|
||||||
CxxPlainNode node = factory.createPlainNode(body);
|
CxxPlainNode node = factory.createPlainNode(body);
|
||||||
addOutgoing(prev, node);
|
addOutgoing(prev, node);
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
} else if (body instanceof IASTAmbiguousStatement) {
|
|
||||||
System.err.println("amb");
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("unknown statement for cfg: "+body);
|
System.err.println("unknown statement for cfg: " + body); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
@ -211,7 +206,7 @@ public class ControlFlowGraphBuilder {
|
||||||
DecisionNode node = factory.createDecisionNode(body
|
DecisionNode node = factory.createDecisionNode(body
|
||||||
.getControllerExpression());
|
.getControllerExpression());
|
||||||
addOutgoing(prev, node);
|
addOutgoing(prev, node);
|
||||||
ConnectorNode conn = new ConnectorNode();
|
IConnectorNode conn = factory.createConnectorNode();
|
||||||
node.setMergeNode(conn);
|
node.setMergeNode(conn);
|
||||||
createSwitchBody(node, conn, body.getBody());
|
createSwitchBody(node, conn, body.getBody());
|
||||||
return conn;
|
return conn;
|
||||||
|
@ -224,7 +219,7 @@ public class ControlFlowGraphBuilder {
|
||||||
* @param body
|
* @param body
|
||||||
*/
|
*/
|
||||||
private void createSwitchBody(DecisionNode switchNode,
|
private void createSwitchBody(DecisionNode switchNode,
|
||||||
ConnectorNode mergeNode, IASTStatement body) {
|
IConnectorNode mergeNode, IASTStatement body) {
|
||||||
if (!(body instanceof IASTCompoundStatement))
|
if (!(body instanceof IASTCompoundStatement))
|
||||||
return; // bad
|
return; // bad
|
||||||
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
||||||
|
@ -232,17 +227,6 @@ public class ControlFlowGraphBuilder {
|
||||||
IBasicBlock prev = switchNode;
|
IBasicBlock prev = switchNode;
|
||||||
for (int i = 0; i < children.length; i++) {
|
for (int i = 0; i < children.length; i++) {
|
||||||
IASTNode elem = children[i];
|
IASTNode elem = children[i];
|
||||||
if (elem instanceof IASTCaseStatement) {
|
|
||||||
IASTCaseStatement caseSt = (IASTCaseStatement) elem;
|
|
||||||
}
|
|
||||||
if (elem instanceof IASTDefaultStatement) {
|
|
||||||
IBranchNode lbl = factory.createBranchNode(IBranchNode.DEFAULT);
|
|
||||||
if (!(prev instanceof IExitNode) && prev != switchNode)
|
|
||||||
addOutgoing(prev, lbl);
|
|
||||||
addOutgoing(switchNode, lbl);
|
|
||||||
prev = lbl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (elem instanceof IASTCaseStatement
|
if (elem instanceof IASTCaseStatement
|
||||||
|| elem instanceof IASTDefaultStatement) {
|
|| elem instanceof IASTDefaultStatement) {
|
||||||
IBranchNode lbl = null;
|
IBranchNode lbl = null;
|
||||||
|
|
|
@ -15,8 +15,8 @@ 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.IExitNode;
|
||||||
import org.eclipse.cdt.codan.core.model.cfg.INodeFactory;
|
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.IPlainNode;
|
||||||
import org.eclipse.cdt.codan.core.model.cfg.NodeFactory;
|
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.AbstractBasicBlock;
|
import org.eclipse.cdt.codan.internal.core.cfg.AbstractBasicBlock;
|
||||||
|
import org.eclipse.cdt.codan.internal.core.cfg.NodeFactory;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,7 @@ Bundle-ActivationPolicy: lazy
|
||||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||||
Export-Package: org.eclipse.cdt.codan.core,
|
Export-Package: org.eclipse.cdt.codan.core,
|
||||||
org.eclipse.cdt.codan.core.model,
|
org.eclipse.cdt.codan.core.model,
|
||||||
org.eclipse.cdt.codan.core.model.cfg,
|
org.eclipse.cdt.codan.core.model.cfg;x-friends:="org.eclipse.cdt.codan.core.cxx",
|
||||||
org.eclipse.cdt.codan.internal.core;
|
org.eclipse.cdt.codan.internal.core;
|
||||||
x-friends:="org.eclipse.cdt.codan.core,
|
x-friends:="org.eclipse.cdt.codan.core,
|
||||||
org.eclipse.cdt.codan.core.cxx,
|
org.eclipse.cdt.codan.core.cxx,
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package org.eclipse.cdt.codan.core.model.cfg;
|
package org.eclipse.cdt.codan.core.model.cfg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connector node has multiple incoming branches and single outgoing
|
||||||
|
*/
|
||||||
public interface IConnectorNode extends IBasicBlock, ISingleOutgoing {
|
public interface IConnectorNode extends IBasicBlock, ISingleOutgoing {
|
||||||
/** Backward connector has incoming node which comes from backward arcs */
|
/** Backward connector has incoming node which comes from backward arcs */
|
||||||
boolean hasBackwardIncoming();
|
boolean hasBackwardIncoming();
|
||||||
|
|
|
@ -14,15 +14,11 @@ import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: add description
|
* Represents control flow graph object
|
||||||
*/
|
*/
|
||||||
public interface IControlFlowGraph {
|
public interface IControlFlowGraph {
|
||||||
IStartNode getStartNode();
|
IStartNode getStartNode();
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Iterator<IExitNode> getExitNodeIterator();
|
Iterator<IExitNode> getExitNodeIterator();
|
||||||
|
|
||||||
int getExitNodeSize();
|
int getExitNodeSize();
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
package org.eclipse.cdt.codan.core.model.cfg;
|
package org.eclipse.cdt.codan.core.model.cfg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Node that changes the control of the graph, i.e. passes control to non-next
|
||||||
|
* statement. Can be used to implement gotos, break, continue, end of branches
|
||||||
|
*/
|
||||||
public interface IJumpNode extends IBasicBlock, ISingleOutgoing {
|
public interface IJumpNode extends IBasicBlock, ISingleOutgoing {
|
||||||
|
/**
|
||||||
|
* True of outgoing arc is backward one
|
||||||
|
*/
|
||||||
boolean isBackwardArc();
|
boolean isBackwardArc();
|
||||||
|
|
||||||
IConnectorNode getJumpNode();
|
IConnectorNode getJumpNode();
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package org.eclipse.cdt.codan.core.model.cfg;
|
package org.eclipse.cdt.codan.core.model.cfg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has one incoming, one outgoing connection. Usually expression statement or
|
||||||
|
* declaration.
|
||||||
|
*/
|
||||||
public interface IPlainNode extends IBasicBlock, ISingleOutgoing,
|
public interface IPlainNode extends IBasicBlock, ISingleOutgoing,
|
||||||
ISingleIncoming {
|
ISingleIncoming {
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.eclipse.cdt.codan.core.model.cfg.IBranchNode;
|
||||||
public class BranchNode extends PlainNode implements IBranchNode {
|
public class BranchNode extends PlainNode implements IBranchNode {
|
||||||
protected String label;
|
protected String label;
|
||||||
|
|
||||||
public BranchNode(String label) {
|
protected BranchNode(String label) {
|
||||||
super();
|
super();
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,7 @@ public class BranchNode extends PlainNode implements IBranchNode {
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.cdt.codan.core.model.cfg.IBranchNode#getLabel()
|
||||||
* org.eclipse.cdt.codan.core.model.cfg.IBranchNode#getLabel()
|
|
||||||
*/
|
*/
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return label;
|
return label;
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class ConnectorNode extends AbstractSingleOutgoingNode implements
|
||||||
IConnectorNode {
|
IConnectorNode {
|
||||||
protected ArrayList<IBasicBlock> incoming = new ArrayList<IBasicBlock>(2);
|
protected ArrayList<IBasicBlock> incoming = new ArrayList<IBasicBlock>(2);
|
||||||
|
|
||||||
public ConnectorNode() {
|
protected ConnectorNode() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,9 +46,7 @@ public class ConnectorNode extends AbstractSingleOutgoingNode implements
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.cdt.codan.core.model.cfg.IBasicBlock#getIncomingSize ()
|
||||||
* org.eclipse.cdt.codan.core.model.cfg.IBasicBlock#getIncomingSize
|
|
||||||
* ()
|
|
||||||
*/
|
*/
|
||||||
public int getIncomingSize() {
|
public int getIncomingSize() {
|
||||||
return incoming.size();
|
return incoming.size();
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class DecisionNode extends AbstractSingleIncomingNode implements
|
||||||
/**
|
/**
|
||||||
* @param prev
|
* @param prev
|
||||||
*/
|
*/
|
||||||
public DecisionNode() {
|
protected DecisionNode() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +53,7 @@ public class DecisionNode extends AbstractSingleIncomingNode implements
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.cdt.codan.core.model.cfg.IBasicBlock#getOutgoingSize ()
|
||||||
* org.eclipse.cdt.codan.core.model.cfg.IBasicBlock#getOutgoingSize
|
|
||||||
* ()
|
|
||||||
*/
|
*/
|
||||||
public int getOutgoingSize() {
|
public int getOutgoingSize() {
|
||||||
return next.size();
|
return next.size();
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.eclipse.cdt.codan.core.model.cfg.IStartNode;
|
||||||
public class ExitNode extends AbstractSingleIncomingNode implements IExitNode {
|
public class ExitNode extends AbstractSingleIncomingNode implements IExitNode {
|
||||||
private IStartNode start;
|
private IStartNode start;
|
||||||
|
|
||||||
public ExitNode() {
|
protected ExitNode() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class JumpNode extends AbstractSingleIncomingNode implements IJumpNode {
|
||||||
private IConnectorNode jump;
|
private IConnectorNode jump;
|
||||||
private boolean backward;
|
private boolean backward;
|
||||||
|
|
||||||
public JumpNode() {
|
protected JumpNode() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,7 @@ public class JumpNode extends AbstractSingleIncomingNode implements IJumpNode {
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.cdt.codan.core.model.cfg.IJumpNode#getJumpNode()
|
||||||
* org.eclipse.cdt.codan.core.model.cfg.IJumpNode#getJumpNode()
|
|
||||||
*/
|
*/
|
||||||
public IConnectorNode getJumpNode() {
|
public IConnectorNode getJumpNode() {
|
||||||
return jump;
|
return jump;
|
||||||
|
|
|
@ -8,18 +8,20 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.model.cfg;
|
package org.eclipse.cdt.codan.internal.core.cfg;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.ConnectorNode;
|
import org.eclipse.cdt.codan.core.model.cfg.IBranchNode;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.DecisionNode;
|
import org.eclipse.cdt.codan.core.model.cfg.IConnectorNode;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.ExitNode;
|
import org.eclipse.cdt.codan.core.model.cfg.IControlFlowGraph;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.JumpNode;
|
import org.eclipse.cdt.codan.core.model.cfg.IDecisionNode;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.BranchNode;
|
import org.eclipse.cdt.codan.core.model.cfg.IExitNode;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.PlainNode;
|
import org.eclipse.cdt.codan.core.model.cfg.IJumpNode;
|
||||||
import org.eclipse.cdt.codan.internal.core.cfg.StartNode;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: add description
|
* Factory that creates cfg nodes
|
||||||
*/
|
*/
|
||||||
public class NodeFactory implements INodeFactory {
|
public class NodeFactory implements INodeFactory {
|
||||||
IControlFlowGraph graph;
|
IControlFlowGraph graph;
|
||||||
|
@ -40,9 +42,7 @@ public class NodeFactory implements INodeFactory {
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createPlainNode ()
|
||||||
* org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createPlainNode
|
|
||||||
* ()
|
|
||||||
*/
|
*/
|
||||||
public IPlainNode createPlainNode() {
|
public IPlainNode createPlainNode() {
|
||||||
return new PlainNode();
|
return new PlainNode();
|
||||||
|
@ -51,9 +51,7 @@ public class NodeFactory implements INodeFactory {
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createJumpNode ()
|
||||||
* org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createJumpNode
|
|
||||||
* ()
|
|
||||||
*/
|
*/
|
||||||
public IJumpNode createJumpNode() {
|
public IJumpNode createJumpNode() {
|
||||||
return new JumpNode();
|
return new JumpNode();
|
||||||
|
@ -82,9 +80,7 @@ public class NodeFactory implements INodeFactory {
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createStartNode ()
|
||||||
* org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createStartNode
|
|
||||||
* ()
|
|
||||||
*/
|
*/
|
||||||
public IStartNode createStartNode() {
|
public IStartNode createStartNode() {
|
||||||
return new StartNode();
|
return new StartNode();
|
||||||
|
@ -93,9 +89,7 @@ public class NodeFactory implements INodeFactory {
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see
|
* @see org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createExitNode ()
|
||||||
* org.eclipse.cdt.codan.core.model.cfg.INodeFactory#createExitNode
|
|
||||||
* ()
|
|
||||||
*/
|
*/
|
||||||
public IExitNode createExitNode() {
|
public IExitNode createExitNode() {
|
||||||
return new ExitNode();
|
return new ExitNode();
|
|
@ -12,7 +12,7 @@ import org.eclipse.cdt.codan.core.model.cfg.IPlainNode;
|
||||||
public class PlainNode extends AbstractSingleIncomingNode implements IPlainNode {
|
public class PlainNode extends AbstractSingleIncomingNode implements IPlainNode {
|
||||||
protected IBasicBlock next;
|
protected IBasicBlock next;
|
||||||
|
|
||||||
public PlainNode() {
|
protected PlainNode() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.eclipse.cdt.codan.core.model.cfg.IStartNode;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class StartNode extends AbstractSingleOutgoingNode implements IStartNode {
|
public class StartNode extends AbstractSingleOutgoingNode implements IStartNode {
|
||||||
public StartNode() {
|
protected StartNode() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue