mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +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:
parent
4f239a093a
commit
6dff32c96a
3 changed files with 35 additions and 2 deletions
|
@ -109,6 +109,25 @@ int f()
|
||||||
goto badStyle;
|
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
|
//!IfStatementTest
|
||||||
//%CPP
|
//%CPP
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Thomas Corbat (IFS)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
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 MODULO_OP = " % "; //$NON-NLS-1$
|
||||||
private static final String DIVIDE_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 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 THIS = "this"; //$NON-NLS-1$
|
||||||
private static final String THROW = "throw "; //$NON-NLS-1$
|
private static final String THROW = "throw "; //$NON-NLS-1$
|
||||||
private final MacroExpansionHandler macroHandler;
|
private final MacroExpansionHandler macroHandler;
|
||||||
|
@ -249,6 +251,7 @@ public class ExpressionWriter extends NodeWriter{
|
||||||
case ICPPASTUnaryExpression.op_throw:
|
case ICPPASTUnaryExpression.op_throw:
|
||||||
case ICPPASTUnaryExpression.op_typeid:
|
case ICPPASTUnaryExpression.op_typeid:
|
||||||
case IASTUnaryExpression.op_alignOf:
|
case IASTUnaryExpression.op_alignOf:
|
||||||
|
case IASTUnaryExpression.op_labelReference:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -302,6 +305,8 @@ public class ExpressionWriter extends NodeWriter{
|
||||||
return TYPEID_OP;
|
return TYPEID_OP;
|
||||||
case IASTUnaryExpression.op_alignOf:
|
case IASTUnaryExpression.op_alignOf:
|
||||||
return ALIGNOF_OP;
|
return ALIGNOF_OP;
|
||||||
|
case IASTUnaryExpression.op_labelReference:
|
||||||
|
return LABEL_REFERENCE_OP;
|
||||||
default:
|
default:
|
||||||
System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
System.err.println("Unkwown unaryExpressionType: " + unaryExpressionType); //$NON-NLS-1$
|
||||||
throw new IllegalArgumentException("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) {
|
private void writeUnaryExpression(IASTUnaryExpression unExp) {
|
||||||
if (isPrefixExpression(unExp )) {
|
if (isPrefixExpression(unExp)) {
|
||||||
scribe.print(getPrefixOperator(unExp));
|
scribe.print(getPrefixOperator(unExp));
|
||||||
}
|
}
|
||||||
visitNodeIfNotNull(unExp.getOperand());
|
visitNodeIfNotNull(unExp.getOperand());
|
||||||
|
|
|
@ -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.ICPPASTSwitchStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
|
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.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.parser.IASTAmbiguousStatement;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
||||||
|
|
||||||
|
@ -106,6 +107,8 @@ public class StatementWriter extends NodeWriter {
|
||||||
} else if (statement instanceof IASTGotoStatement) {
|
} else if (statement instanceof IASTGotoStatement) {
|
||||||
writeGotoStatement((IASTGotoStatement) statement);
|
writeGotoStatement((IASTGotoStatement) statement);
|
||||||
// usually newLine
|
// usually newLine
|
||||||
|
} else if (statement instanceof IGNUASTGotoStatement) {
|
||||||
|
writeGNUASTGotoStatement((IGNUASTGotoStatement) statement);
|
||||||
} else if (statement instanceof IASTLabelStatement) {
|
} else if (statement instanceof IASTLabelStatement) {
|
||||||
writeLabelStatement((IASTLabelStatement) statement);
|
writeLabelStatement((IASTLabelStatement) statement);
|
||||||
newLine = false;
|
newLine = false;
|
||||||
|
@ -266,6 +269,12 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.printSemicolon();
|
scribe.printSemicolon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeGNUASTGotoStatement(IGNUASTGotoStatement gotoStatement) {
|
||||||
|
scribe.print(GOTO);
|
||||||
|
gotoStatement.getLabelNameExpression().accept(visitor);
|
||||||
|
scribe.printSemicolon();
|
||||||
|
}
|
||||||
|
|
||||||
private void writeReturnStatement(IASTReturnStatement returnStatement) {
|
private void writeReturnStatement(IASTReturnStatement returnStatement) {
|
||||||
writeAttributes(returnStatement, EnumSet.of(SpaceLocation.AFTER));
|
writeAttributes(returnStatement, EnumSet.of(SpaceLocation.AFTER));
|
||||||
scribe.noNewLines();
|
scribe.noNewLines();
|
||||||
|
|
Loading…
Add table
Reference in a new issue