From 31381af8990b6f62e2ce9cf2bdc34ec4d66de96b Mon Sep 17 00:00:00 2001 From: John Stiles Date: Fri, 26 Feb 2021 20:42:07 -0500 Subject: [PATCH] Migrate type_is_or_contains_array into Type class. This will be used in the Make functions for BinaryExpression, TernaryExpression and Function. Change-Id: Ifde9ca83ab415a00c4712eaa43fd93c695b915cb Bug: skia:11342 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/377097 Auto-Submit: John Stiles Reviewed-by: Ethan Nicholas --- src/sksl/SkSLIRGenerator.cpp | 19 +++---------------- src/sksl/ir/SkSLType.cpp | 14 ++++++++++++++ src/sksl/ir/SkSLType.h | 2 ++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 8848838408..6503076fc7 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -1008,19 +1008,6 @@ void IRGenerator::finalizeFunction(FunctionDefinition& f) { Finalizer(this, &f.declaration()).visitStatement(*f.body()); } -static bool type_is_or_contains_array(const Type* type) { - if (type->isStruct()) { - for (const auto& f : type->fields()) { - if (type_is_or_contains_array(f.fType)) { - return true; - } - } - return false; - } - - return type->isArray(); -} - void IRGenerator::convertFunction(const ASTNode& f) { SkASSERT(fReferencedIntrinsics.empty()); SK_AT_SCOPE_EXIT(fReferencedIntrinsics.clear()); @@ -1035,7 +1022,7 @@ void IRGenerator::convertFunction(const ASTNode& f) { f.fOffset, "functions may not return type '" + returnType->displayName() + "'"); return; } - if (this->strictES2Mode() && type_is_or_contains_array(returnType)) { + if (this->strictES2Mode() && returnType->isOrContainsArray()) { this->errorReporter().error(f.fOffset, "functions may not return structs containing arrays"); return; @@ -1675,7 +1662,7 @@ std::unique_ptr IRGenerator::convertBinaryExpression( this->errorReporter().error(offset, "assignments to opaque type '" + left->type().displayName() + "' are not permitted"); } - if (this->strictES2Mode() && type_is_or_contains_array(leftType)) { + if (this->strictES2Mode() && leftType->isOrContainsArray()) { // Most operators are already rejected on arrays, but GLSL ES 1.0 is very explicit that the // *only* operator allowed on arrays is subscripting (and the rules against assignment, // comparison, and even sequence apply to structs containing arrays as well). @@ -1727,7 +1714,7 @@ std::unique_ptr IRGenerator::convertTernaryExpression( trueType->displayName() + "' not allowed"); return nullptr; } - if (this->strictES2Mode() && type_is_or_contains_array(trueType)) { + if (this->strictES2Mode() && trueType->isOrContainsArray()) { this->errorReporter().error(offset, "ternary operator result may not be an array (or " "struct containing an array)"); return nullptr; diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp index 12ec2bffb2..c6aaa17526 100644 --- a/src/sksl/ir/SkSLType.cpp +++ b/src/sksl/ir/SkSLType.cpp @@ -275,4 +275,18 @@ std::unique_ptr Type::coerceExpression(std::unique_ptr e return Constructor::Make(context, offset, this->scalarTypeForLiteral(), std::move(args)); } +bool Type::isOrContainsArray() const { + if (this->isStruct()) { + for (const Field& f : this->fields()) { + if (f.fType->isOrContainsArray()) { + return true; + } + } + return false; + } + + return this->isArray(); +} + + } // namespace SkSL diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h index c863d9830b..63dea33e30 100644 --- a/src/sksl/ir/SkSLType.h +++ b/src/sksl/ir/SkSLType.h @@ -358,6 +358,8 @@ public: return fHighPrecision; } + bool isOrContainsArray() const; + /** * Returns the corresponding vector or matrix type with the specified number of columns and * rows.