#include "clang/Basic/Specifiers.h"
namespace clang {
+ class ASTContext;
class ParmVarDecl;
class TypeSourceInfo;
class UnqualTypeLoc;
///
/// This method exists to provide a simple transition for code that
/// relies on location-less types.
- void initialize(SourceLocation Loc) const {
- initializeImpl(*this, Loc);
+ void initialize(ASTContext &Context, SourceLocation Loc) const {
+ initializeImpl(Context, *this, Loc);
}
/// \brief Initializes this by copying its information from another
static bool classof(const TypeLoc *TL) { return true; }
private:
- static void initializeImpl(TypeLoc TL, SourceLocation Loc);
+ static void initializeImpl(ASTContext &Context, TypeLoc TL, SourceLocation Loc);
static TypeLoc getNextTypeLocImpl(TypeLoc TL);
static TypeLoc IgnoreParensImpl(TypeLoc TL);
static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
/// Initializes the local data of this type source info block to
/// provide no information.
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
// do nothing
}
SourceRange getLocalSourceRange() const {
return SourceRange(getNameLoc(), getNameLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setNameLoc(Loc);
}
getWrittenBuiltinSpecs().ModeAttr = written;
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setBuiltinLoc(Loc);
if (needsExtraLocalData()) {
WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs();
return range;
}
- void initializeLocal(SourceLocation loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation loc) {
setAttrNameLoc(loc);
if (hasAttrExprOperand()) {
setAttrOperandParensRange(SourceRange(loc));
return SourceRange(getLAngleLoc(), getRAngleLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setHasBaseTypeAsWritten(true);
setLAngleLoc(Loc);
setRAngleLoc(Loc);
return SourceRange(getNameLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setNameLoc(Loc);
}
};
return SourceRange(getLParenLoc(), getRParenLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setLParenLoc(Loc);
setRParenLoc(Loc);
}
return SourceRange(getSigilLoc(), getSigilLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setSigilLoc(Loc);
}
return SourceRange(getLParenLoc(), getRParenLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setLParenLoc(Loc);
setRParenLoc(Loc);
setTrailingReturn(false);
return SourceRange(getLBracketLoc(), getRBracketLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setLBracketLoc(Loc);
setRBracketLoc(Loc);
setSizeExpr(NULL);
return SourceRange(getTemplateNameLoc(), getRAngleLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setLAngleLoc(Loc);
setRAngleLoc(Loc);
setTemplateNameLoc(Loc);
- initializeArgLocs(getNumArgs(), getTypePtr()->getArgs(),
+ initializeArgLocs(Context, getNumArgs(), getTypePtr()->getArgs(),
getArgInfos(), Loc);
}
- static void initializeArgLocs(unsigned NumArgs,
+ static void initializeArgLocs(ASTContext &Context, unsigned NumArgs,
const TemplateArgument *Args,
TemplateArgumentLocInfo *ArgInfos,
- SourceLocation Loc) {
- for (unsigned i = 0, e = NumArgs; i != e; ++i) {
- // FIXME: We can generate better location info here for type arguments,
- // template template arguments, and template template pack expansions (?).
- ArgInfos[i] = TemplateArgumentLocInfo();
- }
- }
+ SourceLocation Loc);
unsigned getExtraLocalDataSize() const {
return getNumArgs() * sizeof(TemplateArgumentLocInfo);
return SourceRange(getTypeofLoc(), getRParenLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setTypeofLoc(Loc);
setLParenLoc(Loc);
setRParenLoc(Loc);
return getQualifierRange();
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setKeywordLoc(Loc);
setQualifierRange(SourceRange(Loc));
}
memcpy(Data, Loc.Data, size);
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setKeywordLoc(Loc);
setQualifierRange(SourceRange(Loc));
setNameLoc(Loc);
memcpy(Data, Loc.Data, size);
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setKeywordLoc(Loc);
setQualifierRange(SourceRange(Loc));
setNameLoc(Loc);
setLAngleLoc(Loc);
setRAngleLoc(Loc);
- TemplateSpecializationTypeLoc::initializeArgLocs(getNumArgs(),
+ TemplateSpecializationTypeLoc::initializeArgLocs(Context, getNumArgs(),
getTypePtr()->getArgs(),
getArgInfos(), Loc);
}
return SourceRange(getEllipsisLoc(), getEllipsisLoc());
}
- void initializeLocal(SourceLocation Loc) {
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
setEllipsisLoc(Loc);
}
/// \brief Initializes a type location, and all of its children
/// recursively, as if the entire tree had been written in the
/// given location.
-void TypeLoc::initializeImpl(TypeLoc TL, SourceLocation Loc) {
+void TypeLoc::initializeImpl(ASTContext &Context, TypeLoc TL,
+ SourceLocation Loc) {
while (true) {
switch (TL.getTypeLocClass()) {
#define ABSTRACT_TYPELOC(CLASS, PARENT)
#define TYPELOC(CLASS, PARENT) \
case CLASS: { \
CLASS##TypeLoc TLCasted = cast<CLASS##TypeLoc>(TL); \
- TLCasted.initializeLocal(Loc); \
+ TLCasted.initializeLocal(Context, Loc); \
TL = TLCasted.getNextTypeLoc(); \
if (!TL) return; \
continue; \
TL = PTL->getInnerLoc();
return TL;
}
+
+void TemplateSpecializationTypeLoc::initializeArgLocs(ASTContext &Context,
+ unsigned NumArgs,
+ const TemplateArgument *Args,
+ TemplateArgumentLocInfo *ArgInfos,
+ SourceLocation Loc) {
+ for (unsigned i = 0, e = NumArgs; i != e; ++i) {
+ switch (Args[i].getKind()) {
+ case TemplateArgument::Null:
+ case TemplateArgument::Declaration:
+ case TemplateArgument::Integral:
+ case TemplateArgument::Pack:
+ case TemplateArgument::Expression:
+ // FIXME: Can we do better for declarations and integral values?
+ ArgInfos[i] = TemplateArgumentLocInfo();
+ break;
+
+ case TemplateArgument::Type:
+ ArgInfos[i] = TemplateArgumentLocInfo(
+ Context.getTrivialTypeSourceInfo(Args[i].getAsType(),
+ Loc));
+ break;
+
+ case TemplateArgument::Template:
+ ArgInfos[i] = TemplateArgumentLocInfo(SourceRange(Loc), Loc,
+ SourceLocation());
+ break;
+
+ case TemplateArgument::TemplateExpansion:
+ ArgInfos[i] = TemplateArgumentLocInfo(SourceRange(Loc), Loc, Loc);
+ break;
+ }
+ }
+}
+
namespace {
class TypeSpecLocFiller : public TypeLocVisitor<TypeSpecLocFiller> {
+ ASTContext &Context;
const DeclSpec &DS;
public:
- TypeSpecLocFiller(const DeclSpec &DS) : DS(DS) {}
+ TypeSpecLocFiller(ASTContext &Context, const DeclSpec &DS)
+ : Context(Context), DS(DS) {}
void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
Visit(TL.getUnqualifiedLoc());
// Handle the base type, which might not have been written explicitly.
if (DS.getTypeSpecType() == DeclSpec::TST_unspecified) {
TL.setHasBaseTypeAsWritten(false);
- TL.getBaseLoc().initialize(SourceLocation());
+ TL.getBaseLoc().initialize(Context, SourceLocation());
} else {
TL.setHasBaseTypeAsWritten(true);
Visit(TL.getBaseLoc());
// If we got no declarator info from previous Sema routines,
// just fill with the typespec loc.
if (!TInfo) {
- TL.initialize(DS.getTypeSpecTypeLoc());
+ TL.initialize(Context, DS.getTypeSpecTypeLoc());
return;
}
return;
}
}
- TL.initializeLocal(SourceLocation());
+ TL.initializeLocal(Context, SourceLocation());
TL.setKeywordLoc(Keyword != ETK_None
? DS.getTypeSpecTypeLoc()
: SourceLocation());
void VisitTypeLoc(TypeLoc TL) {
// FIXME: add other typespec types and change this to an assert.
- TL.initialize(DS.getTypeSpecTypeLoc());
+ TL.initialize(Context, DS.getTypeSpecTypeLoc());
}
};
assert(TL.getFullDataSize() == CurrTL.getFullDataSize());
memcpy(CurrTL.getOpaqueData(), TL.getOpaqueData(), TL.getFullDataSize());
} else {
- TypeSpecLocFiller(D.getDeclSpec()).Visit(CurrTL);
+ TypeSpecLocFiller(Context, D.getDeclSpec()).Visit(CurrTL);
}
return TInfo;