Files
swift-mirror/include/swift/AST/CatchNode.h
Doug Gregor e1be9c312b Eliminate the DeclContext from ExplicitCaughtTypeRequest
Correctly determining the DeclContext needed for an
ExplicitCaughtTypeRequest is tricky for a number of callers, and
mistakes here can easily lead to redundant computation of the caught
type, redundant diagnostics, etc.

Instead, put a `DeclContext` into `DoCatchStmt`, because that's the
only catch node that needs a `DeclContext` but does not have one.
2023-12-13 11:42:56 -08:00

61 lines
2.1 KiB
C++

//===--- CatchNode.h - An AST node that catches errors -----------*- C++-*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_CATCHNODE_H
#define SWIFT_AST_CATCHNODE_H
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerUnion.h"
#include "swift/AST/Decl.h"
#include "swift/AST/Expr.h"
#include "swift/AST/Stmt.h"
namespace swift {
/// An AST node that represents a point where a thrown error can be caught and
/// or rethrown, which includes functions do...catch statements.
class CatchNode: public llvm::PointerUnion<
AbstractFunctionDecl *, ClosureExpr *, DoCatchStmt *, AnyTryExpr *
> {
public:
using PointerUnion::PointerUnion;
/// Determine the thrown error type within the region of this catch node
/// where it will catch (and possibly rethrow) errors. All of the errors
/// thrown from within that region will be converted to this error type.
///
/// Returns the thrown error type for a throwing context, or \c llvm::None
/// if this is a non-throwing context.
llvm::Optional<Type> getThrownErrorTypeInContext(ASTContext &ctx) const;
/// Determines the explicitly-specified type error that will be caught by
/// this catch node.
///
/// Returns the explicitly-caught type, or a NULL type if the caught type
/// needs to be inferred.
Type getExplicitCaughtType(ASTContext &ctx) const;
friend llvm::hash_code hash_value(CatchNode catchNode) {
using llvm::hash_value;
return hash_value(catchNode.getOpaqueValue());
}
};
void simple_display(llvm::raw_ostream &out, CatchNode catchNode);
SourceLoc extractNearestSourceLoc(CatchNode catchNode);
} // end namespace swift
#endif // SWIFT_AST_CATCHNODE_H