Skip to content

Commit 455d92f

Browse files
committed
Parse C storage-class specifiers
1 parent 554ffe2 commit 455d92f

28 files changed

+503
-318
lines changed

packages/cxx-frontend/src/AST.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8812,6 +8812,31 @@ export class ExternSpecifierAST extends SpecifierAST {
88128812
}
88138813
}
88148814

8815+
/**
8816+
* RegisterSpecifierAST node.
8817+
*/
8818+
export class RegisterSpecifierAST extends SpecifierAST {
8819+
/**
8820+
* Traverse this node using the given visitor.
8821+
* @param visitor the visitor.
8822+
* @param context the context.
8823+
* @returns the result of the visit.
8824+
*/
8825+
accept<Context, Result>(
8826+
visitor: ASTVisitor<Context, Result>,
8827+
context: Context,
8828+
): Result {
8829+
return visitor.visitRegisterSpecifier(this, context);
8830+
}
8831+
8832+
/**
8833+
* Returns the location of the register token in this node
8834+
*/
8835+
getRegisterToken(): Token | undefined {
8836+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
8837+
}
8838+
}
8839+
88158840
/**
88168841
* ThreadLocalSpecifierAST node.
88178842
*/
@@ -13043,6 +13068,7 @@ const AST_CONSTRUCTORS: Array<
1304313068
NoreturnSpecifierAST,
1304413069
StaticSpecifierAST,
1304513070
ExternSpecifierAST,
13071+
RegisterSpecifierAST,
1304613072
ThreadLocalSpecifierAST,
1304713073
ThreadSpecifierAST,
1304813074
MutableSpecifierAST,

packages/cxx-frontend/src/ASTKind.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export enum ASTKind {
184184
NoreturnSpecifier,
185185
StaticSpecifier,
186186
ExternSpecifier,
187+
RegisterSpecifier,
187188
ThreadLocalSpecifier,
188189
ThreadSpecifier,
189190
MutableSpecifier,

packages/cxx-frontend/src/ASTSlot.ts

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -191,63 +191,64 @@ export enum ASTSlot {
191191
refLoc = 169,
192192
refOp = 170,
193193
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,
194+
registerLoc = 172,
195+
requirementList = 173,
196+
requiresClause = 174,
197+
requiresLoc = 175,
198+
restrictLoc = 176,
199+
returnLoc = 177,
200+
rightExpression = 178,
201+
rparen2Loc = 179,
202+
rparenLoc = 180,
203+
scopeLoc = 181,
204+
secondColonLoc = 182,
205+
semicolonLoc = 183,
206+
sizeExpression = 184,
207+
sizeofLoc = 185,
208+
specifier = 186,
209+
specifierLoc = 187,
210+
splicer = 188,
211+
starLoc = 189,
212+
statement = 190,
213+
statementList = 191,
214+
staticAssertLoc = 192,
215+
staticLoc = 193,
216+
stringLiteral = 194,
217+
stringliteralLoc = 195,
218+
switchLoc = 196,
219+
symbolicName = 197,
220+
symbolicNameLoc = 198,
221+
templateArgumentList = 199,
222+
templateId = 200,
223+
templateLoc = 201,
224+
templateParameterList = 202,
225+
templateRequiresClause = 203,
226+
thisLoc = 204,
227+
threadLoc = 205,
228+
threadLocalLoc = 206,
229+
throwLoc = 207,
230+
tildeLoc = 208,
231+
trailingReturnType = 209,
232+
tryLoc = 210,
233+
typeConstraint = 211,
234+
typeId = 212,
235+
typeIdList = 213,
236+
typeLoc = 214,
237+
typeSpecifier = 215,
238+
typeSpecifierList = 216,
239+
typeTraitLoc = 217,
240+
typedefLoc = 218,
241+
typeidLoc = 219,
242+
typenameLoc = 220,
243+
underlyingTypeLoc = 221,
244+
unqualifiedId = 222,
245+
usingDeclaratorList = 223,
246+
usingLoc = 224,
247+
vaArgLoc = 225,
248+
virtualLoc = 226,
249+
virtualOrAccessLoc = 227,
250+
voidLoc = 228,
251+
volatileLoc = 229,
252+
whileLoc = 230,
253+
yieldLoc = 231,
253254
}

packages/cxx-frontend/src/ASTVisitor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,18 @@ export abstract class ASTVisitor<Context, Result> {
17891789
context: Context,
17901790
): Result;
17911791

1792+
/**
1793+
* Visit RegisterSpecifier node.
1794+
*
1795+
* @param node The node to visit.
1796+
* @param context The context.
1797+
* @returns The result of the visit.
1798+
*/
1799+
abstract visitRegisterSpecifier(
1800+
node: ast.RegisterSpecifierAST,
1801+
context: Context,
1802+
): Result;
1803+
17921804
/**
17931805
* Visit ThreadLocalSpecifier node.
17941806
*

packages/cxx-frontend/src/RecursiveASTVisitor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,17 @@ export class RecursiveASTVisitor<Context> extends ASTVisitor<Context, void> {
19531953
*/
19541954
visitExternSpecifier(node: ast.ExternSpecifierAST, context: Context): void {}
19551955

1956+
/**
1957+
* Visit a RegisterSpecifier node.
1958+
*
1959+
* @param node The node to visit.
1960+
* @param context The context.
1961+
*/
1962+
visitRegisterSpecifier(
1963+
node: ast.RegisterSpecifierAST,
1964+
context: Context,
1965+
): void {}
1966+
19561967
/**
19571968
* Visit a ThreadLocalSpecifier node.
19581969
*

src/mlir/cxx/mlir/codegen.cc

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

339339
[[nodiscard]] auto operator()(ExternSpecifierAST* ast) -> SpecifierResult;
340340

341+
[[nodiscard]] auto operator()(RegisterSpecifierAST* ast) -> SpecifierResult;
342+
341343
[[nodiscard]] auto operator()(ThreadLocalSpecifierAST* ast)
342344
-> SpecifierResult;
343345

@@ -2264,6 +2266,11 @@ auto Codegen::SpecifierVisitor::operator()(ExternSpecifierAST* ast)
22642266
return {};
22652267
}
22662268

2269+
auto Codegen::SpecifierVisitor::operator()(RegisterSpecifierAST* ast)
2270+
-> SpecifierResult {
2271+
return {};
2272+
}
2273+
22672274
auto Codegen::SpecifierVisitor::operator()(ThreadLocalSpecifierAST* ast)
22682275
-> SpecifierResult {
22692276
return {};

src/parser/cxx/ast.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,16 @@ auto ExternSpecifierAST::lastSourceLocation() -> SourceLocation {
23262326
return {};
23272327
}
23282328

2329+
auto RegisterSpecifierAST::firstSourceLocation() -> SourceLocation {
2330+
if (auto loc = cxx::firstSourceLocation(registerLoc)) return loc;
2331+
return {};
2332+
}
2333+
2334+
auto RegisterSpecifierAST::lastSourceLocation() -> SourceLocation {
2335+
if (auto loc = cxx::lastSourceLocation(registerLoc)) return loc;
2336+
return {};
2337+
}
2338+
23292339
auto ThreadLocalSpecifierAST::firstSourceLocation() -> SourceLocation {
23302340
if (auto loc = cxx::firstSourceLocation(threadLocalLoc)) return loc;
23312341
return {};
@@ -3620,6 +3630,7 @@ std::string_view kASTKindNames[] = {
36203630
"noreturn-specifier",
36213631
"static-specifier",
36223632
"extern-specifier",
3633+
"register-specifier",
36233634
"thread-local-specifier",
36243635
"thread-specifier",
36253636
"mutable-specifier",

src/parser/cxx/ast.fbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ union Specifier {
244244
NoreturnSpecifier,
245245
StaticSpecifier,
246246
ExternSpecifier,
247+
RegisterSpecifier,
247248
ThreadLocalSpecifier,
248249
ThreadSpecifier,
249250
MutableSpecifier,
@@ -1458,6 +1459,10 @@ table ExternSpecifier /* SpecifierAST */ {
14581459
extern_loc: uint32;
14591460
}
14601461

1462+
table RegisterSpecifier /* SpecifierAST */ {
1463+
register_loc: uint32;
1464+
}
1465+
14611466
table ThreadLocalSpecifier /* SpecifierAST */ {
14621467
thread_local_loc: uint32;
14631468
}

src/parser/cxx/ast.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,6 +2860,20 @@ class ExternSpecifierAST final : public SpecifierAST {
28602860
auto lastSourceLocation() -> SourceLocation override;
28612861
};
28622862

2863+
class RegisterSpecifierAST final : public SpecifierAST {
2864+
public:
2865+
static constexpr ASTKind Kind = ASTKind::RegisterSpecifier;
2866+
2867+
RegisterSpecifierAST() : SpecifierAST(Kind) {}
2868+
2869+
SourceLocation registerLoc;
2870+
2871+
void accept(ASTVisitor* visitor) override { visitor->visit(this); }
2872+
2873+
auto firstSourceLocation() -> SourceLocation override;
2874+
auto lastSourceLocation() -> SourceLocation override;
2875+
};
2876+
28632877
class ThreadLocalSpecifierAST final : public SpecifierAST {
28642878
public:
28652879
static constexpr ASTKind Kind = ASTKind::ThreadLocalSpecifier;
@@ -4791,6 +4805,9 @@ auto visit(Visitor&& visitor, SpecifierAST* ast) {
47914805
case ExternSpecifierAST::Kind:
47924806
return std::invoke(std::forward<Visitor>(visitor),
47934807
static_cast<ExternSpecifierAST*>(ast));
4808+
case RegisterSpecifierAST::Kind:
4809+
return std::invoke(std::forward<Visitor>(visitor),
4810+
static_cast<RegisterSpecifierAST*>(ast));
47944811
case ThreadLocalSpecifierAST::Kind:
47954812
return std::invoke(std::forward<Visitor>(visitor),
47964813
static_cast<ThreadLocalSpecifierAST*>(ast));
@@ -4891,6 +4908,7 @@ template <>
48914908
case NoreturnSpecifierAST::Kind:
48924909
case StaticSpecifierAST::Kind:
48934910
case ExternSpecifierAST::Kind:
4911+
case RegisterSpecifierAST::Kind:
48944912
case ThreadLocalSpecifierAST::Kind:
48954913
case ThreadSpecifierAST::Kind:
48964914
case MutableSpecifierAST::Kind:

src/parser/cxx/ast_fwd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ class InlineSpecifierAST;
243243
class NoreturnSpecifierAST;
244244
class StaticSpecifierAST;
245245
class ExternSpecifierAST;
246+
class RegisterSpecifierAST;
246247
class ThreadLocalSpecifierAST;
247248
class ThreadSpecifierAST;
248249
class MutableSpecifierAST;

0 commit comments

Comments
 (0)