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

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

Issue 1984363002: initial checkin of SkSL compiler (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: fixed CMake build 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
« no previous file with comments | « src/sksl/ir/SkSLUnresolvedFunction.h ('k') | src/sksl/ir/SkSLVarDeclarationStatement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/sksl/ir/SkSLVarDeclaration.h
diff --git a/src/sksl/ir/SkSLVarDeclaration.h b/src/sksl/ir/SkSLVarDeclaration.h
new file mode 100644
index 0000000000000000000000000000000000000000..400f430e4c574d234e2a5e80b34a9f3412304310
--- /dev/null
+++ b/src/sksl/ir/SkSLVarDeclaration.h
@@ -0,0 +1,67 @@
+/*
+ * 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_VARDECLARATION
+#define SKSL_VARDECLARATION
+
+#include "SkSLExpression.h"
+#include "SkSLStatement.h"
+#include "SkSLVariable.h"
+
+namespace SkSL {
+
+/**
+ * A variable declaration, which may consist of multiple individual variables. For instance
+ * 'int x, y = 1, z[4][2];' is a single VarDeclaration. This declaration would have a type of 'int',
+ * names ['x', 'y', 'z'], sizes of [[], [], [4, 2]], and values of [null, 1, null].
+ */
+struct VarDeclaration : public ProgramElement {
+ VarDeclaration(Position position, std::vector<std::shared_ptr<Variable>> vars,
+ std::vector<std::vector<std::unique_ptr<Expression>>> sizes,
+ std::vector<std::unique_ptr<Expression>> values)
+ : INHERITED(position, kVar_Kind)
+ , fVars(std::move(vars))
+ , fSizes(std::move(sizes))
+ , fValues(std::move(values)) {}
+
+ std::string description() const override {
+ std::string result = fVars[0]->fModifiers.description();
+ std::shared_ptr<Type> baseType = fVars[0]->fType;
+ while (baseType->kind() == Type::kArray_Kind) {
+ baseType = baseType->componentType();
+ }
+ result += baseType->description();
+ std::string separator = " ";
+ for (size_t i = 0; i < fVars.size(); i++) {
+ result += separator;
+ separator = ", ";
+ result += fVars[i]->fName;
+ for (size_t j = 0; j < fSizes[i].size(); j++) {
+ if (fSizes[i][j]) {
+ result += "[" + fSizes[i][j]->description() + "]";
+ } else {
+ result += "[]";
+ }
+ }
+ if (fValues[i]) {
+ result += " = " + fValues[i]->description();
+ }
+ }
+ result += ";";
+ return result;
+ }
+
+ const std::vector<std::shared_ptr<Variable>> fVars;
+ const std::vector<std::vector<std::unique_ptr<Expression>>> fSizes;
+ const std::vector<std::unique_ptr<Expression>> fValues;
+
+ typedef ProgramElement INHERITED;
+};
+
+} // namespace
+
+#endif
« no previous file with comments | « src/sksl/ir/SkSLUnresolvedFunction.h ('k') | src/sksl/ir/SkSLVarDeclarationStatement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698