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_ASTPARAMETER
9 #define SKSL_ASTPARAMETER
10 
11 #include "SkSLASTPositionNode.h"
12 #include "SkSLASTType.h"
13 #include "../ir/SkSLModifiers.h"
14 
15 namespace SkSL {
16 
17 /**
18  * A declaration of a parameter, as part of a function declaration.
19  */
20 struct ASTParameter : public ASTPositionNode {
21     // 'sizes' is a list of the array sizes appearing on a parameter, in source order.
22     // e.g. int x[3][1] would have sizes [3, 1].
ASTParameterASTParameter23     ASTParameter(int offset, Modifiers modifiers, std::unique_ptr<ASTType> type,
24                  StringFragment name, std::vector<int> sizes)
25     : INHERITED(offset)
26     , fModifiers(modifiers)
27     , fType(std::move(type))
28     , fName(name)
29     , fSizes(std::move(sizes)) {}
30 
descriptionASTParameter31     String description() const override {
32         String result = fModifiers.description() + fType->description() + " " + fName;
33         for (int size : fSizes) {
34             result += "[" + to_string(size) + "]";
35         }
36         return result;
37     }
38 
39     const Modifiers fModifiers;
40     const std::unique_ptr<ASTType> fType;
41     const StringFragment fName;
42     const std::vector<int> fSizes;
43 
44     typedef ASTPositionNode INHERITED;
45 };
46 
47 } // namespace
48 
49 #endif
50