[cfe-commits] r163083 - in /cfe/trunk: include/clang/AST/ include/clang/Basic/ include/clang/Sema/ include/clang/Serialization/ lib/AST/ lib/CodeGen/ lib/Parse/ lib/Sema/ lib/Serialization/ lib/StaticAnalyzer/Core/ test/Parser/ tools/libclang/
Sean Silva
silvas at purdue.edu
Sat Sep 1 21:32:20 PDT 2012
Since you just implemented a new Stmt, could you take a look at
<http://clang.llvm.org/docs/InternalsManual.html#AddingExprStmt> and
make sure that it is accurate?
Thanks
--Sean Silva
On Sat, Sep 1, 2012 at 11:45 PM, Joao Matos <ripzonetriton at gmail.com> wrote:
> Author: triton
> Date: Sat Sep 1 22:45:41 2012
> New Revision: 163083
>
> URL: http://llvm.org/viewvc/llvm-project?rev=163083&view=rev
> Log:
> Implemented parsing and AST support for the MS __leave exception statement. Also a minor fix to __except printing in StmtPrinter.cpp. Thanks to Aaron Ballman for review.
>
> Modified:
> cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
> cfe/trunk/include/clang/AST/Stmt.h
> cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> cfe/trunk/include/clang/Basic/StmtNodes.td
> cfe/trunk/include/clang/Sema/Scope.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> cfe/trunk/lib/AST/Stmt.cpp
> cfe/trunk/lib/AST/StmtPrinter.cpp
> cfe/trunk/lib/AST/StmtProfile.cpp
> cfe/trunk/lib/CodeGen/CGStmt.cpp
> cfe/trunk/lib/Parse/ParseStmt.cpp
> cfe/trunk/lib/Sema/SemaStmt.cpp
> cfe/trunk/lib/Sema/TreeTransform.h
> cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
> cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
> cfe/trunk/test/Parser/MicrosoftExtensions.c
> cfe/trunk/tools/libclang/RecursiveASTVisitor.h
>
> Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
> +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Sat Sep 1 22:45:41 2012
> @@ -2202,6 +2202,7 @@
> })
>
> DEF_TRAVERSE_STMT(SEHTryStmt, {})
> +DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
> DEF_TRAVERSE_STMT(SEHExceptStmt, {})
> DEF_TRAVERSE_STMT(SEHFinallyStmt,{})
>
>
> Modified: cfe/trunk/include/clang/AST/Stmt.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Stmt.h (original)
> +++ cfe/trunk/include/clang/AST/Stmt.h Sat Sep 1 22:45:41 2012
> @@ -1889,6 +1889,34 @@
> static bool classof(SEHTryStmt *) { return true; }
> };
>
> +class SEHLeaveStmt : public Stmt {
> + SourceLocation LeaveLoc;
> +
> + SEHLeaveStmt(SourceLocation LeaveLoc);
> +
> + friend class ASTReader;
> + friend class ASTStmtReader;
> + explicit SEHLeaveStmt(EmptyShell E) : Stmt(SEHLeaveStmtClass, E) { }
> +
> +public:
> + static SEHLeaveStmt* Create(ASTContext &C,
> + SourceLocation LeaveLoc);
> +
> + SourceRange getSourceRange() const LLVM_READONLY {
> + return SourceRange(getLeaveLoc());
> + }
> +
> + SourceLocation getLeaveLoc() const { return LeaveLoc; }
> +
> + child_range children() { return child_range(); }
> +
> + static bool classof(const Stmt *T) {
> + return T->getStmtClass() == SEHLeaveStmtClass;
> + }
> +
> + static bool classof(SEHLeaveStmt *) { return true; }
> +};
> +
> } // end namespace clang
>
> #endif
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sat Sep 1 22:45:41 2012
> @@ -740,6 +740,9 @@
>
> def err_seh___finally_block : Error<
> "%0 only allowed in __finally block">;
> +
> +def err_seh___try_block : Error<
> + "%0 only allowed in __try block">;
>
> } // end of Parse Issue category.
>
>
> Modified: cfe/trunk/include/clang/Basic/StmtNodes.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/StmtNodes.td?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/StmtNodes.td (original)
> +++ cfe/trunk/include/clang/Basic/StmtNodes.td Sat Sep 1 22:45:41 2012
> @@ -164,6 +164,7 @@
> // Microsoft Extensions.
> def CXXUuidofExpr : DStmt<Expr>;
> def SEHTryStmt : Stmt;
> +def SEHLeaveStmt : Stmt;
> def SEHExceptStmt : Stmt;
> def SEHFinallyStmt : Stmt;
> def MSDependentExistsStmt : Stmt;
>
> Modified: cfe/trunk/include/clang/Sema/Scope.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Scope.h?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/Scope.h (original)
> +++ cfe/trunk/include/clang/Sema/Scope.h Sat Sep 1 22:45:41 2012
> @@ -82,7 +82,10 @@
> SwitchScope = 0x800,
>
> /// TryScope - This is the scope of a C++ try statement.
> - TryScope = 0x1000
> + TryScope = 0x1000,
> +
> + /// SEHTryScope - This is scope of a Microsoft SEH try statement.
> + SEHTryScope = 0x2000
> };
> private:
> /// The parent scope for this scope. This is null for the translation-unit
> @@ -292,6 +295,9 @@
> /// \brief Determine whether this scope is a C++ 'try' block.
> bool isTryScope() const { return getFlags() & Scope::TryScope; }
>
> + /// \brief Determine whether this scope is a MS SEH 'try' block.
> + bool isSEHTryScope() const { return getFlags() & Scope::SEHTryScope; }
> +
> /// containedInPrototypeScope - Return true if this or a parent scope
> /// is a FunctionPrototypeScope.
> bool containedInPrototypeScope() const;
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Sat Sep 1 22:45:41 2012
> @@ -2622,6 +2622,8 @@
> Stmt *TryBlock,
> Stmt *Handler);
>
> + StmtResult ActOnSEHLeaveStmt(SourceLocation LeaveLoc);
> +
> StmtResult ActOnSEHExceptBlock(SourceLocation Loc,
> Expr *FilterExpr,
> Stmt *Block);
>
> Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Sat Sep 1 22:45:41 2012
> @@ -1204,6 +1204,7 @@
> STMT_SEH_EXCEPT, // SEHExceptStmt
> STMT_SEH_FINALLY, // SEHFinallyStmt
> STMT_SEH_TRY, // SEHTryStmt
> + STMT_SEH_LEAVE, // SEHLeaveStmt
>
> // ARC
> EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr
>
> Modified: cfe/trunk/lib/AST/Stmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/Stmt.cpp (original)
> +++ cfe/trunk/lib/AST/Stmt.cpp Sat Sep 1 22:45:41 2012
> @@ -1006,6 +1006,17 @@
> return dyn_cast<SEHFinallyStmt>(getHandler());
> }
>
> +SEHLeaveStmt::SEHLeaveStmt(SourceLocation LeaveLoc)
> + : Stmt(SEHLeaveStmtClass),
> + LeaveLoc(LeaveLoc)
> +{
> +}
> +
> +SEHLeaveStmt* SEHLeaveStmt::Create(ASTContext &C,
> + SourceLocation LeaveLoc) {
> + return new(C) SEHLeaveStmt(LeaveLoc);
> +}
> +
> SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
> Expr *FilterExpr,
> Stmt *Block)
>
> Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
> +++ cfe/trunk/lib/AST/StmtPrinter.cpp Sat Sep 1 22:45:41 2012
> @@ -537,6 +537,11 @@
> OS << "\n";
> }
>
> +void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) {
> + Indent() << "__leave;";
> + OS << "\n";
> +}
> +
> void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) {
> OS << "__finally ";
> PrintRawCompoundStmt(Node->getBlock());
> @@ -546,7 +551,7 @@
> void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) {
> OS << "__except (";
> VisitExpr(Node->getFilterExpr());
> - OS << ")\n";
> + OS << ") ";
> PrintRawCompoundStmt(Node->getBlock());
> OS << "\n";
> }
>
> Modified: cfe/trunk/lib/AST/StmtProfile.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/StmtProfile.cpp (original)
> +++ cfe/trunk/lib/AST/StmtProfile.cpp Sat Sep 1 22:45:41 2012
> @@ -215,6 +215,10 @@
> VisitStmt(S);
> }
>
> +void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
> + VisitStmt(S);
> +}
> +
> void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
> VisitStmt(S);
> }
>
> Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Sep 1 22:45:41 2012
> @@ -163,6 +163,7 @@
> case Stmt::CXXForRangeStmtClass:
> EmitCXXForRangeStmt(cast<CXXForRangeStmt>(*S));
> case Stmt::SEHTryStmtClass:
> + case Stmt::SEHLeaveStmtClass:
> // FIXME Not yet implemented
> break;
> }
>
> Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseStmt.cpp Sat Sep 1 22:45:41 2012
> @@ -183,6 +183,19 @@
>
> return ParseExprStatement();
> }
> +
> + case tok::kw___leave: {
> + Token LeaveTok = Tok;
> + ConsumeToken();
> + if (getCurScope()->isSEHTryScope()) {
> + Res = Actions.ActOnSEHLeaveStmt(LeaveTok.getLocation());
> + } else {
> + Diag(LeaveTok, diag::err_seh___try_block)
> + << LeaveTok.getIdentifierInfo()->getName();
> + Res = StmtError();
> + }
> + break;
> + }
>
> case tok::kw_case: // C99 6.8.1: labeled-statement
> return ParseCaseStatement();
> @@ -322,7 +335,9 @@
> if(Tok.isNot(tok::l_brace))
> return StmtError(Diag(Tok,diag::err_expected_lbrace));
>
> - StmtResult TryBlock(ParseCompoundStatement());
> + // Use the SEHTryScope to handle __leave as a statement.
> + unsigned ScopeFlags = Scope::DeclScope | Scope::SEHTryScope;
> + StmtResult TryBlock(ParseCompoundStatement(false /*isStmtExpr*/, ScopeFlags));
> if(TryBlock.isInvalid())
> return TryBlock;
>
>
> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Sat Sep 1 22:45:41 2012
> @@ -2746,6 +2746,12 @@
> }
>
> StmtResult
> +Sema::ActOnSEHLeaveStmt(SourceLocation LeaveLoc)
> +{
> + return Owned(SEHLeaveStmt::Create(Context, LeaveLoc));
> +}
> +
> +StmtResult
> Sema::ActOnSEHExceptBlock(SourceLocation Loc,
> Expr *FilterExpr,
> Stmt *Block) {
>
> Modified: cfe/trunk/lib/Sema/TreeTransform.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/TreeTransform.h (original)
> +++ cfe/trunk/lib/Sema/TreeTransform.h Sat Sep 1 22:45:41 2012
> @@ -1361,6 +1361,10 @@
> return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
> }
>
> + StmtResult RebuildSEHLeaveStmt(SourceLocation LeaveLoc) {
> + return getSema().ActOnSEHLeaveStmt(LeaveLoc);
> + }
> +
> StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
> Expr *FilterExpr,
> Stmt *Block) {
> @@ -6001,6 +6005,12 @@
>
> template<typename Derived>
> StmtResult
> +TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
> + return getDerived().RebuildSEHLeaveStmt(S->getLeaveLoc());
> +}
> +
> +template<typename Derived>
> +StmtResult
> TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
> StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
> if(Block.isInvalid()) return StmtError();
>
> Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Sat Sep 1 22:45:41 2012
> @@ -1516,6 +1516,11 @@
> S->Children[SEHTryStmt::HANDLER] = Reader.ReadSubStmt();
> }
>
> +void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
> + VisitStmt(S);
> + S->LeaveLoc = ReadSourceLocation(Record, Idx);
> +}
> +
> //===----------------------------------------------------------------------===//
> // CUDA Expressions and Statements
> //===----------------------------------------------------------------------===//
> @@ -1986,6 +1991,9 @@
> case STMT_SEH_TRY:
> S = new (Context) SEHTryStmt(Empty);
> break;
> + case STMT_SEH_LEAVE:
> + S = new (Context) SEHLeaveStmt(Empty);
> + break;
> case STMT_CXX_CATCH:
> S = new (Context) CXXCatchStmt(Empty);
> break;
>
> Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Sat Sep 1 22:45:41 2012
> @@ -1554,6 +1554,12 @@
> Code = serialization::STMT_SEH_TRY;
> }
>
> +void ASTStmtWriter::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
> + VisitStmt(S);
> + Writer.AddSourceLocation(S->getLeaveLoc(), Record);
> + Code = serialization::STMT_SEH_LEAVE;
> +}
> +
> //===----------------------------------------------------------------------===//
> // ASTWriter Implementation
> //===----------------------------------------------------------------------===//
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Sat Sep 1 22:45:41 2012
> @@ -527,6 +527,7 @@
> case Stmt::PackExpansionExprClass:
> case Stmt::SubstNonTypeTemplateParmPackExprClass:
> case Stmt::SEHTryStmtClass:
> + case Stmt::SEHLeaveStmtClass:
> case Stmt::SEHExceptStmtClass:
> case Stmt::LambdaExprClass:
> case Stmt::SEHFinallyStmtClass: {
>
> Modified: cfe/trunk/test/Parser/MicrosoftExtensions.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.c?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/test/Parser/MicrosoftExtensions.c (original)
> +++ cfe/trunk/test/Parser/MicrosoftExtensions.c Sat Sep 1 22:45:41 2012
> @@ -102,3 +102,9 @@
> struct S7 s;
> int i = s.t; /* expected-warning {{'t' is deprecated}} */
> }
> +
> +void SEH() {
> + __try { __leave; } __except (0) {}
> + __try { } __except (0) { __leave; } // expected-error {{__leave only allowed in __try block}}
> + __try { } __finally { __leave; } // expected-error {{__leave only allowed in __try block}}
> +}
> \ No newline at end of file
>
> Modified: cfe/trunk/tools/libclang/RecursiveASTVisitor.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/RecursiveASTVisitor.h?rev=163083&r1=163082&r2=163083&view=diff
> ==============================================================================
> --- cfe/trunk/tools/libclang/RecursiveASTVisitor.h (original)
> +++ cfe/trunk/tools/libclang/RecursiveASTVisitor.h Sat Sep 1 22:45:41 2012
> @@ -2122,6 +2122,7 @@
> })
>
> DEF_TRAVERSE_STMT(SEHTryStmt, {})
> +DEF_TRAVERSE_STMT(SEHLeaveStmt, {})
> DEF_TRAVERSE_STMT(SEHExceptStmt, {})
> DEF_TRAVERSE_STMT(SEHFinallyStmt,{})
>
>
>
> _______________________________________________
> 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