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