~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2006, 2010 Wind River Systems, Inc. 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
 
7
 *
 
8
 * Contributors:
 
9
 *    Markus Schorn - initial API and implementation
 
10
 *    Andrew Ferguson (Symbian)
 
11
 *******************************************************************************/
 
12
package org.eclipse.cdt.internal.index.tests;
 
13
 
 
14
import java.util.Arrays;
 
15
import java.util.regex.Pattern;
 
16
 
 
17
import junit.framework.TestSuite;
 
18
 
 
19
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
 
20
import org.eclipse.cdt.core.dom.ast.DOMException;
 
21
import org.eclipse.cdt.core.dom.ast.IASTName;
 
22
import org.eclipse.cdt.core.dom.ast.IBinding;
 
23
import org.eclipse.cdt.core.dom.ast.ICompositeType;
 
24
import org.eclipse.cdt.core.dom.ast.IEnumeration;
 
25
import org.eclipse.cdt.core.dom.ast.IField;
 
26
import org.eclipse.cdt.core.dom.ast.IFunction;
 
27
import org.eclipse.cdt.core.dom.ast.IParameter;
 
28
import org.eclipse.cdt.core.dom.ast.IPointerType;
 
29
import org.eclipse.cdt.core.dom.ast.IScope;
 
30
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
 
31
import org.eclipse.cdt.core.dom.ast.IType;
 
32
import org.eclipse.cdt.core.dom.ast.ITypedef;
 
33
import org.eclipse.cdt.core.dom.ast.IVariable;
 
34
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
 
35
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
 
36
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
 
37
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
 
38
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
 
39
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
 
40
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
 
41
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
 
42
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
 
43
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
 
44
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
 
45
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
 
46
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
 
47
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
 
48
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
 
49
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
 
50
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
 
51
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
 
52
import org.eclipse.cdt.core.index.IIndex;
 
53
import org.eclipse.cdt.core.index.IIndexBinding;
 
54
import org.eclipse.cdt.core.index.IIndexMacro;
 
55
import org.eclipse.cdt.core.index.IndexFilter;
 
56
import org.eclipse.cdt.core.parser.util.ObjectMap;
 
57
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPTemplateArgument;
 
58
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
 
59
import org.eclipse.core.runtime.CoreException;
 
60
 
 
61
/**
 
62
 * For testing PDOM binding resolution
 
63
 */
 
64
public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBase {
 
65
 
 
66
        public static class SingleProject extends IndexCPPBindingResolutionBugs {
 
67
                public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));}
 
68
                public static TestSuite suite() {return suite(SingleProject.class);}
 
69
        }
 
70
 
 
71
        public static class ProjectWithDepProj extends IndexCPPBindingResolutionBugs {
 
72
                public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));}
 
73
                public static TestSuite suite() {return suite(ProjectWithDepProj.class);}
 
74
        }
 
75
        
 
76
        public static void addTests(TestSuite suite) {          
 
77
                suite.addTest(IndexCPPBindingResolutionBugsSingleProjectFirstAST.suite());
 
78
                suite.addTest(SingleProject.suite());
 
79
                suite.addTest(ProjectWithDepProj.suite());
 
80
        }
 
81
        
 
82
        public static TestSuite suite() {
 
83
                return suite(IndexCPPBindingResolutionBugs.class);
 
84
        }
 
85
        
 
86
        public IndexCPPBindingResolutionBugs() {
 
87
                setStrategy(new SinglePDOMTestStrategy(true));
 
88
        }
 
89
        
 
90
        // #define OBJ void foo()
 
91
        // #define FUNC() void bar()
 
92
        // #define FUNC2(A) void baz()
 
93
        
 
94
 
 
95
        // #include "header.h"
 
96
        //
 
97
        // OBJ {}
 
98
        // FUNC() {}
 
99
        // FUNC2(1) {}
 
100
        public void testBug208558() throws CoreException {
 
101
                IIndex index= getIndex();
 
102
                
 
103
                IIndexMacro[] macrosA= index.findMacros("OBJ".toCharArray(), IndexFilter.ALL, npm());
 
104
                IIndexMacro[] macrosB= index.findMacros("FUNC".toCharArray(), IndexFilter.ALL, npm());
 
105
                IIndexMacro[] macrosC= index.findMacros("FUNC2".toCharArray(), IndexFilter.ALL, npm());
 
106
                
 
107
                assertEquals(1, macrosA.length);
 
108
                assertEquals(1, macrosB.length);
 
109
                assertEquals(1, macrosC.length);
 
110
                IIndexMacro obj= macrosA[0];
 
111
                IIndexMacro func= macrosB[0];
 
112
                IIndexMacro func2= macrosC[0];
 
113
                
 
114
                assertEquals("OBJ", new String(obj.getName()));
 
115
                assertEquals("FUNC", new String(func.getName()));
 
116
                assertEquals("FUNC2", new String(func2.getName()));
 
117
                
 
118
                assertEquals("void foo()", new String(obj.getExpansionImage()));
 
119
                assertEquals("void bar()", new String(func.getExpansionImage()));
 
120
                assertEquals("void baz()", new String(func2.getExpansionImage()));
 
121
                
 
122
                assertEquals("OBJ", new String(obj.getName()));
 
123
                assertNull(obj.getParameterList());
 
124
                
 
125
                assertEquals("FUNC", new String(func.getName()));
 
126
                assertEquals(0, func.getParameterList().length);
 
127
 
 
128
                assertEquals("FUNC2", new String(func2.getName()));
 
129
                assertEquals(1, func2.getParameterList().length);
 
130
                assertEquals("A", new String(func2.getParameterList()[0]));
 
131
                
 
132
                IIndexBinding[] bindings= index.findBindings(Pattern.compile(".*"), false, IndexFilter.ALL, npm());
 
133
                assertEquals(3, bindings.length);
 
134
                
 
135
                IIndexBinding foo= index.findBindings("foo".toCharArray(), IndexFilter.ALL, npm())[0];
 
136
                IIndexBinding bar= index.findBindings("bar".toCharArray(), IndexFilter.ALL, npm())[0];
 
137
                IIndexBinding baz= index.findBindings("baz".toCharArray(), IndexFilter.ALL, npm())[0];
 
138
                
 
139
                assertEquals("foo", foo.getName());
 
140
                assertEquals("bar", bar.getName());
 
141
                assertEquals("baz", baz.getName());
 
142
                assertInstance(foo, ICPPFunction.class);
 
143
                assertInstance(bar, ICPPFunction.class);
 
144
                assertInstance(baz, ICPPFunction.class);
 
145
        }
 
146
        
 
147
        //      template <class T>
 
148
        //      inline void testTemplate(T& aRef);
 
149
        //
 
150
        //      class Temp {
 
151
        //      };
 
152
 
 
153
        //      void main(void) {
 
154
        //          Temp testFile;
 
155
        //          testTemplate(testFile);
 
156
        //      }
 
157
        public void testBug207320() {
 
158
                IBinding b0= getBindingFromASTName("testTemplate(", 12);
 
159
                assertInstance(b0, ICPPFunction.class);
 
160
                assertInstance(b0, ICPPTemplateInstance.class);
 
161
        }
 
162
        
 
163
        //      class testdef{
 
164
        //
 
165
        //      public:
 
166
        //              void testagain();
 
167
        //      };
 
168
        //
 
169
        //      typedef void TAny;
 
170
        //
 
171
        //      inline void testCall(TAny* aExpected){}
 
172
        //
 
173
        //  testdef*  global_cBase;
 
174
        //  testdef*& global_cBaseRef = global_cBase;
 
175
        
 
176
        //      #include "typedefHeader.h"
 
177
        //
 
178
        //
 
179
        //      int main(void)
 
180
        //              {
 
181
        //                      testdef*  local_cBase;
 
182
        //          testdef*& local_cBaseRef = local_cBase;
 
183
        //              
 
184
        //                      testCall( /*1*/ (void *) local_cBase);
 
185
        //          testCall( /*2*/ local_cBase);
 
186
        //
 
187
        //                      testCall( /*3*/ (void *) local_cBaseRef);
 
188
        //          testCall( /*4*/ local_cBaseRef);
 
189
        //
 
190
        //                      testCall( /*5*/ (void *) global_cBase);
 
191
        //          testCall( /*6*/ global_cBase);
 
192
        //
 
193
        //                      testCall( /*7*/ (void *)global_cBaseRef);
 
194
        //          testCall( /*8*/ global_cBaseRef);
 
195
        //              }
 
196
        public void testBug206187() throws Exception {
 
197
                IBinding b1= getBindingFromASTName("testCall( /*1*/", 8);
 
198
                IBinding b2= getBindingFromASTName("testCall( /*2*/", 8);
 
199
                IBinding b3= getBindingFromASTName("testCall( /*3*/", 8);
 
200
                IBinding b4= getBindingFromASTName("testCall( /*4*/", 8);
 
201
                IBinding b5= getBindingFromASTName("testCall( /*5*/", 8);
 
202
                IBinding b6= getBindingFromASTName("testCall( /*6*/", 8);
 
203
                IBinding b7= getBindingFromASTName("testCall( /*7*/", 8);
 
204
                IBinding b8= getBindingFromASTName("testCall( /*8*/", 8);
 
205
        }
 
206
        
 
207
        
 
208
        // template<typename T1>
 
209
    // class A {};
 
210
    // 
 
211
    // template<typename T2>
 
212
    // class B : public A<T2> {};
 
213
    // 
 
214
    // class C {};
 
215
    //
 
216
    // B<C> b;
 
217
    
 
218
    // void foo() {C c; B<int> b;}
 
219
    public void testBug188274() throws Exception {
 
220
        IBinding b0= getBindingFromASTName("C", 1);
 
221
        IBinding b1= getBindingFromASTName("B", 1);
 
222
        assertInstance(b0, ICPPClassType.class);
 
223
        assertInstance(b1, ICPPClassType.class);
 
224
        assertInstance(b1, ICPPClassTemplate.class);
 
225
        assertInstance(b1, ICPPInstanceCache.class);
 
226
        
 
227
        ICPPInstanceCache ct= (ICPPInstanceCache) b1;
 
228
        ICPPSpecialization inst= ct.getInstance(new ICPPTemplateArgument[]{new CPPTemplateArgument((IType)b0)});
 
229
        assertInstance(inst, ICPPClassType.class);
 
230
        ICPPClassType c2t= (ICPPClassType) inst;
 
231
        ICPPBase[] bases= c2t.getBases();
 
232
        assertEquals(1, bases.length);
 
233
        assertInstance(bases[0].getBaseClass(), ICPPClassType.class);
 
234
    }
 
235
        
 
236
        // namespace ns {class A{};}
 
237
        
 
238
        // ns::A a;
 
239
        // class B {};
 
240
        public void testBug188324() throws Exception {
 
241
                IASTName name= findName("B", 1);
 
242
                IBinding b0= getBindingFromASTName("ns::A", 2);
 
243
                assertInstance(b0, ICPPNamespace.class);
 
244
                ICPPNamespace ns= (ICPPNamespace) b0;
 
245
                assertEquals(0, ns.getNamespaceScope().getBindings(name, false, false).length);
 
246
        }
 
247
        
 
248
        //       template<typename T>
 
249
        //       class C : public C<T> {};
 
250
        
 
251
        //       void foo() {
 
252
        //      C<int>::unresolvable();
 
253
        //   };
 
254
        public void testBug185828() throws Exception {
 
255
                // Bug 185828 reports a StackOverflowException is thrown before we get here.
 
256
                // That the SOE is thrown is detected in BaseTestCase via an Error IStatus
 
257
                
 
258
                IBinding b0= getBindingFromASTName("C<int>", 1);
 
259
                IBinding b1= getBindingFromASTName("C<int>", 6);
 
260
                IBinding b2= getProblemFromASTName("unresolvable", 12);
 
261
                
 
262
                assertInstance(b0, ICPPClassType.class);
 
263
                assertInstance(b0, ICPPClassTemplate.class);
 
264
                
 
265
                assertInstance(b1, ICPPClassType.class);
 
266
                assertInstance(b1, ICPPSpecialization.class);
 
267
        }
 
268
        
 
269
        //      class MyClass {
 
270
        //      public:
 
271
        //              template<class T>
 
272
        //              T* MopGetObject(T*& aPtr) 
 
273
        //                      { return 0; }
 
274
        //                      
 
275
        //              
 
276
        //              template<class T>       
 
277
        //              T*  MopGetObjectNoChaining(T*& aPtr)
 
278
        //              { return 0; }
 
279
        //
 
280
        //      };
 
281
        
 
282
        //      int main() {
 
283
        //              MyClass* cls= new MyClass();
 
284
        //      }
 
285
        public void testBug184216() throws Exception {
 
286
                IBinding b0= getBindingFromASTName("MyClass*", 7);
 
287
                assertInstance(b0, ICPPClassType.class);
 
288
                ICPPClassType ct= (ICPPClassType) b0;
 
289
                ICPPMethod[] ms= ct.getDeclaredMethods(); // 184216 reports CCE thrown
 
290
                assertEquals(2, ms.length);
 
291
                assertInstance(ms[0], ICPPTemplateDefinition.class);
 
292
                assertInstance(ms[1], ICPPTemplateDefinition.class);
 
293
        }
 
294
        
 
295
        // // header file
 
296
        //  class cl;
 
297
        //      typedef cl* t1;
 
298
        //  typedef t1 t2;
 
299
        
 
300
        //// referencing content
 
301
        //  void func(t2 a);
 
302
        //  void func(int b);
 
303
        //  void ref() {
 
304
        //     cl* a;
 
305
        //     func(a);
 
306
        //  }
 
307
        public void testBug166954() {
 
308
                IBinding b0 = getBindingFromASTName("func(a)", 4);
 
309
        }
 
310
        
 
311
        // // header
 
312
        //      class Base { 
 
313
        //  public: 
 
314
        //     void foo(int i);
 
315
        //     int  fooint();
 
316
        //     char* fooovr();
 
317
        //     char* fooovr(int a);
 
318
        //     char* fooovr(char x);
 
319
        //  };
 
320
 
 
321
        // // references
 
322
        // #include "header.h"
 
323
        // void Base::foo(int i) {}
 
324
        // int Base::fooint() {return 0;}
 
325
        // char* Base::fooovr() {return 0;}
 
326
        // char* Base::fooovr(int a) {return 0;}
 
327
        // char* Base::fooovr(char x) {return 0;}
 
328
        //
 
329
        // void refs() {
 
330
        //   Base b;
 
331
        //   b.foo(1);
 
332
        //   b.fooint();
 
333
        //   b.fooovr();
 
334
        //   b.fooovr(1);
 
335
        //   b.fooovr('a');
 
336
        // }
 
337
        public void testBug168020() {
 
338
                getBindingFromASTName("foo(int i)", 3);
 
339
                getBindingFromASTName("fooint()", 6);
 
340
                getBindingFromASTName("fooovr()", 6);
 
341
                getBindingFromASTName("fooovr(int", 6);
 
342
                getBindingFromASTName("fooovr(char", 6);
 
343
 
 
344
                getBindingFromASTName("foo(1)", 3);
 
345
                getBindingFromASTName("fooint();", 6);
 
346
                getBindingFromASTName("fooovr();", 6);
 
347
                getBindingFromASTName("fooovr(1", 6);
 
348
                getBindingFromASTName("fooovr('", 6);
 
349
        }
 
350
 
 
351
        
 
352
        // // header
 
353
        //      class Base { 
 
354
        //  public: 
 
355
        //     void foo(int i);
 
356
        //     int  foo2(int i);
 
357
        //  };
 
358
        //
 
359
        //  void func(int k);
 
360
        //  void func2(int i);
 
361
 
 
362
        // // references
 
363
        // #include "header.h"
 
364
        // void Base::foo(int i) {
 
365
        //   i=2;
 
366
        // }
 
367
        // int Base::foo2(int j) {
 
368
        //   j=2;
 
369
        // }
 
370
        // void func(int k) {
 
371
        //  k=2;
 
372
        // }
 
373
        // void func2(int l) {
 
374
        //  l=2;
 
375
        // }
 
376
        public void testBug168054() {
 
377
                getBindingFromASTName("i=2", 1);
 
378
                getBindingFromASTName("j=2", 1);
 
379
                getBindingFromASTName("k=2", 1);
 
380
                getBindingFromASTName("l=2", 1);
 
381
        }
 
382
        
 
383
        // namespace X {}
 
384
        
 
385
        // namespace Y {
 
386
        //    class Ambiguity {};
 
387
        //    enum Ambiguity {A1,A2,A3};
 
388
        //    void foo() {
 
389
        //       Ambiguity problem;
 
390
        //    }
 
391
        // }
 
392
        public void testBug176708_CCE() throws Exception {
 
393
                IBinding binding= getBindingFromASTName("Y {", 1);
 
394
                assertTrue(binding instanceof ICPPNamespace);
 
395
                ICPPNamespace adapted= (ICPPNamespace) strategy.getIndex().adaptBinding(binding);
 
396
                IASTName name= findName("Ambiguity problem", 9);
 
397
                assertNotNull(name);
 
398
                IBinding binding2= adapted.getNamespaceScope().getBinding(name, true);
 
399
        }
 
400
        
 
401
        // namespace X {int i;}
 
402
        
 
403
        // // references
 
404
        // #include "header.h"
 
405
        // int a= X::i;
 
406
        public void testBug176708_NPE() throws Exception {
 
407
                IBinding binding= getBindingFromASTName("i;", 1);
 
408
                assertTrue(binding instanceof ICPPVariable);
 
409
                IScope scope= binding.getScope();
 
410
        }
 
411
        
 
412
        //      template<class T, class U, class V>
 
413
        //      class A {};
 
414
        
 
415
        //      template<>
 
416
        //      class A<int, bool, double> {};
 
417
        public void testBug180784() throws Exception {
 
418
                IBinding b0= getBindingFromASTName("A<int, bool, double> {};", 20);
 
419
                assertInstance(b0, ICPPSpecialization.class);
 
420
                ICPPSpecialization s= (ICPPSpecialization) b0;
 
421
                ObjectMap map= s.getArgumentMap();
 
422
                IBinding b1= s.getSpecializedBinding();
 
423
                assertInstance(b1, ICPPClassTemplate.class);
 
424
                ICPPClassTemplate t= (ICPPClassTemplate) b1;
 
425
                ICPPTemplateParameter[] ps = t.getTemplateParameters();
 
426
                assertNotNull(ps);
 
427
                assertEquals(3, ps.length);
 
428
                assertNotNull(map.get(ps[0]));
 
429
                assertNotNull(map.get(ps[1]));
 
430
                assertNotNull(map.get(ps[2]));
 
431
        }
 
432
        
 
433
        //      class A{};
 
434
        //
 
435
        //      template<typename T>
 
436
        //      T id (T t) {return t;}
 
437
        //
 
438
        //      template<>
 
439
        //      A id (A a) {return a;}
 
440
        //
 
441
        //      int id(int x) {return x;}
 
442
        
 
443
        //      void foo() {
 
444
        //              id(*new A());
 
445
        //              id(6);
 
446
        //      }
 
447
        public void testBug180948() throws Exception {
 
448
                // Main check occurs in BaseTestCase - that no ClassCastException
 
449
                // is thrown during indexing
 
450
                IBinding b0= getBindingFromASTName("id(*", 2);
 
451
                IBinding b1= getBindingFromASTName("id(6", 2);
 
452
        }
 
453
        
 
454
        
 
455
        // void func1(void);
 
456
        
 
457
        //  #include "header.h"
 
458
        //
 
459
        //      int main(void)
 
460
        //      {
 
461
        //      void* v= func1;
 
462
        //      }
 
463
        public void testBug181735() throws DOMException {
 
464
                IBinding b0 = getBindingFromASTName("func1;", 5);
 
465
                assertTrue(b0 instanceof IFunction);
 
466
        }
 
467
        
 
468
        //      class B {
 
469
        //  public:
 
470
        //              class BB {
 
471
        //              public:
 
472
        //                      int field;
 
473
        //              };
 
474
        //      };
 
475
        //
 
476
        //      class A : public B::BB {};
 
477
        
 
478
        //  #include "header.h"
 
479
        //      
 
480
        //  void foo() {
 
481
        //              A c;
 
482
        //              c.field;//comment
 
483
        //      }
 
484
        public void testBug183843() throws DOMException {
 
485
                IBinding b0 = getBindingFromASTName("field;//", 5);
 
486
                assertTrue(b0 instanceof ICPPField);
 
487
        }
 
488
        
 
489
    // typedef struct {
 
490
    //    int utm;
 
491
    // } usertype;
 
492
    // void func(usertype t);
 
493
 
 
494
        // #include "header.h"
 
495
    // void test() {
 
496
        //    usertype ut;
 
497
        //    func(ut);
 
498
    // }
 
499
    public void testFuncWithTypedefForAnonymousStruct_190730() throws Exception {
 
500
                IBinding b0 = getBindingFromASTName("func(", 4);
 
501
                assertTrue(b0 instanceof IFunction);
 
502
                IFunction f= (IFunction) b0;
 
503
                IParameter[] pars= f.getParameters();
 
504
                assertEquals(1, pars.length);
 
505
                IType type= pars[0].getType();
 
506
                assertTrue(type instanceof ITypedef);
 
507
                type= ((ITypedef) type).getType();
 
508
                assertTrue(type instanceof ICPPClassType);
 
509
    }
 
510
 
 
511
    // typedef enum {
 
512
    //    eItem
 
513
    // } userEnum;
 
514
    // void func(userEnum t);
 
515
 
 
516
        // #include "header.h"
 
517
    // void test() {
 
518
        //    userEnum ut;
 
519
        //    func(ut);
 
520
    // }
 
521
    public void testFuncWithTypedefForAnonymousEnum_190730() throws Exception {
 
522
                IBinding b0 = getBindingFromASTName("func(", 4);
 
523
                assertTrue(b0 instanceof IFunction);
 
524
                IFunction f= (IFunction) b0;
 
525
                IParameter[] pars= f.getParameters();
 
526
                assertEquals(1, pars.length);
 
527
                IType type= pars[0].getType();
 
528
                assertTrue(type instanceof ITypedef);
 
529
                type= ((ITypedef) type).getType();
 
530
                assertTrue(type instanceof IEnumeration);
 
531
    }
 
532
    
 
533
    // // no header needed
 
534
    
 
535
    // typedef class {
 
536
    //    int member;
 
537
    // } t_class;
 
538
    // typedef struct {
 
539
    //    int member;
 
540
    // } t_struct;
 
541
    // typedef union {
 
542
    //    int member;
 
543
    // } t_union;
 
544
    // typedef enum {
 
545
    //    ei
 
546
    // } t_enum;
 
547
        public void testIsSameAnonymousType_Bug193962() throws DOMException {
 
548
                // class
 
549
                IBinding tdAST = getBindingFromASTName("t_class;", 7);
 
550
                assertFalse(tdAST instanceof IIndexBinding);
 
551
                IBinding tdIndex= strategy.getIndex().adaptBinding(tdAST);
 
552
                assertTrue(tdIndex instanceof IIndexBinding);
 
553
                assertTrue(tdAST instanceof ITypedef);
 
554
                assertTrue(tdIndex instanceof ITypedef);
 
555
 
 
556
                IType tAST= ((ITypedef) tdAST).getType();
 
557
                IType tIndex= ((ITypedef) tdIndex).getType();
 
558
                assertTrue(tAST instanceof ICompositeType);
 
559
                assertTrue(tIndex instanceof ICompositeType);
 
560
                assertTrue(tAST.isSameType(tIndex));
 
561
                assertTrue(tIndex.isSameType(tAST));
 
562
 
 
563
                // struct
 
564
                tdAST = getBindingFromASTName("t_struct;", 8);
 
565
                assertFalse(tdAST instanceof IIndexBinding);
 
566
                tdIndex= strategy.getIndex().adaptBinding(tdAST);
 
567
                assertTrue(tdIndex instanceof IIndexBinding);
 
568
                assertTrue(tdAST instanceof ITypedef);
 
569
                assertTrue(tdIndex instanceof ITypedef);
 
570
                
 
571
                tAST= ((ITypedef) tdAST).getType();
 
572
                tIndex= ((ITypedef) tdIndex).getType();
 
573
                assertTrue(tAST instanceof ICompositeType);
 
574
                assertTrue(tIndex instanceof ICompositeType);
 
575
                assertTrue(tAST.isSameType(tIndex));
 
576
                assertTrue(tIndex.isSameType(tAST));
 
577
 
 
578
                // union
 
579
                tdAST = getBindingFromASTName("t_union;", 7);
 
580
                assertFalse(tdAST instanceof IIndexBinding);
 
581
                tdIndex= strategy.getIndex().adaptBinding(tdAST);
 
582
                assertTrue(tdIndex instanceof IIndexBinding);
 
583
                assertTrue(tdAST instanceof ITypedef);
 
584
                assertTrue(tdIndex instanceof ITypedef);
 
585
                
 
586
                tAST= ((ITypedef) tdAST).getType();
 
587
                tIndex= ((ITypedef) tdIndex).getType();
 
588
                assertTrue(tAST instanceof ICompositeType);
 
589
                assertTrue(tIndex instanceof ICompositeType);
 
590
                assertTrue(tAST.isSameType(tIndex));
 
591
                assertTrue(tIndex.isSameType(tAST));
 
592
 
 
593
                // enum
 
594
                tdAST = getBindingFromASTName("t_enum;", 6);
 
595
                assertFalse(tdAST instanceof IIndexBinding);
 
596
                tdIndex= strategy.getIndex().adaptBinding(tdAST);
 
597
                assertTrue(tdIndex instanceof IIndexBinding);
 
598
                assertTrue(tdAST instanceof ITypedef);
 
599
                assertTrue(tdIndex instanceof ITypedef);
 
600
                
 
601
                tAST= ((ITypedef) tdAST).getType();
 
602
                tIndex= ((ITypedef) tdIndex).getType();
 
603
                assertTrue(tAST instanceof IEnumeration);
 
604
                assertTrue(tIndex instanceof IEnumeration);
 
605
                assertTrue(tAST.isSameType(tIndex));
 
606
                assertTrue(tIndex.isSameType(tAST));
 
607
        }
 
608
 
 
609
    // // no header needed
 
610
    
 
611
        // namespace ns {
 
612
    // typedef class {
 
613
    //    int member;
 
614
    // } t_class;
 
615
    // typedef struct {
 
616
    //    int member;
 
617
    // } t_struct;
 
618
    // typedef union {
 
619
    //    int member;
 
620
    // } t_union;
 
621
    // typedef enum {
 
622
    //    ei
 
623
    // } t_enum;
 
624
        // };
 
625
        public void testIsSameNestedAnonymousType_Bug193962() throws DOMException {
 
626
                // class
 
627
                IBinding tdAST = getBindingFromASTName("t_class;", 7);
 
628
                assertFalse(tdAST instanceof IIndexBinding);
 
629
                IBinding tdIndex= strategy.getIndex().adaptBinding(tdAST);
 
630
                assertTrue(tdIndex instanceof IIndexBinding);
 
631
                assertTrue(tdAST instanceof ITypedef);
 
632
                assertTrue(tdIndex instanceof ITypedef);
 
633
 
 
634
                IType tAST= ((ITypedef) tdAST).getType();
 
635
                IType tIndex= ((ITypedef) tdIndex).getType();
 
636
                assertTrue(tAST instanceof ICompositeType);
 
637
                assertTrue(tIndex instanceof ICompositeType);
 
638
                assertTrue(tAST.isSameType(tIndex));
 
639
                assertTrue(tIndex.isSameType(tAST));
 
640
 
 
641
                // struct
 
642
                tdAST = getBindingFromASTName("t_struct;", 8);
 
643
                assertFalse(tdAST instanceof IIndexBinding);
 
644
                tdIndex= strategy.getIndex().adaptBinding(tdAST);
 
645
                assertTrue(tdIndex instanceof IIndexBinding);
 
646
                assertTrue(tdAST instanceof ITypedef);
 
647
                assertTrue(tdIndex instanceof ITypedef);
 
648
                
 
649
                tAST= ((ITypedef) tdAST).getType();
 
650
                tIndex= ((ITypedef) tdIndex).getType();
 
651
                assertTrue(tAST instanceof ICompositeType);
 
652
                assertTrue(tIndex instanceof ICompositeType);
 
653
                assertTrue(tAST.isSameType(tIndex));
 
654
                assertTrue(tIndex.isSameType(tAST));
 
655
 
 
656
                // union
 
657
                tdAST = getBindingFromASTName("t_union;", 7);
 
658
                assertFalse(tdAST instanceof IIndexBinding);
 
659
                tdIndex= strategy.getIndex().adaptBinding(tdAST);
 
660
                assertTrue(tdIndex instanceof IIndexBinding);
 
661
                assertTrue(tdAST instanceof ITypedef);
 
662
                assertTrue(tdIndex instanceof ITypedef);
 
663
                
 
664
                tAST= ((ITypedef) tdAST).getType();
 
665
                tIndex= ((ITypedef) tdIndex).getType();
 
666
                assertTrue(tAST instanceof ICompositeType);
 
667
                assertTrue(tIndex instanceof ICompositeType);
 
668
                assertTrue(tAST.isSameType(tIndex));
 
669
                assertTrue(tIndex.isSameType(tAST));
 
670
 
 
671
                // enum
 
672
                tdAST = getBindingFromASTName("t_enum;", 6);
 
673
                assertFalse(tdAST instanceof IIndexBinding);
 
674
                tdIndex= strategy.getIndex().adaptBinding(tdAST);
 
675
                assertTrue(tdIndex instanceof IIndexBinding);
 
676
                assertTrue(tdAST instanceof ITypedef);
 
677
                assertTrue(tdIndex instanceof ITypedef);
 
678
                
 
679
                tAST= ((ITypedef) tdAST).getType();
 
680
                tIndex= ((ITypedef) tdIndex).getType();
 
681
                assertTrue(tAST instanceof IEnumeration);
 
682
                assertTrue(tIndex instanceof IEnumeration);
 
683
                assertTrue(tAST.isSameType(tIndex));
 
684
                assertTrue(tIndex.isSameType(tAST));
 
685
        }
 
686
        
 
687
        //      namespace FOO {
 
688
        //              namespace BAR {
 
689
        //                  class Bar;
 
690
        //              }
 
691
        //              class Foo {
 
692
        //                      BAR::Bar * Test(BAR::Bar * bar);
 
693
        //              };
 
694
        //      }
 
695
 
 
696
        //      #include "header.h"
 
697
        //      namespace FOO {
 
698
        //          using BAR::Bar;
 
699
        //       
 
700
        //          Bar* Foo::Test(Bar* pBar) {
 
701
        //             return pBar;
 
702
        //          }
 
703
        //      }
 
704
        public void testAdvanceUsingDeclaration_Bug217102() throws Exception {
 
705
                IBinding cl = getBindingFromASTName("Bar* Foo", 3);
 
706
 
 
707
                assertEquals("Bar", cl.getName());
 
708
                assertTrue(cl instanceof ICPPClassType);
 
709
                assertEquals("BAR", cl.getScope().getScopeName().toString());
 
710
 
 
711
                cl = getBindingFromASTName("Bar* pBar", 3);
 
712
                assertEquals("Bar", cl.getName());
 
713
                assertTrue(cl instanceof ICPPClassType);
 
714
                assertEquals("BAR", cl.getScope().getScopeName().toString());
 
715
        }
 
716
        
 
717
        // struct outer {
 
718
        //    union {
 
719
        //       int var1;
 
720
        //    };
 
721
        // };
 
722
          
 
723
        // #include "header.h"
 
724
        // void test() {
 
725
        //    struct outer x;
 
726
        //    x.var1=1;
 
727
        // }
 
728
        public void testAnonymousUnion_Bug216791() throws DOMException {
 
729
                // struct
 
730
                IBinding b = getBindingFromASTName("var1=", 4);
 
731
                assertTrue(b instanceof IField);
 
732
                IField f= (IField) b;
 
733
                IScope outer= f.getCompositeTypeOwner().getScope();
 
734
                assertTrue(outer instanceof ICPPClassScope);
 
735
                assertEquals("outer", outer.getScopeName().toString());
 
736
        }
 
737
 
 
738
        // union outer {
 
739
        //    struct {
 
740
        //       int var1;
 
741
        //    };
 
742
        //    struct {
 
743
        //       int var2;
 
744
        //    } hide;
 
745
        // };
 
746
          
 
747
        // #include "header.h"
 
748
        // void test() {
 
749
        //    union outer x;
 
750
        //    x.var1=1;
 
751
        //    x.var2= 2; // must be a problem
 
752
        // }
 
753
        public void testAnonymousStruct_Bug216791() throws DOMException {
 
754
                // struct
 
755
                IBinding b = getBindingFromASTName("var1=", 4);
 
756
                assertTrue(b instanceof IField);
 
757
                IField f= (IField) b;
 
758
                IScope outer= f.getCompositeTypeOwner().getScope();
 
759
                assertTrue(outer instanceof ICPPClassScope);
 
760
                assertEquals("outer", outer.getScopeName().toString());
 
761
                
 
762
                getProblemFromASTName("var2=", 4);
 
763
        }
 
764
        
 
765
        // namespace ns {
 
766
        // int v;
 
767
        // };
 
768
        // using namespace ns;
 
769
        
 
770
        // #include "header.h"
 
771
        // void test() {
 
772
        //    v=1;
 
773
        // }
 
774
        public void testUsingDirective_Bug216527() throws Exception {
 
775
                IBinding b = getBindingFromASTName("v=", 1);
 
776
                assertTrue(b instanceof IVariable);
 
777
                IVariable v= (IVariable) b;
 
778
                IScope scope= v.getScope();
 
779
                assertTrue(scope instanceof ICPPNamespaceScope);
 
780
                assertEquals("ns", scope.getScopeName().toString());
 
781
        }       
 
782
        
 
783
        // namespace NSA {
 
784
        // int a;
 
785
        // }
 
786
        // namespace NSB {
 
787
        // int b;
 
788
        // }
 
789
        // namespace NSAB {
 
790
        //    using namespace NSA;
 
791
        //    using namespace NSB;
 
792
        // }
 
793
 
 
794
        // #include "header.h"
 
795
        // void f() {
 
796
        //   NSAB::a= NSAB::b;
 
797
        // }
 
798
        public void testNamespaceComposition_Bug200673() throws Exception {
 
799
                IBinding a = getBindingFromASTName("a=", 1);
 
800
                assertTrue(a instanceof IVariable);
 
801
                IVariable v= (IVariable) a;
 
802
                IScope scope= v.getScope();
 
803
                assertTrue(scope instanceof ICPPNamespaceScope);
 
804
                assertEquals("NSA", scope.getScopeName().toString());
 
805
 
 
806
                IBinding b = getBindingFromASTName("b;", 1);
 
807
                assertTrue(b instanceof IVariable);
 
808
                v= (IVariable) b;
 
809
                scope= v.getScope();
 
810
                assertTrue(scope instanceof ICPPNamespaceScope);
 
811
                assertEquals("NSB", scope.getScopeName().toString());
 
812
        }
 
813
        
 
814
        // namespace N { namespace M {}}
 
815
 
 
816
        // namespace N {using namespace N::M;}
 
817
        // using namespace N;
 
818
    // void test() {x;}
 
819
        public void testEndlessLoopWithUsingDeclaration_Bug209813() throws DOMException {
 
820
                getProblemFromASTName("x;", 1);
 
821
        }
 
822
        
 
823
        // class MyClass {};
 
824
        
 
825
        // void test(MyClass* ptr);
 
826
        // class MyClass;
 
827
        public void testClassRedeclarationAfterReference_Bug229571() throws Exception {
 
828
                IBinding cl= getBindingFromASTName("MyClass;", 7);
 
829
                IFunction fn= getBindingFromASTName("test(", 4, IFunction.class);
 
830
                IType type= fn.getType().getParameterTypes()[0];
 
831
                assertInstance(type, IPointerType.class);
 
832
                type= ((IPointerType) type).getType();
 
833
                assertSame(type, cl);
 
834
        }
 
835
        
 
836
    // class A {
 
837
    // public:
 
838
    //    void foo() const volatile;
 
839
    //    void foo() volatile;
 
840
    //    void foo() const;
 
841
    //    void foo();
 
842
    //    void bar() const volatile;
 
843
    //    void bar() volatile;
 
844
    //    void bar() const;
 
845
    //    void bar();
 
846
    // };
 
847
    
 
848
    // void A::foo() const volatile { bar();/*1*/ }
 
849
    // void A::foo() volatile       { bar();/*2*/ }
 
850
    // void A::foo() const          { bar();/*3*/ }
 
851
    // void A::foo()                { bar();/*4*/ }
 
852
    // void test() {
 
853
    //   A a;
 
854
    //   const A ca;
 
855
    //   volatile A va;
 
856
    //   const volatile A cva;
 
857
    //   cva.bar();/*5*/
 
858
    //   va.bar();/*6*/
 
859
    //   ca.bar();/*7*/
 
860
    //   a.bar();/*8*/
 
861
    // }
 
862
    public void testMemberFunctionDisambiguationByCVness_238409() throws Exception {
 
863
        ICPPMethod bar_cv= getBindingFromASTName("bar();/*1*/", 3, ICPPMethod.class);
 
864
        ICPPMethod bar_v=  getBindingFromASTName("bar();/*2*/", 3, ICPPMethod.class);
 
865
        ICPPMethod bar_c=  getBindingFromASTName("bar();/*3*/", 3, ICPPMethod.class);
 
866
        ICPPMethod bar=    getBindingFromASTName("bar();/*4*/", 3, ICPPMethod.class);
 
867
        ICPPFunctionType bar_cv_ft= bar_cv.getType();
 
868
        ICPPFunctionType bar_v_ft=  bar_v.getType();
 
869
        ICPPFunctionType bar_c_ft=  bar_c.getType();
 
870
        ICPPFunctionType bar_ft=    bar.getType();
 
871
        
 
872
        assertTrue(bar_cv_ft.isConst()); assertTrue(bar_cv_ft.isVolatile());
 
873
        assertTrue(!bar_v_ft.isConst()); assertTrue(bar_v_ft.isVolatile());
 
874
        assertTrue(bar_c_ft.isConst());  assertTrue(!bar_c_ft.isVolatile());
 
875
        assertTrue(!bar_ft.isConst());   assertTrue(!bar_ft.isVolatile());
 
876
        
 
877
        bar_cv= getBindingFromASTName("bar();/*5*/", 3, ICPPMethod.class);
 
878
        bar_v=  getBindingFromASTName("bar();/*6*/", 3, ICPPMethod.class);
 
879
        bar_c=  getBindingFromASTName("bar();/*7*/", 3, ICPPMethod.class);
 
880
        bar=    getBindingFromASTName("bar();/*8*/", 3, ICPPMethod.class);
 
881
        bar_cv_ft= bar_cv.getType();
 
882
        bar_v_ft=  bar_v.getType();
 
883
        bar_c_ft=  bar_c.getType();
 
884
        bar_ft=    bar.getType();
 
885
        
 
886
        assertTrue(bar_cv_ft.isConst()); assertTrue(bar_cv_ft.isVolatile());
 
887
        assertTrue(!bar_v_ft.isConst()); assertTrue(bar_v_ft.isVolatile());
 
888
        assertTrue(bar_c_ft.isConst());  assertTrue(!bar_c_ft.isVolatile());
 
889
        assertTrue(!bar_ft.isConst());   assertTrue(!bar_ft.isVolatile());
 
890
    }
 
891
    
 
892
        //      typedef char t[12];
 
893
        //      void test1(char *);
 
894
        //      void test2(char []);
 
895
        //      void test3(t);
 
896
    
 
897
        //      void xx() {
 
898
        //         char* x= 0;
 
899
        //         test1(x);
 
900
        //         test2(x); // problem binding here
 
901
        //         test3(x); // problem binding here
 
902
        //      }
 
903
        public void testAdjustmentOfParameterTypes_Bug239975() throws Exception {
 
904
        getBindingFromASTName("test1(x)", 5, ICPPFunction.class);
 
905
        getBindingFromASTName("test2(x)", 5, ICPPFunction.class);
 
906
        getBindingFromASTName("test3(x)", 5, ICPPFunction.class);
 
907
        }
 
908
        
 
909
        // class A {
 
910
        //    A();
 
911
        //    void l();
 
912
        //    void e;
 
913
        //    class M {};
 
914
        // };
 
915
        // class B {
 
916
        //    B();
 
917
        //    void m();
 
918
        //    void f;
 
919
        //    class N {};
 
920
        // };
 
921
        // class C : B {
 
922
        //    C();
 
923
        //    void n();
 
924
        //    int g;
 
925
        //    class O {};
 
926
        // };
 
927
        // template<typename T> class CT : B {
 
928
        //    CT();
 
929
        //    void n();
 
930
        //    T g;
 
931
        //    class O {};
 
932
        // };
 
933
        // template<> class CT<char> : A {
 
934
        //    CT(); CT(int);
 
935
        //    void o();
 
936
        //    int h;
 
937
        //    class P {};
 
938
        // };
 
939
        // template<typename S> class Container {
 
940
        //    class C : B {
 
941
        //       C();
 
942
        //       void n();
 
943
        //       int g;
 
944
        //       class O {};
 
945
        //    };
 
946
        //    template<typename T> class CT : B {
 
947
        //       CT();
 
948
        //       void n();
 
949
        //       T g;
 
950
        //       class O {};
 
951
        //    };
 
952
        // };
 
953
        //      template<> class Container<char>::C : A {
 
954
        //              C(); C(int);
 
955
        //              void o();
 
956
        //              int h;
 
957
        //              class P {};
 
958
        //      };
 
959
        //      template<> template<typename T> class Container<char>::CT : A {
 
960
        //              CT(); CT(int);
 
961
        //              void o();
 
962
        //              int h;
 
963
        //              class P {};
 
964
        //      };
 
965
        
 
966
        // C c;
 
967
        // CT<int> ct;
 
968
        // CT<char> ctinst;
 
969
        // Container<int>::C spec;
 
970
        // Container<int>::CT<int> spect;
 
971
        // Container<char>::C espec;
 
972
        // Container<char>::CT<int> espect;
 
973
        public void testClassTypes_Bug98171() throws Exception {
 
974
                // regular class
 
975
                ICPPClassType ct= getBindingFromASTName("C", 1);
 
976
                assertBindings(new String[] {"B"}, ct.getBases());
 
977
                assertBindings(new String[] {"n", "m", "B", "C"}, ct.getAllDeclaredMethods());
 
978
                assertBindings(new String[] {"C", "C"}, ct.getConstructors());
 
979
                assertBindings(new String[] {"g"}, ct.getDeclaredFields());
 
980
                assertBindings(new String[] {"n", "C"}, ct.getDeclaredMethods());
 
981
                assertBindings(new String[] {"f", "g"}, ct.getFields());
 
982
                assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods());
 
983
                assertBindings(new String[] {"O"}, ct.getNestedClasses());
 
984
 
 
985
                // class template
 
986
                ct= getBindingFromASTName("CT<int>", 2);
 
987
                assertInstance(ct, ICPPClassTemplate.class);
 
988
                assertBindings(new String[] {"B"}, ct.getBases());
 
989
                assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods());
 
990
                assertBindings(new String[] {"CT", "CT"}, ct.getConstructors());
 
991
                assertBindings(new String[] {"g"}, ct.getDeclaredFields());
 
992
                assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods());
 
993
                assertBindings(new String[] {"f", "g"}, ct.getFields());
 
994
                assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods());
 
995
                assertBindings(new String[] {"O"}, ct.getNestedClasses());
 
996
 
 
997
                // class template instance
 
998
                ct= getBindingFromASTName("CT<int>", 7);
 
999
                assertInstance(ct, ICPPTemplateInstance.class);
 
1000
                assertBindings(new String[] {"B"}, ct.getBases());
 
1001
                assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods());
 
1002
                assertBindings(new String[] {"CT", "CT"}, ct.getConstructors());
 
1003
                assertBindings(new String[] {"g"}, ct.getDeclaredFields());
 
1004
                assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods());
 
1005
                assertBindings(new String[] {"f", "g"}, ct.getFields());
 
1006
                assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods());
 
1007
                assertBindings(new String[] {"O"}, ct.getNestedClasses());
 
1008
 
 
1009
                // explicit class template instance
 
1010
                ct= getBindingFromASTName("CT<char>", 8);
 
1011
                assertInstance(ct, ICPPTemplateInstance.class);
 
1012
                assertBindings(new String[] {"A"}, ct.getBases());
 
1013
                assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods());
 
1014
                assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors());
 
1015
                assertBindings(new String[] {"h"}, ct.getDeclaredFields());
 
1016
                assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods());
 
1017
                assertBindings(new String[] {"e", "h"}, ct.getFields());
 
1018
                assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods());
 
1019
                assertBindings(new String[] {"P"}, ct.getNestedClasses());
 
1020
 
 
1021
                // class specialization
 
1022
                ct= getBindingFromASTName("C spec", 1);
 
1023
                assertInstance(ct, ICPPClassSpecialization.class);
 
1024
                assertBindings(new String[] {"B"}, ct.getBases());
 
1025
                assertBindings(new String[] {"n", "m", "B", "C"}, ct.getAllDeclaredMethods());
 
1026
                assertBindings(new String[] {"C", "C"}, ct.getConstructors());
 
1027
                assertBindings(new String[] {"g"}, ct.getDeclaredFields());
 
1028
                assertBindings(new String[] {"n", "C"}, ct.getDeclaredMethods());
 
1029
                assertBindings(new String[] {"f", "g"}, ct.getFields());
 
1030
                assertBindings(new String[] {"m", "n", "C", "C", "~C", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods());
 
1031
                assertBindings(new String[] {"O"}, ct.getNestedClasses());
 
1032
 
 
1033
                // class template specialization
 
1034
                ct= getBindingFromASTName("CT<int> spect", 2);
 
1035
                assertInstance(ct, ICPPClassTemplate.class, ICPPClassSpecialization.class);
 
1036
                assertBindings(new String[] {"B"}, ct.getBases());
 
1037
                assertBindings(new String[] {"n", "m", "B", "CT"}, ct.getAllDeclaredMethods());
 
1038
                assertBindings(new String[] {"CT", "CT"}, ct.getConstructors());
 
1039
                assertBindings(new String[] {"g"}, ct.getDeclaredFields());
 
1040
                assertBindings(new String[] {"n", "CT"}, ct.getDeclaredMethods());
 
1041
                assertBindings(new String[] {"f", "g"}, ct.getFields());
 
1042
                assertBindings(new String[] {"m", "n", "CT", "CT", "~CT", "B", "B", "~B", "operator =", "operator ="}, ct.getMethods());
 
1043
                assertBindings(new String[] {"O"}, ct.getNestedClasses());
 
1044
                
 
1045
                // explicit class specialization
 
1046
                ct= getBindingFromASTName("C espec", 1);
 
1047
                assertInstance(ct, ICPPClassSpecialization.class);
 
1048
                assertBindings(new String[] {"A"}, ct.getBases());
 
1049
                assertBindings(new String[] {"o", "l", "A", "C", "C"}, ct.getAllDeclaredMethods());
 
1050
                assertBindings(new String[] {"C", "C", "C"}, ct.getConstructors());
 
1051
                assertBindings(new String[] {"h"}, ct.getDeclaredFields());
 
1052
                assertBindings(new String[] {"o", "C", "C"}, ct.getDeclaredMethods());
 
1053
                assertBindings(new String[] {"e", "h"}, ct.getFields());
 
1054
                assertBindings(new String[] {"l", "o", "C", "C", "C", "~C", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods());
 
1055
                assertBindings(new String[] {"P"}, ct.getNestedClasses());
 
1056
 
 
1057
                // explicit class template specialization
 
1058
                ct= getBindingFromASTName("CT<int> espect", 7);
 
1059
                assertInstance(ct, ICPPTemplateInstance.class);
 
1060
                assertBindings(new String[] {"A"}, ct.getBases());
 
1061
                assertBindings(new String[] {"o", "l", "A", "CT", "CT"}, ct.getAllDeclaredMethods());
 
1062
                assertBindings(new String[] {"CT", "CT", "CT"}, ct.getConstructors());
 
1063
                assertBindings(new String[] {"h"}, ct.getDeclaredFields());
 
1064
                assertBindings(new String[] {"o", "CT", "CT"}, ct.getDeclaredMethods());
 
1065
                assertBindings(new String[] {"e", "h"}, ct.getFields());
 
1066
                assertBindings(new String[] {"l", "o", "CT", "CT", "CT", "~CT", "A", "A", "~A", "operator =", "operator ="}, ct.getMethods());
 
1067
                assertBindings(new String[] {"P"}, ct.getNestedClasses());
 
1068
        }
 
1069
 
 
1070
        //      void func(const int* x) {}
 
1071
        
 
1072
        //      void func(int* p) {
 
1073
        //      const int* q = p;
 
1074
        //              func(q);
 
1075
        //      }
 
1076
        public void testOverloadedFunctionFromIndex_Bug256240() throws Exception {
 
1077
        getBindingFromASTName("func(q", 4, ICPPFunction.class);
 
1078
        }
 
1079
 
 
1080
        //      class A {
 
1081
        //        class B;
 
1082
        //      };
 
1083
        //      class A::B {
 
1084
        //        void m();
 
1085
        //      };
 
1086
 
 
1087
        //      void A::B::m() {}
 
1088
        public void testNestedClasses_Bug259683() throws Exception {
 
1089
        getBindingFromASTName("A::B::m", 7, ICPPMethod.class);
 
1090
        }
 
1091
 
 
1092
        //      namespace ns {
 
1093
        //              struct S {
 
1094
        //                      int a;
 
1095
        //              };
 
1096
        //      }
 
1097
        //      class A {
 
1098
        //              public:
 
1099
        //                      template<typename T> operator T*(){return 0;};
 
1100
        //      };
 
1101
 
 
1102
        //      namespace ns {
 
1103
        //              void bla() {
 
1104
        //                      A a;
 
1105
        //                      a.operator S *();
 
1106
        //              }
 
1107
        //      }
 
1108
        public void testLookupScopeForConversionNames_267221() throws Exception {
 
1109
        getBindingFromASTName("operator S *", 12, ICPPMethod.class);
 
1110
        }
 
1111
 
 
1112
        private void assertBindings(String[] expected, ICPPBase[] bases) throws DOMException {
 
1113
                IBinding[] bindings= new IBinding[bases.length];
 
1114
                for (int i = 0; i < bindings.length; i++) {
 
1115
                        bindings[i]= bases[i].getBaseClass();
 
1116
                }
 
1117
                assertBindings(expected, bindings);
 
1118
        }
 
1119
 
 
1120
        private void assertBindings(String[] expected, IBinding[] binding) {
 
1121
                String[] actual= new String[binding.length];
 
1122
                for (int i = 0; i < actual.length; i++) {
 
1123
                        actual[i]= binding[i].getName();
 
1124
                }               
 
1125
                Arrays.sort(actual);
 
1126
                Arrays.sort(expected);
 
1127
                assertEquals(toString(expected), toString(actual));
 
1128
        }
 
1129
        
 
1130
        private String toString(String[] actual) {
 
1131
                StringBuilder buf= new StringBuilder();
 
1132
                buf.append('{');
 
1133
                boolean isFirst= true;
 
1134
                for (String val : actual) {
 
1135
                        if (!isFirst) {
 
1136
                                buf.append(',');
 
1137
                        }
 
1138
                        buf.append(val);
 
1139
                        isFirst= false;
 
1140
                }
 
1141
                buf.append('}');
 
1142
                return buf.toString();
 
1143
        }
 
1144
        
 
1145
        //      class Derived;
 
1146
        //  class X {
 
1147
        //     Derived* d;
 
1148
        //  };
 
1149
        //  class Base {};
 
1150
        //  void useBase(Base* b);
 
1151
        
 
1152
        //  class Derived: Base {};
 
1153
        //      void test() {
 
1154
        //      X x;
 
1155
        //      useBase(x.d);
 
1156
        //      }
 
1157
        public void testLateDefinitionOfInheritance_Bug292749() throws Exception {
 
1158
        getBindingFromASTName("useBase(x.d", 7, ICPPFunction.class);
 
1159
        }
 
1160
        
 
1161
        // namespace one {
 
1162
        //   void fx();
 
1163
        //   void fx(int);
 
1164
        //   void fx(int, int);
 
1165
        // }
 
1166
        // namespace two {
 
1167
        //   using one::fx;
 
1168
    // }
 
1169
        
 
1170
        // #include "header.h"
 
1171
        // void test() {
 
1172
        //    two::fx();
 
1173
        //    two::fx(1);
 
1174
        //    two::fx(1,1);
 
1175
        // }
 
1176
        public void testUsingDeclaration_Bug300019() throws Exception {
 
1177
        getBindingFromASTName("fx();", 2, ICPPFunction.class);
 
1178
        getBindingFromASTName("fx(1);", 2, ICPPFunction.class);
 
1179
        getBindingFromASTName("fx(1,1);", 2, ICPPFunction.class);
 
1180
        }
 
1181
        
 
1182
        //      struct YetAnotherTest {
 
1183
        //        void test();
 
1184
        //        friend class InnerClass3;
 
1185
        //        class InnerClass3 {
 
1186
        //          void f() {
 
1187
        //            member=0;
 
1188
        //          }
 
1189
        //          int member;
 
1190
        //        };
 
1191
        //        InnerClass3 arr[32];
 
1192
        //      };
 
1193
 
 
1194
        //      #include "a.h"
 
1195
        //      void YetAnotherTest::test() {
 
1196
        //        arr[0].member=0;
 
1197
        //      }
 
1198
        public void testElaboratedTypeSpecifier_Bug303739() throws Exception {
 
1199
        getBindingFromASTName("member=0", -2, ICPPField.class);
 
1200
        }
 
1201
        
 
1202
        //      typedef int xxx::* MBR_PTR;
 
1203
        
 
1204
        //      void test() {   
 
1205
        //              MBR_PTR x;
 
1206
        //      }
 
1207
        public void testProblemInIndexBinding_Bug317146() throws Exception {
 
1208
        ITypedef td= getBindingFromASTName("MBR_PTR", 0, ITypedef.class);
 
1209
        ICPPPointerToMemberType ptrMbr= (ICPPPointerToMemberType) td.getType();
 
1210
        IType t= ptrMbr.getMemberOfClass();
 
1211
        assertInstance(t, ISemanticProblem.class);
 
1212
        }
 
1213
 
 
1214
        //      void f255(
 
1215
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1216
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1217
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1218
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1219
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1220
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1221
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1222
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1223
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1224
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1225
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1226
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1227
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1228
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1229
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1230
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int);
 
1231
        //      void f256(
 
1232
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1233
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1234
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1235
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1236
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1237
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1238
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1239
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1240
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1241
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1242
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1243
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1244
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1245
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1246
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int,
 
1247
        //     int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int);
 
1248
        
 
1249
        //      void test() {   
 
1250
        //     f255(
 
1251
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1252
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1253
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1254
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1255
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1256
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1257
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1258
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
 
1259
        //     f256(
 
1260
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1261
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1262
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1263
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1264
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1265
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1266
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
 
1267
        //          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
 
1268
        //      }
 
1269
        public void testFunctionsWithManyParameters_Bug319186() throws Exception {
 
1270
                getBindingFromASTName("f255", 0);
 
1271
                getBindingFromASTName("f256", 0);
 
1272
        }               
 
1273
        
 
1274
        // void f(char16_t x);
 
1275
        // void f(char32_t x);
 
1276
        
 
1277
        //      void test() {
 
1278
        //     char16_t c16;
 
1279
        //     char32_t c32;
 
1280
        //     f(c16); f(c32);
 
1281
        // }
 
1282
        public void testChar16_Bug319186() throws Exception {
 
1283
                IFunction f= getBindingFromASTName("f(c16)", 1);
 
1284
                assertEquals("char16_t", ASTTypeUtil.getType(f.getType().getParameterTypes()[0]));
 
1285
                
 
1286
                f= getBindingFromASTName("f(c32)", 1);
 
1287
                assertEquals("char32_t", ASTTypeUtil.getType(f.getType().getParameterTypes()[0]));
 
1288
        }
 
1289
        
 
1290
        //      namespace ns {
 
1291
        //              extern int* var;
 
1292
        //              void fun();
 
1293
        //              typedef int Type;
 
1294
        //      }
 
1295
        //      using ns::var;
 
1296
        //      using ns::fun;
 
1297
        //      using ns::Type;
 
1298
        
 
1299
        //      #include "header.h"
 
1300
        //      using namespace ::ns;
 
1301
        //      void sabel() {
 
1302
        //        var = 0;
 
1303
        //        fun();
 
1304
        //        Type x;
 
1305
        //      }
 
1306
        public void test_Bug326778() throws Exception {
 
1307
                IVariable v= getBindingFromASTName("var", 0);
 
1308
                IFunction f= getBindingFromASTName("fun", 0);
 
1309
                ITypedef t= getBindingFromASTName("Type", 0);
 
1310
        }
 
1311
}