/* * Copyright 2017 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef SKSL_SWITCHSTATEMENT #define SKSL_SWITCHSTATEMENT #include "src/sksl/SkSLDefines.h" #include "src/sksl/SkSLPosition.h" #include "src/sksl/ir/SkSLBlock.h" #include "src/sksl/ir/SkSLExpression.h" #include "src/sksl/ir/SkSLIRNode.h" #include "src/sksl/ir/SkSLStatement.h" #include #include #include namespace SkSL { class Context; class SymbolTable; /** * A 'switch' statement. */ class SwitchStatement final : public Statement { public: inline static constexpr Kind kIRNodeKind = Kind::kSwitch; SwitchStatement(Position pos, std::unique_ptr value, std::unique_ptr caseBlock) : INHERITED(pos, kIRNodeKind) , fValue(std::move(value)) , fCaseBlock(std::move(caseBlock)) {} // Create a `switch` statement with an array of case-values and case-statements. // Coerces case values to the proper type and reports an error if cases are duplicated. // Reports errors via the ErrorReporter. static std::unique_ptr Convert(const Context& context, Position pos, std::unique_ptr value, ExpressionArray caseValues, StatementArray caseStatements, std::unique_ptr symbolTable); // Create a `switch` statement with a Block containing only SwitchCases. The SwitchCase block // must already contain non-overlapping, correctly-typed case values. Reports errors via ASSERT. static std::unique_ptr Make(const Context& context, Position pos, std::unique_ptr value, std::unique_ptr caseBlock); std::unique_ptr& value() { return fValue; } const std::unique_ptr& value() const { return fValue; } std::unique_ptr& caseBlock() { return fCaseBlock; } const std::unique_ptr& caseBlock() const { return fCaseBlock; } StatementArray& cases() { return fCaseBlock->as().children(); } const StatementArray& cases() const { return fCaseBlock->as().children(); } std::string description() const override; private: std::unique_ptr fValue; std::unique_ptr fCaseBlock; // must be a Block containing only SwitchCase statements using INHERITED = Statement; }; } // namespace SkSL #endif