Files
swift-mirror/include/swift/AST/CatchNode.h
Tony Allevato f249db3f85 Use cached evaluator results when looking up function types.
Also improve the output for thrown error destinations in
parsable modes.
2025-01-22 14:26:14 -05:00

66 lines
2.3 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 "swift/AST/Decl.h"
#include "swift/AST/Expr.h"
#include "swift/AST/Stmt.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/PointerUnion.h"
#include <optional>
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 std::nullopt
/// if this is a non-throwing context.
std::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;
/// Returns the explicitly-specified type error that will be caught by this
/// catch node, or `nullopt` if it has not yet been computed. This should only
/// be used for dumping.
std::optional<Type> getCachedExplicitCaughtType(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