mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
implement parsing, AST, and basic Sema support for 'defer'.
SILGen support and diagnosing jumps out of a defer aren't done yet. Swift SVN r27759
This commit is contained in:
@@ -728,6 +728,10 @@ ERROR(expected_close_after_else,stmt_parsing,none,
|
||||
ERROR(expected_expr_return,stmt_parsing,PointsToFirstBadToken,
|
||||
"expected expression in 'return' statement", ())
|
||||
|
||||
// Defer Statement
|
||||
ERROR(expected_lbrace_after_defer,stmt_parsing,PointsToFirstBadToken,
|
||||
"expected '{' after 'defer'", ())
|
||||
|
||||
// If/While Conditions
|
||||
ERROR(expected_expr_conditional_letbinding,stmt_parsing,none,
|
||||
"expected 'let' or 'var' in conditional", ())
|
||||
|
||||
@@ -175,6 +175,32 @@ public:
|
||||
|
||||
static bool classof(const Stmt *S) { return S->getKind() == StmtKind::Return;}
|
||||
};
|
||||
|
||||
/// DeferStmt - A 'defer' statement. This runs the substatement it contains
|
||||
/// when the enclosing scope is exited.
|
||||
///
|
||||
/// defer { cleanUp() }
|
||||
///
|
||||
class DeferStmt : public Stmt {
|
||||
SourceLoc DeferLoc;
|
||||
BraceStmt *Body;
|
||||
|
||||
public:
|
||||
DeferStmt(SourceLoc DeferLoc, BraceStmt *Body)
|
||||
: Stmt(StmtKind::Defer, /*implicit*/false),
|
||||
DeferLoc(DeferLoc), Body(Body) {}
|
||||
|
||||
SourceLoc getDeferLoc() const { return DeferLoc; }
|
||||
|
||||
SourceLoc getStartLoc() const { return DeferLoc; }
|
||||
SourceLoc getEndLoc() const;
|
||||
|
||||
BraceStmt *getBody() const { return Body; }
|
||||
void setBody(BraceStmt *body) { Body = body; }
|
||||
|
||||
static bool classof(const Stmt *S) { return S->getKind() == StmtKind::Defer; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// This represents an entry in an "if" or "while" condition. Pattern bindings
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
STMT(Brace, Stmt)
|
||||
STMT(Return, Stmt)
|
||||
STMT(Defer, Stmt)
|
||||
ABSTRACT_STMT(Labeled, Stmt)
|
||||
ABSTRACT_STMT(LabeledConditional, LabeledStmt)
|
||||
LABELED_STMT(If, LabeledConditionalStmt)
|
||||
|
||||
@@ -1153,6 +1153,7 @@ public:
|
||||
ParserResult<Stmt> parseStmtBreak();
|
||||
ParserResult<Stmt> parseStmtContinue();
|
||||
ParserResult<Stmt> parseStmtReturn();
|
||||
ParserResult<Stmt> parseStmtDefer();
|
||||
ParserStatus parseStmtCondition(StmtCondition &Result, Diag<> ID);
|
||||
ParserResult<Stmt> parseStmtIf(LabeledStmtInfo LabelInfo);
|
||||
ParserResult<Stmt> parseStmtIfConfig(BraceItemListKind Kind
|
||||
|
||||
@@ -73,6 +73,7 @@ KEYWORD(sil_witness_table) // This is only enabled when parsing .sil files.
|
||||
KEYWORD(sil_coverage_map) // This is only enabled when parsing .sil files.
|
||||
|
||||
// Statement keywords.
|
||||
STMT_KEYWORD(defer)
|
||||
STMT_KEYWORD(if)
|
||||
STMT_KEYWORD(do)
|
||||
STMT_KEYWORD(repeat)
|
||||
|
||||
Reference in New Issue
Block a user