zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Token.h
Go to the documentation of this file.
1 //
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 
7 #ifndef COMPILER_PREPROCESSOR_TOKEN_H_
8 #define COMPILER_PREPROCESSOR_TOKEN_H_
9 
10 #include <ostream>
11 #include <string>
12 
13 #include "SourceLocation.h"
14 
15 namespace pp
16 {
17 
18 struct Token
19 {
20  enum Type
21  {
22  LAST = 0, // EOF.
23 
24  IDENTIFIER = 258,
25 
28 
50 
51  // Preprocessing token types.
52  // These types are used by the preprocessor internally.
53  // Preprocessor clients must not depend or check for them.
57  };
58  enum Flags
59  {
60  AT_START_OF_LINE = 1 << 0,
63  };
64 
65  Token() : type(0), flags(0) { }
66 
67  void reset();
68  bool equals(const Token& other) const;
69 
70  // Returns true if this is the first token on line.
71  // It disregards any leading whitespace.
72  bool atStartOfLine() const { return (flags & AT_START_OF_LINE) != 0; }
73  void setAtStartOfLine(bool start);
74 
75  bool hasLeadingSpace() const { return (flags & HAS_LEADING_SPACE) != 0; }
76  void setHasLeadingSpace(bool space);
77 
78  bool expansionDisabled() const { return (flags & EXPANSION_DISABLED) != 0; }
79  void setExpansionDisabled(bool disable);
80 
81  // Converts text into numeric value for CONST_INT and CONST_FLOAT token.
82  // Returns false if the parsed value cannot fit into an int or float.
83  bool iValue(int* value) const;
84  bool uValue(unsigned int* value) const;
85  bool fValue(float* value) const;
86 
87  int type;
88  unsigned int flags;
91 };
92 
93 inline bool operator==(const Token& lhs, const Token& rhs)
94 {
95  return lhs.equals(rhs);
96 }
97 
98 inline bool operator!=(const Token& lhs, const Token& rhs)
99 {
100  return !lhs.equals(rhs);
101 }
102 
103 extern std::ostream& operator<<(std::ostream& out, const Token& token);
104 
105 } // namepsace pp
106 #endif // COMPILER_PREPROCESSOR_TOKEN_H_
bool equals(const Token &other) const
Definition: Token.cpp:24
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
GLuint start
Definition: glew.h:1239
bool operator==(const SourceLocation &lhs, const SourceLocation &rhs)
void reset()
Definition: Token.cpp:16
bool expansionDisabled() const
Definition: Token.h:78
png_sPLT_entryp pp
Definition: pngrutil.c:1375
void setAtStartOfLine(bool start)
Definition: Token.cpp:32
unsigned int flags
Definition: Token.h:88
Token()
Definition: Token.h:65
bool uValue(unsigned int *value) const
Definition: Token.cpp:62
void setExpansionDisabled(bool disable)
Definition: Token.cpp:48
SourceLocation location
Definition: Token.h:89
bool iValue(int *value) const
Definition: Token.cpp:56
bool operator!=(const SourceLocation &lhs, const SourceLocation &rhs)
bool hasLeadingSpace() const
Definition: Token.h:75
std::ostream & operator<<(std::ostream &out, const Token &token)
Definition: Token.cpp:74
EGLSurface EGLint void ** value
Definition: eglext.h:301
std::string text
Definition: Token.h:90
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
Definition: glew.h:2767
bool fValue(float *value) const
Definition: Token.cpp:68
bool atStartOfLine() const
Definition: Token.h:72
GLsizei const GLcharARB ** string
Definition: glew.h:5638
void setHasLeadingSpace(bool space)
Definition: Token.cpp:40
int type
Definition: Token.h:87