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


Files: 1 Branches Taken: 68.4% 39 / 57
Generated: 2010-02-10 01:31 Branches Executed: 93.0% 53 / 57
Line Coverage: 95.4% 411 / 431


Programs: 26 Runs 39234


       1                 : //===--- TypeLoc.h - Type Source Info Wrapper -------------------*- 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 TypeLoc interface and subclasses.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #ifndef LLVM_CLANG_AST_TYPELOC_H
      15                 : #define LLVM_CLANG_AST_TYPELOC_H
      16                 : 
      17                 : #include "clang/AST/Type.h"
      18                 : #include "clang/AST/TemplateBase.h"
      19                 : #include "clang/Basic/Specifiers.h"
      20                 : 
      21                 : namespace clang {
      22                 :   class ParmVarDecl;
      23                 :   class TypeSourceInfo;
      24                 :   class UnqualTypeLoc;
      25                 : 
      26                 : // Predeclare all the type nodes.
      27                 : #define ABSTRACT_TYPELOC(Class, Base)
      28                 : #define TYPELOC(Class, Base) \
      29                 :   class Class##TypeLoc;
      30                 : #include "clang/AST/TypeLocNodes.def"
      31                 : 
      32                 : /// \brief Base wrapper for a particular "section" of type source info.
      33                 : ///
      34                 : /// A client should use the TypeLoc subclasses through cast/dyn_cast in order to
      35                 : /// get at the actual information.
      36                 : class TypeLoc {
      37                 : protected:
      38                 :   // The correctness of this relies on the property that, for Type *Ty,
      39                 :   //   QualType(Ty, 0).getAsOpaquePtr() == (void*) Ty
      40                 :   void *Ty;
      41                 :   void *Data;
      42                 : 
      43                 : public:
      44                 :   /// The kinds of TypeLocs.  Equivalent to the Type::TypeClass enum,
      45                 :   /// except it also defines a Qualified enum that corresponds to the
      46                 :   /// QualifiedLoc class.
      47                 :   enum TypeLocClass {
      48                 : #define ABSTRACT_TYPE(Class, Base)
      49                 : #define TYPE(Class, Base) \
      50                 :     Class = Type::Class,
      51                 : #include "clang/AST/TypeNodes.def"
      52                 :     Qualified
      53                 :   };
      54                 : 
      55            30408:   TypeLoc() : Ty(0), Data(0) { }
      56           313160:   TypeLoc(QualType ty, void *opaqueData)
      57           313160:     : Ty(ty.getAsOpaquePtr()), Data(opaqueData) { }
      58             5386:   TypeLoc(Type *ty, void *opaqueData)
      59             5386:     : Ty(ty), Data(opaqueData) { }
      60                 : 
      61           231772:   TypeLocClass getTypeLocClass() const {
                     5947: branch 2 taken
                   225825: branch 3 taken
      62           231772:     if (getType().hasLocalQualifiers()) return Qualified;
      63           225825:     return (TypeLocClass) getType()->getTypeClass();
      64                 :   }
      65                 : 
      66            12453:   bool isNull() const { return !Ty; }
      67            33359:   operator bool() const { return Ty; }
      68                 : 
      69                 :   /// \brief Returns the size of type source info data block for the given type.
      70                 :   static unsigned getFullDataSizeForType(QualType Ty);
      71                 : 
      72                 :   /// \brief Get the type for which this source info wrapper provides
      73                 :   /// information.
      74           835959:   QualType getType() const {
      75           835959:     return QualType::getFromOpaquePtr(Ty);
      76                 :   }
      77                 : 
      78           120296:   Type *getTypePtr() const {
      79           120296:     return QualType::getFromOpaquePtr(Ty).getTypePtr();
      80                 :   }
      81                 : 
      82                 :   /// \brief Get the pointer where source information is stored.
      83             4470:   void *getOpaqueData() const {
      84             4470:     return Data;
      85                 :   }
      86                 : 
      87                 :   /// \brief Get the full source range.
      88              164:   SourceRange getFullSourceRange() const {
      89              164:     SourceLocation End = getSourceRange().getEnd();
      90              164:     TypeLoc Cur = *this;
      91               37:     while (true) {
      92              201:       TypeLoc Next = Cur.getNextTypeLoc();
                       37: branch 1 taken
                      164: branch 2 taken
      93              201:       if (Next.isNull()) break;
      94               37:       Cur = Next;
      95                 :     }
      96              164:     return SourceRange(Cur.getSourceRange().getBegin(), End);
      97                 :   }
      98                 : 
      99                 :   /// \brief Get the local source range.
     100            10246:   SourceRange getSourceRange() const {
     101            10246:     return getSourceRangeImpl(*this);
     102                 :   }
     103                 : 
     104                 :   /// \brief Returns the size of the type source info data block.
     105            42398:   unsigned getFullDataSize() const {
     106            42398:     return getFullDataSizeForType(getType());
     107                 :   }
     108                 : 
     109                 :   /// \brief Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the
     110                 :   /// TypeLoc is a PointerLoc and next TypeLoc is for "int".
     111            73439:   TypeLoc getNextTypeLoc() const {
     112            73439:     return getNextTypeLocImpl(*this);
     113                 :   }
     114                 : 
     115                 :   /// \brief Skips past any qualifiers, if this is qualified.
     116                 :   UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header
     117                 : 
     118                 :   /// \brief Initializes this to state that every location in this
     119                 :   /// type is the given location.
     120                 :   ///
     121                 :   /// This method exists to provide a simple transition for code that
     122                 :   /// relies on location-less types.
     123            14853:   void initialize(SourceLocation Loc) const {
     124            14853:     initializeImpl(*this, Loc);
     125            14853:   }
     126                 : 
     127                 :   friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) {
     128                 :     return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data;
     129                 :   }
     130                 : 
     131                 :   friend bool operator!=(const TypeLoc &LHS, const TypeLoc &RHS) {
     132                 :     return !(LHS == RHS);
     133                 :   }
     134                 : 
     135             8877:   static bool classof(const TypeLoc *TL) { return true; }
     136                 : 
     137                 : private:
     138                 :   static void initializeImpl(TypeLoc TL, SourceLocation Loc);
     139                 :   static TypeLoc getNextTypeLocImpl(TypeLoc TL);
     140                 :   static SourceRange getSourceRangeImpl(TypeLoc TL);
     141                 : };
     142                 : 
     143                 : /// \brief Wrapper of type source information for a type with
     144                 : /// no direct quqlaifiers.
     145                 : class UnqualTypeLoc : public TypeLoc {
     146                 : public:
     147              284:   UnqualTypeLoc() {}
     148             5386:   UnqualTypeLoc(Type *Ty, void *Data) : TypeLoc(Ty, Data) {}
     149                 : 
     150           534228:   Type *getTypePtr() const {
     151           534228:     return reinterpret_cast<Type*>(Ty);
     152                 :   }
     153                 : 
     154            96848:   TypeLocClass getTypeLocClass() const {
     155            96848:     return (TypeLocClass) getTypePtr()->getTypeClass();
     156                 :   }
     157                 : 
     158           217732:   static bool classof(const TypeLoc *TL) {
     159           217732:     return !TL->getType().hasLocalQualifiers();
     160                 :   }
     161            74387:   static bool classof(const UnqualTypeLoc *TL) { return true; }
     162                 : };
     163                 : 
     164                 : /// \brief Wrapper of type source information for a type with
     165                 : /// non-trivial direct qualifiers.
     166                 : ///
     167                 : /// Currently, we intentionally do not provide source location for
     168                 : /// type qualifiers.
     169                 : class QualifiedTypeLoc : public TypeLoc {
     170                 : public:
     171                5:   SourceRange getSourceRange() const {
     172                5:     return SourceRange();
     173                 :   }
     174                 : 
     175             5386:   UnqualTypeLoc getUnqualifiedLoc() const {
     176             5386:     return UnqualTypeLoc(getTypePtr(), Data);
     177                 :   }
     178                 : 
     179                 :   /// Initializes the local data of this type source info block to
     180                 :   /// provide no information.
     181               51:   void initializeLocal(SourceLocation Loc) {
     182                 :     // do nothing
     183               51:   }
     184                 : 
     185             1819:   TypeLoc getNextTypeLoc() const {
     186             1819:     return getUnqualifiedLoc();
     187                 :   }
     188                 : 
     189                 :   /// \brief Returns the size of the type source info data block that is
     190                 :   /// specific to this type.
     191             4008:   unsigned getLocalDataSize() const {
     192                 :     // In fact, we don't currently preserve any location information
     193                 :     // for qualifiers.
     194             4008:     return 0;
     195                 :   }
     196                 : 
     197                 :   /// \brief Returns the size of the type source info data block.
     198             3820:   unsigned getFullDataSize() const {
     199                 :     return getLocalDataSize() + 
     200             3820:       getFullDataSizeForType(getType().getLocalUnqualifiedType());
     201                 :   }
     202                 : 
     203           106548:   static bool classof(const TypeLoc *TL) {
     204           106548:     return TL->getType().hasLocalQualifiers();
     205                 :   }
     206                 :   static bool classof(const QualifiedTypeLoc *TL) { return true; }
     207                 : };
     208                 : 
     209            96848: inline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {
                    93471: branch 2 taken
     210            96848:   if (isa<QualifiedTypeLoc>(this))
     211             3377:     return cast<QualifiedTypeLoc>(this)->getUnqualifiedLoc();
     212            93471:   return cast<UnqualTypeLoc>(*this);
     213                 : }
     214                 : 
     215                 : /// A metaprogramming base class for TypeLoc classes which correspond
     216                 : /// to a particular Type subclass.  It is accepted for a single
     217                 : /// TypeLoc class to correspond to multiple Type classes.
     218                 : ///
     219                 : /// \param Base a class from which to derive
     220                 : /// \param Derived the class deriving from this one
     221                 : /// \param TypeClass the concrete Type subclass associated with this
     222                 : ///   location type
     223                 : /// \param LocalData the structure type of local location data for
     224                 : ///   this type
     225                 : ///
     226                 : /// sizeof(LocalData) needs to be a multiple of sizeof(void*) or
     227                 : /// else the world will end.
     228                 : ///
     229                 : /// TypeLocs with non-constant amounts of local data should override
     230                 : /// getExtraLocalDataSize(); getExtraLocalData() will then point to
     231                 : /// this extra memory.
     232                 : ///
     233                 : /// TypeLocs with an inner type should define
     234                 : ///   QualType getInnerType() const
     235                 : /// and getInnerTypeLoc() will then point to this inner type's
     236                 : /// location data.
     237                 : ///
     238                 : /// A word about hierarchies: this template is not designed to be
     239                 : /// derived from multiple times in a hierarchy.  It is also not
     240                 : /// designed to be used for classes where subtypes might provide
     241                 : /// different amounts of source information.  It should be subclassed
     242                 : /// only at the deepest portion of the hierarchy where all children
     243                 : /// have identical source information; if that's an abstract type,
     244                 : /// then further descendents should inherit from
     245                 : /// InheritingConcreteTypeLoc instead.
     246                 : template <class Base, class Derived, class TypeClass, class LocalData>
     247              284: class ConcreteTypeLoc : public Base {
     248                 : 
     249           640964:   const Derived *asDerived() const {
     250           640964:     return static_cast<const Derived*>(this);
     251                 :   }
     252                 : 
     253                 : public:
     254           207160:   unsigned getLocalDataSize() const {
     255           207160:     return sizeof(LocalData) + asDerived()->getExtraLocalDataSize();
     256                 :   }
     257                 :   // Give a default implementation that's useful for leaf types.
     258           120470:   unsigned getFullDataSize() const {
     259           120470:     return asDerived()->getLocalDataSize() + getInnerTypeSize();
     260                 :   }
     261                 : 
     262           154311:   static bool classofType(const Type *Ty) {
     263           154311:     return TypeClass::classof(Ty);
     264                 :   }
     265                 : 
     266            71620:   TypeLoc getNextTypeLoc() const {
     267            71620:     return getNextTypeLoc(asDerived()->getInnerType());
     268                 :   }
     269                 : 
     270           397979:   TypeClass *getTypePtr() const {
     271           397979:     return cast<TypeClass>(Base::getTypePtr());
     272                 :   }
     273                 : 
     274                 : protected:
     275            98122:   unsigned getExtraLocalDataSize() const {
     276            98122:     return 0;
     277                 :   }
     278                 : 
     279           282679:   LocalData *getLocalData() const {
     280           282679:     return static_cast<LocalData*>(Base::Data);
     281                 :   }
     282                 : 
     283                 :   /// Gets a pointer past the Info structure; useful for classes with
     284                 :   /// local data that can't be captured in the Info (e.g. because it's
     285                 :   /// of variable size).
     286            84550:   void *getExtraLocalData() const {
     287            84550:     return getLocalData() + 1;
     288                 :   }
     289                 :   
     290            81370:   void *getNonLocalData() const {
     291            81370:     return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize();
     292                 :   }
     293                 : 
     294                 :   struct HasNoInnerType {};
     295           112714:   HasNoInnerType getInnerType() const { return HasNoInnerType(); }
     296                 : 
     297            39874:   TypeLoc getInnerTypeLoc() const {
     298            39874:     return TypeLoc(asDerived()->getInnerType(), getNonLocalData());
     299                 :   }
     300                 : 
     301                 : private:
     302           120470:   unsigned getInnerTypeSize() const {
     303           120470:     return getInnerTypeSize(asDerived()->getInnerType());
     304                 :   }
     305                 : 
     306            82590:   unsigned getInnerTypeSize(HasNoInnerType _) const {
     307            82590:     return 0;
     308                 :   }
     309                 : 
     310            37880:   unsigned getInnerTypeSize(QualType _) const {
     311            37880:     return getInnerTypeLoc().getFullDataSize();
     312                 :   }
     313                 : 
     314            30124:   TypeLoc getNextTypeLoc(HasNoInnerType _) const {
     315            30124:     return TypeLoc();
     316                 :   }
     317                 : 
     318            41496:   TypeLoc getNextTypeLoc(QualType T) const {
     319            41496:     return TypeLoc(T, getNonLocalData());
     320                 :   }
     321                 : };
     322                 : 
     323                 : /// A metaprogramming class designed for concrete subtypes of abstract
     324                 : /// types where all subtypes share equivalently-structured source
     325                 : /// information.  See the note on ConcreteTypeLoc.
     326                 : template <class Base, class Derived, class TypeClass>
     327                 : class InheritingConcreteTypeLoc : public Base {
     328                 : public:
     329           114910:   static bool classof(const TypeLoc *TL) {
     330           114910:     return Derived::classofType(TL->getTypePtr());
     331                 :   }
     332            39401:   static bool classof(const UnqualTypeLoc *TL) {
     333            39401:     return Derived::classofType(TL->getTypePtr());
     334                 :   }
     335             5552:   static bool classof(const Derived *TL) {
     336             5552:     return true;
     337                 :   }
     338                 : 
     339             3272:   TypeClass *getTypePtr() const {
     340             3272:     return cast<TypeClass>(Base::getTypePtr());
     341                 :   }
     342                 : };
     343                 : 
     344                 : 
     345                 : struct TypeSpecLocInfo {
     346                 :   SourceLocation NameLoc;
     347                 : };
     348                 : 
     349                 : /// \brief A reasonable base class for TypeLocs that correspond to
     350                 : /// types that are written as a type-specifier.
     351                 : class TypeSpecTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, 
     352                 :                                                TypeSpecTypeLoc,
     353                 :                                                Type,
     354                 :                                                TypeSpecLocInfo> {
     355                 : public:
     356                 :   enum { LocalDataSize = sizeof(TypeSpecLocInfo) };
     357                 : 
     358            12604:   SourceLocation getNameLoc() const {
     359            12604:     return this->getLocalData()->NameLoc;
     360                 :   }
     361            26644:   void setNameLoc(SourceLocation Loc) {
     362            26644:     this->getLocalData()->NameLoc = Loc;
     363            26644:   }
     364             4627:   SourceRange getSourceRange() const {
     365             4627:     return SourceRange(getNameLoc(), getNameLoc());
     366                 :   }
     367            11013:   void initializeLocal(SourceLocation Loc) {
     368            11013:     setNameLoc(Loc);
     369            11013:   }
     370                 : 
     371                 :   static bool classof(const TypeLoc *TL);
     372                 :   static bool classof(const TypeSpecTypeLoc *TL) { return true; }
     373                 : };
     374                 : 
     375                 : 
     376                 : struct BuiltinLocInfo {
     377                 :   SourceLocation BuiltinLoc;
     378                 : };
     379                 : 
     380                 : /// \brief Wrapper for source info for builtin types.
     381                 : class BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
     382                 :                                               BuiltinTypeLoc,
     383                 :                                               BuiltinType,
     384                 :                                               BuiltinLocInfo> {
     385                 : public:
     386                 :   enum { LocalDataSize = sizeof(BuiltinLocInfo) };
     387                 : 
     388            10077:   SourceLocation getBuiltinLoc() const {
     389            10077:     return getLocalData()->BuiltinLoc;
     390                 :   }
     391            46723:   void setBuiltinLoc(SourceLocation Loc) {
     392            46723:     getLocalData()->BuiltinLoc = Loc;
     393            46723:   }
     394                 : 
     395                 :   SourceLocation getNameLoc() const { return getBuiltinLoc(); }
     396                 : 
     397            22720:   WrittenBuiltinSpecs& getWrittenBuiltinSpecs() {
     398            22720:     return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
     399                 :   }
     400            40296:   const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
     401            40296:     return *(static_cast<WrittenBuiltinSpecs*>(getExtraLocalData()));
     402                 :   }
     403                 : 
     404           125759:   bool needsExtraLocalData() const {
     405           125759:     BuiltinType::Kind bk = getTypePtr()->getKind();
     406                 :     return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128)
     407                 :       || (bk >= BuiltinType::Short && bk <= BuiltinType::LongDouble)
     408                 :       || bk == BuiltinType::UChar
                    98682: branch 1 taken
                    27077: branch 2 taken
                    91079: branch 3 taken
                     7603: branch 4 taken
                    80457: branch 5 taken
                    37699: branch 6 taken
                     4345: branch 7 taken
                    76112: branch 8 taken
                    41008: branch 9 taken
                     1036: branch 10 taken
                      806: branch 11 taken
                    40202: branch 11 taken
     409           125759:       || bk == BuiltinType::SChar;
     410                 :   }
     411                 : 
     412            42267:   unsigned getExtraLocalDataSize() const {
                    22217: branch 1 taken
                    20050: branch 2 taken
     413            42267:     return needsExtraLocalData() ? sizeof(WrittenBuiltinSpecs) : 0;
     414                 :   }
     415                 : 
     416             4829:   SourceRange getSourceRange() const {
     417             4829:     return SourceRange(getBuiltinLoc(), getBuiltinLoc());
     418                 :   }
     419                 : 
     420            21528:   TypeSpecifierSign getWrittenSignSpec() const {
                    21528: branch 1 taken
                        0: branch 2 not taken
     421            21528:     if (needsExtraLocalData())
     422            21528:       return static_cast<TypeSpecifierSign>(getWrittenBuiltinSpecs().Sign);
     423                 :     else
     424                0:       return TSS_unspecified;
     425                 :   }
     426                 :   bool hasWrittenSignSpec() const {
     427                 :     return getWrittenSignSpec() != TSS_unspecified;
     428                 :   }
     429              178:   void setWrittenSignSpec(TypeSpecifierSign written) {
                      178: branch 1 taken
                        0: branch 2 not taken
     430              178:     if (needsExtraLocalData())
     431              178:       getWrittenBuiltinSpecs().Sign = written;
     432              178:   }
     433                 : 
     434            18394:   TypeSpecifierWidth getWrittenWidthSpec() const {
                    18394: branch 1 taken
                        0: branch 2 not taken
     435            18394:     if (needsExtraLocalData())
     436            18394:       return static_cast<TypeSpecifierWidth>(getWrittenBuiltinSpecs().Width);
     437                 :     else
     438                0:       return TSW_unspecified;
     439                 :   }
     440                 :   bool hasWrittenWidthSpec() const {
     441                 :     return getWrittenWidthSpec() != TSW_unspecified;
     442                 :   }
     443              178:   void setWrittenWidthSpec(TypeSpecifierWidth written) {
                      178: branch 1 taken
                        0: branch 2 not taken
     444              178:     if (needsExtraLocalData())
     445              178:       getWrittenBuiltinSpecs().Width = written;
     446              178:   }
     447                 : 
     448                 :   TypeSpecifierType getWrittenTypeSpec() const;
     449                 :   bool hasWrittenTypeSpec() const {
     450                 :     return getWrittenTypeSpec() != TST_unspecified;
     451                 :   }
     452              178:   void setWrittenTypeSpec(TypeSpecifierType written) {
                      178: branch 1 taken
                        0: branch 2 not taken
     453              178:     if (needsExtraLocalData())
     454              178:       getWrittenBuiltinSpecs().Type = written;
     455              178:   }
     456                 : 
     457              187:   bool hasModeAttr() const {
                      187: branch 1 taken
                        0: branch 2 not taken
     458              187:     if (needsExtraLocalData())
     459              187:       return getWrittenBuiltinSpecs().ModeAttr;
     460                 :     else
     461                0:       return false;
     462                 :   }
     463              178:   void setModeAttr(bool written) {
                      178: branch 1 taken
                        0: branch 2 not taken
     464              178:     if (needsExtraLocalData())
     465              178:       getWrittenBuiltinSpecs().ModeAttr = written;
     466              178:   }
     467                 : 
     468             2622:   void initializeLocal(SourceLocation Loc) {
     469             2622:     setBuiltinLoc(Loc);
                      585: branch 1 taken
                     2037: branch 2 taken
     470             2622:     if (needsExtraLocalData()) {
     471              585:       WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs();
     472              585:       wbs.Sign = TSS_unspecified;
     473              585:       wbs.Width = TSW_unspecified;
     474              585:       wbs.Type = TST_unspecified;
     475              585:       wbs.ModeAttr = false;
     476                 :     }
     477             2622:   }
     478                 : };
     479                 : 
     480                 : 
     481                 : /// \brief Wrapper for source info for typedefs.
     482                 : class TypedefTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
     483                 :                                                         TypedefTypeLoc,
     484                 :                                                         TypedefType> {
     485                 : public:
     486               32:   TypedefDecl *getTypedefDecl() const {
     487               32:     return getTypePtr()->getDecl();
     488                 :   }
     489                 : };
     490                 : 
     491                 : /// \brief Wrapper for source info for unresolved typename using decls.
     492                 : class UnresolvedUsingTypeLoc :
     493                 :     public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
     494                 :                                      UnresolvedUsingTypeLoc,
     495                 :                                      UnresolvedUsingType> {
     496                 : public:
     497                0:   UnresolvedUsingTypenameDecl *getDecl() const {
     498                0:     return getTypePtr()->getDecl();
     499                 :   }
     500                 : };
     501                 : 
     502                 : /// \brief Wrapper for source info for tag types.  Note that this only
     503                 : /// records source info for the name itself; a type written 'struct foo'
     504                 : /// should be represented as an ElaboratedTypeLoc.  We currently
     505                 : /// only do that when C++ is enabled because of the expense of
     506                 : /// creating an ElaboratedType node for so many type references in C.
     507                 : class TagTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
     508                 :                                                     TagTypeLoc,
     509                 :                                                     TagType> {
     510                 : public:
     511                7:   TagDecl *getDecl() const { return getTypePtr()->getDecl(); }
     512                 : };
     513                 : 
     514                 : /// \brief Wrapper for source info for record types.
     515                 : class RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
     516                 :                                                        RecordTypeLoc,
     517                 :                                                        RecordType> {
     518                 : public:
     519                 :   RecordDecl *getDecl() const { return getTypePtr()->getDecl(); }
     520                 : };
     521                 : 
     522                 : /// \brief Wrapper for source info for enum types.
     523                 : class EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
     524                 :                                                      EnumTypeLoc,
     525                 :                                                      EnumType> {
     526                 : public:
     527                 :   EnumDecl *getDecl() const { return getTypePtr()->getDecl(); }
     528                 : };
     529                 : 
     530                 : /// \brief Wrapper for template type parameters.
     531                 : class TemplateTypeParmTypeLoc :
     532                 :     public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
     533                 :                                      TemplateTypeParmTypeLoc,
     534                 :                                      TemplateTypeParmType> {
     535                 : };
     536                 : 
     537                 : /// \brief Wrapper for substituted template type parameters.
     538                 : class SubstTemplateTypeParmTypeLoc :
     539                 :     public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
     540                 :                                      SubstTemplateTypeParmTypeLoc,
     541                 :                                      SubstTemplateTypeParmType> {
     542                 : };
     543                 : 
     544                 : 
     545                 : struct ObjCProtocolListLocInfo {
     546                 :   SourceLocation LAngleLoc;
     547                 :   SourceLocation RAngleLoc;
     548                 : };
     549                 : 
     550                 : // A helper class for defining ObjC TypeLocs that can qualified with
     551                 : // protocols.
     552                 : //
     553                 : // TypeClass basically has to be either ObjCInterfaceType or
     554                 : // ObjCObjectPointerType.
     555                 : template <class Derived, class TypeClass, class LocalData>
     556                 : class ObjCProtocolListTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
     557                 :                                                        Derived,
     558                 :                                                        TypeClass,
     559                 :                                                        LocalData> {
     560                 :   // SourceLocations are stored after Info, one for each Protocol.
     561              459:   SourceLocation *getProtocolLocArray() const {
     562              459:     return (SourceLocation*) this->getExtraLocalData();
     563                 :   }
     564                 : 
     565                 : protected:
     566             1276:   void initializeLocalBase(SourceLocation Loc) {
     567             1276:     setLAngleLoc(Loc);
     568             1276:     setRAngleLoc(Loc);
                        0: branch 1 not taken
                        8: branch 2 taken
                        0: branch 4 not taken
                     1268: branch 5 taken
     569             1276:     for (unsigned i = 0, e = getNumProtocols(); i != e; ++i)
     570                0:       setProtocolLoc(i, Loc);
     571             1276:   }
     572                 : 
     573                 : public:
     574               37:   SourceLocation getLAngleLoc() const {
     575               37:     return this->getLocalData()->LAngleLoc;
     576                 :   }
     577             5432:   void setLAngleLoc(SourceLocation Loc) {
     578             5432:     this->getLocalData()->LAngleLoc = Loc;
     579             5432:   }
     580                 : 
     581               50:   SourceLocation getRAngleLoc() const {
     582               50:     return this->getLocalData()->RAngleLoc;
     583                 :   }
     584             5432:   void setRAngleLoc(SourceLocation Loc) {
     585             5432:     this->getLocalData()->RAngleLoc = Loc;
     586             5432:   }
     587                 : 
     588            17832:   unsigned getNumProtocols() const {
     589            17832:     return this->getTypePtr()->getNumProtocols();
     590                 :   }
     591                 : 
     592               44:   SourceLocation getProtocolLoc(unsigned i) const {
                       43: branch 1 taken
                        0: branch 2 not taken
                        1: branch 5 taken
                        0: branch 6 not taken
     593               44:     assert(i < getNumProtocols() && "Index is out of bounds!");
     594               44:     return getProtocolLocArray()[i];
     595                 :   }
     596              415:   void setProtocolLoc(unsigned i, SourceLocation Loc) {
                      264: branch 1 taken
                        0: branch 2 not taken
                      151: branch 5 taken
                        0: branch 6 not taken
     597              415:     assert(i < getNumProtocols() && "Index is out of bounds!");
     598              415:     getProtocolLocArray()[i] = Loc;
     599              415:   }
     600                 : 
     601               38:   ObjCProtocolDecl *getProtocol(unsigned i) const {
                       38: branch 1 taken
                        0: branch 2 not taken
                        0: branch 5 not taken
                        0: branch 6 not taken
     602               38:     assert(i < getNumProtocols() && "Index is out of bounds!");
     603               38:     return *(this->getTypePtr()->qual_begin() + i);
     604                 :   }
     605                 :   
     606                 :   SourceRange getSourceRange() const {
     607                 :     return SourceRange(getLAngleLoc(), getRAngleLoc());
     608                 :   }
     609                 : 
     610                 :   void initializeLocal(SourceLocation Loc) {
     611                 :     initializeLocalBase(Loc);
     612                 :   }
     613                 : 
     614            12883:   unsigned getExtraLocalDataSize() const {
     615            12883:     return this->getNumProtocols() * sizeof(SourceLocation);
     616                 :   }
     617                 : };
     618                 : 
     619                 : 
     620                 : struct ObjCInterfaceLocInfo : ObjCProtocolListLocInfo {
     621                 :   SourceLocation NameLoc;
     622                 : };
     623                 : 
     624                 : /// \brief Wrapper for source info for ObjC interfaces.
     625                 : class ObjCInterfaceTypeLoc :
     626                 :     public ObjCProtocolListTypeLoc<ObjCInterfaceTypeLoc,
     627                 :                                    ObjCInterfaceType,
     628                 :                                    ObjCInterfaceLocInfo> {
     629                 : public:
     630               30:   ObjCInterfaceDecl *getIFaceDecl() const {
     631               30:     return getTypePtr()->getDecl();
     632                 :   }
     633                 : 
     634              743:   SourceLocation getNameLoc() const {
     635              743:     return getLocalData()->NameLoc;
     636                 :   }
     637                 : 
     638             1979:   void setNameLoc(SourceLocation Loc) {
     639             1979:     getLocalData()->NameLoc = Loc;
     640             1979:   }
     641                 : 
     642              360:   SourceRange getSourceRange() const {
                       13: branch 1 taken
                      347: branch 2 taken
     643              360:     if (getNumProtocols()) 
     644               13:       return SourceRange(getNameLoc(), getRAngleLoc());
     645                 :     else
     646              347:       return SourceRange(getNameLoc(), getNameLoc());
     647                 :   }
     648                 : 
     649                8:   void initializeLocal(SourceLocation Loc) {
     650                8:     initializeLocalBase(Loc);
     651                8:     setNameLoc(Loc);
     652                8:   }
     653                 : };
     654                 : 
     655                 : 
     656                 : struct ObjCObjectPointerLocInfo : ObjCProtocolListLocInfo {
     657                 :   SourceLocation StarLoc;
     658                 :   bool HasProtocols;
     659                 :   bool HasBaseType;
     660                 : };
     661                 : 
     662                 : /// Wraps an ObjCPointerType with source location information.  Note
     663                 : /// that not all ObjCPointerTypes actually have a star location; nor
     664                 : /// are protocol locations necessarily written in the source just
     665                 : /// because they're present on the type.
     666                 : class ObjCObjectPointerTypeLoc :
     667                 :     public ObjCProtocolListTypeLoc<ObjCObjectPointerTypeLoc,
     668                 :                                    ObjCObjectPointerType,
     669                 :                                    ObjCObjectPointerLocInfo> {
     670                 : public:
     671              173:   bool hasProtocolsAsWritten() const {
     672              173:     return getLocalData()->HasProtocols;
     673                 :   }
     674                 : 
     675             3453:   void setHasProtocolsAsWritten(bool HasProtocols) {
     676             3453:     getLocalData()->HasProtocols = HasProtocols;
     677             3453:   }
     678                 : 
     679              105:   bool hasBaseTypeAsWritten() const {
     680              105:     return getLocalData()->HasBaseType;
     681                 :   }
     682                 : 
     683             3453:   void setHasBaseTypeAsWritten(bool HasBaseType) {
     684             3453:     getLocalData()->HasBaseType = HasBaseType;
     685             3453:   }
     686                 : 
     687               31:   SourceLocation getStarLoc() const {
     688               31:     return getLocalData()->StarLoc;
     689                 :   }
     690                 : 
     691             3453:   void setStarLoc(SourceLocation Loc) {
     692             3453:     getLocalData()->StarLoc = Loc;
     693             3453:   }
     694                 : 
     695                0:   SourceRange getSourceRange() const {
     696                 :     // Being written with protocols is incompatible with being written
     697                 :     // with a star.
                        0: branch 1 not taken
                        0: branch 2 not taken
     698                0:     if (hasProtocolsAsWritten())
     699                0:       return SourceRange(getLAngleLoc(), getRAngleLoc());
     700                 :     else
     701                0:       return SourceRange(getStarLoc(), getStarLoc());
     702                 :   }
     703                 : 
     704             1268:   void initializeLocal(SourceLocation Loc) {
     705             1268:     initializeLocalBase(Loc);
     706             1268:     setHasProtocolsAsWritten(false);
     707             1268:     setHasBaseTypeAsWritten(false);
     708             1268:     setStarLoc(Loc);
     709             1268:   }
     710                 : 
     711              287:   TypeLoc getBaseTypeLoc() const {
     712              287:     return getInnerTypeLoc();
     713                 :   }
     714                 : 
     715            10904:   QualType getInnerType() const {
     716            10904:     return getTypePtr()->getPointeeType();
     717                 :   }
     718                 : };
     719                 : 
     720                 : 
     721                 : struct PointerLikeLocInfo {
     722                 :   SourceLocation StarLoc;
     723                 : };
     724                 : 
     725                 : /// A base class for 
     726                 : template <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo>
     727                 : class PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived,
     728              284:                                                   TypeClass, LocalData> {
     729                 : public:  
     730             1629:   SourceLocation getSigilLoc() const {
     731             1629:     return this->getLocalData()->StarLoc;
     732                 :   }
     733            16751:   void setSigilLoc(SourceLocation Loc) {
     734            16751:     this->getLocalData()->StarLoc = Loc;
     735            16751:   }
     736                 : 
     737             1277:   TypeLoc getPointeeLoc() const {
     738             1277:     return this->getInnerTypeLoc();
     739                 :   }
     740                 : 
     741               13:   SourceRange getSourceRange() const {
     742               13:     return SourceRange(getSigilLoc(), getSigilLoc());
     743                 :   }
     744                 : 
     745             1268:   void initializeLocal(SourceLocation Loc) {
     746             1268:     setSigilLoc(Loc);
     747             1268:   }
     748                 : 
     749            48896:   QualType getInnerType() const {
     750            48896:     return this->getTypePtr()->getPointeeType();
     751                 :   }
     752                 : };
     753                 : 
     754                 : 
     755                 : /// \brief Wrapper for source info for pointers.
     756                 : class PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc,
     757                 :                                                  PointerType> {
     758                 : public:
     759              108:   SourceLocation getStarLoc() const {
     760              108:     return getSigilLoc();
     761                 :   }
     762            12640:   void setStarLoc(SourceLocation Loc) {
     763            12640:     setSigilLoc(Loc);
     764            12640:   }
     765                 : };
     766                 : 
     767                 : 
     768                 : /// \brief Wrapper for source info for block pointers.
     769                 : class BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc,
     770                 :                                                       BlockPointerType> {
     771                 : public:
     772                2:   SourceLocation getCaretLoc() const {
     773                2:     return getSigilLoc();
     774                 :   }
     775              228:   void setCaretLoc(SourceLocation Loc) {
     776              228:     setSigilLoc(Loc);
     777              228:   }
     778                 : };
     779                 : 
     780                 : 
     781                 : /// \brief Wrapper for source info for member pointers.
     782                 : class MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc,
     783                 :                                                        MemberPointerType> {
     784                 : public:
     785               28:   SourceLocation getStarLoc() const {
     786               28:     return getSigilLoc();
     787                 :   }
     788              287:   void setStarLoc(SourceLocation Loc) {
     789              287:     setSigilLoc(Loc);
     790              287:   }
     791                 : };
     792                 : 
     793                 : 
     794                 : class ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc,
     795              284:                                                    ReferenceType> {
     796                 : public:
     797             7551:   QualType getInnerType() const {
     798             7551:     return getTypePtr()->getPointeeTypeAsWritten();
     799                 :   }
     800                 : };
     801                 : 
     802                 : class LValueReferenceTypeLoc :
     803                 :     public InheritingConcreteTypeLoc<ReferenceTypeLoc,
     804                 :                                      LValueReferenceTypeLoc,
     805                 :                                      LValueReferenceType> {
     806                 : public:
     807                2:   SourceLocation getAmpLoc() const {
     808                2:     return getSigilLoc();
     809                 :   }
     810             1554:   void setAmpLoc(SourceLocation Loc) {
     811             1554:     setSigilLoc(Loc);
     812             1554:   }
     813                 : };
     814                 : 
     815                 : class RValueReferenceTypeLoc :
     816                 :     public InheritingConcreteTypeLoc<ReferenceTypeLoc,
     817                 :                                      RValueReferenceTypeLoc,
     818                 :                                      RValueReferenceType> {
     819                 : public:
     820                0:   SourceLocation getAmpAmpLoc() const {
     821                0:     return getSigilLoc();
     822                 :   }
     823               36:   void setAmpAmpLoc(SourceLocation Loc) {
     824               36:     setSigilLoc(Loc);
     825               36:   }
     826                 : };
     827                 : 
     828                 : 
     829                 : struct FunctionLocInfo {
     830                 :   SourceLocation LParenLoc, RParenLoc;
     831                 : };
     832                 : 
     833                 : /// \brief Wrapper for source info for functions.
     834                 : class FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
     835                 :                                                FunctionTypeLoc,
     836                 :                                                FunctionType,
     837                 :                                                FunctionLocInfo> {
     838                 :   // ParmVarDecls* are stored after Info, one for each argument.
     839            13501:   ParmVarDecl **getParmArray() const {
     840            13501:     return (ParmVarDecl**) getExtraLocalData();
     841                 :   }
     842                 : 
     843                 : public:
     844               77:   SourceLocation getLParenLoc() const {
     845               77:     return getLocalData()->LParenLoc;
     846                 :   }
     847            14483:   void setLParenLoc(SourceLocation Loc) {
     848            14483:     getLocalData()->LParenLoc = Loc;
     849            14483:   }
     850                 : 
     851               77:   SourceLocation getRParenLoc() const {
     852               77:     return getLocalData()->RParenLoc;
     853                 :   }
     854            14483:   void setRParenLoc(SourceLocation Loc) {
     855            14483:     getLocalData()->RParenLoc = Loc;
     856            14483:   }
     857                 : 
     858            59123:   unsigned getNumArgs() const {
                     8284: branch 2 taken
                    50839: branch 3 taken
     859            59123:     if (isa<FunctionNoProtoType>(getTypePtr()))
     860             8284:       return 0;
     861            50839:     return cast<FunctionProtoType>(getTypePtr())->getNumArgs();
     862                 :   }
     863              631:   ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; }
     864            12870:   void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; }
     865                 : 
     866                 :   TypeLoc getArgLoc(unsigned i) const;
     867                 : 
     868              349:   TypeLoc getResultLoc() const {
     869              349:     return getInnerTypeLoc();
     870                 :   }
     871                 : 
     872                1:   SourceRange getSourceRange() const {
     873                1:     return SourceRange(getLParenLoc(), getRParenLoc());
     874                 :   }
     875                 : 
     876              101:   void initializeLocal(SourceLocation Loc) {
     877              101:     setLParenLoc(Loc);
     878              101:     setRParenLoc(Loc);
     879              249:     for (unsigned i = 0, e = getNumArgs(); i != e; ++i)
     880              148:       setArg(i, NULL);
     881              101:   }
     882                 : 
     883                 :   /// \brief Returns the size of the type source info data block that is
     884                 :   /// specific to this type.
     885            44241:   unsigned getExtraLocalDataSize() const {
     886            44241:     return getNumArgs() * sizeof(ParmVarDecl*);
     887                 :   }
     888                 : 
     889            44215:   QualType getInnerType() const { return getTypePtr()->getResultType(); }
     890                 : };
     891                 : 
     892                 : class FunctionProtoTypeLoc :
     893                 :     public InheritingConcreteTypeLoc<FunctionTypeLoc,
     894                 :                                      FunctionProtoTypeLoc,
     895                 :                                      FunctionProtoType> {
     896                 : };
     897                 : 
     898                 : class FunctionNoProtoTypeLoc :
     899                 :     public InheritingConcreteTypeLoc<FunctionTypeLoc,
     900                 :                                      FunctionNoProtoTypeLoc,
     901                 :                                      FunctionNoProtoType> {
     902                 : };
     903                 : 
     904                 : 
     905                 : struct ArrayLocInfo {
     906                 :   SourceLocation LBracketLoc, RBracketLoc;
     907                 :   Expr *Size;
     908                 : };
     909                 : 
     910                 : /// \brief Wrapper for source info for arrays.
     911                 : class ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
     912                 :                                             ArrayTypeLoc,
     913                 :                                             ArrayType,
     914                 :                                             ArrayLocInfo> {
     915                 : public:
     916              149:   SourceLocation getLBracketLoc() const {
     917              149:     return getLocalData()->LBracketLoc;
     918                 :   }
     919             2341:   void setLBracketLoc(SourceLocation Loc) {
     920             2341:     getLocalData()->LBracketLoc = Loc;
     921             2341:   }
     922                 : 
     923              149:   SourceLocation getRBracketLoc() const {
     924              149:     return getLocalData()->RBracketLoc;
     925                 :   }
     926             2341:   void setRBracketLoc(SourceLocation Loc) {
     927             2341:     getLocalData()->RBracketLoc = Loc;
     928             2341:   }
     929                 : 
     930               67:   SourceRange getBracketsRange() const {
     931               67:     return SourceRange(getLBracketLoc(), getRBracketLoc());
     932                 :   }
     933                 : 
     934               71:   Expr *getSizeExpr() const {
     935               71:     return getLocalData()->Size;
     936                 :   }
     937             2341:   void setSizeExpr(Expr *Size) {
     938             2341:     getLocalData()->Size = Size;
     939             2341:   }
     940                 : 
     941               81:   TypeLoc getElementLoc() const {
     942               81:     return getInnerTypeLoc();
     943                 :   }
     944                 : 
     945                6:   SourceRange getSourceRange() const {
     946                6:     return SourceRange(getLBracketLoc(), getRBracketLoc());
     947                 :   }
     948                 : 
     949               16:   void initializeLocal(SourceLocation Loc) {
     950               16:     setLBracketLoc(Loc);
     951               16:     setRBracketLoc(Loc);
     952               16:     setSizeExpr(NULL);
     953               16:   }
     954                 : 
     955             7684:   QualType getInnerType() const { return getTypePtr()->getElementType(); }
     956                 : };
     957                 : 
     958                 : class ConstantArrayTypeLoc :
     959                 :     public InheritingConcreteTypeLoc<ArrayTypeLoc,
     960                 :                                      ConstantArrayTypeLoc,
     961                 :                                      ConstantArrayType> {
     962                 : };
     963                 : 
     964                 : class IncompleteArrayTypeLoc :
     965                 :     public InheritingConcreteTypeLoc<ArrayTypeLoc,
     966                 :                                      IncompleteArrayTypeLoc,
     967                 :                                      IncompleteArrayType> {
     968                 : };
     969                 : 
     970                 : class DependentSizedArrayTypeLoc :
     971                 :     public InheritingConcreteTypeLoc<ArrayTypeLoc,
     972                 :                                      DependentSizedArrayTypeLoc,
     973                 :                                      DependentSizedArrayType> {
     974                 : 
     975                 : };
     976                 : 
     977                 : class VariableArrayTypeLoc :
     978                 :     public InheritingConcreteTypeLoc<ArrayTypeLoc,
     979                 :                                      VariableArrayTypeLoc,
     980                 :                                      VariableArrayType> {
     981                 : };
     982                 : 
     983                 : 
     984                 : // Location information for a TemplateName.  Rudimentary for now.
     985                 : struct TemplateNameLocInfo {
     986                 :   SourceLocation NameLoc;
     987                 : };
     988                 : 
     989                 : struct TemplateSpecializationLocInfo : TemplateNameLocInfo {
     990                 :   SourceLocation LAngleLoc;
     991                 :   SourceLocation RAngleLoc;
     992                 : };
     993                 : 
     994                 : class TemplateSpecializationTypeLoc :
     995                 :     public ConcreteTypeLoc<UnqualTypeLoc,
     996                 :                            TemplateSpecializationTypeLoc,
     997                 :                            TemplateSpecializationType,
     998                 :                            TemplateSpecializationLocInfo> {
     999                 : public:
    1000             2637:   SourceLocation getLAngleLoc() const {
    1001             2637:     return getLocalData()->LAngleLoc;
    1002                 :   }
    1003             4344:   void setLAngleLoc(SourceLocation Loc) {
    1004             4344:     getLocalData()->LAngleLoc = Loc;
    1005             4344:   }
    1006                 : 
    1007             3032:   SourceLocation getRAngleLoc() const {
    1008             3032:     return getLocalData()->RAngleLoc;
    1009                 :   }
    1010             4344:   void setRAngleLoc(SourceLocation Loc) {
    1011             4344:     getLocalData()->RAngleLoc = Loc;
    1012             4344:   }
    1013                 : 
    1014            12673:   unsigned getNumArgs() const {
    1015            12673:     return getTypePtr()->getNumArgs();
    1016                 :   }
    1017             4034:   void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
    1018                 : #ifndef NDEBUG
    1019             4034:     AI.validateForArgument(getTypePtr()->getArg(i));
    1020                 : #endif
    1021             4034:     getArgInfos()[i] = AI;
    1022             4034:   }
    1023             1835:   TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
    1024             1835:     return getArgInfos()[i];
    1025                 :   }
    1026                 : 
    1027             1835:   TemplateArgumentLoc getArgLoc(unsigned i) const {
    1028             1835:     return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
    1029                 :   }
    1030                 : 
    1031             3032:   SourceLocation getTemplateNameLoc() const {
    1032             3032:     return getLocalData()->NameLoc;
    1033                 :   }
    1034             4344:   void setTemplateNameLoc(SourceLocation Loc) {
    1035             4344:     getLocalData()->NameLoc = Loc;
    1036             4344:   }
    1037                 : 
    1038                 :   /// \brief - Copy the location information from the given info.
    1039              889:   void copy(TemplateSpecializationTypeLoc Loc) {
    1040              889:     unsigned size = getFullDataSize();
    1041              889:     assert(size == Loc.getFullDataSize());
    1042                 : 
    1043                 :     // We're potentially copying Expr references here.  We don't
    1044                 :     // bother retaining them because TypeSourceInfos live forever, so
    1045                 :     // as long as the Expr was retained when originally written into
    1046                 :     // the TypeLoc, we're okay.
    1047              889:     memcpy(Data, Loc.Data, size);
    1048              889:   }
    1049                 : 
    1050              395:   SourceRange getSourceRange() const {
    1051              395:     return SourceRange(getTemplateNameLoc(), getRAngleLoc());
    1052                 :   }
    1053                 : 
    1054             1210:   void initializeLocal(SourceLocation Loc) {
    1055             1210:     setLAngleLoc(Loc);
    1056             1210:     setRAngleLoc(Loc);
    1057             1210:     setTemplateNameLoc(Loc);
    1058                 : 
    1059             2915:     for (unsigned i = 0, e = getNumArgs(); i != e; ++i) {
    1060             1705:       TemplateArgumentLocInfo Info;
    1061                 : #ifndef NDEBUG
    1062                 :       // If asserts are enabled, be sure to initialize the argument
    1063                 :       // loc with the right kind of pointer.
    1064             1705:       switch (getTypePtr()->getArg(i).getKind()) {
    1065                 :       case TemplateArgument::Expression:
    1066                 :       case TemplateArgument::Declaration:
    1067              906:         Info = TemplateArgumentLocInfo((Expr*) 0);
    1068              906:         break;
    1069                 : 
    1070                 :       case TemplateArgument::Type:
    1071              799:         Info = TemplateArgumentLocInfo((TypeSourceInfo*) 0);
    1072              799:         break;
    1073                 : 
    1074                 :       case TemplateArgument::Template:
    1075                0:         Info = TemplateArgumentLocInfo(SourceRange(), SourceLocation());
    1076                 :         break;
    1077                 :           
    1078                 :       case TemplateArgument::Integral:
    1079                 :       case TemplateArgument::Pack:
    1080                 :       case TemplateArgument::Null:
    1081                 :         // K_None is fine.
    1082                 :         break;
    1083                 :       }
    1084                 : #endif
    1085             1705:       getArgInfos()[i] = Info;
    1086                 :     }
    1087             1210:   }
    1088                 : 
    1089             9647:   unsigned getExtraLocalDataSize() const {
    1090             9647:     return getNumArgs() * sizeof(TemplateArgumentLocInfo);
    1091                 :   }
    1092                 : 
    1093                 : private:
    1094             7574:   TemplateArgumentLocInfo *getArgInfos() const {
    1095             7574:     return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
    1096                 :   }
    1097                 : };
    1098                 : 
    1099                 : //===----------------------------------------------------------------------===//
    1100                 : //
    1101                 : //  All of these need proper implementations.
    1102                 : //
    1103                 : //===----------------------------------------------------------------------===//
    1104                 : 
    1105                 : // FIXME: size expression and attribute locations (or keyword if we
    1106                 : // ever fully support altivec syntax).
    1107                 : class VectorTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
    1108                 :                                                        VectorTypeLoc,
    1109                 :                                                        VectorType> {
    1110                 : };
    1111                 : 
    1112                 : // FIXME: size expression and attribute locations.
    1113                 : class ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc,
    1114                 :                                                           ExtVectorTypeLoc,
    1115                 :                                                           ExtVectorType> {
    1116                 : };
    1117                 : 
    1118                 : // FIXME: attribute locations.
    1119                 : // For some reason, this isn't a subtype of VectorType.
    1120                 : class DependentSizedExtVectorTypeLoc :
    1121                 :     public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
    1122                 :                                      DependentSizedExtVectorTypeLoc,
    1123                 :                                      DependentSizedExtVectorType> {
    1124                 : };
    1125                 : 
    1126                 : // FIXME: location of the '_Complex' keyword.
    1127                 : class ComplexTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
    1128                 :                                                         ComplexTypeLoc,
    1129                 :                                                         ComplexType> {
    1130                 : };
    1131                 : 
    1132                 : struct TypeofLocInfo {
    1133                 :   SourceLocation TypeofLoc;
    1134                 :   SourceLocation LParenLoc;
    1135                 :   SourceLocation RParenLoc;
    1136                 : };
    1137                 : 
    1138                 : struct TypeOfExprTypeLocInfo : public TypeofLocInfo {
    1139                 : };
    1140                 : 
    1141                 : struct TypeOfTypeLocInfo : public TypeofLocInfo {
    1142                 :   TypeSourceInfo* UnderlyingTInfo;
    1143                 : };
    1144                 : 
    1145                 : template <class Derived, class TypeClass, class LocalData = TypeofLocInfo>
    1146                 : class TypeofLikeTypeLoc
    1147                 :   : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> {
    1148                 : public:
    1149               57:   SourceLocation getTypeofLoc() const {
    1150               57:     return this->getLocalData()->TypeofLoc;
    1151                 :   }
    1152              305:   void setTypeofLoc(SourceLocation Loc) {
    1153              305:     this->getLocalData()->TypeofLoc = Loc;
    1154              305:   }
    1155                 : 
    1156               47:   SourceLocation getLParenLoc() const {
    1157               47:     return this->getLocalData()->LParenLoc;
    1158                 :   }
    1159              305:   void setLParenLoc(SourceLocation Loc) {
    1160              305:     this->getLocalData()->LParenLoc = Loc;
    1161              305:   }
    1162                 : 
    1163               67:   SourceLocation getRParenLoc() const {
    1164               67:     return this->getLocalData()->RParenLoc;
    1165                 :   }
    1166              305:   void setRParenLoc(SourceLocation Loc) {
    1167              305:     this->getLocalData()->RParenLoc = Loc;
    1168              305:   }
    1169                 : 
    1170                 :   SourceRange getParensRange() const {
    1171                 :     return SourceRange(getLParenLoc(), getRParenLoc());
    1172                 :   }
    1173              261:   void setParensRange(SourceRange range) {
    1174              261:       setLParenLoc(range.getBegin());
    1175              261:       setRParenLoc(range.getEnd());
    1176              261:   }
    1177                 : 
    1178                0:   SourceRange getSourceRange() const {
    1179                0:     return SourceRange(getTypeofLoc(), getRParenLoc());
    1180                 :   }
    1181                 : 
    1182                0:   void initializeLocal(SourceLocation Loc) {
    1183                0:     setTypeofLoc(Loc);
    1184                0:     setLParenLoc(Loc);
    1185                0:     setRParenLoc(Loc);
    1186                0:   }
    1187                 : };
    1188                 : 
    1189                 : class TypeOfExprTypeLoc : public TypeofLikeTypeLoc<TypeOfExprTypeLoc,
    1190                 :                                                    TypeOfExprType,
    1191                 :                                                    TypeOfExprTypeLocInfo> {
    1192                 : public:
    1193                4:   Expr* getUnderlyingExpr() const {
    1194                4:     return getTypePtr()->getUnderlyingExpr();
    1195                 :   }
    1196                 :   // Reimplemented to account for GNU/C++ extension
    1197                 :   //     typeof unary-expression
    1198                 :   // where there are no parentheses.
    1199                 :   SourceRange getSourceRange() const;
    1200                 : };
    1201                 : 
    1202                 : class TypeOfTypeLoc
    1203                 :   : public TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo> {
    1204                 : public:
    1205                 :   QualType getUnderlyingType() const {
    1206                 :     return this->getTypePtr()->getUnderlyingType();
    1207                 :   }
    1208                6:   TypeSourceInfo* getUnderlyingTInfo() const {
    1209                6:     return this->getLocalData()->UnderlyingTInfo;
    1210                 :   }
    1211               23:   void setUnderlyingTInfo(TypeSourceInfo* TI) const {
    1212               23:     this->getLocalData()->UnderlyingTInfo = TI;
    1213               23:   }
    1214                 : };
    1215                 : 
    1216                 : // FIXME: location of the 'decltype' and parens.
    1217                 : class DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
    1218                 :                                                          DecltypeTypeLoc,
    1219                 :                                                          DecltypeType> {
    1220                 : };
    1221                 : 
    1222                 : // FIXME: location of the tag keyword.
    1223                 : class ElaboratedTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
    1224                 :                                                            ElaboratedTypeLoc,
    1225                 :                                                            ElaboratedType> {
    1226                 : };
    1227                 : 
    1228                 : // FIXME: locations for the nested name specifier;  at the very least,
    1229                 : // a SourceRange.
    1230                 : class QualifiedNameTypeLoc :
    1231                 :     public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
    1232                 :                                      QualifiedNameTypeLoc,
    1233                 :                                      QualifiedNameType> {
    1234                 : };
    1235                 : 
    1236                 : // FIXME: locations for the typename keyword and nested name specifier.
    1237                 : class TypenameTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
    1238                 :                                                          TypenameTypeLoc,
    1239                 :                                                          TypenameType> {
    1240                 : };
    1241                 : 
    1242                 : }
    1243                 : 
    1244                 : #endif

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