1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/compiler/preprocessor/Token.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +// 1.5 +// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. 1.6 +// Use of this source code is governed by a BSD-style license that can be 1.7 +// found in the LICENSE file. 1.8 +// 1.9 + 1.10 +#include "Token.h" 1.11 + 1.12 +#include <cassert> 1.13 + 1.14 +#include "numeric_lex.h" 1.15 + 1.16 +namespace pp 1.17 +{ 1.18 + 1.19 +void Token::reset() 1.20 +{ 1.21 + type = 0; 1.22 + flags = 0; 1.23 + location = SourceLocation(); 1.24 + text.clear(); 1.25 +} 1.26 + 1.27 +bool Token::equals(const Token& other) const 1.28 +{ 1.29 + return (type == other.type) && 1.30 + (flags == other.flags) && 1.31 + (location == other.location) && 1.32 + (text == other.text); 1.33 +} 1.34 + 1.35 +void Token::setAtStartOfLine(bool start) 1.36 +{ 1.37 + if (start) 1.38 + flags |= AT_START_OF_LINE; 1.39 + else 1.40 + flags &= ~AT_START_OF_LINE; 1.41 +} 1.42 + 1.43 +void Token::setHasLeadingSpace(bool space) 1.44 +{ 1.45 + if (space) 1.46 + flags |= HAS_LEADING_SPACE; 1.47 + else 1.48 + flags &= ~HAS_LEADING_SPACE; 1.49 +} 1.50 + 1.51 +void Token::setExpansionDisabled(bool disable) 1.52 +{ 1.53 + if (disable) 1.54 + flags |= EXPANSION_DISABLED; 1.55 + else 1.56 + flags &= ~EXPANSION_DISABLED; 1.57 +} 1.58 + 1.59 +bool Token::iValue(int* value) const 1.60 +{ 1.61 + assert(type == CONST_INT); 1.62 + return numeric_lex_int(text, value); 1.63 +} 1.64 + 1.65 +bool Token::uValue(unsigned int* value) const 1.66 +{ 1.67 + assert(type == CONST_INT); 1.68 + return numeric_lex_int(text, value); 1.69 +} 1.70 + 1.71 +bool Token::fValue(float* value) const 1.72 +{ 1.73 + assert(type == CONST_FLOAT); 1.74 + return numeric_lex_float(text, value); 1.75 +} 1.76 + 1.77 +std::ostream& operator<<(std::ostream& out, const Token& token) 1.78 +{ 1.79 + if (token.hasLeadingSpace()) 1.80 + out << " "; 1.81 + 1.82 + out << token.text; 1.83 + return out; 1.84 +} 1.85 + 1.86 +} // namespace pp