Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-06-05 13:32:51 -0400
committerSergey Prigogin2012-06-26 21:42:16 -0400
commitd611b69fbf7eb4365671d9cdb3f34ad60aac5192 (patch)
tree5a38d8edb157349f346d82ac8018b9311c77d0f1 /core/org.eclipse.cdt.core.tests
parentc67276494e8d767e9576ca8e01e2b84a605bdfaf (diff)
downloadorg.eclipse.cdt-d611b69fbf7eb4365671d9cdb3f34ad60aac5192.tar.gz
org.eclipse.cdt-d611b69fbf7eb4365671d9cdb3f34ad60aac5192.tar.xz
org.eclipse.cdt-d611b69fbf7eb4365671d9cdb3f34ad60aac5192.zip
Bug 380498. Fixed few more cases where typedefs were not preserved.
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java10
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java25
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java85
3 files changed, 74 insertions, 46 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
index ed3edc18d6..8f172f0f91 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2BaseTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -514,9 +514,13 @@ public class AST2BaseTest extends BaseTestCase {
protected boolean isCPP;
public BindingAssertionHelper(String contents, boolean isCPP) throws ParserException {
+ this(contents, isCPP ? ParserLanguage.CPP : ParserLanguage.C);
+ }
+
+ public BindingAssertionHelper(String contents, ParserLanguage lang) throws ParserException {
this.contents= contents;
- this.isCPP= isCPP;
- this.tu= parse(contents, isCPP ? ParserLanguage.CPP : ParserLanguage.C, true, false);
+ this.isCPP= lang.isCPP();
+ this.tu= parse(contents, lang, true, false);
}
public IASTTranslationUnit getTranslationUnit() {
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index a2773522dc..9f663484c0 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -4706,8 +4706,9 @@ public class AST2CPPTests extends AST2BaseTest {
}
// template<typename T>
- // class basic_string {
+ // struct basic_string {
// basic_string& operator+=(const T* s);
+ // basic_string& append(const T* s);
// };
//
// template<typename T>
@@ -4721,8 +4722,9 @@ public class AST2CPPTests extends AST2BaseTest {
// void test(const string& s) {
// auto s1 = "" + s + "";
// auto s2 = s1 += "";
+ // auto s3 = s2.append("foo");
// }
- public void testTypedefPreservation_380498() throws Exception {
+ public void testTypedefPreservation_380498_1() throws Exception {
BindingAssertionHelper ba= getAssertionHelper();
ICPPVariable s1 = ba.assertNonProblem("s1", ICPPVariable.class);
assertTrue(s1.getType() instanceof ITypedef);
@@ -4730,6 +4732,25 @@ public class AST2CPPTests extends AST2BaseTest {
ICPPVariable s2 = ba.assertNonProblem("s2", ICPPVariable.class);
assertTrue(s2.getType() instanceof ITypedef);
assertEquals("string", ((ITypedef) s2.getType()).getName());
+ ICPPVariable s3 = ba.assertNonProblem("s3", ICPPVariable.class);
+ assertTrue(s3.getType() instanceof ITypedef);
+ assertEquals("string", ((ITypedef) s3.getType()).getName());
+ }
+
+ // template <typename T>
+ // struct vector {
+ // typedef T* const_iterator;
+ // const_iterator begin() const;
+ // };
+ //
+ // void test(const vector<int>& v) {
+ // auto it = v.begin();
+ // }
+ public void testTypedefPreservation_380498_2() throws Exception {
+ BindingAssertionHelper ba= getAssertionHelper();
+ ICPPVariable it = ba.assertNonProblem("it =", "it", ICPPVariable.class);
+ assertTrue(it.getType() instanceof ITypedef);
+ assertEquals("vector<int>::const_iterator", ASTTypeUtil.getType(it.getType(), false));
}
// int f() {
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
index c456941068..d6fb38c236 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -125,7 +125,7 @@ import org.eclipse.cdt.internal.core.model.ASTStringUtil;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
- * Testcases on the AST.
+ * Test cases on the AST.
*/
public class AST2Tests extends AST2BaseTest {
private static final int NUM_TESTS = 3;
@@ -4866,10 +4866,9 @@ public class AST2Tests extends AST2BaseTest {
// myUnionPointer->bar=4;
// }
public void testBug228504_nonExistingMembers() throws Exception {
- boolean[] isCpps= {true, false};
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), isCpp);
- for (int i=1; i < 5; i++) {
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), lang);
+ for (int i= 1; i < 5; i++) {
ba.assertNonProblem("foo=" + i, 3);
ba.assertProblem("bar=" + i, 3);
}
@@ -4912,10 +4911,9 @@ public class AST2Tests extends AST2BaseTest {
// function1(); // ref
// }
public void testOutOfOrderResolution_Bug232300() throws Exception {
- final boolean[] isCpps= {false, true};
String code= getAboveComment();
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(code, isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(code, lang);
IBinding b1= ba.assertNonProblem("function1(); // decl", 9);
IBinding b2= ba.assertNonProblem("function1() {", 9);
IBinding b3= ba.assertNonProblem("function1(); // ref", 9);
@@ -4927,10 +4925,9 @@ public class AST2Tests extends AST2BaseTest {
// #define foo __typeof__((int*)0 - (int*)0)
// typedef foo ptrdiff_t;
public void testRedefinePtrdiff_Bug230895() throws Exception {
- final boolean[] isCpps= {false, true};
String code= getAboveComment();
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(code, isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(code, lang);
IBinding b1= ba.assertNonProblem("ptrdiff_t", 9);
assertInstance(b1, ITypedef.class);
ITypedef td= (ITypedef) b1;
@@ -4944,10 +4941,9 @@ public class AST2Tests extends AST2BaseTest {
// struct S;
// typedef struct S S; // td
public void testRedefineStructInScopeThatIsFullyResolved() throws Exception {
- final boolean[] isCpps= {false, true};
String code= getAboveComment();
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(code, isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(code, lang);
ba.assertNonProblem("a; // ref", 1);
// now scope is fully resolved
ICompositeType ct= ba.assertNonProblem("S;", 1, ICompositeType.class);
@@ -4972,10 +4968,9 @@ public class AST2Tests extends AST2BaseTest {
// VOID func(VOID) {
// }
public void testTypedefVoid_Bug221567() throws Exception {
- final boolean[] isCpps= { false, true };
String code= getAboveComment();
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(code, isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(code, lang);
ITypedef td= ba.assertNonProblem("VOID;", 4, ITypedef.class);
IBinding ref= ba.assertNonProblem("VOID)", 4);
assertSame(td, ref);
@@ -5021,9 +5016,8 @@ public class AST2Tests extends AST2BaseTest {
// int f5(int *(tint[10]));
public void testParamWithFunctionType_Bug84242() throws Exception {
final String comment= getAboveComment();
- final boolean[] isCpps= {false, true};
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(comment, isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(comment, lang);
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
isTypeEqual(f.getType(), "int (int (*)(int))");
@@ -5055,9 +5049,8 @@ public class AST2Tests extends AST2BaseTest {
// int (*f1 (int par))[5];
public void testFunctionReturningPtrToArray_Bug216609() throws Exception {
final String comment= getAboveComment();
- final boolean[] isCpps= {false, true};
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), lang);
IFunction f= ba.assertNonProblem("f1", 2, IFunction.class);
isTypeEqual(f.getType(), "int (* (int))[5]");
@@ -5077,7 +5070,6 @@ public class AST2Tests extends AST2BaseTest {
// void ((f4)());
public void testNestedFunctionDeclarators() throws Exception {
final String comment= getAboveComment();
- final boolean[] isCpps= {false, true};
for (ParserLanguage lang: ParserLanguage.values()) {
IASTTranslationUnit tu= parseAndCheckBindings(comment, lang);
IASTFunctionDefinition fdef= getDeclaration(tu, 0);
@@ -5133,8 +5125,8 @@ public class AST2Tests extends AST2BaseTest {
public void testLocalVariableResolution_Bug235831() throws Exception {
final String comment= getAboveComment();
final boolean[] isCpps= {false, true};
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(comment, isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(comment, lang);
ba.assertNonProblem("b; a", 1, IVariable.class); // fill cache of inner block
IVariable v3= ba.assertNonProblem("a; }", 1, IVariable.class);
@@ -5148,9 +5140,8 @@ public class AST2Tests extends AST2BaseTest {
// int foo(int (*ptr) (int, int));
public void testComplexParameterBinding_Bug214482() throws Exception {
final String comment= getAboveComment();
- final boolean[] isCpps= {false, true};
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(comment, isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(comment, lang);
IParameter p= ba.assertNonProblem("ptr", 3, IParameter.class);
assertEquals("ptr", p.getName());
}
@@ -5519,8 +5510,8 @@ public class AST2Tests extends AST2BaseTest {
// }
public void testAnonymousUnionMember() throws Exception {
final boolean[] isCpps= {false, true};
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), lang);
bh.assertNonProblem("a1=", 2);
bh.assertProblem("a2=", 2);
bh.assertNonProblem("a3=", 2);
@@ -5794,9 +5785,8 @@ public class AST2Tests extends AST2BaseTest {
// enum X {e0, e4=4, e5, e2=2, e3};
public void testValues() throws Exception {
final String code= getAboveComment();
- boolean isCpp= false;
- do {
- BindingAssertionHelper bh= new BindingAssertionHelper(code, false);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper bh= new BindingAssertionHelper(code, lang);
IVariable v= (IVariable) bh.assertNonProblem("a=", 1);
checkValue(v.getInitialValue(), -4);
v= (IVariable) bh.assertNonProblem("b=", 1);
@@ -5814,8 +5804,7 @@ public class AST2Tests extends AST2BaseTest {
checkValue(e.getValue(), 4);
e= (IEnumerator) bh.assertNonProblem("e5", 2);
checkValue(e.getValue(), 5);
- isCpp= !isCpp;
- } while (isCpp);
+ }
}
private void checkValue(IValue initialValue, int i) {
@@ -6088,11 +6077,10 @@ public class AST2Tests extends AST2BaseTest {
// size_t x = a + 5;
// size_t y = 2 + a;
// size_t y = a * 2;
- public void testTypeOfExpressionWithTypedef_380498() throws Exception {
- final boolean[] isCpps= { false, true };
+ public void testTypeOfExpressionWithTypedef_380498_1() throws Exception {
String code= getAboveComment();
- for (boolean isCpp : isCpps) {
- BindingAssertionHelper ba= new BindingAssertionHelper(code, isCpp);
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(code, lang);
IASTExpression exp = ba.assertNode("a + 5", IASTExpression.class);
assertTrue(exp.getExpressionType() instanceof ITypedef);
assertEquals("size_t", ((ITypedef) exp.getExpressionType()).getName());
@@ -6105,6 +6093,21 @@ public class AST2Tests extends AST2BaseTest {
}
}
+ // typedef void* VoidPtr;
+ // typedef VoidPtr (*Func)();
+ //
+ // void test(Func f) {
+ // f();
+ // }
+ public void testTypeOfExpressionWithTypedef_380498_2() throws Exception {
+ String code= getAboveComment();
+ for (ParserLanguage lang: ParserLanguage.values()) {
+ BindingAssertionHelper ba= new BindingAssertionHelper(code, lang);
+ IASTExpression exp = ba.assertNode("f()", IASTExpression.class);
+ assertTrue(exp.getExpressionType() instanceof ITypedef);
+ assertEquals("VoidPtr", ((ITypedef) exp.getExpressionType()).getName());
+ }
+ }
// typedef int TInt;
// int a= TInt; //ref
public void testTypeAsExpressionIsProblem_261175() throws Exception {

Back to the top