Home | History | Annotate | Download | only in ast
      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_ASTIFSTATEMENT
      9 #define SKSL_ASTIFSTATEMENT
     10 
     11 #include "SkSLASTStatement.h"
     12 
     13 namespace SkSL {
     14 
     15 /**
     16  * An 'if' statement.
     17  */
     18 struct ASTIfStatement : public ASTStatement {
     19     ASTIfStatement(int offset, bool isStatic, std::unique_ptr<ASTExpression> test,
     20                    std::unique_ptr<ASTStatement> ifTrue, std::unique_ptr<ASTStatement> ifFalse)
     21     : INHERITED(offset, kIf_Kind)
     22     , fIsStatic(isStatic)
     23     , fTest(std::move(test))
     24     , fIfTrue(std::move(ifTrue))
     25     , fIfFalse(std::move(ifFalse)) {}
     26 
     27     String description() const override {
     28         String result;
     29         if (fIsStatic) {
     30             result += "@";
     31         }
     32         result += "if (";
     33         result += fTest->description();
     34         result += ") ";
     35         result += fIfTrue->description();
     36         if (fIfFalse) {
     37             result += " else ";
     38             result += fIfFalse->description();
     39         }
     40         return result;
     41     }
     42 
     43     const bool fIsStatic;
     44     const std::unique_ptr<ASTExpression> fTest;
     45     const std::unique_ptr<ASTStatement> fIfTrue;
     46     const std::unique_ptr<ASTStatement> fIfFalse;
     47 
     48     typedef ASTStatement INHERITED;
     49 };
     50 
     51 } // namespace
     52 
     53 #endif
     54