[cfe-commits] r84386 - in /cfe/trunk: include/clang/AST/TypeLoc.h include/clang/AST/TypeLocNodes.def include/clang/AST/TypeLocVisitor.h include/clang/Index/ASTLocation.h lib/AST/Decl.cpp lib/AST/TypeLoc.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp lib/Index/ASTLocation.cpp lib/Index/ASTVisitor.h lib/Index/DeclReferenceMap.cpp lib/Index/ResolveLocation.cpp lib/Sema/SemaType.cpp

John McCall rjmccall at apple.com
Sat Oct 17 18:05:36 PDT 2009


Author: rjmccall
Date: Sat Oct 17 20:05:36 2009
New Revision: 84386

URL: http://llvm.org/viewvc/llvm-project?rev=84386&view=rev
Log:
Clone the full Type hierarchy into the TypeLoc hierarchy.  Normalize
TypeLoc class names to be $(Type classname)Loc.  Rewrite the visitor.
Provide skeleton implementations for all the new TypeLocs.

Handle all cases in PCH.  Handle a few more cases when inserting
location information in SemaType.

It should be extremely straightforward to add new location information
to existing TypeLoc objects now.

Modified:
    cfe/trunk/include/clang/AST/TypeLoc.h
    cfe/trunk/include/clang/AST/TypeLocNodes.def
    cfe/trunk/include/clang/AST/TypeLocVisitor.h
    cfe/trunk/include/clang/Index/ASTLocation.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/AST/TypeLoc.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/lib/Index/ASTLocation.cpp
    cfe/trunk/lib/Index/ASTVisitor.h
    cfe/trunk/lib/Index/DeclReferenceMap.cpp
    cfe/trunk/lib/Index/ResolveLocation.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Sat Oct 17 20:05:36 2009
@@ -18,10 +18,15 @@
 
 namespace clang {
   class ParmVarDecl;
-  class TypeSpecLoc;
   class DeclaratorInfo;
   class UnqualTypeLoc;
 
+// Predeclare all the type nodes.
+#define ABSTRACT_TYPELOC(Class, Base)
+#define TYPELOC(Class, Base) \
+  class Class##TypeLoc;
+#include "clang/AST/TypeLocNodes.def"
+
 /// \brief Base wrapper for a particular "section" of type source info.
 ///
 /// A client should use the TypeLoc subclasses through cast/dyn_cast in order to
@@ -34,12 +39,28 @@
   void *Data;
 
 public:
+  /// The kinds of TypeLocs.  Equivalent to the Type::TypeClass enum,
+  /// except it also defines a Qualified enum that corresponds to the
+  /// QualifiedLoc class.
+  enum TypeLocClass {
+#define ABSTRACT_TYPE(Class, Base)
+#define TYPE(Class, Base) \
+    Class = Type::Class,
+#include "clang/AST/TypeNodes.def"
+    Qualified
+  };
+
   TypeLoc() : Ty(0), Data(0) { }
   TypeLoc(QualType ty, void *opaqueData)
     : Ty(ty.getAsOpaquePtr()), Data(opaqueData) { }
   TypeLoc(Type *ty, void *opaqueData)
     : Ty(ty), Data(opaqueData) { }
 
+  TypeLocClass getTypeLocClass() const {
+    if (getType().hasQualifiers()) return Qualified;
+    return (TypeLocClass) getType()->getTypeClass();
+  }
+
   bool isNull() const { return !Ty; }
   operator bool() const { return Ty; }
 
@@ -48,35 +69,36 @@
 
   /// \brief Get the type for which this source info wrapper provides
   /// information.
-  QualType getSourceType() const { return QualType::getFromOpaquePtr(Ty); }
+  QualType getType() const {
+    return QualType::getFromOpaquePtr(Ty);
+  }
 
-  Type *getSourceTypePtr() const {
+  Type *getTypePtr() const {
     return QualType::getFromOpaquePtr(Ty).getTypePtr();
   }
 
   /// \brief Get the pointer where source information is stored.
-  void *getOpaqueData() const { return Data; }
-
-  SourceRange getSourceRange() const;
-
-  /// \brief Find the TypeSpecLoc that is part of this TypeLoc.
-  TypeSpecLoc getTypeSpecLoc() const;
+  void *getOpaqueData() const {
+    return Data;
+  }
 
-  /// \brief Find the TypeSpecLoc that is part of this TypeLoc and return its
-  /// SourceRange.
-  SourceRange getTypeSpecRange() const;
+  SourceRange getSourceRange() const {
+    return getSourceRangeImpl(*this);
+  }
 
   /// \brief Returns the size of the type source info data block.
   unsigned getFullDataSize() const {
-    return getFullDataSizeForType(getSourceType());
+    return getFullDataSizeForType(getType());
   }
 
   /// \brief Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the
   /// TypeLoc is a PointerLoc and next TypeLoc is for "int".
-  TypeLoc getNextTypeLoc() const;
+  TypeLoc getNextTypeLoc() const {
+    return getNextTypeLocImpl(*this);
+  }
 
   /// \brief Skips past any qualifiers, if this is qualified.
-  UnqualTypeLoc getUnqualifiedLoc() const;
+  UnqualTypeLoc getUnqualifiedLoc() const; // implemented in this header
 
   /// \brief Initializes this to state that every location in this
   /// type is the given location.
@@ -99,6 +121,8 @@
 
 private:
   static void initializeImpl(TypeLoc TL, SourceLocation Loc);
+  static TypeLoc getNextTypeLocImpl(TypeLoc TL);
+  static SourceRange getSourceRangeImpl(TypeLoc TL);
 };
 
 /// \brief Wrapper of type source information for a type with
@@ -108,12 +132,16 @@
   UnqualTypeLoc() {}
   UnqualTypeLoc(Type *Ty, void *Data) : TypeLoc(Ty, Data) {}
 
-  Type *getSourceTypePtr() const {
+  Type *getTypePtr() const {
     return reinterpret_cast<Type*>(Ty);
   }
 
+  TypeLocClass getTypeLocClass() const {
+    return (TypeLocClass) getTypePtr()->getTypeClass();
+  }
+
   static bool classof(const TypeLoc *TL) {
-    return !TL->getSourceType().hasQualifiers();
+    return !TL->getType().hasQualifiers();
   }
   static bool classof(const UnqualTypeLoc *TL) { return true; }
 };
@@ -123,14 +151,14 @@
 ///
 /// Currently, we intentionally do not provide source location for
 /// type qualifiers.
-class QualifiedLoc : public TypeLoc {
+class QualifiedTypeLoc : public TypeLoc {
 public:
   SourceRange getSourceRange() const {
     return SourceRange();
   }
 
   UnqualTypeLoc getUnqualifiedLoc() const {
-    return UnqualTypeLoc(getSourceTypePtr(), Data);
+    return UnqualTypeLoc(getTypePtr(), Data);
   }
 
   /// Initializes the local data of this type source info block to
@@ -154,52 +182,21 @@
   /// \brief Returns the size of the type source info data block.
   unsigned getFullDataSize() const {
     return getLocalDataSize() + 
-      getFullDataSizeForType(getSourceType().getUnqualifiedType());
+      getFullDataSizeForType(getType().getUnqualifiedType());
   }
 
   static bool classof(const TypeLoc *TL) {
-    return TL->getSourceType().hasQualifiers();
+    return TL->getType().hasQualifiers();
   }
-  static bool classof(const QualifiedLoc *TL) { return true; }
+  static bool classof(const QualifiedTypeLoc *TL) { return true; }
 };
 
 inline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {
-  if (isa<QualifiedLoc>(this))
-    return cast<QualifiedLoc>(this)->getUnqualifiedLoc();
+  if (isa<QualifiedTypeLoc>(this))
+    return cast<QualifiedTypeLoc>(this)->getUnqualifiedLoc();
   return cast<UnqualTypeLoc>(*this);
 }
 
-/// \brief Base wrapper of type source info data for type-spec types.
-class TypeSpecLoc : public UnqualTypeLoc  {
-public:
-  static bool classof(const TypeLoc *TL) {
-    return (UnqualTypeLoc::classof(TL) &&
-            classof(static_cast<const UnqualTypeLoc*>(TL)));
-  }
-  static bool classof(const UnqualTypeLoc *TL);
-  static bool classof(const TypeSpecLoc *TL) { return true; }
-};
-
-inline SourceRange TypeLoc::getTypeSpecRange() const {
-  return getTypeSpecLoc().getSourceRange();
-}
-  
-/// \brief Base wrapper of type source info data for types part of a declarator,
-/// excluding type-spec types.
-class DeclaratorLoc : public UnqualTypeLoc  {
-public:
-  /// \brief Find the TypeSpecLoc that is part of this DeclaratorLoc.
-  TypeSpecLoc getTypeSpecLoc() const;
-
-  static bool classof(const TypeLoc *TL) {
-    return (UnqualTypeLoc::classof(TL) &&
-            classof(static_cast<const UnqualTypeLoc*>(TL)));
-  }
-  static bool classof(const UnqualTypeLoc *TL);
-  static bool classof(const DeclaratorLoc *TL) { return true; }
-};
-
-
 /// A metaprogramming base class for TypeLoc classes which correspond
 /// to a particular Type subclass.  It is accepted for a single
 /// TypeLoc class to correspond to multiple Type classes.
@@ -222,6 +219,15 @@
 ///   QualType getInnerType() const
 /// and getInnerTypeLoc() will then point to this inner type's
 /// location data.
+///
+/// A word about hierarchies: this template is not designed to be
+/// derived from multiple times in a hierarchy.  It is also not
+/// designed to be used for classes where subtypes might provide
+/// different amounts of source information.  It should be subclassed
+/// only at the deepest portion of the hierarchy where all children
+/// have identical source information; if that's an abstract type,
+/// then further descendents should inherit from
+/// InheritingConcreteTypeLoc instead.
 template <class Base, class Derived, class TypeClass, class LocalData>
 class ConcreteTypeLoc : public Base {
 
@@ -238,16 +244,6 @@
     return asDerived()->getLocalDataSize() + getInnerTypeSize();
   }
 
-  static bool classof(const TypeLoc *TL) {
-    return Derived::classofType(TL->getSourceTypePtr());
-  }
-  static bool classof(const UnqualTypeLoc *TL) {
-    return Derived::classofType(TL->getSourceTypePtr());
-  }
-  static bool classof(const Derived *TL) {
-    return true;
-  }
-
   static bool classofType(const Type *Ty) {
     return TypeClass::classof(Ty);
   }
@@ -256,11 +252,11 @@
     return getNextTypeLoc(asDerived()->getInnerType());
   }
 
-protected:
   TypeClass *getTypePtr() const {
-    return cast<TypeClass>(Base::getSourceTypePtr());
+    return cast<TypeClass>(Base::getTypePtr());
   }
 
+protected:
   unsigned getExtraLocalDataSize() const {
     return 0;
   }
@@ -309,88 +305,70 @@
   }
 };
 
-
-struct DefaultTypeSpecLocInfo {
-  SourceLocation StartLoc;
-};
-
-/// \brief The default wrapper for type-spec types that are not handled by
-/// another specific wrapper.
-class DefaultTypeSpecLoc : public ConcreteTypeLoc<TypeSpecLoc,
-                                                  DefaultTypeSpecLoc,
-                                                  Type,
-                                                  DefaultTypeSpecLocInfo> {
+/// A metaprogramming class designed for concrete subtypes of abstract
+/// types where all subtypes share equivalently-structured source
+/// information.  See the note on ConcreteTypeLoc.
+template <class Base, class Derived, class TypeClass>
+class InheritingConcreteTypeLoc : public Base {
 public:
-  SourceLocation getStartLoc() const {
-    return getLocalData()->StartLoc;
+  static bool classof(const TypeLoc *TL) {
+    return Derived::classofType(TL->getTypePtr());
   }
-  void setStartLoc(SourceLocation Loc) {
-    getLocalData()->StartLoc = Loc;
+  static bool classof(const UnqualTypeLoc *TL) {
+    return Derived::classofType(TL->getTypePtr());
   }
-  SourceRange getSourceRange() const {
-    return SourceRange(getStartLoc(), getStartLoc());
+  static bool classof(const Derived *TL) {
+    return true;
   }
 
-  void initializeLocal(SourceLocation Loc) {
-    setStartLoc(Loc);
+  TypeClass *getTypePtr() const {
+    return cast<TypeClass>(Base::getTypePtr());
   }
-
-  static bool classofType(const Type *T);
 };
 
-
-struct TypedefLocInfo {
+struct TypeSpecLocInfo {
   SourceLocation NameLoc;
 };
 
-/// \brief Wrapper for source info for typedefs.
-class TypedefLoc : public ConcreteTypeLoc<TypeSpecLoc,TypedefLoc,
-                                          TypedefType,TypedefLocInfo> {
+/// \brief A reasonable base class for TypeLocs that correspond to
+/// types that are written as a type-specifier.
+template <class Derived, class TypeClass, class LocalData = TypeSpecLocInfo>
+class TypeSpecTypeLoc
+  : public ConcreteTypeLoc<UnqualTypeLoc, Derived, TypeClass, LocalData> {
 public:
   SourceLocation getNameLoc() const {
-    return getLocalData()->NameLoc;
+    return this->getLocalData()->NameLoc;
   }
   void setNameLoc(SourceLocation Loc) {
-    getLocalData()->NameLoc = Loc;
+    this->getLocalData()->NameLoc = Loc;
   }
   SourceRange getSourceRange() const {
     return SourceRange(getNameLoc(), getNameLoc());
   }
-
   void initializeLocal(SourceLocation Loc) {
     setNameLoc(Loc);
   }
+};
 
+/// \brief Wrapper for source info for typedefs.
+class TypedefTypeLoc : public TypeSpecTypeLoc<TypedefTypeLoc,TypedefType> {
+public:
   TypedefDecl *getTypedefDecl() const {
     return getTypePtr()->getDecl();
   }
 };
 
 
-struct ObjCInterfaceLocInfo {
-  SourceLocation NameLoc;
+/// \brief Wrapper for source info for builtin types.
+class BuiltinTypeLoc : public TypeSpecTypeLoc<BuiltinTypeLoc,
+                                              BuiltinType> {
 };
 
+
 /// \brief Wrapper for source info for ObjC interfaces.
-class ObjCInterfaceLoc : public ConcreteTypeLoc<TypeSpecLoc,
-                                                ObjCInterfaceLoc,
-                                                ObjCInterfaceType,
-                                                ObjCInterfaceLocInfo> {
+class ObjCInterfaceTypeLoc : public TypeSpecTypeLoc<ObjCInterfaceTypeLoc,
+                                                    ObjCInterfaceType> {
 public:
-  SourceLocation getNameLoc() const {
-    return getLocalData()->NameLoc;
-  }
-  void setNameLoc(SourceLocation Loc) {
-    getLocalData()->NameLoc = Loc;
-  }
-  SourceRange getSourceRange() const {
-    return SourceRange(getNameLoc(), getNameLoc());
-  }
-
-  void initializeLocal(SourceLocation Loc) {
-    setNameLoc(Loc);
-  }
-
   ObjCInterfaceDecl *getIFaceDecl() const {
     return getTypePtr()->getDecl();
   }
@@ -402,10 +380,11 @@
 };
 
 /// \brief Wrapper for source info for ObjC protocol lists.
-class ObjCProtocolListLoc : public ConcreteTypeLoc<TypeSpecLoc,
-                                                   ObjCProtocolListLoc,
-                                                   ObjCProtocolListType,
-                                                   ObjCProtocolListLocInfo> {
+class ObjCProtocolListTypeLoc
+  : public ConcreteTypeLoc<UnqualTypeLoc,
+                           ObjCProtocolListTypeLoc,
+                           ObjCProtocolListType,
+                           ObjCProtocolListLocInfo> {
   // SourceLocations are stored after Info, one for each Protocol.
   SourceLocation *getProtocolLocArray() const {
     return (SourceLocation*) getExtraLocalData();
@@ -469,155 +448,119 @@
 };
 
 
-struct PointerLocInfo {
+
+struct PointerLikeLocInfo {
   SourceLocation StarLoc;
 };
 
-/// \brief Wrapper for source info for pointers.
-class PointerLoc : public ConcreteTypeLoc<DeclaratorLoc,
-                                          PointerLoc,
-                                          PointerType,
-                                          PointerLocInfo> {
-public:
-  SourceLocation getStarLoc() const {
-    return getLocalData()->StarLoc;
+/// A base class for 
+template <class Derived, class TypeClass, class LocalData = PointerLikeLocInfo>
+class PointerLikeTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc, Derived,
+                                                  TypeClass, LocalData> {
+protected:
+  SourceLocation getSigilLoc() const {
+    return this->getLocalData()->StarLoc;
   }
-  void setStarLoc(SourceLocation Loc) {
-    getLocalData()->StarLoc = Loc;
+  void setSigilLoc(SourceLocation Loc) {
+    this->getLocalData()->StarLoc = Loc;
   }
 
+public:  
   TypeLoc getPointeeLoc() const {
-    return getInnerTypeLoc();
-  }
-
-  /// \brief Find the TypeSpecLoc that is part of this PointerLoc.
-  TypeSpecLoc getTypeSpecLoc() const {
-    return getPointeeLoc().getTypeSpecLoc();
+    return this->getInnerTypeLoc();
   }
 
   SourceRange getSourceRange() const {
-    return SourceRange(getStarLoc(), getStarLoc());
+    return SourceRange(getSigilLoc(), getSigilLoc());
   }
 
   void initializeLocal(SourceLocation Loc) {
-    setStarLoc(Loc);
+    setSigilLoc(Loc);
   }
 
-  QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
+  QualType getInnerType() const {
+    return this->getTypePtr()->getPointeeType();
+  }
 };
 
 
-struct BlockPointerLocInfo {
-  SourceLocation CaretLoc;
+/// \brief Wrapper for source info for pointers.
+class PointerTypeLoc : public PointerLikeTypeLoc<PointerTypeLoc,
+                                                 PointerType> {
+public:
+  SourceLocation getStarLoc() const {
+    return getSigilLoc();
+  }
+  void setStarLoc(SourceLocation Loc) {
+    setSigilLoc(Loc);
+  }
 };
 
+
 /// \brief Wrapper for source info for block pointers.
-class BlockPointerLoc : public ConcreteTypeLoc<DeclaratorLoc,
-                                               BlockPointerLoc,
-                                               BlockPointerType,
-                                               BlockPointerLocInfo> {
+class BlockPointerTypeLoc : public PointerLikeTypeLoc<BlockPointerTypeLoc,
+                                                      BlockPointerType> {
 public:
   SourceLocation getCaretLoc() const {
-    return getLocalData()->CaretLoc;
+    return getSigilLoc();
   }
   void setCaretLoc(SourceLocation Loc) {
-    getLocalData()->CaretLoc = Loc;
+    setSigilLoc(Loc);
   }
-
-  TypeLoc getPointeeLoc() const {
-    return getInnerTypeLoc();
-  }
-
-  /// \brief Find the TypeSpecLoc that is part of this BlockPointerLoc.
-  TypeSpecLoc getTypeSpecLoc() const {
-    return getPointeeLoc().getTypeSpecLoc();
-  }
-
-  SourceRange getSourceRange() const {
-    return SourceRange(getCaretLoc(), getCaretLoc());
-  }
-
-  void initializeLocal(SourceLocation Loc) {
-    setCaretLoc(Loc);
-  }
-
-  QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
 };
 
 
-struct MemberPointerLocInfo {
-  SourceLocation StarLoc;
-};
-
 /// \brief Wrapper for source info for member pointers.
-class MemberPointerLoc : public ConcreteTypeLoc<DeclaratorLoc,
-                                                MemberPointerLoc,
-                                                MemberPointerType,
-                                                MemberPointerLocInfo> {
+class MemberPointerTypeLoc : public PointerLikeTypeLoc<MemberPointerTypeLoc,
+                                                       MemberPointerType> {
 public:
   SourceLocation getStarLoc() const {
-    return getLocalData()->StarLoc;
+    return getSigilLoc();
   }
   void setStarLoc(SourceLocation Loc) {
-    getLocalData()->StarLoc = Loc;
-  }
-
-  TypeLoc getPointeeLoc() const {
-    return getInnerTypeLoc();
-  }
-
-  /// \brief Find the TypeSpecLoc that is part of this MemberPointerLoc.
-  TypeSpecLoc getTypeSpecLoc() const {
-    return getPointeeLoc().getTypeSpecLoc();
-  }
-
-  SourceRange getSourceRange() const {
-    return SourceRange(getStarLoc(), getStarLoc());
-  }
-
-  void initializeLocal(SourceLocation Loc) {
-    setStarLoc(Loc);
+    setSigilLoc(Loc);
   }
-
-  QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
 };
 
 
-struct ReferenceLocInfo {
-  SourceLocation AmpLoc;
+class ReferenceTypeLoc : public PointerLikeTypeLoc<ReferenceTypeLoc,
+                                                   ReferenceType> {
 };
 
-/// \brief Wrapper for source info for references.
-class ReferenceLoc : public ConcreteTypeLoc<DeclaratorLoc,
-                                            ReferenceLoc,
-                                            ReferenceType,
-                                            ReferenceLocInfo> {
+class LValueReferenceTypeLoc : public PointerLikeTypeLoc<LValueReferenceTypeLoc,
+                                                         LValueReferenceType> {
 public:
   SourceLocation getAmpLoc() const {
-    return getLocalData()->AmpLoc;
+    return getSigilLoc();
   }
   void setAmpLoc(SourceLocation Loc) {
-    getLocalData()->AmpLoc = Loc;
+    setSigilLoc(Loc);
   }
+};
 
-  TypeLoc getPointeeLoc() const {
-    return TypeLoc(getTypePtr()->getPointeeType(), getNonLocalData());
+class RValueReferenceTypeLoc : public PointerLikeTypeLoc<RValueReferenceTypeLoc,
+                                                         RValueReferenceType> {
+public:
+  SourceLocation getAmpAmpLoc() const {
+    return getSigilLoc();
   }
-
-  /// \brief Find the TypeSpecLoc that is part of this ReferenceLoc.
-  TypeSpecLoc getTypeSpecLoc() const {
-    return getPointeeLoc().getTypeSpecLoc();
+  void setAmpAmpLoc(SourceLocation Loc) {
+    setSigilLoc(Loc);
   }
+};
 
-  SourceRange getSourceRange() const {
-    return SourceRange(getAmpLoc(), getAmpLoc());
+/// Wraps an ObjCPointerType with source location information.  Note
+/// that not all ObjCPointerTypes actually have a star location.
+class ObjCObjectPointerTypeLoc :
+    public PointerLikeTypeLoc<ObjCObjectPointerTypeLoc,
+                              ObjCObjectPointerType> {
+public:
+  SourceLocation getStarLoc() const {
+    return getSigilLoc();
   }
-
-  void initializeLocal(SourceLocation Loc) {
-    setAmpLoc(Loc);
+  void setStarLoc(SourceLocation Loc) {
+    setSigilLoc(Loc);
   }
-
-  QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
 };
 
 
@@ -626,10 +569,10 @@
 };
 
 /// \brief Wrapper for source info for functions.
-class FunctionLoc : public ConcreteTypeLoc<DeclaratorLoc,
-                                           FunctionLoc,
-                                           FunctionType,
-                                           FunctionLocInfo> {
+class FunctionTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
+                                               FunctionTypeLoc,
+                                               FunctionType,
+                                               FunctionLocInfo> {
   // ParmVarDecls* are stored after Info, one for each argument.
   ParmVarDecl **getParmArray() const {
     return (ParmVarDecl**) getExtraLocalData();
@@ -664,10 +607,6 @@
     return getInnerTypeLoc();
   }
 
-  /// \brief Find the TypeSpecLoc that is part of this FunctionLoc.
-  TypeSpecLoc getTypeSpecLoc() const {
-    return getResultLoc().getTypeSpecLoc();
-  }
   SourceRange getSourceRange() const {
     return SourceRange(getLParenLoc(), getRParenLoc());
   }
@@ -688,6 +627,18 @@
   QualType getInnerType() const { return getTypePtr()->getResultType(); }
 };
 
+class FunctionProtoTypeLoc :
+    public InheritingConcreteTypeLoc<FunctionTypeLoc,
+                                     FunctionProtoTypeLoc,
+                                     FunctionProtoType> {
+};
+
+class FunctionNoProtoTypeLoc :
+    public InheritingConcreteTypeLoc<FunctionTypeLoc,
+                                     FunctionNoProtoTypeLoc,
+                                     FunctionNoProtoType> {
+};
+
 
 struct ArrayLocInfo {
   SourceLocation LBracketLoc, RBracketLoc;
@@ -695,10 +646,10 @@
 };
 
 /// \brief Wrapper for source info for arrays.
-class ArrayLoc : public ConcreteTypeLoc<DeclaratorLoc,
-                                        ArrayLoc,
-                                        ArrayType,
-                                        ArrayLocInfo> {
+class ArrayTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
+                                            ArrayTypeLoc,
+                                            ArrayType,
+                                            ArrayLocInfo> {
 public:
   SourceLocation getLBracketLoc() const {
     return getLocalData()->LBracketLoc;
@@ -725,10 +676,6 @@
     return getInnerTypeLoc();
   }
 
-  /// \brief Find the TypeSpecLoc that is part of this ArrayLoc.
-  TypeSpecLoc getTypeSpecLoc() const {
-    return getElementLoc().getTypeSpecLoc();
-  }
   SourceRange getSourceRange() const {
     return SourceRange(getLBracketLoc(), getRBracketLoc());
   }
@@ -742,6 +689,100 @@
   QualType getInnerType() const { return getTypePtr()->getElementType(); }
 };
 
+class ConstantArrayTypeLoc :
+    public InheritingConcreteTypeLoc<ArrayTypeLoc,
+                                     ConstantArrayTypeLoc,
+                                     ConstantArrayType> {
+};
+
+class IncompleteArrayTypeLoc :
+    public InheritingConcreteTypeLoc<ArrayTypeLoc,
+                                     IncompleteArrayTypeLoc,
+                                     IncompleteArrayType> {
+};
+
+class DependentSizedArrayTypeLoc :
+    public InheritingConcreteTypeLoc<ArrayTypeLoc,
+                                     DependentSizedArrayTypeLoc,
+                                     DependentSizedArrayType> {
+
+};
+
+class VariableArrayTypeLoc :
+    public InheritingConcreteTypeLoc<ArrayTypeLoc,
+                                     VariableArrayTypeLoc,
+                                     VariableArrayType> {
+};
+
+
+// None of these types have proper implementations yet.
+
+class VectorTypeLoc : public TypeSpecTypeLoc<VectorTypeLoc, VectorType> {
+};
+
+class ExtVectorTypeLoc : public InheritingConcreteTypeLoc<VectorTypeLoc,
+                                                          ExtVectorTypeLoc,
+                                                          ExtVectorType> {
+};
+
+// For some reason, this isn't a subtype of VectorType.
+class DependentSizedExtVectorTypeLoc :
+    public TypeSpecTypeLoc<DependentSizedExtVectorTypeLoc,
+                           DependentSizedExtVectorType> {
+};
+
+class FixedWidthIntTypeLoc : public TypeSpecTypeLoc<FixedWidthIntTypeLoc,
+                                                    FixedWidthIntType> {
+};
+
+class ComplexTypeLoc : public TypeSpecTypeLoc<ComplexTypeLoc,
+                                              ComplexType> {
+};
+
+class TypeOfExprTypeLoc : public TypeSpecTypeLoc<TypeOfExprTypeLoc,
+                                                 TypeOfExprType> {
+};
+
+class TypeOfTypeLoc : public TypeSpecTypeLoc<TypeOfTypeLoc, TypeOfType> {
+};
+
+class DecltypeTypeLoc : public TypeSpecTypeLoc<DecltypeTypeLoc, DecltypeType> {
+};
+
+class TagTypeLoc : public TypeSpecTypeLoc<TagTypeLoc, TagType> {
+};
+
+class RecordTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
+                                                       RecordTypeLoc,
+                                                       RecordType> {
+};
+
+class EnumTypeLoc : public InheritingConcreteTypeLoc<TagTypeLoc,
+                                                     EnumTypeLoc,
+                                                     EnumType> {
+};
+
+class ElaboratedTypeLoc : public TypeSpecTypeLoc<ElaboratedTypeLoc,
+                                                 ElaboratedType> {
+};
+
+class TemplateTypeParmTypeLoc : public TypeSpecTypeLoc<TemplateTypeParmTypeLoc,
+                                                       TemplateTypeParmType> {
+};
+
+class TemplateSpecializationTypeLoc
+  : public TypeSpecTypeLoc<TemplateSpecializationTypeLoc,
+                           TemplateSpecializationType> {
+};
+
+class QualifiedNameTypeLoc : public TypeSpecTypeLoc<QualifiedNameTypeLoc,
+                                                    QualifiedNameType> {
+};
+
+class TypenameTypeLoc : public TypeSpecTypeLoc<TypenameTypeLoc,
+                                               TypenameType> {
+};
+
 }
 
 #endif

Modified: cfe/trunk/include/clang/AST/TypeLocNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLocNodes.def?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/TypeLocNodes.def (original)
+++ cfe/trunk/include/clang/AST/TypeLocNodes.def Sat Oct 17 20:05:36 2009
@@ -7,54 +7,32 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  This file defines the TypeLoc info database. Each node is
-//  enumerated by providing its name (e.g., "PointerLoc" or "ArrayLoc"),
-//  base class (e.g., "TypeSpecLoc" or "DeclaratorLoc"), and the Type subclass
-//  that the TypeLoc is associated with.
+//  This file defines the TypeLoc info database.  Each node is
+//  enumerated by providing its core name (e.g., "Pointer" for "PointerTypeLoc")
+//  and base class (e.g., "DeclaratorLoc").  All nodes except QualifiedTypeLoc
+//  are associated
 //
-//    TYPELOC(Class, Base) - A TypeLoc subclass.
+//    TYPELOC(Class, Base) - A TypeLoc subclass.  If UNQUAL_TYPELOC is
+//      provided, there will be exactly one of these, Qualified.
 //
 //    UNQUAL_TYPELOC(Class, Base, Type) - An UnqualTypeLoc subclass.
 //
 //    ABSTRACT_TYPELOC(Class) - Refers to TypeSpecLoc and DeclaratorLoc.
 //
-//    TYPESPEC_TYPELOC(Class, Type) - A TypeLoc referring to a type-spec type.
-//
-//    DECLARATOR_TYPELOC(Class, Type) - A TypeLoc referring to a type part of
-//    a declarator, excluding type-spec types.
-//
 //===----------------------------------------------------------------------===//
 
 #ifndef UNQUAL_TYPELOC
-#  define UNQUAL_TYPELOC(Class, Base, Type) TYPELOC(Class, Base)
+#  define UNQUAL_TYPELOC(Class, Base) TYPELOC(Class, Base)
 #endif
 
 #ifndef ABSTRACT_TYPELOC
-#  define ABSTRACT_TYPELOC(Class) TYPELOC(Class, TypeLoc)
-#endif
-
-#ifndef TYPESPEC_TYPELOC
-#  define TYPESPEC_TYPELOC(Class, Type) UNQUAL_TYPELOC(Class, TypeSpecLoc, Type)
+#  define ABSTRACT_TYPELOC(Class, Base) UNQUAL_TYPELOC(Class, Base)
 #endif
 
-#ifndef DECLARATOR_TYPELOC
-#  define DECLARATOR_TYPELOC(Class, Type) UNQUAL_TYPELOC(Class, DeclaratorLoc, Type)
-#endif
-
-TYPESPEC_TYPELOC(DefaultTypeSpecLoc, Type)
-TYPESPEC_TYPELOC(TypedefLoc, TypedefType)
-TYPESPEC_TYPELOC(ObjCInterfaceLoc, ObjCInterfaceType)
-TYPESPEC_TYPELOC(ObjCProtocolListLoc, ObjCProtocolListType)
-DECLARATOR_TYPELOC(PointerLoc, PointerType)
-DECLARATOR_TYPELOC(BlockPointerLoc, BlockPointerType)
-DECLARATOR_TYPELOC(MemberPointerLoc, MemberPointerType)
-DECLARATOR_TYPELOC(ReferenceLoc, ReferenceType)
-DECLARATOR_TYPELOC(FunctionLoc, FunctionType)
-DECLARATOR_TYPELOC(ArrayLoc, ArrayType)
-ABSTRACT_TYPELOC(DeclaratorLoc)
-ABSTRACT_TYPELOC(TypeSpecLoc)
-TYPELOC(QualifiedLoc, TypeLoc)
-
+TYPELOC(Qualified, TypeLoc)
+#define TYPE(Class, Base) UNQUAL_TYPELOC(Class, Base##Loc)
+#define ABSTRACT_TYPE(Class, Base) ABSTRACT_TYPELOC(Class, Base##Loc)
+#include "clang/AST/TypeNodes.def"
 
 #undef DECLARATOR_TYPELOC
 #undef TYPESPEC_TYPELOC

Modified: cfe/trunk/include/clang/AST/TypeLocVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLocVisitor.h?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/TypeLocVisitor.h (original)
+++ cfe/trunk/include/clang/AST/TypeLocVisitor.h Sat Oct 17 20:05:36 2009
@@ -15,46 +15,38 @@
 
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/TypeVisitor.h"
+#include "llvm/Support/ErrorHandling.h"
 
 namespace clang {
 
-#define DISPATCH(CLASS) \
-  return static_cast<ImplClass*>(this)->Visit ## CLASS(cast<CLASS>(TyLoc))
+#define DISPATCH(CLASSNAME) \
+  return static_cast<ImplClass*>(this)-> \
+    Visit##CLASSNAME(cast<CLASSNAME>(TyLoc))
 
 template<typename ImplClass, typename RetTy=void>
 class TypeLocVisitor {
-  class TypeDispatch : public TypeVisitor<TypeDispatch, RetTy> {
-    ImplClass *Impl;
-    UnqualTypeLoc TyLoc;
-
-  public:
-    TypeDispatch(ImplClass *impl, UnqualTypeLoc &tyLoc) 
-      : Impl(impl), TyLoc(tyLoc) { }
-#define TYPELOC(CLASS, BASE)
-#define ABSTRACT_TYPELOC(CLASS)
-#define UNQUAL_TYPELOC(CLASS, PARENT, TYPE)                       \
-    RetTy Visit##TYPE(TYPE *) {                                   \
-      return Impl->Visit##CLASS(reinterpret_cast<CLASS&>(TyLoc)); \
-    }
-#include "clang/AST/TypeLocNodes.def"
-  };
-
 public:
   RetTy Visit(TypeLoc TyLoc) {
-    if (isa<QualifiedLoc>(TyLoc))
-      return static_cast<ImplClass*>(this)->
-        VisitQualifiedLoc(cast<QualifiedLoc>(TyLoc));
-
-    return Visit(cast<UnqualTypeLoc>(TyLoc));
+    switch (TyLoc.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+    case TypeLoc::CLASS: DISPATCH(CLASS##TypeLoc);
+#include "clang/AST/TypeLocNodes.def"
+    }
+    llvm::llvm_unreachable("unexpected type loc class!");
   }
 
   RetTy Visit(UnqualTypeLoc TyLoc) {
-    TypeDispatch TD(static_cast<ImplClass*>(this), TyLoc);
-    return TD.Visit(TyLoc.getSourceTypePtr());
+    switch (TyLoc.getTypeLocClass()) {
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+    case TypeLoc::CLASS: DISPATCH(CLASS##TypeLoc);
+#include "clang/AST/TypeLocNodes.def"
+    }
   }
 
 #define TYPELOC(CLASS, PARENT)      \
-  RetTy Visit##CLASS(CLASS TyLoc) { \
+  RetTy Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
     DISPATCH(PARENT);               \
   }
 #include "clang/AST/TypeLocNodes.def"

Modified: cfe/trunk/include/clang/Index/ASTLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/ASTLocation.h?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/ASTLocation.h (original)
+++ cfe/trunk/include/clang/Index/ASTLocation.h Sat Oct 17 20:05:36 2009
@@ -91,7 +91,7 @@
   ASTLocation(const Decl *parentDecl, TypeLoc tyLoc)
     : ParentDecl(const_cast<Decl*>(parentDecl), N_Type) {
     if (tyLoc) {
-      Ty.TyPtr = tyLoc.getSourceType().getAsOpaquePtr();
+      Ty.TyPtr = tyLoc.getType().getAsOpaquePtr();
       Ty.Data = tyLoc.getOpaqueData();
     } else
       ParentDecl.setPointer(0);

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sat Oct 17 20:05:36 2009
@@ -336,8 +336,15 @@
 //===----------------------------------------------------------------------===//
 
 SourceLocation DeclaratorDecl::getTypeSpecStartLoc() const {
-  if (DeclInfo)
-    return DeclInfo->getTypeLoc().getTypeSpecRange().getBegin();
+  if (DeclInfo) {
+    TypeLoc TL = DeclInfo->getTypeLoc();
+    while (true) {
+      TypeLoc NextTL = TL.getNextTypeLoc();
+      if (!NextTL)
+        return TL.getSourceRange().getBegin();
+      TL = NextTL;
+    }
+  }
   return SourceLocation();
 }
 

Modified: cfe/trunk/lib/AST/TypeLoc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/AST/TypeLoc.cpp (original)
+++ cfe/trunk/lib/AST/TypeLoc.cpp Sat Oct 17 20:05:36 2009
@@ -20,55 +20,32 @@
 //===----------------------------------------------------------------------===//
 
 namespace {
-
-/// \brief Return the source range for the visited TypeSpecLoc.
-class TypeLocRanger : public TypeLocVisitor<TypeLocRanger, SourceRange> {
-public:
-#define ABSTRACT_TYPELOC(CLASS)
+  class TypeLocRanger : public TypeLocVisitor<TypeLocRanger, SourceRange> {
+  public:
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
 #define TYPELOC(CLASS, PARENT) \
-    SourceRange Visit##CLASS(CLASS TyLoc) { return TyLoc.getSourceRange(); }
+    SourceRange Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
+      return TyLoc.getSourceRange(); \
+    }
 #include "clang/AST/TypeLocNodes.def"
-
-  SourceRange VisitTypeLoc(TypeLoc TyLoc) {
-    assert(0 && "A typeloc wrapper was not handled!");
-    return SourceRange();
-  }
-};
-
+  };
 }
 
-SourceRange TypeLoc::getSourceRange() const {
-  if (isNull())
-    return SourceRange();
-  return TypeLocRanger().Visit(*this);
-}
-
-/// \brief Find the TypeSpecLoc that is part of this TypeLoc.
-TypeSpecLoc TypeLoc::getTypeSpecLoc() const {
-  if (isNull())
-    return TypeSpecLoc();
-  UnqualTypeLoc Cur = getUnqualifiedLoc();
-  if (const DeclaratorLoc *DL = dyn_cast<DeclaratorLoc>(&Cur))
-    return DL->getTypeSpecLoc();
-  return cast<TypeSpecLoc>(Cur);
+SourceRange TypeLoc::getSourceRangeImpl(TypeLoc TL) {
+  if (TL.isNull()) return SourceRange();
+  return TypeLocRanger().Visit(TL);
 }
 
 namespace {
-
-/// \brief Report the full source info data size for the visited TypeLoc.
-class TypeSizer : public TypeLocVisitor<TypeSizer, unsigned> {
-public:
-#define ABSTRACT_TYPELOC(CLASS)
+  class TypeSizer : public TypeLocVisitor<TypeSizer, unsigned> {
+  public:
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
 #define TYPELOC(CLASS, PARENT) \
-    unsigned Visit##CLASS(CLASS TyLoc) { return TyLoc.getFullDataSize(); }
+    unsigned Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
+      return TyLoc.getFullDataSize(); \
+    }
 #include "clang/AST/TypeLocNodes.def"
-
-  unsigned VisitTypeLoc(TypeLoc TyLoc) {
-    assert(0 && "A type loc wrapper was not handled!");
-    return 0;
-  }
-};
-
+  };
 }
 
 /// \brief Returns the size of the type source info data block.
@@ -78,153 +55,42 @@
 }
 
 namespace {
-
-/// \brief Return the "next" TypeLoc for the visited TypeLoc, e.g for "int*" the
-/// TypeLoc is a PointerLoc and next TypeLoc is for "int".
-class NextLoc : public TypeLocVisitor<NextLoc, TypeLoc> {
-public:
-#define TYPELOC(CLASS, PARENT)
-#define DECLARATOR_TYPELOC(CLASS, TYPE) \
-  TypeLoc Visit##CLASS(CLASS TyLoc);
+  class NextLoc : public TypeLocVisitor<NextLoc, TypeLoc> {
+  public:
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
+#define TYPELOC(CLASS, PARENT) \
+    TypeLoc Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
+      return TyLoc.getNextTypeLoc(); \
+    }
 #include "clang/AST/TypeLocNodes.def"
-
-  TypeLoc VisitTypeSpecLoc(TypeLoc TyLoc) { return TypeLoc(); }
-  TypeLoc VisitObjCProtocolListLoc(ObjCProtocolListLoc TL);
-  TypeLoc VisitQualifiedLoc(QualifiedLoc TyLoc) {
-    return TyLoc.getNextTypeLoc();
-  }
-
-  TypeLoc VisitTypeLoc(TypeLoc TyLoc) {
-    assert(0 && "A declarator loc wrapper was not handled!");
-    return TypeLoc();
-  }
-};
-
-}
-
-TypeLoc NextLoc::VisitObjCProtocolListLoc(ObjCProtocolListLoc TL) {
-  return TL.getNextTypeLoc();
-}
-
-TypeLoc NextLoc::VisitPointerLoc(PointerLoc TL) {
-  return TL.getNextTypeLoc();
-}
-TypeLoc NextLoc::VisitMemberPointerLoc(MemberPointerLoc TL) {
-  return TL.getNextTypeLoc();
-}
-TypeLoc NextLoc::VisitBlockPointerLoc(BlockPointerLoc TL) {
-  return TL.getNextTypeLoc();
-}
-TypeLoc NextLoc::VisitReferenceLoc(ReferenceLoc TL) {
-  return TL.getNextTypeLoc();
-}
-TypeLoc NextLoc::VisitFunctionLoc(FunctionLoc TL) {
-  return TL.getNextTypeLoc();
-}
-TypeLoc NextLoc::VisitArrayLoc(ArrayLoc TL) {
-  return TL.getNextTypeLoc();
+  };
 }
 
 /// \brief Get the next TypeLoc pointed by this TypeLoc, e.g for "int*" the
 /// TypeLoc is a PointerLoc and next TypeLoc is for "int".
-TypeLoc TypeLoc::getNextTypeLoc() const {
-  return NextLoc().Visit(*this);
+TypeLoc TypeLoc::getNextTypeLocImpl(TypeLoc TL) {
+  return NextLoc().Visit(TL);
 }
 
 namespace {
-struct TypeLocInitializer : public TypeLocVisitor<TypeLocInitializer> {
-  SourceLocation Loc;
-  TypeLocInitializer(SourceLocation Loc) : Loc(Loc) {}
+  struct TypeLocInitializer : public TypeLocVisitor<TypeLocInitializer> {
+    SourceLocation Loc;
+    TypeLocInitializer(SourceLocation Loc) : Loc(Loc) {}
   
-#define ABSTRACT_TYPELOC(CLASS)
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
 #define TYPELOC(CLASS, PARENT) \
-  void Visit##CLASS(CLASS TyLoc) { TyLoc.initializeLocal(Loc); }
+    void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc) { \
+      TyLoc.initializeLocal(Loc); \
+    }
 #include "clang/AST/TypeLocNodes.def"
-};
+  };
 }
 
+/// \brief Initializes a type location, and all of its children
+/// recursively, as if the entire tree had been written in the
+/// given location.
 void TypeLoc::initializeImpl(TypeLoc TL, SourceLocation Loc) {
   do {
     TypeLocInitializer(Loc).Visit(TL);
   } while (TL = TL.getNextTypeLoc());
 }
-
-//===----------------------------------------------------------------------===//
-// TypeSpecLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-class TypeSpecChecker : public TypeLocVisitor<TypeSpecChecker, bool> {
-public:
-  bool VisitTypeSpecLoc(TypeSpecLoc TyLoc) { return true; }
-};
-
-}
-
-bool TypeSpecLoc::classof(const UnqualTypeLoc *TL) {
-  return TypeSpecChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// DeclaratorLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-/// \brief Return the TypeSpecLoc for the visited DeclaratorLoc.
-class TypeSpecGetter : public TypeLocVisitor<TypeSpecGetter, TypeSpecLoc> {
-public:
-#define TYPELOC(CLASS, PARENT)
-#define DECLARATOR_TYPELOC(CLASS, TYPE) \
-    TypeSpecLoc Visit##CLASS(CLASS TyLoc) { return TyLoc.getTypeSpecLoc(); }
-#include "clang/AST/TypeLocNodes.def"
-
-  TypeSpecLoc VisitTypeLoc(TypeLoc TyLoc) {
-    assert(0 && "A declarator loc wrapper was not handled!");
-    return TypeSpecLoc();
-  }
-
-  TypeSpecLoc VisitQualifiedLoc(QualifiedLoc TyLoc) {
-    return Visit(TyLoc.getUnqualifiedLoc());
-  }
-};
-
-}
-
-/// \brief Find the TypeSpecLoc that is part of this DeclaratorLoc.
-TypeSpecLoc DeclaratorLoc::getTypeSpecLoc() const {
-  return TypeSpecGetter().Visit(*this);
-}
-
-namespace {
-
-class DeclaratorLocChecker : public TypeLocVisitor<DeclaratorLocChecker, bool> {
-public:
-  bool VisitDeclaratorLoc(DeclaratorLoc TyLoc) { return true; }
-};
-
-}
-
-bool DeclaratorLoc::classof(const UnqualTypeLoc *TL) {
-  return DeclaratorLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// DefaultTypeSpecLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class DefaultTypeSpecLocChecker :
-                        public TypeLocVisitor<DefaultTypeSpecLocChecker, bool> {
-public:
-  bool VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) { return true; }
-};
-
-}
-
-bool DefaultTypeSpecLoc::classofType(const Type *Ty) {
-  return
-    DefaultTypeSpecLocChecker().Visit(UnqualTypeLoc(const_cast<Type*>(Ty), 0));
-}
- 

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Sat Oct 17 20:05:36 2009
@@ -1985,61 +1985,136 @@
                 unsigned &Idx)
     : Reader(Reader), Record(Record), Idx(Idx) { }
 
-#define ABSTRACT_TYPELOC(CLASS)
+  // We want compile-time assurance that we've enumerated all of
+  // these, so unfortunately we have to declare them first, then
+  // define them out-of-line.
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
 #define TYPELOC(CLASS, PARENT) \
-    void Visit##CLASS(CLASS TyLoc);
+  void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
 #include "clang/AST/TypeLocNodes.def"
 
-  void VisitTypeLoc(TypeLoc TyLoc) {
-    assert(0 && "A type loc wrapper was not handled!");
-  }
+  void VisitFunctionTypeLoc(FunctionTypeLoc);
+  void VisitArrayTypeLoc(ArrayTypeLoc);
 };
 
 }
 
-void TypeLocReader::VisitQualifiedLoc(QualifiedLoc TyLoc) {
+void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
   // nothing to do
 }
-void TypeLocReader::VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) {
-  TyLoc.setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitFixedWidthIntTypeLoc(FixedWidthIntTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) {
+  TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
-void TypeLocReader::VisitTypedefLoc(TypedefLoc TyLoc) {
-  TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
+  TL.setCaretLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
-void TypeLocReader::VisitObjCInterfaceLoc(ObjCInterfaceLoc TyLoc) {
-  TyLoc.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
+  TL.setAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
-void TypeLocReader::VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) {
-  TyLoc.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  TyLoc.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  for (unsigned i = 0, e = TyLoc.getNumProtocols(); i != e; ++i)
-    TyLoc.setProtocolLoc(i, SourceLocation::getFromRawEncoding(Record[Idx++]));
-}
-void TypeLocReader::VisitPointerLoc(PointerLoc TyLoc) {
-  TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-}
-void TypeLocReader::VisitBlockPointerLoc(BlockPointerLoc TyLoc) {
-  TyLoc.setCaretLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-}
-void TypeLocReader::VisitMemberPointerLoc(MemberPointerLoc TyLoc) {
-  TyLoc.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-}
-void TypeLocReader::VisitReferenceLoc(ReferenceLoc TyLoc) {
-  TyLoc.setAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-}
-void TypeLocReader::VisitFunctionLoc(FunctionLoc TyLoc) {
-  TyLoc.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  TyLoc.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  for (unsigned i = 0, e = TyLoc.getNumArgs(); i != e; ++i)
-    TyLoc.setArg(i, cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
-}
-void TypeLocReader::VisitArrayLoc(ArrayLoc TyLoc) {
-  TyLoc.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
-  TyLoc.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
+  TL.setAmpAmpLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
+  TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) {
+  TL.setLBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  TL.setRBracketLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   if (Record[Idx++])
-    TyLoc.setSizeExpr(Reader.ReadDeclExpr());
+    TL.setSizeExpr(Reader.ReadDeclExpr());
   else
-    TyLoc.setSizeExpr(0);
+    TL.setSizeExpr(0);
+}
+void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
+  VisitArrayTypeLoc(TL);
+}
+void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
+  VisitArrayTypeLoc(TL);
+}
+void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
+  VisitArrayTypeLoc(TL);
+}
+void TypeLocReader::VisitDependentSizedArrayTypeLoc(
+                                            DependentSizedArrayTypeLoc TL) {
+  VisitArrayTypeLoc(TL);
+}
+void TypeLocReader::VisitDependentSizedExtVectorTypeLoc(
+                                        DependentSizedExtVectorTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
+  TL.setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  TL.setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
+    TL.setArg(i, cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
+  }
+}
+void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
+  VisitFunctionTypeLoc(TL);
+}
+void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
+  VisitFunctionTypeLoc(TL);
+}
+void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitTemplateSpecializationTypeLoc(
+                                           TemplateSpecializationTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitQualifiedNameTypeLoc(QualifiedNameTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitTypenameTypeLoc(TypenameTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
+  TL.setNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
+  TL.setStarLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+}
+void TypeLocReader::VisitObjCProtocolListTypeLoc(ObjCProtocolListTypeLoc TL) {
+  TL.setLAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  TL.setRAngleLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
+    TL.setProtocolLoc(i, SourceLocation::getFromRawEncoding(Record[Idx++]));
 }
 
 DeclaratorInfo *PCHReader::GetDeclaratorInfo(const RecordData &Record,

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Sat Oct 17 20:05:36 2009
@@ -259,60 +259,131 @@
   TypeLocWriter(PCHWriter &Writer, PCHWriter::RecordData &Record)
     : Writer(Writer), Record(Record) { }
 
-#define ABSTRACT_TYPELOC(CLASS)
+#define ABSTRACT_TYPELOC(CLASS, PARENT)
 #define TYPELOC(CLASS, PARENT) \
-    void Visit##CLASS(CLASS TyLoc);
+    void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc);
 #include "clang/AST/TypeLocNodes.def"
 
-  void VisitTypeLoc(TypeLoc TyLoc) {
-    assert(0 && "A type loc wrapper was not handled!");
-  }
+  void VisitArrayTypeLoc(ArrayTypeLoc TyLoc);
+  void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc);
 };
 
 }
 
-void TypeLocWriter::VisitQualifiedLoc(QualifiedLoc TyLoc) {
-  // nothing to do here
+void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
+  // nothing to do
+}
+void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitFixedWidthIntTypeLoc(FixedWidthIntTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getStarLoc(), Record);
+}
+void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getCaretLoc(), Record);
+}
+void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getAmpLoc(), Record);
+}
+void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getAmpAmpLoc(), Record);
+}
+void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getStarLoc(), Record);
+}
+void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getLBracketLoc(), Record);
+  Writer.AddSourceLocation(TL.getRBracketLoc(), Record);
+  Record.push_back(TL.getSizeExpr() ? 1 : 0);
+  if (TL.getSizeExpr())
+    Writer.AddStmt(TL.getSizeExpr());
+}
+void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) {
+  VisitArrayTypeLoc(TL);
+}
+void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) {
+  VisitArrayTypeLoc(TL);
+}
+void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) {
+  VisitArrayTypeLoc(TL);
+}
+void TypeLocWriter::VisitDependentSizedArrayTypeLoc(
+                                            DependentSizedArrayTypeLoc TL) {
+  VisitArrayTypeLoc(TL);
+}
+void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc(
+                                        DependentSizedExtVectorTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getLParenLoc(), Record);
+  Writer.AddSourceLocation(TL.getRParenLoc(), Record);
+  for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i)
+    Writer.AddDeclRef(TL.getArg(i), Record);
+}
+void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) {
+  VisitFunctionTypeLoc(TL);
+}
+void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) {
+  VisitFunctionTypeLoc(TL);
+}
+void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitTemplateSpecializationTypeLoc(
+                                           TemplateSpecializationTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitQualifiedNameTypeLoc(QualifiedNameTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
+}
+void TypeLocWriter::VisitTypenameTypeLoc(TypenameTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
 }
-void TypeLocWriter::VisitDefaultTypeSpecLoc(DefaultTypeSpecLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getStartLoc(), Record);
+void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getNameLoc(), Record);
 }
-void TypeLocWriter::VisitTypedefLoc(TypedefLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getNameLoc(), Record);
+void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getStarLoc(), Record);
 }
-void TypeLocWriter::VisitObjCInterfaceLoc(ObjCInterfaceLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getNameLoc(), Record);
-}
-void TypeLocWriter::VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getLAngleLoc(), Record);
-  Writer.AddSourceLocation(TyLoc.getRAngleLoc(), Record);
-  for (unsigned i = 0, e = TyLoc.getNumProtocols(); i != e; ++i)
-    Writer.AddSourceLocation(TyLoc.getProtocolLoc(i), Record);
-}
-void TypeLocWriter::VisitPointerLoc(PointerLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getStarLoc(), Record);
-}
-void TypeLocWriter::VisitBlockPointerLoc(BlockPointerLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getCaretLoc(), Record);
-}
-void TypeLocWriter::VisitMemberPointerLoc(MemberPointerLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getStarLoc(), Record);
-}
-void TypeLocWriter::VisitReferenceLoc(ReferenceLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getAmpLoc(), Record);
-}
-void TypeLocWriter::VisitFunctionLoc(FunctionLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getLParenLoc(), Record);
-  Writer.AddSourceLocation(TyLoc.getRParenLoc(), Record);
-  for (unsigned i = 0, e = TyLoc.getNumArgs(); i != e; ++i)
-    Writer.AddDeclRef(TyLoc.getArg(i), Record);
-}
-void TypeLocWriter::VisitArrayLoc(ArrayLoc TyLoc) {
-  Writer.AddSourceLocation(TyLoc.getLBracketLoc(), Record);
-  Writer.AddSourceLocation(TyLoc.getRBracketLoc(), Record);
-  Record.push_back(TyLoc.getSizeExpr() ? 1 : 0);
-  if (TyLoc.getSizeExpr())
-    Writer.AddStmt(TyLoc.getSizeExpr());
+void TypeLocWriter::VisitObjCProtocolListTypeLoc(ObjCProtocolListTypeLoc TL) {
+  Writer.AddSourceLocation(TL.getLAngleLoc(), Record);
+  Writer.AddSourceLocation(TL.getRAngleLoc(), Record);
+  for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i)
+    Writer.AddSourceLocation(TL.getProtocolLoc(i), Record);
 }
 
 //===----------------------------------------------------------------------===//
@@ -2032,7 +2103,7 @@
     return;
   }
 
-  AddTypeRef(DInfo->getTypeLoc().getSourceType(), Record);
+  AddTypeRef(DInfo->getType(), Record);
   TypeLocWriter TLW(*this, Record);
   for (TypeLoc TL = DInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
     TLW.Visit(TL);  

Modified: cfe/trunk/lib/Index/ASTLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ASTLocation.cpp?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/Index/ASTLocation.cpp (original)
+++ cfe/trunk/lib/Index/ASTLocation.cpp Sat Oct 17 20:05:36 2009
@@ -101,7 +101,7 @@
     break;
     
   case N_Type: {
-    QualType T = AsTypeLoc().getSourceType();
+    QualType T = AsTypeLoc().getType();
     OS << "[Type: " << T->getTypeClassName() << " " << T.getAsString();
   }
   }

Modified: cfe/trunk/lib/Index/ASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ASTVisitor.h?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/Index/ASTVisitor.h (original)
+++ cfe/trunk/lib/Index/ASTVisitor.h Sat Oct 17 20:05:36 2009
@@ -123,14 +123,14 @@
       BaseTypeLocVisitor::Visit(TL);
   }
   
-  void VisitArrayLoc(ArrayLoc TL) {
-    BaseTypeLocVisitor::VisitArrayLoc(TL);
+  void VisitArrayLoc(ArrayTypeLoc TL) {
+    BaseTypeLocVisitor::VisitArrayTypeLoc(TL);
     if (TL.getSizeExpr())
       Visit(TL.getSizeExpr());
   }
   
-  void VisitFunctionLoc(FunctionLoc TL) {
-    BaseTypeLocVisitor::VisitFunctionLoc(TL);
+  void VisitFunctionTypeLoc(FunctionTypeLoc TL) {
+    BaseTypeLocVisitor::VisitFunctionTypeLoc(TL);
     for (unsigned i = 0; i != TL.getNumArgs(); ++i)
       Visit(TL.getArg(i));
   }

Modified: cfe/trunk/lib/Index/DeclReferenceMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/DeclReferenceMap.cpp?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/Index/DeclReferenceMap.cpp (original)
+++ cfe/trunk/lib/Index/DeclReferenceMap.cpp Sat Oct 17 20:05:36 2009
@@ -31,8 +31,8 @@
   void VisitMemberExpr(MemberExpr *Node);
   void VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node);
   
-  void VisitTypedefLoc(TypedefLoc TL);
-  void VisitObjCInterfaceLoc(ObjCInterfaceLoc TL);
+  void VisitTypedefTypeLoc(TypedefTypeLoc TL);
+  void VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL);
 };
 
 } // anonymous namespace
@@ -55,12 +55,12 @@
   Map.insert(std::make_pair(Node->getDecl(), ASTLocation(CurrentDecl, Node)));
 }
 
-void RefMapper::VisitTypedefLoc(TypedefLoc TL) {
+void RefMapper::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
   NamedDecl *ND = TL.getTypedefDecl();
   Map.insert(std::make_pair(ND, ASTLocation(CurrentDecl, ND, TL.getNameLoc())));
 }
 
-void RefMapper::VisitObjCInterfaceLoc(ObjCInterfaceLoc TL) {
+void RefMapper::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
   NamedDecl *ND = TL.getIFaceDecl();
   Map.insert(std::make_pair(ND, ASTLocation(CurrentDecl, ND, TL.getNameLoc())));
 }

Modified: cfe/trunk/lib/Index/ResolveLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ResolveLocation.cpp?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/Index/ResolveLocation.cpp (original)
+++ cfe/trunk/lib/Index/ResolveLocation.cpp Sat Oct 17 20:05:36 2009
@@ -120,11 +120,11 @@
   TypeLocResolver(ASTContext &ctx, SourceLocation loc, Decl *pd)
     : LocResolverBase(ctx, loc), ParentDecl(pd) { }
 
-  ASTLocation VisitTypedefLoc(TypedefLoc TL);
-  ASTLocation VisitFunctionLoc(FunctionLoc TL);
-  ASTLocation VisitArrayLoc(ArrayLoc TL);
-  ASTLocation VisitObjCInterfaceLoc(ObjCInterfaceLoc TL);
-  ASTLocation VisitObjCProtocolListLoc(ObjCProtocolListLoc TL);
+  ASTLocation VisitTypedefTypeLoc(TypedefTypeLoc TL);
+  ASTLocation VisitFunctionTypeLoc(FunctionTypeLoc TL);
+  ASTLocation VisitArrayTypeLoc(ArrayTypeLoc TL);
+  ASTLocation VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL);
+  ASTLocation VisitObjCProtocolListTypeLoc(ObjCProtocolListTypeLoc TL);
   ASTLocation VisitTypeLoc(TypeLoc TL);
 };
 
@@ -349,7 +349,7 @@
   return ASTLocation(D);
 }
 
-ASTLocation TypeLocResolver::VisitTypedefLoc(TypedefLoc TL) {
+ASTLocation TypeLocResolver::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
   assert(ContainsLocation(TL) &&
          "Should visit only after verifying that loc is in range");
   if (ContainsLocation(TL.getNameLoc()))
@@ -357,7 +357,7 @@
   return ASTLocation(ParentDecl, TL);
 }
 
-ASTLocation TypeLocResolver::VisitFunctionLoc(FunctionLoc TL) {
+ASTLocation TypeLocResolver::VisitFunctionTypeLoc(FunctionTypeLoc TL) {
   assert(ContainsLocation(TL) &&
          "Should visit only after verifying that loc is in range");
 
@@ -373,7 +373,7 @@
   return ASTLocation(ParentDecl, TL);
 }
 
-ASTLocation TypeLocResolver::VisitArrayLoc(ArrayLoc TL) {
+ASTLocation TypeLocResolver::VisitArrayTypeLoc(ArrayTypeLoc TL) {
   assert(ContainsLocation(TL) &&
          "Should visit only after verifying that loc is in range");
 
@@ -384,7 +384,7 @@
   return ASTLocation(ParentDecl, TL);
 }
 
-ASTLocation TypeLocResolver::VisitObjCInterfaceLoc(ObjCInterfaceLoc TL) {
+ASTLocation TypeLocResolver::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
   assert(ContainsLocation(TL) &&
          "Should visit only after verifying that loc is in range");
   if (ContainsLocation(TL.getNameLoc()))
@@ -392,7 +392,7 @@
   return ASTLocation(ParentDecl, TL);
 }
 
-ASTLocation TypeLocResolver::VisitObjCProtocolListLoc(ObjCProtocolListLoc TL) {
+ASTLocation TypeLocResolver::VisitObjCProtocolListTypeLoc(ObjCProtocolListTypeLoc TL) {
   assert(ContainsLocation(TL) &&
          "Should visit only after verifying that loc is in range");
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=84386&r1=84385&r2=84386&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat Oct 17 20:05:36 2009
@@ -17,6 +17,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/TypeLoc.h"
+#include "clang/AST/TypeLocVisitor.h"
 #include "clang/AST/Expr.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Parse/DeclSpec.h"
@@ -1298,100 +1299,118 @@
   return T;
 }
 
-static void FillTypeSpecLoc(TypeLoc TSL, const DeclSpec &DS) {
-  if (TSL.isNull()) return;
+namespace {
+  class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> {
+    const DeclSpec &DS;
 
-  if (TypedefLoc *TL = dyn_cast<TypedefLoc>(&TSL)) {
-    TL->setNameLoc(DS.getTypeSpecTypeLoc());
+  public:
+    TypeSpecLocFiller(const DeclSpec &DS) : DS(DS) {}
 
-  } else if (ObjCInterfaceLoc *TL = dyn_cast<ObjCInterfaceLoc>(&TSL)) {
-    TL->setNameLoc(DS.getTypeSpecTypeLoc());
+    void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
+      Visit(TL.getUnqualifiedLoc());
+    }
+    void VisitTypedefTypeLoc(TypedefTypeLoc TL) {
+      TL.setNameLoc(DS.getTypeSpecTypeLoc());
+    }
+    void VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
+      TL.setNameLoc(DS.getTypeSpecTypeLoc());
+    }
+    void VisitObjCProtocolListTypeLoc(ObjCProtocolListTypeLoc TL) {
+      assert(TL.getNumProtocols() == DS.getNumProtocolQualifiers());
+      TL.setLAngleLoc(DS.getProtocolLAngleLoc());
+      TL.setRAngleLoc(DS.getSourceRange().getEnd());
+      for (unsigned i = 0; i != DS.getNumProtocolQualifiers(); ++i)
+        TL.setProtocolLoc(i, DS.getProtocolLocs()[i]);
 
-  } else if (ObjCProtocolListLoc *PLL = dyn_cast<ObjCProtocolListLoc>(&TSL)) {
-    assert(PLL->getNumProtocols() == DS.getNumProtocolQualifiers());
-    PLL->setLAngleLoc(DS.getProtocolLAngleLoc());
-    PLL->setRAngleLoc(DS.getSourceRange().getEnd());
-    for (unsigned i = 0; i != DS.getNumProtocolQualifiers(); ++i)
-      PLL->setProtocolLoc(i, DS.getProtocolLocs()[i]);
-    FillTypeSpecLoc(PLL->getBaseTypeLoc(), DS);
+      TypeLoc BaseLoc = TL.getBaseTypeLoc();
+      if (BaseLoc)
+        Visit(TL.getBaseTypeLoc());
+    }
+    void VisitTypeLoc(TypeLoc TL) {
+      // FIXME: add other typespec types and change this to an assert.
+      TL.initialize(DS.getTypeSpecTypeLoc());
+    }
+  };
 
-  } else {
-    //FIXME: Other typespecs.
-    DefaultTypeSpecLoc &DTL = cast<DefaultTypeSpecLoc>(TSL);
-    DTL.setStartLoc(DS.getSourceRange().getBegin());
-  }
-}
+  class DeclaratorLocFiller : public TypeLocVisitor<DeclaratorLocFiller> {
+    const DeclaratorChunk &Chunk;
 
-/// \brief Create and instantiate a DeclaratorInfo with type source information.
-///
-/// \param T QualType referring to the type as written in source code.
-DeclaratorInfo *
-Sema::GetDeclaratorInfoForDeclarator(Declarator &D, QualType T, unsigned Skip) {
-  DeclaratorInfo *DInfo = Context.CreateDeclaratorInfo(T);
-  TypeLoc CurrTL = DInfo->getTypeLoc();
+  public:
+    DeclaratorLocFiller(const DeclaratorChunk &Chunk) : Chunk(Chunk) {}
 
-  for (unsigned i = Skip, e = D.getNumTypeObjects(); i != e; ++i) {
-    assert(!CurrTL.isNull());
-    
-    // Don't bother recording source locations for qualifiers.
-    CurrTL = CurrTL.getUnqualifiedLoc();
+    void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
+      llvm::llvm_unreachable("qualified type locs not expected here!");
+    }
 
-    DeclaratorChunk &DeclType = D.getTypeObject(i);
-    switch (DeclType.Kind) {
-    default: assert(0 && "Unknown decltype!");
-    case DeclaratorChunk::BlockPointer: {
-      BlockPointerLoc &BPL = cast<BlockPointerLoc>(CurrTL);
-      BPL.setCaretLoc(DeclType.Loc);
-      break;
+    void VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
+      assert(Chunk.Kind == DeclaratorChunk::BlockPointer);
+      TL.setCaretLoc(Chunk.Loc);
     }
-    case DeclaratorChunk::Pointer: {
-      //FIXME: ObjCObject pointers.
-      PointerLoc &PL = cast<PointerLoc>(CurrTL);
-      PL.setStarLoc(DeclType.Loc);
-      break;
+    void VisitPointerTypeLoc(PointerTypeLoc TL) {
+      assert(Chunk.Kind == DeclaratorChunk::Pointer);
+      TL.setStarLoc(Chunk.Loc);
     }
-    case DeclaratorChunk::Reference: {
-      ReferenceLoc &RL = cast<ReferenceLoc>(CurrTL);
-      RL.setAmpLoc(DeclType.Loc);
-      break;
+    void VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
+      assert(Chunk.Kind == DeclaratorChunk::Pointer);
+      TL.setStarLoc(Chunk.Loc);
     }
-    case DeclaratorChunk::Array: {
-      DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
-      ArrayLoc &AL = cast<ArrayLoc>(CurrTL);
-      AL.setLBracketLoc(DeclType.Loc);
-      AL.setRBracketLoc(DeclType.EndLoc);
-      AL.setSizeExpr(static_cast<Expr*>(ATI.NumElts));
-      //FIXME: Star location for [*].
-      break;
+    void VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
+      assert(Chunk.Kind == DeclaratorChunk::MemberPointer);
+      TL.setStarLoc(Chunk.Loc);
+      // FIXME: nested name specifier
     }
-    case DeclaratorChunk::Function: {
-      const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
-      FunctionLoc &FL = cast<FunctionLoc>(CurrTL);
-      FL.setLParenLoc(DeclType.Loc);
-      FL.setRParenLoc(DeclType.EndLoc);
+    void VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
+      assert(Chunk.Kind == DeclaratorChunk::Reference);
+      assert(Chunk.Ref.LValueRef);
+      TL.setAmpLoc(Chunk.Loc);
+    }
+    void VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
+      assert(Chunk.Kind == DeclaratorChunk::Reference);
+      assert(!Chunk.Ref.LValueRef);
+      TL.setAmpAmpLoc(Chunk.Loc);
+    }
+    void VisitArrayTypeLoc(ArrayTypeLoc TL) {
+      assert(Chunk.Kind == DeclaratorChunk::Array);
+      TL.setLBracketLoc(Chunk.Loc);
+      TL.setRBracketLoc(Chunk.EndLoc);
+      TL.setSizeExpr(static_cast<Expr*>(Chunk.Arr.NumElts));
+    }
+    void VisitFunctionTypeLoc(FunctionTypeLoc TL) {
+      assert(Chunk.Kind == DeclaratorChunk::Function);
+      TL.setLParenLoc(Chunk.Loc);
+      TL.setRParenLoc(Chunk.EndLoc);
+
+      const DeclaratorChunk::FunctionTypeInfo &FTI = Chunk.Fun;
       for (unsigned i = 0, e = FTI.NumArgs, tpi = 0; i != e; ++i) {
         ParmVarDecl *Param = FTI.ArgInfo[i].Param.getAs<ParmVarDecl>();
         if (Param) {
-          assert(tpi < FL.getNumArgs());
-          FL.setArg(tpi++, Param);
+          assert(tpi < TL.getNumArgs());
+          TL.setArg(tpi++, Param);
         }
       }
-      break;
-      //FIXME: Exception specs.
-    }
-    case DeclaratorChunk::MemberPointer: {
-      MemberPointerLoc &MPL = cast<MemberPointerLoc>(CurrTL);
-      MPL.setStarLoc(DeclType.Loc);
-      //FIXME: Class location.
-      break;
+      // FIXME: exception specs
     }
 
+    void VisitTypeLoc(TypeLoc TL) {
+      llvm::llvm_unreachable("unsupported TypeLoc kind in declarator!");
     }
+  };
+}
 
-    CurrTL = CurrTL.getNextTypeLoc();
+/// \brief Create and instantiate a DeclaratorInfo with type source information.
+///
+/// \param T QualType referring to the type as written in source code.
+DeclaratorInfo *
+Sema::GetDeclaratorInfoForDeclarator(Declarator &D, QualType T, unsigned Skip) {
+  DeclaratorInfo *DInfo = Context.CreateDeclaratorInfo(T);
+  UnqualTypeLoc CurrTL = DInfo->getTypeLoc().getUnqualifiedLoc();
+
+  for (unsigned i = Skip, e = D.getNumTypeObjects(); i != e; ++i) {
+    DeclaratorLocFiller(D.getTypeObject(i)).Visit(CurrTL);
+    CurrTL = CurrTL.getNextTypeLoc().getUnqualifiedLoc();
   }
   
-  FillTypeSpecLoc(CurrTL, D.getDeclSpec());
+  TypeSpecLocFiller(D.getDeclSpec()).Visit(CurrTL);
 
   return DInfo;
 }





More information about the cfe-commits mailing list