mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
LLVM has removed llvm::Optional, move over to std::optional. Also clang-format to fix up all the renamed #includes.
61 lines
2.0 KiB
C++
61 lines
2.0 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;
|
|
|
|
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
|