1 | /* |
2 | * Copyright 2019 Google LLC. |
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 | #include "src/sksl/SkSLSectionAndParameterHelper.h" |
9 | #include "src/sksl/ir/SkSLBinaryExpression.h" |
10 | #include "src/sksl/ir/SkSLConstructor.h" |
11 | #include "src/sksl/ir/SkSLDoStatement.h" |
12 | #include "src/sksl/ir/SkSLExpressionStatement.h" |
13 | #include "src/sksl/ir/SkSLFieldAccess.h" |
14 | #include "src/sksl/ir/SkSLForStatement.h" |
15 | #include "src/sksl/ir/SkSLFunctionCall.h" |
16 | #include "src/sksl/ir/SkSLIfStatement.h" |
17 | #include "src/sksl/ir/SkSLIndexExpression.h" |
18 | #include "src/sksl/ir/SkSLPostfixExpression.h" |
19 | #include "src/sksl/ir/SkSLPrefixExpression.h" |
20 | #include "src/sksl/ir/SkSLReturnStatement.h" |
21 | #include "src/sksl/ir/SkSLSwitchStatement.h" |
22 | #include "src/sksl/ir/SkSLSwizzle.h" |
23 | #include "src/sksl/ir/SkSLTernaryExpression.h" |
24 | #include "src/sksl/ir/SkSLVarDeclarationsStatement.h" |
25 | #include "src/sksl/ir/SkSLWhileStatement.h" |
26 | |
27 | namespace SkSL { |
28 | |
29 | SectionAndParameterHelper::SectionAndParameterHelper(const Program* program, ErrorReporter& errors) |
30 | : fProgram(*program) { |
31 | for (const auto& p : fProgram) { |
32 | switch (p.fKind) { |
33 | case ProgramElement::kVar_Kind: { |
34 | const VarDeclarations& decls = (const VarDeclarations&) p; |
35 | for (const auto& raw : decls.fVars) { |
36 | const VarDeclaration& decl = (VarDeclaration&) *raw; |
37 | if (IsParameter(*decl.fVar)) { |
38 | fParameters.push_back(decl.fVar); |
39 | } |
40 | } |
41 | break; |
42 | } |
43 | case ProgramElement::kSection_Kind: { |
44 | const Section& s = (const Section&) p; |
45 | if (IsSupportedSection(s.fName.c_str())) { |
46 | if (SectionRequiresArgument(s.fName.c_str()) && !s.fArgument.size()) { |
47 | errors.error(s.fOffset, |
48 | ("section '@" + s.fName + |
49 | "' requires one parameter" ).c_str()); |
50 | } |
51 | if (!SectionAcceptsArgument(s.fName.c_str()) && s.fArgument.size()) { |
52 | errors.error(s.fOffset, |
53 | ("section '@" + s.fName + "' has no parameters" ).c_str()); |
54 | } |
55 | } else { |
56 | errors.error(s.fOffset, |
57 | ("unsupported section '@" + s.fName + "'" ).c_str()); |
58 | } |
59 | if (!SectionPermitsDuplicates(s.fName.c_str()) && |
60 | fSections.find(s.fName) != fSections.end()) { |
61 | errors.error(s.fOffset, |
62 | ("duplicate section '@" + s.fName + "'" ).c_str()); |
63 | } |
64 | fSections[s.fName].push_back(&s); |
65 | break; |
66 | } |
67 | default: |
68 | break; |
69 | } |
70 | } |
71 | } |
72 | |
73 | } // namespace SkSL |
74 | |