Coverage Report

Created: 2026-08-13 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/glslang/glslang/HLSL/hlslScanContext.h
Line
Count
Source
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 "../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
3.12M
    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
    // If the token is a string parsed from the source, then returns a C-style
68
    // string for it.  Otherwise returns a pointer to an empty string.
69
1
    const char* getCStrOrEmpty() {
70
1
      if (tokenClass == EHTokIdentifier || tokenClass == EHTokStringConstant) {
71
1
        return string->c_str();
72
1
      }
73
0
      return "";
74
1
    }
75
};
76
77
//
78
// The state of scanning and translating raw tokens to slightly richer
79
// semantics, like knowing if an identifier is an existing symbol, or
80
// user-defined type.
81
//
82
class HlslScanContext {
83
public:
84
    HlslScanContext(TParseContextBase& parseContext, TPpContext& ppContext)
85
240
        : parseContext(parseContext), ppContext(ppContext) { }
86
240
    virtual ~HlslScanContext() { }
87
88
    static void fillInKeywordMap();
89
    static void deleteKeywordMap();
90
91
    void tokenize(HlslToken&);
92
    glslang::TBuiltInVariable mapSemantic(const char*);
93
94
protected:
95
    HlslScanContext(HlslScanContext&);
96
    HlslScanContext& operator=(HlslScanContext&);
97
98
    EHlslTokenClass tokenizeClass(HlslToken&);
99
    EHlslTokenClass tokenizeIdentifier();
100
    EHlslTokenClass identifierOrType();
101
    EHlslTokenClass reservedWord();
102
    EHlslTokenClass identifierOrReserved(bool reserved);
103
    EHlslTokenClass nonreservedKeyword(int version);
104
105
    TParseContextBase& parseContext;
106
    TPpContext& ppContext;
107
    TSourceLoc loc;
108
    TPpToken* ppToken;
109
    HlslToken* parserToken;
110
111
    const char* tokenText;
112
    EHlslTokenClass keyword;
113
};
114
115
} // end namespace glslang
116
117
#endif // HLSLSCANCONTEXT_H_