gfx/angle/src/compiler/preprocessor/Token.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 //
     2 // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
     3 // Use of this source code is governed by a BSD-style license that can be
     4 // found in the LICENSE file.
     5 //
     7 #ifndef COMPILER_PREPROCESSOR_TOKEN_H_
     8 #define COMPILER_PREPROCESSOR_TOKEN_H_
    10 #include <ostream>
    11 #include <string>
    13 #include "SourceLocation.h"
    15 namespace pp
    16 {
    18 struct Token
    19 {
    20     enum Type
    21     {
    22         LAST = 0,  // EOF.
    24         IDENTIFIER = 258,
    26         CONST_INT,
    27         CONST_FLOAT,
    29         OP_INC,
    30         OP_DEC,
    31         OP_LEFT,
    32         OP_RIGHT,
    33         OP_LE,
    34         OP_GE,
    35         OP_EQ,
    36         OP_NE,
    37         OP_AND,
    38         OP_XOR,
    39         OP_OR,
    40         OP_ADD_ASSIGN,
    41         OP_SUB_ASSIGN,
    42         OP_MUL_ASSIGN,
    43         OP_DIV_ASSIGN,
    44         OP_MOD_ASSIGN,
    45         OP_LEFT_ASSIGN,
    46         OP_RIGHT_ASSIGN,
    47         OP_AND_ASSIGN,
    48         OP_XOR_ASSIGN,
    49         OP_OR_ASSIGN,
    51         // Preprocessing token types.
    52         // These types are used by the preprocessor internally.
    53         // Preprocessor clients must not depend or check for them.
    54         PP_HASH,
    55         PP_NUMBER,
    56         PP_OTHER
    57     };
    58     enum Flags
    59     {
    60         AT_START_OF_LINE   = 1 << 0,
    61         HAS_LEADING_SPACE  = 1 << 1,
    62         EXPANSION_DISABLED = 1 << 2
    63     };
    65     Token() : type(0), flags(0) { }
    67     void reset();
    68     bool equals(const Token& other) const;
    70     // Returns true if this is the first token on line.
    71     // It disregards any leading whitespace.
    72     bool atStartOfLine() const { return (flags & AT_START_OF_LINE) != 0; }
    73     void setAtStartOfLine(bool start);
    75     bool hasLeadingSpace() const { return (flags & HAS_LEADING_SPACE) != 0; }
    76     void setHasLeadingSpace(bool space);
    78     bool expansionDisabled() const { return (flags & EXPANSION_DISABLED) != 0; }
    79     void setExpansionDisabled(bool disable);
    81     // Converts text into numeric value for CONST_INT and CONST_FLOAT token.
    82     // Returns false if the parsed value cannot fit into an int or float.
    83     bool iValue(int* value) const;
    84     bool uValue(unsigned int* value) const;
    85     bool fValue(float* value) const;
    87     int type;
    88     unsigned int flags;
    89     SourceLocation location;
    90     std::string text;
    91 };
    93 inline bool operator==(const Token& lhs, const Token& rhs)
    94 {
    95     return lhs.equals(rhs);
    96 }
    98 inline bool operator!=(const Token& lhs, const Token& rhs)
    99 {
   100     return !lhs.equals(rhs);
   101 }
   103 extern std::ostream& operator<<(std::ostream& out, const Token& token);
   105 }  // namepsace pp
   106 #endif  // COMPILER_PREPROCESSOR_TOKEN_H_

mercurial