mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Patch for Devin Steffler.
Further updates to DOM AST View. Removed NPE's from C/CPPVisitor.
This commit is contained in:
parent
a8e76780a9
commit
6ac6636352
7 changed files with 54 additions and 16 deletions
|
@ -1400,7 +1400,7 @@ public class CVisitor {
|
||||||
} else if( statement instanceof IASTDeclarationStatement ){
|
} else if( statement instanceof IASTDeclarationStatement ){
|
||||||
if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false;
|
if( !visitDeclaration( ((IASTDeclarationStatement)statement).getDeclaration(), action ) ) return false;
|
||||||
} else if( statement instanceof IASTExpressionStatement ){
|
} else if( statement instanceof IASTExpressionStatement ){
|
||||||
if( !visitExpression( ((IASTExpressionStatement)statement).getExpression(), action ) ) return false;
|
if( ((IASTExpressionStatement)statement).getExpression() != null && !visitExpression( ((IASTExpressionStatement)statement).getExpression(), action ) ) return false;
|
||||||
} else if( statement instanceof IASTCaseStatement ){
|
} else if( statement instanceof IASTCaseStatement ){
|
||||||
if( !visitExpression( ((IASTCaseStatement)statement).getExpression(), action ) ) return false;
|
if( !visitExpression( ((IASTCaseStatement)statement).getExpression(), action ) ) return false;
|
||||||
} else if( statement instanceof IASTDoStatement ){
|
} else if( statement instanceof IASTDoStatement ){
|
||||||
|
@ -1478,7 +1478,7 @@ public class CVisitor {
|
||||||
if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false;
|
if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false;
|
||||||
} else if( expression instanceof IASTFunctionCallExpression ){
|
} else if( expression instanceof IASTFunctionCallExpression ){
|
||||||
if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false;
|
if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false;
|
||||||
if( !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false;
|
if( ((IASTFunctionCallExpression)expression).getParameterExpression() != null && !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false;
|
||||||
} else if( expression instanceof IASTIdExpression ){
|
} else if( expression instanceof IASTIdExpression ){
|
||||||
if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false;
|
if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false;
|
||||||
} else if( expression instanceof IASTTypeIdExpression ){
|
} else if( expression instanceof IASTTypeIdExpression ){
|
||||||
|
|
|
@ -858,7 +858,7 @@ public class CPPVisitor {
|
||||||
if( declarator instanceof IASTArrayDeclarator ){
|
if( declarator instanceof IASTArrayDeclarator ){
|
||||||
IASTArrayModifier [] mods = ((IASTArrayDeclarator) declarator).getArrayModifiers();
|
IASTArrayModifier [] mods = ((IASTArrayDeclarator) declarator).getArrayModifiers();
|
||||||
for( int i = 0; i < mods.length; i++ ){
|
for( int i = 0; i < mods.length; i++ ){
|
||||||
if( !visitExpression( mods[i].getConstantExpression(), action ) ) return false;
|
if( mods[i].getConstantExpression() != null && !visitExpression( mods[i].getConstantExpression(), action ) ) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -971,7 +971,8 @@ public class CPPVisitor {
|
||||||
if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false;
|
if( !visitName( ((IASTFieldReference)expression).getFieldName(), action ) ) return false;
|
||||||
} else if( expression instanceof IASTFunctionCallExpression ){
|
} else if( expression instanceof IASTFunctionCallExpression ){
|
||||||
if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false;
|
if( !visitExpression( ((IASTFunctionCallExpression)expression).getFunctionNameExpression(), action ) ) return false;
|
||||||
if( !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false;
|
if( ((IASTFunctionCallExpression)expression).getParameterExpression() != null )
|
||||||
|
if( !visitExpression( ((IASTFunctionCallExpression)expression).getParameterExpression(), action ) ) return false;
|
||||||
} else if( expression instanceof IASTIdExpression ){
|
} else if( expression instanceof IASTIdExpression ){
|
||||||
if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false;
|
if( !visitName( ((IASTIdExpression)expression).getName(), action ) ) return false;
|
||||||
} else if( expression instanceof IASTTypeIdExpression ){
|
} else if( expression instanceof IASTTypeIdExpression ){
|
||||||
|
|
|
@ -179,7 +179,7 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeNode(ASTNode node) {
|
private void mergeNode(ASTNode node) {
|
||||||
addRoot(node); // TODO Devin need to figure out how to merge these based on location
|
addRoot(node);
|
||||||
|
|
||||||
if (node instanceof ASTObjectMacro)
|
if (node instanceof ASTObjectMacro)
|
||||||
addRoot(((ASTObjectMacro)node).getName());
|
addRoot(((ASTObjectMacro)node).getName());
|
||||||
|
|
|
@ -12,7 +12,6 @@ package org.eclipse.cdt.ui.tests.DOMAST;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
@ -22,7 +21,6 @@ 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.IASTPointerOperator;
|
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
|
@ -161,7 +159,7 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mergeNode(ASTNode node) {
|
private void mergeNode(ASTNode node) {
|
||||||
addRoot(node); // TODO Devin need to figure out how to merge these based on location
|
addRoot(node);
|
||||||
|
|
||||||
if (node instanceof ASTObjectMacro)
|
if (node instanceof ASTObjectMacro)
|
||||||
addRoot(((ASTObjectMacro)node).getName());
|
addRoot(((ASTObjectMacro)node).getName());
|
||||||
|
|
|
@ -464,7 +464,7 @@ private static final String REFRESH_DOM_AST = "Refresh DOM AST"; //$NON-NLS-1
|
||||||
if (aPart instanceof CEditor && obj instanceof TreeObject) {
|
if (aPart instanceof CEditor && obj instanceof TreeObject) {
|
||||||
String filename = ((TreeObject) obj).getFilename();
|
String filename = ((TreeObject) obj).getFilename();
|
||||||
|
|
||||||
if (filename.equals(TreeObject.BLANK_FILENAME))
|
if (filename.equals(TreeObject.BLANK_STRING))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IResource r = ParserUtil.getResourceForFilename(filename);
|
IResource r = ParserUtil.getResourceForFilename(filename);
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.eclipse.core.runtime.IAdaptable;
|
||||||
*/
|
*/
|
||||||
public class TreeObject implements IAdaptable {
|
public class TreeObject implements IAdaptable {
|
||||||
private static final String FILE_SEPARATOR = "\\";
|
private static final String FILE_SEPARATOR = "\\";
|
||||||
public static final String BLANK_FILENAME = ""; //$NON-NLS-1$
|
public static final String BLANK_STRING = ""; //$NON-NLS-1$
|
||||||
private static final String IGCCAST_PREFIX = "IGCCAST"; //$NON-NLS-1$
|
private static final String IGCCAST_PREFIX = "IGCCAST"; //$NON-NLS-1$
|
||||||
private static final String IGNUAST_PREFIX = "IGNUAST"; //$NON-NLS-1$
|
private static final String IGNUAST_PREFIX = "IGNUAST"; //$NON-NLS-1$
|
||||||
private static final String IGPPAST_PREFIX = "IGPPAST"; //$NON-NLS-1$
|
private static final String IGPPAST_PREFIX = "IGPPAST"; //$NON-NLS-1$
|
||||||
|
@ -65,7 +65,7 @@ public class TreeObject implements IAdaptable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if( node == null ) return BLANK_FILENAME; //$NON-NLS-1$
|
if( node == null ) return BLANK_STRING; //$NON-NLS-1$
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
|
||||||
Class[] classes = node.getClass().getInterfaces();
|
Class[] classes = node.getClass().getInterfaces();
|
||||||
|
@ -79,12 +79,14 @@ public class TreeObject implements IAdaptable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( node instanceof IASTSimpleDeclaration ) {
|
if ( node instanceof IASTSimpleDeclaration ) {
|
||||||
|
String name = null;
|
||||||
IASTDeclarator[] decltors = ((IASTSimpleDeclaration)node).getDeclarators();
|
IASTDeclarator[] decltors = ((IASTSimpleDeclaration)node).getDeclarators();
|
||||||
|
|
||||||
if ( decltors.length > 0 ) {
|
if ( decltors.length > 0 ) {
|
||||||
buffer.append(START_OF_LIST);
|
buffer.append(START_OF_LIST);
|
||||||
for (int i=0; i<decltors.length; i++) {
|
for (int i=0; i<decltors.length; i++) {
|
||||||
buffer.append(decltors[i].getName());
|
name = getDeclaratorName(decltors[i]);
|
||||||
|
buffer.append(name);
|
||||||
|
|
||||||
if (i+1<decltors.length)
|
if (i+1<decltors.length)
|
||||||
buffer.append(LIST_SEPARATOR);
|
buffer.append(LIST_SEPARATOR);
|
||||||
|
@ -92,7 +94,7 @@ public class TreeObject implements IAdaptable {
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
} else if ( node instanceof IASTFunctionDefinition ) {
|
} else if ( node instanceof IASTFunctionDefinition ) {
|
||||||
String name = ((IASTFunctionDefinition)node).getDeclarator().getName().toString();
|
String name = getDeclaratorName( ((IASTFunctionDefinition)node).getDeclarator() );
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
buffer.append(START_OF_LIST);
|
buffer.append(START_OF_LIST);
|
||||||
buffer.append(name);
|
buffer.append(name);
|
||||||
|
@ -122,17 +124,29 @@ public class TreeObject implements IAdaptable {
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getDeclaratorName(IASTDeclarator decltor) {
|
||||||
|
String name = BLANK_STRING;
|
||||||
|
while (decltor != null && decltor.getName() != null && decltor.getName().toString() == null) {
|
||||||
|
decltor = decltor.getNestedDeclarator();
|
||||||
|
}
|
||||||
|
if (decltor != null && decltor.getName() != null) {
|
||||||
|
name = decltor.getName().toString();
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getAdapter(Class key) {
|
public Object getAdapter(Class key) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFilename()
|
public String getFilename()
|
||||||
{
|
{
|
||||||
if ( node == null ) return BLANK_FILENAME;
|
if ( node == null ) return BLANK_STRING;
|
||||||
IASTNodeLocation [] location = node.getNodeLocations();
|
IASTNodeLocation [] location = node.getNodeLocations();
|
||||||
if( location.length > 0 && location[0] instanceof IASTFileLocation )
|
if( location.length > 0 && location[0] instanceof IASTFileLocation )
|
||||||
return ((IASTFileLocation)location[0]).getFileName();
|
return ((IASTFileLocation)location[0]).getFileName();
|
||||||
return BLANK_FILENAME; //$NON-NLS-1$
|
return BLANK_STRING; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOffset() {
|
public int getOffset() {
|
||||||
|
|
|
@ -14,6 +14,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||||
|
import org.eclipse.cdt.internal.core.parser.scanner2.LocationMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dsteffle
|
* @author dsteffle
|
||||||
|
@ -26,7 +28,30 @@ public class TreeParent extends TreeObject {
|
||||||
children = new ArrayList();
|
children = new ArrayList();
|
||||||
}
|
}
|
||||||
public void addChild(TreeObject child) {
|
public void addChild(TreeObject child) {
|
||||||
children.add(child);
|
int index = 0;
|
||||||
|
for(int i=0; i<children.size(); i++) {
|
||||||
|
TreeObject treeObj = (TreeObject)children.get(i);
|
||||||
|
int treeObjOffset = 0;
|
||||||
|
int childObjOffset = 0;
|
||||||
|
if( treeObj.getNode() instanceof ASTNode )
|
||||||
|
treeObjOffset = ((ASTNode)treeObj.getNode()).getOffset();
|
||||||
|
else if( treeObj.getNode() instanceof LocationMap.ScannerASTNode )
|
||||||
|
treeObjOffset = ((LocationMap.ScannerASTNode)child.getNode()).getOffset();
|
||||||
|
|
||||||
|
if( child.getNode() instanceof ASTNode )
|
||||||
|
childObjOffset = ((ASTNode)child.getNode()).getOffset();
|
||||||
|
else if( child.getNode() instanceof LocationMap.ScannerASTNode )
|
||||||
|
childObjOffset = ((LocationMap.ScannerASTNode)child.getNode()).getOffset();
|
||||||
|
|
||||||
|
if ( treeObjOffset < childObjOffset ){
|
||||||
|
index = i+1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
children.add(index, child);
|
||||||
|
|
||||||
child.setParent(this);
|
child.setParent(this);
|
||||||
}
|
}
|
||||||
public void removeChild(TreeObject child) {
|
public void removeChild(TreeObject child) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue