Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 woul d 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, | |
|
dogben
2016/06/20 16:23:18
Just to make sure I understand: array variable dec
ethannicholas
2016/06/20 17:45:49
Correct.
| |
| 29 std::vector<std::unique_ptr<ASTExpression>> values) | |
| 30 : INHERITED(type->fPosition, kVar_Kind) | |
| 31 , fModifiers(modifiers) | |
| 32 , fType(std::move(type)) | |
| 33 , fNames(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 for (size_t i = 0; i < fNames.size(); i++) { | |
| 42 result += fNames[i]; | |
| 43 for (size_t j = 0; j < fSizes[i].size(); j++) { | |
| 44 if (fSizes[i][j]) { | |
| 45 result += "[" + fSizes[i][j]->description() + "]"; | |
| 46 } else { | |
| 47 result += "[]"; | |
| 48 } | |
| 49 } | |
| 50 if (fValues[i]) { | |
| 51 result += " = " + fValues[i]->description(); | |
| 52 } | |
| 53 } | |
|
dogben
2016/06/20 16:23:18
missing comma between variables?
| |
| 54 return result + ";"; | |
| 55 } | |
| 56 | |
| 57 const ASTModifiers fModifiers; | |
| 58 const std::unique_ptr<ASTType> fType; | |
| 59 const std::vector<std::string> fNames; | |
| 60 const std::vector<std::vector<std::unique_ptr<ASTExpression>>> fSizes; | |
| 61 const std::vector<std::unique_ptr<ASTExpression>> fValues; | |
| 62 | |
| 63 typedef ASTDeclaration INHERITED; | |
| 64 }; | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 68 #endif | |
| OLD | NEW |