1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 84144 - ASTWriter extension for IGNUASTGotoStatements and label

reference operator. Including tests.

Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
Thomas Corbat 2014-07-10 10:24:20 +02:00
parent 4f239a093a
commit 6dff32c96a
3 changed files with 35 additions and 2 deletions

View file

@ -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

View file

@ -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());

View file

@ -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();