1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

AST representation for member-initializers and function try block, bug 237253.

This commit is contained in:
Markus Schorn 2008-08-04 13:41:50 +00:00
parent b4159f688a
commit 58dced96be
38 changed files with 703 additions and 598 deletions

View file

@ -55,8 +55,10 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
@ -554,8 +556,12 @@ public class DOMLocationTests extends AST2BaseTest {
buffer.append( "};\n"); //$NON-NLS-1$ buffer.append( "};\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
ICPPASTFunctionDeclarator funC = (ICPPASTFunctionDeclarator)((IASTFunctionDefinition)((ICPPASTCompositeTypeSpecifier)((IASTSimpleDeclaration)tu.getDeclarations()[2]).getDeclSpecifier()).getMembers()[1]).getDeclarator(); final ICPPASTCompositeTypeSpecifier ct= getCompositeType(tu, 2);
assertSoleLocation( funC, buffer.toString().indexOf("C() : c(0)"), "C() : c(0)".length() ); //$NON-NLS-1$//$NON-NLS-2$ final ICPPASTFunctionDefinition fdef = getDeclaration(ct, 1);
ICPPASTFunctionDeclarator funC = (ICPPASTFunctionDeclarator) fdef.getDeclarator();
assertSoleLocation( funC, buffer.toString().indexOf("C()"), "C()".length() ); //$NON-NLS-1$//$NON-NLS-2$
ICPPASTConstructorChainInitializer memInit= fdef.getMemberInitializers()[0];
assertSoleLocation( memInit, buffer.toString().indexOf("c(0)"), "c(0)".length() ); //$NON-NLS-1$//$NON-NLS-2$
} }
public void testBug86698_2() throws Exception { public void testBug86698_2() throws Exception {
@ -574,10 +580,13 @@ public class DOMLocationTests extends AST2BaseTest {
buffer.append( "catch (...)\n"); //$NON-NLS-1$ buffer.append( "catch (...)\n"); //$NON-NLS-1$
buffer.append( "{\n }\n"); //$NON-NLS-1$ buffer.append( "{\n }\n"); //$NON-NLS-1$
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); final String code = buffer.toString();
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
final IASTFunctionDefinition fdef = (IASTFunctionDefinition)tu.getDeclarations()[2]; final IASTFunctionDefinition fdef = (IASTFunctionDefinition)tu.getDeclarations()[2];
ICPPASTFunctionTryBlockDeclarator funC = (ICPPASTFunctionTryBlockDeclarator)fdef.getDeclarator(); assertInstance(fdef, ICPPASTFunctionWithTryBlock.class);
assertSoleLocation( funC, buffer.toString().indexOf("C::C(int ii, double id)\ntry\n: i(f(ii)), d(id)"), "C::C(int ii, double id)\ntry\n: i(f(ii)), d(id)".length() ); //$NON-NLS-1$//$NON-NLS-2$ assertSoleLocation(fdef.getDeclarator(), code.indexOf("C::C(int ii, double id)"), "C::C(int ii, double id)".length() ); //$NON-NLS-1$//$NON-NLS-2$
ICPPASTFunctionWithTryBlock tryblock= ((ICPPASTFunctionWithTryBlock) fdef);
assertSoleLocation(tryblock.getCatchHandlers()[0], code.indexOf("catch"), "catch (...)\n{\n }".length());
} }
public void testBug157009_1() throws Exception { public void testBug157009_1() throws Exception {

View file

@ -13,12 +13,12 @@ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest; import org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.ChangeGeneratorTest;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTConstructorChainInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
@ -45,17 +45,17 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest {
final ASTModificationStore modStore) { final ASTModificationStore modStore) {
return new CPPASTVisitor() { return new CPPASTVisitor() {
{ {
shouldVisitDeclarators = true; shouldVisitDeclarations = true;
} }
@Override @Override
public int visit(IASTDeclarator declarator) { public int visit(IASTDeclaration decl) {
if (declarator instanceof CPPASTFunctionDeclarator) { if (decl instanceof CPPASTFunctionDefinition) {
CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition)decl;
CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$ CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$
CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$
ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr); ICPPASTConstructorChainInitializer newInitializer = new CPPASTConstructorChainInitializer(initName, initExpr);
ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, functionDeclarator, newInitializer, null); ASTModification modification = new ASTModification(ModificationKind.APPEND_CHILD, fdef, newInitializer, null);
modStore.storeModification(null, modification); modStore.storeModification(null, modification);
} }

View file

@ -48,7 +48,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
@ -305,9 +304,6 @@ public class ASTStringUtil {
appendTypeIdString(buffer, exceptionTypeIds[i]); appendTypeIdString(buffer, exceptionTypeIds[i]);
} }
} }
if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) {
assert false : "TODO: handle "+ declarator.getClass().getName(); //$NON-NLS-1$
}
} }
} else if (declarator instanceof IASTFieldDeclarator) { } else if (declarator instanceof IASTFieldDeclarator) {
final IASTFieldDeclarator fieldDeclarator= (IASTFieldDeclarator)declarator; final IASTFieldDeclarator fieldDeclarator= (IASTFieldDeclarator)declarator;

View file

@ -1,25 +1,30 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
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.IASTNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
import org.eclipse.cdt.core.dom.ast.IASTNode;
/** /**
* @author jcamelon * <pre> class X {
* int a;
* X();
* };
* X::X : a(0) {} // a(0) is a constructor chain initializer.
*/ */
public interface ICPPASTConstructorChainInitializer extends IASTNode, IASTNameOwner { public interface ICPPASTConstructorChainInitializer extends IASTInitializer, IASTNameOwner {
/** /**
* Constant. * Constant.
*/ */

View file

@ -1,12 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
@ -17,40 +18,9 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId;
/** /**
* C++ adds a few things to function declarators. * C++ adds a few things to function declarators.
* *
* @author Doug Schaefer * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface ICPPASTFunctionDeclarator extends public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarator {
IASTStandardFunctionDeclarator {
/**
* Is this a const method?
*
* @return boolean
*/
public boolean isConst();
/**
* Set the method to be const or not.
*
* @param value
* boolean
*/
public void setConst(boolean value);
/**
* Is this a volatile method?
*
* @return boolean
*/
public boolean isVolatile();
/**
* Set the method to be volatile or not.
*
* @param value
* boolean
*/
public void setVolatile(boolean value);
/** /**
* <code>EXCEPTION_TYPEID</code> represents the type IDs throws in the * <code>EXCEPTION_TYPEID</code> represents the type IDs throws in the
@ -59,63 +29,63 @@ public interface ICPPASTFunctionDeclarator extends
public static final ASTNodeProperty EXCEPTION_TYPEID = new ASTNodeProperty( public static final ASTNodeProperty EXCEPTION_TYPEID = new ASTNodeProperty(
"ICPPASTFunctionDeclarator.EXCEPTION_TYPEID - TypeId throws in the exception specification"); //$NON-NLS-1$ "ICPPASTFunctionDeclarator.EXCEPTION_TYPEID - TypeId throws in the exception specification"); //$NON-NLS-1$
/**
* Is this a const method?
*/
public boolean isConst();
/**
* Set the method to be const or not.
*/
public void setConst(boolean value);
/**
* Is this a volatile method?
*/
public boolean isVolatile();
/**
* Set the method to be volatile or not.
*/
public void setVolatile(boolean value);
/**
* Is the method pure virtual?
*/
public boolean isPureVirtual();
/**
* Set this method to be pure virtual.
*/
public void setPureVirtual(boolean isPureVirtual);
/** /**
* Get the exception specification. * Get the exception specification.
*
* @return <code>IASTTypeId []</code>
*/ */
public IASTTypeId[] getExceptionSpecification(); public IASTTypeId[] getExceptionSpecification();
/** /**
* Add an exception specification type Id. * Add an exception specification type Id.
*
* @param typeId
* <code>IASTTypeId</code>
*/ */
public void addExceptionSpecificationTypeId(IASTTypeId typeId); public void addExceptionSpecificationTypeId(IASTTypeId typeId);
/** /**
* Is the method pure virtual? * Get function scope this node represents. Returns <code>null</code>, if this declarator does not
* * declare a function-prototype or function-definition.
* @return boolean
*/ */
public boolean isPureVirtual(); public ICPPFunctionScope getFunctionScope();
/**
* Set thid method to be pure virtual.
*
* @param isPureVirtual
* boolean
*/
public void setPureVirtual(boolean isPureVirtual);
/** @Deprecated
* <code>CONSTRUCTOR_CHAIN_MEMBER</code> is the role of a constructor
* chain initializer.
*/
public static final ASTNodeProperty CONSTRUCTOR_CHAIN_MEMBER = new ASTNodeProperty( public static final ASTNodeProperty CONSTRUCTOR_CHAIN_MEMBER = new ASTNodeProperty(
"ICPPASTFunctionDeclarator.CONSTRUCTOR_CHAIN_MEMBER - Role of a Constructor Chain Initializer"); //$NON-NLS-1$ "ICPPASTFunctionDeclarator.CONSTRUCTOR_CHAIN_MEMBER - Role of a Constructor Chain Initializer"); //$NON-NLS-1$
/** /**
* Get constructor chain. * @deprecated use {@link ICPPASTFunctionDefinition#getMemberInitializers}, instead.
*
* @return <code>ICPPASTConstructorChainInitializer[]</code>
*/ */
@Deprecated
public ICPPASTConstructorChainInitializer[] getConstructorChain(); public ICPPASTConstructorChainInitializer[] getConstructorChain();
/** @Deprecated
* Add a constructor chain initializer to constructor chain. public void addConstructorToChain(ICPPASTConstructorChainInitializer initializer);
*
* @param initializer
* ICPPASTConstructorChainInitializer
*/
public void addConstructorToChain(
ICPPASTConstructorChainInitializer initializer);
/**
* Get function scope this node represents.
*
* @return ICPPFunctionScope scope
*/
public ICPPFunctionScope getFunctionScope();
} }

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2008 Wind River Systems, Inc. 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:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
/**
* In c++ the a function definition for a constructor may contain member initializers.
* @since 5.1
*
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPASTFunctionDefinition extends IASTFunctionDefinition {
/**
* <code>MEMBER_INITIALIZER</code> is the role of a member initializer in the function definition.
*/
@SuppressWarnings("nls")
public static final ASTNodeProperty MEMBER_INITIALIZER = new ASTNodeProperty(
"ICPPASTFunctionDefinition.MEMBER_INITIALIZER - Role of a member initializer");
/**
* Returns the array of associated member initializers.
*/
public ICPPASTConstructorChainInitializer[] getMemberInitializers();
/**
* Adds a member initializer to this function definition.
*/
public void addMemberInitializer(ICPPASTConstructorChainInitializer initializer);
}

View file

@ -1,22 +1,22 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 IBM Corporation and others. * Copyright (c) 2004, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp; package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
/** /**
* This is a function try block declarator. * @deprecated, use {@link ICPPASTFunctionWithTryBlock}, instead.
*
* @author jcamelon
*/ */
@Deprecated
public interface ICPPASTFunctionTryBlockDeclarator extends public interface ICPPASTFunctionTryBlockDeclarator extends
ICPPASTFunctionDeclarator { ICPPASTFunctionDeclarator {

View file

@ -0,0 +1,43 @@
/*******************************************************************************
* Copyright (c) 2008 Wind River Systems, Inc. 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:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast.cpp;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
/**
* Models a function defined with a try block, which is a function definition:
* <pre> void func() try {
* } catch (...) {
* }
* @since 5.1
*
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ICPPASTFunctionWithTryBlock extends ICPPASTFunctionDefinition {
/**
* A <code>CATCH_HANDLER</code> is the role of an ICPPASTCatchHandler in
* this interface.
*/
public static final ASTNodeProperty CATCH_HANDLER = new ASTNodeProperty(
"ICPPASTFunctionWithTryBlock.CATCH_HANDLER - role of an ICPPASTCatchHandler"); //$NON-NLS-1$
/**
* Adds a catch handler.
*/
public void addCatchHandler(ICPPASTCatchHandler statement);
/**
* Returns an array of catch handlers.
*/
public ICPPASTCatchHandler[] getCatchHandlers();
}

View file

@ -96,6 +96,15 @@ public class ArrayUtil {
return temp; return temp;
} }
/**
* Type safe version of {@link #append(Class, Object[], int, Object)}
* @since 5.1
*/
@SuppressWarnings("unchecked")
static public <T> T[] appendAt(Class<T> c, T[] array, int currentLength, T obj) {
return (T[]) append(c, array, currentLength, obj);
}
static public Object [] append( Object[] array, Object obj ){ static public Object [] append( Object[] array, Object obj ){
return append( Object.class, array, obj ); return append( Object.class, array, obj );
} }
@ -273,7 +282,6 @@ public class ArrayUtil {
* all of the non-null elements in the array are grouped together at the beginning of the array * all of the non-null elements in the array are grouped together at the beginning of the array
* and all of the nulls are at the end of the array. * and all of the nulls are at the end of the array.
* The position of the last non-null element in the array must also be known. * The position of the last non-null element in the array must also be known.
*
*/ */
public static Object[] removeNullsAfter(Class<?> c, Object[] array, int index) { public static Object[] removeNullsAfter(Class<?> c, Object[] array, int index) {
if( array == null || index < 0) if( array == null || index < 0)
@ -288,6 +296,14 @@ public class ArrayUtil {
return newArray; return newArray;
} }
/**
* Type safe version of {@link #removeNullsAfter(Class, Object[], int)}
* @since 5.1
*/
@SuppressWarnings("unchecked")
public static <T> T[] trimAt(Class<T> c, T[] array, int index) {
return (T[]) removeNullsAfter(c, array, index);
}
/** /**
* Insert the obj at the beginning of the array, shifting the whole thing one index * Insert the obj at the beginning of the array, shifting the whole thing one index

View file

@ -10,7 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser; package org.eclipse.cdt.internal.core.dom.parser;
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.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;
@ -29,10 +28,6 @@ import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor; import org.eclipse.cdt.core.dom.ast.c.ICASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
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.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
@ -50,6 +45,7 @@ public class FindNodeForOffsetAction extends CPPASTVisitor implements ICASTVisit
shouldVisitNames = true; shouldVisitNames = true;
shouldVisitDeclarations= true; shouldVisitDeclarations= true;
shouldVisitArrayModifiers=
shouldVisitInitializers= shouldVisitInitializers=
shouldVisitParameterDeclarations= shouldVisitParameterDeclarations=
shouldVisitDeclarators= shouldVisitDeclarators=
@ -95,28 +91,15 @@ public class FindNodeForOffsetAction extends CPPASTVisitor implements ICASTVisit
for (int i = 0; i < ops.length; i++) for (int i = 0; i < ops.length; i++)
processNode(ops[i]); processNode(ops[i]);
if (declarator instanceof IASTArrayDeclarator) {
IASTArrayModifier[] mods = ((IASTArrayDeclarator) declarator)
.getArrayModifiers();
for (int i = 0; i < mods.length; i++)
processNode(mods[i]);
}
else if (declarator instanceof ICPPASTFunctionDeclarator) {
ICPPASTConstructorChainInitializer[] chainInit = ((ICPPASTFunctionDeclarator)declarator).getConstructorChain();
for(int i=0; i<chainInit.length; i++) {
processNode(chainInit[i]);
}
if( declarator instanceof ICPPASTFunctionTryBlockDeclarator ){
ICPPASTCatchHandler [] catchHandlers = ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers();
for( int i = 0; i < catchHandlers.length; i++ ){
processNode(catchHandlers[i]);
}
}
}
return ret; return ret;
} }
@Override
public int visit(IASTArrayModifier arrayModifier) {
return processNode(arrayModifier);
}
@Override @Override
public int visit(IASTDeclSpecifier declSpec) { public int visit(IASTDeclSpecifier declSpec) {
return processNode(declSpec); return processNode(declSpec);

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -53,13 +53,12 @@ public class CASTArrayDeclarator extends CASTDeclarator implements IASTArrayDecl
} }
@Override @Override
protected boolean postAccept( ASTVisitor action ){ protected boolean postAccept(ASTVisitor action) {
IASTArrayModifier [] mods = getArrayModifiers(); IASTArrayModifier[] mods = getArrayModifiers();
for ( int i = 0; i < mods.length; i++ ) { for (int i = 0; i < mods.length; i++) {
if( !mods[i].accept( action ) ) return false; if (!mods[i].accept(action))
} return false;
IASTInitializer initializer = getInitializer(); }
if( initializer != null ) if( !initializer.accept( action ) ) return false; return super.postAccept(action);
return true; }
}
} }

View file

@ -47,23 +47,18 @@ public class CASTArrayModifier extends CASTNode implements IASTArrayModifier, IA
@Override @Override
public boolean accept(ASTVisitor action) { public boolean accept(ASTVisitor action) {
if (exp != null) { if( action.shouldVisitArrayModifiers ){
if( action.shouldVisitArrayModifiers ){ switch( action.visit( this ) ){
switch( action.visit( this ) ){ case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_SKIP : return true;
case ASTVisitor.PROCESS_SKIP : return true; default : break;
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;
}
} }
}
if (exp != null && !exp.accept(action))
return false;
if (action.shouldVisitArrayModifiers && action.leave(this) == ASTVisitor.PROCESS_ABORT) {
return false;
} }
return true; return true;
} }

View file

@ -135,20 +135,20 @@ public class CASTDeclarator extends CASTNode implements IASTDeclarator, IASTAmbi
if( !ptrOps[i].accept( action ) ) return false; if( !ptrOps[i].accept( action ) ) return false;
} }
if( action.shouldVisitDeclarators ){ if (!postAccept(action))
switch( action.leave( this ) ){ return false;
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
return postAccept( action ); if (action.shouldVisitDeclarators && action.leave(this) == ASTVisitor.PROCESS_ABORT) {
return false;
}
return true;
} }
protected boolean postAccept( ASTVisitor action ){ protected boolean postAccept( ASTVisitor action ){
if( initializer != null ) if( !initializer.accept( action ) ) return false; if (initializer != null && !initializer.accept(action))
return true; return false;
return true;
} }
public int getRoleForName(IASTName n ) { public int getRoleForName(IASTName n ) {

View file

@ -14,7 +14,6 @@ package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
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;
@ -46,13 +45,12 @@ public class CASTFieldDeclarator extends CASTDeclarator implements IASTFieldDecl
} }
@Override @Override
protected boolean postAccept( ASTVisitor action ){ protected boolean postAccept(ASTVisitor action) {
if( bitFieldSize != null ) if( !bitFieldSize.accept( action ) ) return false; if (bitFieldSize != null && !bitFieldSize.accept(action))
return false;
IASTInitializer initializer = getInitializer(); return super.postAccept(action);
if( initializer != null ) if( !initializer.accept( action ) ) return false; }
return true;
}
@Override @Override
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {

View file

@ -57,13 +57,14 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
} }
@Override @Override
protected boolean postAccept( ASTVisitor action ){ protected boolean postAccept(ASTVisitor action) {
IASTParameterDeclaration [] params = getParameters(); IASTParameterDeclaration[] params = getParameters();
for ( int i = 0; i < params.length; i++ ) { for (int i = 0; i < params.length; i++) {
if( !params[i].accept( action ) ) return false; if (!params[i].accept(action))
} return false;
return true; }
} return super.postAccept(action);
}
@Override @Override
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {

View file

@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -72,19 +73,21 @@ public class CASTKnRFunctionDeclarator extends CASTDeclarator implements ICASTKn
} }
@Override @Override
protected boolean postAccept( ASTVisitor action ){ protected boolean postAccept(ASTVisitor action) {
IASTName [] ns = getParameterNames(); IASTName[] ns = getParameterNames();
for ( int i = 0; i < ns.length; i++ ) { for (int i = 0; i < ns.length; i++) {
if( !ns[i].accept( action ) ) return false; if (!ns[i].accept(action))
} return false;
}
IASTDeclaration [] params = getParameterDeclarations(); IASTDeclaration[] params = getParameterDeclarations();
for ( int i = 0; i < params.length; i++ ) { for (int i = 0; i < params.length; i++) {
if( !params[i].accept( action ) ) return false; if (!params[i].accept(action))
} return false;
}
return true; return super.postAccept(action);
} }
public IASTDeclarator getDeclaratorForParameterName(IASTName name) { public IASTDeclarator getDeclaratorForParameterName(IASTName name) {
boolean found=false; boolean found=false;

View file

@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -54,13 +55,12 @@ public class CPPASTArrayDeclarator extends CPPASTDeclarator implements
} }
@Override @Override
protected boolean postAccept( ASTVisitor action ){ protected boolean postAccept(ASTVisitor action) {
IASTArrayModifier [] mods = getArrayModifiers(); IASTArrayModifier[] mods = getArrayModifiers();
for ( int i = 0; i < mods.length; i++ ) { for (int i = 0; i < mods.length; i++) {
if( !mods[i].accept( action ) ) return false; if (!mods[i].accept(action))
} return false;
IASTInitializer initializer = getInitializer(); }
if( initializer != null ) if( !initializer.accept( action ) ) return false; return super.postAccept(action);
return true; }
}
} }

View file

@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -62,12 +63,25 @@ public class CPPASTConstructorChainInitializer extends CPPASTNode implements
@Override @Override
public boolean accept(ASTVisitor action) { public boolean accept(ASTVisitor action) {
if (action.shouldVisitInitializers) {
switch(action.visit(this)) {
case ASTVisitor.PROCESS_ABORT:
return false;
case ASTVisitor.PROCESS_SKIP:
return true;
}
}
if (name != null) if (name != null)
if (!name.accept(action)) if (!name.accept(action))
return false; return false;
if (value != null) if (value != null)
if (!value.accept(action)) if (!value.accept(action))
return false; return false;
if (action.shouldVisitInitializers) {
if (action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
}
return true; return true;
} }

View file

@ -130,19 +130,17 @@ public class CPPASTDeclarator extends CPPASTNode implements IASTDeclarator {
if (!postAccept(action)) if (!postAccept(action))
return false; return false;
if( action.shouldVisitDeclarators ){ if (action.shouldVisitDeclarators && action.leave(this) == ASTVisitor.PROCESS_ABORT)
switch( action.leave( this ) ){ return false;
case ASTVisitor.PROCESS_ABORT : return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break;
}
}
return true; return true;
} }
protected boolean postAccept( ASTVisitor action ){ protected boolean postAccept(ASTVisitor action) {
if( initializer != null ) if( !initializer.accept( action ) ) return false; if (initializer != null && !initializer.accept(action))
return true; return false;
return true;
} }

View file

@ -6,14 +6,14 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * 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; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
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.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
@ -48,13 +48,12 @@ public class CPPASTFieldDeclarator extends CPPASTDeclarator implements
} }
@Override @Override
protected boolean postAccept( ASTVisitor action ){ protected boolean postAccept(ASTVisitor action) {
if( bitField != null ) if( !bitField.accept( action ) ) return false; if (bitField != null && !bitField.accept(action))
return false;
IASTInitializer initializer = getInitializer(); return super.postAccept(action);
if( initializer != null ) if( !initializer.accept( action ) ) return false; }
return true;
}
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( child == bitField ) if( child == bitField )

View file

@ -13,32 +13,31 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
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.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/** /**
* @author jcamelon * Represents a function declarator.
*/ */
public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPASTFunctionDeclarator { public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPASTFunctionDeclarator {
private IASTParameterDeclaration[] parameters = null; private IASTParameterDeclaration[] parameters = null;
private int parametersPos = -1; private int parametersPos = -1;
private ICPPFunctionScope scope = null; private IASTTypeId[] typeIds = null;
private int typeIdsPos = -1;
private boolean varArgs; private boolean varArgs;
private boolean pureVirtual; private boolean pureVirtual;
private boolean isVolatile; private boolean isVolatile;
private boolean isConst; private boolean isConst;
private IASTTypeId[] typeIds = null;
private int typeIdsPos = -1; private ICPPFunctionScope scope = null;
private ICPPASTConstructorChainInitializer[] constructorChain = null;
private int constructorChainPos = -1;
public CPPASTFunctionDeclarator() { public CPPASTFunctionDeclarator() {
} }
@ -48,9 +47,10 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
} }
public IASTParameterDeclaration[] getParameters() { public IASTParameterDeclaration[] getParameters() {
if (parameters == null) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY; if (parameters == null)
parameters = (IASTParameterDeclaration[]) ArrayUtil.removeNullsAfter(IASTParameterDeclaration.class, parameters, parametersPos); return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY;
return parameters;
return parameters= ArrayUtil.trimAt(IASTParameterDeclaration.class, parameters, parametersPos);
} }
public void addParameterDeclaration(IASTParameterDeclaration parameter) { public void addParameterDeclaration(IASTParameterDeclaration parameter) {
@ -86,9 +86,10 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
} }
public IASTTypeId[] getExceptionSpecification() { public IASTTypeId[] getExceptionSpecification() {
if (typeIds == null) return IASTTypeId.EMPTY_TYPEID_ARRAY; if (typeIds == null)
typeIds = (IASTTypeId[]) ArrayUtil.removeNullsAfter(IASTTypeId.class, typeIds, typeIdsPos); return IASTTypeId.EMPTY_TYPEID_ARRAY;
return typeIds;
return typeIds= ArrayUtil.trimAt(IASTTypeId.class, typeIds, typeIdsPos);
} }
public void addExceptionSpecificationTypeId(IASTTypeId typeId) { public void addExceptionSpecificationTypeId(IASTTypeId typeId) {
@ -107,20 +108,24 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
this.pureVirtual = isPureVirtual; this.pureVirtual = isPureVirtual;
} }
public ICPPASTConstructorChainInitializer[] getConstructorChain() { @Deprecated
if (constructorChain == null) return ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY; public org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer[] getConstructorChain() {
constructorChain = (ICPPASTConstructorChainInitializer[]) ArrayUtil.removeNullsAfter( if (CPPVisitor.findTypeRelevantDeclarator(this) == this) {
ICPPASTConstructorChainInitializer.class, constructorChain, constructorChainPos); IASTNode parent= getParent();
return constructorChain; while(!(parent instanceof IASTDeclaration)) {
if (parent == null)
break;
parent= parent.getParent();
}
if (parent instanceof ICPPASTFunctionDefinition) {
return ((ICPPASTFunctionDefinition) parent).getMemberInitializers();
}
}
return org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY;
} }
public void addConstructorToChain(ICPPASTConstructorChainInitializer initializer) { @Deprecated
if (initializer != null) { public void addConstructorToChain(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer initializer) {
constructorChain = (ICPPASTConstructorChainInitializer[]) ArrayUtil.append(
ICPPASTConstructorChainInitializer.class, constructorChain, ++constructorChainPos, initializer);
initializer.setParent(this);
initializer.setPropertyInParent(CONSTRUCTOR_CHAIN_MEMBER);
}
} }
public ICPPFunctionScope getFunctionScope() { public ICPPFunctionScope getFunctionScope() {
@ -145,24 +150,18 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
@Override @Override
protected boolean postAccept(ASTVisitor action) { protected boolean postAccept(ASTVisitor action) {
IASTParameterDeclaration[] params = getParameters(); IASTParameterDeclaration[] params = getParameters();
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
if (!params[i].accept(action)) return false; if (!params[i].accept(action))
} return false;
}
IASTTypeId[] ids = getExceptionSpecification(); IASTTypeId[] ids = getExceptionSpecification();
for (int i = 0; i < ids.length; i++) { for (int i = 0; i < ids.length; i++) {
if (!ids[i].accept(action)) return false; if (!ids[i].accept(action))
} return false;
}
IASTInitializer initializer = getInitializer(); return super.postAccept(action);
if (initializer != null && !initializer.accept(action)) return false; }
ICPPASTConstructorChainInitializer[] chain = getConstructorChain();
for (int i = 0; i < chain.length; i++) {
if (!chain[i].accept(action)) return false;
}
return true;
}
} }

View file

@ -15,23 +15,29 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IScope; import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/** /**
* @author jcamelon * Models a function definition without a try-block. If used for a constructor definition it may contain
* member initializers.
*/ */
public class CPPASTFunctionDefinition extends CPPASTNode implements public class CPPASTFunctionDefinition extends CPPASTNode implements
IASTFunctionDefinition, IASTAmbiguityParent { ICPPASTFunctionDefinition, IASTAmbiguityParent {
private IASTDeclSpecifier declSpecifier; private IASTDeclSpecifier declSpecifier;
private IASTFunctionDeclarator declarator; private IASTFunctionDeclarator declarator;
private IASTStatement bodyStatement; private IASTStatement bodyStatement;
private ICPPASTConstructorChainInitializer[] memInits = null;
private int memInitPos= -1;
public CPPASTFunctionDefinition() { public CPPASTFunctionDefinition() {
} }
@ -80,36 +86,73 @@ public class CPPASTFunctionDefinition extends CPPASTNode implements
} }
} }
public void addMemberInitializer(ICPPASTConstructorChainInitializer initializer) {
if (initializer != null) {
memInits= ArrayUtil.appendAt(ICPPASTConstructorChainInitializer.class, memInits, ++memInitPos, initializer);
initializer.setParent(this);
initializer.setPropertyInParent(MEMBER_INITIALIZER);
}
}
public ICPPASTConstructorChainInitializer[] getMemberInitializers() {
if (memInits == null)
return ICPPASTConstructorChainInitializer.EMPTY_CONSTRUCTORCHAININITIALIZER_ARRAY;
return memInits= ArrayUtil.trimAt(
ICPPASTConstructorChainInitializer.class, memInits, memInitPos);
}
public IScope getScope() { public IScope getScope() {
return ((ICPPASTFunctionDeclarator)declarator).getFunctionScope(); return ((ICPPASTFunctionDeclarator)declarator).getFunctionScope();
} }
@Override @Override
public boolean accept( ASTVisitor action ){ public boolean accept(ASTVisitor action) {
if( action.shouldVisitDeclarations ){ if (action.shouldVisitDeclarations) {
switch( action.visit( this ) ){ switch (action.visit(this)) {
case ASTVisitor.PROCESS_ABORT : return false; case ASTVisitor.PROCESS_ABORT:
case ASTVisitor.PROCESS_SKIP : return true; return false;
default : break; case ASTVisitor.PROCESS_SKIP:
} return true;
default:
break;
}
} }
if( declSpecifier != null ) if( !declSpecifier.accept( action ) ) return false; if (declSpecifier != null && !declSpecifier.accept(action))
final IASTDeclarator outerDtor= CPPVisitor.findOutermostDeclarator(declarator); return false;
if( outerDtor != null ) if( !outerDtor.accept( action ) ) return false;
if( bodyStatement != null ) if( !bodyStatement.accept( action ) ) return false;
if( action.shouldVisitDeclarations ){ final IASTDeclarator outerDtor = CPPVisitor.findOutermostDeclarator(declarator);
switch( action.leave( this ) ){ if (outerDtor != null && !outerDtor.accept(action))
case ASTVisitor.PROCESS_ABORT : return false; return false;
case ASTVisitor.PROCESS_SKIP : return true;
default : break; final ICPPASTConstructorChainInitializer[] chain = getMemberInitializers();
} for (ICPPASTConstructorChainInitializer memInit : chain) {
if (!memInit.accept(action))
return false;
} }
return true;
}
public void replace(IASTNode child, IASTNode other) { if (bodyStatement != null && !bodyStatement.accept(action))
return false;
if (!acceptCatchHandlers(action))
return false;
if (action.shouldVisitDeclarations && action.leave(this) == ASTVisitor.PROCESS_ABORT)
return false;
return true;
}
/**
* Allows subclasses to visit catch handlers, returns whether the visit should continue.
*/
protected boolean acceptCatchHandlers(ASTVisitor action) {
return true;
}
public void replace(IASTNode child, IASTNode other) {
if( bodyStatement == child ) if( bodyStatement == child )
{ {
other.setPropertyInParent( bodyStatement.getPropertyInParent() ); other.setPropertyInParent( bodyStatement.getPropertyInParent() );

View file

@ -1,34 +1,35 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2008 IBM Corporation and others. * Copyright (c) 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
/** /**
* @author jcamelon * Represents a function definition contained in a try block.
* @see ICPPASTFunctionWithTryBlock
*/ */
public class CPPASTFunctionTryBlockDeclarator extends CPPASTFunctionDeclarator public class CPPASTFunctionWithTryBlock extends CPPASTFunctionDefinition implements ICPPASTFunctionWithTryBlock {
implements ICPPASTFunctionTryBlockDeclarator {
public CPPASTFunctionWithTryBlock() {
public CPPASTFunctionTryBlockDeclarator() {
} }
public CPPASTFunctionTryBlockDeclarator(IASTName name) { public CPPASTFunctionWithTryBlock(IASTDeclSpecifier declSpecifier,
super(name); IASTFunctionDeclarator declarator, IASTStatement bodyStatement) {
super(declSpecifier, declarator, bodyStatement);
} }
public void addCatchHandler(ICPPASTCatchHandler statement) { public void addCatchHandler(ICPPASTCatchHandler statement) {
@ -48,15 +49,14 @@ public class CPPASTFunctionTryBlockDeclarator extends CPPASTFunctionDeclarator
private ICPPASTCatchHandler [] catchHandlers = null; private ICPPASTCatchHandler [] catchHandlers = null;
private int catchHandlersPos=-1; private int catchHandlersPos=-1;
@Override
protected boolean postAccept( ASTVisitor action ){
if( !super.postAccept( action ) ) return false;
ICPPASTCatchHandler [] handlers = getCatchHandlers(); @Override
for ( int i = 0; i < handlers.length; i++ ) { protected boolean acceptCatchHandlers( ASTVisitor action ){
if( !handlers[i].accept( action ) ) return false; final ICPPASTCatchHandler [] handlers = getCatchHandlers();
for (int i=0; i<handlers.length; i++) {
if (!handlers[i].accept(action))
return false;
} }
return true; return true;
} }
} }

View file

@ -46,7 +46,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFieldDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement; import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer; import org.eclipse.cdt.core.dom.ast.IASTInitializer;
@ -94,7 +93,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTIfStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
@ -171,7 +171,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
private static final int DEFAULT_PARM_LIST_SIZE = 4; private static final int DEFAULT_PARM_LIST_SIZE = 4;
private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4; private static final int DEFAULT_POINTEROPS_LIST_SIZE = 4;
private static final int DEFAULT_SIZE_EXCEPTIONS_LIST = 2; private static final int DEFAULT_SIZE_EXCEPTIONS_LIST = 2;
private static final int DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE = 4;
private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE= 4; private static final int DEFAULT_CATCH_HANDLER_LIST_SIZE= 4;
private static final int DEFAULT_PARAMETER_LIST_SIZE= 4; private static final int DEFAULT_PARAMETER_LIST_SIZE= 4;
private static final ASTVisitor EMPTY_VISITOR = new ASTVisitor() {}; private static final ASTVisitor EMPTY_VISITOR = new ASTVisitor() {};
@ -2313,11 +2312,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
endOffset= consume().getEndOffset(); endOffset= consume().getEndOffset();
break; break;
case IToken.t_try: case IToken.t_try:
consume();
return functionDefinition(firstOffset, declSpec, declarators, true);
case IToken.tCOLON: case IToken.tCOLON:
case IToken.tLBRACE: case IToken.tLBRACE:
return functionDefinition(firstOffset, declSpec, declarators, false); return functionDefinition(firstOffset, declSpec, declarators);
default: default:
if (declOption != DeclarationOptions.LOCAL) { if (declOption != DeclarationOptions.LOCAL) {
insertSemi= true; insertSemi= true;
@ -2372,7 +2369,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
} }
private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec, private IASTDeclaration functionDefinition(final int firstOffset, IASTDeclSpecifier declSpec,
IASTDeclarator[] dtors, boolean hasFunctionTryBlock) throws EndOfFileException, BacktrackException { IASTDeclarator[] dtors) throws EndOfFileException, BacktrackException {
if (dtors.length != 1) if (dtors.length != 1)
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
@ -2382,64 +2379,59 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (dtor instanceof ICPPASTFunctionDeclarator == false) if (dtor instanceof ICPPASTFunctionDeclarator == false)
throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset); throwBacktrack(firstOffset, LA(1).getEndOffset() - firstOffset);
final ICPPASTFunctionDeclarator fdtor= (ICPPASTFunctionDeclarator) dtor;
ICPPASTFunctionDefinition fdef;
if (LT(1) == IToken.t_try) {
consume();
fdef= createFunctionTryBlock();
} else {
fdef= createFunctionDefinition();
}
fdef.setDeclSpecifier(declSpec);
fdef.setDeclarator((ICPPASTFunctionDeclarator) dtor);
if (LT(1) == IToken.tCOLON) { if (LT(1) == IToken.tCOLON) {
List<ICPPASTConstructorChainInitializer> constructorChain= new ArrayList<ICPPASTConstructorChainInitializer>(DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE); ctorInitializer(fdef);
ctorInitializer(constructorChain);
if (!constructorChain.isEmpty()) {
for (ICPPASTConstructorChainInitializer initializer : constructorChain) {
fdtor.addConstructorToChain(initializer);
}
// fix for 86698, update the declarator's length
adjustLength(outerDtor, constructorChain.get(constructorChain.size()-1));
}
} }
IASTStatement body;
try { try {
body= handleFunctionBody(); IASTStatement body= handleFunctionBody();
fdef.setBody(body);
setRange(fdef, firstOffset, calculateEndOffset(body));
} catch (BacktrackException bt) { } catch (BacktrackException bt) {
final IASTNode n= bt.getNodeBeforeProblem(); final IASTNode n= bt.getNodeBeforeProblem();
if (n instanceof IASTCompoundStatement) { if (n instanceof IASTCompoundStatement && !(fdef instanceof ICPPASTFunctionWithTryBlock)) {
IASTFunctionDefinition funcDefinition = createFunctionDefinition(); fdef.setBody((IASTCompoundStatement) n);
funcDefinition.setDeclSpecifier(declSpec); setRange(fdef, firstOffset, calculateEndOffset(n));
funcDefinition.setDeclarator(fdtor); throwBacktrack(bt.getProblem(), fdef);
funcDefinition.setBody((IASTCompoundStatement) n);
((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, calculateEndOffset(n) - firstOffset);
throwBacktrack(bt.getProblem(), funcDefinition);
} }
throw bt; throw bt;
} }
int endOffset= calculateEndOffset(body); if (fdef instanceof ICPPASTFunctionWithTryBlock) {
if (hasFunctionTryBlock) { ICPPASTFunctionWithTryBlock tryblock= (ICPPASTFunctionWithTryBlock) fdef;
List<ICPPASTCatchHandler> handlers = new ArrayList<ICPPASTCatchHandler>(DEFAULT_CATCH_HANDLER_LIST_SIZE); List<ICPPASTCatchHandler> handlers = new ArrayList<ICPPASTCatchHandler>(DEFAULT_CATCH_HANDLER_LIST_SIZE);
catchHandlerSequence(handlers); catchHandlerSequence(handlers);
if (!handlers.isEmpty() && fdtor instanceof ICPPASTFunctionTryBlockDeclarator) { ICPPASTCatchHandler last= null;
ICPPASTFunctionTryBlockDeclarator tbd= (ICPPASTFunctionTryBlockDeclarator) fdtor; for (ICPPASTCatchHandler catchHandler : handlers) {
for (ICPPASTCatchHandler catchHandler : handlers) { tryblock.addCatchHandler(catchHandler);
tbd.addCatchHandler(catchHandler); last= catchHandler;
} }
endOffset= calculateEndOffset(handlers.get(handlers.size()-1)); if (last != null) {
adjustLength(tryblock, last);
} }
} }
return fdef;
IASTFunctionDefinition funcDefinition = createFunctionDefinition();
funcDefinition.setDeclSpecifier(declSpec);
funcDefinition.setDeclarator(fdtor);
funcDefinition.setBody(body);
((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, endOffset-firstOffset);
return funcDefinition;
} }
@Override @Override
protected IASTFunctionDefinition createFunctionDefinition() { protected ICPPASTFunctionDefinition createFunctionDefinition() {
return new CPPASTFunctionDefinition(); return new CPPASTFunctionDefinition();
} }
protected ICPPASTFunctionWithTryBlock createFunctionTryBlock() {
return new CPPASTFunctionWithTryBlock();
}
@Override @Override
protected IASTSimpleDeclaration createSimpleDeclaration() { protected IASTSimpleDeclaration createSimpleDeclaration() {
@ -2455,7 +2447,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
* @throws BacktrackException * @throws BacktrackException
* request a backtrack * request a backtrack
*/ */
protected void ctorInitializer(List<ICPPASTConstructorChainInitializer> collection) throws EndOfFileException, protected void ctorInitializer(ICPPASTFunctionDefinition fdef) throws EndOfFileException,
BacktrackException { BacktrackException {
consume(); consume();
ctorLoop: for (;;) { ctorLoop: for (;;) {
@ -2494,7 +2486,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (expressionList != null) { if (expressionList != null) {
ctorInitializer.setInitializerValue(expressionList); ctorInitializer.setInitializerValue(expressionList);
} }
collection.add(ctorInitializer); fdef.addMemberInitializer(ctorInitializer);
switch (LT(1)) { switch (LT(1)) {
case IToken.tCOMMA: case IToken.tCOMMA:
@ -3477,82 +3469,77 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
// Consume any number of __attribute__ tokens after the parameters // Consume any number of __attribute__ tokens after the parameters
__attribute_decl_seq(supportAttributeSpecifiers, false); __attribute_decl_seq(supportAttributeSpecifiers, false);
boolean isTryCatch= false;
boolean isConst= false; boolean isConst= false;
boolean isVolatile= false; boolean isVolatile= false;
boolean isPureVirtual= false; boolean isPureVirtual= false;
ArrayList<IASTTypeId> exceptionSpecIds= null; ArrayList<IASTTypeId> exceptionSpecIds= null;
if (LT(1) == IToken.t_try) { // cv-qualifiers
isTryCatch= true; cvloop: while(true) {
} else { switch(LT(1)) {
// cv-qualifiers case IToken.t_const:
cvloop: while(true) { isConst= true;
switch(LT(1)) { endOffset= consume().getEndOffset();
case IToken.t_const: break;
isConst= true; case IToken.t_volatile:
endOffset= consume().getEndOffset(); isVolatile= true;
break; endOffset= consume().getEndOffset();
case IToken.t_volatile: break;
isVolatile= true; default:
endOffset= consume().getEndOffset(); break cvloop;
break;
default:
break cvloop;
}
}
// throws clause
if (LT(1) == IToken.t_throw) {
exceptionSpecIds = new ArrayList<IASTTypeId>(DEFAULT_SIZE_EXCEPTIONS_LIST);
consume(); // throw
consume(IToken.tLPAREN);
thloop: while(true) {
switch (LT(1)) {
case IToken.tRPAREN:
case IToken.tEOC:
endOffset= consume().getEndOffset();
break thloop;
case IToken.tCOMMA:
consume();
break;
default:
int thoffset= LA(1).getOffset();
IASTTypeId typeId= typeId(DeclarationOptions.TYPEID);
if (typeId != null) {
exceptionSpecIds.add(typeId);
} else {
int thendoffset= LA(1).getOffset();
if (thoffset == thendoffset) {
thendoffset= consume().getEndOffset();
}
IASTProblem p= createProblem(IProblem.SYNTAX_ERROR, thoffset, thendoffset-thoffset);
IASTProblemTypeId typeIdProblem = createTypeIDProblem();
typeIdProblem.setProblem(p);
((ASTNode) typeIdProblem).setOffsetAndLength(((ASTNode) p));
exceptionSpecIds.add(typeIdProblem);
}
break;
}
}
// more __attribute__ after throws
__attribute_decl_seq(supportAttributeSpecifiers, false);
}
// pure virtual
if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tINTEGER) {
char[] image = LA(2).getCharImage();
if (image.length == 1 && image[0] == '0') {
consume(); // tASSIGN
endOffset= consume().getEndOffset(); // tINTEGER
isPureVirtual= true;
}
} }
} }
final ICPPASTFunctionDeclarator fc= isTryCatch ? createTryBlockDeclarator() : createFunctionDeclarator(); // throws clause
if (LT(1) == IToken.t_throw) {
exceptionSpecIds = new ArrayList<IASTTypeId>(DEFAULT_SIZE_EXCEPTIONS_LIST);
consume(); // throw
consume(IToken.tLPAREN);
thloop: while(true) {
switch (LT(1)) {
case IToken.tRPAREN:
case IToken.tEOC:
endOffset= consume().getEndOffset();
break thloop;
case IToken.tCOMMA:
consume();
break;
default:
int thoffset= LA(1).getOffset();
IASTTypeId typeId= typeId(DeclarationOptions.TYPEID);
if (typeId != null) {
exceptionSpecIds.add(typeId);
} else {
int thendoffset= LA(1).getOffset();
if (thoffset == thendoffset) {
thendoffset= consume().getEndOffset();
}
IASTProblem p= createProblem(IProblem.SYNTAX_ERROR, thoffset, thendoffset-thoffset);
IASTProblemTypeId typeIdProblem = createTypeIDProblem();
typeIdProblem.setProblem(p);
((ASTNode) typeIdProblem).setOffsetAndLength(((ASTNode) p));
exceptionSpecIds.add(typeIdProblem);
}
break;
}
}
// more __attribute__ after throws
__attribute_decl_seq(supportAttributeSpecifiers, false);
}
// pure virtual
if (LT(1) == IToken.tASSIGN && LT(2) == IToken.tINTEGER) {
char[] image = LA(2).getCharImage();
if (image.length == 1 && image[0] == '0') {
consume(); // tASSIGN
endOffset= consume().getEndOffset(); // tINTEGER
isPureVirtual= true;
}
}
final ICPPASTFunctionDeclarator fc= createFunctionDeclarator();
fc.setVarArgs(encounteredVarArgs); fc.setVarArgs(encounteredVarArgs);
fc.setConst(isConst); fc.setConst(isConst);
fc.setVolatile(isVolatile); fc.setVolatile(isVolatile);
@ -3611,12 +3598,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
return new CPPASTProblemTypeId(); return new CPPASTProblemTypeId();
} }
protected ICPPASTFunctionTryBlockDeclarator createTryBlockDeclarator() {
return new CPPASTFunctionTryBlockDeclarator();
}
protected ICPPASTFunctionDeclarator createFunctionDeclarator() { protected ICPPASTFunctionDeclarator createFunctionDeclarator() {
return new CPPASTFunctionDeclarator(); return new CPPASTFunctionDeclarator();
} }
@ -4001,14 +3982,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
} }
collection.add(handler); collection.add(handler);
lt1 = LTcatchEOF(1);
try {
lt1 = LT(1);
} catch (EndOfFileException eofe) {
// if EOF is reached, then return here and let it be encountered elsewhere
// (i.e. try/catch won't be added to the declaration if the exception is thrown here)
return;
}
} }
} }

View file

@ -528,8 +528,8 @@ public class CPPSemantics {
scope = CPPVisitor.getContainingScope(n); scope = CPPVisitor.getContainingScope(n);
} else if (parent instanceof ICPPASTConstructorChainInitializer) { } else if (parent instanceof ICPPASTConstructorChainInitializer) {
ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) parent; ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) parent;
IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) initializer.getParent(); IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent();
IBinding binding = dtor.getName().resolveBinding(); IBinding binding = fdef.getDeclarator().getName().resolveBinding();
if (!(binding instanceof IProblemBinding)) if (!(binding instanceof IProblemBinding))
scope = binding.getScope(); scope = binding.getScope();
} else { } else {

View file

@ -820,7 +820,7 @@ public class CPPVisitor {
} else if (parent instanceof IASTCompoundStatement) { } else if (parent instanceof IASTCompoundStatement) {
return ((IASTCompoundStatement)parent).getScope(); return ((IASTCompoundStatement)parent).getScope();
} else if (parent instanceof ICPPASTConstructorChainInitializer) { } else if (parent instanceof ICPPASTConstructorChainInitializer) {
IASTNode temp = getContainingBlockItem(parent.getParent()); IASTNode temp = getContainingBlockItem(parent);
if (temp instanceof IASTFunctionDefinition) { if (temp instanceof IASTFunctionDefinition) {
IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)temp).getBody(); IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)temp).getBody();
return body.getScope(); return body.getScope();

View file

@ -22,8 +22,10 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
@ -34,6 +36,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisibilityLabel;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.gnu.cpp.IGPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@ -281,17 +284,44 @@ public class DeclarationWriter extends NodeWriter{
} }
IASTDeclarator declarator = CPPVisitor.findOutermostDeclarator(funcDef.getDeclarator()); IASTDeclarator declarator = CPPVisitor.findOutermostDeclarator(funcDef.getDeclarator());
declarator.accept(visitor); declarator.accept(visitor);
if (funcDef instanceof ICPPASTFunctionWithTryBlock) {
scribe.newLine();
scribe.print(Keywords.TRY);
}
if (funcDef instanceof ICPPASTFunctionDefinition) {
ICPPASTFunctionDefinition cppFuncDef= (ICPPASTFunctionDefinition) funcDef;
writeCtorChainInitializer(cppFuncDef, cppFuncDef.getMemberInitializers());
}
scribe.newLine(); scribe.newLine();
funcDef.getBody().accept(visitor); funcDef.getBody().accept(visitor);
if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) {
ICPPASTFunctionTryBlockDeclarator tryDeclSpec = (ICPPASTFunctionTryBlockDeclarator) declarator; if (funcDef instanceof ICPPASTFunctionWithTryBlock) {
ICPPASTCatchHandler[] catches = tryDeclSpec.getCatchHandlers(); ICPPASTFunctionWithTryBlock tryblock = (ICPPASTFunctionWithTryBlock) funcDef;
ICPPASTCatchHandler[] catches = tryblock.getCatchHandlers();
for (ICPPASTCatchHandler handler : catches) { for (ICPPASTCatchHandler handler : catches) {
handler.accept(visitor); handler.accept(visitor);
} }
} }
} }
protected void writeCtorChainInitializer(
ICPPASTFunctionDefinition funcDec, ICPPASTConstructorChainInitializer[] ctorInitChain) {
if(ctorInitChain.length != 0) {
scribe.newLine();
scribe.print(':');
}
for(int i = 0; i < ctorInitChain.length; ++i) {
ICPPASTConstructorChainInitializer initializer = ctorInitChain[i];
initializer.accept(visitor);
if(i+1 < ctorInitChain.length) {
scribe.print(COMMA_SPACE);
}
}
}
private void writeSimpleDeclaration(IASTSimpleDeclaration simpDec) { private void writeSimpleDeclaration(IASTSimpleDeclaration simpDec) {
IASTDeclSpecifier declSpecifier = simpDec.getDeclSpecifier(); IASTDeclSpecifier declSpecifier = simpDec.getDeclSpecifier();
IASTDeclarator[] decls = simpDec.getDeclarators(); IASTDeclarator[] decls = simpDec.getDeclarators();

View file

@ -27,10 +27,8 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.c.ICASTPointer; import org.eclipse.cdt.core.dom.ast.c.ICASTPointer;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTPointerToMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
@ -52,7 +50,6 @@ public class DeclaratorWriter extends NodeWriter {
private static final String AMPERSAND_SPACE = "& "; //$NON-NLS-1$ private static final String AMPERSAND_SPACE = "& "; //$NON-NLS-1$
private static final String STAR_SPACE = "* "; //$NON-NLS-1$ private static final String STAR_SPACE = "* "; //$NON-NLS-1$
private static final String TRY = "try"; //$NON-NLS-1$
private static final String PURE_VIRTUAL = " =0"; //$NON-NLS-1$ private static final String PURE_VIRTUAL = " =0"; //$NON-NLS-1$
public DeclaratorWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) { public DeclaratorWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) {
@ -146,29 +143,6 @@ public class DeclaratorWriter extends NodeWriter {
scribe.print(PURE_VIRTUAL); scribe.print(PURE_VIRTUAL);
} }
writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification()); writeExceptionSpecification(funcDec, funcDec.getExceptionSpecification());
if (funcDec instanceof ICPPASTFunctionTryBlockDeclarator) {
scribe.newLine();
scribe.print(TRY);
}
writeCtorChainInitializer(funcDec, funcDec.getConstructorChain());
}
protected void writeCtorChainInitializer(
ICPPASTFunctionDeclarator funcDec, ICPPASTConstructorChainInitializer[] ctorInitChain) {
if(ctorInitChain.length != 0) {
scribe.newLine();
scribe.print(':');
}
for(int i = 0; i < ctorInitChain.length; ++i) {
ICPPASTConstructorChainInitializer initializer = ctorInitChain[i];
initializer.getMemberInitializerId().accept(visitor);
scribe.print('(');
initializer.getInitializerValue().accept(visitor);
scribe.print(')');
if(i+1 < ctorInitChain.length) {
scribe.print(COMMA_SPACE);
}
}
} }
protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions) { protected void writeExceptionSpecification(ICPPASTFunctionDeclarator funcDec, IASTTypeId[] exceptions) {

View file

@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@ -19,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator; 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.c.ICASTFieldDesignator;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator; import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
@ -49,7 +51,19 @@ public class InitializerWriter extends NodeWriter{
writeConstructorInitializer((ICPPASTConstructorInitializer) initializer); writeConstructorInitializer((ICPPASTConstructorInitializer) initializer);
}else if (initializer instanceof ICASTDesignatedInitializer) { }else if (initializer instanceof ICASTDesignatedInitializer) {
writeDesignatedInitializer((ICASTDesignatedInitializer) initializer); writeDesignatedInitializer((ICASTDesignatedInitializer) initializer);
}else if (initializer instanceof ICPPASTConstructorChainInitializer) {
writeConstructorChainInitializer((ICPPASTConstructorChainInitializer) initializer);
} }
if (hasTrailingComments(initializer))
writeTrailingComments(initializer, false);
}
private void writeConstructorChainInitializer(ICPPASTConstructorChainInitializer initializer) {
initializer.getMemberInitializerId().accept(visitor);
scribe.print('(');
initializer.getInitializerValue().accept(visitor);
scribe.print(')');
} }
private void writeInitializerList(IASTInitializerList initList) { private void writeInitializerList(IASTInitializerList initList) {

View file

@ -7,12 +7,15 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclarationWriter; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclarationWriter;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.Scribe;
@ -33,4 +36,10 @@ public class ModifiedASTDeclarationWriter extends DeclarationWriter {
super.writeDeclarationsInNamespace(namespaceDefinition, modifiedDeclarations); super.writeDeclarationsInNamespace(namespaceDefinition, modifiedDeclarations);
} }
@Override
protected void writeCtorChainInitializer(ICPPASTFunctionDefinition funcDec,
ICPPASTConstructorChainInitializer[] ctorInitChain) {
ICPPASTConstructorChainInitializer[] modifiedChainInitializer = modificationHelper.createModifiedChildArray(funcDec, ctorInitChain, ICPPASTConstructorChainInitializer.class);
super.writeCtorChainInitializer(funcDec, modifiedChainInitializer);
}
} }

View file

@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Institute for Software - initial API and implementation * Institute for Software - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator; package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
@ -22,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; 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.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclaratorWriter; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.DeclaratorWriter;
@ -55,14 +55,6 @@ public class ModifiedASTDeclaratorWriter extends DeclaratorWriter {
} }
@Override
protected void writeCtorChainInitializer(ICPPASTFunctionDeclarator funcDec,
ICPPASTConstructorChainInitializer[] ctorInitChain) {
ICPPASTConstructorChainInitializer[] modifiedChainInitializer = modificationHelper.createModifiedChildArray(funcDec, ctorInitChain, ICPPASTConstructorChainInitializer.class);
super.writeCtorChainInitializer(funcDec, modifiedChainInitializer);
}
@Override @Override
protected void writeArrayModifiers(IASTArrayDeclarator arrDecl, protected void writeArrayModifiers(IASTArrayDeclarator arrDecl,
IASTArrayModifier[] arrMods) { IASTArrayModifier[] arrMods) {

View file

@ -105,7 +105,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFieldReference;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
@ -483,9 +484,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.printNextToken(Token.tRPAREN, false); scribe.printNextToken(Token.tRPAREN, false);
} }
if (node instanceof ICPPASTFunctionTryBlockDeclarator) { if (node instanceof ICPPASTFunctionDeclarator) {
visit((ICPPASTFunctionTryBlockDeclarator)node);
} else if (node instanceof ICPPASTFunctionDeclarator) {
return visit((ICPPASTFunctionDeclarator)node); return visit((ICPPASTFunctionDeclarator)node);
} else if (node instanceof IASTStandardFunctionDeclarator) { } else if (node instanceof IASTStandardFunctionDeclarator) {
visit((IASTStandardFunctionDeclarator)node); visit((IASTStandardFunctionDeclarator)node);
@ -994,6 +993,27 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
declarator.accept(this); declarator.accept(this);
// tletodo
if (node instanceof ICPPASTFunctionWithTryBlock) {
scribe.startNewLine();
scribe.printNextToken(Token.t_try, false);
scribe.printTrailingComment();
}
if (node instanceof ICPPASTFunctionDefinition) {
final ICPPASTConstructorChainInitializer[] constructorChain= ((ICPPASTFunctionDefinition) node).getMemberInitializers();
if (constructorChain != null && constructorChain.length > 0) {
// TLETODO [formatter] need special constructor chain alignment
scribe.printNextToken(Token.tCOLON, true);
scribe.printTrailingComment();
scribe.startNewLine();
scribe.indent();
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
formatList(Arrays.asList(constructorChain), align, false, false);
scribe.unIndent();
}
}
// body // body
IASTStatement bodyStmt= node.getBody(); IASTStatement bodyStmt= node.getBody();
if (bodyStmt instanceof IASTCompoundStatement) { if (bodyStmt instanceof IASTCompoundStatement) {
@ -1013,9 +1033,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.printTrailingComment(); scribe.printTrailingComment();
scribe.startNewLine(); scribe.startNewLine();
// hack: catch handlers are part of declarator if (node instanceof ICPPASTFunctionWithTryBlock) {
if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) { ICPPASTCatchHandler[] catchHandlers= ((ICPPASTFunctionWithTryBlock)node).getCatchHandlers();
ICPPASTCatchHandler[] catchHandlers= ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers();
for (int i= 0; i < catchHandlers.length; i++) { for (int i= 0; i < catchHandlers.length; i++) {
catchHandlers[i].accept(this); catchHandlers[i].accept(this);
scribe.printTrailingComment(); scribe.printTrailingComment();
@ -1043,27 +1062,28 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
} }
} }
if (node instanceof ICPPASTFunctionTryBlockDeclarator) { // tletodo
scribe.startNewLine(); // if (node instanceof ICPPASTFunctionTryBlockDeclarator) {
scribe.printNextToken(Token.t_try, false); // scribe.startNewLine();
scribe.printTrailingComment(); // scribe.printNextToken(Token.t_try, false);
// for catch handlers @see #visit(IASTFunctionDefinition) // scribe.printTrailingComment();
} // // for catch handlers @see #visit(IASTFunctionDefinition)
// }
final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain(); //
if (constructorChain != null && constructorChain.length > 0) { // final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain();
// TLETODO [formatter] need special constructor chain alignment // if (constructorChain != null && constructorChain.length > 0) {
scribe.printNextToken(Token.tCOLON, true); // // TLETODO [formatter] need special constructor chain alignment
scribe.printTrailingComment(); // scribe.printNextToken(Token.tCOLON, true);
scribe.startNewLine(); // scribe.printTrailingComment();
scribe.indent(); // scribe.startNewLine();
final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT); // scribe.indent();
formatList(Arrays.asList(constructorChain), align, false, false); // final ListAlignment align= new ListAlignment(Alignment.M_COMPACT_SPLIT);
scribe.unIndent(); // formatList(Arrays.asList(constructorChain), align, false, false);
} else { // scribe.unIndent();
// } else {
// skip the rest (=0) // skip the rest (=0)
skipNode(node); skipNode(node);
} // }
return PROCESS_SKIP; return PROCESS_SKIP;
} }

View file

@ -12,8 +12,6 @@ package org.eclipse.cdt.ui.tests.DOMAST;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
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;
@ -33,10 +31,6 @@ 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.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
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.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
@ -140,6 +134,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
*/ */
@Override
public int visit(IASTDeclaration declaration) { public int visit(IASTDeclaration declaration) {
DOMASTNodeLeaf temp = addRoot(declaration); DOMASTNodeLeaf temp = addRoot(declaration);
if (temp == null) if (temp == null)
@ -153,6 +148,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
*/ */
@Override
public int visit(IASTDeclarator declarator) { public int visit(IASTDeclarator declarator) {
DOMASTNodeLeaf temp = addRoot(declarator); DOMASTNodeLeaf temp = addRoot(declarator);
@ -160,26 +156,6 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
for(int i=0; i<ops.length; i++) for(int i=0; i<ops.length; i++)
addRoot(ops[i]); addRoot(ops[i]);
if (declarator instanceof IASTArrayDeclarator) {
IASTArrayModifier[] mods = ((IASTArrayDeclarator)declarator).getArrayModifiers();
for(int i=0; i<mods.length; i++)
addRoot(mods[i]);
}
if (declarator instanceof ICPPASTFunctionDeclarator) {
ICPPASTConstructorChainInitializer[] chainInit = ((ICPPASTFunctionDeclarator)declarator).getConstructorChain();
for(int i=0; i<chainInit.length; i++) {
addRoot(chainInit[i]);
}
if( declarator instanceof ICPPASTFunctionTryBlockDeclarator ){
ICPPASTCatchHandler [] catchHandlers = ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers();
for( int i = 0; i < catchHandlers.length; i++ ){
addRoot(catchHandlers[i]);
}
}
}
if (temp == null) if (temp == null)
return PROCESS_ABORT; return PROCESS_ABORT;
else if (temp instanceof DOMASTNodeLeafContinue) else if (temp instanceof DOMASTNodeLeafContinue)
@ -191,6 +167,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier)
*/ */
@Override
public int visit(ICPPASTBaseSpecifier specifier) { public int visit(ICPPASTBaseSpecifier specifier) {
DOMASTNodeLeaf temp = addRoot(specifier); DOMASTNodeLeaf temp = addRoot(specifier);
if (temp == null) if (temp == null)
@ -204,6 +181,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
*/ */
@Override
public int visit(IASTDeclSpecifier declSpec) { public int visit(IASTDeclSpecifier declSpec) {
DOMASTNodeLeaf temp = addRoot(declSpec); DOMASTNodeLeaf temp = addRoot(declSpec);
if (temp == null) if (temp == null)
@ -217,6 +195,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
*/ */
@Override
public int visit(IASTEnumerator enumerator) { public int visit(IASTEnumerator enumerator) {
DOMASTNodeLeaf temp = addRoot(enumerator); DOMASTNodeLeaf temp = addRoot(enumerator);
if (temp == null) if (temp == null)
@ -230,6 +209,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
*/ */
@Override
public int visit(IASTExpression expression) { public int visit(IASTExpression expression) {
DOMASTNodeLeaf temp = addRoot(expression); DOMASTNodeLeaf temp = addRoot(expression);
if (temp == null) if (temp == null)
@ -243,6 +223,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
*/ */
@Override
public int visit(IASTInitializer initializer) { public int visit(IASTInitializer initializer) {
DOMASTNodeLeaf temp = addRoot(initializer); DOMASTNodeLeaf temp = addRoot(initializer);
if (temp == null) if (temp == null)
@ -256,6 +237,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @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)
*/ */
@Override
public int visit(IASTName name) { public int visit(IASTName name) {
DOMASTNodeLeaf temp = null; DOMASTNodeLeaf temp = null;
if (name.toString() != null) if (name.toString() != null)
@ -274,6 +256,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition)
*/ */
@Override
public int visit(ICPPASTNamespaceDefinition namespace) { public int visit(ICPPASTNamespaceDefinition namespace) {
DOMASTNodeLeaf temp = addRoot(namespace); DOMASTNodeLeaf temp = addRoot(namespace);
if (temp == null) if (temp == null)
@ -287,6 +270,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processParameterDeclaration(org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration)
*/ */
@Override
public int visit( public int visit(
IASTParameterDeclaration parameterDeclaration) { IASTParameterDeclaration parameterDeclaration) {
DOMASTNodeLeaf temp = addRoot(parameterDeclaration); DOMASTNodeLeaf temp = addRoot(parameterDeclaration);
@ -301,6 +285,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
*/ */
@Override
public int visit(IASTStatement statement) { public int visit(IASTStatement statement) {
DOMASTNodeLeaf temp = addRoot(statement); DOMASTNodeLeaf temp = addRoot(statement);
if (temp == null) if (temp == null)
@ -314,6 +299,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId) * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
*/ */
@Override
public int visit(IASTTypeId typeId) { public int visit(IASTTypeId typeId) {
DOMASTNodeLeaf temp = addRoot(typeId); DOMASTNodeLeaf temp = addRoot(typeId);
if (temp == null) if (temp == null)
@ -328,6 +314,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter) * @see org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor#visit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateParameter)
*/ */
@Override
public int visit(ICPPASTTemplateParameter templateParameter) { public int visit(ICPPASTTemplateParameter templateParameter) {
DOMASTNodeLeaf temp = addRoot(templateParameter); DOMASTNodeLeaf temp = addRoot(templateParameter);
if (temp == null) if (temp == null)

View file

@ -111,11 +111,19 @@ public class DOMASTNodeLeaf implements IAdaptable {
return false; return false;
} }
@Override
public String toString() { public String toString() {
if( node == null ) return BLANK_STRING; if( node == null ) return BLANK_STRING;
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
Class[] classes = node.getClass().getInterfaces(); Class<?> clazz= node.getClass();
Class<?>[] classes = clazz.getInterfaces();
while (classes.length == 0) {
clazz= clazz.getSuperclass();
if (clazz == null)
break;
classes= clazz.getInterfaces();
}
for(int i=0; i<classes.length; i++) { for(int i=0; i<classes.length; i++) {
if (classes[i].getPackage().toString().indexOf(INTERNAL) >= 0) if (classes[i].getPackage().toString().indexOf(INTERNAL) >= 0)
continue; continue;
@ -275,6 +283,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
return name; return name;
} }
@SuppressWarnings("unchecked")
public Object getAdapter(Class key) { public Object getAdapter(Class key) {
if (key == IPropertySource.class) if (key == IPropertySource.class)
return new ASTPropertySource(getNode()); return new ASTPropertySource(getNode());
@ -386,8 +395,8 @@ public class DOMASTNodeLeaf implements IAdaptable {
private IPropertyDescriptor[] getPropertyDescriptors(Object obj) { private IPropertyDescriptor[] getPropertyDescriptors(Object obj) {
IPropertyDescriptor[] desc = new IPropertyDescriptor[DEFAULT_DESCRIPTOR_SIZE]; IPropertyDescriptor[] desc = new IPropertyDescriptor[DEFAULT_DESCRIPTOR_SIZE];
if (obj==null) return BLANK_DESCRIPTORS; if (obj==null) return BLANK_DESCRIPTORS;
Class objClass = obj.getClass(); Class<?> objClass = obj.getClass();
Class[] interfaces = objClass.getInterfaces(); Class<?>[] interfaces = objClass.getInterfaces();
for(int i=0; i<interfaces.length; i++) { for(int i=0; i<interfaces.length; i++) {
Method[] methods = interfaces[i].getMethods(); Method[] methods = interfaces[i].getMethods();
@ -438,7 +447,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
if (!(id instanceof String)) if (!(id instanceof String))
return BLANK_STRING; return BLANK_STRING;
Class nodeClass = node.getClass(); Class<?> nodeClass = node.getClass();
String value = BLANK_STRING; String value = BLANK_STRING;
@ -448,12 +457,12 @@ public class DOMASTNodeLeaf implements IAdaptable {
String methodName = id.toString(); String methodName = id.toString();
methodName = methodName.replaceAll(BINDING_PREFIX, BLANK_STRING); methodName = methodName.replaceAll(BINDING_PREFIX, BLANK_STRING);
Method method = ((IASTName)node).resolveBinding().getClass().getMethod(methodName, new Class[0]); // only going to be getter methods... Method method = ((IASTName)node).resolveBinding().getClass().getMethod(methodName, new Class[0]); // only going to be getter methods...
result = method.invoke(((IASTName)node).resolveBinding(), null); result = method.invoke(((IASTName)node).resolveBinding());
} else { } else {
String methodName = id.toString(); String methodName = id.toString();
methodName = methodName.replaceAll(NODE_PREFIX, BLANK_STRING); methodName = methodName.replaceAll(NODE_PREFIX, BLANK_STRING);
Method method = nodeClass.getMethod(methodName, new Class[0]); // only going to be getter methods... Method method = nodeClass.getMethod(methodName, new Class[0]); // only going to be getter methods...
result = method.invoke(node, null); result = method.invoke(node);
} }
if (result == null) { if (result == null) {
@ -552,7 +561,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
if (hasGetType) { if (hasGetType) {
try { try {
Object result = methods[i].invoke(obj, null); Object result = methods[i].invoke(obj);
if (result instanceof IType) { if (result instanceof IType) {
return ASTTypeUtil.getType((IType)result); return ASTTypeUtil.getType((IType)result);

View file

@ -31,7 +31,6 @@ import org.eclipse.ui.IWorkbenchPartSite;
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;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTImageLocation; import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation; import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -42,8 +41,6 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroExpansion;
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.cpp.CPPASTVisitor; import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
@ -77,7 +74,8 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
shouldVisitDeclarators= true; shouldVisitDeclarators= true;
shouldVisitNamespaces= true; shouldVisitNamespaces= true;
} }
private boolean shouldVisitCatchHandlers= true; // tletodo
// private boolean shouldVisitCatchHandlers= true;
/** The semantic token */ /** The semantic token */
private SemanticToken fToken= new SemanticToken(); private SemanticToken fToken= new SemanticToken();
@ -136,15 +134,15 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
*/ */
@Override @Override
public int leave(IASTDeclaration declaration) { public int leave(IASTDeclaration declaration) {
if (!shouldVisitCatchHandlers && declaration instanceof IASTFunctionDefinition) { // if (!shouldVisitCatchHandlers && declaration instanceof IASTFunctionDefinition) {
shouldVisitCatchHandlers= true; // shouldVisitCatchHandlers= true;
IASTFunctionDefinition functionDef= (IASTFunctionDefinition) declaration; // IASTFunctionDefinition functionDef= (IASTFunctionDefinition) declaration;
ICPPASTFunctionTryBlockDeclarator declarator= (ICPPASTFunctionTryBlockDeclarator) functionDef.getDeclarator(); // ICPPASTFunctionTryBlockDeclarator declarator= (ICPPASTFunctionTryBlockDeclarator) functionDef.getDeclarator();
ICPPASTCatchHandler[] catchHandlers= declarator.getCatchHandlers(); // ICPPASTCatchHandler[] catchHandlers= declarator.getCatchHandlers();
for (ICPPASTCatchHandler catchHandler : catchHandlers) { // for (ICPPASTCatchHandler catchHandler : catchHandlers) {
catchHandler.accept(this); // catchHandler.accept(this);
} // }
} // }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
@ -164,9 +162,9 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
*/ */
@Override @Override
public int visit(IASTDeclarator declarator) { public int visit(IASTDeclarator declarator) {
if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) { // if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) {
shouldVisitCatchHandlers= false; // shouldVisitCatchHandlers= false;
} // }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
@ -175,9 +173,9 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener {
*/ */
@Override @Override
public int visit(IASTStatement statement) { public int visit(IASTStatement statement) {
if (!shouldVisitCatchHandlers && statement instanceof ICPPASTCatchHandler) { // if (!shouldVisitCatchHandlers && statement instanceof ICPPASTCatchHandler) {
return PROCESS_SKIP; // return PROCESS_SKIP;
} // }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }

View file

@ -73,7 +73,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
@ -138,7 +138,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTForStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionWithTryBlock;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTGotoStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTGotoStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIfStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIfStatement;
@ -530,8 +530,9 @@ public class CPPASTNodeFactory implements ICPPASTNodeFactory {
return new CPPASTConstructorChainInitializer(name, expr); return new CPPASTConstructorChainInitializer(name, expr);
} }
public ICPPASTFunctionTryBlockDeclarator newFunctionTryBlockDeclarator(IASTName name) { public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
return new CPPASTFunctionTryBlockDeclarator(name); IASTStatement bodyStatement) {
return new CPPASTFunctionWithTryBlock(declSpecifier, declarator, bodyStatement);
} }
public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) { public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) {

View file

@ -31,7 +31,6 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression; import org.eclipse.cdt.core.dom.ast.IASTInitializerExpression;
@ -61,7 +60,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
@ -1710,40 +1710,23 @@ public class CPPBuildASTParserAction extends BuildASTParserAction {
setOffsetAndLength(declSpec, parser.getLeftIToken().getStartOffset(), 0); setOffsetAndLength(declSpec, parser.getLeftIToken().getStartOffset(), 0);
} }
if(isTryBlockDeclarator) { ICPPASTFunctionDefinition definition;
// perform a shallow copy if (isTryBlockDeclarator) {
ICPPASTFunctionTryBlockDeclarator tryBlockDeclarator = nodeFactory.newFunctionTryBlockDeclarator(declarator.getName()); ICPPASTFunctionWithTryBlock tryblock= nodeFactory.newFunctionTryBlock(declSpec, declarator, body);
tryBlockDeclarator.setConst(declarator.isConst());
tryBlockDeclarator.setVolatile(declarator.isVolatile());
tryBlockDeclarator.setPureVirtual(declarator.isPureVirtual());
tryBlockDeclarator.setVarArgs(declarator.takesVarArgs());
for(IASTParameterDeclaration parameter : declarator.getParameters()) {
tryBlockDeclarator.addParameterDeclaration(parameter);
}
for(IASTTypeId exception : declarator.getExceptionSpecification()) {
tryBlockDeclarator.addExceptionSpecificationTypeId(exception);
}
for(Object handler : handlers) { for(Object handler : handlers) {
tryBlockDeclarator.addCatchHandler((ICPPASTCatchHandler)handler); tryblock.addCatchHandler((ICPPASTCatchHandler)handler);
} }
definition= tryblock;
declarator = tryBlockDeclarator; } else {
definition= (ICPPASTFunctionDefinition) nodeFactory.newFunctionDefinition(declSpec, declarator, body);
} }
if(initializers != null && !initializers.isEmpty()) { if(initializers != null && !initializers.isEmpty()) {
for(Object initializer : initializers) for(Object initializer : initializers)
declarator.addConstructorToChain((ICPPASTConstructorChainInitializer)initializer); definition.addMemberInitializer((ICPPASTConstructorChainInitializer)initializer);
// recalculate the length of the declarator to include the initializers
IASTNode lastInitializer = (IASTNode)initializers.get(initializers.size()-1);
int offset = offset(declarator);
int length = endOffset(lastInitializer) - offset;
setOffsetAndLength(declarator, offset, length);
} }
IASTFunctionDefinition definition = nodeFactory.newFunctionDefinition(declSpec, declarator, body);
setOffsetAndLength(definition); setOffsetAndLength(definition);
astStack.push(definition); astStack.push(definition);

View file

@ -10,10 +10,12 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.lrparser.action.cpp; package org.eclipse.cdt.core.dom.lrparser.action.cpp;
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.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference; import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement; import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression; import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement; import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
@ -31,7 +33,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeleteExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTExplicitTemplateInstantiation;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionTryBlockDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
@ -135,7 +137,8 @@ public interface ICPPASTNodeFactory extends IASTNodeFactory {
public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName name, IASTExpression expr); public ICPPASTConstructorChainInitializer newConstructorChainInitializer(IASTName name, IASTExpression expr);
public ICPPASTFunctionTryBlockDeclarator newFunctionTryBlockDeclarator(IASTName name); public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator,
IASTStatement bodyStatement);
public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId); public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId);