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