Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8ee622b7c0e70bde4374e47c91f8148bfe90acc8 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2007, 2009 Wind River Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.presentation;

import java.util.Collection;

import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.runtime.ListenerList;

/**
 * A source tag provider based on the C Model.
 */
public class CSourceTagProvider implements ISourceTagProvider {

	private ListenerList fListenerList= new ListenerList(ListenerList.IDENTITY);
	private ITranslationUnit fUnit;
	
	/**
	 * Create a new source tag provider for the given translation unit.
	 * 
	 * @param unit
	 */
	public CSourceTagProvider(ITranslationUnit unit) {
		fUnit= unit;
	}

	public void addSourceTagListener(ISourceTagListener listener) {
		fListenerList.add(listener);
	}

	public int[] getActiveCodePositions() {
		// unsupported
		return null;
	}

	public long getSnapshotTime() {
		return 0;
	}

	public void getSourceTags(Collection<ISourceTag> target) {
		try {
			convertToSourceTags(fUnit.getChildren(), target);
		} catch (CModelException e) {
		}
	}

	/**
	 * @param element
	 * @return
	 */
	private ISourceTag convertToSourceTag(ICElement element) {
		if (element instanceof ISourceReference) {
			return new CSourceTag((ISourceReference)element, element.getElementType());
		}
		return null;
	}

	/**
	 * @param children
	 * @param target
	 * @throws CModelException
	 */
	private void convertToSourceTags(ICElement[] children, Collection<ISourceTag> target) throws CModelException {
		for (int i = 0; i < children.length; i++) {
			ICElement element= children[i];
			ISourceTag tag= convertToSourceTag(element);
			if (tag != null) {
				target.add(tag);
			}
			if (element instanceof IParent) {
				convertToSourceTags(((IParent)element).getChildren(), target);
			}
		}
	}

	/*
	 * @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.presentation.ISourceTagProvider#removeSourceTagListener(org.eclipse.cdt.dsf.debug.internal.ui.disassembly.presentation.ISourceTagListener)
	 */
	public void removeSourceTagListener(ISourceTagListener listener) {
		fListenerList.remove(listener);
	}

}

Back to the top