13#include "clang/AST/ASTConsumer.h"
14#include "clang/Basic/SourceLocation.h"
15#include "clang/Basic/SourceManager.h"
16#include "llvm/ADT/SmallSet.h"
17#include "clang/Sema/Sema.h"
18#include "clang/Frontend/CompilerInstance.h"
20#include "cling/Interpreter/Interpreter.h"
21#include "llvm/Support/Path.h"
27#include "llvm/ADT/StringExtras.h"
33 class RPredicateIsSameNamespace
36 clang::NamespaceDecl *fTarget;
38 RPredicateIsSameNamespace(clang::NamespaceDecl *
target) : fTarget(
target) {}
48 return std::find(
v.begin(),
v.end(),
el) !=
v.end();
53 return std::find(
v.begin(),
v.end(),
el) !=
v.end();
79 unsigned int verbose ) :
80 fVerboseLevel(verbose),
81 fSourceManager(nullptr),
83 fRecordDeclCallback(nullptr),
85 fSelectionRules(
rules),
122 if (
auto M = D->getOwningModule()) {
140 return *num.getRawData();
147 return *num.getRawData();
154 return llvm::toString(num, 10,
true);
161 std::string
txt =
"";
170 std::ostringstream stream;
177inline std::string
Message(
const std::string &
msg,
const std::string &location)
179 std::string
loc = location;
191 const std::string message =
Message(
msg, location);
192 std::cout << message << std::endl;
199 const std::string message =
Message(
msg, location);
200 std::cout << message << std::endl;
207 const std::string message =
Message(
msg, location);
208 std::cout << message << std::endl;
215 std::string
loc = location;
225 std::string location =
"";
226 llvm::raw_string_ostream stream(location);
241 std::string location =
"";
242 llvm::raw_string_ostream stream(location);
252 std::string
name =
"";
256 name =
ND->getQualifiedNameAsString();
277 std::string kind = D->getDeclKindName();
279 ShowInfo(
"Scan: " + kind +
" declaration " +
name, location);
288 std::string kind = D->getDeclKindName();
299 std::string kind = D->getDeclKindName();
310 std::string kind = D->getDeclKindName();
327 clang::Decl::Kind k = D->getKind();
340 std::string kind = D->getDeclKindName();
342 std::string
msg =
"Unimplemented ";
344 msg +=
"declaration";
361 std::string kind =
qual_type.getTypePtr()->getTypeClassName();
370 std::string kind =
qual_type.getTypePtr()->getTypeClassName();
378 std::string
enum_name = D->getQualifiedNameAsString();
380 if (! D->getDeclName ()) {
405 std::string
text =
"";
406 llvm::raw_string_ostream stream(
text);
420 std::string
text =
"";
421 llvm::raw_string_ostream stream(
text);
434 for (clang::FunctionDecl::param_iterator
I = D->param_begin(), E = D->param_end();
I != E; ++
I) {
435 clang::ParmVarDecl* P = *
I;
440 std::string
type = P->getType().getAsString();
441 std::string
name = P->getNameAsString();
461 for (clang::FunctionDecl::param_iterator
I = D->param_begin(), E = D->param_end();
I != E; ++
I) {
462 clang::ParmVarDecl* P = *
I;
467 std::string
type = P->getType().getAsString();
471 return "(" +
result +
")";
488 if((
N &&
N->isImplicit()) || !
N){
508 std::cout<<
"\tSelected namespace -> " <<
qual_name <<
"\n";
550 ROOT::TMetaUtils::Error(
nullptr,
"Union %s has been selected for I/O. This is not supported. Interactive usage of unions is supported, as all C++ entities, without the need of dictionaries.\n",
normName.c_str());
560 selected->RequestStreamerInfo(),
561 selected->RequestNoStreamer(),
562 selected->RequestNoInputOperator(),
563 selected->RequestOnlyTClass(),
564 selected->RequestedVersionNumber(),
565 selected->RequestedRNTupleSerializationMode(),
571 selected->RequestStreamerInfo(),
572 selected->RequestNoStreamer(),
573 selected->RequestNoInputOperator(),
574 selected->RequestOnlyTClass(),
575 selected->RequestedVersionNumber(),
576 selected->RequestedRNTupleSerializationMode(),
597 std::cout <<
"Selected class "
634 "Could not cast typeDecl either to RecordDecl or could not get RecordDecl underneath typedef.\n");
669 const clang::CXXRecordDecl *
cxxdecl = llvm::dyn_cast<clang::CXXRecordDecl>(
recordDecl);
680 if (! selected)
return true;
700 if (selected->IsFromTypedef()) {
708 "Typedef is selected %s.\n",
typedefNameDecl->getNameAsString().c_str());
717 const clang::NamespaceDecl *
nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(
recordDecl->getDeclContext());
720 "Cannot convert context of RecordDecl called pair into a namespace.\n");
725 if (selected->HasAttributeFileName() || selected->HasAttributeFilePattern()) {
748 std::string
cleanFileName = llvm::sys::path::filename(selected->GetSelFileName()).str();
749 auto lineno = selected->GetLineNumber();
752 std::stringstream message;
755 message <<
"Attempt to select a class "<<
normName <<
" with two rules which have incompatible attributes. "
756 <<
"The attributes such as transiency might not be correctly propagated to the typesystem of ROOT.\n";
757 selected->Print(message);
758 message <<
"Conflicting rule already matched:\n";
777 selected->HasAttributePattern() &&
778 "*" == selected->GetAttributePattern();
785 auto msg =
"Class or struct %s was selected but its dictionary cannot be generated: "
786 "this is a private or protected class and this is not supported. No direct "
787 "I/O operation of %s instances will be possible.\n";
797 auto req_type = selected->GetRequestedType();
799 std::string
attr_name = selected->GetAttributeName().c_str();
806 if (
auto CTSD = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(
recordDecl)) {
816 const clang::Type *
thisType =
info.fSelected->GetRequestedType();
855 const clang::DeclContext *ctx = D->getDeclContext();
859 const clang::NamedDecl *parent = llvm::dyn_cast<clang::NamedDecl> (ctx);
860 isInStd = parent && 0 == parent->getQualifiedNameAsString().compare(0,5,
"std::");
893 if (!D->hasGlobalStorage() ||
940 if(clang::FunctionDecl::TemplatedKind::TK_FunctionTemplate == D->getTemplatedKind())
961 if (D && D->isImplicit()){
966 const clang::NamespaceDecl *parent = llvm::dyn_cast<clang::NamespaceDecl> (
DC);
967 if (parent && 0 == parent->getQualifiedNameAsString().compare(0,5,
"std::"))
971 for (DeclContext::decl_iterator
Child =
DC->decls_begin(),
ChildEnd =
DC->decls_end();
987 name =
N->getNameAsString();
1003 llvm::raw_string_ostream stream(
qual_name);
1004 N->getNameForDiagnostic(stream,D->getASTContext().getPrintingPolicy(),
true);
1024 for (clang::FunctionDecl::param_iterator
I = F->param_begin(), E = F->param_end();
I != E; ++
I) {
1025 clang::ParmVarDecl* P = *
I;
1031 std::string
type = P->getType().getAsString();
1032 if (
type.at(
type.length()-1) ==
'*') {
1043 ShowWarning(
"can't convert Decl to FunctionDecl",
"");
1057 std::cout<<
"File name detected"<<std::endl;
1060 cling::Interpreter::PushTransactionRAII
RAII(
const_cast<cling::Interpreter *
>(&
fInterpreter));
std::string IntToStr(int num)
long APIntToLong(const llvm::APInt &num)
std::string AddSpace(const std::string &txt)
size_t APIntToSize(const llvm::APInt &num)
void * ToDeclProp(clang::Decl *item)
std::string APIntToStr(const llvm::APInt &num)
std::string IntToStd(int num)
std::string Message(const std::string &msg, const std::string &location)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h req_type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char text
TRObject operator()(const T1 &t1) const
const_iterator end() const
std::string GetLocation(clang::Decl *D) const
void Scan(const clang::ASTContext &C)
void UnknownDecl(clang::Decl *D, const std::string &txt="") const
unknown - this kind of declaration was not known to programmer
RScanner(SelectionRules &rules, EScanType stype, const cling::Interpreter &interpret, ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, unsigned int verbose=0)
Regular constructor setting up the scanner to search for entities matching the 'rules'.
ROOT::TMetaUtils::TNormalizedCtxt & fNormCtxt
DeclCallback fRecordDeclCallback
void UnsupportedDecl(clang::Decl *D, const std::string &txt="") const
unsupported - this kind of declaration is probably not used (in current version of C++)
static std::map< clang::Decl *, std::string > fgAnonymousEnumMap
void UnimportantDecl(clang::Decl *D, const std::string &txt="") const
unimportant - this kind of declaration is not stored into reflex
void AddDelayedAnnotatedRecordDecls()
const clang::SourceManager * fSourceManager
static const int fgDeclLast
FunctionColl_t fSelectedFunctions
bool VisitFieldDecl(clang::FieldDecl *D)
Nothing to be done here.
void ShowInfo(const std::string &msg, const std::string &location="") const
bool TreatRecordDeclOrTypedefNameDecl(clang::TypeDecl *typeDecl)
static int fgAnonymousClassCounter
std::string FuncParameters(clang::FunctionDecl *D) const
bool fTypeTable[fgTypeLast+1]
void ShowTemplateInfo(const std::string &msg, const std::string &location="") const
std::string GetEnumName(clang::EnumDecl *D) const
NamespaceColl_t fSelectedNamespaces
bool GetFunctionPrototype(clang::Decl *D, std::string &prototype) const
std::set< clang::RecordDecl * > fselectedRecordDecls
std::string ConvTemplateName(clang::TemplateName &N) const
static int fgBadClassCounter
void UnimplementedDecl(clang::Decl *D, const std::string &txt="")
information about item, that should be implemented
bool VisitVarDecl(clang::VarDecl *D)
TypedefColl_t fSelectedTypedefs
std::string GetSrcLocation(clang::SourceLocation L) const
void(* DeclCallback)(const clang::RecordDecl *)
void UnsupportedType(clang::QualType qual_type) const
const cling::Interpreter & fInterpreter
DeclCallback SetRecordDeclCallback(DeclCallback callback)
Set the callback to the RecordDecl and return the previous one.
bool VisitNamespaceDecl(clang::NamespaceDecl *D)
This method visits a namespace node.
void ShowWarning(const std::string &msg, const std::string &location="") const
std::string GetName(clang::Decl *D) const
static int fgAnonymousEnumCounter
static const char * fgClangFuncKey
void ShowError(const std::string &msg, const std::string &location="") const
void UnexpectedDecl(clang::Decl *D, const std::string &txt="") const
unexpected - this kind of declaration is unexpected (in concrete place)
EnumColl_t fSelectedEnums
int AddAnnotatedRecordDecl(const ClassSelectionRule *, const clang::Type *, const clang::RecordDecl *, const std::string &, const clang::TypedefNameDecl *, unsigned int indexOffset=0)
std::vector< DelayedAnnotatedRecordDeclInfo > fDelayedAnnotatedRecordDecls
bool VisitEnumDecl(clang::EnumDecl *D)
static std::map< clang::Decl *, std::string > fgAnonymousClassMap
std::string FuncParameterList(clang::FunctionDecl *D) const
static bool GetDeclQualName(const clang::Decl *D, std::string &qual_name)
std::string ExprToStr(clang::Expr *expr) const
static const int fgTypeLast
SelectionRules & fSelectionRules
static const char * fgClangDeclKey
bool VisitRecordDecl(clang::RecordDecl *D)
void UnknownType(clang::QualType qual_type) const
bool fDeclTable[fgDeclLast+1]
VariableColl_t fSelectedVariables
bool VisitFunctionDecl(clang::FunctionDecl *D)
DeclsSelRulesMap_t fDeclSelRuleMap
unsigned int fVerboseLevel
bool GetDeclName(clang::Decl *D, std::string &name) const
bool TraverseDeclContextHelper(clang::DeclContext *DC)
ClassColl_t fSelectedClasses
void DeclInfo(clang::Decl *D) const
bool shouldVisitDecl(clang::NamedDecl *D)
Whether we can actually visit this declaration, i.e.
bool VisitTypedefNameDecl(clang::TypedefNameDecl *D)
Visitor for every TypedefNameDecl, i.e.
The class representing the collection of selection rules.
bool GetHasFileNameRule() const
const ClassSelectionRule * IsDeclSelected(const clang::RecordDecl *D, bool includeTypedefRule) const
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
bool areEqual< ClassSelectionRule >(const ClassSelectionRule *r1, const ClassSelectionRule *r2, bool moduloNameOrPattern)