diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java index 4f720a1116c..a03b08712ae 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java @@ -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.IASTUnaryExpression; 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.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.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition; @@ -554,8 +556,12 @@ public class DOMLocationTests extends AST2BaseTest { buffer.append( "};\n"); //$NON-NLS-1$ IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP); - ICPPASTFunctionDeclarator funC = (ICPPASTFunctionDeclarator)((IASTFunctionDefinition)((ICPPASTCompositeTypeSpecifier)((IASTSimpleDeclaration)tu.getDeclarations()[2]).getDeclSpecifier()).getMembers()[1]).getDeclarator(); - assertSoleLocation( funC, buffer.toString().indexOf("C() : c(0)"), "C() : c(0)".length() ); //$NON-NLS-1$//$NON-NLS-2$ + final ICPPASTCompositeTypeSpecifier ct= getCompositeType(tu, 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 { @@ -574,10 +580,13 @@ public class DOMLocationTests extends AST2BaseTest { buffer.append( "catch (...)\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]; - ICPPASTFunctionTryBlockDeclarator funC = (ICPPASTFunctionTryBlockDeclarator)fdef.getDeclarator(); - 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$ + assertInstance(fdef, ICPPASTFunctionWithTryBlock.class); + 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 { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java index 0ffdf74e0f5..e652e235a49 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/append/CtorChainInitializerTest.java @@ -13,12 +13,12 @@ package org.eclipse.cdt.core.parser.tests.rewrite.changegenerator.append; 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.ICPPASTConstructorChainInitializer; 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.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.CPPASTName; import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification; @@ -45,17 +45,17 @@ public class CtorChainInitializerTest extends ChangeGeneratorTest { final ASTModificationStore modStore) { return new CPPASTVisitor() { { - shouldVisitDeclarators = true; + shouldVisitDeclarations = true; } @Override - public int visit(IASTDeclarator declarator) { - if (declarator instanceof CPPASTFunctionDeclarator) { - CPPASTFunctionDeclarator functionDeclarator = (CPPASTFunctionDeclarator)declarator; + public int visit(IASTDeclaration decl) { + if (decl instanceof CPPASTFunctionDefinition) { + CPPASTFunctionDefinition fdef = (CPPASTFunctionDefinition)decl; CPPASTIdExpression initExpr = new CPPASTIdExpression(new CPPASTName("a".toCharArray())); //$NON-NLS-1$ CPPASTName initName = new CPPASTName("alpha".toCharArray()); //$NON-NLS-1$ 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); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java index da3f2580857..e7e5b869fe5 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ASTStringUtil.java @@ -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.ICPPASTElaboratedTypeSpecifier; 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.ICPPASTPointerToMember; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName; @@ -305,9 +304,6 @@ public class ASTStringUtil { appendTypeIdString(buffer, exceptionTypeIds[i]); } } - if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) { - assert false : "TODO: handle "+ declarator.getClass().getName(); //$NON-NLS-1$ - } } } else if (declarator instanceof IASTFieldDeclarator) { final IASTFieldDeclarator fieldDeclarator= (IASTFieldDeclarator)declarator; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTConstructorChainInitializer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTConstructorChainInitializer.java index 92cac45641e..3b26a9b9fb7 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTConstructorChainInitializer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTConstructorChainInitializer.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; 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.IASTNameOwner; -import org.eclipse.cdt.core.dom.ast.IASTNode; /** - * @author jcamelon + *
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. */ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java index 73a9f4cb14f..ef44e2e958b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDeclarator.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; @@ -16,41 +17,10 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeId; /** * 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 - 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); +public interface ICPPASTFunctionDeclarator extends IASTStandardFunctionDeclarator { /** *EXCEPTION_TYPEID
represents the type IDs throws in the @@ -59,63 +29,63 @@ public interface ICPPASTFunctionDeclarator extends public static final ASTNodeProperty EXCEPTION_TYPEID = new ASTNodeProperty( "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. - * - * @returnIASTTypeId []
*/ public IASTTypeId[] getExceptionSpecification(); /** * Add an exception specification type Id. - * - * @param typeId - *IASTTypeId
*/ public void addExceptionSpecificationTypeId(IASTTypeId typeId); /** - * Is the method pure virtual? - * - * @return boolean + * Get function scope this node represents. Returnsnull
, if this declarator does not + * declare a function-prototype or function-definition. */ - public boolean isPureVirtual(); + public ICPPFunctionScope getFunctionScope(); - /** - * Set thid method to be pure virtual. - * - * @param isPureVirtual - * boolean - */ - public void setPureVirtual(boolean isPureVirtual); - /** - *CONSTRUCTOR_CHAIN_MEMBER
is the role of a constructor - * chain initializer. - */ + @Deprecated public static final ASTNodeProperty CONSTRUCTOR_CHAIN_MEMBER = new ASTNodeProperty( "ICPPASTFunctionDeclarator.CONSTRUCTOR_CHAIN_MEMBER - Role of a Constructor Chain Initializer"); //$NON-NLS-1$ /** - * Get constructor chain. - * - * @returnICPPASTConstructorChainInitializer[]
+ * @deprecated use {@link ICPPASTFunctionDefinition#getMemberInitializers}, instead. */ + @Deprecated public ICPPASTConstructorChainInitializer[] getConstructorChain(); - /** - * Add a constructor chain initializer to constructor chain. - * - * @param initializer - * ICPPASTConstructorChainInitializer - */ - public void addConstructorToChain( - ICPPASTConstructorChainInitializer initializer); - - /** - * Get function scope this node represents. - * - * @return ICPPFunctionScope scope - */ - public ICPPFunctionScope getFunctionScope(); + @Deprecated + public void addConstructorToChain(ICPPASTConstructorChainInitializer initializer); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java new file mode 100644 index 00000000000..32481635936 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionDefinition.java @@ -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 { + + /** + *MEMBER_INITIALIZER
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); +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionTryBlockDeclarator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionTryBlockDeclarator.java index 8925de36b0f..cae34e2c4ba 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionTryBlockDeclarator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionTryBlockDeclarator.java @@ -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 * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM - Initial API and implementation + * IBM - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.core.dom.ast.cpp; import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; /** - * This is a function try block declarator. - * - * @author jcamelon + * @deprecated, use {@link ICPPASTFunctionWithTryBlock}, instead. */ +@Deprecated public interface ICPPASTFunctionTryBlockDeclarator extends ICPPASTFunctionDeclarator { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionWithTryBlock.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionWithTryBlock.java new file mode 100644 index 00000000000..39721ba81aa --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp/ICPPASTFunctionWithTryBlock.java @@ -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: + *void func() try { + * } catch (...) { + * } + * @since 5.1 + * + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface ICPPASTFunctionWithTryBlock extends ICPPASTFunctionDefinition { + + /** + * ACATCH_HANDLER
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(); + +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java index 03302cd90cc..b6ad6c9c1b3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/util/ArrayUtil.java @@ -96,6 +96,15 @@ public class ArrayUtil { return temp; } + /** + * Type safe version of {@link #append(Class, Object[], int, Object)} + * @since 5.1 + */ + @SuppressWarnings("unchecked") + static publicT[] appendAt(Class c, T[] array, int currentLength, T obj) { + return (T[]) append(c, array, currentLength, obj); + } + static public Object [] append( Object[] array, Object 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 * 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. - * */ public static Object[] removeNullsAfter(Class> c, Object[] array, int index) { if( array == null || index < 0) @@ -288,6 +296,14 @@ public class ArrayUtil { return newArray; } + /** + * Type safe version of {@link #removeNullsAfter(Class, Object[], int)} + * @since 5.1 + */ + @SuppressWarnings("unchecked") + public static T[] trimAt(Class 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 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java index 5c6d0b8f8c4..a915c5d7777 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/FindNodeForOffsetAction.java @@ -10,7 +10,6 @@ *******************************************************************************/ 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.IASTDeclSpecifier; 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.ICASTVisitor; 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.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; @@ -50,6 +45,7 @@ public class FindNodeForOffsetAction extends CPPASTVisitor implements ICASTVisit shouldVisitNames = true; shouldVisitDeclarations= true; + shouldVisitArrayModifiers= shouldVisitInitializers= shouldVisitParameterDeclarations= shouldVisitDeclarators= @@ -95,28 +91,15 @@ public class FindNodeForOffsetAction extends CPPASTVisitor implements ICASTVisit for (int i = 0; i < ops.length; 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 constructorChain= new ArrayList (DEFAULT_CONSTRUCTOR_CHAIN_LIST_SIZE); - 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)); - } + ctorInitializer(fdef); } - IASTStatement body; try { - body= handleFunctionBody(); + IASTStatement body= handleFunctionBody(); + fdef.setBody(body); + setRange(fdef, firstOffset, calculateEndOffset(body)); } catch (BacktrackException bt) { final IASTNode n= bt.getNodeBeforeProblem(); - if (n instanceof IASTCompoundStatement) { - IASTFunctionDefinition funcDefinition = createFunctionDefinition(); - funcDefinition.setDeclSpecifier(declSpec); - funcDefinition.setDeclarator(fdtor); - funcDefinition.setBody((IASTCompoundStatement) n); - ((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, calculateEndOffset(n) - firstOffset); - throwBacktrack(bt.getProblem(), funcDefinition); + if (n instanceof IASTCompoundStatement && !(fdef instanceof ICPPASTFunctionWithTryBlock)) { + fdef.setBody((IASTCompoundStatement) n); + setRange(fdef, firstOffset, calculateEndOffset(n)); + throwBacktrack(bt.getProblem(), fdef); } throw bt; } - int endOffset= calculateEndOffset(body); - if (hasFunctionTryBlock) { + if (fdef instanceof ICPPASTFunctionWithTryBlock) { + ICPPASTFunctionWithTryBlock tryblock= (ICPPASTFunctionWithTryBlock) fdef; List handlers = new ArrayList (DEFAULT_CATCH_HANDLER_LIST_SIZE); catchHandlerSequence(handlers); - if (!handlers.isEmpty() && fdtor instanceof ICPPASTFunctionTryBlockDeclarator) { - ICPPASTFunctionTryBlockDeclarator tbd= (ICPPASTFunctionTryBlockDeclarator) fdtor; - for (ICPPASTCatchHandler catchHandler : handlers) { - tbd.addCatchHandler(catchHandler); - } - endOffset= calculateEndOffset(handlers.get(handlers.size()-1)); + ICPPASTCatchHandler last= null; + for (ICPPASTCatchHandler catchHandler : handlers) { + tryblock.addCatchHandler(catchHandler); + last= catchHandler; + } + if (last != null) { + adjustLength(tryblock, last); } } - - IASTFunctionDefinition funcDefinition = createFunctionDefinition(); - funcDefinition.setDeclSpecifier(declSpec); - funcDefinition.setDeclarator(fdtor); - funcDefinition.setBody(body); - - ((ASTNode) funcDefinition).setOffsetAndLength(firstOffset, endOffset-firstOffset); - return funcDefinition; + return fdef; } @Override - protected IASTFunctionDefinition createFunctionDefinition() { + protected ICPPASTFunctionDefinition createFunctionDefinition() { return new CPPASTFunctionDefinition(); } + protected ICPPASTFunctionWithTryBlock createFunctionTryBlock() { + return new CPPASTFunctionWithTryBlock(); + } @Override protected IASTSimpleDeclaration createSimpleDeclaration() { @@ -2455,7 +2447,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { * @throws BacktrackException * request a backtrack */ - protected void ctorInitializer(List collection) throws EndOfFileException, + protected void ctorInitializer(ICPPASTFunctionDefinition fdef) throws EndOfFileException, BacktrackException { consume(); ctorLoop: for (;;) { @@ -2494,7 +2486,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (expressionList != null) { ctorInitializer.setInitializerValue(expressionList); } - collection.add(ctorInitializer); + fdef.addMemberInitializer(ctorInitializer); switch (LT(1)) { case IToken.tCOMMA: @@ -3477,82 +3469,77 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { // Consume any number of __attribute__ tokens after the parameters __attribute_decl_seq(supportAttributeSpecifiers, false); - boolean isTryCatch= false; boolean isConst= false; boolean isVolatile= false; boolean isPureVirtual= false; ArrayList exceptionSpecIds= null; - if (LT(1) == IToken.t_try) { - isTryCatch= true; - } else { - // cv-qualifiers - cvloop: while(true) { - switch(LT(1)) { - case IToken.t_const: - isConst= true; - endOffset= consume().getEndOffset(); - break; - case IToken.t_volatile: - isVolatile= true; - endOffset= consume().getEndOffset(); - break; - default: - break cvloop; - } - } - - // throws clause - if (LT(1) == IToken.t_throw) { - exceptionSpecIds = new ArrayList (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; - } + // cv-qualifiers + cvloop: while(true) { + switch(LT(1)) { + case IToken.t_const: + isConst= true; + endOffset= consume().getEndOffset(); + break; + case IToken.t_volatile: + isVolatile= true; + endOffset= consume().getEndOffset(); + break; + default: + break cvloop; } } - final ICPPASTFunctionDeclarator fc= isTryCatch ? createTryBlockDeclarator() : createFunctionDeclarator(); + // throws clause + if (LT(1) == IToken.t_throw) { + exceptionSpecIds = new ArrayList (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.setConst(isConst); fc.setVolatile(isVolatile); @@ -3611,12 +3598,6 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { return new CPPASTProblemTypeId(); } - - protected ICPPASTFunctionTryBlockDeclarator createTryBlockDeclarator() { - return new CPPASTFunctionTryBlockDeclarator(); - } - - protected ICPPASTFunctionDeclarator createFunctionDeclarator() { return new CPPASTFunctionDeclarator(); } @@ -4001,14 +3982,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { } collection.add(handler); - - 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; - } + lt1 = LTcatchEOF(1); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 578c765fbd7..8cd19ba1190 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -528,8 +528,8 @@ public class CPPSemantics { scope = CPPVisitor.getContainingScope(n); } else if (parent instanceof ICPPASTConstructorChainInitializer) { ICPPASTConstructorChainInitializer initializer = (ICPPASTConstructorChainInitializer) parent; - IASTFunctionDeclarator dtor = (IASTFunctionDeclarator) initializer.getParent(); - IBinding binding = dtor.getName().resolveBinding(); + IASTFunctionDefinition fdef= (IASTFunctionDefinition) initializer.getParent(); + IBinding binding = fdef.getDeclarator().getName().resolveBinding(); if (!(binding instanceof IProblemBinding)) scope = binding.getScope(); } else { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java index e6cfdb63c4e..6c54e698f9b 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java @@ -820,7 +820,7 @@ public class CPPVisitor { } else if (parent instanceof IASTCompoundStatement) { return ((IASTCompoundStatement)parent).getScope(); } else if (parent instanceof ICPPASTConstructorChainInitializer) { - IASTNode temp = getContainingBlockItem(parent.getParent()); + IASTNode temp = getContainingBlockItem(parent); if (temp instanceof IASTFunctionDefinition) { IASTCompoundStatement body = (IASTCompoundStatement) ((IASTFunctionDefinition)temp).getBody(); return body.getScope(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java index 691b8ca1452..677c3af5167 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java @@ -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.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.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.ICPPASTNamespaceAlias; 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.ICPPASTVisibilityLabel; 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.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; @@ -281,16 +284,43 @@ public class DeclarationWriter extends NodeWriter{ } IASTDeclarator declarator = CPPVisitor.findOutermostDeclarator(funcDef.getDeclarator()); 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(); + funcDef.getBody().accept(visitor); - if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) { - ICPPASTFunctionTryBlockDeclarator tryDeclSpec = (ICPPASTFunctionTryBlockDeclarator) declarator; - ICPPASTCatchHandler[] catches = tryDeclSpec.getCatchHandlers(); + + if (funcDef instanceof ICPPASTFunctionWithTryBlock) { + ICPPASTFunctionWithTryBlock tryblock = (ICPPASTFunctionWithTryBlock) funcDef; + ICPPASTCatchHandler[] catches = tryblock.getCatchHandlers(); for (ICPPASTCatchHandler handler : catches) { 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) { IASTDeclSpecifier declSpecifier = simpDec.getDeclSpecifier(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java index d6b248ca4da..e03a5ca6bfd 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java @@ -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.c.ICASTPointer; 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.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.ICPPASTReferenceOperator; 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 STAR_SPACE = "* "; //$NON-NLS-1$ - private static final String TRY = "try"; //$NON-NLS-1$ private static final String PURE_VIRTUAL = " =0"; //$NON-NLS-1$ public DeclaratorWriter(Scribe scribe, CPPASTVisitor visitor, NodeCommentMap commentMap) { @@ -146,29 +143,6 @@ public class DeclaratorWriter extends NodeWriter { scribe.print(PURE_VIRTUAL); } 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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java index f2d517e9dd8..33ad9d12aa3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * 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; @@ -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.ICASTFieldDesignator; 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.gnu.c.IGCCASTArrayRangeDesignator; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; @@ -49,7 +51,19 @@ public class InitializerWriter extends NodeWriter{ writeConstructorInitializer((ICPPASTConstructorInitializer) initializer); }else if (initializer instanceof ICASTDesignatedInitializer) { 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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclarationWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclarationWriter.java index b16264688d6..6642a036763 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclarationWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclarationWriter.java @@ -7,12 +7,15 @@ * http://www.eclipse.org/legal/epl-v10.html * * 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; 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.ICPPASTConstructorChainInitializer; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; 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.Scribe; @@ -32,5 +35,11 @@ public class ModifiedASTDeclarationWriter extends DeclarationWriter { IASTDeclaration[] modifiedDeclarations = modificationHelper.createModifiedChildArray(namespaceDefinition, declarations, IASTDeclaration.class); super.writeDeclarationsInNamespace(namespaceDefinition, modifiedDeclarations); } - + + @Override + protected void writeCtorChainInitializer(ICPPASTFunctionDefinition funcDec, + ICPPASTConstructorChainInitializer[] ctorInitChain) { + ICPPASTConstructorChainInitializer[] modifiedChainInitializer = modificationHelper.createModifiedChildArray(funcDec, ctorInitChain, ICPPASTConstructorChainInitializer.class); + super.writeCtorChainInitializer(funcDec, modifiedChainInitializer); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java index 04b45a16afd..a7b40f532c3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTDeclaratorWriter.java @@ -7,7 +7,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * 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; @@ -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.IASTTypeId; 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.gnu.c.ICASTKnRFunctionDeclarator; 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 protected void writeArrayModifiers(IASTArrayDeclarator arrDecl, IASTArrayModifier[] arrMods) { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index 0d09996c94e..f6537ecb302 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -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.ICPPASTForStatement; 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.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; @@ -483,9 +484,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.printNextToken(Token.tRPAREN, false); } - if (node instanceof ICPPASTFunctionTryBlockDeclarator) { - visit((ICPPASTFunctionTryBlockDeclarator)node); - } else if (node instanceof ICPPASTFunctionDeclarator) { + if (node instanceof ICPPASTFunctionDeclarator) { return visit((ICPPASTFunctionDeclarator)node); } else if (node instanceof IASTStandardFunctionDeclarator) { visit((IASTStandardFunctionDeclarator)node); @@ -993,6 +992,27 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.space(); } 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 IASTStatement bodyStmt= node.getBody(); @@ -1013,9 +1033,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.printTrailingComment(); scribe.startNewLine(); - // hack: catch handlers are part of declarator - if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) { - ICPPASTCatchHandler[] catchHandlers= ((ICPPASTFunctionTryBlockDeclarator)declarator).getCatchHandlers(); + if (node instanceof ICPPASTFunctionWithTryBlock) { + ICPPASTCatchHandler[] catchHandlers= ((ICPPASTFunctionWithTryBlock)node).getCatchHandlers(); for (int i= 0; i < catchHandlers.length; i++) { catchHandlers[i].accept(this); scribe.printTrailingComment(); @@ -1043,27 +1062,28 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } } - if (node instanceof ICPPASTFunctionTryBlockDeclarator) { - scribe.startNewLine(); - scribe.printNextToken(Token.t_try, false); - scribe.printTrailingComment(); - // for catch handlers @see #visit(IASTFunctionDefinition) - } - - final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain(); - 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(); - } else { +// tletodo +// if (node instanceof ICPPASTFunctionTryBlockDeclarator) { +// scribe.startNewLine(); +// scribe.printNextToken(Token.t_try, false); +// scribe.printTrailingComment(); +// // for catch handlers @see #visit(IASTFunctionDefinition) +// } +// +// final ICPPASTConstructorChainInitializer[] constructorChain= node.getConstructorChain(); +// 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(); +// } else { // skip the rest (=0) skipNode(node); - } +// } return PROCESS_SKIP; } diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java index 8739fbd25bd..4e84faa877d 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java @@ -12,8 +12,6 @@ package org.eclipse.cdt.ui.tests.DOMAST; 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.IASTDeclaration; 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.IASTEnumerationSpecifier.IASTEnumerator; 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.ICPPASTTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier; @@ -140,6 +134,7 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate /* (non-Javadoc) * @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) { DOMASTNodeLeaf temp = addRoot(declaration); if (temp == null) @@ -153,33 +148,14 @@ public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulate /* (non-Javadoc) * @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) { DOMASTNodeLeaf temp = addRoot(declarator); IASTPointerOperator[] ops = declarator.getPointerOperators(); for(int i=0; i 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 = 0) continue; @@ -275,6 +283,7 @@ public class DOMASTNodeLeaf implements IAdaptable { return name; } + @SuppressWarnings("unchecked") public Object getAdapter(Class key) { if (key == IPropertySource.class) return new ASTPropertySource(getNode()); @@ -386,8 +395,8 @@ public class DOMASTNodeLeaf implements IAdaptable { private IPropertyDescriptor[] getPropertyDescriptors(Object obj) { IPropertyDescriptor[] desc = new IPropertyDescriptor[DEFAULT_DESCRIPTOR_SIZE]; if (obj==null) return BLANK_DESCRIPTORS; - Class objClass = obj.getClass(); - Class[] interfaces = objClass.getInterfaces(); + Class> objClass = obj.getClass(); + Class>[] interfaces = objClass.getInterfaces(); for(int i=0; i nodeClass = node.getClass(); String value = BLANK_STRING; @@ -448,12 +457,12 @@ public class DOMASTNodeLeaf implements IAdaptable { String methodName = id.toString(); methodName = methodName.replaceAll(BINDING_PREFIX, BLANK_STRING); 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 { String methodName = id.toString(); methodName = methodName.replaceAll(NODE_PREFIX, BLANK_STRING); 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) { @@ -552,7 +561,7 @@ public class DOMASTNodeLeaf implements IAdaptable { if (hasGetType) { try { - Object result = methods[i].invoke(obj, null); + Object result = methods[i].invoke(obj); if (result instanceof IType) { return ASTTypeUtil.getType((IType)result); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java index ac99f55bfc5..c845ba0c522 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/SemanticHighlightingReconciler.java @@ -31,7 +31,6 @@ import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; 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.IASTMacroExpansionLocation; 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.IASTTranslationUnit; 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.model.ICElement; import org.eclipse.cdt.core.model.ILanguage; @@ -77,7 +74,8 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener { shouldVisitDeclarators= true; shouldVisitNamespaces= true; } - private boolean shouldVisitCatchHandlers= true; +// tletodo +// private boolean shouldVisitCatchHandlers= true; /** The semantic token */ private SemanticToken fToken= new SemanticToken(); @@ -136,15 +134,15 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener { */ @Override public int leave(IASTDeclaration declaration) { - if (!shouldVisitCatchHandlers && declaration instanceof IASTFunctionDefinition) { - shouldVisitCatchHandlers= true; - IASTFunctionDefinition functionDef= (IASTFunctionDefinition) declaration; - ICPPASTFunctionTryBlockDeclarator declarator= (ICPPASTFunctionTryBlockDeclarator) functionDef.getDeclarator(); - ICPPASTCatchHandler[] catchHandlers= declarator.getCatchHandlers(); - for (ICPPASTCatchHandler catchHandler : catchHandlers) { - catchHandler.accept(this); - } - } +// if (!shouldVisitCatchHandlers && declaration instanceof IASTFunctionDefinition) { +// shouldVisitCatchHandlers= true; +// IASTFunctionDefinition functionDef= (IASTFunctionDefinition) declaration; +// ICPPASTFunctionTryBlockDeclarator declarator= (ICPPASTFunctionTryBlockDeclarator) functionDef.getDeclarator(); +// ICPPASTCatchHandler[] catchHandlers= declarator.getCatchHandlers(); +// for (ICPPASTCatchHandler catchHandler : catchHandlers) { +// catchHandler.accept(this); +// } +// } return PROCESS_CONTINUE; } @@ -164,9 +162,9 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener { */ @Override public int visit(IASTDeclarator declarator) { - if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) { - shouldVisitCatchHandlers= false; - } +// if (declarator instanceof ICPPASTFunctionTryBlockDeclarator) { +// shouldVisitCatchHandlers= false; +// } return PROCESS_CONTINUE; } @@ -175,9 +173,9 @@ public class SemanticHighlightingReconciler implements ICReconcilingListener { */ @Override public int visit(IASTStatement statement) { - if (!shouldVisitCatchHandlers && statement instanceof ICPPASTCatchHandler) { - return PROCESS_SKIP; - } +// if (!shouldVisitCatchHandlers && statement instanceof ICPPASTCatchHandler) { +// return PROCESS_SKIP; +// } return PROCESS_CONTINUE; } diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPASTNodeFactory.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPASTNodeFactory.java index 6fb0a5183b6..cefda475846 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPASTNodeFactory.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPASTNodeFactory.java @@ -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.ICPPASTExplicitTemplateInstantiation; 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.ICPPASTNamedTypeSpecifier; 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.CPPASTFunctionDeclarator; 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.CPPASTIdExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIfStatement; @@ -530,8 +530,9 @@ public class CPPASTNodeFactory implements ICPPASTNodeFactory { return new CPPASTConstructorChainInitializer(name, expr); } - public ICPPASTFunctionTryBlockDeclarator newFunctionTryBlockDeclarator(IASTName name) { - return new CPPASTFunctionTryBlockDeclarator(name); + public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, + IASTStatement bodyStatement) { + return new CPPASTFunctionWithTryBlock(declSpecifier, declarator, bodyStatement); } public IASTFieldDeclarator newFieldDeclarator(IASTName name, IASTExpression bitFieldSize) { diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java index bd985d63041..12f8fa4f2e8 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/CPPBuildASTParserAction.java @@ -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.IASTForStatement; 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.IASTIfStatement; 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.ICPPASTExplicitTemplateInstantiation; 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.ICPPASTNamedTypeSpecifier; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias; @@ -1710,39 +1710,22 @@ public class CPPBuildASTParserAction extends BuildASTParserAction { setOffsetAndLength(declSpec, parser.getLeftIToken().getStartOffset(), 0); } - if(isTryBlockDeclarator) { - // perform a shallow copy - ICPPASTFunctionTryBlockDeclarator tryBlockDeclarator = nodeFactory.newFunctionTryBlockDeclarator(declarator.getName()); - 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); - } + ICPPASTFunctionDefinition definition; + if (isTryBlockDeclarator) { + ICPPASTFunctionWithTryBlock tryblock= nodeFactory.newFunctionTryBlock(declSpec, declarator, body); for(Object handler : handlers) { - tryBlockDeclarator.addCatchHandler((ICPPASTCatchHandler)handler); + tryblock.addCatchHandler((ICPPASTCatchHandler)handler); } - - declarator = tryBlockDeclarator; + definition= tryblock; + } else { + definition= (ICPPASTFunctionDefinition) nodeFactory.newFunctionDefinition(declSpec, declarator, body); } if(initializers != null && !initializers.isEmpty()) { for(Object initializer : initializers) - declarator.addConstructorToChain((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); + definition.addMemberInitializer((ICPPASTConstructorChainInitializer)initializer); } - - IASTFunctionDefinition definition = nodeFactory.newFunctionDefinition(declSpec, declarator, body); setOffsetAndLength(definition); astStack.push(definition); diff --git a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/ICPPASTNodeFactory.java b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/ICPPASTNodeFactory.java index e595eec0180..6cc42a5f2f1 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/ICPPASTNodeFactory.java +++ b/lrparser/org.eclipse.cdt.core.lrparser/src/org/eclipse/cdt/core/dom/lrparser/action/cpp/ICPPASTNodeFactory.java @@ -10,10 +10,12 @@ *******************************************************************************/ 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.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTFieldReference; 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.IASTIfStatement; 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.ICPPASTExplicitTemplateInstantiation; 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.ICPPASTNamedTypeSpecifier; 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 ICPPASTFunctionTryBlockDeclarator newFunctionTryBlockDeclarator(IASTName name); + public ICPPASTFunctionWithTryBlock newFunctionTryBlock(IASTDeclSpecifier declSpecifier, IASTFunctionDeclarator declarator, + IASTStatement bodyStatement); public ICPPASTSimpleTypeTemplateParameter newSimpleTypeTemplateParameter(int type, IASTName name, IASTTypeId typeId);