| /* |
| * Copyright 2016 Google Inc. |
| * |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| |
| #ifndef SKSL_TOKEN |
| #define SKSL_TOKEN |
| |
| #include "SkSLPosition.h" |
| #include "SkSLUtil.h" |
| |
| namespace SkSL { |
| |
| #undef IN |
| #undef OUT |
| #undef CONST |
| |
| /** |
| * Represents a lexical analysis token. Token is generally only used during the parse process, but |
| * Token::Kind is also used to represent operator kinds. |
| */ |
| struct Token { |
| enum Kind { |
| END_OF_FILE, |
| IDENTIFIER, |
| INT_LITERAL, |
| FLOAT_LITERAL, |
| TRUE_LITERAL, |
| FALSE_LITERAL, |
| LPAREN, |
| RPAREN, |
| LBRACE, |
| RBRACE, |
| LBRACKET, |
| RBRACKET, |
| DOT, |
| COMMA, |
| PLUSPLUS, |
| MINUSMINUS, |
| PLUS, |
| MINUS, |
| STAR, |
| SLASH, |
| PERCENT, |
| SHL, |
| SHR, |
| BITWISEOR, |
| BITWISEXOR, |
| BITWISEAND, |
| BITWISENOT, |
| LOGICALOR, |
| LOGICALXOR, |
| LOGICALAND, |
| LOGICALNOT, |
| QUESTION, |
| COLON, |
| EQ, |
| EQEQ, |
| NEQ, |
| GT, |
| LT, |
| GTEQ, |
| LTEQ, |
| PLUSEQ, |
| MINUSEQ, |
| STAREQ, |
| SLASHEQ, |
| PERCENTEQ, |
| SHLEQ, |
| SHREQ, |
| BITWISEOREQ, |
| BITWISEXOREQ, |
| BITWISEANDEQ, |
| LOGICALOREQ, |
| LOGICALXOREQ, |
| LOGICALANDEQ, |
| SEMICOLON, |
| IF, |
| ELSE, |
| FOR, |
| WHILE, |
| DO, |
| RETURN, |
| BREAK, |
| CONTINUE, |
| DISCARD, |
| IN, |
| OUT, |
| INOUT, |
| CONST, |
| LOWP, |
| MEDIUMP, |
| HIGHP, |
| UNIFORM, |
| FLAT, |
| NOPERSPECTIVE, |
| READONLY, |
| WRITEONLY, |
| COHERENT, |
| VOLATILE, |
| RESTRICT, |
| STRUCT, |
| LAYOUT, |
| DIRECTIVE, |
| PRECISION, |
| INVALID_TOKEN |
| }; |
| |
| static SkString OperatorName(Kind kind) { |
| switch (kind) { |
| case Token::PLUS: return SkString("+"); |
| case Token::MINUS: return SkString("-"); |
| case Token::STAR: return SkString("*"); |
| case Token::SLASH: return SkString("/"); |
| case Token::PERCENT: return SkString("%"); |
| case Token::SHL: return SkString("<<"); |
| case Token::SHR: return SkString(">>"); |
| case Token::LOGICALNOT: return SkString("!"); |
| case Token::LOGICALAND: return SkString("&&"); |
| case Token::LOGICALOR: return SkString("||"); |
| case Token::LOGICALXOR: return SkString("^^"); |
| case Token::BITWISENOT: return SkString("~"); |
| case Token::BITWISEAND: return SkString("&"); |
| case Token::BITWISEOR: return SkString("|"); |
| case Token::BITWISEXOR: return SkString("^"); |
| case Token::EQ: return SkString("="); |
| case Token::EQEQ: return SkString("=="); |
| case Token::NEQ: return SkString("!="); |
| case Token::LT: return SkString("<"); |
| case Token::GT: return SkString(">"); |
| case Token::LTEQ: return SkString("<="); |
| case Token::GTEQ: return SkString(">="); |
| case Token::PLUSEQ: return SkString("+="); |
| case Token::MINUSEQ: return SkString("-="); |
| case Token::STAREQ: return SkString("*="); |
| case Token::SLASHEQ: return SkString("/="); |
| case Token::PERCENTEQ: return SkString("%="); |
| case Token::SHLEQ: return SkString("<<="); |
| case Token::SHREQ: return SkString(">>="); |
| case Token::LOGICALANDEQ: return SkString("&&="); |
| case Token::LOGICALOREQ: return SkString("||="); |
| case Token::LOGICALXOREQ: return SkString("^^="); |
| case Token::BITWISEANDEQ: return SkString("&="); |
| case Token::BITWISEOREQ: return SkString("|="); |
| case Token::BITWISEXOREQ: return SkString("^="); |
| case Token::PLUSPLUS: return SkString("++"); |
| case Token::MINUSMINUS: return SkString("--"); |
| default: |
| ABORT("unsupported operator: %d\n", kind); |
| } |
| } |
| |
| Token() { |
| } |
| |
| Token(Position position, Kind kind, SkString text) |
| : fPosition(position) |
| , fKind(kind) |
| , fText(std::move(text)) {} |
| |
| Position fPosition; |
| Kind fKind; |
| // will be the empty string unless the token has variable text content (identifiers, numeric |
| // literals, and directives) |
| SkString fText; |
| }; |
| |
| } // namespace |
| #endif |