RetroArch
hlslScanContext.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2016 Google, Inc.
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 // Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // Neither the name of Google, Inc., nor the names of its
19 // contributors may be used to endorse or promote products derived
20 // from this software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 // POSSIBILITY OF SUCH DAMAGE.
34 //
35 
36 //
37 // This holds context specific to the HLSL scanner, which
38 // sits between the preprocessor scanner and HLSL parser.
39 //
40 
41 #ifndef HLSLSCANCONTEXT_H_
42 #define HLSLSCANCONTEXT_H_
43 
44 #include "../glslang/MachineIndependent/ParseHelper.h"
45 #include "hlslTokens.h"
46 
47 namespace glslang {
48 
49 class TPpContext;
50 class TPpToken;
51 
52 
53 //
54 // Everything needed to fully describe a token.
55 //
56 struct HlslToken {
57  HlslToken() : string(nullptr) { loc.init(); }
58  TSourceLoc loc; // location of token in the source
59  EHlslTokenClass tokenClass; // what kind of token it is
60  union { // what data the token holds
61  glslang::TString *string; // for identifiers
62  int i; // for literals
63  unsigned int u;
64  bool b;
65  double d;
66  };
67 };
68 
69 //
70 // The state of scanning and translating raw tokens to slightly richer
71 // semantics, like knowing if an identifier is an existing symbol, or
72 // user-defined type.
73 //
75 public:
78  virtual ~HlslScanContext() { }
79 
80  static void fillInKeywordMap();
81  static void deleteKeywordMap();
82 
83  void tokenize(HlslToken&);
85 
86 protected:
89 
96 
102 
103  const char* tokenText;
105 };
106 
107 } // end namespace glslang
108 
109 #endif // HLSLSCANCONTEXT_H_
Definition: PpContext.h:189
HlslScanContext & operator=(HlslScanContext &)
EHlslTokenClass identifierOrType()
Definition: hlslScanContext.cpp:863
static void fillInKeywordMap()
Definition: hlslScanContext.cpp:68
TPpToken * ppToken
Definition: hlslScanContext.h:100
Definition: PpContext.h:94
HlslToken * parserToken
Definition: hlslScanContext.h:101
EHlslTokenClass identifierOrReserved(bool reserved)
Definition: Common.h:231
int i
Definition: hlslScanContext.h:62
Definition: ParseHelper.h:75
EHlslTokenClass nonreservedKeyword(int version)
TSourceLoc loc
Definition: hlslScanContext.h:99
glslang::TBuiltInVariable mapSemantic(const char *)
Definition: hlslScanContext.cpp:445
TBuiltInVariable
Definition: BaseTypes.h:135
EHlslTokenClass tokenClass
Definition: hlslScanContext.h:59
GLsizei const GLchar *const * string
Definition: glext.h:6699
EHlslTokenClass reservedWord()
Definition: hlslScanContext.cpp:873
double d
Definition: hlslScanContext.h:65
TParseContextBase & _parseContext
Definition: hlslScanContext.h:97
version
Definition: setup.py:6
char reserved[128]
Definition: scefiber.c:17
EHlslTokenClass tokenizeIdentifier()
Definition: hlslScanContext.cpp:562
unsigned int u
Definition: hlslScanContext.h:63
bool b
Definition: hlslScanContext.h:64
void tokenize(HlslToken &)
Definition: hlslScanContext.cpp:439
Definition: arrays.h:46
Definition: hlslScanContext.h:56
TPpContext & ppContext
Definition: hlslScanContext.h:98
const char * tokenText
Definition: hlslScanContext.h:103
EHlslTokenClass
Definition: hlslTokens.h:42
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
Definition: Common.h:128
static void deleteKeywordMap()
Definition: hlslScanContext.cpp:428
virtual ~HlslScanContext()
Definition: hlslScanContext.h:78
EHlslTokenClass keyword
Definition: hlslScanContext.h:104
Definition: hlslScanContext.h:74
HlslScanContext(TParseContextBase &_parseContext, TPpContext &ppContext)
Definition: hlslScanContext.h:76
EHlslTokenClass tokenizeClass(HlslToken &)
Definition: hlslScanContext.cpp:459
HlslToken()
Definition: hlslScanContext.h:57
glslang::TString * string
Definition: hlslScanContext.h:61
TSourceLoc loc
Definition: hlslScanContext.h:58
void init()
Definition: Common.h:232