Skip to content

Commit 1c82367

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Clear the builtin status of SkSL nodes when they are cloned.
This has a slight ripple effect into Enum, as it was using the builtin status as an indicator that the enum was shared with C++ code. This now has a dedicated bool flag. Change-Id: Id03efa902546775666acd031e6d57123e02b6c6e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328381 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
1 parent b270568 commit 1c82367

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

src/sksl/SkSLHCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ bool HCodeGenerator::generateCode() {
356356
"public:\n",
357357
fFullName.c_str());
358358
for (const auto& p : fProgram.elements()) {
359-
if (p->is<Enum>() && !p->as<Enum>().isBuiltin()) {
359+
if (p->is<Enum>() && !p->as<Enum>().isSharedWithCpp()) {
360360
this->writef("%s\n", p->as<Enum>().code().c_str());
361361
}
362362
}

src/sksl/SkSLIRGenerator.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,9 @@ void IRGenerator::convertEnum(const ASTNode& e) {
12321232
}
12331233
// Now we orphanize the Enum's symbol table, so that future lookups in it are strict
12341234
fSymbolTable->fParent = nullptr;
1235-
fProgramElements->push_back(std::unique_ptr<ProgramElement>(
1236-
new Enum(e.fOffset, e.getString(), fSymbolTable, fIsBuiltinCode)));
1235+
fProgramElements->push_back(std::make_unique<Enum>(e.fOffset, e.getString(), fSymbolTable,
1236+
/*isSharedWithCpp=*/fIsBuiltinCode,
1237+
/*isBuiltin=*/fIsBuiltinCode));
12371238
fSymbolTable = oldTable;
12381239
}
12391240

@@ -2021,10 +2022,7 @@ void IRGenerator::copyIntrinsicIfNeeded(const FunctionDeclaration& function) {
20212022
this->copyIntrinsicIfNeeded(*f);
20222023
}
20232024

2024-
// Unmark the function as a built-in when cloning it, so that it is eligible for alteration.
2025-
std::unique_ptr<ProgramElement> clonedIntrinsicFn = original.clone();
2026-
clonedIntrinsicFn->as<FunctionDefinition>().setBuiltin(false);
2027-
fProgramElements->push_back(std::move(clonedIntrinsicFn));
2025+
fProgramElements->push_back(original.clone());
20282026
}
20292027
}
20302028

src/sksl/SkSLRehydrator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ std::unique_ptr<ProgramElement> Rehydrator::element() {
304304
v.setInitialValue(symbols->takeOwnershipOfIRNode(
305305
std::make_unique<IntLiteral>(fContext, /*offset=*/-1, value)));
306306
}
307-
return std::unique_ptr<ProgramElement>(new Enum(-1, typeName, std::move(symbols)));
307+
return std::make_unique<Enum>(/*offset=*/-1, typeName, std::move(symbols),
308+
/*isSharedWithCpp=*/true, /*isBuiltin=*/true);
308309
}
309310
case Rehydrator::kFunctionDefinition_Command: {
310311
const FunctionDeclaration* decl = this->symbolRef<FunctionDeclaration>(

src/sksl/ir/SkSLEnum.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class Enum : public ProgramElement {
2525
static constexpr Kind kProgramElementKind = Kind::kEnum;
2626

2727
Enum(int offset, StringFragment typeName, std::shared_ptr<SymbolTable> symbols,
28-
bool isBuiltin = true)
29-
: INHERITED(offset, EnumData{typeName, std::move(symbols), isBuiltin}) {}
28+
bool isSharedWithCpp, bool isBuiltin = true)
29+
: INHERITED(offset, EnumData{typeName, std::move(symbols), isSharedWithCpp, isBuiltin}) {}
3030

3131
StringFragment typeName() const {
3232
return this->enumData().fTypeName;
@@ -40,9 +40,13 @@ class Enum : public ProgramElement {
4040
return this->enumData().fIsBuiltin;
4141
}
4242

43+
bool isSharedWithCpp() const {
44+
return this->enumData().fIsSharedWithCpp;
45+
}
46+
4347
std::unique_ptr<ProgramElement> clone() const override {
44-
return std::unique_ptr<ProgramElement>(new Enum(fOffset, this->typeName(), this->symbols(),
45-
this->isBuiltin()));
48+
return std::make_unique<Enum>(fOffset, this->typeName(), this->symbols(),
49+
this->isSharedWithCpp(), /*isBuiltin=*/false);
4650
}
4751

4852
String code() const {

src/sksl/ir/SkSLFunctionDefinition.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ struct FunctionDefinition : public ProgramElement {
4040
return this->functionDefinitionData().fBuiltin;
4141
}
4242

43-
void setBuiltin(bool builtin) {
44-
this->functionDefinitionData().fBuiltin = builtin;
45-
}
46-
4743
std::unique_ptr<Statement>& body() {
4844
return this->fStatementChildren[0];
4945
}
@@ -66,7 +62,7 @@ struct FunctionDefinition : public ProgramElement {
6662

6763
std::unique_ptr<ProgramElement> clone() const override {
6864
return std::make_unique<FunctionDefinition>(fOffset, &this->declaration(),
69-
this->isBuiltin(), this->body()->clone(),
65+
/*builtin=*/false, this->body()->clone(),
7066
this->referencedIntrinsics());
7167
}
7268

src/sksl/ir/SkSLIRNode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class IRNode {
8181
struct EnumData {
8282
StringFragment fTypeName;
8383
std::shared_ptr<SymbolTable> fSymbols;
84+
bool fIsSharedWithCpp;
8485
bool fIsBuiltin;
8586
};
8687

0 commit comments

Comments
 (0)