mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Allows to visit array-modifiers, bug 237605.
This commit is contained in:
parent
4e28c73769
commit
7b61bb10f2
9 changed files with 75 additions and 60 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
|
||||
Bundle-Version: 5.0.0.qualifier
|
||||
Bundle-Version: 5.1.0.qualifier
|
||||
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
|
||||
Bundle-Vendor: %providerName
|
||||
Bundle-Localization: plugin
|
||||
|
|
|
@ -62,6 +62,11 @@ public abstract class ASTVisitor {
|
|||
* Set this flag to visit declaration specifiers.
|
||||
*/
|
||||
public boolean shouldVisitDeclSpecifiers = false;
|
||||
/**
|
||||
* Set this flag to visit array modifiers.
|
||||
* @since 5.1
|
||||
*/
|
||||
public boolean shouldVisitArrayModifiers = false;
|
||||
/**
|
||||
* Set this flag to visit expressions.
|
||||
*/
|
||||
|
@ -111,7 +116,6 @@ public abstract class ASTVisitor {
|
|||
*/
|
||||
public boolean shouldVisitTemplateParameters = false;
|
||||
|
||||
|
||||
// visit methods
|
||||
public int visit(IASTTranslationUnit tu) {
|
||||
return PROCESS_CONTINUE;
|
||||
|
@ -141,6 +145,13 @@ public abstract class ASTVisitor {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
public int visit(IASTArrayModifier arrayModifier) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int visit(IASTExpression expression) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
@ -190,6 +201,13 @@ public abstract class ASTVisitor {
|
|||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 5.1
|
||||
*/
|
||||
public int leave(IASTArrayModifier arrayModifier) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
public int leave(IASTExpression expression) {
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.eclipse.cdt.core.dom.IName;
|
|||
* The toString method produces a string representation of the name as
|
||||
* appropriate for the language.
|
||||
*
|
||||
* @author Doug Schaefer
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
*/
|
||||
public interface IASTName extends IASTNode, IName {
|
||||
|
||||
|
@ -88,4 +88,11 @@ public interface IASTName extends IASTNode, IName {
|
|||
* @since 5.0
|
||||
*/
|
||||
public IASTImageLocation getImageLocation();
|
||||
|
||||
/**
|
||||
* For convenience this method returns the last name of a qualified name or this if this is not a
|
||||
* qualified name.
|
||||
* @since 5.1
|
||||
*/
|
||||
public IASTName getLastName();
|
||||
}
|
||||
|
|
|
@ -46,8 +46,25 @@ public class CASTArrayModifier extends CASTNode implements IASTArrayModifier, IA
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean accept( ASTVisitor action ){
|
||||
if( exp != null ) if( !exp.accept( action ) ) return false;
|
||||
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 (!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;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* IBM - Initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -44,10 +45,24 @@ public class CPPASTArrayModifier extends CPPASTNode implements IASTArrayModifier
|
|||
|
||||
@Override
|
||||
public boolean accept(ASTVisitor action) {
|
||||
if (exp != null)
|
||||
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 (!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;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGeneratorWriterVisitor;
|
||||
|
@ -80,16 +78,7 @@ public class ASTWriter {
|
|||
*/
|
||||
public String write(IASTNode rootNode, String fileScope, NodeCommentMap commentMap) throws ProblemRuntimeException {
|
||||
transformationVisitor = new ChangeGeneratorWriterVisitor(modificationStore, givenIndentation, fileScope, commentMap);
|
||||
|
||||
// mstodo: workaround for
|
||||
if (rootNode instanceof IASTArrayModifier) {
|
||||
int result= transformationVisitor.visit((IASTArrayModifier) rootNode);
|
||||
if (result == ASTVisitor.PROCESS_CONTINUE) {
|
||||
rootNode.accept(transformationVisitor);
|
||||
}
|
||||
} else {
|
||||
rootNode.accept(transformationVisitor);
|
||||
}
|
||||
rootNode.accept(transformationVisitor);
|
||||
String str = transformationVisitor.toString();
|
||||
transformationVisitor.cleanCache();
|
||||
return str;
|
||||
|
|
|
@ -69,6 +69,8 @@ public class ASTWriterVisitor extends CPPASTVisitor {
|
|||
|
||||
shouldVisitDeclarators = true;
|
||||
|
||||
shouldVisitArrayModifiers= true;
|
||||
|
||||
shouldVisitInitializers = true;
|
||||
|
||||
shouldVisitBaseSpecifiers = true;
|
||||
|
@ -202,6 +204,7 @@ public class ASTWriterVisitor extends CPPASTVisitor {
|
|||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTArrayModifier amod) {
|
||||
if(!macroHandler.checkisMacroExpansionNode(amod)) {
|
||||
declaratorWriter.writeArrayModifier(amod);
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
|
@ -29,13 +28,10 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
|
||||
|
@ -84,6 +80,8 @@ public class ChangeGenerator extends CPPASTVisitor {
|
|||
|
||||
shouldVisitDeclarators = true;
|
||||
|
||||
shouldVisitArrayModifiers= true;
|
||||
|
||||
shouldVisitInitializers = true;
|
||||
|
||||
shouldVisitBaseSpecifiers = true;
|
||||
|
@ -391,49 +389,16 @@ public class ChangeGenerator extends CPPASTVisitor {
|
|||
synthTreatment(declarator);
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
|
||||
// mstodo workaround
|
||||
if (declarator instanceof IASTArrayDeclarator) {
|
||||
IASTPointerOperator [] ptrOps = declarator.getPointerOperators();
|
||||
for ( int i = 0; i < ptrOps.length; i++ ) {
|
||||
if( !ptrOps[i].accept( this ) ) return PROCESS_ABORT;
|
||||
}
|
||||
|
||||
IASTDeclarator nestedDeclarator= declarator.getNestedDeclarator();
|
||||
IASTName name= declarator.getName();
|
||||
if (nestedDeclarator == null && name != null) {
|
||||
IASTDeclarator outermost= CPPVisitor.findOutermostDeclarator(declarator);
|
||||
if (outermost.getPropertyInParent() != IASTTypeId.ABSTRACT_DECLARATOR) {
|
||||
if (!name.accept(this)) return PROCESS_ABORT;
|
||||
}
|
||||
}
|
||||
|
||||
if (nestedDeclarator != null) {
|
||||
if (!nestedDeclarator.accept(this)) return PROCESS_ABORT;
|
||||
}
|
||||
|
||||
IASTArrayModifier [] mods = ((IASTArrayDeclarator) declarator).getArrayModifiers();
|
||||
for ( int i = 0; i < mods.length; i++ ) {
|
||||
int result= visit(mods[i]);
|
||||
if (result != PROCESS_CONTINUE)
|
||||
return result;
|
||||
|
||||
if( !mods[i].accept( this ) ) return PROCESS_ABORT;
|
||||
}
|
||||
IASTInitializer initializer = declarator.getInitializer();
|
||||
if( initializer != null ) if( !initializer.accept( this ) ) return PROCESS_ABORT;
|
||||
return PROCESS_CONTINUE;
|
||||
}
|
||||
|
||||
return super.visit(declarator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int visit(IASTArrayModifier mod) {
|
||||
if (hasChangedChild(mod)) {
|
||||
synthTreatment(mod);
|
||||
return ASTVisitor.PROCESS_SKIP;
|
||||
}
|
||||
return PROCESS_CONTINUE;
|
||||
return super.visit(mod);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ public class ChangeGeneratorWriterVisitor extends ASTWriterVisitor {
|
|||
shouldVisitTranslationUnit = delegateVisitor.shouldVisitTranslationUnit;
|
||||
shouldVisitProblems = delegateVisitor.shouldVisitProblems;
|
||||
shouldVisitTypeIds = delegateVisitor.shouldVisitTypeIds;
|
||||
shouldVisitArrayModifiers= delegateVisitor.shouldVisitArrayModifiers;
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue