aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLParser.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2018-07-19 15:30:51 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-24 13:53:15 +0000
commit804f81786148cd3a4385d10ab7a31340fa47b10d (patch)
tree8b068b82187c5ba17a7a7d6355c61f4d23afccf9 /src/sksl/SkSLParser.cpp
parent75b7526a2dd37ed7b3fb28a0eb65879354d3a8a9 (diff)
removed SkSLLayoutLexer
Bug: skia: Change-Id: Iad4c89fbde8bc1f6c3d022af9aec2ec5faa8a4ef Reviewed-on: https://skia-review.googlesource.com/142583 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLParser.cpp')
-rw-r--r--src/sksl/SkSLParser.cpp66
1 files changed, 60 insertions, 6 deletions
diff --git a/src/sksl/SkSLParser.cpp b/src/sksl/SkSLParser.cpp
index 46dce11177..bdff116a22 100644
--- a/src/sksl/SkSLParser.cpp
+++ b/src/sksl/SkSLParser.cpp
@@ -46,6 +46,10 @@
#include "ir/SkSLModifiers.h"
#include "ir/SkSLType.h"
+#ifndef SKSL_STANDALONE
+#include "SkOnce.h"
+#endif
+
namespace SkSL {
#define MAX_PARSE_DEPTH 50
@@ -73,12 +77,63 @@ private:
Parser* fParser;
};
+std::unordered_map<String, Parser::LayoutToken> Parser::layoutTokens;
+
+void Parser::InitLayoutMap() {
+ #define TOKEN(name, text) layoutTokens[text] = LayoutToken::name;
+ TOKEN(LOCATION, "location");
+ TOKEN(OFFSET, "offset");
+ TOKEN(BINDING, "binding");
+ TOKEN(INDEX, "index");
+ TOKEN(SET, "set");
+ TOKEN(BUILTIN, "builtin");
+ TOKEN(INPUT_ATTACHMENT_INDEX, "input_attachment_index");
+ TOKEN(ORIGIN_UPPER_LEFT, "origin_upper_left");
+ TOKEN(OVERRIDE_COVERAGE, "override_coverage");
+ TOKEN(BLEND_SUPPORT_ALL_EQUATIONS, "blend_support_all_equations");
+ TOKEN(BLEND_SUPPORT_MULTIPLY, "blend_support_multiply");
+ TOKEN(BLEND_SUPPORT_SCREEN, "blend_support_screen");
+ TOKEN(BLEND_SUPPORT_OVERLAY, "blend_support_overlay");
+ TOKEN(BLEND_SUPPORT_DARKEN, "blend_support_darken");
+ TOKEN(BLEND_SUPPORT_LIGHTEN, "blend_support_lighten");
+ TOKEN(BLEND_SUPPORT_COLORDODGE, "blend_support_colordodge");
+ TOKEN(BLEND_SUPPORT_COLORBURN, "blend_support_colorburn");
+ TOKEN(BLEND_SUPPORT_HARDLIGHT, "blend_support_hardlight");
+ TOKEN(BLEND_SUPPORT_SOFTLIGHT, "blend_support_softlight");
+ TOKEN(BLEND_SUPPORT_DIFFERENCE, "blend_support_difference");
+ TOKEN(BLEND_SUPPORT_EXCLUSION, "blend_support_exclusion");
+ TOKEN(BLEND_SUPPORT_HSL_HUE, "blend_support_hsl_hue");
+ TOKEN(BLEND_SUPPORT_HSL_SATURATION, "blend_support_hsl_saturation");
+ TOKEN(BLEND_SUPPORT_HSL_COLOR, "blend_support_hsl_color");
+ TOKEN(BLEND_SUPPORT_HSL_LUMINOSITY, "blend_support_hsl_luminosity");
+ TOKEN(PUSH_CONSTANT, "push_constant");
+ TOKEN(POINTS, "points");
+ TOKEN(LINES, "lines");
+ TOKEN(LINE_STRIP, "line_strip");
+ TOKEN(LINES_ADJACENCY, "lines_adjacency");
+ TOKEN(TRIANGLES, "triangles");
+ TOKEN(TRIANGLE_STRIP, "triangle_strip");
+ TOKEN(TRIANGLES_ADJACENCY, "triangles_adjacency");
+ TOKEN(MAX_VERTICES, "max_vertices");
+ TOKEN(INVOCATIONS, "invocations");
+ TOKEN(WHEN, "when");
+ TOKEN(KEY, "key");
+ TOKEN(CTYPE, "ctype");
+ #undef TOKEN
+}
+
Parser::Parser(const char* text, size_t length, SymbolTable& types, ErrorReporter& errors)
: fText(text)
, fPushback(Token::INVALID, -1, -1)
, fTypes(types)
, fErrors(errors) {
fLexer.start(text, length);
+#ifdef SKSL_STANDALONE
+ InitLayoutMap();
+#else
+ static SkOnce once;
+ once([] { InitLayoutMap(); });
+#endif
}
/* (directive | section | declaration)* END_OF_FILE */
@@ -690,10 +745,9 @@ Layout Parser::layout() {
for (;;) {
Token t = this->nextToken();
String text = this->text(t);
- fLayoutLexer.start(text.c_str(), text.size());
- int token = fLayoutLexer.next().fKind;
- if (token != LayoutToken::INVALID) {
- switch (token) {
+ auto found = layoutTokens.find(text);
+ if (found != layoutTokens.end()) {
+ switch (found->second) {
case LayoutToken::LOCATION:
location = this->layoutInt();
break;
@@ -809,10 +863,10 @@ Layout Parser::layout() {
ctype = this->layoutIdentifier();
break;
}
- } else if (Layout::ReadFormat(this->text(t), &format)) {
+ } else if (Layout::ReadFormat(text, &format)) {
// AST::ReadFormat stored the result in 'format'.
} else {
- this->error(t, ("'" + this->text(t) + "' is not a valid layout qualifier").c_str());
+ this->error(t, ("'" + text + "' is not a valid layout qualifier").c_str());
}
if (this->checkNext(Token::RPAREN)) {
break;