1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-26 10:25:32 +02:00

Compiler warning.

This commit is contained in:
Markus Schorn 2011-01-21 10:19:47 +00:00
parent 2c376e0343
commit d9c1b0b0c4

View file

@ -1,189 +1,190 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2010 University of Applied Sciences Rapperswil (HSR). * Copyright (c) 2010 University of Applied Sciences Rapperswil (HSR).
* All rights reserved. This program and the accompanying materials are made * All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which * available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at * accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: Pascal Kesseli (HSR) - Initial API and implementation * Contributors: Pascal Kesseli (HSR) - Initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser.tests.rewrite.astwriter; package org.eclipse.cdt.core.parser.tests.rewrite.astwriter;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression; import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCapture;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCapture; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCapture;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLambdaExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLambdaExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTParameterDeclaration;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclSpecifier;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap; import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriterVisitor;
import org.junit.Assert; import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
import org.junit.Before; import org.junit.Assert;
import org.junit.Test; import org.junit.Before;
import org.junit.Test;
public class ExpressionWriterTest extends TestCase {
private static final String BR = System.getProperty("line.separator"); public class ExpressionWriterTest extends TestCase {
private static CPPASTSimpleDeclSpecifier INT = new CPPASTSimpleDeclSpecifier(); private static final String BR = System.getProperty("line.separator");
private static IASTName NO_NAME = new CPPASTName(new char[] {}); private static CPPASTSimpleDeclSpecifier INT = new CPPASTSimpleDeclSpecifier();
private NodeCommentMap commentMap = new NodeCommentMap(); private static IASTName NO_NAME = new CPPASTName(new char[] {});
private ASTVisitor visitor; private NodeCommentMap commentMap = new NodeCommentMap();
private ASTVisitor visitor;
static {
INT.setType(CPPASTSimpleDeclSpecifier.t_int); static {
} INT.setType(IASTSimpleDeclSpecifier.t_int);
}
@Override
@Before @Override
protected void setUp() throws Exception { @Before
visitor = new ASTWriterVisitor(commentMap); protected void setUp() throws Exception {
} visitor = new ASTWriterVisitor(commentMap);
}
@Test
public void testWriteLambdaExpressionEmptyIntroducerNoDeclarator() throws Exception { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionEmptyIntroducerNoDeclarator() throws Exception {
lambda.accept(visitor); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
String expected = "[] {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(expected, visitor.toString()); String expected = "[] {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(expected, visitor.toString());
}
@Test
public void testWriteLambdaExpressionDefaultCaptureByCopyNoDeclarator() { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionDefaultCaptureByCopyNoDeclarator() {
lambda.setCaptureDefault(ICPPASTLambdaExpression.CaptureDefault.BY_COPY); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
lambda.accept(visitor); lambda.setCaptureDefault(ICPPASTLambdaExpression.CaptureDefault.BY_COPY);
String expected = "[=] {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(expected, visitor.toString()); String expected = "[=] {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(expected, visitor.toString());
}
@Test
public void testWriteLambdaExpressionDefaultCaptureByReferenceNoDeclarator() { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionDefaultCaptureByReferenceNoDeclarator() {
lambda.setCaptureDefault(ICPPASTLambdaExpression.CaptureDefault.BY_REFERENCE); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
lambda.accept(visitor); lambda.setCaptureDefault(ICPPASTLambdaExpression.CaptureDefault.BY_REFERENCE);
String expected = "[&] {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(expected, visitor.toString()); String expected = "[&] {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(expected, visitor.toString());
}
@Test
public void testWriteLambdaExpressionThisCaptureNoDeclarator() { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionThisCaptureNoDeclarator() {
lambda.addCapture(new CPPASTCapture()); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
lambda.accept(visitor); lambda.addCapture(new CPPASTCapture());
String expected = "[this] {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(expected, visitor.toString()); String expected = "[this] {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(expected, visitor.toString());
}
@Test
public void testWriteLambdaExpressionMixedCaptureNoDeclarator() { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionMixedCaptureNoDeclarator() {
lambda.setCaptureDefault(ICPPASTLambdaExpression.CaptureDefault.BY_COPY); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
lambda.addCapture(new CPPASTCapture()); lambda.setCaptureDefault(ICPPASTLambdaExpression.CaptureDefault.BY_COPY);
ICPPASTCapture x = new CPPASTCapture(), y = new CPPASTCapture(); lambda.addCapture(new CPPASTCapture());
x.setIdentifier(new CPPASTName(new char[] { 'x' })); ICPPASTCapture x = new CPPASTCapture(), y = new CPPASTCapture();
x.setIsByReference(true); x.setIdentifier(new CPPASTName(new char[] { 'x' }));
y.setIdentifier(new CPPASTName(new char[] { 'y' })); x.setIsByReference(true);
lambda.addCapture(x); y.setIdentifier(new CPPASTName(new char[] { 'y' }));
lambda.addCapture(y); lambda.addCapture(x);
lambda.accept(visitor); lambda.addCapture(y);
String r = "[=, this, &x, y] {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(r, visitor.toString()); String r = "[=, this, &x, y] {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(r, visitor.toString());
}
@Test
public void testWriteLambdaExpressionEmptyIntroducerSimpleDeclarator() throws Exception { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionEmptyIntroducerSimpleDeclarator() throws Exception {
lambda.setDeclarator(getSimpleFunctionDeclarator()); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
lambda.accept(visitor); lambda.setDeclarator(getSimpleFunctionDeclarator());
String r = "[](int i, int j) {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(r, visitor.toString()); String r = "[](int i, int j) {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(r, visitor.toString());
}
@Test
public void testWriteLambdaExpressionEmptyIntroducerMutableDeclarator() throws Exception { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionEmptyIntroducerMutableDeclarator() throws Exception {
ICPPASTFunctionDeclarator f = getSimpleFunctionDeclarator(); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
f.setMutable(true); ICPPASTFunctionDeclarator f = getSimpleFunctionDeclarator();
lambda.setDeclarator(f); f.setMutable(true);
lambda.accept(visitor); lambda.setDeclarator(f);
String r = "[](int i, int j) mutable {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(r, visitor.toString()); String r = "[](int i, int j) mutable {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(r, visitor.toString());
}
@Test
public void testWriteLambdaExpressionEmptyIntroducerExceptionSpecificationDeclarator() throws Exception { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionEmptyIntroducerExceptionSpecificationDeclarator() throws Exception {
ICPPASTFunctionDeclarator f = getSimpleFunctionDeclarator(); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
f.addExceptionSpecificationTypeId(new CPPASTTypeId(INT, new CPPASTDeclarator(NO_NAME))); ICPPASTFunctionDeclarator f = getSimpleFunctionDeclarator();
lambda.setDeclarator(f); f.addExceptionSpecificationTypeId(new CPPASTTypeId(INT, new CPPASTDeclarator(NO_NAME)));
lambda.accept(visitor); lambda.setDeclarator(f);
String r = "[](int i, int j) throw (int) {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(r, visitor.toString()); String r = "[](int i, int j) throw (int) {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(r, visitor.toString());
}
@Test
public void testWriteLambdaExpressionEmptyIntroducerTrailingReturnTypeDeclarator() throws Exception { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteLambdaExpressionEmptyIntroducerTrailingReturnTypeDeclarator() throws Exception {
ICPPASTFunctionDeclarator f = getSimpleFunctionDeclarator(); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
f.setTrailingReturnType(new CPPASTTypeId(INT, new CPPASTDeclarator(NO_NAME))); ICPPASTFunctionDeclarator f = getSimpleFunctionDeclarator();
lambda.setDeclarator(f); f.setTrailingReturnType(new CPPASTTypeId(INT, new CPPASTDeclarator(NO_NAME)));
lambda.accept(visitor); lambda.setDeclarator(f);
String r = "[](int i, int j) -> int {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(r, visitor.toString()); String r = "[](int i, int j) -> int {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(r, visitor.toString());
}
@Test
public void testWriteAllEmbracingLambdaExpression() { @Test
ICPPASTLambdaExpression lambda = getEmptyLambdaExpression(); public void testWriteAllEmbracingLambdaExpression() {
ICPPASTFunctionDeclarator f = getSimpleFunctionDeclarator(); ICPPASTLambdaExpression lambda = getEmptyLambdaExpression();
lambda.setCaptureDefault(ICPPASTLambdaExpression.CaptureDefault.BY_REFERENCE); ICPPASTFunctionDeclarator f = getSimpleFunctionDeclarator();
ICPPASTCapture x = new CPPASTCapture(), y = new CPPASTCapture(); lambda.setCaptureDefault(ICPPASTLambdaExpression.CaptureDefault.BY_REFERENCE);
x.setIdentifier(new CPPASTName(new char[] { 'x' })); ICPPASTCapture x = new CPPASTCapture(), y = new CPPASTCapture();
y.setIdentifier(new CPPASTName(new char[] { 'y' })); x.setIdentifier(new CPPASTName(new char[] { 'x' }));
y.setIsByReference(true); y.setIdentifier(new CPPASTName(new char[] { 'y' }));
lambda.addCapture(x); y.setIsByReference(true);
lambda.addCapture(y); lambda.addCapture(x);
lambda.addCapture(new CPPASTCapture()); lambda.addCapture(y);
f.setMutable(true); lambda.addCapture(new CPPASTCapture());
f.setTrailingReturnType(new CPPASTTypeId(INT, new CPPASTDeclarator(NO_NAME))); f.setMutable(true);
f.addExceptionSpecificationTypeId(new CPPASTTypeId(INT, new CPPASTDeclarator(NO_NAME))); f.setTrailingReturnType(new CPPASTTypeId(INT, new CPPASTDeclarator(NO_NAME)));
lambda.setDeclarator(f); f.addExceptionSpecificationTypeId(new CPPASTTypeId(INT, new CPPASTDeclarator(NO_NAME)));
lambda.accept(visitor); lambda.setDeclarator(f);
String r = "[&, x, &y, this](int i, int j) mutable throw (int) -> int {" + BR + " return 7;" + BR + "}" + BR; lambda.accept(visitor);
Assert.assertEquals(r, visitor.toString()); String r = "[&, x, &y, this](int i, int j) mutable throw (int) -> int {" + BR + " return 7;" + BR + "}" + BR;
} Assert.assertEquals(r, visitor.toString());
}
private static ICPPASTFunctionDeclarator getSimpleFunctionDeclarator() {
ICPPASTFunctionDeclarator f = new CPPASTFunctionDeclarator(new CPPASTName()); private static ICPPASTFunctionDeclarator getSimpleFunctionDeclarator() {
IASTName name = new CPPASTName(new char[] { 'i' }); ICPPASTFunctionDeclarator f = new CPPASTFunctionDeclarator(new CPPASTName());
IASTDeclarator d = new CPPASTDeclarator(name); IASTName name = new CPPASTName(new char[] { 'i' });
f.addParameterDeclaration(new CPPASTParameterDeclaration(INT, d)); IASTDeclarator d = new CPPASTDeclarator(name);
name = new CPPASTName(new char[] { 'j' }); f.addParameterDeclaration(new CPPASTParameterDeclaration(INT, d));
d = new CPPASTDeclarator(name); name = new CPPASTName(new char[] { 'j' });
f.addParameterDeclaration(new CPPASTParameterDeclaration(INT, d)); d = new CPPASTDeclarator(name);
return f; f.addParameterDeclaration(new CPPASTParameterDeclaration(INT, d));
} return f;
}
private static ICPPASTLambdaExpression getEmptyLambdaExpression() {
ICPPASTLambdaExpression lambda = new CPPASTLambdaExpression(); private static ICPPASTLambdaExpression getEmptyLambdaExpression() {
CPPASTCompoundStatement stmt = new CPPASTCompoundStatement(); ICPPASTLambdaExpression lambda = new CPPASTLambdaExpression();
stmt.addStatement(new CPPASTReturnStatement(new CPPASTLiteralExpression( CPPASTCompoundStatement stmt = new CPPASTCompoundStatement();
IASTLiteralExpression.lk_integer_constant, stmt.addStatement(new CPPASTReturnStatement(new CPPASTLiteralExpression(
new char[] { '7' }))); IASTLiteralExpression.lk_integer_constant,
lambda.setBody(stmt); new char[] { '7' })));
return lambda; lambda.setBody(stmt);
} return lambda;
} }
}