Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4dfa977

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Add 'isBoolean' method to SkSL::Type.
We have built-in methods for determining whether a type is an int, float, signed, unsigned, matrix, vector, etc. For some reason, however, the lowly boolean never received similar treatment. Now, booleans are a first-class citizen and can be identified by calling `isBoolean` instead of doing a string compare or looking at the Context type pointers. (I did do a quick search to make sure that kNonnumeric wasn't used anywhere else to check for Boolean-ness.) Change-Id: I35c0e3c7530c13e2c4e307a70272d298ce6b44bc Reviewed-on: https://skia-review.googlesource.com/c/skia/+/338042 Commit-Queue: John Stiles <[email protected]> Commit-Queue: Brian Osman <[email protected]> Auto-Submit: John Stiles <[email protected]> Reviewed-by: Brian Osman <[email protected]>
1 parent feada47 commit 4dfa977

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

src/sksl/SkSLByteCodeGenerator.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ static TypeCategory type_category(const Type& type) {
1717
case Type::TypeKind::kMatrix:
1818
return type_category(type.componentType());
1919
default:
20-
const StringFragment& name = type.name();
21-
if (name == "bool") {
20+
if (type.isBoolean()) {
2221
return TypeCategory::kBool;
23-
} else if (name == "int" ||
24-
name == "short" ||
25-
name == "$intLiteral") {
22+
}
23+
const StringFragment& name = type.name();
24+
if (name == "int" ||
25+
name == "short" ||
26+
name == "$intLiteral") {
2627
return TypeCategory::kSigned;
27-
} else if (name == "uint" ||
28-
name == "ushort") {
28+
}
29+
if (name == "uint" ||
30+
name == "ushort") {
2931
return TypeCategory::kUnsigned;
30-
} else {
31-
SkASSERT(name == "float" ||
32-
name == "half" ||
33-
name == "$floatLiteral");
34-
return TypeCategory::kFloat;
3532
}
36-
ABORT("unsupported type: %s\n", type.displayName().c_str());
33+
SkASSERT(name == "float" ||
34+
name == "half" ||
35+
name == "$floatLiteral");
36+
return TypeCategory::kFloat;
3737
}
3838
}
3939

src/sksl/SkSLCPPCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void CPPCodeGenerator::writeBinaryExpression(const BinaryExpression& b,
116116
}
117117

118118
static String default_value(const Type& type) {
119-
if (type.name() == "bool") {
119+
if (type.isBoolean()) {
120120
return "false";
121121
}
122122
switch (type.typeKind()) {

src/sksl/SkSLContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Context {
5858
, fByte2_Type(new Type("byte2", *fByte_Type, 2))
5959
, fByte3_Type(new Type("byte3", *fByte_Type, 3))
6060
, fByte4_Type(new Type("byte4", *fByte_Type, 4))
61-
, fBool_Type(new Type("bool", Type::NumberKind::kNonnumeric, -1))
61+
, fBool_Type(new Type("bool", Type::NumberKind::kBoolean, -1))
6262
, fBool2_Type(new Type("bool2", *fBool_Type, 2))
6363
, fBool3_Type(new Type("bool3", *fBool_Type, 3))
6464
, fBool4_Type(new Type("bool4", *fBool_Type, 4))

src/sksl/SkSLMemoryLayout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class MemoryLayout {
103103
size_t size(const Type& type) const {
104104
switch (type.typeKind()) {
105105
case Type::TypeKind::kScalar:
106-
if (type.name() == "bool") {
106+
if (type.isBoolean()) {
107107
return 1;
108108
}
109109
// FIXME need to take precision into account, once we figure out how we want to

src/sksl/ir/SkSLType.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class Type final : public Symbol {
9191
kFloat,
9292
kSigned,
9393
kUnsigned,
94+
kBoolean,
9495
kNonnumeric
9596
};
9697

@@ -260,11 +261,18 @@ class Type final : public Symbol {
260261
return fTypeKind;
261262
}
262263

264+
/**
265+
* Returns true if this type is a bool.
266+
*/
267+
bool isBoolean() const {
268+
return fNumberKind == NumberKind::kBoolean;
269+
}
270+
263271
/**
264272
* Returns true if this is a numeric scalar type.
265273
*/
266274
bool isNumber() const {
267-
return fNumberKind != NumberKind::kNonnumeric;
275+
return this->isFloat() || this->isInteger();
268276
}
269277

270278
/**
@@ -292,7 +300,7 @@ class Type final : public Symbol {
292300
* Returns true if this is a signed or unsigned integer.
293301
*/
294302
bool isInteger() const {
295-
return isSigned() || isUnsigned();
303+
return this->isSigned() || this->isUnsigned();
296304
}
297305

298306
/**

0 commit comments

Comments
 (0)