Home | History | Annotate | Download | only in ir
      1 /*
      2  * Copyright 2016 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SKSL_IFSTATEMENT
      9 #define SKSL_IFSTATEMENT
     10 
     11 #include "SkSLExpression.h"
     12 #include "SkSLStatement.h"
     13 
     14 namespace SkSL {
     15 
     16 /**
     17  * An 'if' statement.
     18  */
     19 struct IfStatement : public Statement {
     20     IfStatement(int offset, bool isStatic, std::unique_ptr<Expression> test,
     21                 std::unique_ptr<Statement> ifTrue, std::unique_ptr<Statement> ifFalse)
     22     : INHERITED(offset, kIf_Kind)
     23     , fIsStatic(isStatic)
     24     , fTest(std::move(test))
     25     , fIfTrue(std::move(ifTrue))
     26     , fIfFalse(std::move(ifFalse)) {}
     27 
     28     String description() const override {
     29         String result;
     30         if (fIsStatic) {
     31             result += "@";
     32         }
     33         result += "if (" + fTest->description() + ") " + fIfTrue->description();
     34         if (fIfFalse) {
     35             result += " else " + fIfFalse->description();
     36         }
     37         return result;
     38     }
     39 
     40     bool fIsStatic;
     41     std::unique_ptr<Expression> fTest;
     42     std::unique_ptr<Statement> fIfTrue;
     43     // may be null
     44     std::unique_ptr<Statement> fIfFalse;
     45 
     46     typedef Statement INHERITED;
     47 };
     48 
     49 } // namespace
     50 
     51 #endif
     52