michael@0: // michael@0: // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #ifndef COMPILER_PREPROCESSOR_TOKEN_H_ michael@0: #define COMPILER_PREPROCESSOR_TOKEN_H_ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "SourceLocation.h" michael@0: michael@0: namespace pp michael@0: { michael@0: michael@0: struct Token michael@0: { michael@0: enum Type michael@0: { michael@0: LAST = 0, // EOF. michael@0: michael@0: IDENTIFIER = 258, michael@0: michael@0: CONST_INT, michael@0: CONST_FLOAT, michael@0: michael@0: OP_INC, michael@0: OP_DEC, michael@0: OP_LEFT, michael@0: OP_RIGHT, michael@0: OP_LE, michael@0: OP_GE, michael@0: OP_EQ, michael@0: OP_NE, michael@0: OP_AND, michael@0: OP_XOR, michael@0: OP_OR, michael@0: OP_ADD_ASSIGN, michael@0: OP_SUB_ASSIGN, michael@0: OP_MUL_ASSIGN, michael@0: OP_DIV_ASSIGN, michael@0: OP_MOD_ASSIGN, michael@0: OP_LEFT_ASSIGN, michael@0: OP_RIGHT_ASSIGN, michael@0: OP_AND_ASSIGN, michael@0: OP_XOR_ASSIGN, michael@0: OP_OR_ASSIGN, michael@0: michael@0: // Preprocessing token types. michael@0: // These types are used by the preprocessor internally. michael@0: // Preprocessor clients must not depend or check for them. michael@0: PP_HASH, michael@0: PP_NUMBER, michael@0: PP_OTHER michael@0: }; michael@0: enum Flags michael@0: { michael@0: AT_START_OF_LINE = 1 << 0, michael@0: HAS_LEADING_SPACE = 1 << 1, michael@0: EXPANSION_DISABLED = 1 << 2 michael@0: }; michael@0: michael@0: Token() : type(0), flags(0) { } michael@0: michael@0: void reset(); michael@0: bool equals(const Token& other) const; michael@0: michael@0: // Returns true if this is the first token on line. michael@0: // It disregards any leading whitespace. michael@0: bool atStartOfLine() const { return (flags & AT_START_OF_LINE) != 0; } michael@0: void setAtStartOfLine(bool start); michael@0: michael@0: bool hasLeadingSpace() const { return (flags & HAS_LEADING_SPACE) != 0; } michael@0: void setHasLeadingSpace(bool space); michael@0: michael@0: bool expansionDisabled() const { return (flags & EXPANSION_DISABLED) != 0; } michael@0: void setExpansionDisabled(bool disable); michael@0: michael@0: // Converts text into numeric value for CONST_INT and CONST_FLOAT token. michael@0: // Returns false if the parsed value cannot fit into an int or float. michael@0: bool iValue(int* value) const; michael@0: bool uValue(unsigned int* value) const; michael@0: bool fValue(float* value) const; michael@0: michael@0: int type; michael@0: unsigned int flags; michael@0: SourceLocation location; michael@0: std::string text; michael@0: }; michael@0: michael@0: inline bool operator==(const Token& lhs, const Token& rhs) michael@0: { michael@0: return lhs.equals(rhs); michael@0: } michael@0: michael@0: inline bool operator!=(const Token& lhs, const Token& rhs) michael@0: { michael@0: return !lhs.equals(rhs); michael@0: } michael@0: michael@0: extern std::ostream& operator<<(std::ostream& out, const Token& token); michael@0: michael@0: } // namepsace pp michael@0: #endif // COMPILER_PREPROCESSOR_TOKEN_H_