Skip to content

Commit 2df5d6d

Browse files
author
Finn Plummer
committed
NFC self-review: update comments
1 parent 47139b6 commit 2df5d6d

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,31 @@ class RootSignatureParser {
4040
private:
4141
DiagnosticsEngine &getDiags() { return PP.getDiagnostics(); }
4242

43-
// All private Parse.* methods follow a similar pattern:
43+
// All private parse.* methods follow a similar pattern:
4444
// - Each method will start with an assert to denote what the CurToken is
4545
// expected to be and will parse from that token forward
4646
//
4747
// - Therefore, it is the callers responsibility to ensure that you are
4848
// at the correct CurToken. This should be done with the pattern of:
4949
//
50-
// if (TryConsumeExpectedToken(RootSignatureToken::Kind))
51-
// if (Parse.*())
52-
// return true;
50+
// if (tryConsumeExpectedToken(RootSignatureToken::Kind)) {
51+
// auto ParsedObject = parse.*();
52+
// if (!ParsedObject.has_value())
53+
// return std::nullopt;
54+
// ...
55+
// }
5356
//
5457
// or,
5558
//
56-
// if (ConsumeExpectedToken(RootSignatureToken::Kind, ...))
57-
// return true;
58-
// if (Parse.*())
59-
// return true;
59+
// if (consumeExpectedToken(RootSignatureToken::Kind, ...))
60+
// return std::nullopt;
61+
// auto ParsedObject = parse.*();
62+
// if (!ParsedObject.has_value())
63+
// return std::nullopt;
64+
// ...
6065
//
61-
// - All methods return true if a parsing error is encountered. It is the
62-
// callers responsibility to propogate this error up, or deal with it
66+
// - All methods return std::nullopt if a parsing error is encountered. It
67+
// is the callers responsibility to propogate this error up, or deal with it
6368
// otherwise
6469
//
6570
// - An error will be raised if the proceeding tokens are not what is
@@ -70,16 +75,17 @@ class RootSignatureParser {
7075
std::optional<llvm::hlsl::rootsig::DescriptorTableClause>
7176
parseDescriptorTableClause();
7277

73-
struct ParsedParams {
78+
/// Parameter parse methods
79+
/// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
80+
/// order and only exactly once. `ParsedClauseParams` denotes the current
81+
/// state of parsed params
82+
struct ParsedClauseParams {
7483
std::optional<llvm::hlsl::rootsig::Register> Register;
7584
std::optional<uint32_t> Space;
7685
};
77-
/// Parses out a `ParsedParams` for the caller to use for construction
78-
/// of the in-memory representation of a Root Element.
79-
std::optional<ParsedParams>
86+
std::optional<ParsedClauseParams>
8087
parseDescriptorTableClauseParams(RootSignatureToken::Kind RegType);
8188

82-
/// Parameter parse methods corresponding to a ParamType
8389
std::optional<uint32_t> parseUIntParam();
8490
std::optional<llvm::hlsl::rootsig::Register> parseRegister();
8591

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,17 @@ RootSignatureParser::parseDescriptorTableClause() {
135135
return Clause;
136136
}
137137

138-
std::optional<RootSignatureParser::ParsedParams>
138+
std::optional<RootSignatureParser::ParsedClauseParams>
139139
RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
140140
assert(CurToken.TokKind == TokenKind::pu_l_paren &&
141141
"Expects to only be invoked starting at given token");
142142

143-
ParsedParams Params;
143+
// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
144+
// order and only exactly once. Parse through as many arguments as possible
145+
// reporting an error if a duplicate is seen.
146+
ParsedClauseParams Params;
144147
do {
148+
// ( `b` | `t` | `u` | `s`) POS_INT
145149
if (tryConsumeExpectedToken(RegType)) {
146150
if (Params.Register.has_value()) {
147151
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
@@ -154,14 +158,17 @@ RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
154158
Params.Register = Reg;
155159
}
156160

161+
// `space` `=` POS_INT
157162
if (tryConsumeExpectedToken(TokenKind::kw_space)) {
158163
if (Params.Space.has_value()) {
159164
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
160165
<< CurToken.TokKind;
161166
return std::nullopt;
162167
}
168+
163169
if (consumeExpectedToken(TokenKind::pu_equal))
164170
return std::nullopt;
171+
165172
auto Space = parseUIntParam();
166173
if (!Space.has_value())
167174
return std::nullopt;

0 commit comments

Comments
 (0)