xref: /haiku/headers/private/debugger/debug_info/Function.h (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
1*fce4895dSRene Gollent /*
2*fce4895dSRene Gollent  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3*fce4895dSRene Gollent  * Copyright 2010, Rene Gollent, rene@gollent.com.
4*fce4895dSRene Gollent  * Distributed under the terms of the MIT License.
5*fce4895dSRene Gollent  */
6*fce4895dSRene Gollent #ifndef FUNCTION_H
7*fce4895dSRene Gollent #define FUNCTION_H
8*fce4895dSRene Gollent 
9*fce4895dSRene Gollent #include <util/DoublyLinkedList.h>
10*fce4895dSRene Gollent #include <util/OpenHashTable.h>
11*fce4895dSRene Gollent 
12*fce4895dSRene Gollent #include "FunctionInstance.h"
13*fce4895dSRene Gollent #include "LocatableFile.h"
14*fce4895dSRene Gollent 
15*fce4895dSRene Gollent 
16*fce4895dSRene Gollent class FileSourceCode;
17*fce4895dSRene Gollent 
18*fce4895dSRene Gollent 
19*fce4895dSRene Gollent class Function : public BReferenceable, private LocatableFile::Listener {
20*fce4895dSRene Gollent public:
21*fce4895dSRene Gollent 	class Listener;
22*fce4895dSRene Gollent 
23*fce4895dSRene Gollent public:
24*fce4895dSRene Gollent 								Function();
25*fce4895dSRene Gollent 								~Function();
26*fce4895dSRene Gollent 
27*fce4895dSRene Gollent 			// team must be locked to access the instances
FirstInstance()28*fce4895dSRene Gollent 			FunctionInstance*	FirstInstance() const
29*fce4895dSRene Gollent 									{ return fInstances.Head(); }
LastInstance()30*fce4895dSRene Gollent 			FunctionInstance*	LastInstance() const
31*fce4895dSRene Gollent 									{ return fInstances.Tail(); }
Instances()32*fce4895dSRene Gollent 			const FunctionInstanceList& Instances() const
33*fce4895dSRene Gollent 									{ return fInstances; }
34*fce4895dSRene Gollent 
Name()35*fce4895dSRene Gollent 			const BString&		Name() const
36*fce4895dSRene Gollent 									{ return FirstInstance()->Name(); }
PrettyName()37*fce4895dSRene Gollent 			const BString&		PrettyName() const
38*fce4895dSRene Gollent 									{ return FirstInstance()->PrettyName(); }
SourceFile()39*fce4895dSRene Gollent 			LocatableFile*		SourceFile() const
40*fce4895dSRene Gollent 									{ return FirstInstance()->SourceFile(); }
GetSourceLocation()41*fce4895dSRene Gollent 			SourceLocation		GetSourceLocation() const
42*fce4895dSRene Gollent 									{ return FirstInstance()
43*fce4895dSRene Gollent 										->GetSourceLocation(); }
44*fce4895dSRene Gollent 
GetFunctionID()45*fce4895dSRene Gollent 			FunctionID*			GetFunctionID() const
46*fce4895dSRene Gollent 									{ return FirstInstance()->GetFunctionID(); }
47*fce4895dSRene Gollent 									// returns a reference
48*fce4895dSRene Gollent 
49*fce4895dSRene Gollent 			// mutable attributes follow (locking required)
GetSourceCode()50*fce4895dSRene Gollent 			FileSourceCode*		GetSourceCode() const	{ return fSourceCode; }
SourceCodeState()51*fce4895dSRene Gollent 			function_source_state SourceCodeState() const
52*fce4895dSRene Gollent 									{ return fSourceCodeState; }
53*fce4895dSRene Gollent 			void				SetSourceCode(FileSourceCode* source,
54*fce4895dSRene Gollent 									function_source_state state);
55*fce4895dSRene Gollent 
56*fce4895dSRene Gollent 			void				AddListener(Listener* listener);
57*fce4895dSRene Gollent 			void				RemoveListener(Listener* listener);
58*fce4895dSRene Gollent 
59*fce4895dSRene Gollent 			// package private
60*fce4895dSRene Gollent 			void				AddInstance(FunctionInstance* instance);
61*fce4895dSRene Gollent 			void				RemoveInstance(FunctionInstance* instance);
62*fce4895dSRene Gollent 
63*fce4895dSRene Gollent 			void				NotifySourceCodeChanged();
64*fce4895dSRene Gollent 
65*fce4895dSRene Gollent 			void				LocatableFileChanged(LocatableFile* file);
66*fce4895dSRene Gollent 
67*fce4895dSRene Gollent private:
68*fce4895dSRene Gollent 			typedef DoublyLinkedList<Listener> ListenerList;
69*fce4895dSRene Gollent 
70*fce4895dSRene Gollent private:
71*fce4895dSRene Gollent 			FunctionInstanceList fInstances;
72*fce4895dSRene Gollent 			FileSourceCode*		fSourceCode;
73*fce4895dSRene Gollent 			function_source_state fSourceCodeState;
74*fce4895dSRene Gollent 			ListenerList		fListeners;
75*fce4895dSRene Gollent 			int32				fNotificationsDisabled;
76*fce4895dSRene Gollent 
77*fce4895dSRene Gollent public:
78*fce4895dSRene Gollent 			// BOpenHashTable support
79*fce4895dSRene Gollent 			Function*			fNext;
80*fce4895dSRene Gollent };
81*fce4895dSRene Gollent 
82*fce4895dSRene Gollent 
83*fce4895dSRene Gollent class Function::Listener : public DoublyLinkedListLinkImpl<Listener> {
84*fce4895dSRene Gollent public:
85*fce4895dSRene Gollent 	virtual						~Listener();
86*fce4895dSRene Gollent 
87*fce4895dSRene Gollent 	virtual	void				FunctionSourceCodeChanged(Function* function);
88*fce4895dSRene Gollent 									// called with lock held
89*fce4895dSRene Gollent };
90*fce4895dSRene Gollent 
91*fce4895dSRene Gollent 
92*fce4895dSRene Gollent #endif	// FUNCTION_H
93