зеркало из https://github.com/microsoft/clang-1.git
Add the ability to clone integer and string literals. Use it when instantiating template expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67030 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
f53597fb16
Коммит
a135fb43eb
|
@ -377,6 +377,9 @@ public:
|
||||||
: Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
|
: Expr(IntegerLiteralClass, type), Value(V), Loc(l) {
|
||||||
assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
|
assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IntegerLiteral* Clone(ASTContext &C) const;
|
||||||
|
|
||||||
const llvm::APInt &getValue() const { return Value; }
|
const llvm::APInt &getValue() const { return Value; }
|
||||||
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
|
virtual SourceRange getSourceRange() const { return SourceRange(Loc); }
|
||||||
|
|
||||||
|
@ -515,7 +518,7 @@ public:
|
||||||
/// strings formed from multiple concatenated tokens.
|
/// strings formed from multiple concatenated tokens.
|
||||||
static StringLiteral *Create(ASTContext &C, const char *StrData,
|
static StringLiteral *Create(ASTContext &C, const char *StrData,
|
||||||
unsigned ByteLength, bool Wide, QualType Ty,
|
unsigned ByteLength, bool Wide, QualType Ty,
|
||||||
SourceLocation *Loc, unsigned NumStrs);
|
const SourceLocation *Loc, unsigned NumStrs);
|
||||||
|
|
||||||
/// Simple constructor for string literals made from one token.
|
/// Simple constructor for string literals made from one token.
|
||||||
static StringLiteral *Create(ASTContext &C, const char *StrData,
|
static StringLiteral *Create(ASTContext &C, const char *StrData,
|
||||||
|
@ -523,7 +526,8 @@ public:
|
||||||
bool Wide, QualType Ty, SourceLocation Loc) {
|
bool Wide, QualType Ty, SourceLocation Loc) {
|
||||||
return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
|
return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringLiteral* Clone(ASTContext &C) const;
|
||||||
void Destroy(ASTContext &C);
|
void Destroy(ASTContext &C);
|
||||||
|
|
||||||
const char *getStrData() const { return StrData; }
|
const char *getStrData() const { return StrData; }
|
||||||
|
|
|
@ -26,6 +26,10 @@ using namespace clang;
|
||||||
// Primary Expressions.
|
// Primary Expressions.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
IntegerLiteral* IntegerLiteral::Clone(ASTContext &C) const {
|
||||||
|
return new (C) IntegerLiteral(Value, getType(), Loc);
|
||||||
|
}
|
||||||
|
|
||||||
/// getValueAsApproximateDouble - This returns the value as an inaccurate
|
/// getValueAsApproximateDouble - This returns the value as an inaccurate
|
||||||
/// double. Note that this may cause loss of precision, but is useful for
|
/// double. Note that this may cause loss of precision, but is useful for
|
||||||
/// debugging dumps, etc.
|
/// debugging dumps, etc.
|
||||||
|
@ -40,7 +44,8 @@ double FloatingLiteral::getValueAsApproximateDouble() const {
|
||||||
StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData,
|
StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData,
|
||||||
unsigned ByteLength, bool Wide,
|
unsigned ByteLength, bool Wide,
|
||||||
QualType Ty,
|
QualType Ty,
|
||||||
SourceLocation *Loc, unsigned NumStrs) {
|
const SourceLocation *Loc,
|
||||||
|
unsigned NumStrs) {
|
||||||
// Allocate enough space for the StringLiteral plus an array of locations for
|
// Allocate enough space for the StringLiteral plus an array of locations for
|
||||||
// any concatenated string tokens.
|
// any concatenated string tokens.
|
||||||
void *Mem = C.Allocate(sizeof(StringLiteral)+
|
void *Mem = C.Allocate(sizeof(StringLiteral)+
|
||||||
|
@ -62,6 +67,10 @@ StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData,
|
||||||
return SL;
|
return SL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringLiteral* StringLiteral::Clone(ASTContext &C) const {
|
||||||
|
return Create(C, StrData, ByteLength, IsWide, getType(),
|
||||||
|
TokLocs, NumConcatenated);
|
||||||
|
}
|
||||||
|
|
||||||
void StringLiteral::Destroy(ASTContext &C) {
|
void StringLiteral::Destroy(ASTContext &C) {
|
||||||
C.Deallocate(const_cast<char*>(StrData));
|
C.Deallocate(const_cast<char*>(StrData));
|
||||||
|
|
|
@ -1867,6 +1867,14 @@ public:
|
||||||
ClassTemplateSpecializationDecl *ClassTemplateSpec,
|
ClassTemplateSpecializationDecl *ClassTemplateSpec,
|
||||||
bool ExplicitInstantiation);
|
bool ExplicitInstantiation);
|
||||||
|
|
||||||
|
// Simple function for cloning expressions.
|
||||||
|
template<typename T>
|
||||||
|
OwningExprResult Clone(T *E) {
|
||||||
|
assert(!E->isValueDependent() && !E->isTypeDependent() &&
|
||||||
|
"expression is value or type dependent!");
|
||||||
|
return Owned(E->Clone(Context));
|
||||||
|
}
|
||||||
|
|
||||||
// Objective-C declarations.
|
// Objective-C declarations.
|
||||||
virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
|
virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
|
||||||
IdentifierInfo *ClassName,
|
IdentifierInfo *ClassName,
|
||||||
|
|
|
@ -591,7 +591,8 @@ namespace {
|
||||||
OwningExprResult VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
|
OwningExprResult VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E);
|
||||||
|
|
||||||
// Base case. I'm supposed to ignore this.
|
// Base case. I'm supposed to ignore this.
|
||||||
Sema::OwningExprResult VisitStmt(Stmt *) {
|
Sema::OwningExprResult VisitStmt(Stmt *S) {
|
||||||
|
S->dump();
|
||||||
assert(false && "Cannot instantiate this kind of expression");
|
assert(false && "Cannot instantiate this kind of expression");
|
||||||
return SemaRef.ExprError();
|
return SemaRef.ExprError();
|
||||||
}
|
}
|
||||||
|
@ -600,10 +601,7 @@ namespace {
|
||||||
|
|
||||||
Sema::OwningExprResult
|
Sema::OwningExprResult
|
||||||
TemplateExprInstantiator::VisitIntegerLiteral(IntegerLiteral *E) {
|
TemplateExprInstantiator::VisitIntegerLiteral(IntegerLiteral *E) {
|
||||||
// FIXME: Can't we just re-use the expression node?
|
return SemaRef.Clone(E);
|
||||||
return SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(E->getValue(),
|
|
||||||
E->getType(),
|
|
||||||
E->getLocation()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sema::OwningExprResult
|
Sema::OwningExprResult
|
||||||
|
|
Загрузка…
Ссылка в новой задаче