|
29 | 29 | #define SWIFT_AST_AST_SCOPE_H |
30 | 30 |
|
31 | 31 | #include "swift/AST/ASTNode.h" |
| 32 | +#include "swift/AST/CatchNode.h" |
32 | 33 | #include "swift/AST/NameLookup.h" |
33 | 34 | #include "swift/AST/SimpleRequest.h" |
34 | 35 | #include "swift/Basic/Compiler.h" |
@@ -85,6 +86,7 @@ class SILGenFunction; |
85 | 86 |
|
86 | 87 | namespace ast_scope { |
87 | 88 | class ASTScopeImpl; |
| 89 | +class BraceStmtScope; |
88 | 90 | class GenericTypeOrExtensionScope; |
89 | 91 | class IterableTypeScope; |
90 | 92 | class TypeAliasScope; |
@@ -211,6 +213,7 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> { |
211 | 213 | #pragma mark common queries |
212 | 214 | public: |
213 | 215 | virtual NullablePtr<AbstractClosureExpr> getClosureIfClosureScope() const; |
| 216 | + virtual NullablePtr<const BraceStmtScope> getAsBraceStmtScope() const; |
214 | 217 | virtual ASTContext &getASTContext() const; |
215 | 218 | virtual NullablePtr<Decl> getDeclIfAny() const { return nullptr; }; |
216 | 219 | virtual NullablePtr<Stmt> getStmtIfAny() const { return nullptr; }; |
@@ -287,10 +290,18 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> { |
287 | 290 | SourceFile *sourceFile, SourceLoc loc, |
288 | 291 | llvm::function_ref<bool(ASTScope::PotentialMacro)> consume); |
289 | 292 |
|
| 293 | + static CatchNode lookupCatchNode(ModuleDecl *module, SourceLoc loc); |
| 294 | + |
290 | 295 | /// Scopes that cannot bind variables may set this to true to create more |
291 | 296 | /// compact scope tree in the debug info. |
292 | 297 | virtual bool ignoreInDebugInfo() const { return false; } |
293 | 298 |
|
| 299 | + /// If this scope node represents a potential catch node, return body the |
| 300 | + /// AST node describing the catch (a function, closure, or do...catch) and |
| 301 | + /// the node of it's "body", i.e., the brace statement from which errors |
| 302 | + /// thrown will be caught by that node. |
| 303 | + virtual std::pair<CatchNode, const BraceStmtScope *> getCatchNodeBody() const; |
| 304 | + |
294 | 305 | #pragma mark - - lookup- starting point |
295 | 306 | private: |
296 | 307 | static const ASTScopeImpl *findStartingScopeForLookup(SourceFile *, |
@@ -824,6 +835,8 @@ class FunctionBodyScope : public ASTScopeImpl { |
824 | 835 | Decl *getDecl() const { return decl; } |
825 | 836 | bool ignoreInDebugInfo() const override { return true; } |
826 | 837 |
|
| 838 | + std::pair<CatchNode, const BraceStmtScope *> getCatchNodeBody() const override; |
| 839 | + |
827 | 840 | protected: |
828 | 841 | bool lookupLocalsOrMembers(DeclConsumer) const override; |
829 | 842 |
|
@@ -1069,6 +1082,8 @@ class ClosureParametersScope final : public ASTScopeImpl { |
1069 | 1082 | NullablePtr<AbstractClosureExpr> getClosureIfClosureScope() const override { |
1070 | 1083 | return closureExpr; |
1071 | 1084 | } |
| 1085 | + std::pair<CatchNode, const BraceStmtScope *> getCatchNodeBody() const override; |
| 1086 | + |
1072 | 1087 | NullablePtr<Expr> getExprIfAny() const override { return closureExpr; } |
1073 | 1088 | Expr *getExpr() const { return closureExpr; } |
1074 | 1089 | bool ignoreInDebugInfo() const override { return true; } |
@@ -1440,6 +1455,8 @@ class DoCatchStmtScope final : public AbstractStmtScope { |
1440 | 1455 | void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &); |
1441 | 1456 |
|
1442 | 1457 | public: |
| 1458 | + std::pair<CatchNode, const BraceStmtScope *> getCatchNodeBody() const override; |
| 1459 | + |
1443 | 1460 | std::string getClassName() const override; |
1444 | 1461 | Stmt *getStmt() const override { return stmt; } |
1445 | 1462 | }; |
@@ -1648,6 +1665,8 @@ class BraceStmtScope final : public AbstractStmtScope { |
1648 | 1665 | NullablePtr<AbstractClosureExpr> parentClosureIfAny() const; // public?? |
1649 | 1666 | Stmt *getStmt() const override { return stmt; } |
1650 | 1667 |
|
| 1668 | + NullablePtr<const BraceStmtScope> getAsBraceStmtScope() const override; |
| 1669 | + |
1651 | 1670 | protected: |
1652 | 1671 | bool lookupLocalsOrMembers(DeclConsumer) const override; |
1653 | 1672 | }; |
|
0 commit comments