Skip to content

Commit 3d8b4fd

Browse files
committed
Parse C _Noreturn specifiers
1 parent 259b154 commit 3d8b4fd

27 files changed

+581
-402
lines changed

packages/cxx-frontend/src/AST.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8737,6 +8737,31 @@ export class InlineSpecifierAST extends SpecifierAST {
87378737
}
87388738
}
87398739

8740+
/**
8741+
* NoreturnSpecifierAST node.
8742+
*/
8743+
export class NoreturnSpecifierAST extends SpecifierAST {
8744+
/**
8745+
* Traverse this node using the given visitor.
8746+
* @param visitor the visitor.
8747+
* @param context the context.
8748+
* @returns the result of the visit.
8749+
*/
8750+
accept<Context, Result>(
8751+
visitor: ASTVisitor<Context, Result>,
8752+
context: Context,
8753+
): Result {
8754+
return visitor.visitNoreturnSpecifier(this, context);
8755+
}
8756+
8757+
/**
8758+
* Returns the location of the noreturn token in this node
8759+
*/
8760+
getNoreturnToken(): Token | undefined {
8761+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
8762+
}
8763+
}
8764+
87408765
/**
87418766
* StaticSpecifierAST node.
87428767
*/
@@ -13015,6 +13040,7 @@ const AST_CONSTRUCTORS: Array<
1301513040
ConstinitSpecifierAST,
1301613041
ConstexprSpecifierAST,
1301713042
InlineSpecifierAST,
13043+
NoreturnSpecifierAST,
1301813044
StaticSpecifierAST,
1301913045
ExternSpecifierAST,
1302013046
ThreadLocalSpecifierAST,

packages/cxx-frontend/src/ASTKind.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export enum ASTKind {
181181
ConstinitSpecifier,
182182
ConstexprSpecifier,
183183
InlineSpecifier,
184+
NoreturnSpecifier,
184185
StaticSpecifier,
185186
ExternSpecifier,
186187
ThreadLocalSpecifier,

packages/cxx-frontend/src/ASTSlot.ts

Lines changed: 84 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -166,87 +166,88 @@ export enum ASTSlot {
166166
newLoc = 144,
167167
newPlacement = 145,
168168
noexceptLoc = 146,
169-
offsetofLoc = 147,
170-
op = 148,
171-
opLoc = 149,
172-
openLoc = 150,
173-
operatorFunctionId = 151,
174-
operatorLoc = 152,
175-
otherVirtualOrAccessLoc = 153,
176-
outputOperandList = 154,
177-
parameterDeclarationClause = 155,
178-
parameterDeclarationList = 156,
179-
privateLoc = 157,
180-
privateModuleFragment = 158,
181-
ptrOpList = 159,
182-
qualifier = 160,
183-
qualifierLoc = 161,
184-
questionLoc = 162,
185-
rangeDeclaration = 163,
186-
rangeInitializer = 164,
187-
rbraceLoc = 165,
188-
rbracket2Loc = 166,
189-
rbracketLoc = 167,
190-
refLoc = 168,
191-
refOp = 169,
192-
refQualifierLoc = 170,
193-
requirementList = 171,
194-
requiresClause = 172,
195-
requiresLoc = 173,
196-
restrictLoc = 174,
197-
returnLoc = 175,
198-
rightExpression = 176,
199-
rparen2Loc = 177,
200-
rparenLoc = 178,
201-
scopeLoc = 179,
202-
secondColonLoc = 180,
203-
semicolonLoc = 181,
204-
sizeExpression = 182,
205-
sizeofLoc = 183,
206-
specifier = 184,
207-
specifierLoc = 185,
208-
splicer = 186,
209-
starLoc = 187,
210-
statement = 188,
211-
statementList = 189,
212-
staticAssertLoc = 190,
213-
staticLoc = 191,
214-
stringLiteral = 192,
215-
stringliteralLoc = 193,
216-
switchLoc = 194,
217-
symbolicName = 195,
218-
symbolicNameLoc = 196,
219-
templateArgumentList = 197,
220-
templateId = 198,
221-
templateLoc = 199,
222-
templateParameterList = 200,
223-
templateRequiresClause = 201,
224-
thisLoc = 202,
225-
threadLoc = 203,
226-
threadLocalLoc = 204,
227-
throwLoc = 205,
228-
tildeLoc = 206,
229-
trailingReturnType = 207,
230-
tryLoc = 208,
231-
typeConstraint = 209,
232-
typeId = 210,
233-
typeIdList = 211,
234-
typeLoc = 212,
235-
typeSpecifier = 213,
236-
typeSpecifierList = 214,
237-
typeTraitLoc = 215,
238-
typedefLoc = 216,
239-
typeidLoc = 217,
240-
typenameLoc = 218,
241-
underlyingTypeLoc = 219,
242-
unqualifiedId = 220,
243-
usingDeclaratorList = 221,
244-
usingLoc = 222,
245-
vaArgLoc = 223,
246-
virtualLoc = 224,
247-
virtualOrAccessLoc = 225,
248-
voidLoc = 226,
249-
volatileLoc = 227,
250-
whileLoc = 228,
251-
yieldLoc = 229,
169+
noreturnLoc = 147,
170+
offsetofLoc = 148,
171+
op = 149,
172+
opLoc = 150,
173+
openLoc = 151,
174+
operatorFunctionId = 152,
175+
operatorLoc = 153,
176+
otherVirtualOrAccessLoc = 154,
177+
outputOperandList = 155,
178+
parameterDeclarationClause = 156,
179+
parameterDeclarationList = 157,
180+
privateLoc = 158,
181+
privateModuleFragment = 159,
182+
ptrOpList = 160,
183+
qualifier = 161,
184+
qualifierLoc = 162,
185+
questionLoc = 163,
186+
rangeDeclaration = 164,
187+
rangeInitializer = 165,
188+
rbraceLoc = 166,
189+
rbracket2Loc = 167,
190+
rbracketLoc = 168,
191+
refLoc = 169,
192+
refOp = 170,
193+
refQualifierLoc = 171,
194+
requirementList = 172,
195+
requiresClause = 173,
196+
requiresLoc = 174,
197+
restrictLoc = 175,
198+
returnLoc = 176,
199+
rightExpression = 177,
200+
rparen2Loc = 178,
201+
rparenLoc = 179,
202+
scopeLoc = 180,
203+
secondColonLoc = 181,
204+
semicolonLoc = 182,
205+
sizeExpression = 183,
206+
sizeofLoc = 184,
207+
specifier = 185,
208+
specifierLoc = 186,
209+
splicer = 187,
210+
starLoc = 188,
211+
statement = 189,
212+
statementList = 190,
213+
staticAssertLoc = 191,
214+
staticLoc = 192,
215+
stringLiteral = 193,
216+
stringliteralLoc = 194,
217+
switchLoc = 195,
218+
symbolicName = 196,
219+
symbolicNameLoc = 197,
220+
templateArgumentList = 198,
221+
templateId = 199,
222+
templateLoc = 200,
223+
templateParameterList = 201,
224+
templateRequiresClause = 202,
225+
thisLoc = 203,
226+
threadLoc = 204,
227+
threadLocalLoc = 205,
228+
throwLoc = 206,
229+
tildeLoc = 207,
230+
trailingReturnType = 208,
231+
tryLoc = 209,
232+
typeConstraint = 210,
233+
typeId = 211,
234+
typeIdList = 212,
235+
typeLoc = 213,
236+
typeSpecifier = 214,
237+
typeSpecifierList = 215,
238+
typeTraitLoc = 216,
239+
typedefLoc = 217,
240+
typeidLoc = 218,
241+
typenameLoc = 219,
242+
underlyingTypeLoc = 220,
243+
unqualifiedId = 221,
244+
usingDeclaratorList = 222,
245+
usingLoc = 223,
246+
vaArgLoc = 224,
247+
virtualLoc = 225,
248+
virtualOrAccessLoc = 226,
249+
voidLoc = 227,
250+
volatileLoc = 228,
251+
whileLoc = 229,
252+
yieldLoc = 230,
252253
}

packages/cxx-frontend/src/ASTVisitor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,18 @@ export abstract class ASTVisitor<Context, Result> {
17531753
context: Context,
17541754
): Result;
17551755

1756+
/**
1757+
* Visit NoreturnSpecifier node.
1758+
*
1759+
* @param node The node to visit.
1760+
* @param context The context.
1761+
* @returns The result of the visit.
1762+
*/
1763+
abstract visitNoreturnSpecifier(
1764+
node: ast.NoreturnSpecifierAST,
1765+
context: Context,
1766+
): Result;
1767+
17561768
/**
17571769
* Visit StaticSpecifier node.
17581770
*

packages/cxx-frontend/src/RecursiveASTVisitor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,17 @@ export class RecursiveASTVisitor<Context> extends ASTVisitor<Context, void> {
19261926
*/
19271927
visitInlineSpecifier(node: ast.InlineSpecifierAST, context: Context): void {}
19281928

1929+
/**
1930+
* Visit a NoreturnSpecifier node.
1931+
*
1932+
* @param node The node to visit.
1933+
* @param context The context.
1934+
*/
1935+
visitNoreturnSpecifier(
1936+
node: ast.NoreturnSpecifierAST,
1937+
context: Context,
1938+
): void {}
1939+
19291940
/**
19301941
* Visit a StaticSpecifier node.
19311942
*

src/mlir/cxx/mlir/codegen.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ struct Codegen::SpecifierVisitor {
332332

333333
[[nodiscard]] auto operator()(InlineSpecifierAST* ast) -> SpecifierResult;
334334

335+
[[nodiscard]] auto operator()(NoreturnSpecifierAST* ast) -> SpecifierResult;
336+
335337
[[nodiscard]] auto operator()(StaticSpecifierAST* ast) -> SpecifierResult;
336338

337339
[[nodiscard]] auto operator()(ExternSpecifierAST* ast) -> SpecifierResult;
@@ -2247,6 +2249,11 @@ auto Codegen::SpecifierVisitor::operator()(InlineSpecifierAST* ast)
22472249
return {};
22482250
}
22492251

2252+
auto Codegen::SpecifierVisitor::operator()(NoreturnSpecifierAST* ast)
2253+
-> SpecifierResult {
2254+
return {};
2255+
}
2256+
22502257
auto Codegen::SpecifierVisitor::operator()(StaticSpecifierAST* ast)
22512258
-> SpecifierResult {
22522259
return {};

src/parser/cxx/ast.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,16 @@ auto InlineSpecifierAST::lastSourceLocation() -> SourceLocation {
22962296
return {};
22972297
}
22982298

2299+
auto NoreturnSpecifierAST::firstSourceLocation() -> SourceLocation {
2300+
if (auto loc = cxx::firstSourceLocation(noreturnLoc)) return loc;
2301+
return {};
2302+
}
2303+
2304+
auto NoreturnSpecifierAST::lastSourceLocation() -> SourceLocation {
2305+
if (auto loc = cxx::lastSourceLocation(noreturnLoc)) return loc;
2306+
return {};
2307+
}
2308+
22992309
auto StaticSpecifierAST::firstSourceLocation() -> SourceLocation {
23002310
if (auto loc = cxx::firstSourceLocation(staticLoc)) return loc;
23012311
return {};
@@ -3607,6 +3617,7 @@ std::string_view kASTKindNames[] = {
36073617
"constinit-specifier",
36083618
"constexpr-specifier",
36093619
"inline-specifier",
3620+
"noreturn-specifier",
36103621
"static-specifier",
36113622
"extern-specifier",
36123623
"thread-local-specifier",

src/parser/cxx/ast.fbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ union Specifier {
241241
ConstinitSpecifier,
242242
ConstexprSpecifier,
243243
InlineSpecifier,
244+
NoreturnSpecifier,
244245
StaticSpecifier,
245246
ExternSpecifier,
246247
ThreadLocalSpecifier,
@@ -1445,6 +1446,10 @@ table InlineSpecifier /* SpecifierAST */ {
14451446
inline_loc: uint32;
14461447
}
14471448

1449+
table NoreturnSpecifier /* SpecifierAST */ {
1450+
noreturn_loc: uint32;
1451+
}
1452+
14481453
table StaticSpecifier /* SpecifierAST */ {
14491454
static_loc: uint32;
14501455
}

src/parser/cxx/ast.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,20 @@ class InlineSpecifierAST final : public SpecifierAST {
28182818
auto lastSourceLocation() -> SourceLocation override;
28192819
};
28202820

2821+
class NoreturnSpecifierAST final : public SpecifierAST {
2822+
public:
2823+
static constexpr ASTKind Kind = ASTKind::NoreturnSpecifier;
2824+
2825+
NoreturnSpecifierAST() : SpecifierAST(Kind) {}
2826+
2827+
SourceLocation noreturnLoc;
2828+
2829+
void accept(ASTVisitor* visitor) override { visitor->visit(this); }
2830+
2831+
auto firstSourceLocation() -> SourceLocation override;
2832+
auto lastSourceLocation() -> SourceLocation override;
2833+
};
2834+
28212835
class StaticSpecifierAST final : public SpecifierAST {
28222836
public:
28232837
static constexpr ASTKind Kind = ASTKind::StaticSpecifier;
@@ -4768,6 +4782,9 @@ auto visit(Visitor&& visitor, SpecifierAST* ast) {
47684782
case InlineSpecifierAST::Kind:
47694783
return std::invoke(std::forward<Visitor>(visitor),
47704784
static_cast<InlineSpecifierAST*>(ast));
4785+
case NoreturnSpecifierAST::Kind:
4786+
return std::invoke(std::forward<Visitor>(visitor),
4787+
static_cast<NoreturnSpecifierAST*>(ast));
47714788
case StaticSpecifierAST::Kind:
47724789
return std::invoke(std::forward<Visitor>(visitor),
47734790
static_cast<StaticSpecifierAST*>(ast));
@@ -4871,6 +4888,7 @@ template <>
48714888
case ConstinitSpecifierAST::Kind:
48724889
case ConstexprSpecifierAST::Kind:
48734890
case InlineSpecifierAST::Kind:
4891+
case NoreturnSpecifierAST::Kind:
48744892
case StaticSpecifierAST::Kind:
48754893
case ExternSpecifierAST::Kind:
48764894
case ThreadLocalSpecifierAST::Kind:

src/parser/cxx/ast_fwd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class ConstevalSpecifierAST;
240240
class ConstinitSpecifierAST;
241241
class ConstexprSpecifierAST;
242242
class InlineSpecifierAST;
243+
class NoreturnSpecifierAST;
243244
class StaticSpecifierAST;
244245
class ExternSpecifierAST;
245246
class ThreadLocalSpecifierAST;

0 commit comments

Comments
 (0)