Replace SkSL string macros with inline constexpr char arrays.
C++17 introduced `inline constexpr` as a mechanism for declaring strings
in headers safely without macros. See https://abseil.io/tips/168
Change-Id: I68071fbadebf32753ca4a0586b96e32634083f6a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309047
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp
index 92da59f..6f9375b 100644
--- a/src/sksl/SkSLHCodeGenerator.cpp
+++ b/src/sksl/SkSLHCodeGenerator.cpp
@@ -137,7 +137,7 @@
// super-simple parse, just assume the last token before a comma is the name of a parameter
// (which is true as long as there are no multi-parameter template types involved). Will replace
// this with something more robust if the need arises.
- const Section* section = fSectionAndParameterHelper.getSection(CONSTRUCTOR_PARAMS_SECTION);
+ const Section* section = fSectionAndParameterHelper.getSection(kConstructorParamsSection);
if (section) {
const char* s = section->fText.c_str();
#define BUFFER_SIZE 64
@@ -178,7 +178,7 @@
void HCodeGenerator::writeMake() {
const char* separator;
- if (!this->writeSection(MAKE_SECTION)) {
+ if (!this->writeSection(kMakeSection)) {
this->writef(" static std::unique_ptr<GrFragmentProcessor> Make(");
separator = "";
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
@@ -187,7 +187,7 @@
String(param->fName).c_str());
separator = ", ";
}
- this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator);
+ this->writeSection(kConstructorParamsSection, separator);
this->writef(") {\n"
" return std::unique_ptr<GrFragmentProcessor>(new %s(",
fFullName.c_str());
@@ -215,12 +215,12 @@
}
void HCodeGenerator::writeConstructor() {
- if (this->writeSection(CONSTRUCTOR_SECTION)) {
+ if (this->writeSection(kConstructorSection)) {
const char* msg = "may not be present when constructor is overridden";
- this->failOnSection(CONSTRUCTOR_CODE_SECTION, msg);
- this->failOnSection(CONSTRUCTOR_PARAMS_SECTION, msg);
- this->failOnSection(INITIALIZERS_SECTION, msg);
- this->failOnSection(OPTIMIZATION_FLAGS_SECTION, msg);
+ this->failOnSection(kConstructorCodeSection, msg);
+ this->failOnSection(kConstructorParamsSection, msg);
+ this->failOnSection(kInitializersSection, msg);
+ this->failOnSection(kOptimizationFlagsSection, msg);
return;
}
this->writef(" %s(", fFullName.c_str());
@@ -231,14 +231,14 @@
String(param->fName).c_str());
separator = ", ";
}
- this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator);
+ this->writeSection(kConstructorParamsSection, separator);
this->writef(")\n"
" : INHERITED(k%s_ClassID", fFullName.c_str());
- if (!this->writeSection(OPTIMIZATION_FLAGS_SECTION, ", (OptimizationFlags) ")) {
+ if (!this->writeSection(kOptimizationFlagsSection, ", (OptimizationFlags) ")) {
this->writef(", kNone_OptimizationFlags");
}
this->writef(")");
- this->writeSection(INITIALIZERS_SECTION, "\n , ");
+ this->writeSection(kInitializersSection, "\n , ");
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
String nameString(param->fName);
const char* name = nameString.c_str();
@@ -246,7 +246,7 @@
if (type.kind() == Type::kSampler_Kind) {
this->writef("\n , %s(std::move(%s)", FieldName(name).c_str(), name);
for (const Section* s : fSectionAndParameterHelper.getSections(
- SAMPLER_PARAMS_SECTION)) {
+ kSamplerParamsSection)) {
if (s->fArgument == name) {
this->writef(", %s", s->fText.c_str());
}
@@ -259,7 +259,7 @@
}
}
this->writef(" {\n");
- this->writeSection(CONSTRUCTOR_CODE_SECTION);
+ this->writeSection(kConstructorCodeSection);
if (Analysis::ReferencesSampleCoords(fProgram)) {
this->writef(" this->setUsesSampleCoordsDirectly();\n");
@@ -300,7 +300,7 @@
}
void HCodeGenerator::writeFields() {
- this->writeSection(FIELDS_SECTION);
+ this->writeSection(kFieldsSection);
for (const auto& param : fSectionAndParameterHelper.getParameters()) {
String name = FieldName(String(param->fName).c_str());
if (param->fType.nonnullable() == *fContext.fFragmentProcessor_Type) {
@@ -340,7 +340,7 @@
this->writef("#include \"include/core/SkM44.h\"\n"
"#include \"include/core/SkTypes.h\"\n"
"\n");
- this->writeSection(HEADER_SECTION);
+ this->writeSection(kHeaderSection);
this->writef("\n"
"#include \"src/gpu/GrFragmentProcessor.h\"\n"
"\n");
@@ -352,7 +352,7 @@
this->writef("%s\n", ((Enum&) p).code().c_str());
}
}
- this->writeSection(CLASS_SECTION);
+ this->writeSection(kClassSection);
this->writeMake();
this->writef(" %s(const %s& src);\n"
" std::unique_ptr<GrFragmentProcessor> clone() const override;\n"
@@ -374,7 +374,7 @@
this->writef(" GR_DECLARE_FRAGMENT_PROCESSOR_TEST\n");
this->writef(" typedef GrFragmentProcessor INHERITED;\n"
"};\n");
- this->writeSection(HEADER_END_SECTION);
+ this->writeSection(kHeaderEndSection);
this->writef("#endif\n");
return 0 == fErrors.errorCount();
}