mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Patch for Devin Steffler.
Further UI indicator infrastructure for testing DOM AST.
This commit is contained in:
parent
497e768f98
commit
6fa14f6b94
5 changed files with 140 additions and 20 deletions
|
@ -1345,6 +1345,14 @@ public class CVisitor {
|
|||
if( !visitDeclaration( parmDeclarations[i], action ) ) return false;
|
||||
}
|
||||
}
|
||||
else if( declarator instanceof IASTArrayDeclarator )
|
||||
{
|
||||
IASTArrayDeclarator arrayDecl = (IASTArrayDeclarator) declarator;
|
||||
IASTArrayModifier [] mods = arrayDecl.getArrayModifiers();
|
||||
for( int i = 0; i < mods.length; ++i )
|
||||
if( mods[i].getConstantExpression() != null &&
|
||||
!visitExpression( mods[i].getConstantExpression(), action ) ) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1690,6 +1698,9 @@ public class CVisitor {
|
|||
return new CQualifierType(declSpec);
|
||||
|
||||
ICASTTypedefNameSpecifier nameSpec = (ICASTTypedefNameSpecifier) declSpec;
|
||||
|
||||
if (!(nameSpec.getName().resolveBinding() instanceof IType)) return null;
|
||||
|
||||
lastType = (IType) nameSpec.getName().resolveBinding();
|
||||
|
||||
IType pointerChain = setupPointerChain(declarator.getPointerOperators(), lastType);
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
|||
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.parser.scanner2.LocationMap.ASTObjectMacro;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
|
@ -182,8 +181,8 @@ public class CPPPopulateASTViewAction extends CPPBaseVisitorAction implements IP
|
|||
private void mergeNode(ASTNode node) {
|
||||
addRoot(node);
|
||||
|
||||
if (node instanceof ASTObjectMacro)
|
||||
addRoot(((ASTObjectMacro)node).getName());
|
||||
if (node instanceof IASTPreprocessorMacroDefinition)
|
||||
addRoot(((IASTPreprocessorMacroDefinition)node).getName());
|
||||
}
|
||||
|
||||
private void mergeMacros(IASTPreprocessorMacroDefinition[] macros) {
|
||||
|
|
|
@ -57,6 +57,11 @@ public class CPopulateASTViewAction extends CBaseVisitorAction implements IPopul
|
|||
}
|
||||
|
||||
private void addRoot(IASTNode node) {
|
||||
if (!(node.getNodeLocations().length > 0 &&
|
||||
node.getNodeLocations()[0].getNodeOffset() > 0 &&
|
||||
node.getNodeLocations()[0].getNodeLength() > 0))
|
||||
return;
|
||||
|
||||
TreeParent parent = root.findParentOfNode(node);
|
||||
|
||||
if ( parent != null ) {
|
||||
|
|
|
@ -235,6 +235,9 @@ private static final String REFRESH_DOM_AST = "Refresh DOM AST"; //$NON-NLS-1
|
|||
if (node instanceof IASTArrayModifier) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTArrayModifier;
|
||||
} else if (node instanceof IASTDeclaration) {
|
||||
if (node instanceof IASTProblemDeclaration)
|
||||
imageKey = DOMASTPluginImages.IMG_IASTProblem;
|
||||
else
|
||||
imageKey = DOMASTPluginImages.IMG_IASTDeclaration;
|
||||
} else if (node instanceof IASTDeclarator) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTDeclarator;
|
||||
|
@ -257,9 +260,6 @@ private static final String REFRESH_DOM_AST = "Refresh DOM AST"; //$NON-NLS-1
|
|||
} else if (node instanceof IASTProblem) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTProblem;
|
||||
} else if (node instanceof IASTSimpleDeclaration) {
|
||||
if (node instanceof IASTProblemDeclaration)
|
||||
imageKey = DOMASTPluginImages.IMG_IASTProblem;
|
||||
else
|
||||
imageKey = DOMASTPluginImages.IMG_IASTSimpleDeclaration;
|
||||
} else if (node instanceof IASTStatement) {
|
||||
imageKey = DOMASTPluginImages.IMG_IASTStatement;
|
||||
|
|
|
@ -14,8 +14,10 @@ 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.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -24,21 +26,39 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
|
||||
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTDesignator;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class TreeObject implements IAdaptable {
|
||||
private static final String DASH = "-";
|
||||
private static final String OP_BRACKETEDPRIMARY = "( )"; //$NON-NLS-1$
|
||||
private static final String OP_TILDE = "~"; //$NON-NLS-1$
|
||||
private static final String OP_SIZEOF = "sizeof"; //$NON-NLS-1$
|
||||
private static final String OP_INCR = "++"; //$NON-NLS-1$
|
||||
private static final String OP_DECR = "--"; //$NON-NLS-1$
|
||||
private static final String OP_NOT = "!"; //$NON-NLS-1$
|
||||
private static final String OP_AMPER = "&"; //$NON-NLS-1$
|
||||
private static final String OP_TYPEOF = "typeof"; //$NON-NLS-1$
|
||||
private static final String OP_ALIGNOF = "alignof"; //$NON-NLS-1$
|
||||
private static final String OP_TYPEID = "typeid"; //$NON-NLS-1$
|
||||
private static final String OP_THROW = "throw"; //$NON-NLS-1$
|
||||
private static final String VARIABLE_SIZED_ = "* "; //$NON-NLS-1$
|
||||
private static final String VOLATILE_ = "volatile "; //$NON-NLS-1$
|
||||
private static final String STATIC_ = "static "; //$NON-NLS-1$
|
||||
private static final String RESTRICT_ = "restrict "; //$NON-NLS-1$
|
||||
private static final String CONST_ = "const "; //$NON-NLS-1$
|
||||
private static final String DASH = "-"; //$NON-NLS-1$
|
||||
private static final String OP_NOTEQUALS = "!="; //$NON-NLS-1$
|
||||
private static final String OP_EQUALS = "=="; //$NON-NLS-1$
|
||||
private static final String OP_BINARYXORASSIGN = "^="; //$NON-NLS-1$
|
||||
|
@ -67,7 +87,7 @@ public class TreeObject implements IAdaptable {
|
|||
private static final String OP_PLUS = "+"; //$NON-NLS-1$
|
||||
private static final String OP_MODULO = "%"; //$NON-NLS-1$
|
||||
private static final String OP_DIVIDE = "/"; //$NON-NLS-1$
|
||||
private static final String OP_MULTIPLY = "*"; //$NON-NLS-1$
|
||||
private static final String OP_STAR = "*"; //$NON-NLS-1$
|
||||
private static final String OP_MIN = "<?"; //$NON-NLS-1$
|
||||
private static final String OP_MAX = ">?"; //$NON-NLS-1$
|
||||
private static final String OP_PMDOT = "."; //$NON-NLS-1$
|
||||
|
@ -180,30 +200,115 @@ public class TreeObject implements IAdaptable {
|
|||
} else if ( node instanceof IASTLiteralExpression ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append(node.toString());
|
||||
} else if ( node instanceof IASTUnaryExpression ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append( getUnaryOperatorString( (IASTUnaryExpression)node ) );
|
||||
} else if ( node instanceof IASTBinaryExpression ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append( getBinaryOperatorString( (IASTBinaryExpression)node ) );
|
||||
} else if ( node instanceof ICASTDesignator ) {
|
||||
if (node instanceof ICASTArrayDesignator) {
|
||||
if ( node instanceof ICASTArrayDesignator && ((ICASTArrayDesignator)node).getSubscriptExpression() != null ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append(((ICASTArrayDesignator)node).getSubscriptExpression()); // TODO Devin need to test this!
|
||||
} else if (node instanceof ICASTFieldDesignator) {
|
||||
buffer.append(((ICASTArrayDesignator)node).getSubscriptExpression());
|
||||
} else if ( node instanceof ICASTFieldDesignator && ((ICASTFieldDesignator)node).getName() != null ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append(((ICASTFieldDesignator)node).getName());
|
||||
} else if (node instanceof IGCCASTArrayRangeDesignator) {
|
||||
} else if ( node instanceof IGCCASTArrayRangeDesignator && ((IGCCASTArrayRangeDesignator)node).getRangeCeiling() != null && ((IGCCASTArrayRangeDesignator)node).getRangeFloor() != null ) {
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append(((IGCCASTArrayRangeDesignator)node).getRangeCeiling());
|
||||
buffer.append(DASH);
|
||||
buffer.append(((IGCCASTArrayRangeDesignator)node).getRangeFloor());
|
||||
}
|
||||
} else if ( node instanceof IASTArrayModifier ) {
|
||||
boolean started = false;
|
||||
if ( node instanceof ICASTArrayModifier ) {
|
||||
started = true;
|
||||
buffer.append(START_OF_LIST);
|
||||
buffer.append(((IASTArrayModifier)node).getConstantExpression());
|
||||
if (((ICASTArrayModifier)node).isConst()) buffer.append(CONST_);
|
||||
if (((ICASTArrayModifier)node).isRestrict()) buffer.append(RESTRICT_);
|
||||
if (((ICASTArrayModifier)node).isStatic()) buffer.append(STATIC_);
|
||||
if (((ICASTArrayModifier)node).isVolatile()) buffer.append(VOLATILE_);
|
||||
if (((ICASTArrayModifier)node).isVariableSized()) buffer.append(VARIABLE_SIZED_);
|
||||
}
|
||||
|
||||
IASTExpression constantExpression = ((IASTArrayModifier)node).getConstantExpression();
|
||||
if ( constantExpression != null && constantExpression instanceof IASTIdExpression ) {
|
||||
if (!started) buffer.append(START_OF_LIST);
|
||||
buffer.append(((IASTIdExpression)constantExpression).getName().toString());
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private String getUnaryOperatorString(IASTUnaryExpression be) {
|
||||
int op = be.getOperator();
|
||||
String opString = BLANK_STRING;
|
||||
|
||||
if (be instanceof ICPPASTUnaryExpression) {
|
||||
switch(op) {
|
||||
case ICPPASTUnaryExpression.op_throw:
|
||||
opString = OP_THROW;
|
||||
break;
|
||||
case ICPPASTUnaryExpression.op_typeid:
|
||||
opString = OP_TYPEID;
|
||||
break;
|
||||
}
|
||||
} else if (be instanceof IGNUASTUnaryExpression) {
|
||||
switch(op) {
|
||||
case IGNUASTUnaryExpression.op_alignOf:
|
||||
opString = OP_ALIGNOF;
|
||||
break;
|
||||
case IGNUASTUnaryExpression.op_typeof:
|
||||
opString = OP_TYPEOF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!opString.equals(BLANK_STRING)) return opString;
|
||||
|
||||
switch(op) {
|
||||
case IASTUnaryExpression.op_amper:
|
||||
opString = OP_AMPER;
|
||||
break;
|
||||
case IASTUnaryExpression.op_bracketedPrimary:
|
||||
opString = OP_BRACKETEDPRIMARY;
|
||||
break;
|
||||
case IASTUnaryExpression.op_minus:
|
||||
opString = OP_MINUS;
|
||||
break;
|
||||
case IASTUnaryExpression.op_not:
|
||||
opString = OP_NOT;
|
||||
break;
|
||||
case IASTUnaryExpression.op_plus:
|
||||
opString = OP_PLUS;
|
||||
break;
|
||||
case IASTUnaryExpression.op_postFixDecr:
|
||||
opString = OP_DECR;
|
||||
break;
|
||||
case IASTUnaryExpression.op_postFixIncr:
|
||||
opString = OP_INCR;
|
||||
break;
|
||||
case IASTUnaryExpression.op_prefixDecr:
|
||||
opString = OP_DECR;
|
||||
break;
|
||||
case IASTUnaryExpression.op_prefixIncr:
|
||||
opString = OP_INCR;
|
||||
break;
|
||||
case IASTUnaryExpression.op_sizeof:
|
||||
opString = OP_SIZEOF;
|
||||
break;
|
||||
case IASTUnaryExpression.op_star:
|
||||
opString = OP_STAR;
|
||||
break;
|
||||
case IASTUnaryExpression.op_tilde:
|
||||
opString = OP_TILDE;
|
||||
break;
|
||||
}
|
||||
|
||||
return opString;
|
||||
}
|
||||
|
||||
private String getBinaryOperatorString(IASTBinaryExpression be) {
|
||||
int op = be.getOperator();
|
||||
String opString = BLANK_STRING;
|
||||
|
@ -232,7 +337,7 @@ public class TreeObject implements IAdaptable {
|
|||
|
||||
switch(op) {
|
||||
case IASTBinaryExpression.op_multiply:
|
||||
opString = OP_MULTIPLY;
|
||||
opString = OP_STAR;
|
||||
break;
|
||||
case IASTBinaryExpression.op_divide:
|
||||
opString = OP_DIVIDE;
|
||||
|
|
Loading…
Add table
Reference in a new issue