clang 22.0.0git
LexHLSLRootSignature.h
Go to the documentation of this file.
1//===--- LexHLSLRootSignature.h ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the LexHLSLRootSignature interface.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H
14#define LLVM_CLANG_LEX_LEXHLSLROOTSIGNATURE_H
15
18
19#include "llvm/ADT/SmallVector.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/ADT/StringSwitch.h"
22
23namespace clang {
24namespace hlsl {
25
27 enum Kind {
28#define TOK(X, SPELLING) X,
29#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
30 };
31
32 Kind TokKind = Kind::invalid;
33
34 // Retain the location offset of the token in the Signature
35 // string
36 uint32_t LocOffset;
37
38 // Retain spelling of an numeric constant to be parsed later
39 StringRef NumSpelling;
40
41 // Constructors
45};
46
47inline const DiagnosticBuilder &
49 switch (Kind) {
50#define TOK(X, SPELLING) \
51 case RootSignatureToken::Kind::X: \
52 DB << SPELLING; \
53 break;
54#define PUNCTUATOR(X, SPELLING) \
55 case RootSignatureToken::Kind::pu_##X: \
56 DB << #SPELLING; \
57 break;
58#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
59 }
60 return DB;
61}
62
64public:
65 RootSignatureLexer(StringRef Signature) : Buffer(Signature) {}
66
67 /// Consumes and returns the next token.
69
70 /// Returns the token that proceeds CurToken
72
74 advanceBuffer(Buffer.take_while(isspace).size());
75 return Buffer.empty();
76 }
77
78private:
79 // Internal buffer state
80 StringRef Buffer;
81 uint32_t LocOffset = 0;
82
83 // Current peek state
84 std::optional<RootSignatureToken> NextToken = std::nullopt;
85
86 /// Consumes the buffer and returns the lexed token.
87 RootSignatureToken lexToken();
88
89 /// Advance the buffer by the specified number of characters.
90 /// Updates the SourceLocation appropriately.
91 void advanceBuffer(unsigned NumCharacters = 1) {
92 Buffer = Buffer.drop_front(NumCharacters);
93 LocOffset += NumCharacters;
94 }
95};
96
97} // namespace hlsl
98} // namespace clang
99
100#endif // LLVM_CLANG_LEX_PARSEHLSLROOTSIGNATURE_H
Defines the Diagnostic-related interfaces.
enum clang::sema::@1840::IndirectLocalPathEntry::EntryKind Kind
Defines the clang::SourceLocation class and associated facilities.
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1233
RootSignatureToken peekNextToken()
Returns the token that proceeds CurToken.
RootSignatureLexer(StringRef Signature)
RootSignatureToken consumeToken()
Consumes and returns the next token.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const RootSignatureToken::Kind Kind)
The JSON file list parser is used to communicate input to InstallAPI.
RootSignatureToken(Kind TokKind, uint32_t LocOffset)