Files
swift-mirror/lib/SILGen/Condition.h
Joe Groff 9fe1ab427a Implement 'if let' and 'while let' statements.
Allow IfStmts and WhileStmts to have as their condition either an expression, as usual, or a pattern binding introduced by 'var' or 'let', which will conditionally bind to the value inside an optional. Unlike normal pattern bindings, these bindings require an in-line initializer, which will be required to be Optional type. Parse variable bindings in this position, and type-check them by requiring an Optional on the right-hand side and unwrapping it to form the pattern type. Extend SILGen's lowering of if and while statements to handle conditionally binding variables.

Swift SVN r13146
2014-01-30 10:37:39 +00:00

83 lines
2.8 KiB
C++

//===--- Condition.h - Defines the SILGen Condition class -------*- 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 Condition class, used by SIL Generation.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SIL_LOWERING_CONDITION_H
#define SWIFT_SIL_LOWERING_CONDITION_H
#include "llvm/ADT/ArrayRef.h"
#include "swift/Basic/Optional.h"
#include "swift/SIL/SILLocation.h"
#include "swift/SIL/SILValue.h"
#include "llvm/Support/Compiler.h"
namespace swift {
class PatternBindingDecl;
class SILBuilder;
class SILBasicBlock;
namespace Lowering {
/// A condition is the result of evaluating a boolean expression as
/// control flow.
class LLVM_LIBRARY_VISIBILITY Condition {
/// The blocks responsible for executing the true and false conditions. A
/// block is non-null if that branch is possible, but it's only an independent
/// block if both branches are possible.
SILBasicBlock *TrueBB;
SILBasicBlock *FalseBB;
/// The continuation block if both branches are possible.
SILBasicBlock *ContBB;
/// The location wrapping the originator conditional expression.
SILLocation Loc;
public:
Condition(SILBasicBlock *TrueBB, SILBasicBlock *FalseBB,
SILBasicBlock *ContBB,
SILLocation L)
: TrueBB(TrueBB), FalseBB(FalseBB), ContBB(ContBB), Loc(L)
{}
bool hasTrue() const { return TrueBB; }
bool hasFalse() const { return FalseBB; }
/// enterTrue - Begin the emission of the true block. This should only be
/// called if hasTrue() returns true.
void enterTrue(SILBuilder &B);
/// exitTrue - End the emission of the true block. This must be called after
/// enterTrue but before anything else on this Condition.
void exitTrue(SILBuilder &B, ArrayRef<SILValue> Args = {});
/// enterFalse - Begin the emission of the false block. This should only be
/// called if hasFalse() returns true.
void enterFalse(SILBuilder &B);
/// exitFalse - End the emission of the true block. This must be called after
/// enterFalse but before anything else on this Condition.
void exitFalse(SILBuilder &B, ArrayRef<SILValue> Args = {});
/// complete - Complete this conditional execution. This should be called
/// only after all other calls on this Condition have been made.
SILBasicBlock *complete(SILBuilder &B);
};
} // end namespace Lowering
} // end namespace swift
#endif