diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-09-07 15:44:01 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-11 16:17:00 +0000 |
commit | c576e93d174f3106e072a2f506bca3990b541265 (patch) | |
tree | d4a410200aa71183c95643535b440bec919f2e18 /src/sksl/SkSLHCodeGenerator.cpp | |
parent | a2bdf005f3c706065d1aa93f319f4b73932721d4 (diff) |
Switch to the new SkSL lexer.
This completely replaces flex with a new in-house lexical analyzer generator,
which we have done for performance and memory usage reasons. Flex requires us
to copy strings every time we need the text of a token, whereas this new lexer
allows us to handle strings as a (non-null-terminated) pointer and length
everywhere, eliminating most string copies.
Bug: skia:
Change-Id: I2add26efc9e20cb699520e82abcf713af3968aca
Reviewed-on: https://skia-review.googlesource.com/39780
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLHCodeGenerator.cpp')
-rw-r--r-- | src/sksl/SkSLHCodeGenerator.cpp | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp index 50d242896a..482020af7f 100644 --- a/src/sksl/SkSLHCodeGenerator.cpp +++ b/src/sksl/SkSLHCodeGenerator.cpp @@ -23,17 +23,17 @@ HCodeGenerator::HCodeGenerator(const Program* program, ErrorReporter* errors, St , fSectionAndParameterHelper(*program, *errors) {} String HCodeGenerator::ParameterType(const Type& type) { - if (type.fName == "float2") { + if (type.name() == "float2") { return "SkPoint"; - } else if (type.fName == "int4") { + } else if (type.name() == "int4") { return "SkIRect"; - } else if (type.fName == "float4") { + } else if (type.name() == "float4") { return "SkRect"; - } else if (type.fName == "float4x4") { + } else if (type.name() == "float4x4") { return "SkMatrix44"; } else if (type.kind() == Type::kSampler_Kind) { return "sk_sp<GrTextureProxy>"; - } else if (type.fName == "colorSpaceXform") { + } else if (type.name() == "colorSpaceXform") { return "sk_sp<GrColorSpaceXform>"; } return type.name(); @@ -127,7 +127,7 @@ void HCodeGenerator::writeMake() { separator = ""; for (const auto& param : fSectionAndParameterHelper.getParameters()) { this->writef("%s%s %s", separator, ParameterType(param->fType).c_str(), - param->fName.c_str()); + String(param->fName).c_str()); separator = ", "; } this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator); @@ -136,7 +136,7 @@ void HCodeGenerator::writeMake() { fFullName.c_str()); separator = ""; for (const auto& param : fSectionAndParameterHelper.getParameters()) { - this->writef("%s%s", separator, param->fName.c_str()); + this->writef("%s%s", separator, String(param->fName).c_str()); separator = ", "; } this->writeExtraConstructorParams(separator); @@ -148,7 +148,7 @@ void HCodeGenerator::writeMake() { void HCodeGenerator::failOnSection(const char* section, const char* msg) { std::vector<const Section*> s = fSectionAndParameterHelper.getSections(section); if (s.size()) { - fErrors.error(s[0]->fPosition, String("@") + section + " " + msg); + fErrors.error(s[0]->fOffset, String("@") + section + " " + msg); } } @@ -165,7 +165,7 @@ void HCodeGenerator::writeConstructor() { const char* separator = ""; for (const auto& param : fSectionAndParameterHelper.getParameters()) { this->writef("%s%s %s", separator, ParameterType(param->fType).c_str(), - param->fName.c_str()); + String(param->fName).c_str()); separator = ", "; } this->writeSection(CONSTRUCTOR_PARAMS_SECTION, separator); @@ -177,7 +177,8 @@ void HCodeGenerator::writeConstructor() { this->writef(")"); this->writeSection(INITIALIZERS_SECTION, "\n , "); for (const auto& param : fSectionAndParameterHelper.getParameters()) { - const char* name = param->fName.c_str(); + String nameString(param->fName); + const char* name = nameString.c_str(); if (param->fType.kind() == Type::kSampler_Kind) { this->writef("\n , %s(std::move(%s)", FieldName(name).c_str(), name); for (const Section* s : fSectionAndParameterHelper.getSections( @@ -201,7 +202,7 @@ void HCodeGenerator::writeConstructor() { for (const auto& param : fSectionAndParameterHelper.getParameters()) { if (param->fType.kind() == Type::kSampler_Kind) { this->writef(" this->addTextureSampler(&%s);\n", - FieldName(param->fName.c_str()).c_str()); + FieldName(String(param->fName).c_str()).c_str()); } } for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) { @@ -216,8 +217,8 @@ void HCodeGenerator::writeConstructor() { void HCodeGenerator::writeFields() { this->writeSection(FIELDS_SECTION); for (const auto& param : fSectionAndParameterHelper.getParameters()) { - const char* name = param->fName.c_str(); - this->writef(" %s %s;\n", FieldType(param->fType).c_str(), FieldName(name).c_str()); + this->writef(" %s %s;\n", FieldType(param->fType).c_str(), + FieldName(String(param->fName).c_str()).c_str()); } for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) { this->writef(" GrCoordTransform %sCoordTransform;\n", @@ -245,7 +246,8 @@ bool HCodeGenerator::generateCode() { if (param->fType.kind() == Type::kSampler_Kind) { continue; } - const char* name = param->fName.c_str(); + String nameString(param->fName); + const char* name = nameString.c_str(); this->writef(" %s %s() const { return %s; }\n", FieldType(param->fType).c_str(), name, FieldName(name).c_str()); } |