michael@0: // michael@0: // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #include "Token.h" michael@0: michael@0: #include michael@0: michael@0: #include "numeric_lex.h" michael@0: michael@0: namespace pp michael@0: { michael@0: michael@0: void Token::reset() michael@0: { michael@0: type = 0; michael@0: flags = 0; michael@0: location = SourceLocation(); michael@0: text.clear(); michael@0: } michael@0: michael@0: bool Token::equals(const Token& other) const michael@0: { michael@0: return (type == other.type) && michael@0: (flags == other.flags) && michael@0: (location == other.location) && michael@0: (text == other.text); michael@0: } michael@0: michael@0: void Token::setAtStartOfLine(bool start) michael@0: { michael@0: if (start) michael@0: flags |= AT_START_OF_LINE; michael@0: else michael@0: flags &= ~AT_START_OF_LINE; michael@0: } michael@0: michael@0: void Token::setHasLeadingSpace(bool space) michael@0: { michael@0: if (space) michael@0: flags |= HAS_LEADING_SPACE; michael@0: else michael@0: flags &= ~HAS_LEADING_SPACE; michael@0: } michael@0: michael@0: void Token::setExpansionDisabled(bool disable) michael@0: { michael@0: if (disable) michael@0: flags |= EXPANSION_DISABLED; michael@0: else michael@0: flags &= ~EXPANSION_DISABLED; michael@0: } michael@0: michael@0: bool Token::iValue(int* value) const michael@0: { michael@0: assert(type == CONST_INT); michael@0: return numeric_lex_int(text, value); michael@0: } michael@0: michael@0: bool Token::uValue(unsigned int* value) const michael@0: { michael@0: assert(type == CONST_INT); michael@0: return numeric_lex_int(text, value); michael@0: } michael@0: michael@0: bool Token::fValue(float* value) const michael@0: { michael@0: assert(type == CONST_FLOAT); michael@0: return numeric_lex_float(text, value); michael@0: } michael@0: michael@0: std::ostream& operator<<(std::ostream& out, const Token& token) michael@0: { michael@0: if (token.hasLeadingSpace()) michael@0: out << " "; michael@0: michael@0: out << token.text; michael@0: return out; michael@0: } michael@0: michael@0: } // namespace pp