From 58dced96be1cd6c0e61484a8f02dedecc2d94e9e Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Mon, 4 Aug 2008 13:41:50 +0000 Subject: AST representation for member-initializers and function try block, bug 237253. --- .../dom/rewrite/astwriter/DeclarationWriter.java | 38 +++++++++++++++++++--- .../dom/rewrite/astwriter/DeclaratorWriter.java | 26 --------------- .../dom/rewrite/astwriter/InitializerWriter.java | 16 ++++++++- .../ModifiedASTDeclarationWriter.java | 13 ++++++-- .../ModifiedASTDeclaratorWriter.java | 12 ++----- 5 files changed, 62 insertions(+), 43 deletions(-) (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite') 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) { -- cgit v1.2.3