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_SECTION 9 #define SKSL_SECTION 10 11 #include "src/sksl/ir/SkSLProgramElement.h" 12 13 namespace SkSL { 14 15 /** 16 * A section declaration (e.g. @body { body code here }).. 17 */ 18 class Section final : public ProgramElement { 19 public: 20 static constexpr Kind kProgramElementKind = Kind::kSection; 21 Section(int offset,String name,String arg,String text)22 Section(int offset, String name, String arg, String text) 23 : INHERITED(offset, kProgramElementKind) 24 , fName(std::move(name)) 25 , fArgument(std::move(arg)) 26 , fText(std::move(text)) {} 27 name()28 const String& name() const { 29 return fName; 30 } 31 argument()32 const String& argument() const { 33 return fArgument; 34 } 35 text()36 const String& text() const { 37 return fText; 38 } 39 clone()40 std::unique_ptr<ProgramElement> clone() const override { 41 return std::unique_ptr<ProgramElement>(new Section(fOffset, this->name(), this->argument(), 42 this->text())); 43 } 44 description()45 String description() const override { 46 String result = "@" + this->name(); 47 if (this->argument().size()) { 48 result += "(" + this->argument() + ")"; 49 } 50 result += " { " + this->text() + " }"; 51 return result; 52 } 53 54 private: 55 String fName; 56 String fArgument; 57 String fText; 58 59 using INHERITED = ProgramElement; 60 }; 61 62 } // namespace SkSL 63 64 #endif 65