Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/cxx-frontend/src/AST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8812,6 +8812,31 @@ export class ExternSpecifierAST extends SpecifierAST {
}
}

/**
* RegisterSpecifierAST node.
*/
export class RegisterSpecifierAST extends SpecifierAST {
/**
* Traverse this node using the given visitor.
* @param visitor the visitor.
* @param context the context.
* @returns the result of the visit.
*/
accept<Context, Result>(
visitor: ASTVisitor<Context, Result>,
context: Context,
): Result {
return visitor.visitRegisterSpecifier(this, context);
}

/**
* Returns the location of the register token in this node
*/
getRegisterToken(): Token | undefined {
return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser);
}
}

/**
* ThreadLocalSpecifierAST node.
*/
Expand Down Expand Up @@ -13043,6 +13068,7 @@ const AST_CONSTRUCTORS: Array<
NoreturnSpecifierAST,
StaticSpecifierAST,
ExternSpecifierAST,
RegisterSpecifierAST,
ThreadLocalSpecifierAST,
ThreadSpecifierAST,
MutableSpecifierAST,
Expand Down
1 change: 1 addition & 0 deletions packages/cxx-frontend/src/ASTKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export enum ASTKind {
NoreturnSpecifier,
StaticSpecifier,
ExternSpecifier,
RegisterSpecifier,
ThreadLocalSpecifier,
ThreadSpecifier,
MutableSpecifier,
Expand Down
119 changes: 60 additions & 59 deletions packages/cxx-frontend/src/ASTSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,63 +191,64 @@ export enum ASTSlot {
refLoc = 169,
refOp = 170,
refQualifierLoc = 171,
requirementList = 172,
requiresClause = 173,
requiresLoc = 174,
restrictLoc = 175,
returnLoc = 176,
rightExpression = 177,
rparen2Loc = 178,
rparenLoc = 179,
scopeLoc = 180,
secondColonLoc = 181,
semicolonLoc = 182,
sizeExpression = 183,
sizeofLoc = 184,
specifier = 185,
specifierLoc = 186,
splicer = 187,
starLoc = 188,
statement = 189,
statementList = 190,
staticAssertLoc = 191,
staticLoc = 192,
stringLiteral = 193,
stringliteralLoc = 194,
switchLoc = 195,
symbolicName = 196,
symbolicNameLoc = 197,
templateArgumentList = 198,
templateId = 199,
templateLoc = 200,
templateParameterList = 201,
templateRequiresClause = 202,
thisLoc = 203,
threadLoc = 204,
threadLocalLoc = 205,
throwLoc = 206,
tildeLoc = 207,
trailingReturnType = 208,
tryLoc = 209,
typeConstraint = 210,
typeId = 211,
typeIdList = 212,
typeLoc = 213,
typeSpecifier = 214,
typeSpecifierList = 215,
typeTraitLoc = 216,
typedefLoc = 217,
typeidLoc = 218,
typenameLoc = 219,
underlyingTypeLoc = 220,
unqualifiedId = 221,
usingDeclaratorList = 222,
usingLoc = 223,
vaArgLoc = 224,
virtualLoc = 225,
virtualOrAccessLoc = 226,
voidLoc = 227,
volatileLoc = 228,
whileLoc = 229,
yieldLoc = 230,
registerLoc = 172,
requirementList = 173,
requiresClause = 174,
requiresLoc = 175,
restrictLoc = 176,
returnLoc = 177,
rightExpression = 178,
rparen2Loc = 179,
rparenLoc = 180,
scopeLoc = 181,
secondColonLoc = 182,
semicolonLoc = 183,
sizeExpression = 184,
sizeofLoc = 185,
specifier = 186,
specifierLoc = 187,
splicer = 188,
starLoc = 189,
statement = 190,
statementList = 191,
staticAssertLoc = 192,
staticLoc = 193,
stringLiteral = 194,
stringliteralLoc = 195,
switchLoc = 196,
symbolicName = 197,
symbolicNameLoc = 198,
templateArgumentList = 199,
templateId = 200,
templateLoc = 201,
templateParameterList = 202,
templateRequiresClause = 203,
thisLoc = 204,
threadLoc = 205,
threadLocalLoc = 206,
throwLoc = 207,
tildeLoc = 208,
trailingReturnType = 209,
tryLoc = 210,
typeConstraint = 211,
typeId = 212,
typeIdList = 213,
typeLoc = 214,
typeSpecifier = 215,
typeSpecifierList = 216,
typeTraitLoc = 217,
typedefLoc = 218,
typeidLoc = 219,
typenameLoc = 220,
underlyingTypeLoc = 221,
unqualifiedId = 222,
usingDeclaratorList = 223,
usingLoc = 224,
vaArgLoc = 225,
virtualLoc = 226,
virtualOrAccessLoc = 227,
voidLoc = 228,
volatileLoc = 229,
whileLoc = 230,
yieldLoc = 231,
}
12 changes: 12 additions & 0 deletions packages/cxx-frontend/src/ASTVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,18 @@ export abstract class ASTVisitor<Context, Result> {
context: Context,
): Result;

/**
* Visit RegisterSpecifier node.
*
* @param node The node to visit.
* @param context The context.
* @returns The result of the visit.
*/
abstract visitRegisterSpecifier(
node: ast.RegisterSpecifierAST,
context: Context,
): Result;

/**
* Visit ThreadLocalSpecifier node.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/cxx-frontend/src/RecursiveASTVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,17 @@ export class RecursiveASTVisitor<Context> extends ASTVisitor<Context, void> {
*/
visitExternSpecifier(node: ast.ExternSpecifierAST, context: Context): void {}

/**
* Visit a RegisterSpecifier node.
*
* @param node The node to visit.
* @param context The context.
*/
visitRegisterSpecifier(
node: ast.RegisterSpecifierAST,
context: Context,
): void {}

/**
* Visit a ThreadLocalSpecifier node.
*
Expand Down
7 changes: 7 additions & 0 deletions src/mlir/cxx/mlir/codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ struct Codegen::SpecifierVisitor {

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

[[nodiscard]] auto operator()(RegisterSpecifierAST* ast) -> SpecifierResult;

[[nodiscard]] auto operator()(ThreadLocalSpecifierAST* ast)
-> SpecifierResult;

Expand Down Expand Up @@ -2264,6 +2266,11 @@ auto Codegen::SpecifierVisitor::operator()(ExternSpecifierAST* ast)
return {};
}

auto Codegen::SpecifierVisitor::operator()(RegisterSpecifierAST* ast)
-> SpecifierResult {
return {};
}

auto Codegen::SpecifierVisitor::operator()(ThreadLocalSpecifierAST* ast)
-> SpecifierResult {
return {};
Expand Down
11 changes: 11 additions & 0 deletions src/parser/cxx/ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,16 @@ auto ExternSpecifierAST::lastSourceLocation() -> SourceLocation {
return {};
}

auto RegisterSpecifierAST::firstSourceLocation() -> SourceLocation {
if (auto loc = cxx::firstSourceLocation(registerLoc)) return loc;
return {};
}

auto RegisterSpecifierAST::lastSourceLocation() -> SourceLocation {
if (auto loc = cxx::lastSourceLocation(registerLoc)) return loc;
return {};
}

auto ThreadLocalSpecifierAST::firstSourceLocation() -> SourceLocation {
if (auto loc = cxx::firstSourceLocation(threadLocalLoc)) return loc;
return {};
Expand Down Expand Up @@ -3620,6 +3630,7 @@ std::string_view kASTKindNames[] = {
"noreturn-specifier",
"static-specifier",
"extern-specifier",
"register-specifier",
"thread-local-specifier",
"thread-specifier",
"mutable-specifier",
Expand Down
5 changes: 5 additions & 0 deletions src/parser/cxx/ast.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ union Specifier {
NoreturnSpecifier,
StaticSpecifier,
ExternSpecifier,
RegisterSpecifier,
ThreadLocalSpecifier,
ThreadSpecifier,
MutableSpecifier,
Expand Down Expand Up @@ -1458,6 +1459,10 @@ table ExternSpecifier /* SpecifierAST */ {
extern_loc: uint32;
}

table RegisterSpecifier /* SpecifierAST */ {
register_loc: uint32;
}

table ThreadLocalSpecifier /* SpecifierAST */ {
thread_local_loc: uint32;
}
Expand Down
18 changes: 18 additions & 0 deletions src/parser/cxx/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2860,6 +2860,20 @@ class ExternSpecifierAST final : public SpecifierAST {
auto lastSourceLocation() -> SourceLocation override;
};

class RegisterSpecifierAST final : public SpecifierAST {
public:
static constexpr ASTKind Kind = ASTKind::RegisterSpecifier;

RegisterSpecifierAST() : SpecifierAST(Kind) {}

SourceLocation registerLoc;

void accept(ASTVisitor* visitor) override { visitor->visit(this); }

auto firstSourceLocation() -> SourceLocation override;
auto lastSourceLocation() -> SourceLocation override;
};

class ThreadLocalSpecifierAST final : public SpecifierAST {
public:
static constexpr ASTKind Kind = ASTKind::ThreadLocalSpecifier;
Expand Down Expand Up @@ -4791,6 +4805,9 @@ auto visit(Visitor&& visitor, SpecifierAST* ast) {
case ExternSpecifierAST::Kind:
return std::invoke(std::forward<Visitor>(visitor),
static_cast<ExternSpecifierAST*>(ast));
case RegisterSpecifierAST::Kind:
return std::invoke(std::forward<Visitor>(visitor),
static_cast<RegisterSpecifierAST*>(ast));
case ThreadLocalSpecifierAST::Kind:
return std::invoke(std::forward<Visitor>(visitor),
static_cast<ThreadLocalSpecifierAST*>(ast));
Expand Down Expand Up @@ -4891,6 +4908,7 @@ template <>
case NoreturnSpecifierAST::Kind:
case StaticSpecifierAST::Kind:
case ExternSpecifierAST::Kind:
case RegisterSpecifierAST::Kind:
case ThreadLocalSpecifierAST::Kind:
case ThreadSpecifierAST::Kind:
case MutableSpecifierAST::Kind:
Expand Down
1 change: 1 addition & 0 deletions src/parser/cxx/ast_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class InlineSpecifierAST;
class NoreturnSpecifierAST;
class StaticSpecifierAST;
class ExternSpecifierAST;
class RegisterSpecifierAST;
class ThreadLocalSpecifierAST;
class ThreadSpecifierAST;
class MutableSpecifierAST;
Expand Down
7 changes: 7 additions & 0 deletions src/parser/cxx/ast_interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ struct ASTInterpreter::SpecifierVisitor {

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

[[nodiscard]] auto operator()(RegisterSpecifierAST* ast) -> SpecifierResult;

[[nodiscard]] auto operator()(ThreadLocalSpecifierAST* ast)
-> SpecifierResult;

Expand Down Expand Up @@ -2576,6 +2578,11 @@ auto ASTInterpreter::SpecifierVisitor::operator()(ExternSpecifierAST* ast)
return {};
}

auto ASTInterpreter::SpecifierVisitor::operator()(RegisterSpecifierAST* ast)
-> SpecifierResult {
return {};
}

auto ASTInterpreter::SpecifierVisitor::operator()(ThreadLocalSpecifierAST* ast)
-> SpecifierResult {
return {};
Expand Down
1 change: 1 addition & 0 deletions src/parser/cxx/ast_kind.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ enum class ASTKind {
NoreturnSpecifier,
StaticSpecifier,
ExternSpecifier,
RegisterSpecifier,
ThreadLocalSpecifier,
ThreadSpecifier,
MutableSpecifier,
Expand Down
8 changes: 8 additions & 0 deletions src/parser/cxx/ast_pretty_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ struct ASTPrettyPrinter::SpecifierVisitor {

void operator()(ExternSpecifierAST* ast);

void operator()(RegisterSpecifierAST* ast);

void operator()(ThreadLocalSpecifierAST* ast);

void operator()(ThreadSpecifierAST* ast);
Expand Down Expand Up @@ -3261,6 +3263,12 @@ void ASTPrettyPrinter::SpecifierVisitor::operator()(ExternSpecifierAST* ast) {
}
}

void ASTPrettyPrinter::SpecifierVisitor::operator()(RegisterSpecifierAST* ast) {
if (ast->registerLoc) {
accept.writeToken(ast->registerLoc);
}
}

void ASTPrettyPrinter::SpecifierVisitor::operator()(
ThreadLocalSpecifierAST* ast) {
if (ast->threadLocalLoc) {
Expand Down
4 changes: 4 additions & 0 deletions src/parser/cxx/ast_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,10 @@ void ASTPrinter::visit(ExternSpecifierAST* ast) {
out_ << std::format("{}\n", "extern-specifier");
}

void ASTPrinter::visit(RegisterSpecifierAST* ast) {
out_ << std::format("{}\n", "register-specifier");
}

void ASTPrinter::visit(ThreadLocalSpecifierAST* ast) {
out_ << std::format("{}\n", "thread-local-specifier");
}
Expand Down
1 change: 1 addition & 0 deletions src/parser/cxx/ast_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class ASTPrinter : ASTVisitor {
void visit(NoreturnSpecifierAST* ast) override;
void visit(StaticSpecifierAST* ast) override;
void visit(ExternSpecifierAST* ast) override;
void visit(RegisterSpecifierAST* ast) override;
void visit(ThreadLocalSpecifierAST* ast) override;
void visit(ThreadSpecifierAST* ast) override;
void visit(MutableSpecifierAST* ast) override;
Expand Down
Loading