Logo ROOT  
Reference Guide
TClingMethodInfo.h
Go to the documentation of this file.
1 // @(#)root/core/meta:$Id$
2 // Author: Paul Russo 30/07/2012
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 #ifndef ROOT_TClingMethodInfo
13 #define ROOT_TClingMethodInfo
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TClingMethodInfo //
18 // //
19 // Emulation of the CINT MethodInfo class. //
20 // //
21 // The CINT C++ interpreter provides an interface to metadata about //
22 // a function through the MethodInfo class. This class provides the //
23 // same functionality, using an interface as close as possible to //
24 // MethodInfo but the typedef metadata comes from the Clang C++ //
25 // compiler, not CINT. //
26 // //
27 //////////////////////////////////////////////////////////////////////////
28 
29 #include "TClingDeclInfo.h"
30 #include "TClingMemberIter.h"
31 #include "TDictionary.h"
32 #include "TString.h"
33 
34 #include "llvm/ADT/SmallVector.h"
35 
36 #include <string>
37 
38 namespace clang {
39  class Decl;
40  class FunctionDecl;
41 }
42 
43 namespace cling {
44  class Interpreter;
45 }
46 
47 namespace ROOT {
48  namespace TMetaUtils {
49  class TNormalizedCtxt;
50  }
51 }
52 
53 class TClingClassInfo;
54 class TClingTypeInfo;
55 
56 /// Iterate over FunctionDecl and UsingShadowDecls of FunctionDecl, within a scope,
57 /// recursing through "transparent" scopes (see DCIter::HandleInlineDeclContext()).
59 
60 class SpecFuncIter {
61  using Vec_t = llvm::SmallVector<clang::CXXMethodDecl *,4>;
62  Vec_t fDefDataSpecFuns; // Special functions materialized from DefinitionData.
63  size_t fIDefDataSpecFuns = 0; // Current element in fDefDataSpecFuns.
64 
65 public:
66  SpecFuncIter() = default;
67  SpecFuncIter(cling::Interpreter *interp, clang::DeclContext *DC,
68  llvm::SmallVectorImpl<clang::CXXMethodDecl*> &&specFuncs);
69 
70  bool IsValid() const { return fIDefDataSpecFuns < fDefDataSpecFuns.size(); }
71 
72  bool Next() {
74  return IsValid();
75  }
76 
77  clang::FunctionDecl *operator->() const {
78  return operator*();
79  }
80 
81  clang::FunctionDecl *operator*() const {
82  return IsValid() ? fDefDataSpecFuns[fIDefDataSpecFuns] : nullptr;
83  }
84 };
85 
87 
88 protected:
89  const clang::Decl *
90  InstantiateTemplateWithDefaults(const clang::RedeclarableTemplateDecl *TD) const final;
91 
92  bool ShouldSkip(const clang::Decl* FD) const final;
93  bool ShouldSkip(const clang::UsingShadowDecl* USD) const final;
94 
95  clang::Decl *AdvanceUnfiltered() final {
97  return *fSpecFuncIter;
99  }
100 
101 public:
102  TClingCXXRecMethIter() = default;
103  TClingCXXRecMethIter(cling::Interpreter *interp, clang::DeclContext *DC,
104  llvm::SmallVectorImpl<clang::CXXMethodDecl*> &&specFuncs):
105  TClingMemberIter(interp, DC), fSpecFuncIter(interp, DC, std::move(specFuncs)) {}
106 
107  const clang::Decl *Get() const final {
108  if (!IsValid())
109  return nullptr;
110 
111  if (fSpecFuncIter.IsValid())
112  return *fSpecFuncIter;
113 
114  return TClingMemberIter::Get();
115  }
116 
117  bool IsValid() const final {
119  }
120 
121 };
122 
123 
124 class TClingMethodInfo final : public TClingDeclInfo {
125 private:
126  cling::Interpreter *fInterp; // Cling interpreter, we do *not* own.
127  bool fFirstTime; // Flag for first time incrementing iterator, cint semantics are weird.
128  TClingCXXRecMethIter fIter; // Our iterator.
129  std::string fTitle; // The meta info for the method.
130 
131  const clang::Decl* GetDeclSlow() const;
132 
133 public:
134  explicit TClingMethodInfo(cling::Interpreter *interp)
135  : TClingDeclInfo(nullptr), fInterp(interp), fFirstTime(true), fTitle("") {}
136 
137  // Takes concrete decl and disables the iterator.
138  TClingMethodInfo(cling::Interpreter *, const clang::Decl *);
139  TClingMethodInfo(cling::Interpreter *, TClingClassInfo *);
140 
141  const clang::FunctionDecl *GetAsFunctionDecl() const;
142  const clang::UsingShadowDecl *GetAsUsingShadowDecl() const;
143 
144  /// Get the FunctionDecl, or if this represents a UsingShadowDecl, the underlying target FunctionDecl.
145  const clang::FunctionDecl *GetTargetFunctionDecl() const;
146 
148  cling::Interpreter *GetInterpreter() const { return fInterp; }
149  void CreateSignature(TString &signature) const;
150  void Init(const clang::FunctionDecl *);
151  void *InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
152 
153  const clang::Decl *GetDecl() const override {
154  if (const clang::Decl* SingleDecl = TClingDeclInfo::GetDecl())
155  return SingleDecl;
156  return GetDeclSlow();
157  }
158  int NArg() const;
159  int NDefaultArg() const;
160  int Next();
161  long Property() const;
162  long ExtraProperty() const;
163  TClingTypeInfo *Type() const;
164  std::string GetMangledName() const;
165  const char *GetPrototype();
166  const char *Name() const override;
167  const char *TypeName() const;
168  const char *Title();
169 };
170 
171 #endif // ROOT_TClingMethodInfo
TClingCXXRecMethIter::SpecFuncIter::IsValid
bool IsValid() const
Definition: TClingMethodInfo.h:70
TClingMethodInfo::InterfaceMethod
void * InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const
Definition: TClingMethodInfo.cxx:367
TClingCXXRecMethIter
Iterate over FunctionDecl and UsingShadowDecls of FunctionDecl, within a scope, recursing through "tr...
Definition: TClingMethodInfo.h:58
TClingCXXRecMethIter::AdvanceUnfiltered
clang::Decl * AdvanceUnfiltered() final
Definition: TClingMethodInfo.h:95
TClingCXXRecMethIter::SpecFuncIter::Next
bool Next()
Definition: TClingMethodInfo.h:72
TClingMethodInfo::GetPrototype
const char * GetPrototype()
Definition: TClingMethodInfo.cxx:606
TClingMethodInfo::GetTargetFunctionDecl
const clang::FunctionDecl * GetTargetFunctionDecl() const
Get the FunctionDecl, or if this represents a UsingShadowDecl, the underlying target FunctionDecl.
Definition: TClingMethodInfo.cxx:316
TClingMemberIter::Get
virtual const clang::Decl * Get() const
Definition: TClingMemberIter.h:163
TClingMethodInfo::Title
const char * Title()
Definition: TClingMethodInfo.cxx:670
TClingCXXRecMethIter::SpecFuncIter::operator*
clang::FunctionDecl * operator*() const
Definition: TClingMethodInfo.h:81
TClingDeclInfo
Definition: TClingDeclInfo.h:28
TClingMethodInfo::GetAsFunctionDecl
const clang::FunctionDecl * GetAsFunctionDecl() const
Definition: TClingMethodInfo.cxx:306
TClingMethodInfo::GetInterpreter
cling::Interpreter * GetInterpreter() const
Definition: TClingMethodInfo.h:148
TClingCXXRecMethIter::SpecFuncIter::Vec_t
llvm::SmallVector< clang::CXXMethodDecl *, 4 > Vec_t
Definition: TClingMethodInfo.h:61
TClingMethodInfo::Init
void Init(const clang::FunctionDecl *)
Definition: TClingMethodInfo.cxx:360
TClingMemberIter
Iterate over all DeclT-s (or UsingShadowDecl-s pointing to DeclT-s) of a decl context,...
Definition: TClingMemberIter.h:111
TClingCXXRecMethIter::SpecFuncIter::fDefDataSpecFuns
Vec_t fDefDataSpecFuns
Definition: TClingMethodInfo.h:62
TClingMethodInfo::CreateSignature
void CreateSignature(TString &signature) const
Definition: TClingMethodInfo.cxx:326
TString
Basic string class.
Definition: TString.h:131
TClingCXXRecMethIter::SpecFuncIter
Definition: TClingMethodInfo.h:60
TString.h
TDictionary.h
TClingMethodInfo::GetMangledName
std::string GetMangledName() const
Definition: TClingMethodInfo.cxx:583
TClingMethodInfo::TypeName
const char * TypeName() const
Definition: TClingMethodInfo.cxx:661
TClingCXXRecMethIter::InstantiateTemplateWithDefaults
const clang::Decl * InstantiateTemplateWithDefaults(const clang::RedeclarableTemplateDecl *TD) const final
Definition: TClingMethodInfo.cxx:130
TClingMethodInfo
Emulation of the CINT MethodInfo class.
Definition: TClingMethodInfo.h:124
TClingCXXRecMethIter::SpecFuncIter::SpecFuncIter
SpecFuncIter()=default
TClingMethodInfo::fIter
TClingCXXRecMethIter fIter
Definition: TClingMethodInfo.h:128
TClingCXXRecMethIter::ShouldSkip
bool ShouldSkip(const clang::Decl *FD) const final
Definition: TClingMethodInfo.cxx:87
TClingMethodInfo::ExtraProperty
long ExtraProperty() const
Definition: TClingMethodInfo.cxx:536
TDictionary::DeclId_t
const void * DeclId_t
Definition: TDictionary.h:222
TClingCXXRecMethIter::SpecFuncIter::fIDefDataSpecFuns
size_t fIDefDataSpecFuns
Definition: TClingMethodInfo.h:63
TClingClassInfo
Emulation of the CINT ClassInfo class.
Definition: TClingClassInfo.h:59
TClingMemberIter.h
TClingMethodInfo::Property
long Property() const
Definition: TClingMethodInfo.cxx:441
TClingMethodInfo::GetDecl
const clang::Decl * GetDecl() const override
Definition: TClingMethodInfo.h:153
TClingMethodInfo::Name
const char * Name() const override
Definition: TClingMethodInfo.cxx:649
TClingCXXRecMethIter::TClingCXXRecMethIter
TClingCXXRecMethIter(cling::Interpreter *interp, clang::DeclContext *DC, llvm::SmallVectorImpl< clang::CXXMethodDecl * > &&specFuncs)
Definition: TClingMethodInfo.h:103
TClingCXXRecMethIter::fSpecFuncIter
SpecFuncIter fSpecFuncIter
Definition: TClingMethodInfo.h:86
TClingMethodInfo::TClingMethodInfo
TClingMethodInfo(cling::Interpreter *interp)
Definition: TClingMethodInfo.h:134
ROOT::TMetaUtils::TNormalizedCtxt
Definition: TClingUtils.h:135
TClingMethodInfo::GetAsUsingShadowDecl
const clang::UsingShadowDecl * GetAsUsingShadowDecl() const
Definition: TClingMethodInfo.cxx:311
TClingCXXRecMethIter::SpecFuncIter::operator->
clang::FunctionDecl * operator->() const
Definition: TClingMethodInfo.h:77
TClingMethodInfo::Next
int Next()
Definition: TClingMethodInfo.cxx:420
TClingMemberIter::AdvanceUnfiltered
virtual clang::Decl * AdvanceUnfiltered()
Definition: TClingMemberIter.h:124
TClingDeclInfo.h
The file contains a base class of TCling*Info classes.
TClingMethodInfo::fTitle
std::string fTitle
Definition: TClingMethodInfo.h:129
TClingMethodInfo::fInterp
cling::Interpreter * fInterp
Definition: TClingMethodInfo.h:126
clang
Definition: BaseSelectionRule.h:29
TClingCXXRecMethIter::IsValid
bool IsValid() const final
Definition: TClingMethodInfo.h:117
TClingMethodInfo::GetDeclId
TDictionary::DeclId_t GetDeclId() const
Definition: TClingMethodInfo.cxx:296
TClingMemberIter::IsValid
virtual bool IsValid() const
Definition: TClingMemberIter.h:178
TClingMethodInfo::GetDeclSlow
const clang::Decl * GetDeclSlow() const
Definition: TClingMethodInfo.cxx:378
TClingMethodInfo::fFirstTime
bool fFirstTime
Definition: TClingMethodInfo.h:127
TClingDeclInfo::GetDecl
virtual const clang::Decl * GetDecl() const
Definition: TClingDeclInfo.h:37
TClingCXXRecMethIter::TClingCXXRecMethIter
TClingCXXRecMethIter()=default
TClingMethodInfo::NArg
int NArg() const
Definition: TClingMethodInfo.cxx:383
TClingTypeInfo
Emulation of the CINT TypeInfo class.
Definition: TClingTypeInfo.h:42
TClingMethodInfo::Type
TClingTypeInfo * Type() const
Definition: TClingMethodInfo.cxx:558
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21
TClingMethodInfo::NDefaultArg
int NDefaultArg() const
Definition: TClingMethodInfo.cxx:394
TClingCXXRecMethIter::Get
const clang::Decl * Get() const final
Definition: TClingMethodInfo.h:107