Skip to content

Commit a314aa6

Browse files
committed
Parse C _Atomic qualifier and type qualifiers in array declarators
1 parent ac9db46 commit a314aa6

28 files changed

+371
-72
lines changed

packages/cxx-frontend/src/AST.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9698,6 +9698,31 @@ export class VolatileQualifierAST extends SpecifierAST {
96989698
}
96999699
}
97009700

9701+
/**
9702+
* AtomicQualifierAST node.
9703+
*/
9704+
export class AtomicQualifierAST extends SpecifierAST {
9705+
/**
9706+
* Traverse this node using the given visitor.
9707+
* @param visitor the visitor.
9708+
* @param context the context.
9709+
* @returns the result of the visit.
9710+
*/
9711+
accept<Context, Result>(
9712+
visitor: ASTVisitor<Context, Result>,
9713+
context: Context,
9714+
): Result {
9715+
return visitor.visitAtomicQualifier(this, context);
9716+
}
9717+
9718+
/**
9719+
* Returns the location of the atomic token in this node
9720+
*/
9721+
getAtomicToken(): Token | undefined {
9722+
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
9723+
}
9724+
}
9725+
97019726
/**
97029727
* RestrictQualifierAST node.
97039728
*/
@@ -10728,12 +10753,38 @@ export class ArrayDeclaratorChunkAST extends DeclaratorChunkAST {
1072810753
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
1072910754
}
1073010755

10756+
/**
10757+
* Returns the typeQualifierList of this node
10758+
*/
10759+
getTypeQualifierList(): Iterable<SpecifierAST | undefined> {
10760+
let it = cxx.getASTSlot(this.getHandle(), 0);
10761+
let value: SpecifierAST | undefined;
10762+
let done = false;
10763+
const p = this.parser;
10764+
function advance() {
10765+
done = it === 0;
10766+
if (done) return;
10767+
const ast = cxx.getListValue(it);
10768+
value = AST.from<SpecifierAST>(ast, p);
10769+
it = cxx.getListNext(it);
10770+
}
10771+
function next() {
10772+
advance();
10773+
return { done, value };
10774+
}
10775+
return {
10776+
[Symbol.iterator]() {
10777+
return { next };
10778+
},
10779+
};
10780+
}
10781+
1073110782
/**
1073210783
* Returns the expression of this node
1073310784
*/
1073410785
getExpression(): ExpressionAST | undefined {
1073510786
return AST.from<ExpressionAST>(
10736-
cxx.getASTSlot(this.getHandle(), 1),
10787+
cxx.getASTSlot(this.getHandle(), 2),
1073710788
this.parser,
1073810789
);
1073910790
}
@@ -10742,7 +10793,7 @@ export class ArrayDeclaratorChunkAST extends DeclaratorChunkAST {
1074210793
* Returns the location of the rbracket token in this node
1074310794
*/
1074410795
getRbracketToken(): Token | undefined {
10745-
return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser);
10796+
return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser);
1074610797
}
1074710798

1074810799
/**
@@ -13144,6 +13195,7 @@ const AST_CONSTRUCTORS: Array<
1314413195
PlaceholderTypeSpecifierAST,
1314513196
ConstQualifierAST,
1314613197
VolatileQualifierAST,
13198+
AtomicQualifierAST,
1314713199
RestrictQualifierAST,
1314813200
EnumSpecifierAST,
1314913201
ClassSpecifierAST,

packages/cxx-frontend/src/ASTKind.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export enum ASTKind {
208208
PlaceholderTypeSpecifier,
209209
ConstQualifier,
210210
VolatileQualifier,
211+
AtomicQualifier,
211212
RestrictQualifier,
212213
EnumSpecifier,
213214
ClassSpecifier,

packages/cxx-frontend/src/ASTSlot.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,22 @@ export enum ASTSlot {
234234
typeId = 212,
235235
typeIdList = 213,
236236
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,
237+
typeQualifierList = 215,
238+
typeSpecifier = 216,
239+
typeSpecifierList = 217,
240+
typeTraitLoc = 218,
241+
typedefLoc = 219,
242+
typeidLoc = 220,
243+
typenameLoc = 221,
244+
underlyingTypeLoc = 222,
245+
unqualifiedId = 223,
246+
usingDeclaratorList = 224,
247+
usingLoc = 225,
248+
vaArgLoc = 226,
249+
virtualLoc = 227,
250+
virtualOrAccessLoc = 228,
251+
voidLoc = 229,
252+
volatileLoc = 230,
253+
whileLoc = 231,
254+
yieldLoc = 232,
254255
}

packages/cxx-frontend/src/ASTVisitor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,18 @@ export abstract class ASTVisitor<Context, Result> {
20772077
context: Context,
20782078
): Result;
20792079

2080+
/**
2081+
* Visit AtomicQualifier node.
2082+
*
2083+
* @param node The node to visit.
2084+
* @param context The context.
2085+
* @returns The result of the visit.
2086+
*/
2087+
abstract visitAtomicQualifier(
2088+
node: ast.AtomicQualifierAST,
2089+
context: Context,
2090+
): Result;
2091+
20802092
/**
20812093
* Visit RestrictQualifier node.
20822094
*

packages/cxx-frontend/src/RecursiveASTVisitor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,6 +2234,14 @@ export class RecursiveASTVisitor<Context> extends ASTVisitor<Context, void> {
22342234
context: Context,
22352235
): void {}
22362236

2237+
/**
2238+
* Visit a AtomicQualifier node.
2239+
*
2240+
* @param node The node to visit.
2241+
* @param context The context.
2242+
*/
2243+
visitAtomicQualifier(node: ast.AtomicQualifierAST, context: Context): void {}
2244+
22372245
/**
22382246
* Visit a RestrictQualifier node.
22392247
*
@@ -2440,6 +2448,9 @@ export class RecursiveASTVisitor<Context> extends ASTVisitor<Context, void> {
24402448
node: ast.ArrayDeclaratorChunkAST,
24412449
context: Context,
24422450
): void {
2451+
for (const element of node.getTypeQualifierList()) {
2452+
this.accept(element, context);
2453+
}
24432454
this.accept(node.getExpression(), context);
24442455
for (const element of node.getAttributeList()) {
24452456
this.accept(element, context);

src/mlir/cxx/mlir/codegen.cc

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

398398
[[nodiscard]] auto operator()(RestrictQualifierAST* ast) -> SpecifierResult;
399399

400+
[[nodiscard]] auto operator()(AtomicQualifierAST* ast) -> SpecifierResult;
401+
400402
[[nodiscard]] auto operator()(EnumSpecifierAST* ast) -> SpecifierResult;
401403

402404
[[nodiscard]] auto operator()(ClassSpecifierAST* ast) -> SpecifierResult;
@@ -2417,6 +2419,11 @@ auto Codegen::SpecifierVisitor::operator()(RestrictQualifierAST* ast)
24172419
return {};
24182420
}
24192421

2422+
auto Codegen::SpecifierVisitor::operator()(AtomicQualifierAST* ast)
2423+
-> SpecifierResult {
2424+
return {};
2425+
}
2426+
24202427
auto Codegen::SpecifierVisitor::operator()(EnumSpecifierAST* ast)
24212428
-> SpecifierResult {
24222429
for (auto node : ListView{ast->attributeList}) {

src/parser/cxx/ast.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,6 +2616,16 @@ auto VolatileQualifierAST::lastSourceLocation() -> SourceLocation {
26162616
return {};
26172617
}
26182618

2619+
auto AtomicQualifierAST::firstSourceLocation() -> SourceLocation {
2620+
if (auto loc = cxx::firstSourceLocation(atomicLoc)) return loc;
2621+
return {};
2622+
}
2623+
2624+
auto AtomicQualifierAST::lastSourceLocation() -> SourceLocation {
2625+
if (auto loc = cxx::lastSourceLocation(atomicLoc)) return loc;
2626+
return {};
2627+
}
2628+
26192629
auto RestrictQualifierAST::firstSourceLocation() -> SourceLocation {
26202630
if (auto loc = cxx::firstSourceLocation(restrictLoc)) return loc;
26212631
return {};
@@ -2838,6 +2848,7 @@ auto FunctionDeclaratorChunkAST::lastSourceLocation() -> SourceLocation {
28382848

28392849
auto ArrayDeclaratorChunkAST::firstSourceLocation() -> SourceLocation {
28402850
if (auto loc = cxx::firstSourceLocation(lbracketLoc)) return loc;
2851+
if (auto loc = cxx::firstSourceLocation(typeQualifierList)) return loc;
28412852
if (auto loc = cxx::firstSourceLocation(expression)) return loc;
28422853
if (auto loc = cxx::firstSourceLocation(rbracketLoc)) return loc;
28432854
if (auto loc = cxx::firstSourceLocation(attributeList)) return loc;
@@ -2848,6 +2859,7 @@ auto ArrayDeclaratorChunkAST::lastSourceLocation() -> SourceLocation {
28482859
if (auto loc = cxx::lastSourceLocation(attributeList)) return loc;
28492860
if (auto loc = cxx::lastSourceLocation(rbracketLoc)) return loc;
28502861
if (auto loc = cxx::lastSourceLocation(expression)) return loc;
2862+
if (auto loc = cxx::lastSourceLocation(typeQualifierList)) return loc;
28512863
if (auto loc = cxx::lastSourceLocation(lbracketLoc)) return loc;
28522864
return {};
28532865
}
@@ -3670,6 +3682,7 @@ std::string_view kASTKindNames[] = {
36703682
"placeholder-type-specifier",
36713683
"const-qualifier",
36723684
"volatile-qualifier",
3685+
"atomic-qualifier",
36733686
"restrict-qualifier",
36743687
"enum-specifier",
36753688
"class-specifier",

src/parser/cxx/ast.fbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ union Specifier {
268268
PlaceholderTypeSpecifier,
269269
ConstQualifier,
270270
VolatileQualifier,
271+
AtomicQualifier,
271272
RestrictQualifier,
272273
EnumSpecifier,
273274
ClassSpecifier,
@@ -817,6 +818,7 @@ table FunctionDeclaratorChunk /* DeclaratorChunkAST */ {
817818
}
818819

819820
table ArrayDeclaratorChunk /* DeclaratorChunkAST */ {
821+
type_qualifier_list: [Specifier];
820822
expression: Expression;
821823
attribute_list: [AttributeSpecifier];
822824
lbracket_loc: uint32;
@@ -1587,6 +1589,10 @@ table VolatileQualifier /* SpecifierAST */ {
15871589
volatile_loc: uint32;
15881590
}
15891591

1592+
table AtomicQualifier /* SpecifierAST */ {
1593+
atomic_loc: uint32;
1594+
}
1595+
15901596
table RestrictQualifier /* SpecifierAST */ {
15911597
restrict_loc: uint32;
15921598
}

src/parser/cxx/ast.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,6 +3232,20 @@ class VolatileQualifierAST final : public SpecifierAST {
32323232
auto lastSourceLocation() -> SourceLocation override;
32333233
};
32343234

3235+
class AtomicQualifierAST final : public SpecifierAST {
3236+
public:
3237+
static constexpr ASTKind Kind = ASTKind::AtomicQualifier;
3238+
3239+
AtomicQualifierAST() : SpecifierAST(Kind) {}
3240+
3241+
SourceLocation atomicLoc;
3242+
3243+
void accept(ASTVisitor* visitor) override { visitor->visit(this); }
3244+
3245+
auto firstSourceLocation() -> SourceLocation override;
3246+
auto lastSourceLocation() -> SourceLocation override;
3247+
};
3248+
32353249
class RestrictQualifierAST final : public SpecifierAST {
32363250
public:
32373251
static constexpr ASTKind Kind = ASTKind::RestrictQualifier;
@@ -3475,6 +3489,7 @@ class ArrayDeclaratorChunkAST final : public DeclaratorChunkAST {
34753489
ArrayDeclaratorChunkAST() : DeclaratorChunkAST(Kind) {}
34763490

34773491
SourceLocation lbracketLoc;
3492+
List<SpecifierAST*>* typeQualifierList = nullptr;
34783493
ExpressionAST* expression = nullptr;
34793494
SourceLocation rbracketLoc;
34803495
List<AttributeSpecifierAST*>* attributeList = nullptr;
@@ -4895,6 +4910,9 @@ auto visit(Visitor&& visitor, SpecifierAST* ast) {
48954910
case VolatileQualifierAST::Kind:
48964911
return std::invoke(std::forward<Visitor>(visitor),
48974912
static_cast<VolatileQualifierAST*>(ast));
4913+
case AtomicQualifierAST::Kind:
4914+
return std::invoke(std::forward<Visitor>(visitor),
4915+
static_cast<AtomicQualifierAST*>(ast));
48984916
case RestrictQualifierAST::Kind:
48994917
return std::invoke(std::forward<Visitor>(visitor),
49004918
static_cast<RestrictQualifierAST*>(ast));
@@ -4952,6 +4970,7 @@ template <>
49524970
case PlaceholderTypeSpecifierAST::Kind:
49534971
case ConstQualifierAST::Kind:
49544972
case VolatileQualifierAST::Kind:
4973+
case AtomicQualifierAST::Kind:
49554974
case RestrictQualifierAST::Kind:
49564975
case EnumSpecifierAST::Kind:
49574976
case ClassSpecifierAST::Kind:

src/parser/cxx/ast_fwd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ class DecltypeSpecifierAST;
267267
class PlaceholderTypeSpecifierAST;
268268
class ConstQualifierAST;
269269
class VolatileQualifierAST;
270+
class AtomicQualifierAST;
270271
class RestrictQualifierAST;
271272
class EnumSpecifierAST;
272273
class ClassSpecifierAST;

0 commit comments

Comments
 (0)