summaryrefslogtreecommitdiffstats
path: root/org.eclipse.ptp.pldt.mpi.analysis.cdt/src/org/eclipse/ptp/pldt/mpi/analysis/cdt/graphs/impl/CallGraphNode.java
blob: 11bf50d8e8c253d8fb53748129b47ef2100387e4 (plain)
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
154
155
156
157
158
159
160
161
162
163
/**********************************************************************
 * Copyright (c) 2007, 2008 IBM Corporation.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.impl;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.core.resources.IResource;
import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.ICallGraphNode;
import org.eclipse.ptp.pldt.mpi.analysis.cdt.graphs.IControlFlowGraph;

/**
 * Implementation of a call graph node, which represents a user-defined
 * function
 *
 */
public class CallGraphNode implements ICallGraphNode {
	protected IResource resource_;
	protected String fileName_;
	protected String funcName_;
	protected IASTFunctionDefinition fdef_;
	protected List<ICallGraphNode> callers_;
	protected List<ICallGraphNode> callees_;
	protected boolean nested; //nested function declaration?
	protected IControlFlowGraph CFG_;
	
	/** next node in reverse-topological (bottom-up) order */
	protected ICallGraphNode botNext_;
	/** next node in topological (top-down) order */
	protected ICallGraphNode topNext_; 
	protected Hashtable<String,Object> attrs_;

	protected boolean recursive;
	
	public CallGraphNode(IResource resource, String filename, 
				String funcname, IASTFunctionDefinition fdef){
		resource_ = resource;
		fileName_ = filename;
		funcName_ = funcname;
		fdef_ = fdef;
		init();
	}
	
	public CallGraphNode(IResource resource, String filename, 
				IASTFunctionDefinition fdef){
		resource_ = resource;
		fileName_ = filename;
		fdef_ = fdef;
		funcName_ = getFuncName(fdef);	
		init();
	}
	
	private void init(){
		callers_ = new ArrayList<ICallGraphNode>();
		callees_ = new ArrayList<ICallGraphNode>();
		nested = false;
		CFG_ = null; 
		topNext_ = null;
		botNext_ = null;
		attrs_ = new Hashtable<String,Object>();
		recursive = false;
	}
	
	private String getFuncName(IASTFunctionDefinition fdef){
		IASTDeclarator fdecl = (IASTDeclarator)fdef.getDeclarator();
		return new String(((IASTName)fdecl.getName()).toCharArray());
	}
	
	public String getFuncName(){
		return funcName_;
	}
	
	public String getFileName(){
		return fileName_;
	}
	
	public IResource getResource(){
		return resource_;
	}
	
	public IASTFunctionDefinition getFuncDef(){
		return fdef_;
	}
	
	public boolean isNested(){
		return nested;
	}
	
	public List<ICallGraphNode> getCallers(){
		return callers_;
	}
	
	public void addCaller(ICallGraphNode caller){
		if(!callers_.contains(caller))
			callers_.add(caller);
	}
	
	public List<ICallGraphNode>	getCallees(){
		return callees_;
	}
	
	public void addCallee(ICallGraphNode callee){
		if(!callees_.contains(callee))
			callees_.add(callee);
	}
	/** Returns next node in reverse-topological (bottom-up) order */
	public ICallGraphNode botNext() {
		return botNext_;
	}

	public void setBotNext(ICallGraphNode node){
		botNext_ = node;
	}
	
	public IControlFlowGraph getCFG() {
		return CFG_;
	}
	/** Returns next node in topological (top-down) order */
	public ICallGraphNode topNext() {
		return topNext_;
	}

	public void setTopNext(ICallGraphNode node){
		topNext_ = node;
	}
	
	public void setCFG(IControlFlowGraph cfg) {
		CFG_ = cfg;
	}
	
	public void setAttr(String name, Object attr){
		attrs_.put(name, attr);
	}
	public Object getAttr(String name){
		return attrs_.get(name);
	}
	
	public void removeAttr(String name){
		attrs_.remove(name);
	}
	
	public void setRecursive(boolean val){
		recursive = val;
	}
	
	public boolean isRecursive(){
		return recursive;
	}

}