1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/preprocessor/Token.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +// 1.5 +// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +#ifndef COMPILER_PREPROCESSOR_TOKEN_H_ 1.11 +#define COMPILER_PREPROCESSOR_TOKEN_H_ 1.12 + 1.13 +#include <ostream> 1.14 +#include <string> 1.15 + 1.16 +#include "SourceLocation.h" 1.17 + 1.18 +namespace pp 1.19 +{ 1.20 + 1.21 +struct Token 1.22 +{ 1.23 + enum Type 1.24 + { 1.25 + LAST = 0, // EOF. 1.26 + 1.27 + IDENTIFIER = 258, 1.28 + 1.29 + CONST_INT, 1.30 + CONST_FLOAT, 1.31 + 1.32 + OP_INC, 1.33 + OP_DEC, 1.34 + OP_LEFT, 1.35 + OP_RIGHT, 1.36 + OP_LE, 1.37 + OP_GE, 1.38 + OP_EQ, 1.39 + OP_NE, 1.40 + OP_AND, 1.41 + OP_XOR, 1.42 + OP_OR, 1.43 + OP_ADD_ASSIGN, 1.44 + OP_SUB_ASSIGN, 1.45 + OP_MUL_ASSIGN, 1.46 + OP_DIV_ASSIGN, 1.47 + OP_MOD_ASSIGN, 1.48 + OP_LEFT_ASSIGN, 1.49 + OP_RIGHT_ASSIGN, 1.50 + OP_AND_ASSIGN, 1.51 + OP_XOR_ASSIGN, 1.52 + OP_OR_ASSIGN, 1.53 + 1.54 + // Preprocessing token types. 1.55 + // These types are used by the preprocessor internally. 1.56 + // Preprocessor clients must not depend or check for them. 1.57 + PP_HASH, 1.58 + PP_NUMBER, 1.59 + PP_OTHER 1.60 + }; 1.61 + enum Flags 1.62 + { 1.63 + AT_START_OF_LINE = 1 << 0, 1.64 + HAS_LEADING_SPACE = 1 << 1, 1.65 + EXPANSION_DISABLED = 1 << 2 1.66 + }; 1.67 + 1.68 + Token() : type(0), flags(0) { } 1.69 + 1.70 + void reset(); 1.71 + bool equals(const Token& other) const; 1.72 + 1.73 + // Returns true if this is the first token on line. 1.74 + // It disregards any leading whitespace. 1.75 + bool atStartOfLine() const { return (flags & AT_START_OF_LINE) != 0; } 1.76 + void setAtStartOfLine(bool start); 1.77 + 1.78 + bool hasLeadingSpace() const { return (flags & HAS_LEADING_SPACE) != 0; } 1.79 + void setHasLeadingSpace(bool space); 1.80 + 1.81 + bool expansionDisabled() const { return (flags & EXPANSION_DISABLED) != 0; } 1.82 + void setExpansionDisabled(bool disable); 1.83 + 1.84 + // Converts text into numeric value for CONST_INT and CONST_FLOAT token. 1.85 + // Returns false if the parsed value cannot fit into an int or float. 1.86 + bool iValue(int* value) const; 1.87 + bool uValue(unsigned int* value) const; 1.88 + bool fValue(float* value) const; 1.89 + 1.90 + int type; 1.91 + unsigned int flags; 1.92 + SourceLocation location; 1.93 + std::string text; 1.94 +}; 1.95 + 1.96 +inline bool operator==(const Token& lhs, const Token& rhs) 1.97 +{ 1.98 + return lhs.equals(rhs); 1.99 +} 1.100 + 1.101 +inline bool operator!=(const Token& lhs, const Token& rhs) 1.102 +{ 1.103 + return !lhs.equals(rhs); 1.104 +} 1.105 + 1.106 +extern std::ostream& operator<<(std::ostream& out, const Token& token); 1.107 + 1.108 +} // namepsace pp 1.109 +#endif // COMPILER_PREPROCESSOR_TOKEN_H_