mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 455828 - General cleanup in ControlFlowGraphBuilder
Change-Id: I46cfe23fc10bed235d091afaec8eec29dd7d62ac Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
cd65a29016
commit
d0ef9d1d82
1 changed files with 11 additions and 18 deletions
|
@ -146,14 +146,11 @@ public class ControlFlowGraphBuilder {
|
|||
return node;
|
||||
}
|
||||
|
||||
private IBasicBlock createSubGraph(IBasicBlock prev, IASTNode body) {
|
||||
private IBasicBlock createSubGraph(IBasicBlock prev, IASTStatement body) {
|
||||
if (body instanceof IASTCompoundStatement) {
|
||||
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
||||
IASTNode[] children = comp.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
IASTNode node = children[i];
|
||||
IBasicBlock last = createSubGraph(prev, node);
|
||||
prev = last;
|
||||
for (IASTStatement statement : comp.getStatements()) {
|
||||
prev = createSubGraph(prev, statement);
|
||||
}
|
||||
} else if (body instanceof IASTExpressionStatement || body instanceof IASTDeclarationStatement || body instanceof IASTNullStatement) {
|
||||
if (isThrowStatement(body) || isExitStatement(body)) {
|
||||
|
@ -327,20 +324,17 @@ public class ControlFlowGraphBuilder {
|
|||
return conn;
|
||||
}
|
||||
|
||||
private void createSwitchBody(DecisionNode switchNode, IConnectorNode mergeNode, IASTStatement body) {
|
||||
private void createSwitchBody(IDecisionNode switchNode, IConnectorNode mergeNode, IASTStatement body) {
|
||||
if (!(body instanceof IASTCompoundStatement))
|
||||
return; // bad
|
||||
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
||||
IASTNode[] children = comp.getChildren();
|
||||
IBasicBlock prev = switchNode;
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
IASTNode elem = children[i];
|
||||
if (elem instanceof IASTCaseStatement || elem instanceof IASTDefaultStatement) {
|
||||
for (IASTStatement statement : comp.getStatements()) {
|
||||
if (statement instanceof IASTCaseStatement || statement instanceof IASTDefaultStatement) {
|
||||
IBranchNode lbl = null;
|
||||
if (elem instanceof IASTCaseStatement) {
|
||||
IASTCaseStatement caseSt = (IASTCaseStatement) elem;
|
||||
lbl = factory.createBranchNode(caseSt);
|
||||
} else if (elem instanceof IASTDefaultStatement) {
|
||||
if (statement instanceof IASTCaseStatement) {
|
||||
lbl = factory.createBranchNode(statement);
|
||||
} else if (statement instanceof IASTDefaultStatement) {
|
||||
lbl = factory.createBranchNode(IBranchNode.DEFAULT);
|
||||
}
|
||||
if (!(prev instanceof IExitNode) && prev != switchNode) {
|
||||
|
@ -354,12 +348,11 @@ public class ControlFlowGraphBuilder {
|
|||
addOutgoing(switchNode, lbl);
|
||||
continue;
|
||||
}
|
||||
if (elem instanceof IASTBreakStatement) {
|
||||
if (statement instanceof IASTBreakStatement) {
|
||||
prev = addJump(prev, mergeNode);
|
||||
continue;
|
||||
}
|
||||
IBasicBlock last = createSubGraph(prev, elem);
|
||||
prev = last;
|
||||
prev = createSubGraph(prev, statement);
|
||||
}
|
||||
addJump(prev, mergeNode);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue