From ccb1dd8f267f9d7fe7c9d0ce222ebc81b41853b3 Mon Sep 17 00:00:00 2001
From: ethannicholas <ethannicholas@google.com>
Date: Tue, 11 Oct 2016 08:47:04 -0700
Subject: Turned on SkSL->GLSL compiler GOLD_TRYBOT_URL=
 https://gold.skia.org/search?issue=2288033003

Committed: https://skia.googlesource.com/skia/+/9b0fe3d125f237d9884732a48414fa85fc71b4e3
Committed: https://skia.googlesource.com/skia/+/b12b3c6908c62c908b3680be01e3b5bfd30de310
Committed: https://skia.googlesource.com/skia/+/f008b0a59f45c0d4bea3e66faf3b01805009ec89
Committed: https://skia.googlesource.com/skia/+/08b2ccf398e2b81bc05d2c105837e5419899469b
Committed: https://skia.googlesource.com/skia/+/dcfe6dba4a335e50e86ff68e3252065d4197432c
Review-Url: https://codereview.chromium.org/2288033003
---
 src/sksl/ast/SkSLASTDeclaration.h          |  4 ++-
 src/sksl/ast/SkSLASTIndexSuffix.h          | 16 +++++++++--
 src/sksl/ast/SkSLASTLayout.h               | 17 +++++++++--
 src/sksl/ast/SkSLASTModifiersDeclaration.h | 37 ++++++++++++++++++++++++
 src/sksl/ast/SkSLASTPrecision.h            | 45 ++++++++++++++++++++++++++++++
 5 files changed, 113 insertions(+), 6 deletions(-)
 create mode 100644 src/sksl/ast/SkSLASTModifiersDeclaration.h
 create mode 100644 src/sksl/ast/SkSLASTPrecision.h

(limited to 'src/sksl/ast')

diff --git a/src/sksl/ast/SkSLASTDeclaration.h b/src/sksl/ast/SkSLASTDeclaration.h
index 8b55ecf832..70f0ebc72d 100644
--- a/src/sksl/ast/SkSLASTDeclaration.h
+++ b/src/sksl/ast/SkSLASTDeclaration.h
@@ -20,7 +20,9 @@ struct ASTDeclaration : public ASTPositionNode {
         kVar_Kind,
         kFunction_Kind,
         kInterfaceBlock_Kind,
-        kExtension_Kind
+        kExtension_Kind,
+        kPrecision_Kind,
+        kModifiers_Kind
     };
 
     ASTDeclaration(Position position, Kind kind)
diff --git a/src/sksl/ast/SkSLASTIndexSuffix.h b/src/sksl/ast/SkSLASTIndexSuffix.h
index 44d91fa4c4..755029b0a2 100644
--- a/src/sksl/ast/SkSLASTIndexSuffix.h
+++ b/src/sksl/ast/SkSLASTIndexSuffix.h
@@ -14,17 +14,27 @@
 namespace SkSL {
 
 /**
- * A bracketed expression, as in '[0]', indicating an array access. 
+ * A bracketed expression, as in '[0]', indicating an array access. Empty brackets (as occur in
+ * 'float[](5, 6)' are represented with a null fExpression.
  */
 struct ASTIndexSuffix : public ASTSuffix {
+    ASTIndexSuffix(Position position) 
+    : INHERITED(position, ASTSuffix::kIndex_Kind)
+    , fExpression(nullptr) {}
+
     ASTIndexSuffix(std::unique_ptr<ASTExpression> expression) 
-    : INHERITED(expression->fPosition, ASTSuffix::kIndex_Kind)
+    : INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kIndex_Kind)
     , fExpression(std::move(expression)) {}
 
     std::string description() const override {
-        return "[" + fExpression->description() + "]";
+        if (fExpression) {
+            return "[" + fExpression->description() + "]";
+        } else {
+            return "[]";
+        }
     }
 
+    // may be null
     std::unique_ptr<ASTExpression> fExpression;
 
     typedef ASTSuffix INHERITED;
diff --git a/src/sksl/ast/SkSLASTLayout.h b/src/sksl/ast/SkSLASTLayout.h
index 08d67531c3..515eb2bdbb 100644
--- a/src/sksl/ast/SkSLASTLayout.h
+++ b/src/sksl/ast/SkSLASTLayout.h
@@ -20,13 +20,16 @@ namespace SkSL {
  */
 struct ASTLayout : public ASTNode {
     // For all parameters, a -1 means no value
-    ASTLayout(int location, int binding, int index, int set, int builtin, bool originUpperLeft)
+    ASTLayout(int location, int binding, int index, int set, int builtin, bool originUpperLeft,
+              bool overrideCoverage, bool blendSupportAllEquations)
     : fLocation(location)
     , fBinding(binding)
     , fIndex(index)
     , fSet(set)
     , fBuiltin(builtin)
-    , fOriginUpperLeft(originUpperLeft) {}
+    , fOriginUpperLeft(originUpperLeft)
+    , fOverrideCoverage(overrideCoverage)
+    , fBlendSupportAllEquations(blendSupportAllEquations) {}
 
     std::string description() const {
         std::string result;
@@ -55,6 +58,14 @@ struct ASTLayout : public ASTNode {
             result += separator + "origin_upper_left";
             separator = ", ";
         }
+        if (fOverrideCoverage) {
+            result += separator + "override_coverage";
+            separator = ", ";
+        }
+        if (fBlendSupportAllEquations) {
+            result += separator + "blend_support_all_equations";
+            separator = ", ";
+        }
         if (result.length() > 0) {
             result = "layout (" + result + ")";
         }
@@ -67,6 +78,8 @@ struct ASTLayout : public ASTNode {
     const int fSet;
     const int fBuiltin;
     const bool fOriginUpperLeft;
+    const bool fOverrideCoverage;
+    const bool fBlendSupportAllEquations;
 };
 
 } // namespace
diff --git a/src/sksl/ast/SkSLASTModifiersDeclaration.h b/src/sksl/ast/SkSLASTModifiersDeclaration.h
new file mode 100644
index 0000000000..f5cc620899
--- /dev/null
+++ b/src/sksl/ast/SkSLASTModifiersDeclaration.h
@@ -0,0 +1,37 @@
+/*
+ * 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_ASTMODIFIERDECLARATION
+#define SKSL_ASTMODIFIERDECLARATION
+
+#include "SkSLASTDeclaration.h"
+#include "SkSLASTModifiers.h"
+
+namespace SkSL {
+
+/**
+ * A declaration that consists only of modifiers, e.g.:
+ *
+ * layout(blend_support_all_equations) out;
+ */
+struct ASTModifiersDeclaration : public ASTDeclaration {
+    ASTModifiersDeclaration(ASTModifiers modifiers)
+    : INHERITED(Position(), kModifiers_Kind)
+    , fModifiers(modifiers) {}
+
+    std::string description() const {
+        return fModifiers.description() + ";";
+    }
+
+    ASTModifiers fModifiers;
+
+    typedef ASTDeclaration INHERITED;
+};
+
+} // namespace
+
+#endif
diff --git a/src/sksl/ast/SkSLASTPrecision.h b/src/sksl/ast/SkSLASTPrecision.h
new file mode 100644
index 0000000000..a7df57948e
--- /dev/null
+++ b/src/sksl/ast/SkSLASTPrecision.h
@@ -0,0 +1,45 @@
+/*
+ * 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_ASTPRECISION
+#define SKSL_ASTPRECISION
+
+#include "SkSLASTDeclaration.h"
+#include "../ir/SkSLModifiers.h"
+
+namespace SkSL {
+
+/**
+ * Represents a precision declaration (e.g. 'precision mediump float;').
+ */
+struct ASTPrecision : public ASTDeclaration {
+    // FIXME handle the type
+    ASTPrecision(Position position, Modifiers::Flag precision)
+    : INHERITED(position, kPrecision_Kind)
+    , fPrecision(precision) {}
+
+    std::string description() const {
+        switch (fPrecision) {
+            case Modifiers::kLowp_Flag: return "precision lowp float;";
+            case Modifiers::kMediump_Flag: return "precision mediump float;";
+            case Modifiers::kHighp_Flag: return "precision highp float;";
+            default: 
+                ASSERT(false); 
+                return "<error>";
+        }
+        ASSERT(false);
+        return "<error>";
+    }
+
+    const Modifiers::Flag fPrecision;
+
+    typedef ASTDeclaration INHERITED;
+};
+
+} // namespace
+
+#endif
-- 
cgit v1.2.3