1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/**********************************************************************
* Copyright (c) 2002,2003 Rational Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.core.parser.failedTests;
import java.util.Iterator;
import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration;
import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier;
import org.eclipse.cdt.core.parser.ast.IASTField;
import org.eclipse.cdt.core.parser.ast.IASTFunction;
import org.eclipse.cdt.core.parser.ast.IASTMethod;
import org.eclipse.cdt.core.parser.ast.IASTScope;
import org.eclipse.cdt.core.parser.ast.IASTVariable;
import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
* @author jcamelon
*
*/
public class FailedCompleteParseASTTest extends CompleteParseBaseTest
{
/**
*
*/
public FailedCompleteParseASTTest()
{
super();
}
/**
* @param name
*/
public FailedCompleteParseASTTest(String name)
{
super(name);
}
public void testPMDotStarPointerToMemberFunction_Bug43242() throws Exception
{
Iterator i = parse ("class A { int m(int); }; \n A a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a.*pm)(5));").getDeclarations();
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
Iterator members = getDeclarations(cl);
IASTMethod method = (IASTMethod)members.next();
IASTVariable a = (IASTVariable) i.next();
IASTVariable pm = (IASTVariable) i.next();
IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next();
assertAllReferences( 5 /* should be 8 */,
createTaskList( new Task( cl, 2 /* should be 3 */ ), new Task( method ), new Task( a ), new Task( pm ) /* should be ,new Task( f2 ) */
));
}
public void testPMArrowStarPointerToMemberFunction_Bug43242() throws Exception
{
Iterator i = parse ("class A { int m(int); }; \n A * a; int A::*pm = &A::m; \n int f(){} \n int f(int); \n int x = f((a->*pm)(5));").getDeclarations();
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
Iterator members = getDeclarations(cl);
IASTMethod method = (IASTMethod)members.next();
IASTVariable a = (IASTVariable) i.next();
IASTVariable pm = (IASTVariable) i.next();
IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next();
assertAllReferences( 5 /* should be more */,
createTaskList( new Task( cl, 2 ), new Task( method ), new Task( a /*, 2 */), new Task( pm )/* ,new Task( f2 )*/));
}
public void testUnaryStarCastexpressionPointerToFunction_Bug43241() throws Exception
{
Iterator i = parse ("int m(int); \n int *pm = &m; \n int f(){} \n int f(int); \n int x = f((*pm)(5));").getDeclarations();
IASTFunction m = (IASTFunction) i.next();
IASTVariable pm = (IASTVariable) i.next();
IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next();
assertAllReferences( 2 /* should be 3 */,
createTaskList( new Task( m ), new Task( pm ) /* ,new Task( f2 )*/));
}
// Kind DELETE_CASTEXPRESSION
// Kind DELETE_VECTORCASTEXPRESSION
// Kind CASTEXPRESSION
// Kind PM_DOTSTAR
public void testPMDotStar_bug43579() throws Exception
{
Iterator i = parse ("class A { int m; }; \n A a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a.*pm);").getDeclarations();
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
IASTVariable a = (IASTVariable) i.next();
IASTVariable pm = (IASTVariable) i.next();
IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next();
assertFalse( i.hasNext() );
assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2)));
}
// Kind PM_ARROWSTAR
public void testPMArrowStar_bug43579() throws Exception
{
Iterator i = parse ("class A { int m; }; \n A * a; int A::*pm; \n int f(){} \n int f(int); \n int x = f(a->*pm);").getDeclarations();
IASTClassSpecifier cl = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
IASTVariable a = (IASTVariable) i.next();
IASTVariable pm = (IASTVariable) i.next();
IASTFunction f1 = (IASTFunction) i.next();
IASTFunction f2 = (IASTFunction) i.next();
IASTVariable x = (IASTVariable) i.next();
assertFalse( i.hasNext() );
assertAllReferences( 4 /*should be 5 */, createTaskList( new Task( cl /* , 2 */ ), new Task( a), new Task( pm), new Task( f2)));
}
public void testErrorHandling_1() throws Exception
{
Iterator i = parse( "A anA; int x = c; class A {}; A * anotherA = &anA; int b;", false ).getDeclarations();
IASTVariable x = (IASTVariable)i.next();
assertEquals( x.getName(), "x");
IASTClassSpecifier A = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
IASTVariable anotherA = (IASTVariable)i.next();
assertFalse(i.hasNext()); // should be true
// this variable is skipped because of wrong error handling
// IASTVariable b = (IASTVariable)i.next();
// assertEquals( b.getName(), "b");
// assertFalse(i.hasNext());
}
public void testBug44340() throws Exception {
try {
// inline function with reference to variables declared after them
IASTScope scope = parse ("class A{ int getX() {return x[1];} int x[10];};");
Iterator i = scope.getDeclarations();
IASTClassSpecifier classA = (IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier();
Iterator j = getDeclarations(classA);
IASTMethod g = (IASTMethod)j.next();
IASTField x = (IASTField)j.next();
assertFalse(j.hasNext());
assertAllReferences( 1, createTaskList( new Task( x )));
} catch (ParserException e){
// parsing fails for now
}
}
}
|