aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/TypeLoc.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-10-18 01:05:36 +0000
committerJohn McCall <rjmccall@apple.com>2009-10-18 01:05:36 +0000
commit51bd803fbdade51d674598ed45da3d54190a656c (patch)
tree6a0f7a2881033be64625cb432e7b7e96eb0729fa /lib/AST/TypeLoc.cpp
parenta47dd191719e88e41ce82555685869d2054178e1 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84386 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/TypeLoc.cpp')
-rw-r--r--lib/AST/TypeLoc.cpp210
1 files changed, 38 insertions, 172 deletions
diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp
index c216a29e64..7e6b110bf5 100644
--- a/lib/AST/TypeLoc.cpp
+++ b/lib/AST/TypeLoc.cpp
@@ -20,55 +20,32 @@ using namespace clang;
//===----------------------------------------------------------------------===//
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 @@ unsigned TypeLoc::getFullDataSizeForType(QualType Ty) {
}
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));
-}
-