View | Details | Raw Unified | Return to bug 94989
Collapse All | Expand All

(-)src/org/eclipse/cdt/ui/tests/DOMAST/CPPPopulateASTViewAction.java (-56 / +128 lines)
Lines 48-54 Link Here
48
 */
48
 */
49
public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulateDOMASTAction {
49
public class CPPPopulateASTViewAction extends CPPASTVisitor implements IPopulateDOMASTAction {
50
	private static final int INITIAL_PROBLEM_SIZE = 4;
50
	private static final int INITIAL_PROBLEM_SIZE = 4;
51
	private static final int INITIAL_INCLUDE_STATEMENT_SIZE = 8;
52
	{
51
	{
53
		shouldVisitNames          = true;
52
		shouldVisitNames          = true;
54
		shouldVisitDeclarations   = true;
53
		shouldVisitDeclarations   = true;
Lines 73-86 Link Here
73
		this.monitor = monitor;
72
		this.monitor = monitor;
74
	}
73
	}
75
	
74
	
76
	private int addRoot(IASTNode node) {
75
	private class DOMASTNodeLeafContinue extends DOMASTNodeLeaf {
77
        if (monitor != null && monitor.isCanceled()) return PROCESS_ABORT;
76
		public DOMASTNodeLeafContinue(IASTNode node) {
78
        if (node == null) return PROCESS_CONTINUE;
77
			super(node);
78
		}
79
	}
80
81
	/** 
82
	 * return null if the algorithm should stop (monitor was cancelled)
83
	 * return DOMASTNodeLeafContinue if the algorithm should continue but no valid DOMASTNodeLeaf was added (i.e. node was null
84
	 * return the DOMASTNodeLeaf added to the DOM AST View's model otherwise 
85
	 * 
86
	 * @param node
87
	 * @return
88
	 */
89
	private DOMASTNodeLeaf addRoot(IASTNode node) {
90
        if (monitor != null && monitor.isCanceled()) return null;
91
        if (node == null) return new DOMASTNodeLeafContinue(null);
79
        
92
        
80
        // only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very expensive)
93
        // only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very expensive)
81
        if (!(node instanceof ICPPASTLinkageSpecification) && 
94
        if (!(node instanceof ICPPASTLinkageSpecification) && 
82
        	node instanceof ASTNode && ((ASTNode)node).getLength() <= 0)
95
        	node instanceof ASTNode && ((ASTNode)node).getLength() <= 0)
83
            return PROCESS_CONTINUE;
96
            return new DOMASTNodeLeafContinue(null);
84
        
97
        
85
        DOMASTNodeParent parent = null;
98
        DOMASTNodeParent parent = null;
86
        
99
        
Lines 99-110 Link Here
99
        if (parent == null)
112
        if (parent == null)
100
            parent = root;
113
            parent = root;
101
        
114
        
102
        createNode(parent, node);
115
        return createNode(parent, node);
103
        
104
        return PROCESS_CONTINUE;
105
	}
116
	}
106
    
117
    
107
    private void createNode(DOMASTNodeParent parent, IASTNode node) {
118
    private DOMASTNodeLeaf createNode(DOMASTNodeParent parent, IASTNode node) {
108
        DOMASTNodeParent tree = new DOMASTNodeParent(node);
119
        DOMASTNodeParent tree = new DOMASTNodeParent(node);
109
        parent.addChild(tree);
120
        parent.addChild(tree);
110
        
121
        
Lines 121-140 Link Here
121
            tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);
132
            tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);
122
        if (node instanceof IASTPreprocessorIncludeStatement)
133
        if (node instanceof IASTPreprocessorIncludeStatement)
123
            tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_INCLUDE_STATEMENTS);
134
            tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_INCLUDE_STATEMENTS);
135
		
136
		return tree;
124
    }
137
    }
125
	
138
	
126
	/* (non-Javadoc)
139
	/* (non-Javadoc)
127
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
140
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
128
	 */
141
	 */
129
	public int visit(IASTDeclaration declaration) {
142
	public int visit(IASTDeclaration declaration) {
130
		return addRoot(declaration);
143
		DOMASTNodeLeaf temp = addRoot(declaration);
144
		if (temp == null)
145
			return PROCESS_ABORT;
146
		else if (temp instanceof DOMASTNodeLeafContinue)
147
			return PROCESS_CONTINUE;
148
		else
149
			return PROCESS_CONTINUE;
131
	}
150
	}
132
	
151
	
133
	/* (non-Javadoc)
152
	/* (non-Javadoc)
134
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
153
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
135
	 */
154
	 */
136
	public int visit(IASTDeclarator declarator) {
155
	public int visit(IASTDeclarator declarator) {
137
		int ret = addRoot(declarator);
156
		DOMASTNodeLeaf temp =  addRoot(declarator);
138
		
157
		
139
		IASTPointerOperator[] ops = declarator.getPointerOperators();
158
		IASTPointerOperator[] ops = declarator.getPointerOperators();
140
		for(int i=0; i<ops.length; i++)
159
		for(int i=0; i<ops.length; i++)
Lines 160-217 Link Here
160
			}	
179
			}	
161
		}
180
		}
162
		
181
		
163
		return ret;
182
		if (temp == null)
183
			return PROCESS_ABORT;
184
		else if (temp instanceof DOMASTNodeLeafContinue)
185
			return PROCESS_CONTINUE;
186
		else
187
			return PROCESS_CONTINUE;
164
	}
188
	}
165
	
189
	
166
	/* (non-Javadoc)
190
	/* (non-Javadoc)
167
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier)
191
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processBaseSpecifier(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier)
168
	 */
192
	 */
169
	public int visit(ICPPASTBaseSpecifier specifier) {
193
	public int visit(ICPPASTBaseSpecifier specifier) {
170
		return addRoot(specifier);
194
		DOMASTNodeLeaf temp = addRoot(specifier);
195
		if (temp == null)
196
			return PROCESS_ABORT;
197
		else if (temp instanceof DOMASTNodeLeafContinue)
198
			return PROCESS_CONTINUE;
199
		else
200
			return PROCESS_CONTINUE;
171
	}
201
	}
172
	
202
	
173
	/* (non-Javadoc)
203
	/* (non-Javadoc)
174
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
204
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
175
	 */
205
	 */
176
	public int visit(IASTDeclSpecifier declSpec) {
206
	public int visit(IASTDeclSpecifier declSpec) {
177
		return addRoot(declSpec);
207
		DOMASTNodeLeaf temp = addRoot(declSpec);
208
		if (temp == null)
209
			return PROCESS_ABORT;
210
		else if (temp instanceof DOMASTNodeLeafContinue)
211
			return PROCESS_CONTINUE;
212
		else
213
			return PROCESS_CONTINUE;
178
	}
214
	}
179
	
215
	
180
	/* (non-Javadoc)
216
	/* (non-Javadoc)
181
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
217
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
182
	 */
218
	 */
183
	public int visit(IASTEnumerator enumerator) {
219
	public int visit(IASTEnumerator enumerator) {
184
		return addRoot(enumerator);
220
		DOMASTNodeLeaf temp = addRoot(enumerator);
221
		if (temp == null)
222
			return PROCESS_ABORT;
223
		else if (temp instanceof DOMASTNodeLeafContinue)
224
			return PROCESS_CONTINUE;
225
		else
226
			return PROCESS_CONTINUE;
185
	}
227
	}
186
	
228
	
187
	/* (non-Javadoc)
229
	/* (non-Javadoc)
188
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
230
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
189
	 */
231
	 */
190
	public int visit(IASTExpression expression) {
232
	public int visit(IASTExpression expression) {
191
		return addRoot(expression);
233
		DOMASTNodeLeaf temp = addRoot(expression);
234
		if (temp == null)
235
			return PROCESS_ABORT;
236
		else if (temp instanceof DOMASTNodeLeafContinue)
237
			return PROCESS_CONTINUE;
238
		else
239
			return PROCESS_CONTINUE;
192
	}
240
	}
193
	
241
	
194
	/* (non-Javadoc)
242
	/* (non-Javadoc)
195
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
243
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
196
	 */
244
	 */
197
	public int visit(IASTInitializer initializer) {
245
	public int visit(IASTInitializer initializer) {
198
		return addRoot(initializer);
246
		DOMASTNodeLeaf temp = addRoot(initializer);
247
		if (temp == null)
248
			return PROCESS_ABORT;
249
		else if (temp instanceof DOMASTNodeLeafContinue)
250
			return PROCESS_CONTINUE;
251
		else
252
			return PROCESS_CONTINUE;
199
	}
253
	}
200
		
254
		
201
	/* (non-Javadoc)
255
	/* (non-Javadoc)
202
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
256
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
203
	 */
257
	 */
204
	public int visit(IASTName name) {
258
	public int visit(IASTName name) {
259
		DOMASTNodeLeaf temp = null;
205
		if (name.toString() != null)
260
		if (name.toString() != null)
206
			return addRoot(name);
261
			temp = addRoot(name);
207
		return PROCESS_CONTINUE;
262
		else
263
			return PROCESS_CONTINUE;
264
		
265
		if (temp == null)
266
			return PROCESS_ABORT;
267
		else if (temp instanceof DOMASTNodeLeafContinue)
268
			return PROCESS_CONTINUE;
269
		else
270
			return PROCESS_CONTINUE;
208
	}
271
	}
209
	
272
	
210
	/* (non-Javadoc)
273
	/* (non-Javadoc)
211
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition)
274
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processNamespace(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition)
212
	 */
275
	 */
213
	public int visit(ICPPASTNamespaceDefinition namespace) {
276
	public int visit(ICPPASTNamespaceDefinition namespace) {
214
		return addRoot(namespace);
277
		DOMASTNodeLeaf temp = addRoot(namespace);
278
		if (temp == null)
279
			return PROCESS_ABORT;
280
		else if (temp instanceof DOMASTNodeLeafContinue)
281
			return PROCESS_CONTINUE;
282
		else
283
			return PROCESS_CONTINUE;
215
	}
284
	}
216
	
285
	
217
	/* (non-Javadoc)
286
	/* (non-Javadoc)
Lines 219-255 Link Here
219
	 */
288
	 */
220
	public int visit(
289
	public int visit(
221
			IASTParameterDeclaration parameterDeclaration) {
290
			IASTParameterDeclaration parameterDeclaration) {
222
		return addRoot(parameterDeclaration);
291
		DOMASTNodeLeaf temp = addRoot(parameterDeclaration);
292
		if (temp == null)
293
			return PROCESS_ABORT;
294
		else if (temp instanceof DOMASTNodeLeafContinue)
295
			return PROCESS_CONTINUE;
296
		else
297
			return PROCESS_CONTINUE;
223
	}
298
	}
224
	
299
	
225
	/* (non-Javadoc)
300
	/* (non-Javadoc)
226
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
301
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
227
	 */
302
	 */
228
	public int visit(IASTStatement statement) {
303
	public int visit(IASTStatement statement) {
229
		return addRoot(statement);
304
		DOMASTNodeLeaf temp = addRoot(statement);
305
		if (temp == null)
306
			return PROCESS_ABORT;
307
		else if (temp instanceof DOMASTNodeLeafContinue)
308
			return PROCESS_CONTINUE;
309
		else
310
			return PROCESS_CONTINUE;
230
	}
311
	}
231
	
312
	
232
	/* (non-Javadoc)
313
	/* (non-Javadoc)
233
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
314
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
234
	 */
315
	 */
235
	public int visit(IASTTypeId typeId) {
316
	public int visit(IASTTypeId typeId) {
236
		return addRoot(typeId);
317
		DOMASTNodeLeaf temp = addRoot(typeId);
318
		if (temp == null)
319
			return PROCESS_ABORT;
320
		else if (temp instanceof DOMASTNodeLeafContinue)
321
			return PROCESS_CONTINUE;
322
		else
323
			return PROCESS_CONTINUE;
237
	}
324
	}
238
325
239
	private void mergeNode(ASTNode node) {
326
	private DOMASTNodeLeaf mergeNode(ASTNode node) {
240
		addRoot(node);
327
		DOMASTNodeLeaf leaf = addRoot(node);
241
		
328
		
242
		if (node instanceof IASTPreprocessorMacroDefinition)
329
		if (node instanceof IASTPreprocessorMacroDefinition)
243
			addRoot(((IASTPreprocessorMacroDefinition)node).getName());
330
			addRoot(((IASTPreprocessorMacroDefinition)node).getName());
331
		
332
		return leaf;
244
	}
333
	}
245
	
334
	
246
	public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
335
	public DOMASTNodeLeaf[] mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
336
		DOMASTNodeLeaf[] leaves = new DOMASTNodeLeaf[statements.length];
247
		for(int i=0; i<statements.length; i++) {
337
		for(int i=0; i<statements.length; i++) {
248
			if (monitor != null && monitor.isCanceled()) return;
338
			if (monitor != null && monitor.isCanceled()) return leaves;
249
			
339
			
250
			if (statements[i] instanceof ASTNode)
340
			if (statements[i] instanceof ASTNode)
251
				mergeNode((ASTNode)statements[i]);
341
				leaves[i] = mergeNode((ASTNode)statements[i]);
252
		}
342
		}
343
		
344
		return leaves;
253
	}
345
	}
254
	
346
	
255
	public void mergePreprocessorProblems(IASTProblem[] problems) {
347
	public void mergePreprocessorProblems(IASTProblem[] problems) {
Lines 265-309 Link Here
265
		return root;
357
		return root;
266
	}
358
	}
267
	
359
	
268
	public void groupIncludes(IASTPreprocessorStatement[] statements) {
360
	public void groupIncludes(DOMASTNodeLeaf[] treeIncludes) {
269
		// get all of the includes from the preprocessor statements (need the object since .equals isn't implemented)
270
		IASTPreprocessorIncludeStatement[] includes = new IASTPreprocessorIncludeStatement[INITIAL_INCLUDE_STATEMENT_SIZE];
271
		int index = 0;
272
		for(int i=0; i<statements.length; i++) {
273
			if (monitor != null && monitor.isCanceled()) return;
274
			if (statements[i] instanceof IASTPreprocessorIncludeStatement) {
275
				if (index == includes.length) {
276
					includes = (IASTPreprocessorIncludeStatement[])ArrayUtil.append(IASTPreprocessorIncludeStatement.class, includes, statements[i]);
277
					index++;
278
				} else {
279
					includes[index++] = (IASTPreprocessorIncludeStatement)statements[i];	
280
				}
281
			}
282
		}
283
		
284
		// get the tree model elements corresponding to the includes
285
		DOMASTNodeParent[] treeIncludes = new DOMASTNodeParent[index];
286
		for (int i=0; i<treeIncludes.length; i++) {
287
			if (monitor != null && monitor.isCanceled()) return;
288
			treeIncludes[i] = root.findTreeObject(includes[i], false);
289
		}
290
		
291
		// loop through the includes and make sure that all of the nodes 
361
		// loop through the includes and make sure that all of the nodes 
292
		// that are children of the TU are in the proper include (based on offset)
362
		// that are children of the TU are in the proper include (based on offset)
293
		DOMASTNodeLeaf child = null;
363
		DOMASTNodeLeaf child = null;
294
		outerLoop: for (int i=treeIncludes.length-1; i>=0; i--) {
364
		outerLoop: for (int i=treeIncludes.length-1; i>=0; i--) {
295
			if (treeIncludes[i] == null) continue;
365
			if (treeIncludes[i] == null) continue;
296
366
367
			IASTNode node = null;
297
			for(int j=root.getChildren(false).length-1; j>=0; j--) {
368
			for(int j=root.getChildren(false).length-1; j>=0; j--) {
298
				if (monitor != null && monitor.isCanceled()) return;
369
//				if (monitor != null && monitor.isCanceled()) return; // this causes a deadlock when checked here
299
				child = root.getChildren(false)[j];
370
				child = root.getChildren(false)[j];
300
				
371
				
372
				node = treeIncludes[i].getNode();
301
				if (child != null && treeIncludes[i] != child &&
373
				if (child != null && treeIncludes[i] != child &&
302
						includes[i] instanceof ASTInclusionStatement &&
374
						node instanceof ASTInclusionStatement &&
303
						((ASTNode)child.getNode()).getOffset() >= ((ASTInclusionStatement)includes[i]).startOffset &&
375
						((ASTNode)child.getNode()).getOffset() >= ((ASTInclusionStatement)node).startOffset &&
304
						((ASTNode)child.getNode()).getOffset() <= ((ASTInclusionStatement)includes[i]).endOffset) {
376
						((ASTNode)child.getNode()).getOffset() <= ((ASTInclusionStatement)node).endOffset) {
305
					root.removeChild(child);
377
					root.removeChild(child);
306
					treeIncludes[i].addChild(child);
378
					((DOMASTNodeParent)treeIncludes[i]).addChild(child);
307
				}
379
				}
308
			}
380
			}
309
		}
381
		}
(-)src/org/eclipse/cdt/ui/tests/DOMAST/CPopulateASTViewAction.java (-56 / +121 lines)
Lines 42-48 Link Here
42
 */
42
 */
43
public class CPopulateASTViewAction extends CASTVisitor implements IPopulateDOMASTAction {
43
public class CPopulateASTViewAction extends CASTVisitor implements IPopulateDOMASTAction {
44
	private static final int INITIAL_PROBLEM_SIZE = 4;
44
	private static final int INITIAL_PROBLEM_SIZE = 4;
45
	private static final int INITIAL_INCLUDE_STATEMENT_SIZE = 8;
46
	{
45
	{
47
		shouldVisitNames          = true;
46
		shouldVisitNames          = true;
48
		shouldVisitDeclarations   = true;
47
		shouldVisitDeclarations   = true;
Lines 66-78 Link Here
66
		this.monitor = monitor;
65
		this.monitor = monitor;
67
	}
66
	}
68
	
67
	
69
	private int addRoot(IASTNode node) {
68
	private class DOMASTNodeLeafContinue extends DOMASTNodeLeaf {
70
		if (monitor != null && monitor.isCanceled()) return PROCESS_ABORT;
69
		public DOMASTNodeLeafContinue(IASTNode node) {
71
		if (node == null) return PROCESS_CONTINUE;
70
			super(node);
71
		}
72
	}
73
74
	/** 
75
	 * return null if the algorithm should stop (monitor was cancelled)
76
	 * return DOMASTNodeLeafContinue if the algorithm should continue but no valid DOMASTNodeLeaf was added (i.e. node was null
77
	 * return the DOMASTNodeLeaf added to the DOM AST View's model otherwise 
78
	 * 
79
	 * @param node
80
	 * @return
81
	 */
82
	private DOMASTNodeLeaf addRoot(IASTNode node) {
83
		if (monitor != null && monitor.isCanceled()) return null;
84
		if (node == null) return new DOMASTNodeLeafContinue(null);
72
		
85
		
73
        // only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very expensive)
86
        // only do length check for ASTNode (getNodeLocations on PreprocessorStatements is very expensive)
74
        if (node instanceof ASTNode && ((ASTNode)node).getLength() <= 0)
87
        if (node instanceof ASTNode && ((ASTNode)node).getLength() <= 0)
75
            return PROCESS_CONTINUE;
88
            return new DOMASTNodeLeafContinue(null);
76
        
89
        
77
        DOMASTNodeParent parent = null;
90
        DOMASTNodeParent parent = null;
78
        
91
        
Lines 91-102 Link Here
91
        if (parent == null)
104
        if (parent == null)
92
            parent = root;
105
            parent = root;
93
        
106
        
94
        createNode(parent, node);
107
        return createNode(parent, node);
95
        
96
        return PROCESS_CONTINUE;
97
	}
108
	}
98
    
109
    
99
    private void createNode(DOMASTNodeParent parent, IASTNode node) {
110
    private DOMASTNodeLeaf createNode(DOMASTNodeParent parent, IASTNode node) {
100
        DOMASTNodeParent tree = new DOMASTNodeParent(node);
111
        DOMASTNodeParent tree = new DOMASTNodeParent(node);
101
        parent.addChild(tree);
112
        parent.addChild(tree);
102
        
113
        
Lines 113-132 Link Here
113
            tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);
124
            tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);
114
        if (node instanceof IASTPreprocessorIncludeStatement)
125
        if (node instanceof IASTPreprocessorIncludeStatement)
115
            tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_INCLUDE_STATEMENTS);
126
            tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_INCLUDE_STATEMENTS);
127
		
128
		return tree;
116
    }
129
    }
117
	
130
	
118
	/* (non-Javadoc)
131
	/* (non-Javadoc)
119
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
132
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclaration(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
120
	 */
133
	 */
121
	public int visit(IASTDeclaration declaration) {
134
	public int visit(IASTDeclaration declaration) {
122
		return addRoot(declaration);
135
		DOMASTNodeLeaf temp = addRoot(declaration);
136
		if (temp == null)
137
			return PROCESS_ABORT;
138
		else if (temp instanceof DOMASTNodeLeafContinue)
139
			return PROCESS_CONTINUE;
140
		else
141
			return PROCESS_CONTINUE;
123
	}
142
	}
124
	
143
	
125
	/* (non-Javadoc)
144
	/* (non-Javadoc)
126
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
145
	 * @see org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVisitor.CPPBaseVisitorAction#processDeclarator(org.eclipse.cdt.core.dom.ast.IASTDeclarator)
127
	 */
146
	 */
128
	public int visit(IASTDeclarator declarator) {
147
	public int visit(IASTDeclarator declarator) {
129
		int ret = addRoot(declarator);
148
		DOMASTNodeLeaf temp = addRoot(declarator);
130
		
149
		
131
		IASTPointerOperator[] ops = declarator.getPointerOperators();
150
		IASTPointerOperator[] ops = declarator.getPointerOperators();
132
		for(int i=0; i<ops.length; i++)
151
		for(int i=0; i<ops.length; i++)
Lines 138-188 Link Here
138
				addRoot(mods[i]);	
157
				addRoot(mods[i]);	
139
		}
158
		}
140
		
159
		
141
		return ret;
160
		if (temp == null)
161
			return PROCESS_ABORT;
162
		else if (temp instanceof DOMASTNodeLeafContinue)
163
			return PROCESS_CONTINUE;
164
		else
165
			return PROCESS_CONTINUE;
142
	}
166
	}
143
	
167
	
144
	/* (non-Javadoc)
168
	/* (non-Javadoc)
145
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
169
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDesignator(org.eclipse.cdt.core.dom.ast.c.ICASTDesignator)
146
	 */
170
	 */
147
	public int visit(ICASTDesignator designator) {
171
	public int visit(ICASTDesignator designator) {
148
		return addRoot(designator);
172
		DOMASTNodeLeaf temp = addRoot(designator);
173
		if (temp == null)
174
			return PROCESS_ABORT;
175
		else if (temp instanceof DOMASTNodeLeafContinue)
176
			return PROCESS_CONTINUE;
177
		else
178
			return PROCESS_CONTINUE;
149
	}
179
	}
150
	
180
	
151
	/* (non-Javadoc)
181
	/* (non-Javadoc)
152
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
182
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processDeclSpecifier(org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier)
153
	 */
183
	 */
154
	public int visit(IASTDeclSpecifier declSpec) {
184
	public int visit(IASTDeclSpecifier declSpec) {
155
		return addRoot(declSpec);
185
		DOMASTNodeLeaf temp = addRoot(declSpec);
186
		if (temp == null)
187
			return PROCESS_ABORT;
188
		else if (temp instanceof DOMASTNodeLeafContinue)
189
			return PROCESS_CONTINUE;
190
		else
191
			return PROCESS_CONTINUE;
156
	}
192
	}
157
	
193
	
158
	/* (non-Javadoc)
194
	/* (non-Javadoc)
159
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
195
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processEnumerator(org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator)
160
	 */
196
	 */
161
	public int visit(IASTEnumerator enumerator) {
197
	public int visit(IASTEnumerator enumerator) {
162
		return addRoot(enumerator);
198
		DOMASTNodeLeaf temp = addRoot(enumerator);
199
		if (temp == null)
200
			return PROCESS_ABORT;
201
		else if (temp instanceof DOMASTNodeLeafContinue)
202
			return PROCESS_CONTINUE;
203
		else
204
			return PROCESS_CONTINUE;
163
	}
205
	}
164
	
206
	
165
	/* (non-Javadoc)
207
	/* (non-Javadoc)
166
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
208
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processExpression(org.eclipse.cdt.core.dom.ast.IASTExpression)
167
	 */
209
	 */
168
	public int visit(IASTExpression expression) {
210
	public int visit(IASTExpression expression) {
169
		return addRoot(expression);
211
		DOMASTNodeLeaf temp = addRoot(expression);
212
		if (temp == null)
213
			return PROCESS_ABORT;
214
		else if (temp instanceof DOMASTNodeLeafContinue)
215
			return PROCESS_CONTINUE;
216
		else
217
			return PROCESS_CONTINUE;
170
	}
218
	}
171
	
219
	
172
	/* (non-Javadoc)
220
	/* (non-Javadoc)
173
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
221
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processInitializer(org.eclipse.cdt.core.dom.ast.IASTInitializer)
174
	 */
222
	 */
175
	public int visit(IASTInitializer initializer) {
223
	public int visit(IASTInitializer initializer) {
176
		return addRoot(initializer);
224
		DOMASTNodeLeaf temp = addRoot(initializer);
225
		if (temp == null)
226
			return PROCESS_ABORT;
227
		else if (temp instanceof DOMASTNodeLeafContinue)
228
			return PROCESS_CONTINUE;
229
		else
230
			return PROCESS_CONTINUE;
177
	}
231
	}
178
	
232
	
179
	/* (non-Javadoc)
233
	/* (non-Javadoc)
180
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
234
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processName(org.eclipse.cdt.core.dom.ast.IASTName)
181
	 */
235
	 */
182
	public int visit(IASTName name) {
236
	public int visit(IASTName name) {
237
		DOMASTNodeLeaf temp = null;
183
		if ( name.toString() != null )
238
		if ( name.toString() != null )
184
			return addRoot(name);
239
			temp = addRoot(name);
185
		return PROCESS_CONTINUE;
240
		else
241
			return PROCESS_CONTINUE;
242
		if (temp == null)
243
			return PROCESS_ABORT;
244
		else if (temp instanceof DOMASTNodeLeafContinue)
245
			return PROCESS_CONTINUE;
246
		else
247
			return PROCESS_CONTINUE;
186
	}
248
	}
187
	
249
	
188
	/* (non-Javadoc)
250
	/* (non-Javadoc)
Lines 190-226 Link Here
190
	 */
252
	 */
191
	public int visit(
253
	public int visit(
192
			IASTParameterDeclaration parameterDeclaration) {
254
			IASTParameterDeclaration parameterDeclaration) {
193
		return addRoot(parameterDeclaration);
255
		DOMASTNodeLeaf temp = addRoot(parameterDeclaration);
256
		if (temp == null)
257
			return PROCESS_ABORT;
258
		else if (temp instanceof DOMASTNodeLeafContinue)
259
			return PROCESS_CONTINUE;
260
		else
261
			return PROCESS_CONTINUE;
194
	}
262
	}
195
	
263
	
196
	/* (non-Javadoc)
264
	/* (non-Javadoc)
197
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
265
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processStatement(org.eclipse.cdt.core.dom.ast.IASTStatement)
198
	 */
266
	 */
199
	public int visit(IASTStatement statement) {
267
	public int visit(IASTStatement statement) {
200
		return addRoot(statement);
268
		DOMASTNodeLeaf temp = addRoot(statement);
269
		if (temp == null)
270
			return PROCESS_ABORT;
271
		else if (temp instanceof DOMASTNodeLeafContinue)
272
			return PROCESS_CONTINUE;
273
		else
274
			return PROCESS_CONTINUE;
201
	}
275
	}
202
	
276
	
203
	/* (non-Javadoc)
277
	/* (non-Javadoc)
204
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
278
	 * @see org.eclipse.cdt.internal.core.dom.parser.c.CVisitor.CBaseVisitorAction#processTypeId(org.eclipse.cdt.core.dom.ast.IASTTypeId)
205
	 */
279
	 */
206
	public int visit(IASTTypeId typeId) {
280
	public int visit(IASTTypeId typeId) {
207
		return addRoot(typeId);
281
		DOMASTNodeLeaf temp = addRoot(typeId);
282
		if (temp == null)
283
			return PROCESS_ABORT;
284
		else if (temp instanceof DOMASTNodeLeafContinue)
285
			return PROCESS_CONTINUE;
286
		else
287
			return PROCESS_CONTINUE;
208
	}
288
	}
209
	
289
	
210
	private void mergeNode(ASTNode node) {
290
	private DOMASTNodeLeaf mergeNode(ASTNode node) {
211
		addRoot(node);
291
		DOMASTNodeLeaf temp = addRoot(node);
212
		
292
		
213
		if (node instanceof IASTPreprocessorMacroDefinition )
293
		if (node instanceof IASTPreprocessorMacroDefinition )
214
			addRoot(((IASTPreprocessorMacroDefinition)node).getName());
294
			addRoot(((IASTPreprocessorMacroDefinition)node).getName());
295
		
296
		return temp;
215
	}
297
	}
216
	
298
	
217
	public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
299
	public DOMASTNodeLeaf[] mergePreprocessorStatements(IASTPreprocessorStatement[] statements) {
300
		DOMASTNodeLeaf[] leaves = new DOMASTNodeLeaf[statements.length];
218
		for(int i=0; i<statements.length; i++) {
301
		for(int i=0; i<statements.length; i++) {
219
			if (monitor != null && monitor.isCanceled()) return;
302
			if (monitor != null && monitor.isCanceled()) return leaves;
220
			
303
			
221
			if (statements[i] instanceof ASTNode)
304
			if (statements[i] instanceof ASTNode)
222
				mergeNode((ASTNode)statements[i]);
305
				leaves[i] = mergeNode((ASTNode)statements[i]);
223
		}
306
		}
307
		
308
		return leaves;
224
	}
309
	}
225
	
310
	
226
	public void mergePreprocessorProblems(IASTProblem[] problems) {
311
	public void mergePreprocessorProblems(IASTProblem[] problems) {
Lines 236-281 Link Here
236
		return root;
321
		return root;
237
	}
322
	}
238
	
323
	
239
	public void groupIncludes(IASTPreprocessorStatement[] statements) {
324
	public void groupIncludes(DOMASTNodeLeaf[] treeIncludes) {
240
		// get all of the includes from the preprocessor statements (need the object since .equals isn't implemented)
241
		IASTPreprocessorIncludeStatement[] includes = new IASTPreprocessorIncludeStatement[INITIAL_INCLUDE_STATEMENT_SIZE];
242
		int index = 0;
243
		for(int i=0; i<statements.length; i++) {
244
			if (monitor != null && monitor.isCanceled()) return;
245
			if (statements[i] instanceof IASTPreprocessorIncludeStatement) {
246
				if (index == includes.length) {
247
					includes = (IASTPreprocessorIncludeStatement[])ArrayUtil.append(IASTPreprocessorIncludeStatement.class, includes, statements[i]);
248
					index++;
249
				} else {
250
					includes[index++] = (IASTPreprocessorIncludeStatement)statements[i];	
251
				}
252
			}
253
		}
254
		
255
		// get the tree model elements corresponding to the includes
256
		DOMASTNodeParent[] treeIncludes = new DOMASTNodeParent[index];
257
		for (int i=0; i<treeIncludes.length; i++) {
258
			if (monitor != null && monitor.isCanceled()) return;
259
			treeIncludes[i] = root.findTreeObject(includes[i], false);
260
		}
261
		
262
		// loop through the includes and make sure that all of the nodes 
325
		// loop through the includes and make sure that all of the nodes 
263
		// that are children of the TU are in the proper include (based on offset)
326
		// that are children of the TU are in the proper include (based on offset)
264
		DOMASTNodeLeaf child = null;
327
		DOMASTNodeLeaf child = null;
265
		outerLoop: for (int i=treeIncludes.length-1; i>=0; i--) {
328
		outerLoop: for (int i=treeIncludes.length-1; i>=0; i--) {
266
			if (treeIncludes[i] == null) continue;
329
			if (treeIncludes[i] == null) continue;
267
330
331
			IASTNode node = null;
268
			for(int j=root.getChildren(false).length-1; j>=0; j--) {
332
			for(int j=root.getChildren(false).length-1; j>=0; j--) {
269
				if (monitor != null && monitor.isCanceled()) return;
333
//				if (monitor != null && monitor.isCanceled()) return; // this causes a deadlock when checked here
270
				child = root.getChildren(false)[j]; 
334
				child = root.getChildren(false)[j];
271
				
335
				
336
				node = treeIncludes[i].getNode();
272
				if (child != null && 
337
				if (child != null && 
273
						treeIncludes[i] != child &&
338
						treeIncludes[i] != child &&
274
						includes[i] instanceof ASTInclusionStatement &&
339
						node instanceof ASTInclusionStatement &&
275
						((ASTNode)child.getNode()).getOffset() >= ((ASTInclusionStatement)includes[i]).startOffset &&
340
						((ASTNode)child.getNode()).getOffset() >= ((ASTInclusionStatement)node).startOffset &&
276
						((ASTNode)child.getNode()).getOffset() <= ((ASTInclusionStatement)includes[i]).endOffset) {
341
						((ASTNode)child.getNode()).getOffset() <= ((ASTInclusionStatement)node).endOffset) {
277
					root.removeChild(child);
342
					root.removeChild(child);
278
					treeIncludes[i].addChild(child);
343
					((DOMASTNodeParent)treeIncludes[i]).addChild(child);
279
				}
344
				}
280
			}
345
			}
281
		}
346
		}
(-)src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java (-137 / +137 lines)
Lines 404-410 Link Here
404
	         monitor.subTask(MERGING_ + statements.length + _PREPROCESSOR_STATEMENTS_);
404
	         monitor.subTask(MERGING_ + statements.length + _PREPROCESSOR_STATEMENTS_);
405
	         start=System.currentTimeMillis();
405
	         start=System.currentTimeMillis();
406
	         // merge preprocessor statements to the tree
406
	         // merge preprocessor statements to the tree
407
	         action.mergePreprocessorStatements(statements);
407
	         DOMASTNodeLeaf[] includeStatements = action.mergePreprocessorStatements(statements);
408
	         monitor.worked(2);
408
	         monitor.worked(2);
409
	         System.out.println(DOM_AST_VIEW_DONE + MERGING_ + statements.length + _PREPROCESSOR_STATEMENTS_ + COLON_SPACE + (System.currentTimeMillis()- start) );
409
	         System.out.println(DOM_AST_VIEW_DONE + MERGING_ + statements.length + _PREPROCESSOR_STATEMENTS_ + COLON_SPACE + (System.currentTimeMillis()- start) );
410
	         
410
	         
Lines 426-432 Link Here
426
	         monitor.subTask(GROUPING_AST);
426
	         monitor.subTask(GROUPING_AST);
427
	         start=System.currentTimeMillis();
427
	         start=System.currentTimeMillis();
428
	         // group #includes
428
	         // group #includes
429
	         action.groupIncludes(statements);
429
	         action.groupIncludes(includeStatements);
430
	         monitor.worked(30);
430
	         monitor.worked(30);
431
	         System.out.println(DOM_AST_VIEW_DONE + GROUPING_AST + COLON_SPACE + (System.currentTimeMillis()- start) );
431
	         System.out.println(DOM_AST_VIEW_DONE + GROUPING_AST + COLON_SPACE + (System.currentTimeMillis()- start) );
432
432
Lines 811-951 Link Here
811
   }
811
   }
812
812
813
   private void makeActions() {
813
   private void makeActions() {
814
 	  loadActiveEditorAction = new Action() {
814
	   loadActiveEditorAction = new Action() {
815
        public void run() {
815
		   public void run() {
816
        	openDOMASTView(getActiveEditor());
816
			   openDOMASTView(getActiveEditor());
817
        }
817
		   }
818
     };
818
	   };
819
     loadActiveEditorAction.setText(LOAD_ACTIVE_EDITOR);
819
	   loadActiveEditorAction.setText(LOAD_ACTIVE_EDITOR);
820
     loadActiveEditorAction.setToolTipText(LOAD_ACTIVE_EDITOR);
820
	   loadActiveEditorAction.setToolTipText(LOAD_ACTIVE_EDITOR);
821
     loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_RELOAD_VIEW);
821
	   loadActiveEditorAction.setImageDescriptor(DOMASTPluginImages.DESC_RELOAD_VIEW);
822
   	
822
	   
823
     refreshAction = new Action() {
823
	   refreshAction = new Action() {
824
         public void run() {
824
		   public void run() {
825
            // take a snapshot of the tree expansion
825
			   // take a snapshot of the tree expansion
826
         	Object[] expanded = viewer.getExpandedElements();
826
			   Object[] expanded = viewer.getExpandedElements();
827
827
			   
828
         	// set the new content provider
828
			   // set the new content provider
829
         	setContentProvider(new ViewContentProvider(file, expanded));
829
			   setContentProvider(new ViewContentProvider(file, expanded));
830
         }
830
		   }
831
      };
831
	   };
832
      refreshAction.setText(REFRESH_DOM_AST);
832
	   refreshAction.setText(REFRESH_DOM_AST);
833
      refreshAction.setToolTipText(REFRESH_DOM_AST);
833
	   refreshAction.setToolTipText(REFRESH_DOM_AST);
834
      refreshAction.setImageDescriptor(DOMASTPluginImages.DESC_REFRESH_VIEW);
834
	   refreshAction.setImageDescriptor(DOMASTPluginImages.DESC_REFRESH_VIEW);
835
835
	   
836
     expandAllAction = new Action() {
836
	   expandAllAction = new Action() {
837
        public void run() {
837
		   public void run() {
838
        	viewer.expandAll();
838
			   viewer.expandAll();
839
        }
839
		   }
840
     };
840
	   };
841
     expandAllAction.setText(EXPAND_ALL);
841
	   expandAllAction.setText(EXPAND_ALL);
842
     expandAllAction.setToolTipText(EXPAND_ALL);
842
	   expandAllAction.setToolTipText(EXPAND_ALL);
843
     expandAllAction.setImageDescriptor(DOMASTPluginImages.DESC_EXPAND_ALL);
843
	   expandAllAction.setImageDescriptor(DOMASTPluginImages.DESC_EXPAND_ALL);
844
     
844
	   
845
     collapseAllAction = new Action() {
845
	   collapseAllAction = new Action() {
846
        public void run() {
846
		   public void run() {
847
        	viewer.collapseAll();
847
			   viewer.collapseAll();
848
        }
848
		   }
849
     };
849
	   };
850
     collapseAllAction.setText(COLLAPSE_ALL);
850
	   collapseAllAction.setText(COLLAPSE_ALL);
851
     collapseAllAction.setToolTipText(COLLAPSE_ALL);
851
	   collapseAllAction.setToolTipText(COLLAPSE_ALL);
852
     collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL);
852
	   collapseAllAction.setImageDescriptor(DOMASTPluginImages.DESC_COLLAPSE_ALL);
853
853
	   
854
     clearAction = new Action() {
854
	   clearAction = new Action() {
855
        public void run() {
855
		   public void run() {
856
        	viewer.setContentProvider(new ViewContentProvider(null));
856
			   viewer.setContentProvider(new ViewContentProvider(null));
857
        	viewer.refresh();
857
			   viewer.refresh();
858
        }
858
		   }
859
     };
859
	   };
860
     clearAction.setText(CLEAR);
860
	   clearAction.setText(CLEAR);
861
     clearAction.setToolTipText(CLEAR);
861
	   clearAction.setToolTipText(CLEAR);
862
     clearAction.setImageDescriptor(DOMASTPluginImages.DESC_CLEAR);
862
	   clearAction.setImageDescriptor(DOMASTPluginImages.DESC_CLEAR);
863
     
863
	   
864
     searchNamesAction = new Action() {
864
	   searchNamesAction = new Action() {
865
        private void performSearch() {
865
		   private void performSearch() {
866
        	if (viewer.getTree().getItems().length == 0) {
866
			   if (viewer.getTree().getItems().length == 0) {
867
        		showMessage(DOM_AST_HAS_NO_CONTENT);
867
				   showMessage(DOM_AST_HAS_NO_CONTENT);
868
        	}
868
			   }
869
        	
869
			   
870
        	FindIASTNameDialog dialog = new FindIASTNameDialog(getSite().getShell(), new FindIASTNameTarget(viewer, lang));
870
			   FindIASTNameDialog dialog = new FindIASTNameDialog(getSite().getShell(), new FindIASTNameTarget(viewer, lang));
871
        	dialog.open();
871
			   dialog.open();
872
       }
872
		   }
873
     	
873
		   
874
     	public void run() {
874
		   public void run() {
875
     		performSearch();
875
			   performSearch();
876
        }
876
		   }
877
     };
877
	   };
878
     searchNamesAction.setText(SEARCH_FOR_IASTNAME);
878
	   searchNamesAction.setText(SEARCH_FOR_IASTNAME);
879
     searchNamesAction.setToolTipText(SEARCH_FOR_IASTNAME);
879
	   searchNamesAction.setToolTipText(SEARCH_FOR_IASTNAME);
880
     searchNamesAction.setImageDescriptor(DOMASTPluginImages.DESC_SEARCH_NAMES);
880
	   searchNamesAction.setImageDescriptor(DOMASTPluginImages.DESC_SEARCH_NAMES);
881
     
881
	   
882
      openDeclarationsAction = new DisplayDeclarationsAction();
882
	   openDeclarationsAction = new DisplayDeclarationsAction();
883
      openDeclarationsAction.setText(OPEN_DECLARATIONS);
883
	   openDeclarationsAction.setText(OPEN_DECLARATIONS);
884
      openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
884
	   openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
885
            .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
885
			   .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
886
886
	   
887
      openReferencesAction = new DisplayReferencesAction();
887
	   openReferencesAction = new DisplayReferencesAction();
888
      openReferencesAction.setText(OPEN_REFERENCES);
888
	   openReferencesAction.setText(OPEN_REFERENCES);
889
      openReferencesAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
889
	   openReferencesAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
890
            .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
890
			   .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
891
	  
891
	   
892
	  displayProblemsAction = new DisplayProblemsResultAction();
892
	   displayProblemsAction = new DisplayProblemsResultAction();
893
	  displayProblemsAction.setText(DISPLAY_PROBLEMS);
893
	   displayProblemsAction.setText(DISPLAY_PROBLEMS);
894
      displayProblemsAction.setImageDescriptor(DOMASTPluginImages.DESC_IASTProblem);
894
	   displayProblemsAction.setImageDescriptor(DOMASTPluginImages.DESC_IASTProblem);
895
	  
895
	   
896
	  displayNodeTypeAction = new Action() { 
896
	   displayNodeTypeAction = new Action() { 
897
		  public void run() {
897
		   public void run() {
898
			  ISelection selection = viewer.getSelection();
898
			   ISelection selection = viewer.getSelection();
899
		     	if (selection instanceof IStructuredSelection &&
899
			   if (selection instanceof IStructuredSelection &&
900
		     			((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
900
					   ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
901
		     			((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) {
901
					   ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) {
902
					showMessage("ASTUtil#getNodeType(IASTNode): \"" + ASTTypeUtil.getNodeType(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
902
				   showMessage("ASTUtil#getNodeType(IASTNode): \"" + ASTTypeUtil.getNodeType(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
903
		     	}
903
			   }
904
		  } };
904
		   } };
905
	  displayNodeTypeAction.setText(DISPLAY_TYPE);
905
	   displayNodeTypeAction.setText(DISPLAY_TYPE);
906
      displayNodeTypeAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
906
	   displayNodeTypeAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
907
            .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
907
			   .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
908
908
	   
909
	  displayNodeSignatureAction = new Action() { 
909
	   displayNodeSignatureAction = new Action() { 
910
		  public void run() {
910
		   public void run() {
911
			  ISelection selection = viewer.getSelection();
911
			   ISelection selection = viewer.getSelection();
912
		     	if (selection instanceof IStructuredSelection &&
912
			   if (selection instanceof IStructuredSelection &&
913
		     			((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
913
					   ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
914
		     			((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) {
914
					   ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() != null) {
915
					showMessage("ASTSignatureUtil#getNodeSignature(IASTNode): \"" + ASTSignatureUtil.getNodeSignature(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
915
				   showMessage("ASTSignatureUtil#getNodeSignature(IASTNode): \"" + ASTSignatureUtil.getNodeSignature(((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
916
		     	}
916
			   }
917
		  } };
917
		   } };
918
      displayNodeSignatureAction.setText(DISPLAY_SIGNATURE);
918
	   displayNodeSignatureAction.setText(DISPLAY_SIGNATURE);
919
	  displayNodeSignatureAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
919
	   displayNodeSignatureAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
920
		  .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
920
			   .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
921
	  
921
	   
922
	  displayExpressionAction = new Action() { 
922
	   displayExpressionAction = new Action() { 
923
		  public void run() {
923
		   public void run() {
924
			  ISelection selection = viewer.getSelection();
924
			   ISelection selection = viewer.getSelection();
925
		     	if (selection instanceof IStructuredSelection &&
925
			   if (selection instanceof IStructuredSelection &&
926
		     			((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
926
					   ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
927
		     			((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTExpression) {
927
					   ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTExpression) {
928
					showMessage("ASTSignatureUtil#getExpressionString(IASTExpression): \"" + ASTSignatureUtil.getExpressionString((IASTExpression)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
928
				   showMessage("ASTSignatureUtil#getExpressionString(IASTExpression): \"" + ASTSignatureUtil.getExpressionString((IASTExpression)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
929
		     	}
929
			   }
930
		  } };
930
		   } };
931
	  displayExpressionAction.setText(DISPLAY_EXPRESSION);
931
	   displayExpressionAction.setText(DISPLAY_EXPRESSION);
932
	  displayExpressionAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
932
	   displayExpressionAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
933
		  .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
933
			   .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
934
	  
934
	   
935
	  displayInitializerAction = new Action() { 
935
	   displayInitializerAction = new Action() { 
936
		  public void run() {
936
		   public void run() {
937
			  ISelection selection = viewer.getSelection();
937
			   ISelection selection = viewer.getSelection();
938
		     	if (selection instanceof IStructuredSelection &&
938
			   if (selection instanceof IStructuredSelection &&
939
		     			((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
939
					   ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf &&
940
		     			((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTInitializer) {
940
					   ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTInitializer) {
941
					showMessage("ASTSignatureUtil#getInitializerString(IASTInitializer): \"" + ASTSignatureUtil.getInitializerString((IASTInitializer)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
941
				   showMessage("ASTSignatureUtil#getInitializerString(IASTInitializer): \"" + ASTSignatureUtil.getInitializerString((IASTInitializer)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode()) + "\""); //$NON-NLS-1$ //$NON-NLS-2$
942
		     	}
942
			   }
943
		  } };
943
		   } };
944
	  displayInitializerAction.setText(DISPLAY_INITIALIZER);
944
	   displayInitializerAction.setText(DISPLAY_INITIALIZER);
945
	  displayInitializerAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
945
	   displayInitializerAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
946
		  .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
946
			   .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
947
	  
947
	   
948
      singleClickAction = new ASTHighlighterAction(part);
948
	   singleClickAction = new ASTHighlighterAction(part);
949
   }
949
   }
950
950
951
   protected IEditorPart getActiveEditor() {
951
   protected IEditorPart getActiveEditor() {
(-)src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeParent.java (-75 / +107 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.cdt.ui.tests.DOMAST;
11
package org.eclipse.cdt.ui.tests.DOMAST;
12
12
13
import java.lang.reflect.Array;
13
import java.util.Arrays;
14
import java.util.Arrays;
14
import java.util.Comparator;
15
import java.util.Comparator;
15
16
16
import org.eclipse.cdt.core.dom.ast.IASTNode;
17
import org.eclipse.cdt.core.dom.ast.IASTNode;
17
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
18
import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
18
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
19
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
19
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
20
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
20
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
21
import org.eclipse.cdt.core.parser.util.ArrayUtil;
21
import org.eclipse.cdt.core.parser.util.ArrayUtil;
Lines 88-98 Link Here
88
        return children;
88
        return children;
89
	}
89
	}
90
    
90
    
91
	/**
92
	 * Inserts obj into the array at position pos and if this is not possible (due to a bad offset)
93
	 * then the obj is just appended to the end of the array.
94
	 * 
95
	 * @param c
96
	 * @param array
97
	 * @param obj
98
	 * @param pos
99
	 * @return
100
	 */
101
	public Object[] insert(Class c, Object[] array, Object obj, int pos) {
102
		if (pos < 0 || pos >= array.length) {
103
			return ArrayUtil.append(c, array, obj);
104
		}
105
		
106
		Object[] temp = (Object[]) Array.newInstance( c, array.length + 1 );
107
		if (pos > 0) {
108
			System.arraycopy( array, 0, temp, 0, pos );
109
			temp[pos] = obj;
110
			System.arraycopy( array, pos, temp, pos + 1, array.length - pos );
111
		} else {
112
			temp[0] = obj;
113
			System.arraycopy( array, 0, temp, 1, array.length );
114
		}
115
		
116
		return temp;
117
	}
118
	
91
    public void cleanChildren() {
119
    public void cleanChildren() {
92
        // remove null elements
120
        // remove null elements
93
        children = (DOMASTNodeLeaf[])ArrayUtil.removeNulls(DOMASTNodeLeaf.class, children);
121
        children = (DOMASTNodeLeaf[])ArrayUtil.removeNulls(DOMASTNodeLeaf.class, children);
94
        
122
        
95
        // sort the elements
123
        // sort the elements
124
//		if (indexFirstPreproStmnt >= 0) { // TODO Devin what if it's ALL preprocessor statements ?
125
			int firstOffset=0;
126
			int firstLength=0;
127
			int checkOffset=0;
128
			int checkLength=0;
129
			boolean moved=false;
130
			for (int j=0, i=0; j<children.length; ) { // TODO Devin need to update indexFirstPreproStmnt
131
				i=0; // TODO Devin there is a problem with this... but work on this patch over the weekend instead of at work...
132
				
133
				while(true) {
134
					if (i==j) break; // don't need to check itself or anything after it //TODO Devin is this completely correct? even with #incluedes?
135
					
136
					checkOffset = ((ASTNode)children[j].getNode()).getOffset();
137
					checkLength = ((ASTNode)children[j].getNode()).getLength();
138
					firstOffset = ((ASTNode)children[i].getNode()).getOffset();
139
					firstLength = ((ASTNode)children[i].getNode()).getLength();
140
					
141
					// if the checking element comes before the first element then move the checking element before the first element
142
					if (checkOffset < firstOffset && checkOffset + checkLength < firstOffset + firstLength) {
143
						// TODO Devin would it be possible to do a switch instead of insert and then remove nulls ???
144
						DOMASTNodeLeaf temp = children[j];
145
						children[j] = null;
146
						children = (DOMASTNodeLeaf[])ArrayUtil.removeNulls(DOMASTNodeLeaf.class, children);
147
						children = (DOMASTNodeLeaf[])insert(DOMASTNodeLeaf.class, children, temp, i);
148
						break;
149
					}
150
					
151
					// if the checking element is within the bounds of the first element then it must be a child of that element
152
					if (checkOffset > firstOffset && checkOffset + checkLength < firstOffset + firstLength) {
153
						DOMASTNodeLeaf temp = children[j];
154
						children[j] = null;
155
						children = (DOMASTNodeLeaf[])ArrayUtil.removeNulls(DOMASTNodeLeaf.class, children);
156
						((DOMASTNodeParent)children[i]).addChild(temp);
157
						moved=true;
158
						break;
159
					}
160
					
161
					i++;
162
				}
163
				
164
				if (!moved) {
165
					j++;
166
				} else {
167
					moved=false;
168
				}
169
			}
170
//		}
171
		
96
        Arrays.sort(children, new Comparator() {
172
        Arrays.sort(children, new Comparator() {
97
            public int compare(Object a, Object b) {
173
            public int compare(Object a, Object b) {
98
                if(a instanceof DOMASTNodeLeaf && b instanceof DOMASTNodeLeaf &&
174
                if(a instanceof DOMASTNodeLeaf && b instanceof DOMASTNodeLeaf &&
Lines 157-163 Link Here
157
            if (nodeChain[i] != null) {
233
            if (nodeChain[i] != null) {
158
                parentToFind = nodeChain[i];
234
                parentToFind = nodeChain[i];
159
                
235
                
160
                for(; j>=indexFirstPreproStmnt; j--) {
236
                for(; j>=0; j--) {
161
                    if (childrenToSearch[j] instanceof DOMASTNodeParent) {
237
                    if (childrenToSearch[j] instanceof DOMASTNodeParent) {
162
                        if ( childrenToSearch[j].getNode() == node.getParent() ) {
238
                        if ( childrenToSearch[j].getNode() == node.getParent() ) {
163
                            return (DOMASTNodeParent)childrenToSearch[j];
239
                            return (DOMASTNodeParent)childrenToSearch[j];
Lines 270-349 Link Here
270
		if (equalNodes(node, this.getNode(), useOffset)) {
346
		if (equalNodes(node, this.getNode(), useOffset)) {
271
			return this;
347
			return this;
272
		}
348
		}
273
		if( !useOffset || node instanceof IASTPreprocessorStatement) {
349
		if( children.length == 0 )
274
		    IASTNode nodeToFind = node;
350
			return null;
275
		    // build the chain of nodes... and use it to search the tree for the DOMASTNodeParent that contains the node
351
		if( !cleanupedElements ){
276
			IASTNode[] nodeChain = new IASTNode[DEFAULT_NODE_CHAIN_SIZE];
352
			cleanChildren();
277
			IASTNode topNode = node;
278
			nodeChain = (IASTNode[])ArrayUtil.append(IASTNode.class, nodeChain, topNode);
279
			while(topNode.getParent() != null && !(topNode.getParent() instanceof IASTTranslationUnit)) {
280
				topNode = topNode.getParent();
281
				nodeChain = (IASTNode[])ArrayUtil.append(IASTNode.class, nodeChain, topNode);
282
			}
283
			
284
			// loop through the chain of nodes and use it to only search the necessary children required to find the node
285
			DOMASTNodeLeaf[] childrenToSearch = children;
286
			outerLoop: for(int i=nodeChain.length-1; i>=0; i--) {
287
				if (nodeChain[i] != null) {
288
					nodeToFind = nodeChain[i];
289
					
290
					for(int j=0; j<childrenToSearch.length; j++) {
291
						if (childrenToSearch[j] instanceof DOMASTNodeParent) {
292
							
293
							if ( equalNodes(childrenToSearch[j].getNode(), node, useOffset) ) { 
294
								return (DOMASTNodeParent)childrenToSearch[j];
295
							}						
296
							
297
							if ( equalNodes(childrenToSearch[j].getNode(), nodeToFind, useOffset) ) {
298
								childrenToSearch = ((DOMASTNodeParent)childrenToSearch[j]).getChildren(false);
299
								continue outerLoop;
300
							}
301
							
302
							// since the nodeChain doesn't include #includes, if an #include is encountered then search it's children
303
							if (childrenToSearch[j].getNode() instanceof IASTPreprocessorIncludeStatement) {
304
								DOMASTNodeParent foundParentInInclude = ((DOMASTNodeParent)childrenToSearch[j]).findTreeObject(node, useOffset);
305
								if(foundParentInInclude != null) {
306
									return foundParentInInclude;
307
								}
308
							}
309
						}
310
					}
311
				}
312
			}
313
		} else {
314
		    if( children.length == 0 )
315
			    return null;
316
		    if( !cleanupedElements ){
317
		        cleanChildren();
318
		    }
319
			int a = 0, z = children.length - 1;
320
			int idx = (z - a) / 2 ;
321
			while( true ){
322
			    int compare = children[ idx ].relativeNodePosition( node );
323
			    if( compare == 0 ){
324
			        if( children[idx] instanceof DOMASTNodeParent ){
325
			            return ((DOMASTNodeParent)children[idx]).findTreeObject( node, useOffset );
326
			        }
327
			        return null; //??
328
			    } else if( compare == -1 )
329
			        z = idx;
330
			    else
331
			        a = idx;
332
			    int diff = z - a;
333
			    if( diff == 0 )
334
			        return null;
335
			    else if( diff == 1 )
336
			        idx = ( idx == z ) ? a : z;
337
			    else 
338
			        idx = a + ( z - a ) / 2;
339
			    if( z == a )
340
			        return null;
341
			    if( z - a == 1 && children[ a ].relativeNodePosition( node ) == 1 && children[ z ].relativeNodePosition( node ) == -1 )
342
			        return null;
343
			}   
344
		}
353
		}
345
		
354
		int a = 0, z = children.length - 1;
346
		return null; // nothing found
355
		int idx = (z - a) / 2 ;
356
		while( true ){
357
			int compare = children[ idx ].relativeNodePosition( node );
358
			if( compare == 0 ){
359
				if( children[idx] instanceof DOMASTNodeParent ){
360
					return ((DOMASTNodeParent)children[idx]).findTreeObject( node, useOffset );
361
				}
362
				return null; //??
363
			} else if( compare == -1 )
364
				z = idx;
365
			else
366
				a = idx;
367
			int diff = z - a;
368
			if( diff == 0 )
369
				return null;
370
			else if( diff == 1 )
371
				idx = ( idx == z ) ? a : z;
372
			else 
373
				idx = a + ( z - a ) / 2;
374
			if( z == a )
375
				return null;
376
			if( z - a == 1 && children[ a ].relativeNodePosition( node ) == 1 && children[ z ].relativeNodePosition( node ) == -1 )
377
				return null;
378
		}   
347
	}
379
	}
348
	
380
	
349
	private boolean equalNodes(IASTNode node1, IASTNode node2, boolean useOffset) {
381
	private boolean equalNodes(IASTNode node1, IASTNode node2, boolean useOffset) {
(-)src/org/eclipse/cdt/ui/tests/DOMAST/IPopulateDOMASTAction.java (-2 / +2 lines)
Lines 18-24 Link Here
18
 */
18
 */
19
public interface IPopulateDOMASTAction {
19
public interface IPopulateDOMASTAction {
20
	public DOMASTNodeParent getTree();
20
	public DOMASTNodeParent getTree();
21
	public void mergePreprocessorStatements(IASTPreprocessorStatement[] statements);
21
	public DOMASTNodeLeaf[] mergePreprocessorStatements(IASTPreprocessorStatement[] statements);
22
	public void mergePreprocessorProblems(IASTProblem[] problems);
22
	public void mergePreprocessorProblems(IASTProblem[] problems);
23
	public void groupIncludes(IASTPreprocessorStatement[] statements);
23
	public void groupIncludes(DOMASTNodeLeaf[] statements);
24
}
24
}

Return to bug 94989