mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Devin Steffler.
Further updates to DOM AST View.
This commit is contained in:
parent
3dbe65030b
commit
11f8e7fc7a
6 changed files with 88 additions and 4 deletions
|
@ -77,7 +77,13 @@
|
||||||
<visibility>
|
<visibility>
|
||||||
<or>
|
<or>
|
||||||
<objectState name="extension" value="cpp"/>
|
<objectState name="extension" value="cpp"/>
|
||||||
<objectState name="extension" value="c"/>
|
<objectState name="extension" value="CPP"/>
|
||||||
|
<objectState name="extension" value="c"/>
|
||||||
|
<objectState name="extension" value="C"/>
|
||||||
|
<objectState name="extension" value="cc"/>
|
||||||
|
<objectState name="extension" value="CC"/>
|
||||||
|
<objectState name="extension" value="cxx"/>
|
||||||
|
<objectState name="extension" value="CXX"/>
|
||||||
</or>
|
</or>
|
||||||
</visibility>
|
</visibility>
|
||||||
</viewerContribution>
|
</viewerContribution>
|
||||||
|
|
|
@ -18,13 +18,17 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap.ASTObjectMacro;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dsteffle
|
* @author dsteffle
|
||||||
|
@ -122,7 +126,8 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
|
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||||
*/
|
*/
|
||||||
public int processName(IASTName name) {
|
public int processName(IASTName name) {
|
||||||
addRoot(name);
|
if (name.toString() != null)
|
||||||
|
addRoot(name);
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,8 +163,40 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
||||||
addRoot(typeId);
|
addRoot(typeId);
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void mergeNode(ASTNode node) {
|
||||||
|
addRoot(node); // TODO Devin need to figure out how to merge these based on location
|
||||||
|
|
||||||
|
if (node instanceof ASTObjectMacro)
|
||||||
|
addRoot(((ASTObjectMacro)node).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeMacros(IASTPreprocessorMacroDefinition[] macros) {
|
||||||
|
for(int i=0; i<macros.length; i++) {
|
||||||
|
if (macros[i] instanceof ASTNode)
|
||||||
|
mergeNode((ASTNode)macros[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergePreprocessorProblems(IASTProblem[] problems) {
|
||||||
|
for(int i=0; i<problems.length; i++) {
|
||||||
|
if (problems[i] instanceof ASTNode)
|
||||||
|
mergeNode((ASTNode)problems[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public TreeParent getTree() {
|
public TreeParent getTree() {
|
||||||
|
if (root.getNode() instanceof IASTTranslationUnit) {
|
||||||
|
IASTTranslationUnit tu = (IASTTranslationUnit)root.getNode();
|
||||||
|
|
||||||
|
// merge macro definitions to the tree
|
||||||
|
mergeMacros(tu.getMacroDefinitions());
|
||||||
|
|
||||||
|
// merge preprocessor problems to the tree
|
||||||
|
mergePreprocessorProblems(tu.getPreprocesorProblems());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,16 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap.ASTObjectMacro;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dsteffle
|
* @author dsteffle
|
||||||
|
@ -110,7 +115,8 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
||||||
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
|
* @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
|
||||||
*/
|
*/
|
||||||
public int processName(IASTName name) {
|
public int processName(IASTName name) {
|
||||||
addRoot(name);
|
if ( name.toString() != null )
|
||||||
|
addRoot(name);
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +145,39 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void mergeNode(ASTNode node) {
|
||||||
|
addRoot(node); // TODO Devin need to figure out how to merge these based on location
|
||||||
|
|
||||||
|
if (node instanceof ASTObjectMacro)
|
||||||
|
addRoot(((ASTObjectMacro)node).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeMacros(IASTPreprocessorMacroDefinition[] macros) {
|
||||||
|
for(int i=0; i<macros.length; i++) {
|
||||||
|
if (macros[i] instanceof ASTNode)
|
||||||
|
mergeNode((ASTNode)macros[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergePreprocessorProblems(IASTProblem[] problems) {
|
||||||
|
for(int i=0; i<problems.length; i++) {
|
||||||
|
if (problems[i] instanceof ASTNode)
|
||||||
|
mergeNode((ASTNode)problems[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public TreeParent getTree() {
|
public TreeParent getTree() {
|
||||||
|
if (root.getNode() instanceof IASTTranslationUnit) {
|
||||||
|
IASTTranslationUnit tu = (IASTTranslationUnit)root.getNode();
|
||||||
|
|
||||||
|
// merge macro definitions to the tree
|
||||||
|
mergeMacros(tu.getMacroDefinitions());
|
||||||
|
|
||||||
|
// merge preprocessor problems to the tree
|
||||||
|
mergePreprocessorProblems(tu.getPreprocesorProblems());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -463,6 +463,8 @@ public class DOMAST extends ViewPart {
|
||||||
}
|
}
|
||||||
((CEditor) aPart).selectAndReveal(((TreeObject) obj).getOffset(),
|
((CEditor) aPart).selectAndReveal(((TreeObject) obj).getOffset(),
|
||||||
((TreeObject) obj).getLength());
|
((TreeObject) obj).getLength());
|
||||||
|
|
||||||
|
aPart.getSite().getPage().activate(aPart.getSite().getPage().findView(OpenDOMViewAction.VIEW_ID));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.eclipse.ui.PartInitException;
|
||||||
*/
|
*/
|
||||||
public class OpenDOMViewAction implements IViewActionDelegate, IEditorActionDelegate, IObjectActionDelegate {
|
public class OpenDOMViewAction implements IViewActionDelegate, IEditorActionDelegate, IObjectActionDelegate {
|
||||||
|
|
||||||
private static final String VIEW_ID = "org.eclipse.cdt.ui.tests.DOMAST.DOMAST"; //$NON-NLS-1$
|
public static final String VIEW_ID = "org.eclipse.cdt.ui.tests.DOMAST.DOMAST"; //$NON-NLS-1$
|
||||||
IViewPart viewPart = null;
|
IViewPart viewPart = null;
|
||||||
ISelection selection = null;
|
ISelection selection = null;
|
||||||
IFile file = null;
|
IFile file = null;
|
||||||
|
|
|
@ -85,6 +85,7 @@ public class TreeObject implements IAdaptable {
|
||||||
|
|
||||||
public String getFilename()
|
public String getFilename()
|
||||||
{
|
{
|
||||||
|
if ( node == null ) return ""; //$NON-NLS-1$
|
||||||
IASTNodeLocation [] location = node.getNodeLocations();
|
IASTNodeLocation [] location = node.getNodeLocations();
|
||||||
if( location[0] instanceof IASTFileLocation )
|
if( location[0] instanceof IASTFileLocation )
|
||||||
return ((IASTFileLocation)location[0]).getFileName();
|
return ((IASTFileLocation)location[0]).getFileName();
|
||||||
|
|
Loading…
Add table
Reference in a new issue