1
/*******************************************************************************
2
* Copyright (c) 2007, 2008 Symbian Software Systems and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Andrew Ferguson (Symbian) - Initial implementation
10
* Markus Schorn (Wind River Systems)
11
* Sergey Prigogin (Google)
12
*******************************************************************************/
13
package org.eclipse.cdt.internal.index.tests;
15
import java.io.IOException;
16
import java.util.Arrays;
17
import java.util.HashSet;
20
import junit.framework.TestSuite;
22
import org.eclipse.cdt.core.dom.ast.DOMException;
23
import org.eclipse.cdt.core.dom.ast.IBinding;
24
import org.eclipse.cdt.core.dom.ast.ICompositeType;
25
import org.eclipse.cdt.core.dom.ast.IEnumeration;
26
import org.eclipse.cdt.core.dom.ast.IEnumerator;
27
import org.eclipse.cdt.core.dom.ast.IPointerType;
28
import org.eclipse.cdt.core.dom.ast.IType;
29
import org.eclipse.cdt.core.dom.ast.IValue;
30
import org.eclipse.cdt.core.dom.ast.IVariable;
31
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
32
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
33
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
34
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
35
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
36
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
37
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
38
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
39
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
40
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
41
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
42
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
43
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
44
import org.eclipse.cdt.core.index.IIndex;
45
import org.eclipse.cdt.core.index.IIndexBinding;
46
import org.eclipse.core.runtime.CoreException;
49
* For testing PDOM binding CPP language resolution
52
* aftodo - once we have non-problem bindings working, each test should
53
* additionally check that the binding obtained has characteristics as
54
* expected (type,name,etc..)
56
public abstract class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase {
58
public static class SingleProject extends IndexCPPBindingResolutionTest {
59
public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));}
60
public static TestSuite suite() {return suite(SingleProject.class);}
62
public static class ProjectWithDepProj extends IndexCPPBindingResolutionTest {
63
public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));}
64
public static TestSuite suite() {return suite(ProjectWithDepProj.class);}
67
public static void addTests(TestSuite suite) {
68
suite.addTest(SingleProject.suite());
69
suite.addTest(ProjectWithDepProj.suite());
72
// namespace ns { class A; enum E {E1}; typedef int T; }
101
public void testUsingTypeDirective_201177() {
102
IBinding b0= getBindingFromASTName("B::m", 4);
103
IBinding b1= getBindingFromASTName("B::n", 4);
104
IBinding b2= getBindingFromASTName("B::o", 4);
105
IBinding b3= getBindingFromASTName("p(E1)", 1);
106
assertInstance(b0, ICPPMethod.class);
107
assertInstance(b1, ICPPMethod.class);
108
assertInstance(b2, ICPPMethod.class);
111
// namespace n { class A{}; class B{}; class C{}; }
114
// using namespace n;
119
public void testUsingNamingDirective_177917_1a() {
120
IBinding b0= getBindingFromASTName("C c", 1);
121
IBinding b1= getBindingFromASTName("D d", 1);
124
// namespace n { class A{}; }
126
// using namespace n;
130
// #include "header.h"
131
// namespace n { class C{}; }
133
public void testUsingNamingDirective_177917_1b() {
134
IBinding b0= getBindingFromASTName("C c", 1);
137
// int ff(int x) { return x; }
138
// namespace n { class A {}; }
139
// namespace m { class B {}; enum C{CE1,CE2}; }
140
// namespace o { int (*f)(int)= ff; }
144
// using namespace m;
148
// int g(int x) {return 4;}
149
// int g(char x) {return 2;}
151
public void testUsingTypeDirective_177917_1() {
152
IBinding b1= getBindingFromASTName("A a", 1);
153
IBinding b2= getBindingFromASTName("B b", 1);
154
IBinding b3= getBindingFromASTName("C c", 1);
155
IBinding b4= getBindingFromASTName("CE1", 3);
156
IBinding b5= getBindingFromASTName("f(2", 1);
159
// namespace a { class A {}; }
165
// #include "header.h"
168
public void testUsingTypeDirective_177917_2() {
169
IBinding b0= getBindingFromASTName("A aa", 1);
170
IBinding b1= getBindingFromASTName("B bb", 1);
173
// namespace header {
184
// using header::clh;
187
// #include "header.h"
188
// namespace source {
199
// using source::cls;
216
public void testUsingOverloadedFunctionDirective() {
218
b= getBindingFromASTName("fh()", 2);
219
b= getBindingFromASTName("fh(1)", 2);
220
b= getBindingFromASTName("clh c", 3);
221
b= getBindingFromASTName("f()", 1);
222
b= getBindingFromASTName("f(1)", 1);
223
b= getBindingFromASTName("cl c1", 2);
224
b= getBindingFromASTName("fs()", 2);
225
b= getBindingFromASTName("fs(1)", 2);
226
b= getBindingFromASTName("cls c2", 3);
231
// int g(int n){return n;}
232
// int g(int n, int m){ return n+m; }
237
public void testPointerToFunction() throws Exception {
238
IBinding b0 = getBindingFromASTName("f= g;", 1);
239
IBinding b1 = getBindingFromASTName("g;", 1);
241
assertInstance(b0, ICPPVariable.class);
242
ICPPVariable v0= (ICPPVariable) b0;
243
assertInstance(v0.getType(), IPointerType.class);
244
IPointerType p0= (IPointerType) v0.getType();
245
assertInstance(p0.getType(), ICPPFunctionType.class);
246
ICPPFunctionType f0= (ICPPFunctionType) p0.getType();
247
assertInstance(f0.getReturnType(), ICPPBasicType.class);
248
assertEquals(1, f0.getParameterTypes().length);
249
assertInstance(f0.getParameterTypes()[0], ICPPBasicType.class);
251
assertInstance(b1, ICPPFunction.class);
252
ICPPFunctionType f1= ((ICPPFunction)b1).getType();
253
assertInstance(f1.getReturnType(), ICPPBasicType.class);
254
assertEquals(1, f1.getParameterTypes().length);
255
assertInstance(f1.getParameterTypes()[0], ICPPBasicType.class);
259
// class Base {public: int field; void foo() {}};
260
// class C : public Base {
262
// struct CS { long* l; C *method(CS **); };
265
// long * CS::* ouch;
266
// long * CS::* autsch;
267
// C* (CS::*method)(CS **);
270
// // referencing file
271
// #include "header.h"
273
// C *cp = new C(); /*b0, b1*/
274
// void references() {
277
// cp->cs.*cp->ouch = lp = cp->cs.*cp->autsch; /*b2, b3, b4*/
278
// &(cp->cs)->*cp->autsch = lp = &(cp->cs)->*cp->ouch;
279
// (cp->cs).method(cp->cspp);/*1*/ (&(cp->cs))->method(cp->cspp);/*2*/
280
// ((cp->cs).*(cp->method))(cp->cspp);/*3*/
281
// ((&(cp->cs))->*(cp->method))(cp->cspp);/*4*/
283
public void testPointerToMemberFields() throws IOException, DOMException {
284
IBinding b0 = getBindingFromASTName("C *cp", 1);
285
assertClassType((ICPPClassType)b0, "C", ICPPClassType.k_class, 1, 6, 5, 9, 0, 1, 0, 2, 1);
287
IBinding b1 = getBindingFromASTName("cp = new C()", 2);
288
assertVariable(b1, "cp", IPointerType.class, null);
289
IPointerType b1type = (IPointerType) ((ICPPVariable)b1).getType();
290
assertClassType(b1type.getType(), "C", ICPPClassType.k_class, 1, 6, 5, 9, 0, 1, 0, 2, 1);
292
IBinding b2 = getBindingFromASTName("cs.*cp->o", 2);
293
ICPPField field0 = (ICPPField) b2;
294
assertTrue(field0.getType() instanceof ICPPClassType);
296
IBinding b3 = getBindingFromASTName("ouch = lp", 4);
297
assertField(b3, "C::ouch", ICPPPointerToMemberType.class, null);
298
assertPTM(((ICPPField)b3).getType(), "C::CS", null);
300
IBinding b4 = getBindingFromASTName("autsch;", 6);
301
assertField(b4, "C::autsch", ICPPPointerToMemberType.class, null);
302
assertPTM(((ICPPField)b4).getType(), "C::CS", null);
304
IBinding b5 = getBindingFromASTName("cs)->*cp->a", 2);
305
assertField(b5, "C::cs", ICPPClassType.class, "C::CS");
306
assertClassType(((ICPPField)b5).getType(), "C::CS", ICompositeType.k_struct, 0, 1, 1, 5, 1, 1, 0, 2, 0);
308
IBinding b6 = getBindingFromASTName("autsch = lp", 6);
309
assertField(b4, "C::autsch", ICPPPointerToMemberType.class, null);
310
assertPTM(((ICPPField)b4).getType(), "C::CS", null);
312
IBinding b7 = getBindingFromASTName("ouch;", 4);
313
assertField(b3, "C::ouch", ICPPPointerToMemberType.class, null);
314
assertPTM(((ICPPField)b3).getType(), "C::CS", null);
318
// class C {}; struct S {}; union U {}; enum E {ER1,ER2,ER3};
319
// int var1; C var2; S *var3; void func(E); void func(C);
321
// typedef int Int; typedef int *IntPtr;
322
// void func(int*); void func(int);
324
// // referencing file
325
// #include "header.h"
326
// void references() {
327
// C c; /*c*/ S s; /*s*/ U u; /*u*/ E e; /*e*/
328
// var1 = 1; /*var1*/ var2 = c; /*var2*/ var3 = &s; /*var3*/
329
// func(e); /*func1*/ func(var1); /*func2*/ func(c); /*func3*/
331
// IntPtr b = &a; /*b*/
332
// func(*b); /*func4*/ func(a); /*func5*/
334
// class C2 : public C {}; /*base*/
335
// struct S2 : public S {}; /*base*/
336
public void testSimpleGlobalBindings() throws IOException, DOMException {
338
IBinding b0 = getBindingFromASTName("C c; ", 1);
339
assertClassTypeBinding(b0, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
341
IBinding b1 = getBindingFromASTName("c; ", 1);
342
assertVariable(b1, "c", ICPPClassType.class, "C");
343
ICPPClassType b1type = (ICPPClassType)((ICPPVariable)b1).getType();
344
assertClassTypeBinding(b1type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
345
assertTrue(b1type.getScope() == null);
346
assertTrue(b1type.getCompositeScope() instanceof ICPPClassScope);
347
assertClassTypeBinding(((ICPPClassScope)b1type.getCompositeScope()).getClassType(), "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
350
IBinding b2 = getBindingFromASTName("S s;", 1);
351
assertClassTypeBinding(b2, "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0);
353
IBinding b3 = getBindingFromASTName("s;", 1);
354
assertVariable(b3, "s", ICPPClassType.class, "S");
355
ICPPClassType b3type = (ICPPClassType)((ICPPVariable)b3).getType();
356
assertClassTypeBinding(b3type, "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0);
359
IBinding b4 = getBindingFromASTName("U u;", 1);
360
assertClassTypeBinding(b4, "U", ICompositeType.k_union, 0, 0, 0, 4, 0, 0, 0, 2, 0);
362
IBinding b5 = getBindingFromASTName("u; ", 1);
363
assertVariable(b5, "u", ICPPClassType.class, "U");
364
ICPPClassType b5type = (ICPPClassType)((ICPPVariable)b5).getType();
365
assertClassTypeBinding(b5type, "U", ICompositeType.k_union, 0, 0, 0, 4, 0, 0, 0, 2, 0);
368
IBinding b6 = getBindingFromASTName("E e; ", 1);
369
assertEnumeration(b6, "E", new String[] {"ER1","ER2","ER3"});
371
IBinding b7 = getBindingFromASTName("e; ", 1);
372
assertVariable(b7, "e", IEnumeration.class, "E");
373
IEnumeration b5type = (IEnumeration)((ICPPVariable)b7).getType();
374
assertEnumeration(b5type, "E", new String[] {"ER1","ER2","ER3"});
375
assertTrue(b5type.getScope() == null);
378
IBinding b8 = getBindingFromASTName("var1 = 1;", 4);
379
assertVariable(b8, "var1", ICPPBasicType.class, null);
382
IBinding b9 = getBindingFromASTName("var2 = c;", 4);
383
assertVariable(b9, "var2", ICPPClassType.class, "C");
384
ICPPClassType b9type = (ICPPClassType)((ICPPVariable)b9).getType();
385
assertClassTypeBinding(b9type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
388
IBinding b10 = getBindingFromASTName("var3 = &s;", 4);
389
assertVariable(b10, "var3", IPointerType.class, null);
390
IPointerType b10type = (IPointerType) ((ICPPVariable)b10).getType();
391
assertClassTypeBinding((ICPPClassType) b10type.getType(), "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0);
394
IBinding b11 = getBindingFromASTName("func(e);", 4);
396
IBinding b12 = getBindingFromASTName("func(var1);", 4);
397
IBinding b13 = getBindingFromASTName("func(c);", 4);
398
IBinding b14 = getBindingFromASTName("Int a; ", 3);
399
IBinding b15 = getBindingFromASTName("a; ", 1);
400
IBinding b16 = getBindingFromASTName("IntPtr b = &a; ", 6);
401
IBinding b17 = getBindingFromASTName("b = &a; /*b*/", 1);
402
IBinding b18 = getBindingFromASTName("func(*b);", 4);
403
IBinding b19 = getBindingFromASTName("b); /*func4*/", 1);
404
IBinding b20 = getBindingFromASTName("func(a);", 4);
405
IBinding b21 = getBindingFromASTName("a); /*func5*/", 1);
406
IBinding b22 = getBindingFromASTName("C2 : public", 2);
407
IBinding b23 = getBindingFromASTName("C {}; /*base*/", 1);
408
IBinding b24 = getBindingFromASTName("S2 : public", 2);
409
IBinding b25 = getBindingFromASTName("S {}; /*base*/", 1);
414
//class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2};
415
//short topBasic; void *topPtr; TopC *topCPtr; TopU topFunc(){return *new TopU();}
417
//// referencing content
419
// class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2};
420
// short topBasic; void *topPtr;/*A*/ TopC *topCPtr;/*A*/ TopU topFunc(){return *new TopU();}
422
// class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2};
423
// short topBasic; void *topPtr;/*B*/ TopC *topCPtr;/*B*/ TopU topFunc(){return *new TopU();}
424
// void references() {
425
// ::TopC c; ::TopS s; ::TopU u; ::TopE e = ::TopER1;
426
// ::topBasic++; ::topPtr = &::topBasic; ::topCPtr = &c; ::topFunc();
430
public void testSingletonQualifiedName() {
431
IBinding b0 = getBindingFromASTName("TopC c", 4);
432
IBinding b1 = getBindingFromASTName("TopS s", 4);
433
IBinding b2 = getBindingFromASTName("TopU u", 4);
434
IBinding b3 = getBindingFromASTName("TopE e", 4);
435
IBinding b4 = getBindingFromASTName("TopER1;", 6);
436
IBinding b5 = getBindingFromASTName("topBasic++", 8);
437
IBinding b6 = getBindingFromASTName("topPtr = &", 6);
438
IBinding b7 = getBindingFromASTName("topBasic; ::", 8);
439
IBinding b8 = getBindingFromASTName("topCPtr = &", 7);
440
IBinding b9 = getBindingFromASTName("topFunc();", 7);
442
IBinding _b5 = getBindingFromASTName("topBasic; v", 8);
443
IBinding _b6 = getBindingFromASTName("topPtr;/*A*/", 6);
444
IBinding _b7 = getBindingFromASTName("topPtr;/*B*/", 6);
445
IBinding _b8 = getBindingFromASTName("topCPtr;/*A*/", 7);
446
IBinding _b9 = getBindingFromASTName("topCPtr;/*B*/", 7);
447
IBinding _b10 = getBindingFromASTName("topFunc(){", 7);
451
// namespace n1 { namespace n2 { struct S {}; } }
452
// class c1 { public: class c2 { public: struct S {}; }; };
453
// struct s1 { struct s2 { struct S {}; }; };
454
// union u1 { struct u2 { struct S {}; }; };
455
// namespace n3 { class c3 { public: struct s3 { union u3 { struct S {}; }; }; }; }
457
// // reference content
458
// void reference() {
459
// ::n1::n2::S _s0; n1::n2::S _s1;
460
// ::c1::c2::S _s2; c1::c2::S _s3;
461
// ::s1::s2::S _s4; s1::s2::S _s5;
462
// ::u1::u2::S _s6; u1::u2::S _s7;
463
// ::n3::c3::s3::u3::S _s8;
464
// n3::c3::s3::u3::S _s9;
466
// namespace n3 { c3::s3::u3::S _s10; }
467
// namespace n1 { n2::S _s11; }
468
// namespace n1 { namespace n2 { S _s12; }}
469
public void testQualifiedNamesForStruct() throws DOMException {
470
IBinding b0 = getBindingFromASTName("S _s0;", 1);
471
assertTrue(b0.getScope() instanceof ICPPNamespaceScope);
472
assertTrue(b0.getScope().getParent() instanceof ICPPNamespaceScope);
473
assertTrue(b0.getScope().getParent().getParent() == null);
474
assertQNEquals("n1::n2::S", b0);
476
IBinding b1 = getBindingFromASTName("S _s1;", 1);
477
assertTrue(b1.getScope() instanceof ICPPNamespaceScope);
478
assertTrue(b1.getScope().getParent() instanceof ICPPNamespaceScope);
479
assertTrue(b1.getScope().getParent().getParent() == null);
480
assertQNEquals("n1::n2::S", b1);
482
IBinding b2 = getBindingFromASTName("S _s2;", 1);
483
assertTrue(b2.getScope() instanceof ICPPClassScope);
484
assertTrue(b2.getScope().getParent() instanceof ICPPClassScope);
485
assertTrue(b2.getScope().getParent().getParent() == null);
486
assertQNEquals("c1::c2::S", b2);
488
IBinding b3 = getBindingFromASTName("S _s3;", 1);
489
assertQNEquals("c1::c2::S", b3);
490
IBinding b4 = getBindingFromASTName("S _s4;", 1);
491
assertQNEquals("s1::s2::S", b4);
492
IBinding b5 = getBindingFromASTName("S _s5;", 1);
493
assertQNEquals("s1::s2::S", b5);
494
IBinding b6 = getBindingFromASTName("S _s6;", 1);
495
assertQNEquals("u1::u2::S", b6);
496
IBinding b7 = getBindingFromASTName("S _s7;", 1);
497
assertQNEquals("u1::u2::S", b7);
498
IBinding b8 = getBindingFromASTName("S _s8;", 1);
499
assertQNEquals("n3::c3::s3::u3::S", b8);
500
IBinding b9 = getBindingFromASTName("S _s9;", 1);
501
assertQNEquals("n3::c3::s3::u3::S", b9);
503
IBinding b10 = getBindingFromASTName("S _s10;", 1);
504
assertTrue(b10.getScope() instanceof ICPPClassScope);
505
assertTrue(b10.getScope().getParent() instanceof ICPPClassScope);
506
assertTrue(b10.getScope().getParent().getParent() instanceof ICPPClassScope);
507
assertTrue(b10.getScope().getParent().getParent().getParent() instanceof ICPPNamespaceScope);
508
assertTrue(b10.getScope().getParent().getParent().getParent().getParent() == null);
509
assertQNEquals("n3::c3::s3::u3::S", b10);
511
IBinding b11 = getBindingFromASTName("S _s11;", 1);
512
assertQNEquals("n1::n2::S", b11);
513
IBinding b12 = getBindingFromASTName("S _s12;", 1);
514
assertQNEquals("n1::n2::S", b12);
518
// namespace n1 { namespace n2 { union U {}; } }
519
// class c1 { public: class c2 { public: union U {}; }; };
520
// struct s1 { struct s2 { union U {}; }; };
521
// union u1 { struct u2 { union U {}; }; };
522
// namespace n3 { class c3 { public: struct s3 { union u3 { union U {}; }; }; }; }
524
// // reference content
525
// void reference() {
526
// ::n1::n2::U _u0; n1::n2::U _u1;
527
// ::c1::c2::U _u2; c1::c2::U _u3;
528
// ::s1::s2::U _u4; s1::s2::U _u5;
529
// ::u1::u2::U _u6; u1::u2::U _u7;
530
// ::n3::c3::s3::u3::U _u8;
531
// n3::c3::s3::u3::U _u9;
533
// namespace n3 { c3::s3::u3::U _u10; }
534
// namespace n1 { n2::U _u11; }
535
// namespace n1 { namespace n2 { U _u12; }}
536
public void testQualifiedNamesForUnion() throws DOMException {
537
IBinding b0 = getBindingFromASTName("U _u0;", 1);
538
assertQNEquals("n1::n2::U", b0);
539
IBinding b1 = getBindingFromASTName("U _u1;", 1);
540
assertQNEquals("n1::n2::U", b1);
541
IBinding b2 = getBindingFromASTName("U _u2;", 1);
542
assertQNEquals("c1::c2::U", b2);
543
IBinding b3 = getBindingFromASTName("U _u3;", 1);
544
assertQNEquals("c1::c2::U", b3);
545
IBinding b4 = getBindingFromASTName("U _u4;", 1);
546
assertQNEquals("s1::s2::U", b4);
547
IBinding b5 = getBindingFromASTName("U _u5;", 1);
548
assertQNEquals("s1::s2::U", b5);
549
IBinding b6 = getBindingFromASTName("U _u6;", 1);
550
assertQNEquals("u1::u2::U", b6);
551
IBinding b7 = getBindingFromASTName("U _u7;", 1);
552
assertQNEquals("u1::u2::U", b7);
553
IBinding b8 = getBindingFromASTName("U _u8;", 1);
554
assertQNEquals("n3::c3::s3::u3::U", b8);
555
IBinding b9 = getBindingFromASTName("U _u9;", 1);
556
assertQNEquals("n3::c3::s3::u3::U", b9);
557
IBinding b10 = getBindingFromASTName("U _u10;", 1);
558
assertQNEquals("n3::c3::s3::u3::U", b10);
559
IBinding b11 = getBindingFromASTName("U _u11;", 1);
560
assertQNEquals("n1::n2::U", b11);
561
IBinding b12 = getBindingFromASTName("U _u12;", 1);
562
assertQNEquals("n1::n2::U", b12);
566
// namespace n1 { namespace n2 { class C {}; } }
567
// class c1 { public: class c2 { public: class C {}; }; };
568
// struct s1 { struct s2 { class C {}; }; };
569
// union u1 { union u2 { class C {}; }; };
570
// namespace n3 { class c3 { public: struct s3 { union u3 { class C {}; }; }; }; }
572
// // reference content
573
// void reference() {
574
// ::n1::n2::C _c0; n1::n2::C _c1;
575
// ::c1::c2::C _c2; c1::c2::C _c3;
576
// ::s1::s2::C _c4; s1::s2::C _c5;
577
// ::u1::u2::C _c6; u1::u2::C _c7;
578
// ::n3::c3::s3::u3::C _c8;
579
// n3::c3::s3::u3::C _c9;
581
// namespace n3 { c3::s3::u3::C _c10; }
582
// namespace n1 { n2::C _c11; }
583
// namespace n1 { namespace n2 { C _c12; }}
584
public void testQualifiedNamesForClass() throws DOMException {
585
IBinding b0 = getBindingFromASTName("C _c0;", 1);
586
assertQNEquals("n1::n2::C", b0);
587
IBinding b1 = getBindingFromASTName("C _c1;", 1);
588
assertQNEquals("n1::n2::C", b1);
589
IBinding b2 = getBindingFromASTName("C _c2;", 1);
590
assertQNEquals("c1::c2::C", b2);
591
IBinding b3 = getBindingFromASTName("C _c3;", 1);
592
assertQNEquals("c1::c2::C", b3);
593
IBinding b4 = getBindingFromASTName("C _c4;", 1);
594
assertQNEquals("s1::s2::C", b4);
595
IBinding b5 = getBindingFromASTName("C _c5;", 1);
596
assertQNEquals("s1::s2::C", b5);
597
IBinding b6 = getBindingFromASTName("C _c6;", 1);
598
assertQNEquals("u1::u2::C", b6);
599
IBinding b7 = getBindingFromASTName("C _c7;", 1);
600
assertQNEquals("u1::u2::C", b7);
601
IBinding b8 = getBindingFromASTName("C _c8;", 1);
602
assertQNEquals("n3::c3::s3::u3::C", b8);
603
IBinding b9 = getBindingFromASTName("C _c9;", 1);
604
assertQNEquals("n3::c3::s3::u3::C", b9);
605
IBinding b10 = getBindingFromASTName("C _c10;", 1);
606
assertQNEquals("n3::c3::s3::u3::C", b10);
607
IBinding b11 = getBindingFromASTName("C _c11;", 1);
608
assertQNEquals("n1::n2::C", b11);
609
IBinding b12 = getBindingFromASTName("C _c12;", 1);
610
assertQNEquals("n1::n2::C", b12);
614
// namespace n1 { namespace n2 { typedef int Int; } }
615
// class c1 { public: class c2 { public: typedef int Int; }; };
616
// struct s1 { struct s2 { typedef int Int; }; };
617
// union u1 { struct u2 { typedef int Int; }; };
618
// namespace n3 { class c3 { public: struct s3 { union u3 { typedef int Int; }; }; }; }
620
// // reference content
621
// void reference() {
622
// ::n1::n2::Int i0; n1::n2::Int i1;
623
// ::c1::c2::Int i2; c1::c2::Int i3;
624
// ::s1::s2::Int i4; s1::s2::Int i5;
625
// ::u1::u2::Int i6; u1::u2::Int i7;
626
// ::n3::c3::s3::u3::Int i8;
627
// n3::c3::s3::u3::Int i9;
629
// namespace n3 { c3::s3::u3::Int i10; }
630
// namespace n1 { n2::Int i11; }
631
// namespace n1 { namespace n2 { Int i12; }}
632
public void testQualifiedNamesForTypedef() throws DOMException {
633
IBinding b0 = getBindingFromASTName("Int i0;", 3);
634
assertQNEquals("n1::n2::Int", b0);
635
IBinding b1= getBindingFromASTName("Int i1;", 3);
636
assertQNEquals("n1::n2::Int", b1);
638
IBinding b2 = getBindingFromASTName("Int i2;", 3);
639
assertQNEquals("c1::c2::Int", b2);
640
IBinding b3 = getBindingFromASTName("Int i3;", 3);
641
assertQNEquals("c1::c2::Int", b3);
643
IBinding b4 = getBindingFromASTName("Int i4;", 3);
644
assertQNEquals("s1::s2::Int", b4);
645
IBinding b5 = getBindingFromASTName("Int i5;", 3);
646
assertQNEquals("s1::s2::Int", b5);
648
IBinding b6 = getBindingFromASTName("Int i6;", 3);
649
assertQNEquals("u1::u2::Int", b6);
650
IBinding b7 = getBindingFromASTName("Int i7;", 3);
651
assertQNEquals("u1::u2::Int", b7);
653
IBinding b8 = getBindingFromASTName("Int i8;", 3);
654
assertQNEquals("n3::c3::s3::u3::Int", b8);
655
IBinding b9 = getBindingFromASTName("Int i9;", 3);
656
assertQNEquals("n3::c3::s3::u3::Int", b9);
657
IBinding b10 = getBindingFromASTName("Int i10;", 3);
658
assertQNEquals("n3::c3::s3::u3::Int", b10);
659
IBinding b11 = getBindingFromASTName("Int i11;", 3);
660
assertQNEquals("n1::n2::Int", b11);
661
IBinding b12 = getBindingFromASTName("Int i12;", 3);
662
assertQNEquals("n1::n2::Int", b12);
666
// enum E { ER1, ER2 };
668
// // referencing content
672
// void m1() { e1 = ER1; }
673
// static void m2() { e2 = ER2; }
675
public void testEnumeratorInClassScope() {
676
IBinding b0 = getBindingFromASTName("E e1", 1);
677
IBinding b1 = getBindingFromASTName("ER1; }", 3);
678
IBinding b2 = getBindingFromASTName("ER2; }", 3);
682
// enum E { ER1, ER2 };
684
// // referencing content
688
// void m1() { e1 = ER1; }
689
// static void m2() { e2 = ER2; }
691
public void testEnumeratorInStructScope() {
692
IBinding b0 = getBindingFromASTName("E e1", 1);
693
IBinding b1 = getBindingFromASTName("ER1; }", 3);
694
IBinding b2 = getBindingFromASTName("ER2; }", 3);
698
// enum E { ER1, ER2 };
700
// // referencing content
704
// void m1() { e1 = ER1; }
705
// static void m2() { e2 = ER2; }
707
public void testEnumeratorInUnionScope() {
708
IBinding b0 = getBindingFromASTName("E e1", 1);
709
IBinding b1 = getBindingFromASTName("ER1; }", 3);
710
IBinding b2 = getBindingFromASTName("ER2; }", 3);
714
// enum E { ER1, ER2 };
716
// // referencing content
720
// void f1() { e1 = ER1; }
721
// static void f2() { e2 = ER2; }
723
public void testEnumeratorInNamespaceScope() {
724
IBinding b0 = getBindingFromASTName("E e1", 1);
725
IBinding b1 = getBindingFromASTName("ER1; }", 3);
726
IBinding b2 = getBindingFromASTName("ER2; }", 3);
730
// void foo(int a=2, int b=3);
732
// #include "header.h"
733
// void ref() { foo(); }
734
public void testFunctionDefaultArguments() {
735
IBinding b0 = getBindingFromASTName("foo();", 3);
741
// const TYPE* foo(int a);
744
// #include "header.h"
745
// const TYPE* ns::foo(int a) { return 0; }
746
public void testTypeQualifier() {
747
IBinding b0 = getBindingFromASTName("foo(", 3);
751
// class Base { public: void foo(int i) {} };
752
// class Derived : public Base { public: void foo(long l) {} };
755
// #include "header.h"
756
// void references() {
758
// d.foo(55L); // calls long version
759
// d.foo(4); // also calls long version (int version is hidden)
760
// // aftodo - does this test make sense?
762
public void testMethodHidingInInheritance() {
763
IBinding b0 = getBindingFromASTName("d; /*d*/", 1);
764
IBinding b1 = getBindingFromASTName("foo(55L);", 3);
765
IBinding b2 = getBindingFromASTName("foo(4);", 3);
769
// namespace x { namespace y { int i; } }
772
// #include "header.h"
784
public void testGQualifiedReference() {
785
IBinding b0 = getBindingFromASTName("x::y::i++", 1);
786
assertTrue(ICPPNamespace.class.isInstance(b0));
787
IBinding b1 = getBindingFromASTName("y::i++", 1);
788
assertTrue(ICPPNamespace.class.isInstance(b1));
789
IBinding b2 = getBindingFromASTName("i++", 1);
790
assertTrue(ICPPVariable.class.isInstance(b2));
791
IBinding b3 = getBindingFromASTName("x::y::j++", 1);
792
assertTrue(ICPPClassType.class.isInstance(b3));
793
IBinding b4 = getBindingFromASTName("y::j++", 1);
794
assertTrue(ICPPClassType.class.isInstance(b4));
795
IBinding b5 = getBindingFromASTName("j++", 1);
796
assertTrue(ICPPVariable.class.isInstance(b5));
802
//struct SS { S s, *sp; };
804
//S* retsptr() {return 0;}
805
//S rets() { return *new S(); }
810
////reference content
811
//void references() {
812
// a[0]->i/*0*/++; (*a[0]).i/*1*/++; // IASTArraySubscriptExpression
813
// /* not applicable ?? */ // IASTBinaryExpression
814
// ((S*)sp)->i/*3*/++; ((S)s).i/*4*/++; //aftodo-valid? // IASTCastExpression
815
// (true ? sp : sp)->i/*5*/++; (true ? s : s).i/*6*/++; // IASTConditionalExpression
816
// (sp,sp)->i/*7*/++; (s,s).i/*8*/++; // IASTExpressionList
817
// ss.sp->i/*9*/++; ss.s.i/*10*/++; // IASTFieldReference
818
// ssp->sp->i/*11*/++; ssp->s.i/*12*/++; // IASTFieldReference
819
// retsptr()->i/*13*/++; rets().i/*14*/++; // IASTFunctionCallExpression
820
// sp->i/*15*/++; s.i/*16*/++; // IASTIdExpression
821
// /* not applicable */ // IASTLiteralExpression
822
// /* not applicable */ // IASTTypeIdExpression
823
// (*sp).i/*17*/++; // IASTUnaryExpression
824
// /* not applicable */ // ICPPASTDeleteExpression
825
// (new S())->i/*18*/++; // ICPPASTNewExpression
827
public void testFieldReference() {
828
IBinding b0 = getBindingFromASTName("i/*0*/", 1);
829
IBinding b1 = getBindingFromASTName("i/*1*/", 1);
830
// IBinding b2 = getBindingFromASTName(ast, "i/*2*/", 1);
831
IBinding b3 = getBindingFromASTName("i/*3*/", 1);
832
IBinding b4 = getBindingFromASTName("i/*4*/", 1);
833
IBinding b5 = getBindingFromASTName("i/*5*/", 1);
834
IBinding b6 = getBindingFromASTName("i/*6*/", 1);
835
IBinding b7 = getBindingFromASTName("i/*7*/", 1);
836
IBinding b8 = getBindingFromASTName("i/*8*/", 1);
837
IBinding b9 = getBindingFromASTName("i/*9*/", 1);
838
IBinding b10 = getBindingFromASTName("i/*10*/", 1);
839
IBinding b11 = getBindingFromASTName("i/*11*/", 1);
840
IBinding b12 = getBindingFromASTName("i/*12*/", 1);
841
IBinding b13 = getBindingFromASTName("i/*13*/", 1);
842
IBinding b14 = getBindingFromASTName("i/*14*/", 1);
843
IBinding b15 = getBindingFromASTName("i/*15*/", 1);
844
IBinding b16 = getBindingFromASTName("i/*16*/", 1);
845
IBinding b17 = getBindingFromASTName("i/*17*/", 1);
846
IBinding b18 = getBindingFromASTName("i/*18*/", 1);
851
// class C {public: C* cp;};
855
// int foo(int i, C c);
857
// // referencing content
858
// #include "header.h"
859
// void references() {
861
// foo/*a*/(cp[1]); // IASTArraySubscriptExpression
862
// foo/*b*/(cp+1); // IASTBinaryExpression
863
// foo/*c*/((C*) cp);/*1*/ // IASTCastExpression
864
// foo/*d*/(true ? c : c);/*2*/ // IASTConditionalExpression
865
// foo/*e*/(5, c);/*3*/ // IASTExpressionList
866
// foo/*f*/(c.cp);/*4*/ foo(cp->cp);/*5*/ // IASTFieldReference
867
// foo/*g*/(foo(c));/*6*/ foo(foo(1));/*7*/// IASTFunctionCallExpression
868
// foo/*h*/(c);/*8*/ // IASTIdExpression
869
// foo/*i*/(23489); // IASTLiteralExpression
870
// foo/*j*/(sizeof(C));/*9*/ // IASTTypeIdExpression
871
// foo/*k*/(*cp);/*10*/ // IASTUnaryExpression
872
// foo/*l*/(delete cp);/*11*/ // ICPPASTDeleteExpression
873
// foo/*m*/(new C());/*12*/ // ICPPASTNewExpression
874
// // ?? foo/*n*/(); // ICPPASTSimpleTypeConstructorExpression
875
// // ?? foo/*o*/(); // ICPPASTTypenameExprssion
876
// // foo/*p*/(MADE_UP_SYMBOL); // ICPPASTTypenameExprssion
878
public void testExpressionKindForFunctionCalls() {
879
// depends on bug 164470 because resolution takes place during parse.
880
IBinding b0 = getBindingFromASTName("foo/*a*/", 3);
881
IBinding b0a = getBindingFromASTName("cp[1]", 2);
882
// assertCompositeTypeParam(0, ICPPClassType.k_class, b0, "C");
884
IBinding b1 = getBindingFromASTName("foo/*b*/", 3);
885
IBinding b1a = getBindingFromASTName("cp+1", 2);
887
IBinding b2 = getBindingFromASTName("foo/*c*/", 3);
888
IBinding b2a = getBindingFromASTName("cp);/*1*/", 2);
890
IBinding b3 = getBindingFromASTName("foo/*d*/", 3);
891
IBinding b3a = getBindingFromASTName("c : c", 1);
892
IBinding b3b = getBindingFromASTName("c);/*2*/", 1);
894
IBinding b4 = getBindingFromASTName("foo/*e*/", 3);
895
IBinding b4a = getBindingFromASTName("c);/*3*/", 1);
897
IBinding b5 = getBindingFromASTName("cp);/*4*/", 2);
898
IBinding b5a = getBindingFromASTName("foo/*f*/", 3);
899
IBinding b5b = getBindingFromASTName("cp->cp);/*5*/", 2);
900
IBinding b5c = getBindingFromASTName("cp);/*5*/", 2);
902
IBinding b6 = getBindingFromASTName("foo/*g*/", 3);
903
IBinding b6a = getBindingFromASTName("foo(c));/*6*/", 3);
904
IBinding b6b = getBindingFromASTName("c));/*6*/", 1);
905
IBinding b6c = getBindingFromASTName("foo(foo(1));/*7*/", 3);
906
IBinding b6d = getBindingFromASTName("foo(1));/*7*/", 3);
908
IBinding b7 = getBindingFromASTName("foo/*h*/", 3);
909
IBinding b7a = getBindingFromASTName("c);/*8*/", 1);
911
IBinding b8 = getBindingFromASTName("foo/*i*/", 3);
913
IBinding b9 = getBindingFromASTName("foo/*j*/", 3);
914
IBinding b9a = getBindingFromASTName("C));/*9*/", 1);
916
IBinding b10 = getBindingFromASTName("foo/*k*/", 3);
917
IBinding b10a = getBindingFromASTName("cp);/*10*/", 2);
919
IBinding b11 = getBindingFromASTName("foo/*l*/", 3);
920
IBinding b11a = getBindingFromASTName("cp);/*11*/", 2);
922
IBinding b12 = getBindingFromASTName("foo/*m*/", 3);
923
IBinding b12a = getBindingFromASTName("C());/*12*/", 1);
924
// IBinding b13 = getBindingFromASTName(ast, "foo/*n*/", 3);
929
// typedef int i1; typedef long *lp1;
930
// class C1 {}; struct S1 {}; union U1 {}; enum E1 {A1};
932
// struct S { public:
933
// typedef int i2; typedef long *lp2;
934
// class C2 {}; struct S2 {}; union U2 {}; enum E2 {A2};
937
// typedef int i3; typedef long *lp3;
938
// class C3 {}; struct S3 {}; union U3 {}; enum E3 {A3};
942
// typedef int i4; typedef long *lp4;
943
// class C4 {}; struct S4 {}; union U4 {}; enum E4 {A4};
947
// void f(C); void f(C::i1); void f(C::lp1); void f(C::S1); void f(C::U1); void f(C::E1);
948
// void f(S); void f(S::i2); void f(S::lp2); void f(S::S2); void f(S::U2); void f(S::E2);
949
// void f(U); void f(U::i3); void f(U::lp3); void f(U::S3); void f(U::U3); void f(U::E3);
950
// void f(n::i4); void f(n::lp4); void f(n::S4); void f(n::U4); void f(n::E4);
953
// // reference content
954
// #include "header.h"
955
// void references() {
956
// void (*fintptr)(int), (*flongptr)(long);
957
// void (*fC)(C), (*fCi1)(C::i1), (*fClp1)(C::lp1), (*fCS1)(C::S1), (*fCU1)(C::U1), (*fCE1)(C::E1);
958
// void (*fS)(S), (*fSi2)(S::i2), (*fSlp2)(S::lp2), (*fSS2)(S::S2), (*fSU2)(S::U2), (*fSE2)(S::E2);
959
// void (*fU)(U), (*fUi3)(U::i3), (*fUlp3)(U::lp3), (*fUS3)(U::S3), (*fUU3)(U::U3), (*fUE3)(U::E3);
960
// void (*fni4)(n::i4), (*fnlp4)(n::lp4), (*fnS4)(n::S4), (*fnU4)(n::U4), (*fnE4)(n::E4);
962
// fintptr = &f;/*0*/ flongptr = &f;/*1*/
963
// fC = &f;/*2*/ fCi1 = &f;/*3*/ fClp1 = &f;/*4*/ fCS1 = &f;/*5*/ fCU1 = &f;/*6*/ fCE1 = &f;/*7*/
964
// fS = &f;/*8*/ fSi2 = &f;/*9*/ fSlp2 = &f;/*10*/ fSS2 = &f;/*11*/ fSU2 = &f;/*12*/ fSE2 = &f;/*13*/
965
// fU = &f;/*14*/ fUi3 = &f;/*15*/ fUlp3 = &f;/*16*/ fUS3 = &f;/*17*/ fUU3 = &f;/*18*/ fUE3 = &f;/*19*/
966
// fni4 = &f;/*20*/ fnlp4 = &f;/*21*/ fnS4 = &f;/*22*/ fnU4 = &f;/*23*/ fnE4 = &f;/*24*/
969
public void testAddressOfOverloadedFunction() throws DOMException {
970
IBinding b0 = getBindingFromASTName("f;/*0*/", 1);
971
IBinding b1 = getBindingFromASTName("f;/*1*/", 1);
972
IBinding b2 = getBindingFromASTName("f;/*2*/", 1);
973
IBinding b3 = getBindingFromASTName("f;/*3*/", 1);
974
IBinding b4 = getBindingFromASTName("f;/*4*/", 1);
975
IBinding b5 = getBindingFromASTName("f;/*5*/", 1);
976
IBinding b6 = getBindingFromASTName("f;/*6*/", 1);
977
IBinding b7 = getBindingFromASTName("f;/*7*/", 1);
978
IBinding b8 = getBindingFromASTName("f;/*8*/", 1);
979
IBinding b9 = getBindingFromASTName("f;/*9*/", 1);
980
IBinding b10= getBindingFromASTName("f;/*10*/", 1);
981
IBinding b11 = getBindingFromASTName("f;/*11*/", 1);
982
IBinding b12 = getBindingFromASTName("f;/*12*/", 1);
983
IBinding b13 = getBindingFromASTName("f;/*13*/", 1);
984
IBinding b14 = getBindingFromASTName("f;/*14*/", 1);
985
IBinding b15 = getBindingFromASTName("f;/*15*/", 1);
986
IBinding b16 = getBindingFromASTName("f;/*16*/", 1);
987
IBinding b17 = getBindingFromASTName("f;/*17*/", 1);
988
IBinding b18 = getBindingFromASTName("f;/*18*/", 1);
989
IBinding b19 = getBindingFromASTName("f;/*19*/", 1);
990
IBinding b20 = getBindingFromASTName("f;/*20*/", 1);
991
IBinding b21 = getBindingFromASTName("f;/*21*/", 1);
992
IBinding b22 = getBindingFromASTName("f;/*22*/", 1);
993
IBinding b23 = getBindingFromASTName("f;/*23*/", 1);
994
IBinding b24 = getBindingFromASTName("f;/*24*/", 1);
999
// int m2(int a) const;
1002
// C* func(int (C::*m)(int) const);
1003
// C* func(int (C::*m)(int));
1009
public void testAddressOfConstMethod_233889() throws Exception {
1010
IBinding fn1= getBindingFromASTName("func(&C::m1", 4, ICPPFunction.class);
1011
IBinding fn2= getBindingFromASTName("func(&C::m2", 4, ICPPFunction.class);
1012
assertNotSame(fn1, fn2);
1017
// void f_const_int(const int);
1018
// void f_int_ptr(int*);
1020
// #include "header.h"
1023
// const int const_int = 0;
1026
// f_int(const_int); // ok (passed as value)
1027
// f_const_int(i); // ok
1028
// f_const_int(const_int); // ok
1031
// void f_const_int(const int const_int) {
1032
// f_int_ptr(&const_int); // error
1034
public void testConstIntParameter() {
1035
getBindingFromASTName("f_int(i)", 5);
1036
getBindingFromASTName("f_int(const_int)", 5);
1037
getBindingFromASTName("f_const_int(i)", 11);
1038
getBindingFromASTName("f_const_int(const_int)", 11);
1039
getProblemFromASTName("f_int_ptr(&const_int)", 9);
1043
// void f_int_ptr(int*);
1044
// void f_const_int_ptr(const int*);
1045
// void f_int_const_ptr(int const*);
1046
// void f_int_ptr_const(int *const);
1047
// void f_const_int_ptr_const(const int*const);
1048
// void f_int_const_ptr_const(int const*const);
1050
// #include "header.h"
1052
// int* int_ptr = 0;
1053
// const int* const_int_ptr = 0;
1054
// int const* int_const_ptr = 0;
1055
// int *const int_ptr_const = 0;
1056
// const int*const const_int_ptr_const = 0;
1057
// int const*const int_const_ptr_const = 0;
1059
// f_int_ptr(int_ptr); // ok
1060
// f_int_ptr(const_int_ptr); // error
1061
// f_int_ptr(int_const_ptr); // error
1062
// f_int_ptr(int_ptr_const); // ok
1063
// f_int_ptr(const_int_ptr_const); // error
1064
// f_int_ptr(int_const_ptr_const); // error
1066
// f_const_int_ptr(int_ptr); // ok
1067
// f_const_int_ptr(const_int_ptr); // ok
1068
// f_const_int_ptr(int_const_ptr); // ok
1069
// f_const_int_ptr(int_ptr_const); // ok
1070
// f_const_int_ptr(const_int_ptr_const); // ok
1071
// f_const_int_ptr(int_const_ptr_const); // ok
1073
// f_int_const_ptr(int_ptr); // ok
1074
// f_int_const_ptr(const_int_ptr); // ok
1075
// f_int_const_ptr(int_const_ptr); // ok
1076
// f_int_const_ptr(int_ptr_const); // ok
1077
// f_int_const_ptr(const_int_ptr_const); // ok
1078
// f_int_const_ptr(int_const_ptr_const); // ok
1080
// f_int_ptr_const(int_ptr); // ok
1081
// f_int_ptr_const(const_int_ptr); // error
1082
// f_int_ptr_const(int_const_ptr); // error
1083
// f_int_ptr_const(int_ptr_const); // ok
1084
// f_int_ptr_const(const_int_ptr_const); // error
1085
// f_int_ptr_const(int_const_ptr_const); // error
1087
// f_const_int_ptr_const(int_ptr); // ok
1088
// f_const_int_ptr_const(const_int_ptr); // ok
1089
// f_const_int_ptr_const(int_const_ptr); // ok
1090
// f_const_int_ptr_const(int_ptr_const); // ok
1091
// f_const_int_ptr_const(const_int_ptr_const); // ok
1092
// f_const_int_ptr_const(int_const_ptr_const); // ok
1094
// f_int_const_ptr_const(int_ptr); // ok
1095
// f_int_const_ptr_const(const_int_ptr); // ok
1096
// f_int_const_ptr_const(int_const_ptr); // ok
1097
// f_int_const_ptr_const(int_ptr_const); // ok
1098
// f_int_const_ptr_const(const_int_ptr_const); // ok
1099
// f_int_const_ptr_const(int_const_ptr_const); // ok
1101
public void testConstIntPtrParameter() {
1102
getBindingFromASTName("f_int_ptr(int_ptr)", 9);
1103
getProblemFromASTName("f_int_ptr(const_int_ptr)", 9);
1104
getProblemFromASTName("f_int_ptr(int_const_ptr)", 9);
1105
getBindingFromASTName("f_int_ptr(int_ptr_const)", 9);
1106
getProblemFromASTName("f_int_ptr(const_int_ptr_const)", 9);
1107
getProblemFromASTName("f_int_ptr(int_const_ptr_const)", 9);
1109
getBindingFromASTName("f_const_int_ptr(int_ptr)", 15);
1110
getBindingFromASTName("f_const_int_ptr(const_int_ptr)", 15);
1111
getBindingFromASTName("f_const_int_ptr(int_const_ptr)", 15);
1112
getBindingFromASTName("f_const_int_ptr(int_ptr_const)", 15);
1113
getBindingFromASTName("f_const_int_ptr(const_int_ptr_const)", 15);
1114
getBindingFromASTName("f_const_int_ptr(int_const_ptr_const)", 15);
1116
getBindingFromASTName("f_int_const_ptr(int_ptr)", 15);
1117
getBindingFromASTName("f_int_const_ptr(const_int_ptr)", 15);
1118
getBindingFromASTName("f_int_const_ptr(int_const_ptr)", 15);
1119
getBindingFromASTName("f_int_const_ptr(int_ptr_const)", 15);
1120
getBindingFromASTName("f_int_const_ptr(const_int_ptr_const)", 15);
1121
getBindingFromASTName("f_int_const_ptr(int_const_ptr_const)", 15);
1123
getBindingFromASTName("f_int_ptr_const(int_ptr)", 15);
1124
getProblemFromASTName("f_int_ptr_const(const_int_ptr)", 15);
1125
getProblemFromASTName("f_int_ptr_const(int_const_ptr)", 15);
1126
getBindingFromASTName("f_int_ptr_const(int_ptr_const)", 15);
1127
getProblemFromASTName("f_int_ptr_const(const_int_ptr_const)", 15);
1128
getProblemFromASTName("f_int_ptr_const(int_const_ptr_const)", 15);
1130
getBindingFromASTName("f_const_int_ptr_const(int_ptr)", 21);
1131
getBindingFromASTName("f_const_int_ptr_const(const_int_ptr)", 21);
1132
getBindingFromASTName("f_const_int_ptr_const(int_const_ptr)", 21);
1133
getBindingFromASTName("f_const_int_ptr_const(int_ptr_const)", 21);
1134
getBindingFromASTName("f_const_int_ptr_const(const_int_ptr_const)", 21);
1135
getBindingFromASTName("f_const_int_ptr_const(int_const_ptr_const)", 21);
1137
getBindingFromASTName("f_int_const_ptr_const(int_ptr)", 21);
1138
getBindingFromASTName("f_int_const_ptr_const(const_int_ptr)", 21);
1139
getBindingFromASTName("f_int_const_ptr_const(int_const_ptr)", 21);
1140
getBindingFromASTName("f_int_const_ptr_const(int_ptr_const)", 21);
1141
getBindingFromASTName("f_int_const_ptr_const(const_int_ptr_const)", 21);
1142
getBindingFromASTName("f_int_const_ptr_const(int_const_ptr_const)", 21);
1147
// void f(int*){} // b1
1148
// void f(const int*){} // b2
1149
// void f(int const*){} // b2, redef
1150
// void f(int *const){} // b1, redef
1151
// void f(const int*const){} // b2, redef
1152
// void f(int const*const){} // b2, redef
1153
public void testConstIntPtrParameterInDefinitionAST() throws CoreException {
1154
IBinding binding1= getBindingFromASTName("f(int*){}", 1);
1155
IBinding binding2= getBindingFromASTName("f(const int*){}", 1);
1156
getProblemFromASTName("f(int const*){}", 1);
1157
getProblemFromASTName("f(int *const){}", 1);
1158
getProblemFromASTName("f(const int*const){}", 1);
1159
getProblemFromASTName("f(int const*const){}", 1);
1164
// void f(int&){} // b1
1165
// void f(const int&){} // b2
1166
// void f(int const&){} // b2, redef
1167
public void testConstIntRefParameterInDefinitionAST() throws CoreException {
1168
IBinding binding1= getBindingFromASTName("f(int&){}", 1);
1169
IBinding binding2= getBindingFromASTName("f(const int&){}", 1);
1170
getProblemFromASTName("f(int const&){}", 1);
1175
// void f(int*); // b1
1176
// void f(const int*); // b2
1177
// void f(int const*); // b2
1178
// void f(int *const); // b1
1179
// void f(const int*const); // b2
1180
// void f(int const*const); // b2
1182
// void f(int*){} // b1
1183
// void f(const int*){} // b2
1186
// int* int_ptr = 0;
1187
// const int* const_int_ptr = 0;
1188
// int const* int_const_ptr = 0;
1189
// int *const int_ptr_const = 0;
1190
// const int*const const_int_ptr_const = 0;
1191
// int const*const int_const_ptr_const = 0;
1193
// f(int_ptr); // b1
1194
// f(const_int_ptr); // b2
1195
// f(int_const_ptr); // b2
1196
// f(int_ptr_const); // b1
1197
// f(const_int_ptr_const); // b2
1198
// f(int_const_ptr_const); // b2
1200
public void testConstIntPtrParameterInDefinitionAST2() throws CoreException {
1201
IBinding binding1= getBindingFromASTName("f(int*){}", 1);
1202
IBinding binding2= getBindingFromASTName("f(const int*){}", 1);
1204
assertEquals(binding1, getBindingFromASTName("f(int_ptr)", 1));
1205
assertEquals(binding2, getBindingFromASTName("f(const_int_ptr)", 1));
1206
assertEquals(binding2, getBindingFromASTName("f(int_const_ptr)", 1));
1207
assertEquals(binding1, getBindingFromASTName("f(int_ptr_const)", 1));
1208
assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1));
1209
assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1));
1213
// void f(int*); // b1
1214
// void f(const int*); // b2
1215
// void f(int const*); // b2
1216
// void f(int *const); // b1
1217
// void f(const int*const); // b2
1218
// void f(int const*const); // b2
1220
// #include "header.h"
1221
// void f(int*){} // b1
1222
// void f(const int*){} // b2
1225
// int* int_ptr = 0;
1226
// const int* const_int_ptr = 0;
1227
// int const* int_const_ptr = 0;
1228
// int *const int_ptr_const = 0;
1229
// const int*const const_int_ptr_const = 0;
1230
// int const*const int_const_ptr_const = 0;
1232
// f(int_ptr); // b1
1233
// f(const_int_ptr); // b2
1234
// f(int_const_ptr); // b2
1235
// f(int_ptr_const); // b1
1236
// f(const_int_ptr_const); // b2
1237
// f(int_const_ptr_const); // b2
1239
public void testConstIntPtrParameterInDefinition() throws CoreException {
1240
IBinding binding1= getBindingFromASTName("f(int*){}", 1);
1241
IBinding binding2= getBindingFromASTName("f(const int*){}", 1);
1243
assertEquals(binding1, getBindingFromASTName("f(int_ptr)", 1));
1244
assertEquals(binding2, getBindingFromASTName("f(const_int_ptr)", 1));
1245
assertEquals(binding2, getBindingFromASTName("f(int_const_ptr)", 1));
1246
assertEquals(binding1, getBindingFromASTName("f(int_ptr_const)", 1));
1247
assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1));
1248
assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1));
1250
assertEquals(2, getIndex().findNames(binding1, IIndex.FIND_DECLARATIONS).length);
1251
assertEquals(4, getIndex().findNames(binding2, IIndex.FIND_DECLARATIONS).length);
1252
assertEquals(1, getIndex().findNames(binding1, IIndex.FIND_DEFINITIONS).length);
1253
assertEquals(1, getIndex().findNames(binding2, IIndex.FIND_DEFINITIONS).length);
1257
// struct myStruct {
1264
// // referencing content
1268
// struct myStruct* u;
1269
// union myUnion* v;
1270
// u->a= 1; // since we include the definition, we may use the type.
1271
// v->b= 1; // since we include the definition, we may use the type.
1273
public void testTypeDefinitionWithFwdDeclaration() {
1274
getBindingFromASTName("a= 1", 1);
1275
getBindingFromASTName("b= 1", 1);
1281
// using namespace x;
1284
// #include "header.h"
1288
public void testLegalConflictWithUsingDeclaration() throws Exception {
1289
getBindingFromASTName("a(1)", 1);
1296
// operator B() {B b; return b;}
1298
// class D : public C {};
1301
// class E : public C {};
1310
public void testUserDefinedConversionOperator_224364() throws Exception {
1311
IBinding ca= getBindingFromASTName("C c;", 1);
1312
assertInstance(ca, ICPPClassType.class);
1314
IBinding foo1= getBindingFromASTName("foo(c)", 3);
1316
IBinding da= getBindingFromASTName("D d", 1);
1317
assertInstance(da, ICPPClassType.class);
1319
IBinding foo2= getBindingFromASTName("foo(d)", 3);
1320
IBinding foo3= getBindingFromASTName("foo(e)", 3);
1323
// int a= 1+2-3*4+10/2; // -4
1326
// enum X {e0, e4=4, e5, e2=2, e3};
1329
// a; b; c; e0; e2; e3; e4; e5;
1331
public void testValues() throws Exception {
1332
IVariable v= (IVariable) getBindingFromASTName("a;", 1);
1333
checkValue(v.getInitialValue(), -4);
1334
v= (IVariable) getBindingFromASTName("b;", 1);
1335
checkValue(v.getInitialValue(), 0);
1336
v= (IVariable) getBindingFromASTName("c;", 1);
1337
assertNull(v.getInitialValue().numericalValue());
1339
IEnumerator e= (IEnumerator) getBindingFromASTName("e0", 2);
1340
checkValue(e.getValue(), 0);
1341
e= (IEnumerator) getBindingFromASTName("e2", 2);
1342
checkValue(e.getValue(), 2);
1343
e= (IEnumerator) getBindingFromASTName("e3", 2);
1344
checkValue(e.getValue(), 3);
1345
e= (IEnumerator) getBindingFromASTName("e4", 2);
1346
checkValue(e.getValue(), 4);
1347
e= (IEnumerator) getBindingFromASTName("e5", 2);
1348
checkValue(e.getValue(), 5);
1351
// namespace ns1 { namespace ns2 {
1354
// using namespace ns1::ns2;
1356
// #include "header.h"
1358
public void testUsingDirectiveWithQualifiedName_269727() throws Exception {
1359
getBindingFromASTName("A a", 1, ICPPClassType.class);
1369
// static void m(int p);
1372
// void A::method() {
1376
public void testNestedClass_284665() throws Exception {
1377
ICPPClassType b0 = getBindingFromASTName("B {", 1, ICPPClassType.class);
1378
assertFalse(b0 instanceof IIndexBinding);
1379
ICPPConstructor b1 = getBindingFromASTName("B(int x)", 1, ICPPConstructor.class);
1380
assertFalse(b1 instanceof IIndexBinding);
1381
ICPPConstructor b2 = getBindingFromASTName("B(0)", 1, ICPPConstructor.class);
1382
assertFalse(b2 instanceof IIndexBinding);
1383
assertEquals(b1, b2);
1384
ICPPMethod b3 = getBindingFromASTName("m(0)", 1, ICPPMethod.class);
1385
assertFalse(b3 instanceof IIndexBinding);
1389
// friend inline void m(A p) {}
1395
public void testInlineFriendFunction_284690() throws Exception {
1396
getBindingFromASTName("m(a)", 1, ICPPFunction.class);
1399
private void checkValue(IValue initialValue, int i) {
1400
assertNotNull(initialValue);
1401
final Long numericalValue = initialValue.numericalValue();
1402
assertNotNull(numericalValue);
1403
assertEquals(i, numericalValue.intValue());
1406
/* CPP assertion helpers */
1407
/* ##################################################################### */
1409
static protected void assertField(
1416
assertTrue(binding instanceof ICPPField);
1417
ICPPField field = (ICPPField) binding;
1418
assertQNEquals(qn, field);
1419
assertTrue(expType.isInstance(field.getType()));
1420
if(expTypeQN!=null) {
1421
assert(field.getType() instanceof ICPPBinding);
1422
ICPPBinding tyBinding = (ICPPBinding) field.getType();
1423
assertQNEquals(expTypeQN, tyBinding);
1425
} catch(DOMException de) {
1426
fail(de.getMessage());
1430
static protected void assertClassTypeBinding(IBinding binding,
1437
int declaredMethods,
1438
int allDeclaredMethods,
1441
int nestedClasses) {
1442
assertTrue(binding instanceof ICPPClassType);
1443
assertClassType(((ICPPClassType) binding), qn, key, bases, fields, declaredFields, methods, declaredMethods, allDeclaredMethods, friends, constructors, nestedClasses);
1446
static protected void assertClassType(
1454
int declaredMethods,
1455
int allDeclaredMethods,
1461
assertTrue(type instanceof ICPPClassType);
1462
ICPPClassType classType = (ICPPClassType) type;
1463
assertQNEquals(qn, classType);
1464
assertEquals(key, classType.getKey());
1465
assertEquals(bases, classType.getBases().length);
1466
assertEquals(fields, classType.getFields().length);
1467
assertEquals(declaredFields, classType.getDeclaredFields().length);
1468
assertEquals(methods, classType.getMethods().length);
1469
assertEquals(declaredMethods, classType.getDeclaredMethods().length);
1470
assertEquals(allDeclaredMethods, classType.getAllDeclaredMethods().length);
1471
// assertEquals(friends, classType.getFriends().length); (PDOMNotImplementedError)
1472
assertEquals(constructors, classType.getConstructors().length);
1473
assertEquals(nestedClasses, classType.getNestedClasses().length);
1474
} catch(DOMException de) {
1475
fail(de.getMessage());
1479
public void assertEnumeration(IBinding binding, String name, String[] enumerators) throws DOMException {
1480
assertTrue(binding instanceof IEnumeration);
1481
assertEquals(name, binding.getName());
1482
IEnumerator[] aEnumerators = ((IEnumeration)binding).getEnumerators();
1483
Set expectedEnumerators = new HashSet();
1484
expectedEnumerators.addAll(Arrays.asList(enumerators));
1485
Set actualEnumerators = new HashSet();
1486
for (IEnumerator enumerator : aEnumerators) {
1487
actualEnumerators.add(enumerator.getName());
1489
assertEquals(expectedEnumerators, actualEnumerators);
1495
* @param qn may be null
1497
static protected void assertPTM(IType type, String cqn, String qn) {
1499
assertTrue(type instanceof ICPPPointerToMemberType);
1500
ICPPPointerToMemberType ptmt = (ICPPPointerToMemberType) type;
1501
ICPPClassType classType = (ICPPClassType) ptmt.getMemberOfClass();
1502
assertQNEquals(cqn, classType);
1504
assert(ptmt.getType() instanceof ICPPBinding);
1505
ICPPBinding tyBinding = (ICPPBinding) ptmt.getType();
1506
assertQNEquals(qn, tyBinding);
1508
} catch(DOMException de) {
1509
fail(de.getMessage());