Files
swift-mirror/include/swift/AST/ExprHandle.h
Doug Gregor 797f863d12 Don't null out the expression in an ExprHandle; it breaks invariants.
Fixes <rdar://problem/14564964>.


Swift SVN r7022
2013-08-07 23:37:43 +00:00

63 lines
2.0 KiB
C++

//===--- ExprHandle.h - Swift Expression Handle -----------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines the ExprHandle class.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_EXPRHANDLE_H
#define SWIFT_EXPRHANDLE_H
#include "llvm/Support/DataTypes.h"
#include "llvm/ADT/PointerIntPair.h"
namespace swift {
class ASTContext;
class Expr;
/// ExprHandle - Provides an indirection for expressions, so both a type and a
/// pattern can point at the same expression during type-checking.
class ExprHandle {
/// \brief The expression along with a bit saying whether this expression
/// was already type-checked (or not).
llvm::PointerIntPair<Expr *, 1, bool> EAndChecked;
private:
ExprHandle(Expr *E) : EAndChecked(E, false) {}
void *operator new(size_t Bytes) throw() = delete;
void operator delete(void *Data) throw() = delete;
void *operator new(size_t Bytes, void *Mem) throw() = delete;
void *operator new(size_t Bytes, ASTContext &C,
unsigned Alignment = 8);
public:
Expr *getExpr() {
return EAndChecked.getPointer();
}
/// \brief Determine whether the referenced expression has already been
/// type-checked.
bool alreadyChecked() const { return EAndChecked.getInt(); }
/// \brief Set the expression after it has been type-checked.
void setExpr(Expr *newE, bool checked) {
assert(newE && "Null expression in handle");
EAndChecked.setPointer(newE);
EAndChecked.setInt(checked);
}
static ExprHandle *get(ASTContext &Context, Expr *E);
};
} // end namespace swift
#endif