Path: blob/main_old/src/compiler/preprocessor/Token.h
1693 views
//1// Copyright 2011 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56#ifndef COMPILER_PREPROCESSOR_TOKEN_H_7#define COMPILER_PREPROCESSOR_TOKEN_H_89#include <ostream>10#include <string>1112#include "compiler/preprocessor/SourceLocation.h"1314namespace angle15{1617namespace pp18{1920struct Token21{22enum Type23{24// Calling this ERROR causes a conflict with wingdi.h25GOT_ERROR = -1,26LAST = 0, // EOF.2728IDENTIFIER = 258,2930CONST_INT,31CONST_FLOAT,3233OP_INC,34OP_DEC,35OP_LEFT,36OP_RIGHT,37OP_LE,38OP_GE,39OP_EQ,40OP_NE,41OP_AND,42OP_XOR,43OP_OR,44OP_ADD_ASSIGN,45OP_SUB_ASSIGN,46OP_MUL_ASSIGN,47OP_DIV_ASSIGN,48OP_MOD_ASSIGN,49OP_LEFT_ASSIGN,50OP_RIGHT_ASSIGN,51OP_AND_ASSIGN,52OP_XOR_ASSIGN,53OP_OR_ASSIGN,5455// Preprocessing token types.56// These types are used by the preprocessor internally.57// Preprocessor clients must not depend or check for them.58PP_HASH,59PP_NUMBER,60PP_OTHER61};62enum Flags63{64AT_START_OF_LINE = 1 << 0,65HAS_LEADING_SPACE = 1 << 1,66EXPANSION_DISABLED = 1 << 267};6869Token() : type(0), flags(0) {}7071void reset();72bool equals(const Token &other) const;7374// Returns true if this is the first token on line.75// It disregards any leading whitespace.76bool atStartOfLine() const { return (flags & AT_START_OF_LINE) != 0; }77void setAtStartOfLine(bool start);7879bool hasLeadingSpace() const { return (flags & HAS_LEADING_SPACE) != 0; }80void setHasLeadingSpace(bool space);8182bool expansionDisabled() const { return (flags & EXPANSION_DISABLED) != 0; }83void setExpansionDisabled(bool disable);8485// Converts text into numeric value for CONST_INT and CONST_FLOAT token.86// Returns false if the parsed value cannot fit into an int or float.87bool iValue(int *value) const;88bool uValue(unsigned int *value) const;8990int type;91unsigned int flags;92SourceLocation location;93std::string text;94};9596inline bool operator==(const Token &lhs, const Token &rhs)97{98return lhs.equals(rhs);99}100101inline bool operator!=(const Token &lhs, const Token &rhs)102{103return !lhs.equals(rhs);104}105106std::ostream &operator<<(std::ostream &out, const Token &token);107108constexpr char kDefined[] = "defined";109110} // namespace pp111112} // namespace angle113114#endif // COMPILER_PREPROCESSOR_TOKEN_H_115116117