Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Unified Diff: src/sksl/ir/SkSLIndexExpression.h

Issue 1984363002: initial checkin of SkSL compiler (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: more cleanups Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/sksl/ir/SkSLIndexExpression.h
diff --git a/src/sksl/ir/SkSLIndexExpression.h b/src/sksl/ir/SkSLIndexExpression.h
new file mode 100644
index 0000000000000000000000000000000000000000..40e713c79906cfd8252bdb40941e1918f3cad4bf
--- /dev/null
+++ b/src/sksl/ir/SkSLIndexExpression.h
@@ -0,0 +1,64 @@
+/*
+ * 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_INDEX
+#define SKSL_INDEX
+
+#include "SkSLExpression.h"
+#include "SkSLUtil.h"
+
+namespace SkSL {
+
+/**
+ * Given a type, returns the type that will resulting from extracting an array value from it.
dogben 2016/06/22 17:43:57 typo: s/resulting/result/
+ */
+static std::shared_ptr<Type> index_type(std::shared_ptr<Type> type) {
+ if (type->kind() == Type::kMatrix_Kind) {
+ if (type->componentType() == kFloat_Type) {
+ switch (type->columns()) {
+ case 2: return kVec2_Type;
+ case 3: return kVec3_Type;
+ case 4: return kVec4_Type;
+ default: ASSERT(false);
+ }
+ } else {
+ ASSERT(type->componentType() == kDouble_Type);
+ switch (type->columns()) {
+ case 2: return kDVec2_Type;
+ case 3: return kDVec3_Type;
+ case 4: return kDVec4_Type;
+ default: ASSERT(false);
+ }
+ }
+ }
+ return type->componentType();
+}
+
+/**
+ * An expression which extracts a value from an array or matrix, as in 'm[2]'.
+ */
+struct IndexExpression : public Expression {
+ IndexExpression(std::unique_ptr<Expression> base, std::unique_ptr<Expression> index)
+ : INHERITED(base->fPosition, kIndex_Kind, index_type(base->fType))
+ , fBase(std::move(base))
+ , fIndex(std::move(index)) {
+ ASSERT(fIndex->fType == kInt_Type);
+ }
+
+ virtual std::string description() const override {
dogben 2016/06/22 17:43:57 nit: remove virtual
+ return fBase->description() + "[" + fIndex->description() + "]";
+ }
+
+ const std::unique_ptr<Expression> fBase;
+ const std::unique_ptr<Expression> fIndex;
+
+ typedef Expression INHERITED;
+};
+
+} // namespace
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698