mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +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;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBasicBlock createSubGraph(IBasicBlock prev, IASTNode body) {
|
private IBasicBlock createSubGraph(IBasicBlock prev, IASTStatement body) {
|
||||||
if (body instanceof IASTCompoundStatement) {
|
if (body instanceof IASTCompoundStatement) {
|
||||||
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
||||||
IASTNode[] children = comp.getChildren();
|
for (IASTStatement statement : comp.getStatements()) {
|
||||||
for (int i = 0; i < children.length; i++) {
|
prev = createSubGraph(prev, statement);
|
||||||
IASTNode node = children[i];
|
|
||||||
IBasicBlock last = createSubGraph(prev, node);
|
|
||||||
prev = last;
|
|
||||||
}
|
}
|
||||||
} else if (body instanceof IASTExpressionStatement || body instanceof IASTDeclarationStatement || body instanceof IASTNullStatement) {
|
} else if (body instanceof IASTExpressionStatement || body instanceof IASTDeclarationStatement || body instanceof IASTNullStatement) {
|
||||||
if (isThrowStatement(body) || isExitStatement(body)) {
|
if (isThrowStatement(body) || isExitStatement(body)) {
|
||||||
|
@ -327,20 +324,17 @@ public class ControlFlowGraphBuilder {
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSwitchBody(DecisionNode switchNode, IConnectorNode mergeNode, IASTStatement body) {
|
private void createSwitchBody(IDecisionNode switchNode, IConnectorNode mergeNode, IASTStatement body) {
|
||||||
if (!(body instanceof IASTCompoundStatement))
|
if (!(body instanceof IASTCompoundStatement))
|
||||||
return; // bad
|
return; // bad
|
||||||
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
IASTCompoundStatement comp = (IASTCompoundStatement) body;
|
||||||
IASTNode[] children = comp.getChildren();
|
|
||||||
IBasicBlock prev = switchNode;
|
IBasicBlock prev = switchNode;
|
||||||
for (int i = 0; i < children.length; i++) {
|
for (IASTStatement statement : comp.getStatements()) {
|
||||||
IASTNode elem = children[i];
|
if (statement instanceof IASTCaseStatement || statement instanceof IASTDefaultStatement) {
|
||||||
if (elem instanceof IASTCaseStatement || elem instanceof IASTDefaultStatement) {
|
|
||||||
IBranchNode lbl = null;
|
IBranchNode lbl = null;
|
||||||
if (elem instanceof IASTCaseStatement) {
|
if (statement instanceof IASTCaseStatement) {
|
||||||
IASTCaseStatement caseSt = (IASTCaseStatement) elem;
|
lbl = factory.createBranchNode(statement);
|
||||||
lbl = factory.createBranchNode(caseSt);
|
} else if (statement instanceof IASTDefaultStatement) {
|
||||||
} else if (elem instanceof IASTDefaultStatement) {
|
|
||||||
lbl = factory.createBranchNode(IBranchNode.DEFAULT);
|
lbl = factory.createBranchNode(IBranchNode.DEFAULT);
|
||||||
}
|
}
|
||||||
if (!(prev instanceof IExitNode) && prev != switchNode) {
|
if (!(prev instanceof IExitNode) && prev != switchNode) {
|
||||||
|
@ -354,12 +348,11 @@ public class ControlFlowGraphBuilder {
|
||||||
addOutgoing(switchNode, lbl);
|
addOutgoing(switchNode, lbl);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (elem instanceof IASTBreakStatement) {
|
if (statement instanceof IASTBreakStatement) {
|
||||||
prev = addJump(prev, mergeNode);
|
prev = addJump(prev, mergeNode);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
IBasicBlock last = createSubGraph(prev, elem);
|
prev = createSubGraph(prev, statement);
|
||||||
prev = last;
|
|
||||||
}
|
}
|
||||||
addJump(prev, mergeNode);
|
addJump(prev, mergeNode);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue