[cfe-commits] r84286 - in /cfe/trunk: include/clang/AST/TypeLoc.h lib/AST/TypeLoc.cpp
John McCall
rjmccall at apple.com
Fri Oct 16 15:31:59 PDT 2009
Author: rjmccall
Date: Fri Oct 16 17:31:57 2009
New Revision: 84286
URL: http://llvm.org/viewvc/llvm-project?rev=84286&view=rev
Log:
Allow TypeLocs to be fully initialized with a single SourceLocation. This
will be the keystone of converting existing rewrites to be rewrites on TypeLocs.
Modified:
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/lib/AST/TypeLoc.cpp
Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=84286&r1=84285&r2=84286&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Fri Oct 16 17:31:57 2009
@@ -78,6 +78,15 @@
/// \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 @@
}
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 @@
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 @@
return TypeClass::classof(Ty);
}
+ TypeLoc getNextTypeLoc() const {
+ return getNextTypeLoc(asDerived()->getInnerType());
+ }
+
protected:
TypeClass *getTypePtr() const {
return cast<TypeClass>(Base::getSourceTypePtr());
@@ -273,6 +299,14 @@
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 @@
return SourceRange(getStartLoc(), getStartLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStartLoc(Loc);
+ }
+
static bool classofType(const Type *T);
};
@@ -319,6 +357,10 @@
return SourceRange(getNameLoc(), getNameLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setNameLoc(Loc);
+ }
+
TypedefDecl *getTypedefDecl() const {
return getTypePtr()->getDecl();
}
@@ -345,6 +387,10 @@
return SourceRange(getNameLoc(), getNameLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setNameLoc(Loc);
+ }
+
ObjCInterfaceDecl *getIFaceDecl() const {
return getTypePtr()->getDecl();
}
@@ -406,6 +452,13 @@
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 @@
return SourceRange(getStarLoc(), getStarLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStarLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
@@ -480,6 +537,10 @@
return SourceRange(getCaretLoc(), getCaretLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setCaretLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
@@ -514,6 +575,10 @@
return SourceRange(getStarLoc(), getStarLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStarLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
@@ -548,6 +613,10 @@
return SourceRange(getAmpLoc(), getAmpLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setAmpLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
@@ -603,6 +672,13 @@
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 @@
return SourceRange(getLBracketLoc(), getRBracketLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setLBracketLoc(Loc);
+ setRBracketLoc(Loc);
+ setSizeExpr(NULL);
+ }
+
QualType getInnerType() const { return getTypePtr()->getElementType(); }
};
Modified: cfe/trunk/lib/AST/TypeLoc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=84286&r1=84285&r2=84286&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypeLoc.cpp (original)
+++ cfe/trunk/lib/AST/TypeLoc.cpp Fri Oct 16 17:31:57 2009
@@ -91,7 +91,7 @@
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 @@
}
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());
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list