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


Files: 1 Branches Taken: 55.0% 11 / 20
Generated: 2010-02-10 01:31 Branches Executed: 85.0% 17 / 20
Line Coverage: 100.0% 59 / 59


Programs: 54 Runs 103694


       1                 : //===--- DeclGroup.h - Classes for representing groups of Decls -*- 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 defines the DeclGroup, DeclGroupRef, and OwningDeclGroup classes.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #ifndef LLVM_CLANG_AST_DECLGROUP_H
      15                 : #define LLVM_CLANG_AST_DECLGROUP_H
      16                 : 
      17                 : #include "llvm/System/DataTypes.h"
      18                 : #include <cassert>
      19                 : 
      20                 : namespace clang {
      21                 : 
      22                 : class ASTContext;
      23                 : class Decl;
      24                 : class DeclGroup;
      25                 : class DeclGroupIterator;
      26                 : 
      27                5: class DeclGroup {
      28                 :   // FIXME: Include a TypeSpecifier object.
      29                 :   unsigned NumDecls;
      30                 : 
      31                 : private:
      32                 :   DeclGroup() : NumDecls(0) {}
      33                 :   DeclGroup(unsigned numdecls, Decl** decls);
      34                 : 
      35                 : public:
      36                 :   static DeclGroup *Create(ASTContext &C, Decl **Decls, unsigned NumDecls);
      37                 :   void Destroy(ASTContext& C);
      38                 : 
      39             1232:   unsigned size() const { return NumDecls; }
      40                 : 
      41             2558:   Decl*& operator[](unsigned i) {
                        0: branch 0 not taken
                     2558: branch 1 taken
      42             2558:     assert (i < NumDecls && "Out-of-bounds access.");
      43             2558:     return *((Decl**) (this+1));
      44                 :   }
      45                 : 
      46              186:   Decl* const& operator[](unsigned i) const {
                        0: branch 0 not taken
                      186: branch 1 taken
      47              186:     assert (i < NumDecls && "Out-of-bounds access.");
      48              186:     return *((Decl* const*) (this+1));
      49                 :   }
      50                 : };
      51                 : 
      52                 : class DeclGroupRef {
      53                 :   // Note this is not a PointerIntPair because we need the address of the
      54                 :   // non-group case to be valid as a Decl** for iteration.
      55                 :   enum Kind { SingleDeclKind=0x0, DeclGroupKind=0x1, Mask=0x1 };
      56                 :   Decl* D;
      57                 : 
      58            90924:   Kind getKind() const {
      59            90924:     return (Kind) (reinterpret_cast<uintptr_t>(D) & Mask);
      60                 :   }
      61                 : 
      62                 : public:
      63            34968:   DeclGroupRef() : D(0) {}
      64                 : 
      65            41130:   explicit DeclGroupRef(Decl* d) : D(d) {}
      66             1533:   explicit DeclGroupRef(DeclGroup* dg)
      67             1533:     : D((Decl*) (reinterpret_cast<uintptr_t>(dg) | DeclGroupKind)) {}
      68                 : 
      69            22819:   static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
                     1562: branch 0 taken
                    21257: branch 1 taken
      70            22819:     if (NumDecls == 0)
      71             1562:       return DeclGroupRef();
                    19726: branch 0 taken
                     1531: branch 1 taken
      72            21257:     if (NumDecls == 1)
      73            19726:       return DeclGroupRef(Decls[0]);
      74             1531:     return DeclGroupRef(DeclGroup::Create(C, Decls, NumDecls));
      75                 :   }
      76                 : 
      77                 :   typedef Decl** iterator;
      78                 :   typedef Decl* const * const_iterator;
      79                 : 
      80             7120:   bool isNull() const { return D == 0; }
      81            88150:   bool isSingleDecl() const { return getKind() == SingleDeclKind; }
      82             2774:   bool isDeclGroup() const { return getKind() == DeclGroupKind; }
      83                 : 
      84             6533:   Decl *getSingleDecl() {
                     6533: branch 1 taken
                        0: branch 2 not taken
      85             6533:     assert(isSingleDecl() && "Isn't a declgroup");
      86             6533:     return D;
      87                 :   }
      88             2902:   const Decl *getSingleDecl() const {
      89             2902:     return const_cast<DeclGroupRef*>(this)->getSingleDecl();
      90                 :   }
      91                 : 
      92             2749:   DeclGroup &getDeclGroup() {
                        0: branch 2 not taken
                        0: branch 2 not taken
      93             2749:     assert(isDeclGroup() && "Isn't a declgroup");
      94             2749:     return *((DeclGroup*)(reinterpret_cast<uintptr_t>(D) & ~Mask));
      95                 :   }
      96              186:   const DeclGroup &getDeclGroup() const {
      97              186:     return const_cast<DeclGroupRef*>(this)->getDeclGroup();
      98                 :   }
      99                 : 
     100            36990:   iterator begin() {
                      100: branch 1 taken
                        0: branch 2 not taken
     101            36990:     if (isSingleDecl())
                      100: branch 0 taken
                        0: branch 1 not taken
     102            35571:       return D ? &D : 0;
     103             1419:     return &getDeclGroup()[0];
     104                 :   }
     105                 : 
     106            35980:   iterator end() {
                      100: branch 2 taken
                        0: branch 2 not taken
     107            35980:     if (isSingleDecl())
                      100: branch 0 taken
                        0: branch 1 not taken
     108            34841:       return D ? &D+1 : 0;
     109             1139:     DeclGroup &G = getDeclGroup();
     110             1139:     return &G[0] + G.size();
     111                 :   }
     112                 : 
     113             1152:   const_iterator begin() const {
     114             1152:     if (isSingleDecl())
     115             1059:       return D ? &D : 0;
     116               93:     return &getDeclGroup()[0];
     117                 :   }
     118                 : 
     119             1152:   const_iterator end() const {
     120             1152:     if (isSingleDecl())
     121             1059:       return D ? &D+1 : 0;
     122               93:     const DeclGroup &G = getDeclGroup();
     123               93:     return &G[0] + G.size();
     124                 :   }
     125                 : 
     126            43150:   void *getAsOpaquePtr() const { return D; }
     127            33385:   static DeclGroupRef getFromOpaquePtr(void *Ptr) {
     128            33385:     DeclGroupRef X;
     129            33385:     X.D = static_cast<Decl*>(Ptr);
     130                 :     return X;
     131                 :   }
     132                 : };
     133                 : 
     134                 : } // end clang namespace
     135                 : 
     136                 : namespace llvm {
     137                 :   // DeclGroupRef is "like a pointer", implement PointerLikeTypeTraits.
     138                 :   template <typename T>
     139                 :   class PointerLikeTypeTraits;
     140                 :   template <>
     141                 :   class PointerLikeTypeTraits<clang::DeclGroupRef> {
     142                 :   public:
     143            43150:     static inline void *getAsVoidPointer(clang::DeclGroupRef P) {
     144            43150:       return P.getAsOpaquePtr();
     145                 :     }
     146            33385:     static inline clang::DeclGroupRef getFromVoidPointer(void *P) {
     147            33385:       return clang::DeclGroupRef::getFromOpaquePtr(P);
     148                 :     }
     149                 :     enum { NumLowBitsAvailable = 0 };
     150                 :   };
     151                 : }
     152                 : #endif

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