/// \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;
}
}
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
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 {
return TypeClass::classof(Ty);
}
+ TypeLoc getNextTypeLoc() const {
+ return getNextTypeLoc(asDerived()->getInnerType());
+ }
+
protected:
TypeClass *getTypePtr() const {
return cast<TypeClass>(Base::getSourceTypePtr());
unsigned getInnerTypeSize(QualType _) const {
return getInnerTypeLoc().getFullDataSize();
}
+
+ TypeLoc getNextTypeLoc(HasNoInnerType _) const {
+ return TypeLoc();
+ }
+
+ TypeLoc getNextTypeLoc(QualType T) const {
+ return TypeLoc(T, getNonLocalData());
+ }
};
return SourceRange(getStartLoc(), getStartLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStartLoc(Loc);
+ }
+
static bool classofType(const Type *T);
};
return SourceRange(getNameLoc(), getNameLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setNameLoc(Loc);
+ }
+
TypedefDecl *getTypedefDecl() const {
return getTypePtr()->getDecl();
}
return SourceRange(getNameLoc(), getNameLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setNameLoc(Loc);
+ }
+
ObjCInterfaceDecl *getIFaceDecl() const {
return getTypePtr()->getDecl();
}
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 {
return SourceRange(getStarLoc(), getStarLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStarLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
return SourceRange(getCaretLoc(), getCaretLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setCaretLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
return SourceRange(getStarLoc(), getStarLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setStarLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
return SourceRange(getAmpLoc(), getAmpLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setAmpLoc(Loc);
+ }
+
QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
};
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 {
return SourceRange(getLBracketLoc(), getRBracketLoc());
}
+ void initializeLocal(SourceLocation Loc) {
+ setLBracketLoc(Loc);
+ setRBracketLoc(Loc);
+ setSizeExpr(NULL);
+ }
+
QualType getInnerType() const { return getTypePtr()->getElementType(); }
};
TypeLoc VisitTypeSpecLoc(TypeLoc TyLoc) { return TypeLoc(); }
TypeLoc VisitObjCProtocolListLoc(ObjCProtocolListLoc TL);
TypeLoc VisitQualifiedLoc(QualifiedLoc TyLoc) {
- return TyLoc.getUnqualifiedLoc();
+ return TyLoc.getNextTypeLoc();
}
TypeLoc VisitTypeLoc(TypeLoc TyLoc) {
}
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());
}
//===----------------------------------------------------------------------===//