Improve handling of SkSL literal types.
Previously, the only way to detect a literal Type was to explicitly
check against the values fFloatLiteral/fIntLiteral or compare the name
against $floatLiteral or $intLiteral.
Now, you can call type.isLiteral() to see if the type corresponds to a
literal, or call type.scalarTypeForLiteral() to promote to the
equivalent non-literal type (fFloat/fInt). Calling
type.scalarTypeForLiteral() on a non-literal type is safe and will just
return the input type unscathed.
Change-Id: Ib939dda9bcd43b3ef4159211c5349d71fc857b95
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353037
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp
index e0fcc2f..76f8e59 100644
--- a/src/sksl/SkSLInliner.cpp
+++ b/src/sksl/SkSLInliner.cpp
@@ -595,12 +595,9 @@
// $floatLiteral or $intLiteral aren't real types that we can use for scratch variables, so
// replace them if they ever appear here. If this happens, we likely forgot to coerce a type
// somewhere during compilation.
- if (type == fContext->fTypes.fFloatLiteral.get()) {
- SkDEBUGFAIL("found a $floatLiteral type while inlining");
- type = fContext->fTypes.fFloat.get();
- } else if (type == fContext->fTypes.fIntLiteral.get()) {
- SkDEBUGFAIL("found an $intLiteral type while inlining");
- type = fContext->fTypes.fInt.get();
+ if (type->isLiteral()) {
+ SkDEBUGFAIL("found a $literal type while inlining");
+ type = &type->scalarTypeForLiteral();
}
// Provide our new variable with a unique name, and add it to our symbol table.