diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterStatementTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterStatementTestSource.awts index a322f51b197..66b9dbe1a01 100644 --- a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterStatementTestSource.awts +++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterStatementTestSource.awts @@ -109,6 +109,25 @@ int f() goto badStyle; } +//!CPP GNU Goto Expression Statement Test +//%CPP GNU +void f() +{ + void* labelPtr = &&foo; + goto *labelPtr; + foo: + return; +} + +//!C GNU Goto Expression Statement Test +//%CPP GNU +void f() +{ + void* labelPtr = &&foo; + goto *labelPtr; + foo: + return; +} //!IfStatementTest //%CPP diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java index 142998e2d2b..ab70bc5ce78 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/ExpressionWriter.java @@ -9,6 +9,7 @@ * Contributors: * Institute for Software - initial API and implementation * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.core.dom.rewrite.astwriter; @@ -110,6 +111,7 @@ public class ExpressionWriter extends NodeWriter{ private static final String MODULO_OP = " % "; //$NON-NLS-1$ private static final String DIVIDE_OP = " / "; //$NON-NLS-1$ private static final String MULTIPLY_OP = " * "; //$NON-NLS-1$ + private static final String LABEL_REFERENCE_OP = "&&"; //$NON-NLS-1$ private static final String THIS = "this"; //$NON-NLS-1$ private static final String THROW = "throw "; //$NON-NLS-1$ private final MacroExpansionHandler macroHandler; @@ -248,7 +250,8 @@ public class ExpressionWriter extends NodeWriter{ case IASTUnaryExpression.op_bracketedPrimary: case ICPPASTUnaryExpression.op_throw: case ICPPASTUnaryExpression.op_typeid: - case IASTUnaryExpression.op_alignOf: + case IASTUnaryExpression.op_alignOf: + case IASTUnaryExpression.op_labelReference: return true; default: @@ -302,6 +305,8 @@ public class ExpressionWriter extends NodeWriter{ return TYPEID_OP; case IASTUnaryExpression.op_alignOf: return ALIGNOF_OP; + case IASTUnaryExpression.op_labelReference: + return LABEL_REFERENCE_OP; default: System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$ throw new IllegalArgumentException("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$ @@ -380,7 +385,7 @@ public class ExpressionWriter extends NodeWriter{ } private void writeUnaryExpression(IASTUnaryExpression unExp) { - if (isPrefixExpression(unExp )) { + if (isPrefixExpression(unExp)) { scribe.print(getPrefixOperator(unExp)); } visitNodeIfNotNull(unExp.getOperand()); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java index cf89b05a539..a11ec90d526 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java @@ -42,6 +42,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement; +import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTGotoStatement; import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; @@ -106,6 +107,8 @@ public class StatementWriter extends NodeWriter { } else if (statement instanceof IASTGotoStatement) { writeGotoStatement((IASTGotoStatement) statement); // usually newLine + } else if (statement instanceof IGNUASTGotoStatement) { + writeGNUASTGotoStatement((IGNUASTGotoStatement) statement); } else if (statement instanceof IASTLabelStatement) { writeLabelStatement((IASTLabelStatement) statement); newLine = false; @@ -266,6 +269,12 @@ public class StatementWriter extends NodeWriter { scribe.printSemicolon(); } + private void writeGNUASTGotoStatement(IGNUASTGotoStatement gotoStatement) { + scribe.print(GOTO); + gotoStatement.getLabelNameExpression().accept(visitor); + scribe.printSemicolon(); + } + private void writeReturnStatement(IASTReturnStatement returnStatement) { writeAttributes(returnStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.noNewLines();