Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
31 #include "TString.h"
32 #include "TDictionary.h"
33 
34 #include "clang/AST/DeclBase.h"
35 #include "llvm/ADT/SmallVector.h"
36 
37 namespace cling {
38  class Interpreter;
39 }
40 
41 namespace clang {
42  class FunctionDecl;
43 }
44 
45 namespace ROOT {
46  namespace TMetaUtils {
47  class TNormalizedCtxt;
48  }
49 }
50 
51 class TClingClassInfo;
52 class TClingTypeInfo;
53 
54 class TClingMethodInfo final : public TClingDeclInfo {
55 private:
56  cling::Interpreter *fInterp; // Cling interpreter, we do *not* own.
57  llvm::SmallVector<clang::DeclContext *, 2> fContexts; // Set of DeclContext that we will iterate over.
58  bool fFirstTime; // Flag for first time incrementing iterator, cint semantics are weird.
59  unsigned int fContextIdx; // Index in fContexts of DeclContext we are iterating over.
60  clang::DeclContext::decl_iterator fIter; // Our iterator.
61  std::string fTitle; // The meta info for the method.
62  const clang::FunctionDecl *fTemplateSpec; // an all-default-template-args function.
63 
64  const clang::Decl* GetDeclSlow() const;
65 
66 public:
67  explicit TClingMethodInfo(cling::Interpreter *interp)
68  : TClingDeclInfo(nullptr), fInterp(interp), fFirstTime(true), fContextIdx(0U), fTitle(""),
69  fTemplateSpec(0) {}
70 
71  TClingMethodInfo(const TClingMethodInfo&);
72  TClingMethodInfo& operator=(const TClingMethodInfo &in);
73 
74  // Takes concrete decl and disables the iterator.
75  TClingMethodInfo(cling::Interpreter *, const clang::FunctionDecl *);
76  TClingMethodInfo(cling::Interpreter *, TClingClassInfo *);
77 
78  ~TClingMethodInfo();
79 
80  const clang::FunctionDecl *GetMethodDecl() const;
81  TDictionary::DeclId_t GetDeclId() const;
82  cling::Interpreter *GetInterpreter() const { return fInterp; }
83  void CreateSignature(TString &signature) const;
84  void Init(const clang::FunctionDecl *);
85  void *InterfaceMethod(const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;
86 
87  const clang::Decl *GetDecl() const override {
88  if (const clang::Decl* SingleDecl = TClingDeclInfo::GetDecl())
89  return SingleDecl;
90  return GetDeclSlow();
91  }
92  int NArg() const;
93  int NDefaultArg() const;
94  int InternalNext();
95  int Next();
96  long Property() const;
97  long ExtraProperty() const;
98  TClingTypeInfo *Type() const;
99  std::string GetMangledName() const;
100  const char *GetPrototype();
101  const char *Name() override;
102  const char *TypeName() const;
103  const char *Title();
104 };
105 
106 #endif // ROOT_TClingMethodInfo