/* * Copyright 2016 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SKSL_IFSTATEMENT #define SKSL_IFSTATEMENT #include "include/private/SkSLStatement.h" #include "src/sksl/ir/SkSLExpression.h" #include namespace SkSL { /** * An 'if' statement. */ class IfStatement final : public Statement { public: inline static constexpr Kind kStatementKind = Kind::kIf; IfStatement(int line, bool isStatic, std::unique_ptr test, std::unique_ptr ifTrue, std::unique_ptr ifFalse) : INHERITED(line, kStatementKind) , fTest(std::move(test)) , fIfTrue(std::move(ifTrue)) , fIfFalse(std::move(ifFalse)) , fIsStatic(isStatic) {} // Creates a potentially-simplified form of the if-statement. Typechecks and coerces the test // expression; reports errors via ErrorReporter. static std::unique_ptr Convert(const Context& context, int line, bool isStatic, std::unique_ptr test, std::unique_ptr ifTrue, std::unique_ptr ifFalse); // Creates a potentially-simplified form of the if-statement; reports errors via ASSERT. static std::unique_ptr Make(const Context& context, int line, bool isStatic, std::unique_ptr test, std::unique_ptr ifTrue, std::unique_ptr ifFalse); bool isStatic() const { return fIsStatic; } std::unique_ptr& test() { return fTest; } const std::unique_ptr& test() const { return fTest; } std::unique_ptr& ifTrue() { return fIfTrue; } const std::unique_ptr& ifTrue() const { return fIfTrue; } std::unique_ptr& ifFalse() { return fIfFalse; } const std::unique_ptr& ifFalse() const { return fIfFalse; } std::unique_ptr clone() const override; String description() const override; private: std::unique_ptr fTest; std::unique_ptr fIfTrue; std::unique_ptr fIfFalse; bool fIsStatic; using INHERITED = Statement; }; } // namespace SkSL #endif