blob: 45b917bf03cce6b4679db64a50fe93951b8ea4a9 [file] [log] [blame]
alokp@chromium.org4e4b8072011-08-07 05:36:04 +00001//
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//
6
Corentin Wallez054f7ed2016-09-20 17:15:59 -04007#include "compiler/preprocessor/Token.h"
alokp@chromium.org4e4b8072011-08-07 05:36:04 +00008
Corentin Wallez054f7ed2016-09-20 17:15:59 -04009#include "common/debug.h"
10#include "compiler/preprocessor/numeric_lex.h"
alokp@chromium.org2e818912012-06-29 21:26:03 +000011
Geoff Lang197d5292018-04-25 14:29:00 -040012namespace angle
13{
14
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000015namespace pp
16{
17
alokp@chromium.org19d7aa62012-05-31 17:34:05 +000018void Token::reset()
19{
Jamie Madillf832c9d2016-12-12 17:38:48 -050020 type = 0;
21 flags = 0;
alokp@chromium.org19d7aa62012-05-31 17:34:05 +000022 location = SourceLocation();
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +000023 text.clear();
alokp@chromium.org19d7aa62012-05-31 17:34:05 +000024}
25
Zhenyao Mod526f982014-05-13 14:51:19 -070026bool Token::equals(const Token &other) const
alokp@chromium.org19d7aa62012-05-31 17:34:05 +000027{
Jamie Madillf832c9d2016-12-12 17:38:48 -050028 return (type == other.type) && (flags == other.flags) && (location == other.location) &&
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +000029 (text == other.text);
alokp@chromium.org19d7aa62012-05-31 17:34:05 +000030}
31
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
40void Token::setHasLeadingSpace(bool space)
41{
42 if (space)
43 flags |= HAS_LEADING_SPACE;
44 else
45 flags &= ~HAS_LEADING_SPACE;
46}
47
alokp@chromium.org7fc38dd2012-06-14 18:23:23 +000048void Token::setExpansionDisabled(bool disable)
49{
50 if (disable)
51 flags |= EXPANSION_DISABLED;
52 else
53 flags &= ~EXPANSION_DISABLED;
54}
55
Zhenyao Mod526f982014-05-13 14:51:19 -070056bool Token::iValue(int *value) const
alokp@chromium.org2e818912012-06-29 21:26:03 +000057{
Corentin Wallez054f7ed2016-09-20 17:15:59 -040058 ASSERT(type == CONST_INT);
alokp@chromium.orgfc0543f2012-07-11 20:31:02 +000059 return numeric_lex_int(text, value);
alokp@chromium.org2e818912012-06-29 21:26:03 +000060}
61
Zhenyao Mod526f982014-05-13 14:51:19 -070062bool Token::uValue(unsigned int *value) const
alokp@chromium.org2e818912012-06-29 21:26:03 +000063{
Corentin Wallez054f7ed2016-09-20 17:15:59 -040064 ASSERT(type == CONST_INT);
alokp@chromium.orgfc0543f2012-07-11 20:31:02 +000065 return numeric_lex_int(text, value);
alokp@chromium.org2e818912012-06-29 21:26:03 +000066}
67
Zhenyao Mod526f982014-05-13 14:51:19 -070068std::ostream &operator<<(std::ostream &out, const Token &token)
alokp@chromium.orgb81c4012011-08-21 06:53:11 +000069{
alokp@chromium.org40da4c52012-04-12 05:23:19 +000070 if (token.hasLeadingSpace())
71 out << " ";
72
alokp@chromium.org5b6a68e2012-06-28 20:29:13 +000073 out << token.text;
alokp@chromium.orgb81c4012011-08-21 06:53:11 +000074 return out;
75}
alokp@chromium.org4e4b8072011-08-07 05:36:04 +000076
alokp@chromium.org4b2a5222012-04-03 17:19:42 +000077} // namespace pp
Geoff Lang197d5292018-04-25 14:29:00 -040078
79} // namespace angle