mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Extracted interface for data object of Basic Block in control flow graph
This commit is contained in:
parent
ed2cdbc529
commit
a39fe6b4b2
6 changed files with 42 additions and 12 deletions
|
@ -16,7 +16,7 @@ import org.eclipse.cdt.codan.core.cxx.model.AbstractAstFunctionChecker;
|
|||
import org.eclipse.cdt.codan.core.cxx.model.CxxModelsCache;
|
||||
import org.eclipse.cdt.codan.core.model.cfg.IControlFlowGraph;
|
||||
import org.eclipse.cdt.codan.core.model.cfg.IExitNode;
|
||||
import org.eclipse.cdt.codan.internal.core.cfg.AbstractBasicBlock;
|
||||
import org.eclipse.cdt.codan.internal.core.cfg.ICfgData;
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
|
@ -100,7 +100,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
|||
boolean noexitop = false;
|
||||
for (; exitNodeIterator.hasNext();) {
|
||||
IExitNode node = exitNodeIterator.next();
|
||||
if (((AbstractBasicBlock) node).getData() == null) {
|
||||
if (((ICfgData) node).getData() == null) {
|
||||
// if it real exit node such as return, exit or throw data
|
||||
// will be an ast node, it is null it is fake node added by the
|
||||
// graph builder
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.cdt.codan.core.model.cfg.IPlainNode;
|
|||
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.DecisionNode;
|
||||
import org.eclipse.cdt.codan.internal.core.cfg.ICfgData;
|
||||
import org.eclipse.cdt.codan.internal.core.cfg.JumpNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
|
||||
|
@ -440,7 +441,7 @@ public class ControlFlowGraphBuilder {
|
|||
if (prev instanceof IExitNode || prev == null) {
|
||||
dead.add(node);
|
||||
return;
|
||||
} else if (prev instanceof AbstractBasicBlock) {
|
||||
} else if (prev instanceof ICfgData) {
|
||||
((AbstractBasicBlock) prev).addOutgoing(node);
|
||||
}
|
||||
if (!(node instanceof IStartNode))
|
||||
|
|
|
@ -15,7 +15,7 @@ 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.INodeFactory;
|
||||
import org.eclipse.cdt.codan.core.model.cfg.IPlainNode;
|
||||
import org.eclipse.cdt.codan.internal.core.cfg.AbstractBasicBlock;
|
||||
import org.eclipse.cdt.codan.internal.core.cfg.ICfgData;
|
||||
import org.eclipse.cdt.codan.internal.core.cfg.NodeFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
||||
|
@ -41,19 +41,19 @@ public class CxxNodeFactory extends NodeFactory implements INodeFactory {
|
|||
|
||||
public CxxPlainNode createPlainNode(IASTNode ast) {
|
||||
IPlainNode node = createPlainNode();
|
||||
((AbstractBasicBlock) node).setData(ast);
|
||||
((ICfgData) node).setData(ast);
|
||||
return (CxxPlainNode) node;
|
||||
}
|
||||
|
||||
public CxxDecisionNode createDecisionNode(IASTNode ast) {
|
||||
IDecisionNode node = createDecisionNode();
|
||||
((AbstractBasicBlock) node).setData(ast);
|
||||
((ICfgData) node).setData(ast);
|
||||
return (CxxDecisionNode) node;
|
||||
}
|
||||
|
||||
public CxxExitNode createExitNode(IASTNode ast) {
|
||||
IExitNode node = createExitNode();
|
||||
((AbstractBasicBlock) node).setData(ast);
|
||||
((ICfgData) node).setData(ast);
|
||||
return (CxxExitNode) node;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class CxxNodeFactory extends NodeFactory implements INodeFactory {
|
|||
*/
|
||||
public IBranchNode createBranchNode(IASTNode caseSt) {
|
||||
IBranchNode node = createBranchNode(caseSt.getRawSignature());
|
||||
((AbstractBasicBlock) node).setData(caseSt);
|
||||
((ICfgData) node).setData(caseSt);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,19 @@ import java.util.Iterator;
|
|||
|
||||
import org.eclipse.cdt.codan.core.model.cfg.IBasicBlock;
|
||||
|
||||
public abstract class AbstractBasicBlock implements IBasicBlock {
|
||||
public abstract class AbstractBasicBlock implements IBasicBlock, ICfgData {
|
||||
private Object data;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.internal.core.cfg.ICfgData#getData()
|
||||
*/
|
||||
public Object getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.internal.core.cfg.ICfgData#setData(java.lang.Object)
|
||||
*/
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Interface to access data object that control flog graph block carries,
|
||||
* usually
|
||||
* it is an ast node
|
||||
*/
|
||||
public interface ICfgData {
|
||||
public abstract Object getData();
|
||||
|
||||
public abstract void setData(Object data);
|
||||
}
|
|
@ -16,6 +16,7 @@ import org.eclipse.cdt.codan.core.model.cfg.IJumpNode;
|
|||
import org.eclipse.cdt.codan.core.model.cfg.ISingleOutgoing;
|
||||
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.ICfgData;
|
||||
import org.eclipse.cdt.codan.ui.cfgview.ControlFlowGraphPlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
|
@ -168,7 +169,7 @@ public class ControlFlowGraphView extends ViewPart {
|
|||
if (obj == null)
|
||||
return null;
|
||||
String strdata = "";
|
||||
if (obj instanceof AbstractBasicBlock) {
|
||||
if (obj instanceof ICfgData) {
|
||||
strdata = ((AbstractBasicBlock) obj).toStringData();
|
||||
}
|
||||
if (obj instanceof IConnectorNode) {
|
||||
|
@ -376,8 +377,8 @@ public class ControlFlowGraphView extends ViewPart {
|
|||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection) selection).getFirstElement();
|
||||
if (obj instanceof AbstractBasicBlock) {
|
||||
Object data = ((AbstractBasicBlock) obj).getData();
|
||||
if (obj instanceof ICfgData) {
|
||||
Object data = ((ICfgData) obj).getData();
|
||||
if (data instanceof IASTNode) {
|
||||
IASTNode node = (IASTNode) data;
|
||||
if (node instanceof IASTTranslationUnit) // don't
|
||||
|
|
Loading…
Add table
Reference in a new issue