Logo ROOT   master
Reference Guide
TClingDeclInfo.cxx
Go to the documentation of this file.
1 /// \file TClingDeclInfo.cxx
2 ///
3 /// \brief The file contains a base class of TCling*Info classes.
4 ///
5 /// \author Vassil Vassilev <vvasilev@cern.ch>
6 ///
7 /// \date March, 2019
8 ///
9 /*************************************************************************
10  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
11  * All rights reserved. *
12  * *
13  * For the licensing terms see $ROOTSYS/LICENSE. *
14  * For the list of contributors see $ROOTSYS/README/CREDITS. *
15  *************************************************************************/
16 
17 #include "TClingDeclInfo.h"
18 
19 #include "TDictionary.h"
20 
21 #include "clang/AST/ASTContext.h"
22 #include "clang/AST/Decl.h"
23 
24 using namespace clang;
25 
26 // pin the vtable here.
28 
29 const char* TClingDeclInfo::Name() const
30 {
31  if (!IsValid())
32  return 0;
33 
34  if (!fNameCache.empty())
35  return fNameCache.c_str();
36 
37  const Decl* D = GetDecl();
38  if (!isa<NamedDecl>(D))
39  return 0;
40 
41  const NamedDecl* ND = cast<NamedDecl>(D);
42  clang::PrintingPolicy policy(ND->getASTContext().getPrintingPolicy());
43  llvm::raw_string_ostream stream(fNameCache);
44  ND->getNameForDiagnostic(stream, policy, /*Qualified=*/false);
45  stream.flush();
46  return fNameCache.c_str();
47 }
48 
49 long TClingDeclInfo::Property(long property, clang::QualType &qt) const
50 {
51  if (!IsValid()) {
52  return 0L;
53  }
54  if (qt.isConstQualified()) {
55  property |= kIsConstant;
56  }
57  while (1) {
58  if (qt->isArrayType()) {
59  property |= kIsArray;
60  qt = llvm::cast<clang::ArrayType>(qt)->getElementType();
61  continue;
62  }
63  else if (qt->isReferenceType()) {
64  property |= kIsReference;
65  qt = llvm::cast<clang::ReferenceType>(qt)->getPointeeType();
66  continue;
67  }
68  else if (qt->isPointerType()) {
69  property |= kIsPointer;
70  if (qt.isConstQualified()) {
71  property |= kIsConstPointer;
72  }
73  qt = llvm::cast<clang::PointerType>(qt)->getPointeeType();
74  continue;
75  }
76  else if (qt->isMemberPointerType()) {
77  qt = llvm::cast<clang::MemberPointerType>(qt)->getPointeeType();
78  continue;
79  }
80  break;
81  }
82  if (qt->isBuiltinType()) {
83  property |= kIsFundamental;
84  }
85  if (qt.isConstQualified()) {
86  property |= kIsConstant;
87  }
88  return property;
89 }
virtual ~TClingDeclInfo()
static constexpr double L
virtual const char * Name() const
The file contains a base class of TCling*Info classes.
long Property(long property, clang::QualType &qt) const