From: Argyrios Kyrtzidis Date: Tue, 29 Sep 2009 19:40:46 +0000 (+0000) Subject: Introduce TypeLoc::getSourceRange(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68006af18fb880cd8547ce797152111b810aa0ba;p=clang Introduce TypeLoc::getSourceRange(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83089 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h index 93cc48aa07..21b7d9af52 100644 --- a/include/clang/AST/TypeLoc.h +++ b/include/clang/AST/TypeLoc.h @@ -48,6 +48,8 @@ public: /// \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; @@ -76,8 +78,6 @@ public: /// \brief Base wrapper of type source info data for type-spec types. class TypeSpecLoc : public TypeLoc { public: - SourceRange getSourceRange() const; - static bool classof(const TypeLoc *TL); static bool classof(const TypeSpecLoc *TL) { return true; } }; diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp index a95f38897a..cea8dc5169 100644 --- a/lib/AST/TypeLoc.cpp +++ b/lib/AST/TypeLoc.cpp @@ -18,6 +18,30 @@ using namespace clang; // TypeLoc Implementation //===----------------------------------------------------------------------===// +namespace { + +/// \brief Return the source range for the visited TypeSpecLoc. +class TypeLocRanger : public TypeLocVisitor { +public: +#define ABSTRACT_TYPELOC(CLASS) +#define TYPELOC(CLASS, PARENT, TYPE) \ + SourceRange Visit##CLASS(CLASS 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 Returns the size of type source info data block for the given type. unsigned TypeLoc::getFullDataSizeForType(QualType Ty) { return TypeLoc(Ty, 0).getFullDataSize(); @@ -112,30 +136,6 @@ TypeLoc TypeLoc::getNextTypeLoc() const { // TypeSpecLoc Implementation //===----------------------------------------------------------------------===// -namespace { - -/// \brief Return the source range for the visited TypeSpecLoc. -class TypeSpecRanger : public TypeLocVisitor { -public: -#define TYPELOC(CLASS, PARENT, TYPE) -#define TYPESPEC_TYPELOC(CLASS, TYPE) \ - SourceRange Visit##CLASS(CLASS TyLoc) { return TyLoc.getSourceRange(); } -#include "clang/AST/TypeLocNodes.def" - - SourceRange VisitTypeLoc(TypeLoc TyLoc) { - assert(0 && "A typespec loc wrapper was not handled!"); - return SourceRange(); - } -}; - -} - -SourceRange TypeSpecLoc::getSourceRange() const { - if (isNull()) - return SourceRange(); - return TypeSpecRanger().Visit(*this); -} - namespace { class TypeSpecChecker : public TypeLocVisitor { public: