Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-08-04 13:41:50 +0000
committerMarkus Schorn2008-08-04 13:41:50 +0000
commit58dced96be1cd6c0e61484a8f02dedecc2d94e9e (patch)
treed23673f015d96a342c2a1fa264a38576f2602537 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter
parentb4159f688a501ab3a584a2043cc8df4d9d36fa56 (diff)
downloadorg.eclipse.cdt-58dced96be1cd6c0e61484a8f02dedecc2d94e9e.tar.gz
org.eclipse.cdt-58dced96be1cd6c0e61484a8f02dedecc2d94e9e.tar.xz
org.eclipse.cdt-58dced96be1cd6c0e61484a8f02dedecc2d94e9e.zip
AST representation for member-initializers and function try block, bug 237253.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclarationWriter.java38
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/DeclaratorWriter.java26
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/InitializerWriter.java16
3 files changed, 49 insertions, 31 deletions
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) {

Back to the top