1 // 2 // Copyright 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 // 6 7 #include "compiler/preprocessor/Token.h" 8 9 #include "common/debug.h" 10 #include "compiler/preprocessor/numeric_lex.h" 11 12 namespace angle 13 { 14 15 namespace pp 16 { 17 reset()18void Token::reset() 19 { 20 type = 0; 21 flags = 0; 22 location = SourceLocation(); 23 text.clear(); 24 } 25 equals(const Token & other) const26bool Token::equals(const Token &other) const 27 { 28 return (type == other.type) && (flags == other.flags) && (location == other.location) && 29 (text == other.text); 30 } 31 setAtStartOfLine(bool start)32void Token::setAtStartOfLine(bool start) 33 { 34 if (start) 35 flags |= AT_START_OF_LINE; 36 else 37 flags &= ~AT_START_OF_LINE; 38 } 39 setHasLeadingSpace(bool space)40void Token::setHasLeadingSpace(bool space) 41 { 42 if (space) 43 flags |= HAS_LEADING_SPACE; 44 else 45 flags &= ~HAS_LEADING_SPACE; 46 } 47 setExpansionDisabled(bool disable)48void Token::setExpansionDisabled(bool disable) 49 { 50 if (disable) 51 flags |= EXPANSION_DISABLED; 52 else 53 flags &= ~EXPANSION_DISABLED; 54 } 55 iValue(int * value) const56bool Token::iValue(int *value) const 57 { 58 ASSERT(type == CONST_INT); 59 return numeric_lex_int(text, value); 60 } 61 uValue(unsigned int * value) const62bool Token::uValue(unsigned int *value) const 63 { 64 ASSERT(type == CONST_INT); 65 return numeric_lex_int(text, value); 66 } 67 operator <<(std::ostream & out,const Token & token)68std::ostream &operator<<(std::ostream &out, const Token &token) 69 { 70 if (token.hasLeadingSpace()) 71 out << " "; 72 73 out << token.text; 74 return out; 75 } 76 77 } // namespace pp 78 79 } // namespace angle 80