[cfe-commits] r91494 - in /cfe/trunk: clang.xcodeproj/project.pbxproj include/clang/AST/FullExpr.h include/clang/AST/Stmt.h include/clang/Parse/Action.h lib/AST/CMakeLists.txt lib/AST/FullExpr.cpp lib/Parse/ParseObjc.cpp lib/Parse/ParseStmt.cpp l
Daniel Dunbar
daniel at zuster.org
Mon Dec 21 08:39:28 PST 2009
On Tue, Dec 15, 2009 at 6:09 PM, Anders Carlsson <andersca at mac.com> wrote:
> Author: andersca
> Date: Tue Dec 15 20:09:40 2009
> New Revision: 91494
>
> URL: http://llvm.org/viewvc/llvm-project?rev=91494&view=rev
> Log:
> Check in a rudimentary FullExpr class that isn't used anywhere yet. Rename Action::FullExpr to Action::MakeFullExpr to avoid name clashes.
Nice!
> Added:
> cfe/trunk/include/clang/AST/FullExpr.h
> cfe/trunk/lib/AST/FullExpr.cpp
> Modified:
> cfe/trunk/clang.xcodeproj/project.pbxproj
> cfe/trunk/include/clang/AST/Stmt.h
> cfe/trunk/include/clang/Parse/Action.h
> cfe/trunk/lib/AST/CMakeLists.txt
> cfe/trunk/lib/Parse/ParseObjc.cpp
> cfe/trunk/lib/Parse/ParseStmt.cpp
> cfe/trunk/lib/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/lib/Sema/TreeTransform.h
>
> Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
> +++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Dec 15 20:09:40 2009
> @@ -46,6 +46,7 @@
> 1A869AA80BA21ABA008DA07A /* LiteralSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */; };
> 1A986AB710D0746D00A8EA9E /* CGDeclCXX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A986AB610D0746D00A8EA9E /* CGDeclCXX.cpp */; };
> 1AA1D91810125DE30078DEBC /* RecordLayoutBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AA1D91610125DE30078DEBC /* RecordLayoutBuilder.cpp */; };
> + 1AA963C410D85A7300786C86 /* FullExpr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AA963C310D85A7300786C86 /* FullExpr.cpp */; };
> 1ABC36940C7A4BDC006DB0AB /* CGBuiltin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */; };
> 1ADD795410A90C6100741BBA /* TypePrinter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ADD795110A90C6100741BBA /* TypePrinter.cpp */; };
> 1ADD795510A90C6100741BBA /* TypeLoc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ADD795210A90C6100741BBA /* TypeLoc.cpp */; };
> @@ -400,6 +401,8 @@
> 1A986AB610D0746D00A8EA9E /* CGDeclCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGDeclCXX.cpp; path = lib/CodeGen/CGDeclCXX.cpp; sourceTree = "<group>"; tabWidth = 2; };
> 1AA1D91610125DE30078DEBC /* RecordLayoutBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = RecordLayoutBuilder.cpp; path = lib/AST/RecordLayoutBuilder.cpp; sourceTree = "<group>"; tabWidth = 2; };
> 1AA1D91710125DE30078DEBC /* RecordLayoutBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = RecordLayoutBuilder.h; path = lib/AST/RecordLayoutBuilder.h; sourceTree = "<group>"; tabWidth = 2; };
> + 1AA963AB10D8576800786C86 /* FullExpr.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = FullExpr.h; path = clang/AST/FullExpr.h; sourceTree = "<group>"; tabWidth = 2; };
> + 1AA963C310D85A7300786C86 /* FullExpr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FullExpr.cpp; path = lib/AST/FullExpr.cpp; sourceTree = "<group>"; };
> 1AB290021045858B00FE33D8 /* PartialDiagnostic.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; path = PartialDiagnostic.h; sourceTree = "<group>"; tabWidth = 2; };
> 1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = CGBuiltin.cpp; path = lib/CodeGen/CGBuiltin.cpp; sourceTree = "<group>"; tabWidth = 2; };
> 1ADD795110A90C6100741BBA /* TypePrinter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TypePrinter.cpp; path = lib/AST/TypePrinter.cpp; sourceTree = "<group>"; };
> @@ -1348,6 +1351,7 @@
> DE0FCA620A95859D00248FD5 /* Expr.h */,
> 1A30A9E80B93A4C800201A91 /* ExprCXX.h */,
> 35CEA05A0DF9E82700A41296 /* ExprObjC.h */,
> + 1AA963AB10D8576800786C86 /* FullExpr.h */,
> DEDFE5CB0F7206CC0035BD10 /* NestedNameSpecifier.h */,
> 35EE48AE0E0C4CB200715C54 /* ParentMap.h */,
> 3547129D0C88881300B3E1D5 /* PrettyPrinter.h */,
> @@ -1385,6 +1389,7 @@
> DE0FCB330A9C21F100248FD5 /* Expr.cpp */,
> 1A32C17E0E1C87AD00A6B483 /* ExprConstant.cpp */,
> 35260CA40C7F75C000D66CE9 /* ExprCXX.cpp */,
> + 1AA963C310D85A7300786C86 /* FullExpr.cpp */,
> 3557D1A80EB136B100C59739 /* InheritViz.cpp */,
> DEDFE5CE0F7206E40035BD10 /* NestedNameSpecifier.cpp */,
> 35EE48B00E0C4CCA00715C54 /* ParentMap.cpp */,
> @@ -1929,6 +1934,7 @@
> 1ADD795610A90C6100741BBA /* TemplateBase.cpp in Sources */,
> 1A986AB710D0746D00A8EA9E /* CGDeclCXX.cpp in Sources */,
> E16B523510D30B2400430AC9 /* cc1_main.cpp in Sources */,
> + 1AA963C410D85A7300786C86 /* FullExpr.cpp in Sources */,
> );
> runOnlyForDeploymentPostprocessing = 0;
> };
>
> Added: cfe/trunk/include/clang/AST/FullExpr.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/FullExpr.h?rev=91494&view=auto
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/FullExpr.h (added)
> +++ cfe/trunk/include/clang/AST/FullExpr.h Tue Dec 15 20:09:40 2009
> @@ -0,0 +1,51 @@
> +//===--- FullExpr.h - C++ full expression class -----------------*- C++ -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This file defines the FullExpr interface, to be used for type safe handling
> +// of full expressions.
It might be nice to clarify this to make it clear "type safe" refers
to Clang's code, not the code we are compiling.
- Daniel
> +// Full expressions are described in C++ [intro.execution]p12.
> +//
> +//===----------------------------------------------------------------------===//
> +#ifndef LLVM_CLANG_AST_FULLEXPR_H
> +#define LLVM_CLANG_AST_FULLEXPR_H
> +
> +#include "llvm/ADT/PointerUnion.h"
> +
> +namespace clang {
> + class ASTContext;
> + class CXXTemporary;
> + class Expr;
> +
> + class FullExpr {
> + struct ExprAndTemporaries {
> + Expr *SubExpr;
> +
> + unsigned NumTemps;
> +
> + typedef CXXTemporary** iterator;
> +
> + iterator begin() { return reinterpret_cast<CXXTemporary **>(this + 1); }
> + iterator end() { return begin() + NumTemps; }
> +
> + };
> +
> + llvm::PointerUnion<Expr *, ExprAndTemporaries *> SubExpr;
> +
> + FullExpr() { }
> +
> + public:
> + static FullExpr Create(ASTContext &Context, Expr *SubExpr,
> + CXXTemporary **Temps, unsigned NumTemps);
> + };
> +
> +
> +} // end namespace clang
> +
> +#endif
>
> Modified: cfe/trunk/include/clang/AST/Stmt.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Stmt.h (original)
> +++ cfe/trunk/include/clang/AST/Stmt.h Tue Dec 15 20:09:40 2009
> @@ -20,6 +20,7 @@
> #include "clang/AST/PrettyPrinter.h"
> #include "clang/AST/StmtIterator.h"
> #include "clang/AST/DeclGroup.h"
> +#include "clang/AST/FullExpr.h"
> #include "llvm/ADT/SmallVector.h"
> #include "clang/AST/ASTContext.h"
> #include <string>
>
> Modified: cfe/trunk/include/clang/Parse/Action.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Parse/Action.h (original)
> +++ cfe/trunk/include/clang/Parse/Action.h Tue Dec 15 20:09:40 2009
> @@ -131,7 +131,7 @@
> };
>
> template<typename T>
> - FullExprArg FullExpr(T &Arg) {
> + FullExprArg MakeFullExpr(T &Arg) {
> return FullExprArg(ActOnFinishFullExpr(move(Arg)));
> }
>
>
> Modified: cfe/trunk/lib/AST/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/CMakeLists.txt (original)
> +++ cfe/trunk/lib/AST/CMakeLists.txt Tue Dec 15 20:09:40 2009
> @@ -16,6 +16,7 @@
> Expr.cpp
> ExprCXX.cpp
> ExprConstant.cpp
> + FullExpr.cpp
> InheritViz.cpp
> NestedNameSpecifier.cpp
> ParentMap.cpp
>
> Added: cfe/trunk/lib/AST/FullExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/FullExpr.cpp?rev=91494&view=auto
>
> ==============================================================================
> --- cfe/trunk/lib/AST/FullExpr.cpp (added)
> +++ cfe/trunk/lib/AST/FullExpr.cpp Tue Dec 15 20:09:40 2009
> @@ -0,0 +1,42 @@
> +//===--- FullExpr.cpp - C++ full expression class ---------------*- C++ -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +//
> +// This file defines the FullExpr interface, to be used for type safe handling
> +// of full expressions.
> +//
> +// Full expressions are described in C++ [intro.execution]p12.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#include "clang/AST/ASTContext.h"
> +#include "clang/AST/FullExpr.h"
> +#include "llvm/Support/AlignOf.h"
> +using namespace clang;
> +
> +FullExpr FullExpr::Create(ASTContext &Context, Expr *SubExpr,
> + CXXTemporary **Temporaries, unsigned NumTemporaries) {
> + FullExpr E;
> +
> + if (!NumTemporaries) {
> + E.SubExpr = SubExpr;
> + return E;
> + }
> +
> + unsigned Size = sizeof(FullExpr)
> + + sizeof(CXXTemporary *) * NumTemporaries;
> +
> + unsigned Align = llvm::AlignOf<ExprAndTemporaries>::Alignment;
> + ExprAndTemporaries *ET =
> + static_cast<ExprAndTemporaries *>(Context.Allocate(Size, Align));
> +
> + ET->SubExpr = SubExpr;
> + std::copy(Temporaries, Temporaries + NumTemporaries, ET->begin());
> +
> + return E;
> +}
>
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Dec 15 20:09:40 2009
> @@ -1589,7 +1589,7 @@
>
> // Otherwise, eat the semicolon.
> ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
> - return Actions.ActOnExprStmt(Actions.FullExpr(Res));
> + return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res));
> }
>
> Parser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
>
> Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseStmt.cpp Tue Dec 15 20:09:40 2009
> @@ -131,7 +131,7 @@
> }
> // Otherwise, eat the semicolon.
> ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
> - return Actions.ActOnExprStmt(Actions.FullExpr(Expr));
> + return Actions.ActOnExprStmt(Actions.MakeFullExpr(Expr));
> }
>
> case tok::kw_case: // C99 6.8.1: labeled-statement
> @@ -494,7 +494,7 @@
> // Eat the semicolon at the end of stmt and convert the expr into a
> // statement.
> ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr);
> - R = Actions.ActOnExprStmt(Actions.FullExpr(Res));
> + R = Actions.ActOnExprStmt(Actions.MakeFullExpr(Res));
> }
> }
>
> @@ -593,7 +593,7 @@
> if (ParseParenExprOrCondition(CondExp, CondVar))
> return StmtError();
>
> - FullExprArg FullCondExp(Actions.FullExpr(CondExp));
> + FullExprArg FullCondExp(Actions.MakeFullExpr(CondExp));
>
> // C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if
> // there is no compound stmt. C90 does not have this clause. We only do this
> @@ -720,7 +720,7 @@
> if (ParseParenExprOrCondition(Cond, CondVar))
> return StmtError();
>
> - FullExprArg FullCond(Actions.FullExpr(Cond));
> + FullExprArg FullCond(Actions.MakeFullExpr(Cond));
>
> OwningStmtResult Switch = Actions.ActOnStartOfSwitchStmt(FullCond, CondVar);
>
> @@ -801,7 +801,7 @@
> if (ParseParenExprOrCondition(Cond, CondVar))
> return StmtError();
>
> - FullExprArg FullCond(Actions.FullExpr(Cond));
> + FullExprArg FullCond(Actions.MakeFullExpr(Cond));
>
> // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if
> // there is no compound stmt. C90 does not have this clause. We only do this
> @@ -993,7 +993,7 @@
>
> // Turn the expression into a stmt.
> if (!Value.isInvalid())
> - FirstPart = Actions.ActOnExprStmt(Actions.FullExpr(Value));
> + FirstPart = Actions.ActOnExprStmt(Actions.MakeFullExpr(Value));
>
> if (Tok.is(tok::semi)) {
> ConsumeToken();
> @@ -1060,8 +1060,8 @@
>
> if (!ForEach)
> return Actions.ActOnForStmt(ForLoc, LParenLoc, move(FirstPart),
> - Actions.FullExpr(SecondPart), SecondVar,
> - Actions.FullExpr(ThirdPart), RParenLoc,
> + Actions.MakeFullExpr(SecondPart), SecondVar,
> + Actions.MakeFullExpr(ThirdPart), RParenLoc,
> move(Body));
>
> return Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
>
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Tue Dec 15 20:09:40 2009
> @@ -24,6 +24,7 @@
> #include "clang/AST/Decl.h"
> #include "clang/AST/DeclObjC.h"
> #include "clang/AST/DeclTemplate.h"
> +#include "clang/AST/FullExpr.h"
> #include "clang/Parse/Action.h"
> #include "clang/Sema/SemaDiagnostic.h"
> #include "llvm/ADT/SmallVector.h"
> @@ -2005,6 +2006,8 @@
> /// Otherwise, just returs the passed in expression.
> Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr);
>
> + FullExpr CreateFullExpr(Expr *SubExpr);
> +
> virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr);
>
> bool RequireCompleteDeclContext(const CXXScopeSpec &SS);
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Dec 15 20:09:40 2009
> @@ -2102,6 +2102,22 @@
> return E;
> }
>
> +FullExpr Sema::CreateFullExpr(Expr *SubExpr) {
> + unsigned FirstTemporary = ExprEvalContexts.back().NumTemporaries;
> + assert(ExprTemporaries.size() >= FirstTemporary);
> +
> + unsigned NumTemporaries = ExprTemporaries.size() - FirstTemporary;
> + CXXTemporary **Temporaries =
> + NumTemporaries == 0 ? 0 : &ExprTemporaries[FirstTemporary];
> +
> + FullExpr E = FullExpr::Create(Context, SubExpr, Temporaries, NumTemporaries);
> +
> + ExprTemporaries.erase(ExprTemporaries.begin() + FirstTemporary,
> + ExprTemporaries.end());
> +
> + return E;
> +}
> +
> Sema::OwningExprResult
> Sema::ActOnStartCXXMemberReference(Scope *S, ExprArg Base, SourceLocation OpLoc,
> tok::TokenKind OpKind, TypeTy *&ObjectType) {
>
> Modified: cfe/trunk/lib/Sema/TreeTransform.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=91494&r1=91493&r2=91494&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/TreeTransform.h (original)
> +++ cfe/trunk/lib/Sema/TreeTransform.h Tue Dec 15 20:09:40 2009
> @@ -1655,7 +1655,7 @@
> if (E.isInvalid())
> return getSema().StmtError();
>
> - return getSema().ActOnExprStmt(getSema().FullExpr(E));
> + return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
> }
> }
>
> @@ -3067,7 +3067,7 @@
> return SemaRef.StmtError();
> }
>
> - Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
> + Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
>
> // Transform the "then" branch.
> OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
> @@ -3110,7 +3110,7 @@
> return SemaRef.StmtError();
> }
>
> - Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
> + Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
>
> // Rebuild the switch statement.
> OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
> @@ -3147,7 +3147,7 @@
> return SemaRef.StmtError();
> }
>
> - Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
> + Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
>
> // Transform the body
> OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
> @@ -3229,9 +3229,9 @@
> return SemaRef.Owned(S->Retain());
>
> return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
> - move(Init), getSema().FullExpr(Cond),
> + move(Init), getSema().MakeFullExpr(Cond),
> ConditionVar,
> - getSema().FullExpr(Inc),
> + getSema().MakeFullExpr(Inc),
> S->getRParenLoc(), move(Body));
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list