From: Sebastian Redl Date: Sat, 16 May 2009 18:50:46 +0000 (+0000) Subject: Implement instantiation of a few boring, simple expressions. I don't think these... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b0b475b3464b0f70b91ba7d679d23c424677d5e;p=clang Implement instantiation of a few boring, simple expressions. I don't think these are testable yet, though. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71953 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index eceb93e64a..c7dfffce9f 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -361,6 +361,8 @@ public: explicit PredefinedExpr(EmptyShell Empty) : Expr(PredefinedExprClass, Empty) { } + PredefinedExpr* Clone(ASTContext &C) const; + IdentType getIdentType() const { return Type; } void setIdentType(IdentType IT) { Type = IT; } @@ -433,6 +435,8 @@ public: /// \brief Construct an empty character literal. CharacterLiteral(EmptyShell Empty) : Expr(CharacterLiteralClass, Empty) { } + CharacterLiteral* Clone(ASTContext &C) const; + SourceLocation getLoc() const { return Loc; } bool isWide() const { return IsWide; } @@ -464,9 +468,11 @@ public: : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {} /// \brief Construct an empty floating-point literal. - FloatingLiteral(EmptyShell Empty) + explicit FloatingLiteral(EmptyShell Empty) : Expr(FloatingLiteralClass, Empty), Value(0.0) { } + FloatingLiteral* Clone(ASTContext &C) const; + const llvm::APFloat &getValue() const { return Value; } void setValue(const llvm::APFloat &Val) { Value = Val; } @@ -1806,6 +1812,8 @@ public: /// \brief Build an empty GNU __null expression. explicit GNUNullExpr(EmptyShell Empty) : Expr(GNUNullExprClass, Empty) { } + GNUNullExpr* Clone(ASTContext &C) const; + /// getTokenLocation - The location of the __null token. SourceLocation getTokenLocation() const { return TokenLoc; } void setTokenLocation(SourceLocation L) { TokenLoc = L; } diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index b6a970e231..d9cd35836b 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -207,7 +207,9 @@ class CXXBoolLiteralExpr : public Expr { public: CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {} - + + CXXBoolLiteralExpr* Clone(ASTContext &C) const; + bool getValue() const { return Value; } virtual SourceRange getSourceRange() const { return SourceRange(Loc); } @@ -229,6 +231,8 @@ public: CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : Expr(CXXNullPtrLiteralExprClass, Ty), Loc(l) {} + CXXNullPtrLiteralExpr* Clone(ASTContext &C) const; + virtual SourceRange getSourceRange() const { return SourceRange(Loc); } static bool classof(const Stmt *T) { diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 9a860033df..3133a8f42c 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -27,10 +27,27 @@ using namespace clang; // Primary Expressions. //===----------------------------------------------------------------------===// +PredefinedExpr* PredefinedExpr::Clone(ASTContext &C) const { + return new (C) PredefinedExpr(Loc, getType(), Type); +} + IntegerLiteral* IntegerLiteral::Clone(ASTContext &C) const { return new (C) IntegerLiteral(Value, getType(), Loc); } +CharacterLiteral* CharacterLiteral::Clone(ASTContext &C) const { + return new (C) CharacterLiteral(Value, IsWide, getType(), Loc); +} + +FloatingLiteral* FloatingLiteral::Clone(ASTContext &C) const { + bool exact = IsExact; + return new (C) FloatingLiteral(Value, &exact, getType(), Loc); +} + +GNUNullExpr* GNUNullExpr::Clone(ASTContext &C) const { + return new (C) GNUNullExpr(getType(), TokenLoc); +} + /// getValueAsApproximateDouble - This returns the value as an inaccurate /// double. Note that this may cause loss of precision, but is useful for /// debugging dumps, etc. diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 8176db5bf5..71617c4df2 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -309,3 +309,15 @@ Stmt::child_iterator CXXExprWithTemporaries::child_end() { return &SubExpr + 1; } + +//===----------------------------------------------------------------------===// +// Cloners +//===----------------------------------------------------------------------===// + +CXXBoolLiteralExpr* CXXBoolLiteralExpr::Clone(ASTContext &C) const { + return new (C) CXXBoolLiteralExpr(Value, getType(), Loc); +} + +CXXNullPtrLiteralExpr* CXXNullPtrLiteralExpr::Clone(ASTContext &C) const { + return new (C) CXXNullPtrLiteralExpr(getType(), Loc); +} diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp index f90454f5e4..3c3fb7e98e 100644 --- a/lib/Sema/SemaTemplateInstantiateExpr.cpp +++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp @@ -36,7 +36,11 @@ namespace { // FIXME: Once we get closer to completion, replace these manually-written // declarations with automatically-generated ones from // clang/AST/StmtNodes.def. + OwningExprResult VisitPredefinedExpr(PredefinedExpr *E); OwningExprResult VisitIntegerLiteral(IntegerLiteral *E); + OwningExprResult VisitFloatingLiteral(FloatingLiteral *E); + OwningExprResult VisitStringLiteral(StringLiteral *E); + OwningExprResult VisitCharacterLiteral(CharacterLiteral *E); OwningExprResult VisitDeclRefExpr(DeclRefExpr *E); OwningExprResult VisitParenExpr(ParenExpr *E); OwningExprResult VisitUnaryOperator(UnaryOperator *E); @@ -49,7 +53,10 @@ namespace { OwningExprResult VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E); OwningExprResult VisitImplicitCastExpr(ImplicitCastExpr *E); OwningExprResult VisitCXXThisExpr(CXXThisExpr *E); - + OwningExprResult VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); + OwningExprResult VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); + OwningExprResult VisitGNUNullExpr(GNUNullExpr *E); + // Base case. I'm supposed to ignore this. Sema::OwningExprResult VisitStmt(Stmt *S) { S->dump(); @@ -59,11 +66,46 @@ namespace { }; } -Sema::OwningExprResult +Sema::OwningExprResult +TemplateExprInstantiator::VisitPredefinedExpr(PredefinedExpr *E) { + return SemaRef.Clone(E); +} + +Sema::OwningExprResult TemplateExprInstantiator::VisitIntegerLiteral(IntegerLiteral *E) { return SemaRef.Clone(E); } +Sema::OwningExprResult +TemplateExprInstantiator::VisitFloatingLiteral(FloatingLiteral *E) { + return SemaRef.Clone(E); +} + +Sema::OwningExprResult +TemplateExprInstantiator::VisitStringLiteral(StringLiteral *E) { + return SemaRef.Clone(E); +} + +Sema::OwningExprResult +TemplateExprInstantiator::VisitCharacterLiteral(CharacterLiteral *E) { + return SemaRef.Clone(E); +} + +Sema::OwningExprResult +TemplateExprInstantiator::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { + return SemaRef.Clone(E); +} + +Sema::OwningExprResult +TemplateExprInstantiator::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { + return SemaRef.Clone(E); +} + +Sema::OwningExprResult +TemplateExprInstantiator::VisitGNUNullExpr(GNUNullExpr *E) { + return SemaRef.Clone(E); +} + Sema::OwningExprResult TemplateExprInstantiator::VisitDeclRefExpr(DeclRefExpr *E) { Decl *D = E->getDecl();