Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TList of temp func #56

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/base/inc/TROOT.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class TROOT;
class TListOfDataMembers;
class TListOfEnums;
class TListOfFunctions;
class TListOfFunctionTemplates;
class TFunctionTemplate;


Expand Down Expand Up @@ -112,7 +113,7 @@ friend TROOT *ROOT::GetROOT2();
TVirtualPad *fSelectPad; //Currently selected pad
TCollection *fClasses; //List of classes definition
TCollection *fTypes; //List of data types definition
TCollection *fFuncTemplate; //List of global function templates
TListOfFunctionTemplates *fFuncTemplate; //List of global function templates
TListOfDataMembers*fGlobals; //List of global variables
TListOfFunctions*fGlobalFunctions; //List of global functions
TSeqCollection *fClosedObjects; //List of closed objects from the list of files and sockets, so we can delete them if neededCl.
Expand Down Expand Up @@ -223,6 +224,7 @@ friend TROOT *ROOT::GetROOT2();
TSeqCollection *GetClipboard() const { return fClipboard; }
TSeqCollection *GetListOfDataSets() const { return fDataSets; }
TCollection *GetListOfEnums();
TCollection *GetListOfFunctionTemplates();
TList *GetListOfBrowsables() const { return fBrowsables; }
TDataType *GetType(const char *name, Bool_t load = kFALSE) const;
TFile *GetFile() const { if (gDirectory != this) return gDirectory->GetFile(); else return 0;}
Expand Down
23 changes: 12 additions & 11 deletions core/base/src/TROOT.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#include "TListOfDataMembers.h"
#include "TListOfEnums.h"
#include "TListOfFunctions.h"
#include "TListOfFunctionTemplates.h"
#include "TFunctionTemplate.h"

#include <string>
Expand Down Expand Up @@ -1225,18 +1226,9 @@ TFunctionTemplate *TROOT::GetFunctionTemplate(const char *name)
{
if (!gInterpreter) return 0;

if (!fFuncTemplate) fFuncTemplate = new TList();
if (!fFuncTemplate) fFuncTemplate = new TListOfFunctionTemplates(0);

TFunctionTemplate *result;
result = (TFunctionTemplate*)fFuncTemplate->FindObject(name);
if (!result) {
TInterpreter::DeclId_t id = gInterpreter->GetFunctionTemplate(0,name);
if (id) {
FuncTempInfo_t *info = gInterpreter->FuncTempInfo_Factory(id);
result = new TFunctionTemplate(info, 0);
}
}
return result;
return (TFunctionTemplate*)fFuncTemplate->FindObject(name);
}

//______________________________________________________________________________
Expand Down Expand Up @@ -1368,6 +1360,15 @@ TCollection *TROOT::GetListOfEnums()
return fEnums;
}

//______________________________________________________________________________
TCollection *TROOT::GetListOfFunctionTemplates()
{
if(!fFuncTemplate) {
fFuncTemplate = new TListOfFunctionTemplates(0);
}
return fFuncTemplate;
}

//______________________________________________________________________________
TCollection *TROOT::GetListOfGlobals(Bool_t load)
{
Expand Down
1 change: 1 addition & 0 deletions core/meta/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#pragma link C++ class std::vector<std::pair<Int_t, Int_t> >+;
#pragma link C++ class TFileMergeInfo;
#pragma link C++ class TListOfFunctions+;
#pragma link C++ class TListOfFunctionTemplates+;
#pragma link C++ class TListOfDataMembers;
#pragma link C++ class TListOfEnums+;

Expand Down
4 changes: 3 additions & 1 deletion core/meta/inc/TClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class TVirtualIsAProxy;
class TVirtualRefProxy;
class THashTable;
class TListOfFunctions;
class TListOfFunctionTemplates;
class TListOfDataMembers;
class TListOfEnums;
class TViewPubFunctions;
Expand Down Expand Up @@ -116,7 +117,7 @@ friend class ROOT::TGenericClassInfo;
TList *fBase; //linked list for base classes
TListOfDataMembers*fData; //linked list for data members
TListOfEnums *fEnums; //linked list for the enums
TList *fFuncTemplate; //linked list for function templates [Not public until implemented as active list]
TListOfFunctionTemplates *fFuncTemplate; //linked list for function templates [Not public until implemented as active list]
TListOfFunctions *fMethod; //linked list for methods
TViewPubDataMembers*fAllPubData; //all public data members (including from base classes)
TViewPubFunctions *fAllPubMethod; //all public methods (including from base classes)
Expand Down Expand Up @@ -298,6 +299,7 @@ friend class ROOT::TGenericClassInfo;
}
TList *GetListOfDataMembers(Bool_t load = kTRUE);
TList *GetListOfEnums(Bool_t load = kTRUE);
TList *GetListOfFunctionTemplates(Bool_t load = kTRUE);
TList *GetListOfBases();
TList *GetListOfMethods(Bool_t load = kTRUE);
TCollection *GetListOfMethodOverloads(const char* name) const;
Expand Down
1 change: 1 addition & 0 deletions core/meta/inc/TInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class TInterpreter : public TNamed {
virtual DeclId_t GetFunctionWithValues(ClassInfo_t *cl, const char* method, const char* params, Bool_t objectIsConst = kFALSE) = 0;
virtual DeclId_t GetFunctionTemplate(ClassInfo_t *cl, const char *funcname) = 0;
virtual void GetFunctionOverloads(ClassInfo_t *cl, const char *funcname, std::vector<DeclId_t>& res) const = 0;
virtual void LoadFunctionTemplates(TClass* cl) const = 0;

// CallFunc interface
virtual void CallFunc_Delete(CallFunc_t * /* func */) const {;}
Expand Down
93 changes: 93 additions & 0 deletions core/meta/inc/TListOfFunctionTemplates.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// @(#)root/cont
// Author: Philippe Canal Aug 2013

/*************************************************************************
* Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef ROOT_TListOfFunctionTemplates
#define ROOT_TListOfFunctionTemplates

//////////////////////////////////////////////////////////////////////////
// //
// TListOfFunctionTemplates //
// //
// A collection of TFunctionTemplate objects designed for fast access //
// given a DeclId_t and for keep track of TFunctionTempalte that were //
// described unloaded function. //
// //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_THastList
#include "THashList.h"
#endif

#ifndef ROOT_THastTable
#include "THashTable.h"
#endif

#ifndef ROOT_TDictionary
#include "TDictionary.h"
#endif

class TExMap;
class TFunctionTemplate;

class TListOfFunctionTemplates : public THashList
{
private:
typedef TDictionary::DeclId_t DeclId_t;
TClass *fClass; // Context of this list. Not owned.

TExMap *fIds; // Map from DeclId_t to TFunction*
THashList *fUnloaded; // Holder of TFunction for unloaded functions.
THashTable fOverloads; // TLists of overloads.

TListOfFunctionTemplates(const TListOfFunctionTemplates&); // not implemented
TListOfFunctionTemplates& operator=(const TListOfFunctionTemplates&); // not implemented
TList *GetListForObjectNonConst(const char* name);

void MapObject(TObject *obj);
void UnmapObject(TObject *obj);

public:

TListOfFunctionTemplates(TClass *cl);
~TListOfFunctionTemplates();

virtual void Clear(Option_t *option);
virtual void Delete(Option_t *option="");

using THashList::FindObject;
virtual TObject *FindObject(const char *name) const;
virtual TList *GetListForObject(const char* name) const;
virtual TList *GetListForObject(const TObject* obj) const;

TFunctionTemplate *Get(DeclId_t id);

void AddFirst(TObject *obj);
void AddFirst(TObject *obj, Option_t *opt);
void AddLast(TObject *obj);
void AddLast(TObject *obj, Option_t *opt);
void AddAt(TObject *obj, Int_t idx);
void AddAfter(const TObject *after, TObject *obj);
void AddAfter(TObjLink *after, TObject *obj);
void AddBefore(const TObject *before, TObject *obj);
void AddBefore(TObjLink *before, TObject *obj);

void RecursiveRemove(TObject *obj);
TObject *Remove(TObject *obj);
TObject *Remove(TObjLink *lnk);

void Load();
void Unload();
void Unload(TFunctionTemplate *func);

ClassDef(TListOfFunctionTemplates,0); // List of TFunctions for a class
};

#endif // ROOT_TListOfFunctionTemplates
26 changes: 15 additions & 11 deletions core/meta/src/TClass.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

#include "TListOfDataMembers.h"
#include "TListOfFunctions.h"
#include "TListOfFunctionTemplates.h"
#include "TListOfEnums.h"
#include "TViewPubDataMembers.h"
#include "TViewPubFunctions.h"
Expand Down Expand Up @@ -3087,18 +3088,9 @@ TFunctionTemplate *TClass::GetFunctionTemplate(const char *name)
if (!gInterpreter || !fClassInfo) return 0;

// The following
if (!fFuncTemplate) fFuncTemplate = new TList();
if (!fFuncTemplate) fFuncTemplate = new TListOfFunctionTemplates(this);

TFunctionTemplate *result;
result = (TFunctionTemplate*)fFuncTemplate->FindObject(name);
if (!result) {
DeclId_t id = gInterpreter->GetFunctionTemplate(fClassInfo,name);
if (id) {
FuncTempInfo_t *info = gInterpreter->FuncTempInfo_Factory(id);
result = new TFunctionTemplate(info,this);
}
}
return result;
return (TFunctionTemplate*)fFuncTemplate->FindObject(name);
}

//______________________________________________________________________________
Expand Down Expand Up @@ -3164,6 +3156,18 @@ TList *TClass::GetListOfDataMembers(Bool_t load /* = kTRUE */)
return fData;
}

//______________________________________________________________________________
TList *TClass::GetListOfFunctionTemplates(Bool_t load /* = kTRUE */)
{
// Return list containing the TEnums of a class.

R__LOCKGUARD(gInterpreterMutex);

if (!fFuncTemplate) fFuncTemplate = new TListOfFunctionTemplates(this);
if (load) fFuncTemplate->Load();
return fFuncTemplate;
}

//______________________________________________________________________________
TList *TClass::GetListOfMethods(Bool_t load /* = kTRUE */)
{
Expand Down
35 changes: 35 additions & 0 deletions core/meta/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "TMetaUtils.h"
#include "TVirtualCollectionProxy.h"
#include "TListOfEnums.h"
#include "TListOfFunctionTemplates.h"

#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
Expand Down Expand Up @@ -2535,6 +2536,40 @@ void TCling::LoadEnums(TClass* cl) const
}
}

//______________________________________________________________________________
void TCling::LoadFunctionTemplates(TClass* cl) const
{
// Create list of pointers to function templates for TClass cl.
R__LOCKGUARD2(gInterpreterMutex);

const Decl * D;
TListOfFunctionTemplates* funcTempList;
if (cl) {
D = ((TClingClassInfo*)cl->GetClassInfo())->GetDecl();
funcTempList = (TListOfFunctionTemplates*)cl->GetListOfFunctionTemplates(false);
}
else {
D = fInterpreter->getCI()->getASTContext().getTranslationUnitDecl();
funcTempList = (TListOfFunctionTemplates*)gROOT->GetListOfFunctionTemplates();
}
// Iterate on the decl of the class and get the enums.
if (const clang::DeclContext* DC = dyn_cast<clang::DeclContext>(D)) {
cling::Interpreter::PushTransactionRAII deserRAII(fInterpreter);
// Collect all contexts of the namespace.
llvm::SmallVector< DeclContext *, 4> allDeclContexts;
const_cast< clang::DeclContext *>(DC)->collectAllContexts(allDeclContexts);
for (llvm::SmallVector<DeclContext*, 4>::iterator declIter = allDeclContexts.begin(),
declEnd = allDeclContexts.end(); declIter != declEnd; ++declIter) {
// Iterate on all decls for each context.
for (clang::DeclContext::decl_iterator DI = (*declIter)->decls_begin(),
DE = (*declIter)->decls_end(); DI != DE; ++DI) {
if (const clang::FunctionTemplateDecl* FTD = dyn_cast<clang::FunctionTemplateDecl>(*DI)) {
funcTempList->Get(FTD);
}
}
}
}
}
//______________________________________________________________________________
void TCling::CreateListOfDataMembers(TClass* cl) const
{
Expand Down
1 change: 1 addition & 0 deletions core/meta/src/TCling.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class TCling : public TInterpreter {
DeclId_t GetFunctionWithValues(ClassInfo_t *cl, const char* method, const char* params, Bool_t objectIsConst = kFALSE);
DeclId_t GetFunctionTemplate(ClassInfo_t *cl, const char *funcname);
void GetFunctionOverloads(ClassInfo_t *cl, const char *funcname, std::vector<DeclId_t>& res) const;
virtual void LoadFunctionTemplates(TClass* cl) const;

void GetInterpreterTypeName(const char* name, std::string &output, Bool_t full = kFALSE);
void Execute(const char* function, const char* params, int* error = 0);
Expand Down
Loading