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

Side by Side Diff: src/sksl/ast/SkSLASTVarDeclaration.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, 5 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 unified diff | Download patch
« no previous file with comments | « src/sksl/ast/SkSLASTType.h ('k') | src/sksl/ast/SkSLASTVarDeclarationStatement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_ASTVARDECLARATION
9 #define SKSL_ASTVARDECLARATION
10
11 #include "SkSLASTDeclaration.h"
12 #include "SkSLASTModifiers.h"
13 #include "SkSLASTStatement.h"
14 #include "SkSLASTType.h"
15 #include "../SkSLUtil.h"
16
17 namespace SkSL {
18
19 /**
20 * A variable declaration, which may consist of multiple individual variables. F or instance
21 * 'int x, y = 1, z[4][2]' is a single ASTVarDeclaration. This declaration would have a type of
22 * 'int', names ['x', 'y', 'z'], sizes of [[], [], [4, 2]], and values of [null, 1, null].
23 */
24 struct ASTVarDeclaration : public ASTDeclaration {
25 ASTVarDeclaration(ASTModifiers modifiers,
26 std::unique_ptr<ASTType> type,
27 std::vector<std::string> names,
28 std::vector<std::vector<std::unique_ptr<ASTExpression>>> s izes,
29 std::vector<std::unique_ptr<ASTExpression>> values)
30 : INHERITED(type->fPosition, kVar_Kind)
31 , fModifiers(modifiers)
32 , fType(std::move(type))
33 , fNames(std::move(names))
34 , fSizes(std::move(sizes))
35 , fValues(std::move(values)) {
36 ASSERT(fNames.size() == fValues.size());
37 }
38
39 std::string description() const override {
40 std::string result = fModifiers.description() + fType->description() + " ";
41 std::string separator = "";
42 for (size_t i = 0; i < fNames.size(); i++) {
43 result += separator;
44 separator = ", ";
45 result += fNames[i];
46 for (size_t j = 0; j < fSizes[i].size(); j++) {
47 if (fSizes[i][j]) {
48 result += "[" + fSizes[i][j]->description() + "]";
49 } else {
50 result += "[]";
51 }
52 }
53 if (fValues[i]) {
54 result += " = " + fValues[i]->description();
55 }
56 }
57 return result;
58 }
59
60 const ASTModifiers fModifiers;
61 const std::unique_ptr<ASTType> fType;
62 const std::vector<std::string> fNames;
63 const std::vector<std::vector<std::unique_ptr<ASTExpression>>> fSizes;
64 const std::vector<std::unique_ptr<ASTExpression>> fValues;
65
66 typedef ASTDeclaration INHERITED;
67 };
68
69 } // namespace
70
71 #endif
OLDNEW
« no previous file with comments | « src/sksl/ast/SkSLASTType.h ('k') | src/sksl/ast/SkSLASTVarDeclarationStatement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698