class ParmVarDecl;
class TypeSpecLoc;
class DeclaratorInfo;
+ class UnqualTypeLoc;
/// \brief Base wrapper for a particular "section" of type source info.
///
/// get at the actual information.
class TypeLoc {
protected:
- QualType Ty;
+ // The correctness of this relies on the property that, for Type *Ty,
+ // QualType(Ty, 0).getAsOpaquePtr() == (void*) Ty
+ void *Ty;
void *Data;
public:
- TypeLoc() : Data(0) { }
- TypeLoc(QualType ty, void *opaqueData) : Ty(ty), Data(opaqueData) { }
+ TypeLoc() : Ty(0), Data(0) { }
+ TypeLoc(QualType ty, void *opaqueData)
+ : Ty(ty.getAsOpaquePtr()), Data(opaqueData) { }
+ TypeLoc(Type *ty, void *opaqueData)
+ : Ty(ty), Data(opaqueData) { }
- bool isNull() const { return Ty.isNull(); }
- operator bool() const { return !isNull(); }
+ bool isNull() const { return !Ty; }
+ operator bool() const { return Ty; }
/// \brief Returns the size of type source info data block for the given type.
static unsigned getFullDataSizeForType(QualType Ty);
/// \brief Get the type for which this source info wrapper provides
/// information.
- QualType getSourceType() const { return Ty; }
+ QualType getSourceType() const { return QualType::getFromOpaquePtr(Ty); }
+
+ Type *getSourceTypePtr() const {
+ return QualType::getFromOpaquePtr(Ty).getTypePtr();
+ }
/// \brief Get the pointer where source information is stored.
void *getOpaqueData() const { return Data; }
SourceRange getTypeSpecRange() const;
/// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const;
+ unsigned getFullDataSize() const {
+ return getFullDataSizeForType(getSourceType());
+ }
/// \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 getNextTypeLoc() const;
+ /// \brief Skips past any qualifiers, if this is qualified.
+ UnqualTypeLoc getUnqualifiedLoc() const;
+
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; }
};
+/// \brief Wrapper of type source information for a type with
+/// no direct quqlaifiers.
+class UnqualTypeLoc : public TypeLoc {
+public:
+ UnqualTypeLoc() {}
+ UnqualTypeLoc(Type *Ty, void *Data) : TypeLoc(Ty, Data) {}
+
+ Type *getSourceTypePtr() const {
+ return reinterpret_cast<Type*>(Ty);
+ }
+
+ static bool classof(const TypeLoc *TL) {
+ return !TL->getSourceType().hasQualifiers();
+ }
+ static bool classof(const UnqualTypeLoc *TL) { return true; }
+};
+
+/// \brief Wrapper of type source information for a type with
+/// non-trivial direct qualifiers.
+///
+/// Currently, we intentionally do not provide source location for
+/// type qualifiers.
+class QualifiedLoc : public TypeLoc {
+public:
+ SourceRange getSourceRange() const {
+ return SourceRange();
+ }
+
+ UnqualTypeLoc getUnqualifiedLoc() const {
+ return UnqualTypeLoc(getSourceTypePtr(), Data);
+ }
+
+ /// \brief Returns the size of the type source info data block that is
+ /// specific to this type.
+ unsigned getLocalDataSize() const {
+ // In fact, we don't currently preserve any location information
+ // for qualifiers.
+ return 0;
+ }
+
+ /// \brief Returns the size of the type source info data block.
+ unsigned getFullDataSize() const {
+ return getLocalDataSize() +
+ getFullDataSizeForType(getSourceType().getUnqualifiedType());
+ }
+
+ static bool classof(const TypeLoc *TL) {
+ return TL->getSourceType().hasQualifiers();
+ }
+ static bool classof(const QualifiedLoc *TL) { return true; }
+};
+
+inline UnqualTypeLoc TypeLoc::getUnqualifiedLoc() const {
+ if (isa<QualifiedLoc>(this))
+ return cast<QualifiedLoc>(this)->getUnqualifiedLoc();
+ return cast<UnqualTypeLoc>(*this);
+}
+
/// \brief Base wrapper of type source info data for type-spec types.
-class TypeSpecLoc : public TypeLoc {
+class TypeSpecLoc : public UnqualTypeLoc {
public:
- static bool classof(const TypeLoc *TL);
+ static bool classof(const TypeLoc *TL) {
+ return (UnqualTypeLoc::classof(TL) &&
+ classof(static_cast<const UnqualTypeLoc*>(TL)));
+ }
+ static bool classof(const UnqualTypeLoc *TL);
static bool classof(const TypeSpecLoc *TL) { return true; }
};
+inline SourceRange TypeLoc::getTypeSpecRange() const {
+ return getTypeSpecLoc().getSourceRange();
+}
+
/// \brief Base wrapper of type source info data for types part of a declarator,
/// excluding type-spec types.
-class DeclaratorLoc : public TypeLoc {
+class DeclaratorLoc : public UnqualTypeLoc {
public:
/// \brief Find the TypeSpecLoc that is part of this DeclaratorLoc.
TypeSpecLoc getTypeSpecLoc() const;
- static bool classof(const TypeLoc *TL);
+ static bool classof(const TypeLoc *TL) {
+ return (UnqualTypeLoc::classof(TL) &&
+ classof(static_cast<const UnqualTypeLoc*>(TL)));
+ }
+ static bool classof(const UnqualTypeLoc *TL);
static bool classof(const DeclaratorLoc *TL) { return true; }
};
+
+/// A metaprogramming base class for TypeLoc classes which correspond
+/// to a particular Type subclass.
+///
+/// \param Base a class from which to derive
+/// \param Derived the class deriving from this one
+/// \param TypeClass the concrete Type subclass which this
+/// \param LocalData the structure type of local location data for
+/// this type
+///
+/// sizeof(LocalData) needs to be a multiple of sizeof(void*) or
+/// else the world will end.
+///
+/// TypeLocs with non-constant amounts of local data should override
+/// getExtraLocalDataSize(); getExtraLocalData() will then point to
+/// this extra memory.
+///
+/// TypeLocs with an inner type should override ha
+template <class Base, class Derived, class TypeClass, class LocalData>
+class ConcreteTypeLoc : public Base {
+
+ const Derived *asDerived() const {
+ return static_cast<const Derived*>(this);
+ }
+
+public:
+ unsigned getLocalDataSize() const {
+ return sizeof(LocalData) + asDerived()->getExtraLocalDataSize();
+ }
+ // Give a default implementation that's useful for leaf types.
+ unsigned getFullDataSize() const {
+ return asDerived()->getLocalDataSize() + getInnerTypeSize();
+ }
+
+ static bool classof(const TypeLoc *TL) {
+ return Derived::classofType(TL->getSourceTypePtr());
+ }
+ static bool classof(const UnqualTypeLoc *TL) {
+ return Derived::classofType(TL->getSourceTypePtr());
+ }
+ static bool classof(const Derived *TL) {
+ return true;
+ }
+
+ static bool classofType(const Type *Ty) {
+ return TypeClass::classof(Ty);
+ }
+
+protected:
+ TypeClass *getTypePtr() const {
+ return cast<TypeClass>(Base::getSourceTypePtr());
+ }
+
+ unsigned getExtraLocalDataSize() const {
+ return 0;
+ }
+
+ LocalData *getLocalData() const {
+ return static_cast<LocalData*>(Base::Data);
+ }
+
+ /// Gets a pointer past the Info structure; useful for classes with
+ /// local data that can't be captured in the Info (e.g. because it's
+ /// of variable size).
+ void *getExtraLocalData() const {
+ return getLocalData() + 1;
+ }
+
+ void *getNonLocalData() const {
+ return static_cast<char*>(Base::Data) + asDerived()->getLocalDataSize();
+ }
+
+ bool hasInnerType() const {
+ return false;
+ }
+
+ TypeLoc getInnerTypeLoc() const {
+ assert(asDerived()->hasInnerType());
+ return TypeLoc(asDerived()->getInnerType(), getNonLocalData());
+ }
+
+private:
+ unsigned getInnerTypeSize() const {
+ if (asDerived()->hasInnerType())
+ return getInnerTypeLoc().getFullDataSize();
+ return 0;
+ }
+
+ // Required here because my metaprogramming is too weak to avoid it.
+ QualType getInnerType() const {
+ assert(0 && "getInnerType() not overridden");
+ return QualType();
+ }
+};
+
+
+struct DefaultTypeSpecLocInfo {
+ SourceLocation StartLoc;
+};
+
/// \brief The default wrapper for type-spec types that are not handled by
/// another specific wrapper.
-class DefaultTypeSpecLoc : public TypeSpecLoc {
- struct Info {
- SourceLocation StartLoc;
- };
-
+class DefaultTypeSpecLoc : public ConcreteTypeLoc<TypeSpecLoc,
+ DefaultTypeSpecLoc,
+ Type,
+ DefaultTypeSpecLocInfo> {
public:
SourceLocation getStartLoc() const {
- return static_cast<Info*>(Data)->StartLoc;
+ return getLocalData()->StartLoc;
}
void setStartLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->StartLoc = Loc;
+ getLocalData()->StartLoc = Loc;
}
SourceRange getSourceRange() const {
return SourceRange(getStartLoc(), getStartLoc());
}
- /// \brief Returns the size of the type source info data block that is
- /// specific to this type.
- unsigned getLocalDataSize() const { return sizeof(Info); }
+ static bool classofType(const Type *T);
+};
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const { return getLocalDataSize(); }
- static bool classof(const TypeLoc *TL);
- static bool classof(const DefaultTypeSpecLoc *TL) { return true; }
+struct TypedefLocInfo {
+ SourceLocation NameLoc;
};
/// \brief Wrapper for source info for typedefs.
-class TypedefLoc : public TypeSpecLoc {
- struct Info {
- SourceLocation NameLoc;
- };
-
+class TypedefLoc : public ConcreteTypeLoc<TypeSpecLoc,TypedefLoc,
+ TypedefType,TypedefLocInfo> {
public:
SourceLocation getNameLoc() const {
- return static_cast<Info*>(Data)->NameLoc;
+ return getLocalData()->NameLoc;
}
void setNameLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->NameLoc = Loc;
+ getLocalData()->NameLoc = Loc;
}
SourceRange getSourceRange() const {
return SourceRange(getNameLoc(), getNameLoc());
}
TypedefDecl *getTypedefDecl() const {
- return cast<TypedefType>(Ty)->getDecl();
+ return getTypePtr()->getDecl();
}
+};
- /// \brief Returns the size of the type source info data block that is
- /// specific to this type.
- unsigned getLocalDataSize() const { return sizeof(Info); }
-
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const { return getLocalDataSize(); }
- static bool classof(const TypeLoc *TL);
- static bool classof(const TypedefLoc *TL) { return true; }
+struct ObjCInterfaceLocInfo {
+ SourceLocation NameLoc;
};
/// \brief Wrapper for source info for ObjC interfaces.
-class ObjCInterfaceLoc : public TypeSpecLoc {
- struct Info {
- SourceLocation NameLoc;
- };
-
+class ObjCInterfaceLoc : public ConcreteTypeLoc<TypeSpecLoc,
+ ObjCInterfaceLoc,
+ ObjCInterfaceType,
+ ObjCInterfaceLocInfo> {
public:
SourceLocation getNameLoc() const {
- return static_cast<Info*>(Data)->NameLoc;
+ return getLocalData()->NameLoc;
}
void setNameLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->NameLoc = Loc;
+ getLocalData()->NameLoc = Loc;
}
SourceRange getSourceRange() const {
return SourceRange(getNameLoc(), getNameLoc());
}
ObjCInterfaceDecl *getIFaceDecl() const {
- return cast<ObjCInterfaceType>(Ty)->getDecl();
+ return getTypePtr()->getDecl();
}
+};
- /// \brief Returns the size of the type source info data block that is
- /// specific to this type.
- unsigned getLocalDataSize() const { return sizeof(Info); }
-
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const { return getLocalDataSize(); }
- static bool classof(const TypeLoc *TL);
- static bool classof(const TypedefLoc *TL) { return true; }
+struct ObjCProtocolListLocInfo {
+ SourceLocation LAngleLoc, RAngleLoc;
};
/// \brief Wrapper for source info for ObjC protocol lists.
-class ObjCProtocolListLoc : public TypeSpecLoc {
- struct Info {
- SourceLocation LAngleLoc, RAngleLoc;
- };
+class ObjCProtocolListLoc : public ConcreteTypeLoc<TypeSpecLoc,
+ ObjCProtocolListLoc,
+ ObjCProtocolListType,
+ ObjCProtocolListLocInfo> {
// SourceLocations are stored after Info, one for each Protocol.
SourceLocation *getProtocolLocArray() const {
- return reinterpret_cast<SourceLocation*>(static_cast<Info*>(Data) + 1);
+ return (SourceLocation*) getExtraLocalData();
}
public:
SourceLocation getLAngleLoc() const {
- return static_cast<Info*>(Data)->LAngleLoc;
+ return getLocalData()->LAngleLoc;
}
void setLAngleLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->LAngleLoc = Loc;
+ getLocalData()->LAngleLoc = Loc;
}
SourceLocation getRAngleLoc() const {
- return static_cast<Info*>(Data)->RAngleLoc;
+ return getLocalData()->RAngleLoc;
}
void setRAngleLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->RAngleLoc = Loc;
+ getLocalData()->RAngleLoc = Loc;
}
unsigned getNumProtocols() const {
- return cast<ObjCProtocolListType>(Ty)->getNumProtocols();
+ return getTypePtr()->getNumProtocols();
}
SourceLocation getProtocolLoc(unsigned i) const {
ObjCProtocolDecl *getProtocol(unsigned i) const {
assert(i < getNumProtocols() && "Index is out of bounds!");
- return *(cast<ObjCProtocolListType>(Ty)->qual_begin() + i);
+ return *(getTypePtr()->qual_begin() + i);
}
TypeLoc getBaseTypeLoc() const {
- void *Next = static_cast<char*>(Data) + getLocalDataSize();
- return TypeLoc(cast<ObjCProtocolListType>(Ty)->getBaseType(), Next);
+ return getInnerTypeLoc();
}
SourceRange getSourceRange() const {
/// \brief Returns the size of the type source info data block that is
/// specific to this type.
- unsigned getLocalDataSize() const {
- return sizeof(Info) + getNumProtocols() * sizeof(SourceLocation);
+ unsigned getExtraLocalDataSize() const {
+ return getNumProtocols() * sizeof(SourceLocation);
}
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const {
- return getLocalDataSize() + getBaseTypeLoc().getFullDataSize();
- }
+ bool hasInnerType() const { return true; }
+ QualType getInnerType() const { return getTypePtr()->getBaseType(); }
+};
- static bool classof(const TypeLoc *TL);
- static bool classof(const ObjCProtocolListLoc *TL) { return true; }
+
+struct PointerLocInfo {
+ SourceLocation StarLoc;
};
/// \brief Wrapper for source info for pointers.
-class PointerLoc : public DeclaratorLoc {
- struct Info {
- SourceLocation StarLoc;
- };
-
+class PointerLoc : public ConcreteTypeLoc<DeclaratorLoc,
+ PointerLoc,
+ PointerType,
+ PointerLocInfo> {
public:
SourceLocation getStarLoc() const {
- return static_cast<Info*>(Data)->StarLoc;
+ return getLocalData()->StarLoc;
}
void setStarLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->StarLoc = Loc;
+ getLocalData()->StarLoc = Loc;
}
TypeLoc getPointeeLoc() const {
- void *Next = static_cast<char*>(Data) + getLocalDataSize();
- return TypeLoc(cast<PointerType>(Ty)->getPointeeType(), Next);
+ return getInnerTypeLoc();
}
/// \brief Find the TypeSpecLoc that is part of this PointerLoc.
return SourceRange(getStarLoc(), getStarLoc());
}
- /// \brief Returns the size of the type source info data block that is
- /// specific to this type.
- unsigned getLocalDataSize() const { return sizeof(Info); }
+ bool hasInnerType() const { return true; }
+ QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
+};
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const {
- return getLocalDataSize() + getPointeeLoc().getFullDataSize();
- }
- static bool classof(const TypeLoc *TL);
- static bool classof(const PointerLoc *TL) { return true; }
+struct BlockPointerLocInfo {
+ SourceLocation CaretLoc;
};
/// \brief Wrapper for source info for block pointers.
-class BlockPointerLoc : public DeclaratorLoc {
- struct Info {
- SourceLocation CaretLoc;
- };
-
+class BlockPointerLoc : public ConcreteTypeLoc<DeclaratorLoc,
+ BlockPointerLoc,
+ BlockPointerType,
+ BlockPointerLocInfo> {
public:
SourceLocation getCaretLoc() const {
- return static_cast<Info*>(Data)->CaretLoc;
+ return getLocalData()->CaretLoc;
}
void setCaretLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->CaretLoc = Loc;
+ getLocalData()->CaretLoc = Loc;
}
TypeLoc getPointeeLoc() const {
- void *Next = static_cast<char*>(Data) + getLocalDataSize();
- return TypeLoc(cast<BlockPointerType>(Ty)->getPointeeType(), Next);
+ return getInnerTypeLoc();
}
/// \brief Find the TypeSpecLoc that is part of this BlockPointerLoc.
return SourceRange(getCaretLoc(), getCaretLoc());
}
- /// \brief Returns the size of the type source info data block that is
- /// specific to this type.
- unsigned getLocalDataSize() const { return sizeof(Info); }
+ bool hasInnerType() const { return true; }
+ QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
+};
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const {
- return getLocalDataSize() + getPointeeLoc().getFullDataSize();
- }
- static bool classof(const TypeLoc *TL);
- static bool classof(const BlockPointerLoc *TL) { return true; }
+struct MemberPointerLocInfo {
+ SourceLocation StarLoc;
};
/// \brief Wrapper for source info for member pointers.
-class MemberPointerLoc : public DeclaratorLoc {
- struct Info {
- SourceLocation StarLoc;
- };
-
+class MemberPointerLoc : public ConcreteTypeLoc<DeclaratorLoc,
+ MemberPointerLoc,
+ MemberPointerType,
+ MemberPointerLocInfo> {
public:
SourceLocation getStarLoc() const {
- return static_cast<Info*>(Data)->StarLoc;
+ return getLocalData()->StarLoc;
}
void setStarLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->StarLoc = Loc;
+ getLocalData()->StarLoc = Loc;
}
TypeLoc getPointeeLoc() const {
- void *Next = static_cast<char*>(Data) + getLocalDataSize();
- return TypeLoc(cast<MemberPointerType>(Ty)->getPointeeType(), Next);
+ return getInnerTypeLoc();
}
/// \brief Find the TypeSpecLoc that is part of this MemberPointerLoc.
return SourceRange(getStarLoc(), getStarLoc());
}
- /// \brief Returns the size of the type source info data block that is
- /// specific to this type.
- unsigned getLocalDataSize() const { return sizeof(Info); }
+ bool hasInnerType() const { return true; }
+ QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
+};
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const {
- return getLocalDataSize() + getPointeeLoc().getFullDataSize();
- }
- static bool classof(const TypeLoc *TL);
- static bool classof(const MemberPointerLoc *TL) { return true; }
+struct ReferenceLocInfo {
+ SourceLocation AmpLoc;
};
/// \brief Wrapper for source info for references.
-class ReferenceLoc : public DeclaratorLoc {
- struct Info {
- SourceLocation AmpLoc;
- };
-
+class ReferenceLoc : public ConcreteTypeLoc<DeclaratorLoc,
+ ReferenceLoc,
+ ReferenceType,
+ ReferenceLocInfo> {
public:
SourceLocation getAmpLoc() const {
- return static_cast<Info*>(Data)->AmpLoc;
+ return getLocalData()->AmpLoc;
}
void setAmpLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->AmpLoc = Loc;
+ getLocalData()->AmpLoc = Loc;
}
TypeLoc getPointeeLoc() const {
- void *Next = static_cast<char*>(Data) + getLocalDataSize();
- return TypeLoc(cast<ReferenceType>(Ty)->getPointeeType(), Next);
+ return TypeLoc(getTypePtr()->getPointeeType(), getNonLocalData());
}
/// \brief Find the TypeSpecLoc that is part of this ReferenceLoc.
return SourceRange(getAmpLoc(), getAmpLoc());
}
- /// \brief Returns the size of the type source info data block that is
- /// specific to this type.
- unsigned getLocalDataSize() const { return sizeof(Info); }
+ bool hasInnerType() const { return true; }
+ QualType getInnerType() const { return getTypePtr()->getPointeeType(); }
+};
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const {
- return getLocalDataSize() + getPointeeLoc().getFullDataSize();
- }
- static bool classof(const TypeLoc *TL);
- static bool classof(const ReferenceLoc *TL) { return true; }
+struct FunctionLocInfo {
+ SourceLocation LParenLoc, RParenLoc;
};
/// \brief Wrapper for source info for functions.
-class FunctionLoc : public DeclaratorLoc {
- struct Info {
- SourceLocation LParenLoc, RParenLoc;
- };
+class FunctionLoc : public ConcreteTypeLoc<DeclaratorLoc,
+ FunctionLoc,
+ FunctionType,
+ FunctionLocInfo> {
// ParmVarDecls* are stored after Info, one for each argument.
ParmVarDecl **getParmArray() const {
- return reinterpret_cast<ParmVarDecl**>(static_cast<Info*>(Data) + 1);
+ return (ParmVarDecl**) getExtraLocalData();
}
public:
SourceLocation getLParenLoc() const {
- return static_cast<Info*>(Data)->LParenLoc;
+ return getLocalData()->LParenLoc;
}
void setLParenLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->LParenLoc = Loc;
+ getLocalData()->LParenLoc = Loc;
}
SourceLocation getRParenLoc() const {
- return static_cast<Info*>(Data)->RParenLoc;
+ return getLocalData()->RParenLoc;
}
void setRParenLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->RParenLoc = Loc;
+ getLocalData()->RParenLoc = Loc;
}
unsigned getNumArgs() const {
- if (isa<FunctionNoProtoType>(Ty))
+ if (isa<FunctionNoProtoType>(getTypePtr()))
return 0;
- return cast<FunctionProtoType>(Ty)->getNumArgs();
+ return cast<FunctionProtoType>(getTypePtr())->getNumArgs();
}
ParmVarDecl *getArg(unsigned i) const { return getParmArray()[i]; }
void setArg(unsigned i, ParmVarDecl *VD) { getParmArray()[i] = VD; }
TypeLoc getArgLoc(unsigned i) const;
TypeLoc getResultLoc() const {
- void *Next = static_cast<char*>(Data) + getLocalDataSize();
- return TypeLoc(cast<FunctionType>(Ty)->getResultType(), Next);
+ return getInnerTypeLoc();
}
/// \brief Find the TypeSpecLoc that is part of this FunctionLoc.
/// \brief Returns the size of the type source info data block that is
/// specific to this type.
- unsigned getLocalDataSize() const {
- return sizeof(Info) + getNumArgs() * sizeof(ParmVarDecl*);
+ unsigned getExtraLocalDataSize() const {
+ return getNumArgs() * sizeof(ParmVarDecl*);
}
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const {
- return getLocalDataSize() + getResultLoc().getFullDataSize();
- }
+ bool hasInnerType() const { return true; }
+ QualType getInnerType() const { return getTypePtr()->getResultType(); }
+};
+
- static bool classof(const TypeLoc *TL);
- static bool classof(const FunctionLoc *TL) { return true; }
+struct ArrayLocInfo {
+ SourceLocation LBracketLoc, RBracketLoc;
+ Expr *Size;
};
/// \brief Wrapper for source info for arrays.
-class ArrayLoc : public DeclaratorLoc {
- struct Info {
- SourceLocation LBracketLoc, RBracketLoc;
- Expr *Size;
- };
+class ArrayLoc : public ConcreteTypeLoc<DeclaratorLoc,
+ ArrayLoc,
+ ArrayType,
+ ArrayLocInfo> {
public:
SourceLocation getLBracketLoc() const {
- return static_cast<Info*>(Data)->LBracketLoc;
+ return getLocalData()->LBracketLoc;
}
void setLBracketLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->LBracketLoc = Loc;
+ getLocalData()->LBracketLoc = Loc;
}
SourceLocation getRBracketLoc() const {
- return static_cast<Info*>(Data)->RBracketLoc;
+ return getLocalData()->RBracketLoc;
}
void setRBracketLoc(SourceLocation Loc) {
- static_cast<Info*>(Data)->RBracketLoc = Loc;
+ getLocalData()->RBracketLoc = Loc;
}
Expr *getSizeExpr() const {
- return static_cast<Info*>(Data)->Size;
+ return getLocalData()->Size;
}
void setSizeExpr(Expr *Size) {
- static_cast<Info*>(Data)->Size = Size;
+ getLocalData()->Size = Size;
}
TypeLoc getElementLoc() const {
- void *Next = static_cast<char*>(Data) + getLocalDataSize();
- return TypeLoc(cast<ArrayType>(Ty)->getElementType(), Next);
+ return getInnerTypeLoc();
}
/// \brief Find the TypeSpecLoc that is part of this ArrayLoc.
return SourceRange(getLBracketLoc(), getRBracketLoc());
}
- /// \brief Returns the size of the type source info data block that is
- /// specific to this type.
- unsigned getLocalDataSize() const { return sizeof(Info); }
-
- /// \brief Returns the size of the type source info data block.
- unsigned getFullDataSize() const {
- return getLocalDataSize() + getElementLoc().getFullDataSize();
- }
-
- static bool classof(const TypeLoc *TL);
- static bool classof(const ArrayLoc *TL) { return true; }
+ bool hasInnerType() const { return true; }
+ QualType getInnerType() const { return getTypePtr()->getElementType(); }
};
}
//
//===----------------------------------------------------------------------===//
+#include "llvm/Support/raw_ostream.h"
#include "clang/AST/TypeLocVisitor.h"
using namespace clang;
class TypeLocRanger : public TypeLocVisitor<TypeLocRanger, SourceRange> {
public:
#define ABSTRACT_TYPELOC(CLASS)
-#define TYPELOC(CLASS, PARENT, TYPE) \
+#define TYPELOC(CLASS, PARENT) \
SourceRange Visit##CLASS(CLASS TyLoc) { return TyLoc.getSourceRange(); }
#include "clang/AST/TypeLocNodes.def"
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();
-}
-
/// \brief Find the TypeSpecLoc that is part of this TypeLoc.
TypeSpecLoc TypeLoc::getTypeSpecLoc() const {
if (isNull())
return TypeSpecLoc();
-
- if (const DeclaratorLoc *DL = dyn_cast<DeclaratorLoc>(this))
+ UnqualTypeLoc Cur = getUnqualifiedLoc();
+ if (const DeclaratorLoc *DL = dyn_cast<DeclaratorLoc>(&Cur))
return DL->getTypeSpecLoc();
- return cast<TypeSpecLoc>(*this);
-}
-
-/// \brief Find the TypeSpecLoc that is part of this TypeLoc and return its
-/// SourceRange.
-SourceRange TypeLoc::getTypeSpecRange() const {
- return getTypeSpecLoc().getSourceRange();
+ return cast<TypeSpecLoc>(Cur);
}
namespace {
class TypeSizer : public TypeLocVisitor<TypeSizer, unsigned> {
public:
#define ABSTRACT_TYPELOC(CLASS)
-#define TYPELOC(CLASS, PARENT, TYPE) \
+#define TYPELOC(CLASS, PARENT) \
unsigned Visit##CLASS(CLASS TyLoc) { return TyLoc.getFullDataSize(); }
#include "clang/AST/TypeLocNodes.def"
}
/// \brief Returns the size of the type source info data block.
-unsigned TypeLoc::getFullDataSize() const {
- if (isNull()) return 0;
- return TypeSizer().Visit(*this);
+unsigned TypeLoc::getFullDataSizeForType(QualType Ty) {
+ if (Ty.isNull()) return 0;
+ return TypeSizer().Visit(TypeLoc(Ty, 0));
}
namespace {
/// TypeLoc is a PointerLoc and next TypeLoc is for "int".
class NextLoc : public TypeLocVisitor<NextLoc, TypeLoc> {
public:
-#define TYPELOC(CLASS, PARENT, TYPE)
+#define TYPELOC(CLASS, PARENT)
#define DECLARATOR_TYPELOC(CLASS, TYPE) \
- TypeLoc Visit##CLASS(CLASS TyLoc);
+ TypeLoc Visit##CLASS(CLASS TyLoc);
#include "clang/AST/TypeLocNodes.def"
TypeLoc VisitTypeSpecLoc(TypeLoc TyLoc) { return TypeLoc(); }
TypeLoc VisitObjCProtocolListLoc(ObjCProtocolListLoc TL);
+ TypeLoc VisitQualifiedLoc(QualifiedLoc TyLoc) {
+ return TyLoc.getUnqualifiedLoc();
+ }
TypeLoc VisitTypeLoc(TypeLoc TyLoc) {
assert(0 && "A declarator loc wrapper was not handled!");
/// \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);
+ //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;
}
//===----------------------------------------------------------------------===//
}
-bool TypeSpecLoc::classof(const TypeLoc *TL) {
+bool TypeSpecLoc::classof(const UnqualTypeLoc *TL) {
return TypeSpecChecker().Visit(*TL);
}
/// \brief Return the TypeSpecLoc for the visited DeclaratorLoc.
class TypeSpecGetter : public TypeLocVisitor<TypeSpecGetter, TypeSpecLoc> {
public:
-#define TYPELOC(CLASS, PARENT, TYPE)
+#define TYPELOC(CLASS, PARENT)
#define DECLARATOR_TYPELOC(CLASS, TYPE) \
TypeSpecLoc Visit##CLASS(CLASS TyLoc) { return TyLoc.getTypeSpecLoc(); }
#include "clang/AST/TypeLocNodes.def"
assert(0 && "A declarator loc wrapper was not handled!");
return TypeSpecLoc();
}
+
+ TypeSpecLoc VisitQualifiedLoc(QualifiedLoc TyLoc) {
+ return Visit(TyLoc.getUnqualifiedLoc());
+ }
};
}
}
-bool DeclaratorLoc::classof(const TypeLoc *TL) {
+bool DeclaratorLoc::classof(const UnqualTypeLoc *TL) {
return DeclaratorLocChecker().Visit(*TL);
}
}
-bool DefaultTypeSpecLoc::classof(const TypeLoc *TL) {
- return DefaultTypeSpecLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// TypedefLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class TypedefLocChecker : public TypeLocVisitor<TypedefLocChecker, bool> {
-public:
- bool VisitTypedefLoc(TypedefLoc TyLoc) { return true; }
-};
-
-}
-
-bool TypedefLoc::classof(const TypeLoc *TL) {
- return TypedefLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// ObjCInterfaceLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class ObjCInterfaceLocChecker :
- public TypeLocVisitor<ObjCInterfaceLocChecker, bool> {
-public:
- bool VisitObjCInterfaceLoc(ObjCInterfaceLoc TyLoc) { return true; }
-};
-
-}
-
-bool ObjCInterfaceLoc::classof(const TypeLoc *TL) {
- return ObjCInterfaceLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// ObjCProtocolListLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class ObjCProtocolListLocChecker :
- public TypeLocVisitor<ObjCProtocolListLocChecker, bool> {
-public:
- bool VisitObjCProtocolListLoc(ObjCProtocolListLoc TyLoc) { return true; }
-};
-
-}
-
-bool ObjCProtocolListLoc::classof(const TypeLoc *TL) {
- return ObjCProtocolListLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// PointerLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class PointerLocChecker : public TypeLocVisitor<PointerLocChecker, bool> {
-public:
- bool VisitPointerLoc(PointerLoc TyLoc) { return true; }
-};
-
-}
-
-bool PointerLoc::classof(const TypeLoc *TL) {
- return PointerLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// BlockPointerLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class BlockPointerLocChecker :
- public TypeLocVisitor<BlockPointerLocChecker, bool> {
-public:
- bool VisitBlockPointerLoc(BlockPointerLoc TyLoc) { return true; }
-};
-
-}
-
-bool BlockPointerLoc::classof(const TypeLoc *TL) {
- return BlockPointerLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// MemberPointerLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class MemberPointerLocChecker :
- public TypeLocVisitor<MemberPointerLocChecker, bool> {
-public:
- bool VisitMemberPointerLoc(MemberPointerLoc TyLoc) { return true; }
-};
-
-}
-
-bool MemberPointerLoc::classof(const TypeLoc *TL) {
- return MemberPointerLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// ReferenceLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class ReferenceLocChecker : public TypeLocVisitor<ReferenceLocChecker, bool> {
-public:
- bool VisitReferenceLoc(ReferenceLoc TyLoc) { return true; }
-};
-
-}
-
-bool ReferenceLoc::classof(const TypeLoc *TL) {
- return ReferenceLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// FunctionLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class FunctionLocChecker : public TypeLocVisitor<FunctionLocChecker, bool> {
-public:
- bool VisitFunctionLoc(FunctionLoc TyLoc) { return true; }
-};
-
-}
-
-bool FunctionLoc::classof(const TypeLoc *TL) {
- return FunctionLocChecker().Visit(*TL);
-}
-
-//===----------------------------------------------------------------------===//
-// ArrayLoc Implementation
-//===----------------------------------------------------------------------===//
-
-namespace {
-
-class ArrayLocChecker : public TypeLocVisitor<ArrayLocChecker, bool> {
-public:
- bool VisitArrayLoc(ArrayLoc TyLoc) { return true; }
-};
-
-}
-
-bool ArrayLoc::classof(const TypeLoc *TL) {
- return ArrayLocChecker().Visit(*TL);
+bool DefaultTypeSpecLoc::classofType(const Type *Ty) {
+ return
+ DefaultTypeSpecLocChecker().Visit(UnqualTypeLoc(const_cast<Type*>(Ty), 0));
}
+