VR-Forces 4.3.1 Class Documentation
Home
Modules
Namespaces
Classes
Files
Examples
Behavior Models
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
include
vrvOsg
DtGLSLPreprocessor.h
Go to the documentation of this file.
1
/*****************************************************************************
2
* Copyright (c) 2012 MAK Technologies, Inc.
3
* All rights reserved.
4
*****************************************************************************/
5
8
37
#ifndef DTGLSLPREPROCESSOR_H
38
#define DTGLSLPREPROCESSOR_H
39
40
#include <string.h>
41
#include <stdlib.h>
42
43
namespace
makVrv {
44
69
class
CPreprocessor
70
{
84
class
Token
85
{
86
public
:
87
enum
Kind
88
{
89
TK_EOS
,
// End of input stream
90
TK_ERROR
,
// An error has been encountered
91
TK_WHITESPACE
,
// A whitespace span (but not newline)
92
TK_NEWLINE
,
// A single newline (CR & LF)
93
TK_LINECONT
,
// Line continuation ('\' followed by LF)
94
TK_NUMBER
,
// A number
95
TK_KEYWORD
,
// A keyword
96
TK_PUNCTUATION
,
// A punctuation character
97
TK_DIRECTIVE
,
// A preprocessor directive
98
TK_STRING
,
// A string
99
TK_COMMENT
,
// A block comment
100
TK_LINECOMMENT
,
// A line comment
101
TK_TEXT
,
// An unparsed text (cannot be returned from GetToken())
102
};
103
105
Kind
Type
;
107
mutable
size_t
Allocated
;
108
union
109
{
111
const
char
*
String
;
113
char
*
Buffer
;
114
};
116
size_t
Length
;
117
118
Token
() :
Allocated
(0),
String
(NULL)
119
{ }
120
121
Token
(
Kind
iType) :
Type
(iType),
Allocated
(0),
String
(NULL)
122
{ }
123
124
Token
(
Kind
iType,
const
char
*iString,
size_t
iLength) :
125
Type
(iType),
Allocated
(0),
String
(iString),
Length
(iLength)
126
{ }
127
128
Token
(
const
Token
&iOther)
129
{
130
Type
= iOther.
Type
;
131
Allocated
= iOther.
Allocated
;
132
iOther.
Allocated
= 0;
// !!! not quite correct but effective
133
String
= iOther.
String
;
134
Length
= iOther.
Length
;
135
}
136
137
~Token
()
138
{
if
(
Allocated
) free (
Buffer
); }
139
141
Token
&
operator =
(
const
Token
&iOther)
142
{
143
if
(
Allocated
) free (
Buffer
);
144
Type
= iOther.
Type
;
145
Allocated
= iOther.
Allocated
;
146
iOther.
Allocated
= 0;
// !!! not quite correct but effective
147
String
= iOther.
String
;
148
Length
= iOther.
Length
;
149
return
*
this
;
150
}
151
153
void
Append
(
const
char
*iString,
size_t
iLength);
154
156
void
Append
(
const
Token
&iOther);
157
159
void
AppendNL
(
int
iCount);
160
162
int
CountNL
();
163
165
bool
GetValue
(
long
&oValue)
const
;
166
168
void
SetValue
(
long
iValue);
169
171
bool
operator ==
(
const
Token
&iOther)
172
{
173
if
(iOther.
Length
!=
Length
)
174
return
false
;
175
return
(memcmp (
String
, iOther.
String
,
Length
) == 0);
176
}
177
};
178
180
class
Macro
181
{
182
public
:
184
Token
Name
;
186
int
NumArgs
;
188
Token
*
Args
;
190
Token
Value
;
192
Token
Body
;
194
Macro
*
Next
;
196
Token
(*
ExpandFunc
) (
CPreprocessor
*iParent,
int
iNumArgs,
Token
*iArgs);
198
bool
Expanding
;
199
200
Macro
(
const
Token
&iName) :
201
Name
(iName),
NumArgs
(0),
Args
(NULL),
Next
(NULL),
202
ExpandFunc
(NULL),
Expanding
(false)
203
{ }
204
205
~Macro
()
206
{
delete
[]
Args
;
delete
Next
; }
207
209
Token
Expand
(
int
iNumArgs,
Token
*iArgs,
Macro
*iMacros);
210
};
211
212
friend
class
CPreprocessor::Macro
;
213
215
const
char
*
Source
;
217
const
char
*
SourceEnd
;
219
int
Line
;
221
bool
BOL
;
223
unsigned
EnableOutput
;
225
Macro
*
MacroList
;
226
230
CPreprocessor
(
const
Token
&iToken,
int
iLine);
231
239
Token
GetToken
(
bool
iExpand);
240
250
Token
HandleDirective
(
Token
&iToken,
int
iLine);
251
262
bool
HandleDefine
(
Token
&iBody,
int
iLine);
263
274
bool
HandleUnDef
(
Token
&iBody,
int
iLine);
275
286
bool
HandleIfDef
(
Token
&iBody,
int
iLine);
287
298
bool
HandleIf
(
Token
&iBody,
int
iLine);
299
310
bool
HandleElse
(
Token
&iBody,
int
iLine);
311
322
bool
HandleEndIf
(
Token
&iBody,
int
iLine);
323
334
Token
GetArgument
(
Token
&oArg,
bool
iExpand);
335
346
Token
GetArguments
(
int
&oNumArgs,
Token
*&oArgs,
bool
iExpand);
347
361
Token
GetExpression
(
Token
&oResult,
int
iLine,
int
iOpPriority = 0);
362
378
bool
GetValue
(
const
Token
&iToken,
long
&oValue,
int
iLine);
379
388
Token
ExpandMacro
(
const
Token
&iToken);
389
397
Macro
*
IsDefined
(
const
Token
&iToken);
398
410
static
Token
ExpandDefined
(
CPreprocessor
*iParent,
int
iNumArgs,
Token
*iArgs);
411
419
Token
Parse
(
const
Token
&iSource);
420
430
void
Error
(
int
iLine,
const
char
*iError,
const
Token
*iToken = NULL);
431
432
public
:
434
CPreprocessor
() :
MacroList
(NULL)
435
{ }
436
438
virtual
~CPreprocessor
();
439
451
void
Define
(
const
char
*iMacroName,
size_t
iMacroNameLen,
452
const
char
*iMacroValue,
size_t
iMacroValueLen);
453
463
void
Define
(
const
char
*iMacroName,
size_t
iMacroNameLen,
long
iMacroValue);
464
474
bool
Undef
(
const
char
*iMacroName,
size_t
iMacroNameLen);
475
498
char
*
Parse
(
const
char
*iSource,
size_t
iLength,
size_t
&oLength);
499
515
typedef
void (*
ErrorHandlerFunc
) (
516
void
*iData,
int
iLine,
const
char
*iError,
517
const
char
*iToken,
size_t
iTokenLen);
518
524
static
ErrorHandlerFunc
ErrorHandler
;
525
527
void
*
ErrorData
;
528
};
529
530
}
531
532
#endif // DTGLSLPREPROCESSOR_H
Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (
www.mak.com
)