Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TFunction.cxx
Go to the documentation of this file.
1// @(#)root/meta:$Id$
2// Author: Fons Rademakers 07/02/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TFunction
13Global functions class (global functions are obtained from CINT).
14This class describes one single global function.
15The TROOT class contains a list of all currently defined global
16functions (accessible via TROOT::GetListOfGlobalFunctions()).
17*/
18
19#include "TFunction.h"
20#include "TMethodArg.h"
21#include "TList.h"
22#include "TROOT.h"
23#include "TInterpreter.h"
24#include "Strlen.h"
25
26#include <iostream>
27#include "TVirtualMutex.h"
28
29
30////////////////////////////////////////////////////////////////////////////////
31/// Default TFunction ctor. TFunctions are constructed in TROOT via
32/// a call to TCling::UpdateListOfGlobalFunctions().
33
35{
36 fInfo = info;
37 fMethodArgs = nullptr;
38 if (fInfo) {
39 // The next calls into TClingMethodInfo methods lock the interpreter. Lock
40 // once here instead of locking/unlocking every time.
45 }
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Copy operator.
50
52{
53 if (orig.fInfo) {
54 // The next call locks the interpreter mutex.
56 fMangledName = orig.fMangledName;
57 } else
58 fInfo = nullptr;
59 fMethodArgs = nullptr;
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Assignment operator.
64
66{
67 if (this != &rhs) {
68 // The next calls lock the interpreter mutex. Lock once here instead of
69 // locking/unlocking every time.
73 delete fMethodArgs;
74 if (rhs.fInfo) {
79 } else
80 fInfo = nullptr;
81 fMethodArgs = nullptr;
82 }
83 return *this;
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// TFunction dtor deletes adopted CINT MethodInfo.
88
96
97////////////////////////////////////////////////////////////////////////////////
98/// Clone method.
99
101{
102 // The constructor locks the interpreter mutex.
103 TNamed *newobj = new TFunction(*this);
104 if (newname && strlen(newname)) newobj->SetName(newname);
105 return newobj;
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Using the CINT method arg information to create a complete signature string.
110
112{
113 // The next call locks the interpreter mutex. The result is cached in the
114 // fSignature data member.
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Return signature of function.
120
122{
123 if (fInfo && fSignature.IsNull())
124 // The next call locks the interpreter mutex.
125 // The result is cached in the fSignature data member.
127
128 return fSignature.Data();
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Return list containing the TMethodArgs of a TFunction.
133
135{
136 if (!fMethodArgs && fInfo) {
137 if (!gInterpreter)
138 Fatal("GetListOfMethodArgs", "gInterpreter not initialized");
139
140 // The next call locks the interpreter mutex.
141 gInterpreter->CreateListOfMethodArgs(this);
142 }
143 return fMethodArgs;
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Get full type description of function return type, e,g.: "class TDirectory*".
148
150{
151 // The next calls lock the interpreter mutex.
152 if (fInfo == nullptr || gCling->MethodInfo_Type(fInfo) == nullptr) return "Unknown";
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// Get the normalized name of the return type. A normalized name is fully
158/// qualified and has all typedef desugared except for the 'special' typedef
159/// which include Double32_t, Float16_t, [U]Long64_t and std::string. It
160/// also has std:: removed [This is subject to change].
161///
162
164{
165 // The next calls lock the interpreter mutex.
166 if (fInfo == nullptr || gCling->MethodInfo_Type(fInfo) == nullptr) return "Unknown";
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Number of function arguments.
172
174{
175 if (fInfo) return gCling->MethodInfo_NArg(fInfo);
176 else if (fMethodArgs) return fMethodArgs->GetEntries();
177 else return 0;
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Number of function optional (default) arguments.
182
184{
185 // FIXME: when unload this is an over-estimate.
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Get property description word. For meaning of bits see EProperty.
191
193{
194 // The next call locks the interpreter mutex.
195 return fInfo ? gCling->MethodInfo_Property(fInfo) : 0;
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Get property description word. For meaning of bits see EProperty.
200
202{
203 // The next call locks the interpreter mutex.
205}
206
207////////////////////////////////////////////////////////////////////////////////
208
210{
211 // The next call locks the interpreter mutex.
212 return gInterpreter->GetDeclId(fInfo);
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Return pointer to the interface method. Using this pointer we
217/// can find which TFunction belongs to a CINT MethodInfo object.
218/// Both need to have the same InterfaceMethod pointer.
219
221{
222 // The next call locks the interpreter mutex.
223 return fInfo ? gCling->MethodInfo_InterfaceMethod(fInfo) : nullptr;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Return true if this function object is pointing to a currently
228/// loaded function. If a function is unloaded after the TFunction
229/// is created, the TFunction will be set to be invalid.
230
232{
233 // Register the transaction when checking the validity of the object.
235 // Only for global functions. For data member functions TMethod does it.
236 // The next calls lock the interpreter mutex.
237 DeclId_t newId = gInterpreter->GetFunction(nullptr, fName);
238 if (newId) {
239 // The next call locks the interpreter mutex. (TODO: why?)
240 MethodInfo_t *info = gInterpreter->MethodInfo_Factory(newId);
241 Update(info);
242 }
243 return newId != nullptr;
244 }
245 return fInfo != nullptr;
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Returns the mangled name as defined by CINT, or 0 in case of error.
250
251const char *TFunction::GetMangledName() const
252{
253 return fMangledName;
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// Returns the prototype of a function as defined by CINT, or 0 in
258/// case of error.
259
260const char *TFunction::GetPrototype() const
261{
262 if (fInfo) {
263 // The next call locks the interpreter mutex.
265 } else
266 return nullptr;
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// List TFunction name and title.
271
272void TFunction::ls(Option_t *options /* ="" */) const
273{
274 TDictionary::ls(options);
276 std::cout << " " << GetPrototype() << '\n';
277}
278
279////////////////////////////////////////////////////////////////////////////////
280/// Print TFunction name and title.
281
282void TFunction::Print(Option_t *options /* ="" */) const
283{
284 TDictionary::Print(options);
285}
286
287////////////////////////////////////////////////////////////////////////////////
288/// Update the TFunction to reflect the new info.
289///
290/// This can be used to implement unloading (info == 0) and then reloading
291/// (info being the 'new' decl address).
292
294{
295 // This function needs to lock access to the interpreter multiple times.
296 // Take the lock at the beginning of the function so that we don't incur
297 // in too much locking/unlocking.
299 if (info == nullptr) {
300
301 if (fInfo) {
302 // The next call locks the interpreter mutex.
304 }
305 fInfo = nullptr;
306 if (fMethodArgs) {
307 for (Int_t i = 0; i < fMethodArgs->LastIndex() + 1; i ++) {
308 TMethodArg *arg = (TMethodArg *) fMethodArgs->At( i );
309 arg->Update(nullptr);
310 }
311 }
312 return kTRUE;
313 } else {
314 if (fInfo) {
315 // The next call locks the interpreter mutex.
317 }
318 fInfo = info;
319 // The next call locks the interpreter mutex.
322 Error("Update","TFunction object updated with the 'wrong' MethodInfo (%s vs %s).",
324 fInfo = nullptr;
325 return false;
326 }
327 // The next call locks the interpreter mutex.
329 if (fMethodArgs) {
330 // TODO: Check for MethodArgInfo thread-safety
332 Int_t i = 0;
333 while (gCling->MethodArgInfo_Next(arg)) {
334 if (gCling->MethodArgInfo_IsValid(arg)) {
336 ((TMethodArg *) fMethodArgs->At( i ))->Update(new_arg);
337 ++i;
338 }
339 }
340 }
341 return kTRUE;
342 }
343}
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TVirtualMutex * gInterpreterMutex
R__EXTERN TInterpreter * gCling
#define gInterpreter
#define R__LOCKGUARD(mutex)
virtual Int_t GetEntries() const
This class defines an abstract interface that must be implemented by all classes that contain diction...
Bool_t UpdateInterpreterStateMarker()
the Cling ID of the transaction that last updated the object
const void * DeclId_t
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
virtual const char * GetMangledName() const
Returns the mangled name as defined by CINT, or 0 in case of error.
TList * fMethodArgs
Definition TFunction.h:39
TString fSignature
Definition TFunction.h:38
virtual void CreateSignature()
Using the CINT method arg information to create a complete signature string.
TString fMangledName
Definition TFunction.h:37
virtual const char * GetPrototype() const
Returns the prototype of a function as defined by CINT, or 0 in case of error.
TFunction(MethodInfo_t *info=nullptr)
Default TFunction ctor.
Definition TFunction.cxx:34
void * InterfaceMethod() const
Return pointer to the interface method.
virtual Bool_t IsValid()
Return true if this function object is pointing to a currently loaded function.
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
MethodInfo_t * fInfo
Definition TFunction.h:36
const char * GetSignature()
Return signature of function.
TObject * Clone(const char *newname="") const override
Clone method.
void Print(Option_t *option="") const override
Print TFunction name and title.
virtual bool Update(MethodInfo_t *info)
Update the TFunction to reflect the new info.
Int_t GetNargsOpt() const
Number of function optional (default) arguments.
Int_t GetNargs() const
Number of function arguments.
DeclId_t GetDeclId() const
Long_t ExtraProperty() const
Get property description word. For meaning of bits see EProperty.
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
virtual ~TFunction()
TFunction dtor deletes adopted CINT MethodInfo.
Definition TFunction.cxx:89
TFunction & operator=(const TFunction &rhs)
Assignment operator.
Definition TFunction.cxx:65
const char * GetReturnTypeName() const
Get full type description of function return type, e,g.: "class TDirectory*".
void ls(Option_t *option="") const override
List TFunction name and title.
std::string GetReturnTypeNormalizedName() const
Get the normalized name of the return type.
virtual int MethodInfo_NArg(MethodInfo_t *) const
virtual Long_t MethodInfo_ExtraProperty(MethodInfo_t *) const =0
virtual const char * MethodInfo_Title(MethodInfo_t *) const
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *) const
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *) const
virtual int MethodArgInfo_Next(MethodArgInfo_t *) const
virtual void MethodInfo_Delete(MethodInfo_t *) const
virtual int MethodInfo_NDefaultArg(MethodInfo_t *) const
virtual Bool_t MethodArgInfo_IsValid(MethodArgInfo_t *) const
virtual const char * MethodInfo_TypeName(MethodInfo_t *) const
virtual MethodArgInfo_t * MethodArgInfo_Factory() const
virtual void * MethodInfo_InterfaceMethod(MethodInfo_t *) const
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *) const
virtual const char * MethodInfo_Name(MethodInfo_t *) const
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *) const
virtual void MethodInfo_CreateSignature(MethodInfo_t *, TString &) const
virtual std::string MethodInfo_TypeNormalizedName(MethodInfo_t *) const
virtual Long_t MethodInfo_Property(MethodInfo_t *) const =0
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *) const
A doubly linked list.
Definition TList.h:38
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:467
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:354
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
void Update(MethodArgInfo_t *info)
Update fInfo (to 0 for unloading and non-zero for reloading).
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:173
void Print(Option_t *option="") const override
Print TNamed name and title.
Definition TNamed.cxx:127
TString fName
Definition TNamed.h:32
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
void ls(Option_t *option="") const override
List TNamed name and title.
Definition TNamed.cxx:112
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1099
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2898
Int_t LastIndex() const
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
Bool_t IsNull() const
Definition TString.h:422