aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-10-16 22:31:57 +0000
committerJohn McCall <rjmccall@apple.com>2009-10-16 22:31:57 +0000
commit4ce74bd425dccd9d9ad6ccfc9ffbc01698a6e71a (patch)
tree6fc0ca0158a571bbcdf14e6cda9079ab90d74cf0
parent1cad602ee0283947dbf103f13d9a7c098649dfe3 (diff)
Allow TypeLocs to be fully initialized with a single SourceLocation. This
will be the keystone of converting existing rewrites to be rewrites on TypeLocs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84286 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/TypeLoc.h82
-rw-r--r--lib/AST/TypeLoc.cpp39
2 files changed, 109 insertions, 12 deletions
diff --git a/include/clang/AST/TypeLoc.h b/include/clang/AST/TypeLoc.h
index d97886961d..22837d8048 100644
--- a/include/clang/AST/TypeLoc.h
+++ b/include/clang/AST/TypeLoc.h
@@ -78,6 +78,15 @@ public:
/// \brief Skips past any qualifiers, if this is qualified.
UnqualTypeLoc getUnqualifiedLoc() const;
+ /// \brief Initializes this to state that every location in this
+ /// type is the given location.
+ ///
+ /// This method exists to provide a simple transition for code that
+ /// relies on location-less types.
+ void initialize(SourceLocation Loc) const {
+ initializeImpl(*this, Loc);
+ }
+
friend bool operator==(const TypeLoc &LHS, const TypeLoc &RHS) {
return LHS.Ty == RHS.Ty && LHS.Data == RHS.Data;
}
@@ -87,6 +96,9 @@ public:
}
static bool classof(const TypeLoc *TL) { return true; }
+
+private:
+ static void initializeImpl(TypeLoc TL, SourceLocation Loc);
};
/// \brief Wrapper of type source information for a type with
@@ -121,6 +133,16 @@ public:
return UnqualTypeLoc(getSourceTypePtr(), Data);
}
+ /// Initializes the local data of this type source info block to
+ /// provide no information.
+ void initializeLocal(SourceLocation Loc) {
+ // do nothing
+ }
+
+ TypeLoc getNextTypeLoc() const {
+ return getUnqualifiedLoc();
+ }
+
/// \brief Returns the size of the type source info data block that is
/// specific to this type.
unsigned getLocalDataSize() const {
@@ -230,6 +252,10 @@ public:
return TypeClass::classof(Ty);
}
+ TypeLoc getNextTypeLoc() const {
+ return getNextTypeLoc(asDerived()->getInnerType());
+ }
+
protected:
TypeClass *getTypePtr() const {
return cast<TypeClass>(Base::getSourceTypePtr());
@@ -273,6 +299,14 @@ private:
unsigned getInnerTypeSize(QualType _) const {
return getInnerTypeLoc().getFullDataSize();
}
+
+ TypeLoc getNextTypeLoc(HasNoInnerType _) const {
+ return TypeLoc();
+ }
+
+ TypeLoc getNextTypeLoc(QualType T) const {
+ return TypeLoc(T, getNonLocalData());
+ }
};
@@ -297,6 +331,10 @@ public:
return SourceRange(getStartLoc(), getStartLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStartLoc(Loc);
+ }
+
static bool classofType(const Type *T);
};
@@ -319,6 +357,10 @@ public:
return SourceRange(getNameLoc(), getNameLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setNameLoc(Loc);
+ }
+
TypedefDecl *getTypedefDecl() const {
return getTypePtr()->getDecl();
}
@@ -345,6 +387,10 @@ public:
return SourceRange(getNameLoc(), getNameLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setNameLoc(Loc);
+ }
+
ObjCInterfaceDecl *getIFaceDecl() const {
return getTypePtr()->getDecl();
}
@@ -406,6 +452,13 @@ public:
return SourceRange(getLAngleLoc(), getRAngleLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setLAngleLoc(Loc);
+ setRAngleLoc(Loc);
+ for (unsigned i = 0, e = getNumProtocols(); i != e; ++i)
+ setProtocolLoc(i, Loc);
+ }
+
/// \brief Returns the size of the type source info data block that is
/// specific to this type.
unsigned getExtraLocalDataSize() const {
@@ -446,6 +499,10 @@ public:
return SourceRange(getStarLoc(), getStarLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStarLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
@@ -480,6 +537,10 @@ public:
return SourceRange(getCaretLoc(), getCaretLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setCaretLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
@@ -514,6 +575,10 @@ public:
return SourceRange(getStarLoc(), getStarLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStarLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
@@ -548,6 +613,10 @@ public:
return SourceRange(getAmpLoc(), getAmpLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setAmpLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
@@ -603,6 +672,13 @@ public:
return SourceRange(getLParenLoc(), getRParenLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setLParenLoc(Loc);
+ setRParenLoc(Loc);
+ for (unsigned i = 0, e = getNumArgs(); i != e; ++i)
+ setArg(i, NULL);
+ }
+
/// \brief Returns the size of the type source info data block that is
/// specific to this type.
unsigned getExtraLocalDataSize() const {
@@ -657,6 +733,12 @@ public:
return SourceRange(getLBracketLoc(), getRBracketLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setLBracketLoc(Loc);
+ setRBracketLoc(Loc);
+ setSizeExpr(NULL);
+ }
+
QualType getInnerType() const { return getTypePtr()->getElementType(); }
};
diff --git a/lib/AST/TypeLoc.cpp b/lib/AST/TypeLoc.cpp
index 04e708370a..c216a29e64 100644
--- a/lib/AST/TypeLoc.cpp
+++ b/lib/AST/TypeLoc.cpp
@@ -91,7 +91,7 @@ public:
TypeLoc VisitTypeSpecLoc(TypeLoc TyLoc) { return TypeLoc(); }
TypeLoc VisitObjCProtocolListLoc(ObjCProtocolListLoc TL);
TypeLoc VisitQualifiedLoc(QualifiedLoc TyLoc) {
- return TyLoc.getUnqualifiedLoc();
+ return TyLoc.getNextTypeLoc();
}
TypeLoc VisitTypeLoc(TypeLoc TyLoc) {
@@ -103,35 +103,50 @@ public:
}
TypeLoc NextLoc::VisitObjCProtocolListLoc(ObjCProtocolListLoc TL) {
- return TL.getBaseTypeLoc();
+ return TL.getNextTypeLoc();
}
TypeLoc NextLoc::VisitPointerLoc(PointerLoc TL) {
- return TL.getPointeeLoc();
+ return TL.getNextTypeLoc();
}
TypeLoc NextLoc::VisitMemberPointerLoc(MemberPointerLoc TL) {
- return TL.getPointeeLoc();
+ return TL.getNextTypeLoc();
}
TypeLoc NextLoc::VisitBlockPointerLoc(BlockPointerLoc TL) {
- return TL.getPointeeLoc();
+ return TL.getNextTypeLoc();
}
TypeLoc NextLoc::VisitReferenceLoc(ReferenceLoc TL) {
- return TL.getPointeeLoc();
+ return TL.getNextTypeLoc();
}
TypeLoc NextLoc::VisitFunctionLoc(FunctionLoc TL) {
- return TL.getResultLoc();
+ return TL.getNextTypeLoc();
}
TypeLoc NextLoc::VisitArrayLoc(ArrayLoc TL) {
- return TL.getElementLoc();
+ 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 {
- //llvm::errs() << "getNextTypeLoc: Ty=" << Ty << ", Data=" << Data << "\n";
- TypeLoc Tmp = NextLoc().Visit(*this);
- //llvm::errs() << " result: Ty=" << Tmp.Ty << ", Data=" << Tmp.Data << "\n";
- return Tmp;
+ return NextLoc().Visit(*this);
+}
+
+namespace {
+struct TypeLocInitializer : public TypeLocVisitor<TypeLocInitializer> {
+ SourceLocation Loc;
+ TypeLocInitializer(SourceLocation Loc) : Loc(Loc) {}
+
+#define ABSTRACT_TYPELOC(CLASS)
+#define TYPELOC(CLASS, PARENT) \
+ void Visit##CLASS(CLASS TyLoc) { TyLoc.initializeLocal(Loc); }
+#include "clang/AST/TypeLocNodes.def"
+};
+}
+
+void TypeLoc::initializeImpl(TypeLoc TL, SourceLocation Loc) {
+ do {
+ TypeLocInitializer(Loc).Visit(TL);
+ } while (TL = TL.getNextTypeLoc());
}
//===----------------------------------------------------------------------===//