mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Visit method for pointer operators, bug 260461.
This commit is contained in:
parent
4e20a3afa8
commit
8d489aa58e
10 changed files with 135 additions and 64 deletions
|
@ -52,6 +52,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNullStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
|
||||
|
@ -5868,11 +5869,12 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertInstance(children[1], IASTDeclarator.class);
|
||||
|
||||
children= children[1].getChildren();
|
||||
assertEquals(2, children.length);
|
||||
assertInstance(children[0], IASTName.class);
|
||||
assertInstance(children[1], IASTInitializer.class);
|
||||
assertEquals(3, children.length);
|
||||
assertInstance(children[0], IASTPointerOperator.class);
|
||||
assertInstance(children[1], IASTName.class);
|
||||
assertInstance(children[2], IASTInitializer.class);
|
||||
|
||||
children= children[1].getChildren()[0].getChildren(); // skip binary expression
|
||||
children= children[2].getChildren()[0].getChildren(); // skip binary expression
|
||||
assertEquals(2, children.length);
|
||||
assertInstance(children[0], IASTLiteralExpression.class);
|
||||
assertInstance(children[1], IASTLiteralExpression.class);
|
||||
|
@ -6007,4 +6009,17 @@ public class AST2Tests extends AST2BaseTest {
|
|||
IVariable v= ba.assertNonProblem("y);", 1);
|
||||
}
|
||||
}
|
||||
|
||||
// int* v;
|
||||
public void testPointerOperatorsAsChildren_260461() throws Exception {
|
||||
final String code= getAboveComment();
|
||||
for (ParserLanguage lang : ParserLanguage.values()) {
|
||||
IASTTranslationUnit tu= parseAndCheckBindings(code, lang, true);
|
||||
IASTSimpleDeclaration decl= getDeclaration(tu, 0);
|
||||
IASTDeclarator dtor= decl.getDeclarators()[0];
|
||||
IASTNode[] nodes = dtor.getChildren();
|
||||
assertEquals(2, nodes.length);
|
||||
assertInstance(nodes[0], IASTPointerOperator.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,11 @@ public abstract class ASTGenericVisitor extends ASTVisitor implements ICPPASTVis
|
|||
public int visit(IASTArrayModifier arrayModifier) {
|
||||
return genericVisit(arrayModifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTPointerOperator ptrOperator) {
|
||||
return genericVisit(ptrOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTDeclaration declaration) {
|
||||
|
@ -137,6 +142,11 @@ public abstract class ASTGenericVisitor extends ASTVisitor implements ICPPASTVis
|
|||
public int leave(IASTArrayModifier arrayModifier) {
|
||||
return genericLeave(arrayModifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTPointerOperator ptrOperator) {
|
||||
return genericLeave(ptrOperator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int leave(IASTDeclaration declaration) {
|
||||
|
|
|
@ -70,6 +70,11 @@ public abstract class ASTVisitor {
|
|||
* @since 5.1
|
||||
*/
|
||||
public boolean shouldVisitArrayModifiers = false;
|
||||
/**
|
||||
* Set this flag to visit pointer operators of declarators.
|
||||
* @since 5.1
|
||||
*/
|
||||
public boolean shouldVisitPointerOperators = false;
|
||||
/**
|
||||
* Set this flag to visit expressions.
|
||||
*/
|
||||
|
@ -160,6 +165,7 @@ public abstract class ASTVisitor {
|
|||
shouldVisitNames= visitNodes;
|
||||
shouldVisitNamespaces= visitNodes;
|
||||
shouldVisitParameterDeclarations= visitNodes;
|
||||
shouldVisitPointerOperators= visitNodes;
|
||||
shouldVisitProblems= visitNodes;
|
||||
shouldVisitStatements= visitNodes;
|
||||
shouldVisitTemplateParameters= visitNodes;
|
||||
|
@ -203,6 +209,13 @@ public abstract class ASTVisitor {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
public int visit(IASTPointerOperator ptrOperator) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int visit(IASTExpression expression) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
@ -258,6 +271,12 @@ public abstract class ASTVisitor {
|
|||
public int leave(IASTArrayModifier arrayModifier) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
public int leave(IASTPointerOperator ptrOperator) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int leave(IASTExpression expression) {
|
||||
return PROCESS_CONTINUE;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* 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
|
||||
|
@ -131,6 +131,11 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
|
|||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= pointerOpsPos; i++) {
|
||||
if (!pointerOps[i].accept(action))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR && nestedDeclarator == null) {
|
||||
if (getParent() instanceof IASTDeclarator) {
|
||||
IASTDeclarator outermostDeclarator = (IASTDeclarator) getParent();
|
||||
|
@ -148,12 +153,6 @@ public class CASTDeclarator extends ASTNode implements IASTDeclarator, IASTAmbig
|
|||
return false;
|
||||
}
|
||||
|
||||
IASTPointerOperator[] ptrOps = getPointerOperators();
|
||||
for (int i = 0; i < ptrOps.length; i++) {
|
||||
if (!ptrOps[i].accept(action))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!postAccept(action))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2009 IBM Corporation and others.
|
||||
* 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:
|
||||
* IBM Rational Software - Initial API and implementation
|
||||
* John Camelon (IBM Rational Software) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.c;
|
||||
|
||||
|
@ -14,9 +15,6 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CASTPointer extends ASTNode implements ICASTPointer {
|
||||
|
||||
private boolean isRestrict;
|
||||
|
@ -60,8 +58,15 @@ public class CASTPointer extends ASTNode implements ICASTPointer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor visitor) {
|
||||
return true;
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitPointerOperators) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
}
|
||||
if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* 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
|
||||
|
@ -53,25 +53,20 @@ public class CPPASTArrayModifier extends ASTNode implements IASTArrayModifier, I
|
|||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (exp != null) {
|
||||
if( action.shouldVisitArrayModifiers ){
|
||||
switch( action.visit( this ) ){
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
}
|
||||
if (action.shouldVisitArrayModifiers) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
}
|
||||
if (!exp.accept(action))
|
||||
return false;
|
||||
if( action.shouldVisitArrayModifiers ){
|
||||
switch( action.leave( this ) ){
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
default : break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (exp != null && !exp.accept(action))
|
||||
return false;
|
||||
|
||||
if (action.shouldVisitArrayModifiers && action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replace(IASTNode child, IASTNode other) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* 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
|
||||
|
@ -26,7 +26,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
|
||||
|
||||
/**
|
||||
* C++ specific declarator.
|
||||
|
@ -130,13 +130,13 @@ public class CPPASTDeclarator extends ASTNode implements IASTDeclarator {
|
|||
}
|
||||
}
|
||||
|
||||
IASTPointerOperator[] ptrOps = getPointerOperators();
|
||||
for (int i = 0; i < ptrOps.length; i++) {
|
||||
if (!ptrOps[i].accept(action)) return false;
|
||||
for (int i = 0; i <= pointerOpsPos; i++) {
|
||||
if (!pointerOps[i].accept(action))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nested == null && name != null) {
|
||||
IASTDeclarator outermost= CPPVisitor.findOutermostDeclarator(this);
|
||||
IASTDeclarator outermost= ASTQueries.findOutermostDeclarator(this);
|
||||
if (outermost.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR) {
|
||||
if (!name.accept(action)) return false;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* 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:
|
||||
* IBM - Initial API and implementation
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -15,14 +16,15 @@ import org.eclipse.cdt.core.dom.ast.IASTPointer;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
* A pointer operator of a declarator
|
||||
*/
|
||||
public class CPPASTPointer extends ASTNode implements IASTPointer {
|
||||
|
||||
private boolean isConst;
|
||||
|
||||
private boolean isVolatile;
|
||||
|
||||
public CPPASTPointer() {
|
||||
}
|
||||
|
||||
public CPPASTPointer copy() {
|
||||
CPPASTPointer copy = new CPPASTPointer();
|
||||
|
@ -52,6 +54,14 @@ public class CPPASTPointer extends ASTNode implements IASTPointer {
|
|||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
return true;
|
||||
if (action.shouldVisitPointerOperators) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
}
|
||||
if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* 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:
|
||||
* IBM - Initial API and implementation
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -14,9 +15,6 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTPointerToMember extends CPPASTPointer implements ICPPASTPointerToMember {
|
||||
|
||||
private IASTName n;
|
||||
|
@ -52,11 +50,20 @@ public class CPPASTPointerToMember extends CPPASTPointer implements ICPPASTPoint
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean accept( ASTVisitor action ){
|
||||
if( n != null ) if( !n.accept( action ) ) return false;
|
||||
return true;
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitPointerOperators) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
}
|
||||
}
|
||||
if (n != null && !n.accept(action))
|
||||
return false;
|
||||
|
||||
if (action.shouldVisitPointerOperators && action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public int getRoleForName(IASTName name ) {
|
||||
if( name == this.n )
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* 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:
|
||||
* IBM - Initial API and implementation
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -15,10 +16,13 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
* Reference operator for declarators.
|
||||
*/
|
||||
public class CPPASTReferenceOperator extends ASTNode implements ICPPASTReferenceOperator {
|
||||
|
||||
public CPPASTReferenceOperator() {
|
||||
}
|
||||
|
||||
public CPPASTReferenceOperator copy() {
|
||||
CPPASTReferenceOperator copy = new CPPASTReferenceOperator();
|
||||
copy.setOffsetAndLength(this);
|
||||
|
@ -26,8 +30,15 @@ public class CPPASTReferenceOperator extends ASTNode implements ICPPASTReference
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean accept( ASTVisitor action ){
|
||||
return true;
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (action.shouldVisitPointerOperators) {
|
||||
switch (action.visit(this)) {
|
||||
case ASTVisitor.PROCESS_ABORT : return false;
|
||||
case ASTVisitor.PROCESS_SKIP : return true;
|
||||
}
|
||||
if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue