• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
HlslTokenHlslToken57     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 //
74 class HlslScanContext {
75 public:
HlslScanContext(TParseContextBase & parseContext,TPpContext & ppContext)76     HlslScanContext(TParseContextBase& parseContext, TPpContext& ppContext)
77         : parseContext(parseContext), ppContext(ppContext) { }
~HlslScanContext()78     virtual ~HlslScanContext() { }
79 
80     static void fillInKeywordMap();
81     static void deleteKeywordMap();
82 
83     void tokenize(HlslToken&);
84     glslang::TBuiltInVariable mapSemantic(const char*);
85 
86 protected:
87     HlslScanContext(HlslScanContext&);
88     HlslScanContext& operator=(HlslScanContext&);
89 
90     EHlslTokenClass tokenizeClass(HlslToken&);
91     EHlslTokenClass tokenizeIdentifier();
92     EHlslTokenClass identifierOrType();
93     EHlslTokenClass reservedWord();
94     EHlslTokenClass identifierOrReserved(bool reserved);
95     EHlslTokenClass nonreservedKeyword(int version);
96 
97     TParseContextBase& parseContext;
98     TPpContext& ppContext;
99     TSourceLoc loc;
100     TPpToken* ppToken;
101     HlslToken* parserToken;
102 
103     const char* tokenText;
104     EHlslTokenClass keyword;
105 };
106 
107 } // end namespace glslang
108 
109 #endif // HLSLSCANCONTEXT_H_
110