Removed ErrorHandler pointers from CodeGenerators
These pointers were largely redundant because the CodeGenerators also
had access to a Context, and in a future CL Context becomes the source
of truth regarding the current ErrorHandler, so they are potentially
dangerous.
Change-Id: Ie4175fcb3e1f586baaa42d16c05058aea78532f0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439164
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/codegen/SkSLMetalCodeGenerator.cpp b/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
index b39ee1c..6bc4698 100644
--- a/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLMetalCodeGenerator.cpp
@@ -1038,7 +1038,7 @@
} else if (c.type().isMatrix()) {
this->writeConstructorCompoundMatrix(c, parentPrecedence);
} else {
- fErrors.error(c.fOffset, "unsupported compound constructor");
+ fContext.errors().error(c.fOffset, "unsupported compound constructor");
}
}
@@ -1686,7 +1686,7 @@
this->write("vertex Outputs vertexMain");
break;
default:
- fErrors.error(-1, "unsupported kind of program");
+ fContext.errors().error(-1, "unsupported kind of program");
return false;
}
this->write("(Inputs _in [[stage_in]]");
@@ -1700,13 +1700,13 @@
const VarDeclaration& var = decls.declaration()->as<VarDeclaration>();
if (var.var().type().typeKind() == Type::TypeKind::kSampler) {
if (var.var().modifiers().fLayout.fBinding < 0) {
- fErrors.error(decls.fOffset,
- "Metal samplers must have 'layout(binding=...)'");
+ fContext.errors().error(decls.fOffset,
+ "Metal samplers must have 'layout(binding=...)'");
return false;
}
if (var.var().type().dimensions() != SpvDim2D) {
// Not yet implemented--Skia currently only uses 2D textures.
- fErrors.error(decls.fOffset, "Unsupported texture dimensions");
+ fContext.errors().error(decls.fOffset, "Unsupported texture dimensions");
return false;
}
this->write(", texture2d<float> ");
@@ -1894,14 +1894,15 @@
int fieldOffset = field.fModifiers.fLayout.fOffset;
const Type* fieldType = field.fType;
if (!MemoryLayout::LayoutIsSupported(*fieldType)) {
- fErrors.error(parentOffset, "type '" + fieldType->name() + "' is not permitted here");
+ fContext.errors().error(parentOffset, "type '" + fieldType->name() +
+ "' is not permitted here");
return;
}
if (fieldOffset != -1) {
if (currentOffset > fieldOffset) {
- fErrors.error(parentOffset,
- "offset of field '" + field.fName + "' must be at least " +
- to_string((int) currentOffset));
+ fContext.errors().error(parentOffset,
+ "offset of field '" + field.fName + "' must be at least " +
+ to_string((int) currentOffset));
return;
} else if (currentOffset < fieldOffset) {
this->write("char pad");
@@ -1913,15 +1914,15 @@
}
int alignment = memoryLayout.alignment(*fieldType);
if (fieldOffset % alignment) {
- fErrors.error(parentOffset,
- "offset of field '" + field.fName + "' must be a multiple of " +
- to_string((int) alignment));
+ fContext.errors().error(parentOffset,
+ "offset of field '" + field.fName + "' must be a multiple of " +
+ to_string((int) alignment));
return;
}
}
size_t fieldSize = memoryLayout.size(*fieldType);
if (fieldSize > static_cast<size_t>(std::numeric_limits<int>::max() - currentOffset)) {
- fErrors.error(parentOffset, "field offset overflow");
+ fContext.errors().error(parentOffset, "field offset overflow");
return;
}
currentOffset += fieldSize;
@@ -2116,8 +2117,9 @@
this->writeExpression(*r.expression(), Precedence::kTopLevel);
this->writeLine(";");
} else {
- fErrors.error(r.fOffset, "Metal does not support returning '" +
- r.expression()->type().description() + "' from main()");
+ fContext.errors().error(r.fOffset,
+ "Metal does not support returning '" +
+ r.expression()->type().description() + "' from main()");
}
}
this->writeReturnStatementFromMain();
@@ -2151,8 +2153,9 @@
this->write("struct Uniforms {\n");
fUniformBuffer = uniformSet;
} else if (uniformSet != fUniformBuffer) {
- fErrors.error(decls.fOffset, "Metal backend requires all uniforms to have "
- "the same 'layout(set=...)'");
+ fContext.errors().error(decls.fOffset,
+ "Metal backend requires all uniforms to have the same "
+ "'layout(set=...)'");
}
this->write(" ");
this->writeType(var.type());
@@ -2215,8 +2218,8 @@
int location = var.modifiers().fLayout.fLocation;
if (location < 0) {
- fErrors.error(var.fOffset,
- "Metal out variables must have 'layout(location=...)'");
+ fContext.errors().error(var.fOffset,
+ "Metal out variables must have 'layout(location=...)'");
} else if (fProgram.fConfig->fKind == ProgramKind::kVertex) {
this->write(" [[user(locn" + to_string(location) + ")]]");
} else if (fProgram.fConfig->fKind == ProgramKind::kFragment) {
@@ -2600,7 +2603,7 @@
write_stringstream(fExtraFunctionPrototypes, *fOut);
write_stringstream(fExtraFunctions, *fOut);
write_stringstream(body, *fOut);
- return 0 == fErrors.errorCount();
+ return fContext.errors().errorCount() == 0;
}
} // namespace SkSL