1818
1919#include " swift/AST/ActorIsolation.h"
2020#include " swift/AST/AnyFunctionRef.h"
21+ #include " swift/AST/ASTNode.h"
2122#include " swift/AST/ASTTypeIDs.h"
2223#include " swift/AST/Effects.h"
2324#include " swift/AST/GenericParamList.h"
@@ -1544,12 +1545,82 @@ class TypeCheckFunctionBodyRequest
15441545 readDependencySource (const evaluator::DependencyRecorder &) const ;
15451546};
15461547
1548+ // / Describes the context in which the AST node to type check in a
1549+ // / \c TypeCheckASTNodeAtLocRequest should be searched. This can be either of
1550+ // / two cases:
1551+ // / 1. A \c DeclContext that contains the node representing the location to
1552+ // / type check
1553+ // / 2. If the node that should be type checked that might not be part of the
1554+ // / AST (e.g. because it is a dangling property attribute), an \c ASTNode
1555+ // / that contains the location to type check in together with a DeclContext
1556+ // / in which we should pretend that node occurs.
1557+ class TypeCheckASTNodeAtLocContext {
1558+ DeclContext *DC;
1559+ ASTNode Node;
1560+
1561+ // / Memberwise initializer
1562+ TypeCheckASTNodeAtLocContext (DeclContext *DC, ASTNode Node)
1563+ : DC(DC), Node(Node) {
1564+ assert (DC != nullptr );
1565+ }
1566+
1567+ public:
1568+ static TypeCheckASTNodeAtLocContext declContext (DeclContext *DC) {
1569+ return TypeCheckASTNodeAtLocContext (DC, /* Node=*/ nullptr );
1570+ }
1571+
1572+ static TypeCheckASTNodeAtLocContext node (DeclContext *DC, ASTNode Node) {
1573+ assert (!Node.isNull ());
1574+ return TypeCheckASTNodeAtLocContext (DC, Node);
1575+ }
1576+
1577+ DeclContext *getDeclContext () const { return DC; }
1578+
1579+ bool isForUnattachedNode () const { return !Node.isNull (); }
1580+
1581+ ASTNode getUnattachedNode () const {
1582+ assert (isForUnattachedNode ());
1583+ return Node;
1584+ }
1585+
1586+ ASTNode &getUnattachedNode () {
1587+ assert (isForUnattachedNode ());
1588+ return Node;
1589+ }
1590+
1591+ friend llvm::hash_code hash_value (const TypeCheckASTNodeAtLocContext &ctx) {
1592+ return llvm::hash_combine (ctx.DC , ctx.Node );
1593+ }
1594+
1595+ friend bool operator ==(const TypeCheckASTNodeAtLocContext &lhs,
1596+ const TypeCheckASTNodeAtLocContext &rhs) {
1597+ return lhs.DC == rhs.DC && lhs.Node == rhs.Node ;
1598+ }
1599+
1600+ friend bool operator !=(const TypeCheckASTNodeAtLocContext &lhs,
1601+ const TypeCheckASTNodeAtLocContext &rhs) {
1602+ return !(lhs == rhs);
1603+ }
1604+
1605+ friend SourceLoc
1606+ extractNearestSourceLoc (const TypeCheckASTNodeAtLocContext &ctx) {
1607+ if (!ctx.Node .isNull ()) {
1608+ return ctx.Node .getStartLoc ();
1609+ } else {
1610+ return extractNearestSourceLoc (ctx.DC );
1611+ }
1612+ }
1613+ };
1614+
1615+ void simple_display (llvm::raw_ostream &out,
1616+ const TypeCheckASTNodeAtLocContext &ctx);
1617+
15471618// / Request to typecheck a function body element at the given source location.
15481619// /
15491620// / Produces true if an error occurred, false otherwise.
15501621class TypeCheckASTNodeAtLocRequest
15511622 : public SimpleRequest<TypeCheckASTNodeAtLocRequest,
1552- bool (DeclContext * , SourceLoc),
1623+ bool (TypeCheckASTNodeAtLocContext , SourceLoc),
15531624 RequestFlags::Uncached> {
15541625public:
15551626 using SimpleRequest::SimpleRequest;
@@ -1558,7 +1629,8 @@ class TypeCheckASTNodeAtLocRequest
15581629 friend SimpleRequest;
15591630
15601631 // Evaluation.
1561- bool evaluate (Evaluator &evaluator, DeclContext *DC, SourceLoc Loc) const ;
1632+ bool evaluate (Evaluator &evaluator, TypeCheckASTNodeAtLocContext,
1633+ SourceLoc Loc) const ;
15621634};
15631635
15641636// / Request to obtain a list of stored properties in a nominal type.
@@ -3606,6 +3678,7 @@ class GetSourceFileAsyncNode
36063678 bool isCached () const { return true ; }
36073679};
36083680
3681+ void simple_display (llvm::raw_ostream &out, ASTNode node);
36093682void simple_display (llvm::raw_ostream &out, Type value);
36103683void simple_display (llvm::raw_ostream &out, const TypeRepr *TyR);
36113684void simple_display (llvm::raw_ostream &out, ImplicitMemberAction action);
0 commit comments