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_VARDECLARATIONS | |
9 #define SKSL_VARDECLARATIONS | |
10 | |
11 #include "SkSLExpression.h" | |
12 #include "SkSLStatement.h" | |
13 #include "SkSLVariable.h" | |
14 | |
15 namespace SkSL { | |
16 | |
17 /** | |
18 * A single variable declaration within a var declaration statement. For instanc
e, the statement | |
19 * 'int x = 2, y[3];' is a VarDeclarations statement containing two individual V
arDeclaration | |
20 * instances. | |
21 */ | |
22 struct VarDeclaration { | |
23 VarDeclaration(const Variable* var, | |
24 std::vector<std::unique_ptr<Expression>> sizes, | |
25 std::unique_ptr<Expression> value) | |
26 : fVar(var) | |
27 , fSizes(std::move(sizes)) | |
28 , fValue(std::move(value)) {} | |
29 | |
30 std::string description() const { | |
31 std::string result = fVar->fName; | |
32 for (const auto& size : fSizes) { | |
33 if (size) { | |
34 result += "[" + size->description() + "]"; | |
35 } else { | |
36 result += "[]"; | |
37 } | |
38 } | |
39 if (fValue) { | |
40 result += " = " + fValue->description(); | |
41 } | |
42 return result; | |
43 } | |
44 | |
45 const Variable* fVar; | |
46 std::vector<std::unique_ptr<Expression>> fSizes; | |
47 std::unique_ptr<Expression> fValue; | |
48 }; | |
49 | |
50 /** | |
51 * A variable declaration statement, which may consist of one or more individual
variables. | |
52 */ | |
53 struct VarDeclarations : public ProgramElement { | |
54 VarDeclarations(Position position, const Type* baseType, | |
55 std::vector<VarDeclaration> vars) | |
56 : INHERITED(position, kVar_Kind) | |
57 , fBaseType(*baseType) | |
58 , fVars(std::move(vars)) {} | |
59 | |
60 std::string description() const override { | |
61 if (!fVars.size()) { | |
62 return ""; | |
63 } | |
64 std::string result = fVars[0].fVar->fModifiers.description() + fBaseType
.description() + | |
65 " "; | |
66 std::string separator = ""; | |
67 for (const auto& var : fVars) { | |
68 result += separator; | |
69 separator = ", "; | |
70 result += var.description(); | |
71 } | |
72 return result; | |
73 } | |
74 | |
75 const Type& fBaseType; | |
76 const std::vector<VarDeclaration> fVars; | |
77 | |
78 typedef ProgramElement INHERITED; | |
79 }; | |
80 | |
81 } // namespace | |
82 | |
83 #endif | |
OLD | NEW |