zcov: / include/clang/AST/DeclarationName.h


Files: 1 Branches Taken: 73.1% 19 / 26
Generated: 2010-02-10 01:31 Branches Executed: 100.0% 26 / 26
Line Coverage: 98.8% 84 / 85


Programs: 124 Runs 231532


       1                 : //===-- DeclarationName.h - Representation of declaration names -*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : // This file declares the DeclarationName and DeclarationNameTable classes.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : #ifndef LLVM_CLANG_AST_DECLARATIONNAME_H
      14                 : #define LLVM_CLANG_AST_DECLARATIONNAME_H
      15                 : 
      16                 : #include "clang/Basic/IdentifierTable.h"
      17                 : #include "clang/AST/Type.h"
      18                 : #include "clang/AST/CanonicalType.h"
      19                 : #include "clang/Basic/PartialDiagnostic.h"
      20                 : 
      21                 : namespace llvm {
      22                 :   template <typename T> struct DenseMapInfo;
      23                 : }
      24                 : 
      25                 : namespace clang {
      26                 :   class CXXSpecialName;
      27                 :   class CXXOperatorIdName;
      28                 :   class CXXLiteralOperatorIdName;
      29                 :   class DeclarationNameExtra;
      30                 :   class IdentifierInfo;
      31                 :   class MultiKeywordSelector;
      32                 :   class UsingDirectiveDecl;
      33                 : 
      34                 : /// DeclarationName - The name of a declaration. In the common case,
      35                 : /// this just stores an IdentifierInfo pointer to a normal
      36                 : /// name. However, it also provides encodings for Objective-C
      37                 : /// selectors (optimizing zero- and one-argument selectors, which make
      38                 : /// up 78% percent of all selectors in Cocoa.h) and special C++ names
      39                 : /// for constructors, destructors, and conversion functions.
      40           241728: class DeclarationName {
      41                 : public:
      42                 :   /// NameKind - The kind of name this object contains.
      43                 :   enum NameKind {
      44                 :     Identifier,
      45                 :     ObjCZeroArgSelector,
      46                 :     ObjCOneArgSelector,
      47                 :     ObjCMultiArgSelector,
      48                 :     CXXConstructorName,
      49                 :     CXXDestructorName,
      50                 :     CXXConversionFunctionName,
      51                 :     CXXOperatorName,
      52                 :     CXXLiteralOperatorName,
      53                 :     CXXUsingDirective
      54                 :   };
      55                 : 
      56                 : private:
      57                 :   /// StoredNameKind - The kind of name that is actually stored in the
      58                 :   /// upper bits of the Ptr field. This is only used internally.
      59                 :   enum StoredNameKind {
      60                 :     StoredIdentifier = 0,
      61                 :     StoredObjCZeroArgSelector,
      62                 :     StoredObjCOneArgSelector,
      63                 :     StoredDeclarationNameExtra,
      64                 :     PtrMask = 0x03
      65                 :   };
      66                 : 
      67                 :   /// Ptr - The lowest two bits are used to express what kind of name
      68                 :   /// we're actually storing, using the values of NameKind. Depending
      69                 :   /// on the kind of name this is, the upper bits of Ptr may have one
      70                 :   /// of several different meanings:
      71                 :   ///
      72                 :   ///   StoredIdentifier - The name is a normal identifier, and Ptr is
      73                 :   ///   a normal IdentifierInfo pointer.
      74                 :   ///
      75                 :   ///   StoredObjCZeroArgSelector - The name is an Objective-C
      76                 :   ///   selector with zero arguments, and Ptr is an IdentifierInfo
      77                 :   ///   pointer pointing to the selector name.
      78                 :   ///
      79                 :   ///   StoredObjCOneArgSelector - The name is an Objective-C selector
      80                 :   ///   with one argument, and Ptr is an IdentifierInfo pointer
      81                 :   ///   pointing to the selector name.
      82                 :   ///
      83                 :   ///   StoredDeclarationNameExtra - Ptr is actually a pointer to a
      84                 :   ///   DeclarationNameExtra structure, whose first value will tell us
      85                 :   ///   whether this is an Objective-C selector, C++ operator-id name,
      86                 :   ///   or special C++ name.
      87                 :   uintptr_t Ptr;
      88                 : 
      89                 :   /// getStoredNameKind - Return the kind of object that is stored in
      90                 :   /// Ptr.
      91          1844211:   StoredNameKind getStoredNameKind() const {
      92          1844211:     return static_cast<StoredNameKind>(Ptr & PtrMask);
      93                 :   }
      94                 : 
      95                 :   /// getExtra - Get the "extra" information associated with this
      96                 :   /// multi-argument selector or C++ special name.
      97           101190:   DeclarationNameExtra *getExtra() const {
      98                 :     assert(getStoredNameKind() == StoredDeclarationNameExtra &&
                   101190: branch 1 taken
                        0: branch 2 not taken
      99           101190:            "Declaration name does not store an Extra structure");
     100           101190:     return reinterpret_cast<DeclarationNameExtra *>(Ptr & ~PtrMask);
     101                 :   }
     102                 : 
     103                 :   /// getAsCXXSpecialName - If the stored pointer is actually a
     104                 :   /// CXXSpecialName, returns a pointer to it. Otherwise, returns
     105                 :   /// a NULL pointer.
     106            18302:   CXXSpecialName *getAsCXXSpecialName() const {
                    16266: branch 1 taken
                     2036: branch 2 taken
                    16259: branch 4 taken
                        7: branch 5 taken
                    16259: branch 6 taken
                     2043: branch 7 taken
     107            18302:     if (getNameKind() >= CXXConstructorName &&
     108                 :         getNameKind() <= CXXConversionFunctionName)
     109            16259:       return reinterpret_cast<CXXSpecialName *>(Ptr & ~PtrMask);
     110             2043:     return 0;
     111                 :   }
     112                 : 
     113                 :   /// getAsCXXOperatorIdName
     114            11770:   CXXOperatorIdName *getAsCXXOperatorIdName() const {
                     4834: branch 1 taken
                     6936: branch 2 taken
     115            11770:     if (getNameKind() == CXXOperatorName)
     116             4834:       return reinterpret_cast<CXXOperatorIdName *>(Ptr & ~PtrMask);
     117             6936:     return 0;
     118                 :   }
     119                 : 
     120              223:   CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const {
                      223: branch 1 taken
                        0: branch 2 not taken
     121              223:     if (getNameKind() == CXXLiteralOperatorName)
     122              223:       return reinterpret_cast<CXXLiteralOperatorIdName *>(Ptr & ~PtrMask);
     123                0:     return 0;
     124                 :   }
     125                 : 
     126                 :   // Construct a declaration name from the name of a C++ constructor,
     127                 :   // destructor, or conversion function.
     128            20550:   DeclarationName(CXXSpecialName *Name)
     129            20550:     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
                        0: branch 0 not taken
                    20550: branch 1 taken
     130            20550:     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXSpecialName");
     131            20550:     Ptr |= StoredDeclarationNameExtra;
     132            20550:   }
     133                 : 
     134                 :   // Construct a declaration name from the name of a C++ overloaded
     135                 :   // operator.
     136             7828:   DeclarationName(CXXOperatorIdName *Name)
     137             7828:     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
                        0: branch 0 not taken
                     7828: branch 1 taken
     138             7828:     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXOperatorId");
     139             7828:     Ptr |= StoredDeclarationNameExtra;
     140             7828:   }
     141                 : 
     142               43:   DeclarationName(CXXLiteralOperatorIdName *Name)
     143               43:     : Ptr(reinterpret_cast<uintptr_t>(Name)) {
                        0: branch 0 not taken
                       43: branch 1 taken
     144               43:     assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXLiteralOperatorId");
     145               43:     Ptr |= StoredDeclarationNameExtra;
     146               43:   }
     147                 : 
     148                 :   /// Construct a declaration name from a raw pointer.
     149          1225030:   DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { }
     150                 : 
     151                 :   friend class DeclarationNameTable;
     152                 :   friend class NamedDecl;
     153                 : 
     154                 :   /// getFETokenInfoAsVoid - Retrieves the front end-specified pointer
     155                 :   /// for this name as a void pointer.
     156                 :   void *getFETokenInfoAsVoid() const;
     157                 : 
     158                 : public:
     159                 :   /// DeclarationName - Used to create an empty selector.
     160           107553:   DeclarationName() : Ptr(0) { }
     161                 : 
     162                 :   // Construct a declaration name from an IdentifierInfo *.
     163           366122:   DeclarationName(const IdentifierInfo *II)
     164           366122:     : Ptr(reinterpret_cast<uintptr_t>(II)) {
                        0: branch 0 not taken
                   366122: branch 1 taken
     165           366122:     assert((Ptr & PtrMask) == 0 && "Improperly aligned IdentifierInfo");
     166           366122:   }
     167                 : 
     168                 :   // Construct a declaration name from an Objective-C selector.
     169                 :   DeclarationName(Selector Sel);
     170                 : 
     171                 :   /// getUsingDirectiveName - Return name for all using-directives.
     172                 :   static DeclarationName getUsingDirectiveName();
     173                 : 
     174                 :   // operator bool() - Evaluates true when this declaration name is
     175                 :   // non-empty.
     176           337131:   operator bool() const {
     177                 :     return ((Ptr & PtrMask) != 0) ||
                      210: branch 3 taken
                        4: branch 1 taken
                      210: branch 2 taken
                        0: branch 3 not taken
     178           337131:            (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask));
     179                 :   }
     180                 : 
     181                 :   /// Predicate functions for querying what type of name this is.
     182           938309:   bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
     183              293:   bool isObjCZeroArgSelector() const {
     184              293:     return getStoredNameKind() == StoredObjCZeroArgSelector;
     185                 :   }
     186                 :   bool isObjCOneArgSelector() const {
     187                 :     return getStoredNameKind() == StoredObjCOneArgSelector;
     188                 :   }
     189                 : 
     190                 :   /// getNameKind - Determine what kind of name this is.
     191                 :   NameKind getNameKind() const;
     192                 : 
     193                 :   /// \brief Determines whether the name itself is dependent, e.g., because it 
     194                 :   /// involves a C++ type that is itself dependent.
     195                 :   ///
     196                 :   /// Note that this does not capture all of the notions of "dependent name",
     197                 :   /// because an identifier can be a dependent name if it is used as the 
     198                 :   /// callee in a call expression with dependent arguments.
     199                 :   bool isDependentName() const;
     200                 :   
     201                 :   /// getName - Retrieve the human-readable string for this name.
     202                 :   std::string getAsString() const;
     203                 : 
     204                 :   /// getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in
     205                 :   /// this declaration name, or NULL if this declaration name isn't a
     206                 :   /// simple identifier.
     207           925309:   IdentifierInfo *getAsIdentifierInfo() const {
                   917993: branch 2 taken
                     7316: branch 2 taken
     208           925309:     if (isIdentifier())
     209           917993:       return reinterpret_cast<IdentifierInfo *>(Ptr);
     210             7316:     return 0;
     211                 :   }
     212                 : 
     213                 :   /// getAsOpaqueInteger - Get the representation of this declaration
     214                 :   /// name as an opaque integer.
     215             4957:   uintptr_t getAsOpaqueInteger() const { return Ptr; }
     216                 : 
     217                 :   /// getAsOpaquePtr - Get the representation of this declaration name as
     218                 :   /// an opaque pointer.
     219           214250:   void *getAsOpaquePtr() const { return reinterpret_cast<void*>(Ptr); }
     220                 : 
     221             1592:   static DeclarationName getFromOpaquePtr(void *P) {
     222             1592:     DeclarationName N;
     223             1592:     N.Ptr = reinterpret_cast<uintptr_t> (P);
     224                 :     return N;
     225                 :   }
     226                 : 
     227             1261:   static DeclarationName getFromOpaqueInteger(uintptr_t P) {
     228             1261:     DeclarationName N;
     229             1261:     N.Ptr = P;
     230                 :     return N;
     231                 :   }
     232                 : 
     233                 :   /// getCXXNameType - If this name is one of the C++ names (of a
     234                 :   /// constructor, destructor, or conversion function), return the
     235                 :   /// type associated with that name.
     236                 :   QualType getCXXNameType() const;
     237                 : 
     238                 :   /// getCXXOverloadedOperator - If this name is the name of an
     239                 :   /// overloadable operator in C++ (e.g., @c operator+), retrieve the
     240                 :   /// kind of overloaded operator.
     241                 :   OverloadedOperatorKind getCXXOverloadedOperator() const;
     242                 : 
     243                 :   /// getCXXLiteralIdentifier - If this name is the name of a literal
     244                 :   /// operator, retrieve the identifier associated with it.
     245                 :   IdentifierInfo *getCXXLiteralIdentifier() const;
     246                 : 
     247                 :   /// getObjCSelector - Get the Objective-C selector stored in this
     248                 :   /// declaration name.
     249                 :   Selector getObjCSelector() const;
     250                 : 
     251                 :   /// getFETokenInfo/setFETokenInfo - The language front-end is
     252                 :   /// allowed to associate arbitrary metadata with some kinds of
     253                 :   /// declaration names, including normal identifiers and C++
     254                 :   /// constructors, destructors, and conversion functions.
     255                 :   template<typename T>
     256           395656:   T *getFETokenInfo() const { return static_cast<T*>(getFETokenInfoAsVoid()); }
     257                 : 
     258                 :   void setFETokenInfo(void *T);
     259                 : 
     260                 :   /// operator== - Determine whether the specified names are identical..
     261          1458762:   friend bool operator==(DeclarationName LHS, DeclarationName RHS) {
     262          1458762:     return LHS.Ptr == RHS.Ptr;
     263                 :   }
     264                 : 
     265                 :   /// operator!= - Determine whether the specified names are different.
     266              249:   friend bool operator!=(DeclarationName LHS, DeclarationName RHS) {
     267              249:     return LHS.Ptr != RHS.Ptr;
     268                 :   }
     269                 : 
     270           628466:   static DeclarationName getEmptyMarker() {
     271           628466:     return DeclarationName(uintptr_t(-1));
     272                 :   }
     273                 : 
     274           528439:   static DeclarationName getTombstoneMarker() {
     275           528439:     return DeclarationName(uintptr_t(-2));
     276                 :   }
     277                 :   
     278                 :   void dump() const;
     279                 : };
     280                 : 
     281                 : /// Ordering on two declaration names. If both names are identifiers,
     282                 : /// this provides a lexicographical ordering.
     283                 : bool operator<(DeclarationName LHS, DeclarationName RHS);
     284                 : 
     285                 : /// Ordering on two declaration names. If both names are identifiers,
     286                 : /// this provides a lexicographical ordering.
     287                 : inline bool operator>(DeclarationName LHS, DeclarationName RHS) {
     288                 :   return RHS < LHS;
     289                 : }
     290                 : 
     291                 : /// Ordering on two declaration names. If both names are identifiers,
     292                 : /// this provides a lexicographical ordering.
     293                 : inline bool operator<=(DeclarationName LHS, DeclarationName RHS) {
     294                 :   return !(RHS < LHS);
     295                 : }
     296                 : 
     297                 : /// Ordering on two declaration names. If both names are identifiers,
     298                 : /// this provides a lexicographical ordering.
     299                 : inline bool operator>=(DeclarationName LHS, DeclarationName RHS) {
     300                 :   return !(LHS < RHS);
     301                 : }
     302                 : 
     303                 : /// DeclarationNameTable - Used to store and retrieve DeclarationName
     304                 : /// instances for the various kinds of declaration names, e.g., normal
     305                 : /// identifiers, C++ constructor names, etc. This class contains
     306                 : /// uniqued versions of each of the C++ special names, which can be
     307                 : /// retrieved using its member functions (e.g.,
     308                 : /// getCXXConstructorName).
     309                 : class DeclarationNameTable {
     310                 :   void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> *
     311                 :   CXXOperatorIdName *CXXOperatorNames; // Operator names
     312                 :   void *CXXLiteralOperatorNames; // Actually a FoldingSet<...> *
     313                 : 
     314                 :   DeclarationNameTable(const DeclarationNameTable&);            // NONCOPYABLE
     315                 :   DeclarationNameTable& operator=(const DeclarationNameTable&); // NONCOPYABLE
     316                 : 
     317                 : public:
     318                 :   DeclarationNameTable();
     319                 :   ~DeclarationNameTable();
     320                 : 
     321                 :   /// getIdentifier - Create a declaration name that is a simple
     322                 :   /// identifier.
     323                4:   DeclarationName getIdentifier(const IdentifierInfo *ID) {
     324                4:     return DeclarationName(ID);
     325                 :   }
     326                 : 
     327                 :   /// getCXXConstructorName - Returns the name of a C++ constructor
     328                 :   /// for the given Type.
     329            13259:   DeclarationName getCXXConstructorName(CanQualType Ty) {
     330            13259:     return getCXXSpecialName(DeclarationName::CXXConstructorName, Ty);
     331                 :   }
     332                 : 
     333                 :   /// getCXXDestructorName - Returns the name of a C++ destructor
     334                 :   /// for the given Type.
     335             6445:   DeclarationName getCXXDestructorName(CanQualType Ty) {
     336             6445:     return getCXXSpecialName(DeclarationName::CXXDestructorName, Ty);
     337                 :   }
     338                 : 
     339                 :   /// getCXXConversionFunctionName - Returns the name of a C++
     340                 :   /// conversion function for the given Type.
     341              831:   DeclarationName getCXXConversionFunctionName(CanQualType Ty) {
     342              831:     return getCXXSpecialName(DeclarationName::CXXConversionFunctionName, Ty);
     343                 :   }
     344                 : 
     345                 :   /// getCXXSpecialName - Returns a declaration name for special kind
     346                 :   /// of C++ name, e.g., for a constructor, destructor, or conversion
     347                 :   /// function.
     348                 :   DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind,
     349                 :                                     CanQualType Ty);
     350                 : 
     351                 :   /// getCXXOperatorName - Get the name of the overloadable C++
     352                 :   /// operator corresponding to Op.
     353                 :   DeclarationName getCXXOperatorName(OverloadedOperatorKind Op);
     354                 : 
     355                 :   /// getCXXLiteralOperatorName - Get the name of the literal operator function
     356                 :   /// with II as the identifier.
     357                 :   DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
     358                 : };
     359                 : 
     360                 : /// Insertion operator for diagnostics.  This allows sending DeclarationName's
     361                 : /// into a diagnostic with <<.
     362                 : inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
     363             4559:                                            DeclarationName N) {
     364                 :   DB.AddTaggedVal(N.getAsOpaqueInteger(),
     365             4559:                   Diagnostic::ak_declarationname);
     366             4559:   return DB;
     367                 : }
     368                 : 
     369                 : /// Insertion operator for partial diagnostics.  This allows binding
     370                 : /// DeclarationName's into a partial diagnostic with <<.
     371                 : inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
     372              398:                                            DeclarationName N) {
     373                 :   PD.AddTaggedVal(N.getAsOpaqueInteger(),
     374              398:                   Diagnostic::ak_declarationname);
     375              398:   return PD;
     376                 : }
     377                 :   
     378                 : }  // end namespace clang
     379                 : 
     380                 : namespace llvm {
     381                 : /// Define DenseMapInfo so that DeclarationNames can be used as keys
     382                 : /// in DenseMap and DenseSets.
     383                 : template<>
     384                 : struct DenseMapInfo<clang::DeclarationName> {
     385           628466:   static inline clang::DeclarationName getEmptyKey() {
     386           628466:     return clang::DeclarationName::getEmptyMarker();
     387                 :   }
     388                 : 
     389           528439:   static inline clang::DeclarationName getTombstoneKey() {
     390           528439:     return clang::DeclarationName::getTombstoneMarker();
     391                 :   }
     392                 : 
     393                 :   static unsigned getHashValue(clang::DeclarationName);
     394                 : 
     395                 :   static inline bool
     396          1441079:   isEqual(clang::DeclarationName LHS, clang::DeclarationName RHS) {
     397          1441079:     return LHS == RHS;
     398                 :   }
     399                 : };
     400                 : 
     401                 : template <>
     402                 : struct isPodLike<clang::DeclarationName> { static const bool value = true; };
     403                 : 
     404                 : }  // end namespace llvm
     405                 : 
     406                 : #endif

Generated: 2010-02-10 01:31 by zcov