From d8b354437b9a08832a14e74596b3052ddf1abd89 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Fri, 22 Aug 2025 21:17:43 +0200 Subject: [PATCH] Update the reflection syntax according to the latest draft --- packages/cxx-frontend/src/AST.ts | 76 +----- packages/cxx-frontend/src/ASTKind.ts | 4 +- packages/cxx-frontend/src/ASTSlot.ts | 39 ++- packages/cxx-frontend/src/ASTVisitor.ts | 30 +-- .../cxx-frontend/src/RecursiveASTVisitor.ts | 28 +-- packages/cxx-frontend/src/TokenKind.ts | 2 + packages/cxx-gen-ast/src/tokens.ts | 2 + src/mlir/cxx/mlir/codegen_expressions.cc | 8 - src/mlir/cxx/mlir/codegen_specifiers.cc | 10 +- src/mlir/cxx/mlir/convert_type.cc | 6 + src/parser/cxx/ast.cc | 44 +--- src/parser/cxx/ast.fbs | 22 +- src/parser/cxx/ast.h | 58 +---- src/parser/cxx/ast_fwd.h | 4 +- src/parser/cxx/ast_interpreter.cc | 64 +++-- src/parser/cxx/ast_interpreter.h | 3 +- src/parser/cxx/ast_kind.h | 4 +- src/parser/cxx/ast_pretty_printer.cc | 38 +-- src/parser/cxx/ast_printer.cc | 17 +- src/parser/cxx/ast_printer.h | 4 +- src/parser/cxx/ast_rewriter_expressions.cc | 23 +- src/parser/cxx/ast_rewriter_specifiers.cc | 19 +- src/parser/cxx/ast_slot.cc | 143 +++++------ src/parser/cxx/ast_slot.h | 4 +- src/parser/cxx/ast_visitor.cc | 6 +- src/parser/cxx/ast_visitor.h | 4 +- src/parser/cxx/const_value.h | 18 +- src/parser/cxx/control.cc | 5 + src/parser/cxx/control.h | 1 + src/parser/cxx/decl_specs.cc | 37 ++- src/parser/cxx/external_name_encoder.cc | 5 + src/parser/cxx/flatbuffers/ast_decoder.cc | 45 +--- src/parser/cxx/flatbuffers/ast_encoder.cc | 30 +-- src/parser/cxx/lexer.cc | 3 + src/parser/cxx/memory_layout.cc | 5 + src/parser/cxx/names.cc | 9 + src/parser/cxx/parser.cc | 60 +++-- src/parser/cxx/private/ast_decoder.h | 9 +- src/parser/cxx/private/ast_encoder.h | 4 +- src/parser/cxx/private/keywords-priv.h | 46 ++++ src/parser/cxx/token_fwd.h | 226 +++++++++--------- src/parser/cxx/type_checker.cc | 25 +- src/parser/cxx/type_printer.cc | 4 + src/parser/cxx/type_traits.h | 5 + src/parser/cxx/types.h | 6 + src/parser/cxx/types_fwd.h | 3 +- tests/unit_tests/ast/reflect_01.cc | 36 +-- tests/unit_tests/ast/reflect_02.cc | 4 +- tests/unit_tests/ast/variadic_function_02.cc | 2 +- tests/unit_tests/sema/reflect_01.cc | 27 +++ 50 files changed, 584 insertions(+), 693 deletions(-) create mode 100644 tests/unit_tests/sema/reflect_01.cc diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index a400e236..cedd86ed 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -5041,31 +5041,6 @@ export class TryBlockStatementAST extends StatementAST { } } -/** - * GeneratedLiteralExpressionAST node. - */ -export class GeneratedLiteralExpressionAST extends ExpressionAST { - /** - * Traverse this node using the given visitor. - * @param visitor the visitor. - * @param context the context. - * @returns the result of the visit. - */ - accept( - visitor: ASTVisitor, - context: Context, - ): Result { - return visitor.visitGeneratedLiteralExpression(this, context); - } - - /** - * Returns the location of the literal token in this node - */ - getLiteralToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); - } -} - /** * CharLiteralExpressionAST node. */ @@ -7012,9 +6987,9 @@ export class GlobalScopeReflectExpressionAST extends ExpressionAST { } /** - * Returns the location of the caret token in this node + * Returns the location of the caretCaret token in this node */ - getCaretToken(): Token | undefined { + getCaretCaretToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } @@ -7044,9 +7019,9 @@ export class NamespaceReflectExpressionAST extends ExpressionAST { } /** - * Returns the location of the caret token in this node + * Returns the location of the caretCaret token in this node */ - getCaretToken(): Token | undefined { + getCaretCaretToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } @@ -7084,9 +7059,9 @@ export class TypeIdReflectExpressionAST extends ExpressionAST { } /** - * Returns the location of the caret token in this node + * Returns the location of the caretCaret token in this node */ - getCaretToken(): Token | undefined { + getCaretCaretToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } @@ -7119,9 +7094,9 @@ export class ReflectExpressionAST extends ExpressionAST { } /** - * Returns the location of the caret token in this node + * Returns the location of the caretCaret token in this node */ - getCaretToken(): Token | undefined { + getCaretCaretToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } @@ -8922,31 +8897,6 @@ export class ConstraintTypeParameterAST extends TemplateParameterAST { } } -/** - * GeneratedTypeSpecifierAST node. - */ -export class GeneratedTypeSpecifierAST extends SpecifierAST { - /** - * Traverse this node using the given visitor. - * @param visitor the visitor. - * @param context the context. - * @returns the result of the visit. - */ - accept( - visitor: ASTVisitor, - context: Context, - ): Result { - return visitor.visitGeneratedTypeSpecifier(this, context); - } - - /** - * Returns the location of the type token in this node - */ - getTypeToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); - } -} - /** * TypedefSpecifierAST node. */ @@ -9461,9 +9411,9 @@ export class SignTypeSpecifierAST extends SpecifierAST { } /** - * VaListTypeSpecifierAST node. + * BuiltinTypeSpecifierAST node. */ -export class VaListTypeSpecifierAST extends SpecifierAST { +export class BuiltinTypeSpecifierAST extends SpecifierAST { /** * Traverse this node using the given visitor. * @param visitor the visitor. @@ -9474,7 +9424,7 @@ export class VaListTypeSpecifierAST extends SpecifierAST { visitor: ASTVisitor, context: Context, ): Result { - return visitor.visitVaListTypeSpecifier(this, context); + return visitor.visitBuiltinTypeSpecifier(this, context); } /** @@ -13404,7 +13354,6 @@ const AST_CONSTRUCTORS: Array< GotoStatementAST, DeclarationStatementAST, TryBlockStatementAST, - GeneratedLiteralExpressionAST, CharLiteralExpressionAST, BoolLiteralExpressionAST, IntLiteralExpressionAST, @@ -13475,7 +13424,6 @@ const AST_CONSTRUCTORS: Array< NonTypeTemplateParameterAST, TypenameTypeParameterAST, ConstraintTypeParameterAST, - GeneratedTypeSpecifierAST, TypedefSpecifierAST, FriendSpecifierAST, ConstevalSpecifierAST, @@ -13495,7 +13443,7 @@ const AST_CONSTRUCTORS: Array< VoidTypeSpecifierAST, SizeTypeSpecifierAST, SignTypeSpecifierAST, - VaListTypeSpecifierAST, + BuiltinTypeSpecifierAST, IntegralTypeSpecifierAST, FloatingPointTypeSpecifierAST, ComplexTypeSpecifierAST, diff --git a/packages/cxx-frontend/src/ASTKind.ts b/packages/cxx-frontend/src/ASTKind.ts index fe58d81b..9f56bd4a 100644 --- a/packages/cxx-frontend/src/ASTKind.ts +++ b/packages/cxx-frontend/src/ASTKind.ts @@ -104,7 +104,6 @@ export enum ASTKind { TryBlockStatement, // ExpressionAST - GeneratedLiteralExpression, CharLiteralExpression, BoolLiteralExpression, IntLiteralExpression, @@ -183,7 +182,6 @@ export enum ASTKind { ConstraintTypeParameter, // SpecifierAST - GeneratedTypeSpecifier, TypedefSpecifier, FriendSpecifier, ConstevalSpecifier, @@ -203,7 +201,7 @@ export enum ASTKind { VoidTypeSpecifier, SizeTypeSpecifier, SignTypeSpecifier, - VaListTypeSpecifier, + BuiltinTypeSpecifier, IntegralTypeSpecifier, FloatingPointTypeSpecifier, ComplexTypeSpecifier, diff --git a/packages/cxx-frontend/src/ASTSlot.ts b/packages/cxx-frontend/src/ASTSlot.ts index a4d94bb6..91459735 100644 --- a/packages/cxx-frontend/src/ASTSlot.ts +++ b/packages/cxx-frontend/src/ASTSlot.ts @@ -48,7 +48,7 @@ export enum ASTSlot { captureDefault = 25, captureDefaultLoc = 26, captureList = 27, - caretLoc = 28, + caretCaretLoc = 28, caseLoc = 29, castLoc = 30, catchLoc = 31, @@ -240,23 +240,22 @@ export enum ASTSlot { typeConstraint = 217, typeId = 218, typeIdList = 219, - typeLoc = 220, - typeQualifierList = 221, - typeSpecifier = 222, - typeSpecifierList = 223, - typeTraitLoc = 224, - typedefLoc = 225, - typeidLoc = 226, - typenameLoc = 227, - underlyingTypeLoc = 228, - unqualifiedId = 229, - usingDeclaratorList = 230, - usingLoc = 231, - vaArgLoc = 232, - virtualLoc = 233, - virtualOrAccessLoc = 234, - voidLoc = 235, - volatileLoc = 236, - whileLoc = 237, - yieldLoc = 238, + typeQualifierList = 220, + typeSpecifier = 221, + typeSpecifierList = 222, + typeTraitLoc = 223, + typedefLoc = 224, + typeidLoc = 225, + typenameLoc = 226, + underlyingTypeLoc = 227, + unqualifiedId = 228, + usingDeclaratorList = 229, + usingLoc = 230, + vaArgLoc = 231, + virtualLoc = 232, + virtualOrAccessLoc = 233, + voidLoc = 234, + volatileLoc = 235, + whileLoc = 236, + yieldLoc = 237, } diff --git a/packages/cxx-frontend/src/ASTVisitor.ts b/packages/cxx-frontend/src/ASTVisitor.ts index 64edbecc..35f58440 100644 --- a/packages/cxx-frontend/src/ASTVisitor.ts +++ b/packages/cxx-frontend/src/ASTVisitor.ts @@ -890,18 +890,6 @@ export abstract class ASTVisitor { context: Context, ): Result; - /** - * Visit GeneratedLiteralExpression node. - * - * @param node The node to visit. - * @param context The context. - * @returns The result of the visit. - */ - abstract visitGeneratedLiteralExpression( - node: ast.GeneratedLiteralExpressionAST, - context: Context, - ): Result; - /** * Visit CharLiteralExpression node. * @@ -1742,18 +1730,6 @@ export abstract class ASTVisitor { context: Context, ): Result; - /** - * Visit GeneratedTypeSpecifier node. - * - * @param node The node to visit. - * @param context The context. - * @returns The result of the visit. - */ - abstract visitGeneratedTypeSpecifier( - node: ast.GeneratedTypeSpecifierAST, - context: Context, - ): Result; - /** * Visit TypedefSpecifier node. * @@ -1983,14 +1959,14 @@ export abstract class ASTVisitor { ): Result; /** - * Visit VaListTypeSpecifier node. + * Visit BuiltinTypeSpecifier node. * * @param node The node to visit. * @param context The context. * @returns The result of the visit. */ - abstract visitVaListTypeSpecifier( - node: ast.VaListTypeSpecifierAST, + abstract visitBuiltinTypeSpecifier( + node: ast.BuiltinTypeSpecifierAST, context: Context, ): Result; diff --git a/packages/cxx-frontend/src/RecursiveASTVisitor.ts b/packages/cxx-frontend/src/RecursiveASTVisitor.ts index c4b8ed77..5ec9c37f 100644 --- a/packages/cxx-frontend/src/RecursiveASTVisitor.ts +++ b/packages/cxx-frontend/src/RecursiveASTVisitor.ts @@ -1038,17 +1038,6 @@ export class RecursiveASTVisitor extends ASTVisitor { } } - /** - * Visit a GeneratedLiteralExpression node. - * - * @param node The node to visit. - * @param context The context. - */ - visitGeneratedLiteralExpression( - node: ast.GeneratedLiteralExpressionAST, - context: Context, - ): void {} - /** * Visit a CharLiteralExpression node. * @@ -1940,17 +1929,6 @@ export class RecursiveASTVisitor extends ASTVisitor { this.accept(node.getTypeId(), context); } - /** - * Visit a GeneratedTypeSpecifier node. - * - * @param node The node to visit. - * @param context The context. - */ - visitGeneratedTypeSpecifier( - node: ast.GeneratedTypeSpecifierAST, - context: Context, - ): void {} - /** * Visit a TypedefSpecifier node. * @@ -2148,13 +2126,13 @@ export class RecursiveASTVisitor extends ASTVisitor { ): void {} /** - * Visit a VaListTypeSpecifier node. + * Visit a BuiltinTypeSpecifier node. * * @param node The node to visit. * @param context The context. */ - visitVaListTypeSpecifier( - node: ast.VaListTypeSpecifierAST, + visitBuiltinTypeSpecifier( + node: ast.BuiltinTypeSpecifierAST, context: Context, ): void {} diff --git a/packages/cxx-frontend/src/TokenKind.ts b/packages/cxx-frontend/src/TokenKind.ts index c3f30b62..b2805230 100644 --- a/packages/cxx-frontend/src/TokenKind.ts +++ b/packages/cxx-frontend/src/TokenKind.ts @@ -41,6 +41,7 @@ export enum TokenKind { BAR_BAR, BAR_EQUAL, BAR, + CARET_CARET, CARET_EQUAL, CARET, COLON_COLON, @@ -100,6 +101,7 @@ export enum TokenKind { _NORETURN, __ATTRIBUTE__, __BUILTIN_BIT_CAST, + __BUILTIN_META_INFO, __BUILTIN_OFFSETOF, __BUILTIN_VA_ARG, __BUILTIN_VA_LIST, diff --git a/packages/cxx-gen-ast/src/tokens.ts b/packages/cxx-gen-ast/src/tokens.ts index 3ea2ded7..3f34134c 100644 --- a/packages/cxx-gen-ast/src/tokens.ts +++ b/packages/cxx-gen-ast/src/tokens.ts @@ -43,6 +43,7 @@ export const OPERATORS: Array<[kind: string, spelling: string]> = [ ["BAR_BAR", "||"], ["BAR_EQUAL", "|="], ["BAR", "|"], + ["CARET_CARET", "^^"], ["CARET_EQUAL", "^="], ["CARET", "^"], ["COLON_COLON", "::"], @@ -182,6 +183,7 @@ export const CXX_KEYWORDS: string[] = [ "__builtin_offsetof", "__builtin_va_arg", "__builtin_va_list", + "__builtin_meta_info", "__complex__", "__extension__", "__float128", diff --git a/src/mlir/cxx/mlir/codegen_expressions.cc b/src/mlir/cxx/mlir/codegen_expressions.cc index 8b3fad25..e2c728bc 100644 --- a/src/mlir/cxx/mlir/codegen_expressions.cc +++ b/src/mlir/cxx/mlir/codegen_expressions.cc @@ -46,7 +46,6 @@ struct Codegen::ExpressionVisitor { return type_cast(control()->remove_cv(type)); } - auto operator()(GeneratedLiteralExpressionAST* ast) -> ExpressionResult; auto operator()(CharLiteralExpressionAST* ast) -> ExpressionResult; auto operator()(BoolLiteralExpressionAST* ast) -> ExpressionResult; auto operator()(IntLiteralExpressionAST* ast) -> ExpressionResult; @@ -174,13 +173,6 @@ auto Codegen::newPlacement(NewPlacementAST* ast) -> NewPlacementResult { return {}; } -auto Codegen::ExpressionVisitor::operator()(GeneratedLiteralExpressionAST* ast) - -> ExpressionResult { - auto op = - gen.emitTodoExpr(ast->firstSourceLocation(), to_string(ast->kind())); - return {op}; -} - auto Codegen::ExpressionVisitor::operator()(CharLiteralExpressionAST* ast) -> ExpressionResult { auto loc = gen.getLocation(ast->literalLoc); diff --git a/src/mlir/cxx/mlir/codegen_specifiers.cc b/src/mlir/cxx/mlir/codegen_specifiers.cc index 3095ec5d..b693af43 100644 --- a/src/mlir/cxx/mlir/codegen_specifiers.cc +++ b/src/mlir/cxx/mlir/codegen_specifiers.cc @@ -28,7 +28,6 @@ namespace cxx { struct Codegen::SpecifierVisitor { Codegen& gen; - auto operator()(GeneratedTypeSpecifierAST* ast) -> SpecifierResult; auto operator()(TypedefSpecifierAST* ast) -> SpecifierResult; auto operator()(FriendSpecifierAST* ast) -> SpecifierResult; auto operator()(ConstevalSpecifierAST* ast) -> SpecifierResult; @@ -48,7 +47,7 @@ struct Codegen::SpecifierVisitor { auto operator()(VoidTypeSpecifierAST* ast) -> SpecifierResult; auto operator()(SizeTypeSpecifierAST* ast) -> SpecifierResult; auto operator()(SignTypeSpecifierAST* ast) -> SpecifierResult; - auto operator()(VaListTypeSpecifierAST* ast) -> SpecifierResult; + auto operator()(BuiltinTypeSpecifierAST* ast) -> SpecifierResult; auto operator()(IntegralTypeSpecifierAST* ast) -> SpecifierResult; auto operator()(FloatingPointTypeSpecifierAST* ast) -> SpecifierResult; auto operator()(ComplexTypeSpecifierAST* ast) -> SpecifierResult; @@ -173,11 +172,6 @@ auto Codegen::typeId(TypeIdAST* ast) -> TypeIdResult { return {}; } -auto Codegen::SpecifierVisitor::operator()(GeneratedTypeSpecifierAST* ast) - -> SpecifierResult { - return {}; -} - auto Codegen::SpecifierVisitor::operator()(TypedefSpecifierAST* ast) -> SpecifierResult { return {}; @@ -275,7 +269,7 @@ auto Codegen::SpecifierVisitor::operator()(SignTypeSpecifierAST* ast) return {}; } -auto Codegen::SpecifierVisitor::operator()(VaListTypeSpecifierAST* ast) +auto Codegen::SpecifierVisitor::operator()(BuiltinTypeSpecifierAST* ast) -> SpecifierResult { return {}; } diff --git a/src/mlir/cxx/mlir/convert_type.cc b/src/mlir/cxx/mlir/convert_type.cc index b1f50706..8c395270 100644 --- a/src/mlir/cxx/mlir/convert_type.cc +++ b/src/mlir/cxx/mlir/convert_type.cc @@ -90,6 +90,7 @@ struct Codegen::ConvertType { auto operator()(const UnresolvedUnderlyingType* type) -> mlir::Type; auto operator()(const OverloadSetType* type) -> mlir::Type; auto operator()(const BuiltinVaListType* type) -> mlir::Type; + auto operator()(const BuiltinMetaInfoType* type) -> mlir::Type; }; auto Codegen::convertType(const Type* type) -> mlir::Type { @@ -369,4 +370,9 @@ auto Codegen::ConvertType::operator()(const BuiltinVaListType* type) return gen.builder_.getType(voidType); } +auto Codegen::ConvertType::operator()(const BuiltinMetaInfoType* type) + -> mlir::Type { + return getExprType(); +} + } // namespace cxx diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index 0920dc50..8abb31cc 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -1239,16 +1239,6 @@ auto TryBlockStatementAST::lastSourceLocation() -> SourceLocation { return {}; } -auto GeneratedLiteralExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; - return {}; -} - -auto GeneratedLiteralExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; - return {}; -} - auto CharLiteralExpressionAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; return {}; @@ -1770,50 +1760,50 @@ auto SpliceExpressionAST::lastSourceLocation() -> SourceLocation { } auto GlobalScopeReflectExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(caretLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(caretCaretLoc)) return loc; if (auto loc = cxx::firstSourceLocation(scopeLoc)) return loc; return {}; } auto GlobalScopeReflectExpressionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(scopeLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(caretLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(caretCaretLoc)) return loc; return {}; } auto NamespaceReflectExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(caretLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(caretCaretLoc)) return loc; if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; return {}; } auto NamespaceReflectExpressionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(caretLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(caretCaretLoc)) return loc; return {}; } auto TypeIdReflectExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(caretLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(caretCaretLoc)) return loc; if (auto loc = cxx::firstSourceLocation(typeId)) return loc; return {}; } auto TypeIdReflectExpressionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(typeId)) return loc; - if (auto loc = cxx::lastSourceLocation(caretLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(caretCaretLoc)) return loc; return {}; } auto ReflectExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(caretLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(caretCaretLoc)) return loc; if (auto loc = cxx::firstSourceLocation(expression)) return loc; return {}; } auto ReflectExpressionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(caretLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(caretCaretLoc)) return loc; return {}; } @@ -2321,16 +2311,6 @@ auto ConstraintTypeParameterAST::lastSourceLocation() -> SourceLocation { return {}; } -auto GeneratedTypeSpecifierAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(typeLoc)) return loc; - return {}; -} - -auto GeneratedTypeSpecifierAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(typeLoc)) return loc; - return {}; -} - auto TypedefSpecifierAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(typedefLoc)) return loc; return {}; @@ -2527,12 +2507,12 @@ auto SignTypeSpecifierAST::lastSourceLocation() -> SourceLocation { return {}; } -auto VaListTypeSpecifierAST::firstSourceLocation() -> SourceLocation { +auto BuiltinTypeSpecifierAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(specifierLoc)) return loc; return {}; } -auto VaListTypeSpecifierAST::lastSourceLocation() -> SourceLocation { +auto BuiltinTypeSpecifierAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(specifierLoc)) return loc; return {}; } @@ -3656,7 +3636,6 @@ std::string_view kASTKindNames[] = { "try-block-statement", // ExpressionAST - "generated-literal-expression", "char-literal-expression", "bool-literal-expression", "int-literal-expression", @@ -3735,7 +3714,6 @@ std::string_view kASTKindNames[] = { "constraint-type-parameter", // SpecifierAST - "generated-type-specifier", "typedef-specifier", "friend-specifier", "consteval-specifier", @@ -3755,7 +3733,7 @@ std::string_view kASTKindNames[] = { "void-type-specifier", "size-type-specifier", "sign-type-specifier", - "va-list-type-specifier", + "builtin-type-specifier", "integral-type-specifier", "floating-point-type-specifier", "complex-type-specifier", diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index e12c3c02..a9115643 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -127,7 +127,6 @@ union ExceptionSpecifier { } union Expression { - GeneratedLiteralExpression, CharLiteralExpression, BoolLiteralExpression, IntLiteralExpression, @@ -244,7 +243,6 @@ union Requirement { } union Specifier { - GeneratedTypeSpecifier, TypedefSpecifier, FriendSpecifier, ConstevalSpecifier, @@ -264,7 +262,7 @@ union Specifier { VoidTypeSpecifier, SizeTypeSpecifier, SignTypeSpecifier, - VaListTypeSpecifier, + BuiltinTypeSpecifier, IntegralTypeSpecifier, FloatingPointTypeSpecifier, ComplexTypeSpecifier, @@ -869,10 +867,6 @@ table NoexceptSpecifier /* ExceptionSpecifierAST */ { rparen_loc: uint32; } -table GeneratedLiteralExpression /* ExpressionAST */ { - literal_loc: uint32; -} - table CharLiteralExpression /* ExpressionAST */ { literal: string; literal_loc: uint32; @@ -1114,24 +1108,24 @@ table SpliceExpression /* ExpressionAST */ { } table GlobalScopeReflectExpression /* ExpressionAST */ { - caret_loc: uint32; + caret_caret_loc: uint32; scope_loc: uint32; } table NamespaceReflectExpression /* ExpressionAST */ { identifier: string; - caret_loc: uint32; + caret_caret_loc: uint32; identifier_loc: uint32; } table TypeIdReflectExpression /* ExpressionAST */ { type_id: TypeId; - caret_loc: uint32; + caret_caret_loc: uint32; } table ReflectExpression /* ExpressionAST */ { expression: Expression; - caret_loc: uint32; + caret_caret_loc: uint32; } table LabelAddressExpression /* ExpressionAST */ { @@ -1474,10 +1468,6 @@ table NestedRequirement /* RequirementAST */ { semicolon_loc: uint32; } -table GeneratedTypeSpecifier /* SpecifierAST */ { - type_loc: uint32; -} - table TypedefSpecifier /* SpecifierAST */ { typedef_loc: uint32; } @@ -1559,7 +1549,7 @@ table SignTypeSpecifier /* SpecifierAST */ { specifier_loc: uint32; } -table VaListTypeSpecifier /* SpecifierAST */ { +table BuiltinTypeSpecifier /* SpecifierAST */ { specifier: uint32; specifier_loc: uint32; } diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index d8881677..5b42d6d5 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -1611,21 +1611,6 @@ class TryBlockStatementAST final : public StatementAST { auto lastSourceLocation() -> SourceLocation override; }; -class GeneratedLiteralExpressionAST final : public ExpressionAST { - public: - static constexpr ASTKind Kind = ASTKind::GeneratedLiteralExpression; - - GeneratedLiteralExpressionAST() : ExpressionAST(Kind) {} - - SourceLocation literalLoc; - ConstValue value; - - void accept(ASTVisitor* visitor) override { visitor->visit(this); } - - auto firstSourceLocation() -> SourceLocation override; - auto lastSourceLocation() -> SourceLocation override; -}; - class CharLiteralExpressionAST final : public ExpressionAST { public: static constexpr ASTKind Kind = ASTKind::CharLiteralExpression; @@ -2202,7 +2187,7 @@ class GlobalScopeReflectExpressionAST final : public ExpressionAST { GlobalScopeReflectExpressionAST() : ExpressionAST(Kind) {} - SourceLocation caretLoc; + SourceLocation caretCaretLoc; SourceLocation scopeLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -2217,7 +2202,7 @@ class NamespaceReflectExpressionAST final : public ExpressionAST { NamespaceReflectExpressionAST() : ExpressionAST(Kind) {} - SourceLocation caretLoc; + SourceLocation caretCaretLoc; SourceLocation identifierLoc; const Identifier* identifier = nullptr; NamespaceSymbol* symbol = nullptr; @@ -2234,7 +2219,7 @@ class TypeIdReflectExpressionAST final : public ExpressionAST { TypeIdReflectExpressionAST() : ExpressionAST(Kind) {} - SourceLocation caretLoc; + SourceLocation caretCaretLoc; TypeIdAST* typeId = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -2249,7 +2234,7 @@ class ReflectExpressionAST final : public ExpressionAST { ReflectExpressionAST() : ExpressionAST(Kind) {} - SourceLocation caretLoc; + SourceLocation caretCaretLoc; ExpressionAST* expression = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -2834,21 +2819,6 @@ class ConstraintTypeParameterAST final : public TemplateParameterAST { auto lastSourceLocation() -> SourceLocation override; }; -class GeneratedTypeSpecifierAST final : public SpecifierAST { - public: - static constexpr ASTKind Kind = ASTKind::GeneratedTypeSpecifier; - - GeneratedTypeSpecifierAST() : SpecifierAST(Kind) {} - - SourceLocation typeLoc; - const Type* type = nullptr; - - void accept(ASTVisitor* visitor) override { visitor->visit(this); } - - auto firstSourceLocation() -> SourceLocation override; - auto lastSourceLocation() -> SourceLocation override; -}; - class TypedefSpecifierAST final : public SpecifierAST { public: static constexpr ASTKind Kind = ASTKind::TypedefSpecifier; @@ -3120,11 +3090,11 @@ class SignTypeSpecifierAST final : public SpecifierAST { auto lastSourceLocation() -> SourceLocation override; }; -class VaListTypeSpecifierAST final : public SpecifierAST { +class BuiltinTypeSpecifierAST final : public SpecifierAST { public: - static constexpr ASTKind Kind = ASTKind::VaListTypeSpecifier; + static constexpr ASTKind Kind = ASTKind::BuiltinTypeSpecifier; - VaListTypeSpecifierAST() : SpecifierAST(Kind) {} + BuiltinTypeSpecifierAST() : SpecifierAST(Kind) {} SourceLocation specifierLoc; TokenKind specifier = TokenKind::T_EOF_SYMBOL; @@ -4573,9 +4543,6 @@ template <> template auto visit(Visitor&& visitor, ExpressionAST* ast) { switch (ast->kind()) { - case GeneratedLiteralExpressionAST::Kind: - return std::invoke(std::forward(visitor), - static_cast(ast)); case CharLiteralExpressionAST::Kind: return std::invoke(std::forward(visitor), static_cast(ast)); @@ -4772,7 +4739,6 @@ template <> [[nodiscard]] inline auto ast_cast(AST* ast) -> ExpressionAST* { if (!ast) return nullptr; switch (ast->kind()) { - case GeneratedLiteralExpressionAST::Kind: case CharLiteralExpressionAST::Kind: case BoolLiteralExpressionAST::Kind: case IntLiteralExpressionAST::Kind: @@ -4932,9 +4898,6 @@ template <> template auto visit(Visitor&& visitor, SpecifierAST* ast) { switch (ast->kind()) { - case GeneratedTypeSpecifierAST::Kind: - return std::invoke(std::forward(visitor), - static_cast(ast)); case TypedefSpecifierAST::Kind: return std::invoke(std::forward(visitor), static_cast(ast)); @@ -4992,9 +4955,9 @@ auto visit(Visitor&& visitor, SpecifierAST* ast) { case SignTypeSpecifierAST::Kind: return std::invoke(std::forward(visitor), static_cast(ast)); - case VaListTypeSpecifierAST::Kind: + case BuiltinTypeSpecifierAST::Kind: return std::invoke(std::forward(visitor), - static_cast(ast)); + static_cast(ast)); case IntegralTypeSpecifierAST::Kind: return std::invoke(std::forward(visitor), static_cast(ast)); @@ -5058,7 +5021,6 @@ template <> [[nodiscard]] inline auto ast_cast(AST* ast) -> SpecifierAST* { if (!ast) return nullptr; switch (ast->kind()) { - case GeneratedTypeSpecifierAST::Kind: case TypedefSpecifierAST::Kind: case FriendSpecifierAST::Kind: case ConstevalSpecifierAST::Kind: @@ -5078,7 +5040,7 @@ template <> case VoidTypeSpecifierAST::Kind: case SizeTypeSpecifierAST::Kind: case SignTypeSpecifierAST::Kind: - case VaListTypeSpecifierAST::Kind: + case BuiltinTypeSpecifierAST::Kind: case IntegralTypeSpecifierAST::Kind: case FloatingPointTypeSpecifierAST::Kind: case ComplexTypeSpecifierAST::Kind: diff --git a/src/parser/cxx/ast_fwd.h b/src/parser/cxx/ast_fwd.h index 4e4f7882..eddac30b 100644 --- a/src/parser/cxx/ast_fwd.h +++ b/src/parser/cxx/ast_fwd.h @@ -164,7 +164,6 @@ class DeclarationStatementAST; class TryBlockStatementAST; // ExpressionAST -class GeneratedLiteralExpressionAST; class CharLiteralExpressionAST; class BoolLiteralExpressionAST; class IntLiteralExpressionAST; @@ -243,7 +242,6 @@ class TypenameTypeParameterAST; class ConstraintTypeParameterAST; // SpecifierAST -class GeneratedTypeSpecifierAST; class TypedefSpecifierAST; class FriendSpecifierAST; class ConstevalSpecifierAST; @@ -263,7 +261,7 @@ class AutoTypeSpecifierAST; class VoidTypeSpecifierAST; class SizeTypeSpecifierAST; class SignTypeSpecifierAST; -class VaListTypeSpecifierAST; +class BuiltinTypeSpecifierAST; class IntegralTypeSpecifierAST; class FloatingPointTypeSpecifierAST; class ComplexTypeSpecifierAST; diff --git a/src/parser/cxx/ast_interpreter.cc b/src/parser/cxx/ast_interpreter.cc index 020b24ac..e7ba4eb6 100644 --- a/src/parser/cxx/ast_interpreter.cc +++ b/src/parser/cxx/ast_interpreter.cc @@ -30,6 +30,8 @@ #include #include +#include + namespace cxx { namespace { @@ -69,6 +71,11 @@ struct ArithmeticCast { return T{}; } + auto operator()(const std::shared_ptr&) const -> T { + cxx_runtime_error("invalid artihmetic cast"); + return T{}; + } + auto operator()(auto value) const -> T { return static_cast(value); } }; @@ -114,8 +121,6 @@ struct ASTInterpreter::AttributeSpecifierResult {}; struct ASTInterpreter::AttributeTokenResult {}; -struct ASTInterpreter::SplicerResult {}; - struct ASTInterpreter::GlobalModuleFragmentResult {}; struct ASTInterpreter::PrivateModuleFragmentResult {}; @@ -171,6 +176,10 @@ struct ASTInterpreter::ToBool { return true; } + auto operator()(const Meta&) const -> std::optional { + return std::nullopt; + } + auto operator()(const auto& value) const -> std::optional { return bool(value); } @@ -665,9 +674,6 @@ struct ASTInterpreter::ExpressionVisitor { return right; } - [[nodiscard]] auto operator()(GeneratedLiteralExpressionAST* ast) - -> ExpressionResult; - [[nodiscard]] auto operator()(CharLiteralExpressionAST* ast) -> ExpressionResult; @@ -844,9 +850,6 @@ struct ASTInterpreter::TemplateParameterVisitor { struct ASTInterpreter::SpecifierVisitor { ASTInterpreter& accept; - [[nodiscard]] auto operator()(GeneratedTypeSpecifierAST* ast) - -> SpecifierResult; - [[nodiscard]] auto operator()(TypedefSpecifierAST* ast) -> SpecifierResult; [[nodiscard]] auto operator()(FriendSpecifierAST* ast) -> SpecifierResult; @@ -886,7 +889,8 @@ struct ASTInterpreter::SpecifierVisitor { [[nodiscard]] auto operator()(SignTypeSpecifierAST* ast) -> SpecifierResult; - [[nodiscard]] auto operator()(VaListTypeSpecifierAST* ast) -> SpecifierResult; + [[nodiscard]] auto operator()(BuiltinTypeSpecifierAST* ast) + -> SpecifierResult; [[nodiscard]] auto operator()(IntegralTypeSpecifierAST* ast) -> SpecifierResult; @@ -1258,12 +1262,12 @@ auto ASTInterpreter::operator()(AttributeTokenAST* ast) return {}; } -auto ASTInterpreter::operator()(SplicerAST* ast) -> SplicerResult { +auto ASTInterpreter::operator()(SplicerAST* ast) -> ExpressionResult { if (!ast) return {}; auto expressionResult = operator()(ast->expression); - return {}; + return expressionResult; } auto ASTInterpreter::operator()(GlobalModuleFragmentAST* ast) @@ -1983,11 +1987,6 @@ auto ASTInterpreter::StatementVisitor::operator()(TryBlockStatementAST* ast) return {}; } -auto ASTInterpreter::ExpressionVisitor::operator()( - GeneratedLiteralExpressionAST* ast) -> ExpressionResult { - return ast->value; -} - auto ASTInterpreter::ExpressionVisitor::operator()( CharLiteralExpressionAST* ast) -> ExpressionResult { return ConstValue(ast->literal->charValue()); @@ -2269,8 +2268,17 @@ auto ASTInterpreter::ExpressionVisitor::operator()( auto ASTInterpreter::ExpressionVisitor::operator()(SpliceExpressionAST* ast) -> ExpressionResult { auto splicerResult = accept(ast->splicer); + if (!splicerResult.has_value()) return std::nullopt; - return ExpressionResult{std::nullopt}; + auto metaPtr = std::get_if>(&splicerResult.value()); + if (!metaPtr) return std::nullopt; + + auto meta = *metaPtr; + + auto constExprPtr = std::get_if(&meta->value); + if (!constExprPtr) return std::nullopt; + + return constExprPtr->value; } auto ASTInterpreter::ExpressionVisitor::operator()( @@ -2285,15 +2293,24 @@ auto ASTInterpreter::ExpressionVisitor::operator()( auto ASTInterpreter::ExpressionVisitor::operator()( TypeIdReflectExpressionAST* ast) -> ExpressionResult { - auto typeIdResult = accept(ast->typeId); + if (!ast->typeId) return std::nullopt; + if (!ast->typeId->type) return std::nullopt; - return ExpressionResult{std::nullopt}; + auto meta = std::make_shared(ast->typeId->type); + + return ConstValue{meta}; } auto ASTInterpreter::ExpressionVisitor::operator()(ReflectExpressionAST* ast) -> ExpressionResult { auto expressionResult = accept(ast->expression); + if (expressionResult.has_value()) { + auto meta = std::make_shared(Meta::ConstExpr{ + .expression = ast->expression, .value = expressionResult.value()}); + return meta; + } + return ExpressionResult{std::nullopt}; } @@ -2806,7 +2823,7 @@ auto ASTInterpreter::ExpressionVisitor::operator()(EqualInitializerAST* ast) -> ExpressionResult { auto expressionResult = accept(ast->expression); - return ExpressionResult{std::nullopt}; + return expressionResult; } auto ASTInterpreter::ExpressionVisitor::operator()(BracedInitListAST* ast) @@ -2861,11 +2878,6 @@ auto ASTInterpreter::TemplateParameterVisitor::operator()( return {}; } -auto ASTInterpreter::SpecifierVisitor::operator()( - GeneratedTypeSpecifierAST* ast) -> SpecifierResult { - return {}; -} - auto ASTInterpreter::SpecifierVisitor::operator()(TypedefSpecifierAST* ast) -> SpecifierResult { return {}; @@ -2963,7 +2975,7 @@ auto ASTInterpreter::SpecifierVisitor::operator()(SignTypeSpecifierAST* ast) return {}; } -auto ASTInterpreter::SpecifierVisitor::operator()(VaListTypeSpecifierAST* ast) +auto ASTInterpreter::SpecifierVisitor::operator()(BuiltinTypeSpecifierAST* ast) -> SpecifierResult { return {}; } diff --git a/src/parser/cxx/ast_interpreter.h b/src/parser/cxx/ast_interpreter.h index 7142f2d4..c3419ae6 100644 --- a/src/parser/cxx/ast_interpreter.h +++ b/src/parser/cxx/ast_interpreter.h @@ -83,7 +83,6 @@ class ASTInterpreter { struct AttributeSpecifierResult; struct AttributeTokenResult; // misc nodes - struct SplicerResult; struct GlobalModuleFragmentResult; struct PrivateModuleFragmentResult; struct ModuleDeclarationResult; @@ -165,7 +164,7 @@ class ASTInterpreter { [[nodiscard]] auto operator()(AttributeTokenAST* ast) -> AttributeTokenResult; // run on the misc nodes - [[nodiscard]] auto operator()(SplicerAST* ast) -> SplicerResult; + [[nodiscard]] auto operator()(SplicerAST* ast) -> ExpressionResult; [[nodiscard]] auto operator()(GlobalModuleFragmentAST* ast) -> GlobalModuleFragmentResult; [[nodiscard]] auto operator()(PrivateModuleFragmentAST* ast) diff --git a/src/parser/cxx/ast_kind.h b/src/parser/cxx/ast_kind.h index b1468538..d676dab5 100644 --- a/src/parser/cxx/ast_kind.h +++ b/src/parser/cxx/ast_kind.h @@ -109,7 +109,6 @@ enum class ASTKind { TryBlockStatement, // ExpressionAST - GeneratedLiteralExpression, CharLiteralExpression, BoolLiteralExpression, IntLiteralExpression, @@ -188,7 +187,6 @@ enum class ASTKind { ConstraintTypeParameter, // SpecifierAST - GeneratedTypeSpecifier, TypedefSpecifier, FriendSpecifier, ConstevalSpecifier, @@ -208,7 +206,7 @@ enum class ASTKind { VoidTypeSpecifier, SizeTypeSpecifier, SignTypeSpecifier, - VaListTypeSpecifier, + BuiltinTypeSpecifier, IntegralTypeSpecifier, FloatingPointTypeSpecifier, ComplexTypeSpecifier, diff --git a/src/parser/cxx/ast_pretty_printer.cc b/src/parser/cxx/ast_pretty_printer.cc index a24cf478..e5280f53 100644 --- a/src/parser/cxx/ast_pretty_printer.cc +++ b/src/parser/cxx/ast_pretty_printer.cc @@ -175,8 +175,6 @@ struct ASTPrettyPrinter::ExpressionVisitor { void indent() { accept.indent(); } void unindent() { accept.unindent(); } - void operator()(GeneratedLiteralExpressionAST* ast); - void operator()(CharLiteralExpressionAST* ast); void operator()(BoolLiteralExpressionAST* ast); @@ -373,8 +371,6 @@ struct ASTPrettyPrinter::SpecifierVisitor { void indent() { accept.indent(); } void unindent() { accept.unindent(); } - void operator()(GeneratedTypeSpecifierAST* ast); - void operator()(TypedefSpecifierAST* ast); void operator()(FriendSpecifierAST* ast); @@ -413,7 +409,7 @@ struct ASTPrettyPrinter::SpecifierVisitor { void operator()(SignTypeSpecifierAST* ast); - void operator()(VaListTypeSpecifierAST* ast); + void operator()(BuiltinTypeSpecifierAST* ast); void operator()(IntegralTypeSpecifierAST* ast); @@ -2244,13 +2240,6 @@ void ASTPrettyPrinter::StatementVisitor::operator()(TryBlockStatementAST* ast) { } } -void ASTPrettyPrinter::ExpressionVisitor::operator()( - GeneratedLiteralExpressionAST* ast) { - if (ast->literalLoc) { - accept.writeToken(ast->literalLoc); - } -} - void ASTPrettyPrinter::ExpressionVisitor::operator()( CharLiteralExpressionAST* ast) { if (ast->literalLoc) { @@ -2804,8 +2793,8 @@ void ASTPrettyPrinter::ExpressionVisitor::operator()(SpliceExpressionAST* ast) { void ASTPrettyPrinter::ExpressionVisitor::operator()( GlobalScopeReflectExpressionAST* ast) { - if (ast->caretLoc) { - accept.writeToken(ast->caretLoc); + if (ast->caretCaretLoc) { + accept.writeToken(ast->caretCaretLoc); } if (ast->scopeLoc) { nospace(); @@ -2816,8 +2805,8 @@ void ASTPrettyPrinter::ExpressionVisitor::operator()( void ASTPrettyPrinter::ExpressionVisitor::operator()( NamespaceReflectExpressionAST* ast) { - if (ast->caretLoc) { - accept.writeToken(ast->caretLoc); + if (ast->caretCaretLoc) { + accept.writeToken(ast->caretCaretLoc); } if (ast->identifierLoc) { accept.writeToken(ast->identifierLoc); @@ -2826,16 +2815,16 @@ void ASTPrettyPrinter::ExpressionVisitor::operator()( void ASTPrettyPrinter::ExpressionVisitor::operator()( TypeIdReflectExpressionAST* ast) { - if (ast->caretLoc) { - accept.writeToken(ast->caretLoc); + if (ast->caretCaretLoc) { + accept.writeToken(ast->caretCaretLoc); } accept(ast->typeId); } void ASTPrettyPrinter::ExpressionVisitor::operator()( ReflectExpressionAST* ast) { - if (ast->caretLoc) { - accept.writeToken(ast->caretLoc); + if (ast->caretCaretLoc) { + accept.writeToken(ast->caretCaretLoc); } accept(ast->expression); } @@ -3329,13 +3318,6 @@ void ASTPrettyPrinter::TemplateParameterVisitor::operator()( accept(ast->typeId); } -void ASTPrettyPrinter::SpecifierVisitor::operator()( - GeneratedTypeSpecifierAST* ast) { - if (ast->typeLoc) { - accept.writeToken(ast->typeLoc); - } -} - void ASTPrettyPrinter::SpecifierVisitor::operator()(TypedefSpecifierAST* ast) { if (ast->typedefLoc) { accept.writeToken(ast->typedefLoc); @@ -3465,7 +3447,7 @@ void ASTPrettyPrinter::SpecifierVisitor::operator()(SignTypeSpecifierAST* ast) { } void ASTPrettyPrinter::SpecifierVisitor::operator()( - VaListTypeSpecifierAST* ast) { + BuiltinTypeSpecifierAST* ast) { if (ast->specifierLoc) { accept.writeToken(ast->specifierLoc); } diff --git a/src/parser/cxx/ast_printer.cc b/src/parser/cxx/ast_printer.cc index 89337e13..d641f9a6 100644 --- a/src/parser/cxx/ast_printer.cc +++ b/src/parser/cxx/ast_printer.cc @@ -996,15 +996,6 @@ void ASTPrinter::visit(TryBlockStatementAST* ast) { } } -void ASTPrinter::visit(GeneratedLiteralExpressionAST* ast) { - out_ << "generated-literal-expression"; - if (ast->type) { - out_ << std::format(" [{} {}]", to_string(ast->valueCategory), - to_string(ast->type)); - } - out_ << "\n"; -} - void ASTPrinter::visit(CharLiteralExpressionAST* ast) { out_ << "char-literal-expression"; if (ast->type) { @@ -2039,10 +2030,6 @@ void ASTPrinter::visit(ConstraintTypeParameterAST* ast) { accept(ast->typeId, "type-id"); } -void ASTPrinter::visit(GeneratedTypeSpecifierAST* ast) { - out_ << std::format("{}\n", "generated-type-specifier"); -} - void ASTPrinter::visit(TypedefSpecifierAST* ast) { out_ << std::format("{}\n", "typedef-specifier"); } @@ -2132,8 +2119,8 @@ void ASTPrinter::visit(SignTypeSpecifierAST* ast) { } } -void ASTPrinter::visit(VaListTypeSpecifierAST* ast) { - out_ << std::format("{}\n", "va-list-type-specifier"); +void ASTPrinter::visit(BuiltinTypeSpecifierAST* ast) { + out_ << std::format("{}\n", "builtin-type-specifier"); if (ast->specifier != TokenKind::T_EOF_SYMBOL) { ++indent_; out_ << std::format("{:{}}", "", indent_ * 2); diff --git a/src/parser/cxx/ast_printer.h b/src/parser/cxx/ast_printer.h index e1df2739..9d11c66b 100644 --- a/src/parser/cxx/ast_printer.h +++ b/src/parser/cxx/ast_printer.h @@ -122,7 +122,6 @@ class ASTPrinter : ASTVisitor { void visit(DeclarationStatementAST* ast) override; void visit(TryBlockStatementAST* ast) override; - void visit(GeneratedLiteralExpressionAST* ast) override; void visit(CharLiteralExpressionAST* ast) override; void visit(BoolLiteralExpressionAST* ast) override; void visit(IntLiteralExpressionAST* ast) override; @@ -197,7 +196,6 @@ class ASTPrinter : ASTVisitor { void visit(TypenameTypeParameterAST* ast) override; void visit(ConstraintTypeParameterAST* ast) override; - void visit(GeneratedTypeSpecifierAST* ast) override; void visit(TypedefSpecifierAST* ast) override; void visit(FriendSpecifierAST* ast) override; void visit(ConstevalSpecifierAST* ast) override; @@ -217,7 +215,7 @@ class ASTPrinter : ASTVisitor { void visit(VoidTypeSpecifierAST* ast) override; void visit(SizeTypeSpecifierAST* ast) override; void visit(SignTypeSpecifierAST* ast) override; - void visit(VaListTypeSpecifierAST* ast) override; + void visit(BuiltinTypeSpecifierAST* ast) override; void visit(IntegralTypeSpecifierAST* ast) override; void visit(FloatingPointTypeSpecifierAST* ast) override; void visit(ComplexTypeSpecifierAST* ast) override; diff --git a/src/parser/cxx/ast_rewriter_expressions.cc b/src/parser/cxx/ast_rewriter_expressions.cc index 375b9ccd..3fc51be1 100644 --- a/src/parser/cxx/ast_rewriter_expressions.cc +++ b/src/parser/cxx/ast_rewriter_expressions.cc @@ -45,9 +45,6 @@ struct ASTRewriter::ExpressionVisitor { [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - [[nodiscard]] auto operator()(GeneratedLiteralExpressionAST* ast) - -> ExpressionAST*; - [[nodiscard]] auto operator()(CharLiteralExpressionAST* ast) -> ExpressionAST*; @@ -314,18 +311,6 @@ auto ASTRewriter::lambdaSpecifier(LambdaSpecifierAST* ast) return copy; } -auto ASTRewriter::ExpressionVisitor::operator()( - GeneratedLiteralExpressionAST* ast) -> ExpressionAST* { - auto copy = make_node(arena()); - - copy->valueCategory = ast->valueCategory; - copy->type = ast->type; - copy->literalLoc = ast->literalLoc; - copy->value = ast->value; - - return copy; -} - auto ASTRewriter::ExpressionVisitor::operator()(CharLiteralExpressionAST* ast) -> ExpressionAST* { auto copy = make_node(arena()); @@ -973,7 +958,7 @@ auto ASTRewriter::ExpressionVisitor::operator()( copy->valueCategory = ast->valueCategory; copy->type = ast->type; - copy->caretLoc = ast->caretLoc; + copy->caretCaretLoc = ast->caretCaretLoc; copy->scopeLoc = ast->scopeLoc; return copy; @@ -985,7 +970,7 @@ auto ASTRewriter::ExpressionVisitor::operator()( copy->valueCategory = ast->valueCategory; copy->type = ast->type; - copy->caretLoc = ast->caretLoc; + copy->caretCaretLoc = ast->caretCaretLoc; copy->identifierLoc = ast->identifierLoc; copy->identifier = ast->identifier; copy->symbol = ast->symbol; @@ -999,7 +984,7 @@ auto ASTRewriter::ExpressionVisitor::operator()(TypeIdReflectExpressionAST* ast) copy->valueCategory = ast->valueCategory; copy->type = ast->type; - copy->caretLoc = ast->caretLoc; + copy->caretCaretLoc = ast->caretCaretLoc; copy->typeId = rewrite.typeId(ast->typeId); return copy; @@ -1011,7 +996,7 @@ auto ASTRewriter::ExpressionVisitor::operator()(ReflectExpressionAST* ast) copy->valueCategory = ast->valueCategory; copy->type = ast->type; - copy->caretLoc = ast->caretLoc; + copy->caretCaretLoc = ast->caretCaretLoc; copy->expression = rewrite.expression(ast->expression); return copy; diff --git a/src/parser/cxx/ast_rewriter_specifiers.cc b/src/parser/cxx/ast_rewriter_specifiers.cc index a13c982d..10f132b0 100644 --- a/src/parser/cxx/ast_rewriter_specifiers.cc +++ b/src/parser/cxx/ast_rewriter_specifiers.cc @@ -51,9 +51,6 @@ struct ASTRewriter::SpecifierVisitor { [[nodiscard]] auto rewriter() const -> ASTRewriter* { return &rewrite; } [[nodiscard]] auto binder() const -> Binder* { return &rewrite.binder_; } - [[nodiscard]] auto operator()(GeneratedTypeSpecifierAST* ast) - -> SpecifierAST*; - [[nodiscard]] auto operator()(TypedefSpecifierAST* ast) -> SpecifierAST*; [[nodiscard]] auto operator()(FriendSpecifierAST* ast) -> SpecifierAST*; @@ -92,7 +89,7 @@ struct ASTRewriter::SpecifierVisitor { [[nodiscard]] auto operator()(SignTypeSpecifierAST* ast) -> SpecifierAST*; - [[nodiscard]] auto operator()(VaListTypeSpecifierAST* ast) -> SpecifierAST*; + [[nodiscard]] auto operator()(BuiltinTypeSpecifierAST* ast) -> SpecifierAST*; [[nodiscard]] auto operator()(IntegralTypeSpecifierAST* ast) -> SpecifierAST*; @@ -331,16 +328,6 @@ auto ASTRewriter::splicer(SplicerAST* ast) -> SplicerAST* { return copy; } -auto ASTRewriter::SpecifierVisitor::operator()(GeneratedTypeSpecifierAST* ast) - -> SpecifierAST* { - auto copy = make_node(arena()); - - copy->typeLoc = ast->typeLoc; - copy->type = ast->type; - - return copy; -} - auto ASTRewriter::SpecifierVisitor::operator()(TypedefSpecifierAST* ast) -> SpecifierAST* { auto copy = make_node(arena()); @@ -517,9 +504,9 @@ auto ASTRewriter::SpecifierVisitor::operator()(SignTypeSpecifierAST* ast) return copy; } -auto ASTRewriter::SpecifierVisitor::operator()(VaListTypeSpecifierAST* ast) +auto ASTRewriter::SpecifierVisitor::operator()(BuiltinTypeSpecifierAST* ast) -> SpecifierAST* { - auto copy = make_node(arena()); + auto copy = make_node(arena()); copy->specifierLoc = ast->specifierLoc; copy->specifier = ast->specifier; diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index 21ecd250..d5600c2e 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -78,7 +78,7 @@ std::string_view kMemberSlotNames[] = { "captureDefault", "captureDefaultLoc", "captureList", - "caretLoc", + "caretCaretLoc", "caseLoc", "castLoc", "catchLoc", @@ -270,7 +270,6 @@ std::string_view kMemberSlotNames[] = { "typeConstraint", "typeId", "typeIdList", - "typeLoc", "typeQualifierList", "typeSpecifier", "typeSpecifierList", @@ -458,7 +457,7 @@ void ASTSlot::visit(NamespaceAliasDefinitionAST* ast) { case 4: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 5: // semicolonLoc value_ = ast->semicolonLoc.index(); @@ -480,12 +479,12 @@ void ASTSlot::visit(UsingDeclarationAST* ast) { case 0: // usingLoc value_ = ast->usingLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{231}; + slotNameIndex_ = SlotNameIndex{230}; break; case 1: // usingDeclaratorList value_ = reinterpret_cast(ast->usingDeclaratorList); slotKind_ = ASTSlotKind::kNodeList; - slotNameIndex_ = SlotNameIndex{230}; + slotNameIndex_ = SlotNameIndex{229}; break; case 2: // semicolonLoc value_ = ast->semicolonLoc.index(); @@ -502,7 +501,7 @@ void ASTSlot::visit(UsingEnumDeclarationAST* ast) { case 0: // usingLoc value_ = ast->usingLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{231}; + slotNameIndex_ = SlotNameIndex{230}; break; case 1: // enumTypeSpecifier value_ = reinterpret_cast(ast->enumTypeSpecifier); @@ -529,7 +528,7 @@ void ASTSlot::visit(UsingDirectiveAST* ast) { case 1: // usingLoc value_ = ast->usingLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{231}; + slotNameIndex_ = SlotNameIndex{230}; break; case 2: // namespaceLoc value_ = ast->namespaceLoc.index(); @@ -544,7 +543,7 @@ void ASTSlot::visit(UsingDirectiveAST* ast) { case 4: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 5: // semicolonLoc value_ = ast->semicolonLoc.index(); @@ -608,7 +607,7 @@ void ASTSlot::visit(AliasDeclarationAST* ast) { case 0: // usingLoc value_ = ast->usingLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{231}; + slotNameIndex_ = SlotNameIndex{230}; break; case 1: // identifierLoc value_ = ast->identifierLoc.index(); @@ -675,7 +674,7 @@ void ASTSlot::visit(OpaqueEnumDeclarationAST* ast) { case 4: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 5: // colonLoc value_ = ast->colonLoc.index(); @@ -685,7 +684,7 @@ void ASTSlot::visit(OpaqueEnumDeclarationAST* ast) { case 6: // typeSpecifierList value_ = reinterpret_cast(ast->typeSpecifierList); slotKind_ = ASTSlotKind::kNodeList; - slotNameIndex_ = SlotNameIndex{223}; + slotNameIndex_ = SlotNameIndex{222}; break; case 7: // emicolonLoc value_ = ast->emicolonLoc.index(); @@ -1097,7 +1096,7 @@ void ASTSlot::visit(ParameterDeclarationAST* ast) { case 2: // typeSpecifierList value_ = reinterpret_cast(ast->typeSpecifierList); slotKind_ = ASTSlotKind::kNodeList; - slotNameIndex_ = SlotNameIndex{223}; + slotNameIndex_ = SlotNameIndex{222}; break; case 3: // declarator value_ = reinterpret_cast(ast->declarator); @@ -1573,7 +1572,7 @@ void ASTSlot::visit(UsingDeclaratorAST* ast) { case 0: // typenameLoc value_ = ast->typenameLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{227}; + slotNameIndex_ = SlotNameIndex{226}; break; case 1: // nestedNameSpecifier value_ = reinterpret_cast(ast->nestedNameSpecifier); @@ -1583,7 +1582,7 @@ void ASTSlot::visit(UsingDeclaratorAST* ast) { case 2: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 3: // ellipsisLoc value_ = ast->ellipsisLoc.index(); @@ -1637,7 +1636,7 @@ void ASTSlot::visit(TypeIdAST* ast) { case 0: // typeSpecifierList value_ = reinterpret_cast(ast->typeSpecifierList); slotKind_ = ASTSlotKind::kNodeList; - slotNameIndex_ = SlotNameIndex{223}; + slotNameIndex_ = SlotNameIndex{222}; break; case 1: // declarator value_ = reinterpret_cast(ast->declarator); @@ -1691,7 +1690,7 @@ void ASTSlot::visit(BaseSpecifierAST* ast) { case 1: // virtualOrAccessLoc value_ = ast->virtualOrAccessLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{234}; + slotNameIndex_ = SlotNameIndex{233}; break; case 2: // otherVirtualOrAccessLoc value_ = ast->otherVirtualOrAccessLoc.index(); @@ -1711,7 +1710,7 @@ void ASTSlot::visit(BaseSpecifierAST* ast) { case 5: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 6: // ellipsisLoc value_ = ast->ellipsisLoc.index(); @@ -1902,7 +1901,7 @@ void ASTSlot::visit(AttributeUsingPrefixAST* ast) { case 0: // usingLoc value_ = ast->usingLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{231}; + slotNameIndex_ = SlotNameIndex{230}; break; case 1: // attributeNamespaceLoc value_ = ast->attributeNamespaceLoc.index(); @@ -2209,7 +2208,7 @@ void ASTSlot::visit(WhileStatementAST* ast) { case 0: // whileLoc value_ = ast->whileLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{237}; + slotNameIndex_ = SlotNameIndex{236}; break; case 1: // lparenLoc value_ = ast->lparenLoc.index(); @@ -2251,7 +2250,7 @@ void ASTSlot::visit(DoStatementAST* ast) { case 2: // whileLoc value_ = ast->whileLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{237}; + slotNameIndex_ = SlotNameIndex{236}; break; case 3: // lparenLoc value_ = ast->lparenLoc.index(); @@ -2521,18 +2520,6 @@ void ASTSlot::visit(TryBlockStatementAST* ast) { slotCount_ = 3; } -void ASTSlot::visit(GeneratedLiteralExpressionAST* ast) { - switch (slot_) { - case 0: // literalLoc - value_ = ast->literalLoc.index(); - slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{133}; - break; - } // switch - - slotCount_ = 1; -} - void ASTSlot::visit(CharLiteralExpressionAST* ast) { switch (slot_) { case 0: // literalLoc @@ -2792,7 +2779,7 @@ void ASTSlot::visit(IdExpressionAST* ast) { case 2: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 3: // isTemplateIntroduced value_ = std::intptr_t(ast->isTemplateIntroduced != 0); @@ -3079,7 +3066,7 @@ void ASTSlot::visit(VaArgExpressionAST* ast) { case 0: // vaArgLoc value_ = ast->vaArgLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{232}; + slotNameIndex_ = SlotNameIndex{231}; break; case 1: // lparenLoc value_ = ast->lparenLoc.index(); @@ -3170,7 +3157,7 @@ void ASTSlot::visit(TypeConstructionAST* ast) { case 0: // typeSpecifier value_ = reinterpret_cast(ast->typeSpecifier); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{222}; + slotNameIndex_ = SlotNameIndex{221}; break; case 1: // lparenLoc value_ = ast->lparenLoc.index(); @@ -3197,7 +3184,7 @@ void ASTSlot::visit(BracedTypeConstructionAST* ast) { case 0: // typeSpecifier value_ = reinterpret_cast(ast->typeSpecifier); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{222}; + slotNameIndex_ = SlotNameIndex{221}; break; case 1: // bracedInitList value_ = reinterpret_cast(ast->bracedInitList); @@ -3271,7 +3258,7 @@ void ASTSlot::visit(MemberExpressionAST* ast) { case 4: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 5: // accessOp value_ = std::intptr_t(ast->accessOp); @@ -3441,7 +3428,7 @@ void ASTSlot::visit(TypeidExpressionAST* ast) { case 0: // typeidLoc value_ = ast->typeidLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{226}; + slotNameIndex_ = SlotNameIndex{225}; break; case 1: // lparenLoc value_ = ast->lparenLoc.index(); @@ -3468,7 +3455,7 @@ void ASTSlot::visit(TypeidOfTypeExpressionAST* ast) { case 0: // typeidLoc value_ = ast->typeidLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{226}; + slotNameIndex_ = SlotNameIndex{225}; break; case 1: // lparenLoc value_ = ast->lparenLoc.index(); @@ -3504,8 +3491,8 @@ void ASTSlot::visit(SpliceExpressionAST* ast) { void ASTSlot::visit(GlobalScopeReflectExpressionAST* ast) { switch (slot_) { - case 0: // caretLoc - value_ = ast->caretLoc.index(); + case 0: // caretCaretLoc + value_ = ast->caretCaretLoc.index(); slotKind_ = ASTSlotKind::kToken; slotNameIndex_ = SlotNameIndex{28}; break; @@ -3521,8 +3508,8 @@ void ASTSlot::visit(GlobalScopeReflectExpressionAST* ast) { void ASTSlot::visit(NamespaceReflectExpressionAST* ast) { switch (slot_) { - case 0: // caretLoc - value_ = ast->caretLoc.index(); + case 0: // caretCaretLoc + value_ = ast->caretCaretLoc.index(); slotKind_ = ASTSlotKind::kToken; slotNameIndex_ = SlotNameIndex{28}; break; @@ -3543,8 +3530,8 @@ void ASTSlot::visit(NamespaceReflectExpressionAST* ast) { void ASTSlot::visit(TypeIdReflectExpressionAST* ast) { switch (slot_) { - case 0: // caretLoc - value_ = ast->caretLoc.index(); + case 0: // caretCaretLoc + value_ = ast->caretCaretLoc.index(); slotKind_ = ASTSlotKind::kToken; slotNameIndex_ = SlotNameIndex{28}; break; @@ -3560,8 +3547,8 @@ void ASTSlot::visit(TypeIdReflectExpressionAST* ast) { void ASTSlot::visit(ReflectExpressionAST* ast) { switch (slot_) { - case 0: // caretLoc - value_ = ast->caretLoc.index(); + case 0: // caretCaretLoc + value_ = ast->caretCaretLoc.index(); slotKind_ = ASTSlotKind::kToken; slotNameIndex_ = SlotNameIndex{28}; break; @@ -3813,7 +3800,7 @@ void ASTSlot::visit(NewExpressionAST* ast) { case 4: // typeSpecifierList value_ = reinterpret_cast(ast->typeSpecifierList); slotKind_ = ASTSlotKind::kNodeList; - slotNameIndex_ = SlotNameIndex{223}; + slotNameIndex_ = SlotNameIndex{222}; break; case 5: // declarator value_ = reinterpret_cast(ast->declarator); @@ -3970,7 +3957,7 @@ void ASTSlot::visit(YieldExpressionAST* ast) { case 0: // yieldLoc value_ = ast->yieldLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{238}; + slotNameIndex_ = SlotNameIndex{237}; break; case 1: // expression value_ = reinterpret_cast(ast->expression); @@ -4092,7 +4079,7 @@ void ASTSlot::visit(TypeTraitExpressionAST* ast) { case 0: // typeTraitLoc value_ = ast->typeTraitLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{224}; + slotNameIndex_ = SlotNameIndex{223}; break; case 1: // lparenLoc value_ = ast->lparenLoc.index(); @@ -4453,24 +4440,12 @@ void ASTSlot::visit(ConstraintTypeParameterAST* ast) { slotCount_ = 6; } -void ASTSlot::visit(GeneratedTypeSpecifierAST* ast) { - switch (slot_) { - case 0: // typeLoc - value_ = ast->typeLoc.index(); - slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{220}; - break; - } // switch - - slotCount_ = 1; -} - void ASTSlot::visit(TypedefSpecifierAST* ast) { switch (slot_) { case 0: // typedefLoc value_ = ast->typedefLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{225}; + slotNameIndex_ = SlotNameIndex{224}; break; } // switch @@ -4626,7 +4601,7 @@ void ASTSlot::visit(VirtualSpecifierAST* ast) { case 0: // virtualLoc value_ = ast->virtualLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{233}; + slotNameIndex_ = SlotNameIndex{232}; break; } // switch @@ -4677,7 +4652,7 @@ void ASTSlot::visit(VoidTypeSpecifierAST* ast) { case 0: // voidLoc value_ = ast->voidLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{235}; + slotNameIndex_ = SlotNameIndex{234}; break; } // switch @@ -4718,7 +4693,7 @@ void ASTSlot::visit(SignTypeSpecifierAST* ast) { slotCount_ = 2; } -void ASTSlot::visit(VaListTypeSpecifierAST* ast) { +void ASTSlot::visit(BuiltinTypeSpecifierAST* ast) { switch (slot_) { case 0: // specifierLoc value_ = ast->specifierLoc.index(); @@ -4796,7 +4771,7 @@ void ASTSlot::visit(NamedTypeSpecifierAST* ast) { case 2: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 3: // isTemplateIntroduced value_ = std::intptr_t(ast->isTemplateIntroduced != 0); @@ -4840,7 +4815,7 @@ void ASTSlot::visit(UnderlyingTypeSpecifierAST* ast) { case 0: // underlyingTypeLoc value_ = ast->underlyingTypeLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{228}; + slotNameIndex_ = SlotNameIndex{227}; break; case 1: // lparenLoc value_ = ast->lparenLoc.index(); @@ -4887,7 +4862,7 @@ void ASTSlot::visit(ElaboratedTypeSpecifierAST* ast) { case 4: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 5: // classKey value_ = std::intptr_t(ast->classKey); @@ -4992,7 +4967,7 @@ void ASTSlot::visit(VolatileQualifierAST* ast) { case 0: // volatileLoc value_ = ast->volatileLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{236}; + slotNameIndex_ = SlotNameIndex{235}; break; } // switch @@ -5048,7 +5023,7 @@ void ASTSlot::visit(EnumSpecifierAST* ast) { case 4: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 5: // colonLoc value_ = ast->colonLoc.index(); @@ -5058,7 +5033,7 @@ void ASTSlot::visit(EnumSpecifierAST* ast) { case 6: // typeSpecifierList value_ = reinterpret_cast(ast->typeSpecifierList); slotKind_ = ASTSlotKind::kNodeList; - slotNameIndex_ = SlotNameIndex{223}; + slotNameIndex_ = SlotNameIndex{222}; break; case 7: // lbraceLoc value_ = ast->lbraceLoc.index(); @@ -5105,7 +5080,7 @@ void ASTSlot::visit(ClassSpecifierAST* ast) { case 3: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 4: // finalLoc value_ = ast->finalLoc.index(); @@ -5157,7 +5132,7 @@ void ASTSlot::visit(TypenameSpecifierAST* ast) { case 0: // typenameLoc value_ = ast->typenameLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{227}; + slotNameIndex_ = SlotNameIndex{226}; break; case 1: // nestedNameSpecifier value_ = reinterpret_cast(ast->nestedNameSpecifier); @@ -5172,7 +5147,7 @@ void ASTSlot::visit(TypenameSpecifierAST* ast) { case 3: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 4: // isTemplateIntroduced value_ = std::intptr_t(ast->isTemplateIntroduced != 0); @@ -5189,7 +5164,7 @@ void ASTSlot::visit(SplicerTypeSpecifierAST* ast) { case 0: // typenameLoc value_ = ast->typenameLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{227}; + slotNameIndex_ = SlotNameIndex{226}; break; case 1: // splicer value_ = reinterpret_cast(ast->splicer); @@ -5277,7 +5252,7 @@ void ASTSlot::visit(BitfieldDeclaratorAST* ast) { case 0: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 1: // colonLoc value_ = ast->colonLoc.index(); @@ -5326,7 +5301,7 @@ void ASTSlot::visit(IdDeclaratorAST* ast) { case 2: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 3: // attributeList value_ = reinterpret_cast(ast->attributeList); @@ -5437,7 +5412,7 @@ void ASTSlot::visit(ArrayDeclaratorChunkAST* ast) { case 1: // typeQualifierList value_ = reinterpret_cast(ast->typeQualifierList); slotKind_ = ASTSlotKind::kNodeList; - slotNameIndex_ = SlotNameIndex{221}; + slotNameIndex_ = SlotNameIndex{220}; break; case 2: // expression value_ = reinterpret_cast(ast->expression); @@ -5995,7 +5970,7 @@ void ASTSlot::visit(TypeRequirementAST* ast) { case 0: // typenameLoc value_ = ast->typenameLoc.index(); slotKind_ = ASTSlotKind::kToken; - slotNameIndex_ = SlotNameIndex{227}; + slotNameIndex_ = SlotNameIndex{226}; break; case 1: // nestedNameSpecifier value_ = reinterpret_cast(ast->nestedNameSpecifier); @@ -6010,7 +5985,7 @@ void ASTSlot::visit(TypeRequirementAST* ast) { case 3: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 4: // semicolonLoc value_ = ast->semicolonLoc.index(); @@ -6093,7 +6068,7 @@ void ASTSlot::visit(ParenMemInitializerAST* ast) { case 1: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 2: // lparenLoc value_ = ast->lparenLoc.index(); @@ -6130,7 +6105,7 @@ void ASTSlot::visit(BracedMemInitializerAST* ast) { case 1: // unqualifiedId value_ = reinterpret_cast(ast->unqualifiedId); slotKind_ = ASTSlotKind::kNode; - slotNameIndex_ = SlotNameIndex{229}; + slotNameIndex_ = SlotNameIndex{228}; break; case 2: // bracedInitList value_ = reinterpret_cast(ast->bracedInitList); @@ -6306,7 +6281,7 @@ void ASTSlot::visit(TypeExceptionDeclarationAST* ast) { case 1: // typeSpecifierList value_ = reinterpret_cast(ast->typeSpecifierList); slotKind_ = ASTSlotKind::kNodeList; - slotNameIndex_ = SlotNameIndex{223}; + slotNameIndex_ = SlotNameIndex{222}; break; case 2: // declarator value_ = reinterpret_cast(ast->declarator); diff --git a/src/parser/cxx/ast_slot.h b/src/parser/cxx/ast_slot.h index da31d9d1..2bbf20c0 100644 --- a/src/parser/cxx/ast_slot.h +++ b/src/parser/cxx/ast_slot.h @@ -133,7 +133,6 @@ class ASTSlot final : ASTVisitor { void visit(DeclarationStatementAST* ast) override; void visit(TryBlockStatementAST* ast) override; - void visit(GeneratedLiteralExpressionAST* ast) override; void visit(CharLiteralExpressionAST* ast) override; void visit(BoolLiteralExpressionAST* ast) override; void visit(IntLiteralExpressionAST* ast) override; @@ -208,7 +207,6 @@ class ASTSlot final : ASTVisitor { void visit(TypenameTypeParameterAST* ast) override; void visit(ConstraintTypeParameterAST* ast) override; - void visit(GeneratedTypeSpecifierAST* ast) override; void visit(TypedefSpecifierAST* ast) override; void visit(FriendSpecifierAST* ast) override; void visit(ConstevalSpecifierAST* ast) override; @@ -228,7 +226,7 @@ class ASTSlot final : ASTVisitor { void visit(VoidTypeSpecifierAST* ast) override; void visit(SizeTypeSpecifierAST* ast) override; void visit(SignTypeSpecifierAST* ast) override; - void visit(VaListTypeSpecifierAST* ast) override; + void visit(BuiltinTypeSpecifierAST* ast) override; void visit(IntegralTypeSpecifierAST* ast) override; void visit(FloatingPointTypeSpecifierAST* ast) override; void visit(ComplexTypeSpecifierAST* ast) override; diff --git a/src/parser/cxx/ast_visitor.cc b/src/parser/cxx/ast_visitor.cc index b2959c22..63a8f48a 100644 --- a/src/parser/cxx/ast_visitor.cc +++ b/src/parser/cxx/ast_visitor.cc @@ -443,8 +443,6 @@ void ASTVisitor::visit(TryBlockStatementAST* ast) { } } -void ASTVisitor::visit(GeneratedLiteralExpressionAST* ast) {} - void ASTVisitor::visit(CharLiteralExpressionAST* ast) {} void ASTVisitor::visit(BoolLiteralExpressionAST* ast) {} @@ -736,8 +734,6 @@ void ASTVisitor::visit(ConstraintTypeParameterAST* ast) { accept(ast->typeId); } -void ASTVisitor::visit(GeneratedTypeSpecifierAST* ast) {} - void ASTVisitor::visit(TypedefSpecifierAST* ast) {} void ASTVisitor::visit(FriendSpecifierAST* ast) {} @@ -776,7 +772,7 @@ void ASTVisitor::visit(SizeTypeSpecifierAST* ast) {} void ASTVisitor::visit(SignTypeSpecifierAST* ast) {} -void ASTVisitor::visit(VaListTypeSpecifierAST* ast) {} +void ASTVisitor::visit(BuiltinTypeSpecifierAST* ast) {} void ASTVisitor::visit(IntegralTypeSpecifierAST* ast) {} diff --git a/src/parser/cxx/ast_visitor.h b/src/parser/cxx/ast_visitor.h index 5ba0d994..3a1440ea 100644 --- a/src/parser/cxx/ast_visitor.h +++ b/src/parser/cxx/ast_visitor.h @@ -118,7 +118,6 @@ class ASTVisitor { virtual void visit(TryBlockStatementAST* ast); // ExpressionAST - virtual void visit(GeneratedLiteralExpressionAST* ast); virtual void visit(CharLiteralExpressionAST* ast); virtual void visit(BoolLiteralExpressionAST* ast); virtual void visit(IntLiteralExpressionAST* ast); @@ -197,7 +196,6 @@ class ASTVisitor { virtual void visit(ConstraintTypeParameterAST* ast); // SpecifierAST - virtual void visit(GeneratedTypeSpecifierAST* ast); virtual void visit(TypedefSpecifierAST* ast); virtual void visit(FriendSpecifierAST* ast); virtual void visit(ConstevalSpecifierAST* ast); @@ -217,7 +215,7 @@ class ASTVisitor { virtual void visit(VoidTypeSpecifierAST* ast); virtual void visit(SizeTypeSpecifierAST* ast); virtual void visit(SignTypeSpecifierAST* ast); - virtual void visit(VaListTypeSpecifierAST* ast); + virtual void visit(BuiltinTypeSpecifierAST* ast); virtual void visit(IntegralTypeSpecifierAST* ast); virtual void visit(FloatingPointTypeSpecifierAST* ast); virtual void visit(ComplexTypeSpecifierAST* ast); diff --git a/src/parser/cxx/const_value.h b/src/parser/cxx/const_value.h index 77e69ae6..683a68eb 100644 --- a/src/parser/cxx/const_value.h +++ b/src/parser/cxx/const_value.h @@ -20,15 +20,31 @@ #pragma once +#include #include #include +#include +#include #include +#include #include namespace cxx { +class Meta; + using ConstValue = std::variant; + double, long double, std::shared_ptr>; + +class Meta { + public: + struct ConstExpr { + ExpressionAST* expression = nullptr; + ConstValue value; + }; + + std::variant value; +}; } // namespace cxx \ No newline at end of file diff --git a/src/parser/cxx/control.cc b/src/parser/cxx/control.cc index 91c04669..521935c0 100644 --- a/src/parser/cxx/control.cc +++ b/src/parser/cxx/control.cc @@ -79,6 +79,7 @@ struct Control::Private { std::unordered_set templateIds; BuiltinVaListType builtinVaListType; + BuiltinMetaInfoType builtinMetaInfoType; VoidType voidType; NullptrType nullptrType; DecltypeAutoType decltypeAutoType; @@ -275,6 +276,10 @@ auto Control::getBuiltinVaListType() -> const BuiltinVaListType* { return &d->builtinVaListType; } +auto Control::getBuiltinMetaInfoType() -> const BuiltinMetaInfoType* { + return &d->builtinMetaInfoType; +} + auto Control::getVoidType() -> const VoidType* { return &d->voidType; } auto Control::getNullptrType() -> const NullptrType* { return &d->nullptrType; } diff --git a/src/parser/cxx/control.h b/src/parser/cxx/control.h index 2e2cf5f7..24290131 100644 --- a/src/parser/cxx/control.h +++ b/src/parser/cxx/control.h @@ -78,6 +78,7 @@ class Control { [[nodiscard]] auto getSizeType() -> const Type*; [[nodiscard]] auto getBuiltinVaListType() -> const BuiltinVaListType*; + [[nodiscard]] auto getBuiltinMetaInfoType() -> const BuiltinMetaInfoType*; [[nodiscard]] auto getVoidType() -> const VoidType*; [[nodiscard]] auto getNullptrType() -> const NullptrType*; [[nodiscard]] auto getDecltypeAutoType() -> const DecltypeAutoType*; diff --git a/src/parser/cxx/decl_specs.cc b/src/parser/cxx/decl_specs.cc index b91e48d5..51b64594 100644 --- a/src/parser/cxx/decl_specs.cc +++ b/src/parser/cxx/decl_specs.cc @@ -22,6 +22,7 @@ // cxx #include +#include #include #include #include @@ -35,7 +36,6 @@ struct DeclSpecs::Visitor { [[nodiscard]] auto control() const -> Control* { return specs.control(); } - void operator()(GeneratedTypeSpecifierAST* ast); void operator()(TypedefSpecifierAST* ast); void operator()(FriendSpecifierAST* ast); void operator()(ConstevalSpecifierAST* ast); @@ -55,7 +55,7 @@ struct DeclSpecs::Visitor { void operator()(VoidTypeSpecifierAST* ast); void operator()(SizeTypeSpecifierAST* ast); void operator()(SignTypeSpecifierAST* ast); - void operator()(VaListTypeSpecifierAST* ast); + void operator()(BuiltinTypeSpecifierAST* ast); void operator()(IntegralTypeSpecifierAST* ast); void operator()(FloatingPointTypeSpecifierAST* ast); void operator()(ComplexTypeSpecifierAST* ast); @@ -76,8 +76,6 @@ struct DeclSpecs::Visitor { void operator()(SplicerTypeSpecifierAST* ast); }; -void DeclSpecs::Visitor::operator()(GeneratedTypeSpecifierAST* ast) {} - void DeclSpecs::Visitor::operator()(TypedefSpecifierAST* ast) { specs.isTypedef = true; } @@ -182,9 +180,21 @@ void DeclSpecs::Visitor::operator()(SignTypeSpecifierAST* ast) { } // switch } -void DeclSpecs::Visitor::operator()(VaListTypeSpecifierAST* ast) { +void DeclSpecs::Visitor::operator()(BuiltinTypeSpecifierAST* ast) { specs.typeSpecifier_ = ast; - specs.type_ = control()->getBuiltinVaListType(); + + switch (ast->specifier) { + case TokenKind::T___BUILTIN_VA_LIST: + specs.type_ = control()->getBuiltinVaListType(); + break; + + case TokenKind::T___BUILTIN_META_INFO: + specs.type_ = control()->getBuiltinMetaInfoType(); + break; + + default: + break; + } // switch } void DeclSpecs::Visitor::operator()(IntegralTypeSpecifierAST* ast) { @@ -356,7 +366,20 @@ void DeclSpecs::Visitor::operator()(TypenameSpecifierAST* ast) { void DeclSpecs::Visitor::operator()(SplicerTypeSpecifierAST* ast) { specs.typeSpecifier_ = ast; - // ### todo + + auto interp = ASTInterpreter{specs.unit_}; + auto value = interp.evaluate(ast->splicer->expression); + if (!value.has_value()) return; + + auto metaPtr = std::get_if>(&*value); + if (!metaPtr) return; + + auto meta = *metaPtr; + + auto typePtr = std::get_if(&meta->value); + if (!typePtr) return; + + specs.type_ = *typePtr; } DeclSpecs::DeclSpecs(TranslationUnit* unit) : unit_(unit) {} diff --git a/src/parser/cxx/external_name_encoder.cc b/src/parser/cxx/external_name_encoder.cc index a0c3ecab..cddcb678 100644 --- a/src/parser/cxx/external_name_encoder.cc +++ b/src/parser/cxx/external_name_encoder.cc @@ -323,6 +323,11 @@ struct ExternalNameEncoder::EncodeType { encoder.out("Pc"); return true; } + + auto operator()(const BuiltinMetaInfoType* type) -> bool { + cxx_runtime_error(std::format("todo encode type '{}'", to_string(type))); + return true; + } }; struct ExternalNameEncoder::EncodeUnqualifiedName { diff --git a/src/parser/cxx/flatbuffers/ast_decoder.cc b/src/parser/cxx/flatbuffers/ast_decoder.cc index 9fb6a422..cce7b031 100644 --- a/src/parser/cxx/flatbuffers/ast_decoder.cc +++ b/src/parser/cxx/flatbuffers/ast_decoder.cc @@ -208,9 +208,6 @@ auto ASTDecoder::decodeStatement(const void* ptr, io::Statement type) auto ASTDecoder::decodeExpression(const void* ptr, io::Expression type) -> ExpressionAST* { switch (type) { - case io::Expression_GeneratedLiteralExpression: - return decodeGeneratedLiteralExpression( - reinterpret_cast(ptr)); case io::Expression_CharLiteralExpression: return decodeCharLiteralExpression( reinterpret_cast(ptr)); @@ -454,9 +451,6 @@ auto ASTDecoder::decodeTemplateParameter(const void* ptr, auto ASTDecoder::decodeSpecifier(const void* ptr, io::Specifier type) -> SpecifierAST* { switch (type) { - case io::Specifier_GeneratedTypeSpecifier: - return decodeGeneratedTypeSpecifier( - reinterpret_cast(ptr)); case io::Specifier_TypedefSpecifier: return decodeTypedefSpecifier( reinterpret_cast(ptr)); @@ -514,9 +508,9 @@ auto ASTDecoder::decodeSpecifier(const void* ptr, io::Specifier type) case io::Specifier_SignTypeSpecifier: return decodeSignTypeSpecifier( reinterpret_cast(ptr)); - case io::Specifier_VaListTypeSpecifier: - return decodeVaListTypeSpecifier( - reinterpret_cast(ptr)); + case io::Specifier_BuiltinTypeSpecifier: + return decodeBuiltinTypeSpecifier( + reinterpret_cast(ptr)); case io::Specifier_IntegralTypeSpecifier: return decodeIntegralTypeSpecifier( reinterpret_cast(ptr)); @@ -2233,16 +2227,6 @@ auto ASTDecoder::decodeTryBlockStatement(const io::TryBlockStatement* node) return ast; } -auto ASTDecoder::decodeGeneratedLiteralExpression( - const io::GeneratedLiteralExpression* node) - -> GeneratedLiteralExpressionAST* { - if (!node) return nullptr; - - auto ast = new (pool_) GeneratedLiteralExpressionAST(); - ast->literalLoc = SourceLocation(node->literal_loc()); - return ast; -} - auto ASTDecoder::decodeCharLiteralExpression( const io::CharLiteralExpression* node) -> CharLiteralExpressionAST* { if (!node) return nullptr; @@ -2775,7 +2759,7 @@ auto ASTDecoder::decodeGlobalScopeReflectExpression( if (!node) return nullptr; auto ast = new (pool_) GlobalScopeReflectExpressionAST(); - ast->caretLoc = SourceLocation(node->caret_loc()); + ast->caretCaretLoc = SourceLocation(node->caret_caret_loc()); ast->scopeLoc = SourceLocation(node->scope_loc()); return ast; } @@ -2786,7 +2770,7 @@ auto ASTDecoder::decodeNamespaceReflectExpression( if (!node) return nullptr; auto ast = new (pool_) NamespaceReflectExpressionAST(); - ast->caretLoc = SourceLocation(node->caret_loc()); + ast->caretCaretLoc = SourceLocation(node->caret_caret_loc()); ast->identifierLoc = SourceLocation(node->identifier_loc()); if (node->identifier()) { ast->identifier = @@ -2800,7 +2784,7 @@ auto ASTDecoder::decodeTypeIdReflectExpression( if (!node) return nullptr; auto ast = new (pool_) TypeIdReflectExpressionAST(); - ast->caretLoc = SourceLocation(node->caret_loc()); + ast->caretCaretLoc = SourceLocation(node->caret_caret_loc()); ast->typeId = decodeTypeId(node->type_id()); return ast; } @@ -2810,7 +2794,7 @@ auto ASTDecoder::decodeReflectExpression(const io::ReflectExpression* node) if (!node) return nullptr; auto ast = new (pool_) ReflectExpressionAST(); - ast->caretLoc = SourceLocation(node->caret_loc()); + ast->caretCaretLoc = SourceLocation(node->caret_caret_loc()); ast->expression = decodeExpression(node->expression(), node->expression_type()); return ast; @@ -3324,15 +3308,6 @@ auto ASTDecoder::decodeConstraintTypeParameter( return ast; } -auto ASTDecoder::decodeGeneratedTypeSpecifier( - const io::GeneratedTypeSpecifier* node) -> GeneratedTypeSpecifierAST* { - if (!node) return nullptr; - - auto ast = new (pool_) GeneratedTypeSpecifierAST(); - ast->typeLoc = SourceLocation(node->type_loc()); - return ast; -} - auto ASTDecoder::decodeTypedefSpecifier(const io::TypedefSpecifier* node) -> TypedefSpecifierAST* { if (!node) return nullptr; @@ -3510,11 +3485,11 @@ auto ASTDecoder::decodeSignTypeSpecifier(const io::SignTypeSpecifier* node) return ast; } -auto ASTDecoder::decodeVaListTypeSpecifier(const io::VaListTypeSpecifier* node) - -> VaListTypeSpecifierAST* { +auto ASTDecoder::decodeBuiltinTypeSpecifier( + const io::BuiltinTypeSpecifier* node) -> BuiltinTypeSpecifierAST* { if (!node) return nullptr; - auto ast = new (pool_) VaListTypeSpecifierAST(); + auto ast = new (pool_) BuiltinTypeSpecifierAST(); ast->specifierLoc = SourceLocation(node->specifier_loc()); ast->specifier = static_cast(node->specifier()); return ast; diff --git a/src/parser/cxx/flatbuffers/ast_encoder.cc b/src/parser/cxx/flatbuffers/ast_encoder.cc index 692b8bad..c831b82a 100644 --- a/src/parser/cxx/flatbuffers/ast_encoder.cc +++ b/src/parser/cxx/flatbuffers/ast_encoder.cc @@ -2305,14 +2305,6 @@ void ASTEncoder::visit(TryBlockStatementAST* ast) { type_ = io::Statement_TryBlockStatement; } -void ASTEncoder::visit(GeneratedLiteralExpressionAST* ast) { - io::GeneratedLiteralExpression::Builder builder{fbb_}; - builder.add_literal_loc(ast->literalLoc.index()); - - offset_ = builder.Finish().Union(); - type_ = io::Expression_GeneratedLiteralExpression; -} - void ASTEncoder::visit(CharLiteralExpressionAST* ast) { flatbuffers::Offset literal; if (ast->literal) { @@ -3034,7 +3026,7 @@ void ASTEncoder::visit(SpliceExpressionAST* ast) { void ASTEncoder::visit(GlobalScopeReflectExpressionAST* ast) { io::GlobalScopeReflectExpression::Builder builder{fbb_}; - builder.add_caret_loc(ast->caretLoc.index()); + builder.add_caret_caret_loc(ast->caretCaretLoc.index()); builder.add_scope_loc(ast->scopeLoc.index()); offset_ = builder.Finish().Union(); @@ -3053,7 +3045,7 @@ void ASTEncoder::visit(NamespaceReflectExpressionAST* ast) { } io::NamespaceReflectExpression::Builder builder{fbb_}; - builder.add_caret_loc(ast->caretLoc.index()); + builder.add_caret_caret_loc(ast->caretCaretLoc.index()); builder.add_identifier_loc(ast->identifierLoc.index()); if (ast->identifier) { builder.add_identifier(identifier); @@ -3067,7 +3059,7 @@ void ASTEncoder::visit(TypeIdReflectExpressionAST* ast) { const auto typeId = accept(ast->typeId); io::TypeIdReflectExpression::Builder builder{fbb_}; - builder.add_caret_loc(ast->caretLoc.index()); + builder.add_caret_caret_loc(ast->caretCaretLoc.index()); builder.add_type_id(typeId.o); offset_ = builder.Finish().Union(); @@ -3078,7 +3070,7 @@ void ASTEncoder::visit(ReflectExpressionAST* ast) { const auto [expression, expressionType] = acceptExpression(ast->expression); io::ReflectExpression::Builder builder{fbb_}; - builder.add_caret_loc(ast->caretLoc.index()); + builder.add_caret_caret_loc(ast->caretCaretLoc.index()); builder.add_expression(expression); builder.add_expression_type(static_cast(expressionType)); @@ -3761,14 +3753,6 @@ void ASTEncoder::visit(ConstraintTypeParameterAST* ast) { type_ = io::TemplateParameter_ConstraintTypeParameter; } -void ASTEncoder::visit(GeneratedTypeSpecifierAST* ast) { - io::GeneratedTypeSpecifier::Builder builder{fbb_}; - builder.add_type_loc(ast->typeLoc.index()); - - offset_ = builder.Finish().Union(); - type_ = io::Specifier_GeneratedTypeSpecifier; -} - void ASTEncoder::visit(TypedefSpecifierAST* ast) { io::TypedefSpecifier::Builder builder{fbb_}; builder.add_typedef_loc(ast->typedefLoc.index()); @@ -3929,13 +3913,13 @@ void ASTEncoder::visit(SignTypeSpecifierAST* ast) { type_ = io::Specifier_SignTypeSpecifier; } -void ASTEncoder::visit(VaListTypeSpecifierAST* ast) { - io::VaListTypeSpecifier::Builder builder{fbb_}; +void ASTEncoder::visit(BuiltinTypeSpecifierAST* ast) { + io::BuiltinTypeSpecifier::Builder builder{fbb_}; builder.add_specifier_loc(ast->specifierLoc.index()); builder.add_specifier(static_cast(ast->specifier)); offset_ = builder.Finish().Union(); - type_ = io::Specifier_VaListTypeSpecifier; + type_ = io::Specifier_BuiltinTypeSpecifier; } void ASTEncoder::visit(IntegralTypeSpecifierAST* ast) { diff --git a/src/parser/cxx/lexer.cc b/src/parser/cxx/lexer.cc index 2388c4af..f09d9b2b 100644 --- a/src/parser/cxx/lexer.cc +++ b/src/parser/cxx/lexer.cc @@ -397,6 +397,9 @@ auto Lexer::readToken() -> TokenKind { if (pos_ != end_ && LA() == '=') { consume(); return TokenKind::T_CARET_EQUAL; + } else if (pos_ != end_ && LA() == '^') { + consume(); + return TokenKind::T_CARET_CARET; } return TokenKind::T_CARET; diff --git a/src/parser/cxx/memory_layout.cc b/src/parser/cxx/memory_layout.cc index 6f32854e..3c090a1c 100644 --- a/src/parser/cxx/memory_layout.cc +++ b/src/parser/cxx/memory_layout.cc @@ -36,6 +36,11 @@ struct SizeOf { return memoryLayout.sizeOfPointer(); } + auto operator()(const BuiltinMetaInfoType* type) const + -> std::optional { + return std::nullopt; + } + auto operator()(const VoidType* type) const -> std::optional { return std::nullopt; } diff --git a/src/parser/cxx/names.cc b/src/parser/cxx/names.cc index 1f347b7f..63208549 100644 --- a/src/parser/cxx/names.cc +++ b/src/parser/cxx/names.cc @@ -52,6 +52,15 @@ struct ConstValueHash { auto operator()(const StringLiteral* value) const -> std::size_t { return value->hashCode(); } + auto operator()(const std::shared_ptr& value) const -> std::size_t { + if (std::holds_alternative(value->value)) { + return std::hash{}(std::get(value->value)); + } else if (std::holds_alternative(value->value)) { + auto symbol = std::get(value->value); + return symbol->name() ? symbol->name()->hashValue() : 0; + } + return 0; + } }; struct TemplateArgumentHash { diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 06fd1836..a652fa18 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -741,14 +741,15 @@ auto Parser::parse_splicer_expression(ExpressionAST*& yyast, auto ast = make_node(pool_); yyast = ast; ast->splicer = splicer; + check(ast); return true; } auto Parser::parse_reflect_expression(ExpressionAST*& yyast, const ExprContext& ctx) -> bool { - SourceLocation caretLoc; + SourceLocation caretCaretLoc; - if (!match(TokenKind::T_CARET, caretLoc)) return false; + if (!match(TokenKind::T_CARET_CARET, caretCaretLoc)) return false; auto lookat_namespace_name = [&] { LookaheadParser lookahead{this}; @@ -761,10 +762,11 @@ auto Parser::parse_reflect_expression(ExpressionAST*& yyast, auto ast = make_node(pool_); yyast = ast; - ast->caretLoc = caretLoc; + ast->caretCaretLoc = caretCaretLoc; ast->identifierLoc = identifierLoc; ast->identifier = identifier; ast->symbol = symbol; + check(ast); return true; }; @@ -776,8 +778,9 @@ auto Parser::parse_reflect_expression(ExpressionAST*& yyast, auto ast = make_node(pool_); yyast = ast; - ast->caretLoc = caretLoc; + ast->caretCaretLoc = caretCaretLoc; ast->typeId = typeId; + check(ast); return true; }; @@ -789,16 +792,18 @@ auto Parser::parse_reflect_expression(ExpressionAST*& yyast, auto ast = make_node(pool_); yyast = ast; - ast->caretLoc = caretLoc; + ast->caretCaretLoc = caretCaretLoc; ast->expression = expression; + check(ast); return true; }; if (SourceLocation scopeLoc; match(TokenKind::T_COLON_COLON, scopeLoc)) { auto ast = make_node(pool_); yyast = ast; - ast->caretLoc = caretLoc; + ast->caretCaretLoc = caretCaretLoc; ast->scopeLoc = scopeLoc; + check(ast); return true; } @@ -5211,8 +5216,9 @@ auto Parser::parse_primitive_type_specifier(SpecifierAST*& yyast, }; switch (auto tk = LA(); tk.kind()) { - case TokenKind::T___BUILTIN_VA_LIST: { - auto ast = make_node(pool_); + case TokenKind::T___BUILTIN_VA_LIST: + case TokenKind::T___BUILTIN_META_INFO: { + auto ast = make_node(pool_); yyast = ast; ast->specifierLoc = consumeToken(); ast->specifier = unit->tokenKind(ast->specifierLoc); @@ -5313,8 +5319,8 @@ auto Parser::is_template(Symbol* symbol) const -> bool { auto Parser::evaluate_constant_expression(ExpressionAST* expr) -> std::optional { - ASTInterpreter sem{unit}; - return sem.evaluate(expr); + auto interp = ASTInterpreter{unit}; + return interp.evaluate(expr); } auto Parser::parse_elaborated_enum_specifier(SpecifierAST*& yyast, @@ -5570,11 +5576,37 @@ auto Parser::parse_init_declarator(InitDeclaratorAST*& yyast, } } } - } - if (ast->initializer && !control()->is_reference(symbol->type())) { - (void)implicit_conversion(ast->initializer, - control()->remove_cv(symbol->type())); + if (type_cast(var->type())) { + if (!var->initializer()) { + parse_error(var->location(), + "variable with 'auto' type must be initialized"); + } else { + var->setType(control()->remove_cvref(var->initializer()->type)); + } + } + + if (var->isConstexpr()) { + var->setType(control()->add_const(var->type())); + } + + if (ast->initializer && !control()->is_reference(var->type())) { + (void)implicit_conversion(ast->initializer, + control()->remove_cv(var->type())); + } + + if (var->isConstexpr()) { + if (!var->initializer()) { + parse_error(var->location(), "constexpr variable must be initialized"); + } else { + var->setConstValue(evaluate_constant_expression(var->initializer())); + + if (!var->constValue().has_value()) { + type_error(var->location(), + "initializer of constexpr variable is not a constant"); + } + } + } } return true; diff --git a/src/parser/cxx/private/ast_decoder.h b/src/parser/cxx/private/ast_decoder.h index 6525bee4..3a5e4b3a 100644 --- a/src/parser/cxx/private/ast_decoder.h +++ b/src/parser/cxx/private/ast_decoder.h @@ -219,9 +219,6 @@ class ASTDecoder { auto decodeTryBlockStatement(const io::TryBlockStatement* node) -> TryBlockStatementAST*; - auto decodeGeneratedLiteralExpression( - const io::GeneratedLiteralExpression* node) - -> GeneratedLiteralExpressionAST*; auto decodeCharLiteralExpression(const io::CharLiteralExpression* node) -> CharLiteralExpressionAST*; auto decodeBoolLiteralExpression(const io::BoolLiteralExpression* node) @@ -372,8 +369,6 @@ class ASTDecoder { auto decodeConstraintTypeParameter(const io::ConstraintTypeParameter* node) -> ConstraintTypeParameterAST*; - auto decodeGeneratedTypeSpecifier(const io::GeneratedTypeSpecifier* node) - -> GeneratedTypeSpecifierAST*; auto decodeTypedefSpecifier(const io::TypedefSpecifier* node) -> TypedefSpecifierAST*; auto decodeFriendSpecifier(const io::FriendSpecifier* node) @@ -412,8 +407,8 @@ class ASTDecoder { -> SizeTypeSpecifierAST*; auto decodeSignTypeSpecifier(const io::SignTypeSpecifier* node) -> SignTypeSpecifierAST*; - auto decodeVaListTypeSpecifier(const io::VaListTypeSpecifier* node) - -> VaListTypeSpecifierAST*; + auto decodeBuiltinTypeSpecifier(const io::BuiltinTypeSpecifier* node) + -> BuiltinTypeSpecifierAST*; auto decodeIntegralTypeSpecifier(const io::IntegralTypeSpecifier* node) -> IntegralTypeSpecifierAST*; auto decodeFloatingPointTypeSpecifier( diff --git a/src/parser/cxx/private/ast_encoder.h b/src/parser/cxx/private/ast_encoder.h index a5710f16..a7e1f2dd 100644 --- a/src/parser/cxx/private/ast_encoder.h +++ b/src/parser/cxx/private/ast_encoder.h @@ -207,7 +207,6 @@ class ASTEncoder : ASTVisitor { void visit(DeclarationStatementAST* ast) override; void visit(TryBlockStatementAST* ast) override; - void visit(GeneratedLiteralExpressionAST* ast) override; void visit(CharLiteralExpressionAST* ast) override; void visit(BoolLiteralExpressionAST* ast) override; void visit(IntLiteralExpressionAST* ast) override; @@ -282,7 +281,6 @@ class ASTEncoder : ASTVisitor { void visit(TypenameTypeParameterAST* ast) override; void visit(ConstraintTypeParameterAST* ast) override; - void visit(GeneratedTypeSpecifierAST* ast) override; void visit(TypedefSpecifierAST* ast) override; void visit(FriendSpecifierAST* ast) override; void visit(ConstevalSpecifierAST* ast) override; @@ -302,7 +300,7 @@ class ASTEncoder : ASTVisitor { void visit(VoidTypeSpecifierAST* ast) override; void visit(SizeTypeSpecifierAST* ast) override; void visit(SignTypeSpecifierAST* ast) override; - void visit(VaListTypeSpecifierAST* ast) override; + void visit(BuiltinTypeSpecifierAST* ast) override; void visit(IntegralTypeSpecifierAST* ast) override; void visit(FloatingPointTypeSpecifierAST* ast) override; void visit(ComplexTypeSpecifierAST* ast) override; diff --git a/src/parser/cxx/private/keywords-priv.h b/src/parser/cxx/private/keywords-priv.h index 3337b860..5f5e3df5 100644 --- a/src/parser/cxx/private/keywords-priv.h +++ b/src/parser/cxx/private/keywords-priv.h @@ -1801,6 +1801,50 @@ static inline auto classify18(const char* s) -> cxx::TokenKind { return cxx::TokenKind::T_IDENTIFIER; } +static inline auto classify19(const char* s) -> cxx::TokenKind { + if (s[0] == '_') { + if (s[1] == '_') { + if (s[2] == 'b') { + if (s[3] == 'u') { + if (s[4] == 'i') { + if (s[5] == 'l') { + if (s[6] == 't') { + if (s[7] == 'i') { + if (s[8] == 'n') { + if (s[9] == '_') { + if (s[10] == 'm') { + if (s[11] == 'e') { + if (s[12] == 't') { + if (s[13] == 'a') { + if (s[14] == '_') { + if (s[15] == 'i') { + if (s[16] == 'n') { + if (s[17] == 'f') { + if (s[18] == 'o') { + return cxx::TokenKind:: + T___BUILTIN_META_INFO; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + return cxx::TokenKind::T_IDENTIFIER; +} + static auto classify(const char* s, int n) -> cxx::TokenKind { switch (n) { case 2: @@ -1835,6 +1879,8 @@ static auto classify(const char* s, int n) -> cxx::TokenKind { return classify17(s); case 18: return classify18(s); + case 19: + return classify19(s); default: return cxx::TokenKind::T_IDENTIFIER; } // switch diff --git a/src/parser/cxx/token_fwd.h b/src/parser/cxx/token_fwd.h index 666e8e68..d0e76969 100644 --- a/src/parser/cxx/token_fwd.h +++ b/src/parser/cxx/token_fwd.h @@ -55,6 +55,7 @@ class Token; V(BAR_BAR, "||") \ V(BAR_EQUAL, "|=") \ V(BAR, "|") \ + V(CARET_CARET, "^^") \ V(CARET_EQUAL, "^=") \ V(CARET, "^") \ V(COLON_COLON, "::") \ @@ -104,118 +105,119 @@ class Token; V(STAR, "*") \ V(TILDE, "~") -#define FOR_EACH_KEYWORD(V) \ - V(_ATOMIC, "_Atomic") \ - V(_BITINT, "_BitInt") \ - V(_COMPLEX, "_Complex") \ - V(_DECIMAL128, "_Decimal128") \ - V(_DECIMAL32, "_Decimal32") \ - V(_DECIMAL64, "_Decimal64") \ - V(_GENERIC, "_Generic") \ - V(_IMAGINARY, "_Imaginary") \ - V(_NORETURN, "_Noreturn") \ - V(__ATTRIBUTE__, "__attribute__") \ - V(__BUILTIN_BIT_CAST, "__builtin_bit_cast") \ - V(__BUILTIN_OFFSETOF, "__builtin_offsetof") \ - V(__BUILTIN_VA_ARG, "__builtin_va_arg") \ - V(__BUILTIN_VA_LIST, "__builtin_va_list") \ - V(__COMPLEX__, "__complex__") \ - V(__EXTENSION__, "__extension__") \ - V(__FLOAT128, "__float128") \ - V(__FLOAT80, "__float80") \ - V(__IMAG__, "__imag__") \ - V(__INT128, "__int128") \ - V(__INT128_T, "__int128_t") \ - V(__INT64, "__int64") \ - V(__REAL__, "__real__") \ - V(__RESTRICT__, "__restrict__") \ - V(__THREAD, "__thread") \ - V(__UINT128_T, "__uint128_t") \ - V(__UNDERLYING_TYPE, "__underlying_type") \ - V(ALIGNAS, "alignas") \ - V(ALIGNOF, "alignof") \ - V(ASM, "asm") \ - V(AUTO, "auto") \ - V(BOOL, "bool") \ - V(BREAK, "break") \ - V(CASE, "case") \ - V(CATCH, "catch") \ - V(CHAR, "char") \ - V(CHAR16_T, "char16_t") \ - V(CHAR32_T, "char32_t") \ - V(CHAR8_T, "char8_t") \ - V(CLASS, "class") \ - V(CO_AWAIT, "co_await") \ - V(CO_RETURN, "co_return") \ - V(CO_YIELD, "co_yield") \ - V(CONCEPT, "concept") \ - V(CONST, "const") \ - V(CONST_CAST, "const_cast") \ - V(CONSTEVAL, "consteval") \ - V(CONSTEXPR, "constexpr") \ - V(CONSTINIT, "constinit") \ - V(CONTINUE, "continue") \ - V(DECLTYPE, "decltype") \ - V(DEFAULT, "default") \ - V(DELETE, "delete") \ - V(DO, "do") \ - V(DOUBLE, "double") \ - V(DYNAMIC_CAST, "dynamic_cast") \ - V(ELSE, "else") \ - V(ENUM, "enum") \ - V(EXPLICIT, "explicit") \ - V(EXPORT, "export") \ - V(EXTERN, "extern") \ - V(FALSE, "false") \ - V(FLOAT, "float") \ - V(FOR, "for") \ - V(FRIEND, "friend") \ - V(GOTO, "goto") \ - V(IF, "if") \ - V(IMPORT, "import") \ - V(INLINE, "inline") \ - V(INT, "int") \ - V(LONG, "long") \ - V(MODULE, "module") \ - V(MUTABLE, "mutable") \ - V(NAMESPACE, "namespace") \ - V(NEW, "new") \ - V(NOEXCEPT, "noexcept") \ - V(NULLPTR, "nullptr") \ - V(OPERATOR, "operator") \ - V(PRIVATE, "private") \ - V(PROTECTED, "protected") \ - V(PUBLIC, "public") \ - V(REGISTER, "register") \ - V(REINTERPRET_CAST, "reinterpret_cast") \ - V(REQUIRES, "requires") \ - V(RETURN, "return") \ - V(SHORT, "short") \ - V(SIGNED, "signed") \ - V(SIZEOF, "sizeof") \ - V(STATIC, "static") \ - V(STATIC_ASSERT, "static_assert") \ - V(STATIC_CAST, "static_cast") \ - V(STRUCT, "struct") \ - V(SWITCH, "switch") \ - V(TEMPLATE, "template") \ - V(THIS, "this") \ - V(THREAD_LOCAL, "thread_local") \ - V(THROW, "throw") \ - V(TRUE, "true") \ - V(TRY, "try") \ - V(TYPEDEF, "typedef") \ - V(TYPEID, "typeid") \ - V(TYPENAME, "typename") \ - V(TYPEOF, "typeof") \ - V(TYPEOF_UNQUAL, "typeof_unqual") \ - V(UNION, "union") \ - V(UNSIGNED, "unsigned") \ - V(USING, "using") \ - V(VIRTUAL, "virtual") \ - V(VOID, "void") \ - V(VOLATILE, "volatile") \ - V(WCHAR_T, "wchar_t") \ +#define FOR_EACH_KEYWORD(V) \ + V(_ATOMIC, "_Atomic") \ + V(_BITINT, "_BitInt") \ + V(_COMPLEX, "_Complex") \ + V(_DECIMAL128, "_Decimal128") \ + V(_DECIMAL32, "_Decimal32") \ + V(_DECIMAL64, "_Decimal64") \ + V(_GENERIC, "_Generic") \ + V(_IMAGINARY, "_Imaginary") \ + V(_NORETURN, "_Noreturn") \ + V(__ATTRIBUTE__, "__attribute__") \ + V(__BUILTIN_BIT_CAST, "__builtin_bit_cast") \ + V(__BUILTIN_META_INFO, "__builtin_meta_info") \ + V(__BUILTIN_OFFSETOF, "__builtin_offsetof") \ + V(__BUILTIN_VA_ARG, "__builtin_va_arg") \ + V(__BUILTIN_VA_LIST, "__builtin_va_list") \ + V(__COMPLEX__, "__complex__") \ + V(__EXTENSION__, "__extension__") \ + V(__FLOAT128, "__float128") \ + V(__FLOAT80, "__float80") \ + V(__IMAG__, "__imag__") \ + V(__INT128, "__int128") \ + V(__INT128_T, "__int128_t") \ + V(__INT64, "__int64") \ + V(__REAL__, "__real__") \ + V(__RESTRICT__, "__restrict__") \ + V(__THREAD, "__thread") \ + V(__UINT128_T, "__uint128_t") \ + V(__UNDERLYING_TYPE, "__underlying_type") \ + V(ALIGNAS, "alignas") \ + V(ALIGNOF, "alignof") \ + V(ASM, "asm") \ + V(AUTO, "auto") \ + V(BOOL, "bool") \ + V(BREAK, "break") \ + V(CASE, "case") \ + V(CATCH, "catch") \ + V(CHAR, "char") \ + V(CHAR16_T, "char16_t") \ + V(CHAR32_T, "char32_t") \ + V(CHAR8_T, "char8_t") \ + V(CLASS, "class") \ + V(CO_AWAIT, "co_await") \ + V(CO_RETURN, "co_return") \ + V(CO_YIELD, "co_yield") \ + V(CONCEPT, "concept") \ + V(CONST, "const") \ + V(CONST_CAST, "const_cast") \ + V(CONSTEVAL, "consteval") \ + V(CONSTEXPR, "constexpr") \ + V(CONSTINIT, "constinit") \ + V(CONTINUE, "continue") \ + V(DECLTYPE, "decltype") \ + V(DEFAULT, "default") \ + V(DELETE, "delete") \ + V(DO, "do") \ + V(DOUBLE, "double") \ + V(DYNAMIC_CAST, "dynamic_cast") \ + V(ELSE, "else") \ + V(ENUM, "enum") \ + V(EXPLICIT, "explicit") \ + V(EXPORT, "export") \ + V(EXTERN, "extern") \ + V(FALSE, "false") \ + V(FLOAT, "float") \ + V(FOR, "for") \ + V(FRIEND, "friend") \ + V(GOTO, "goto") \ + V(IF, "if") \ + V(IMPORT, "import") \ + V(INLINE, "inline") \ + V(INT, "int") \ + V(LONG, "long") \ + V(MODULE, "module") \ + V(MUTABLE, "mutable") \ + V(NAMESPACE, "namespace") \ + V(NEW, "new") \ + V(NOEXCEPT, "noexcept") \ + V(NULLPTR, "nullptr") \ + V(OPERATOR, "operator") \ + V(PRIVATE, "private") \ + V(PROTECTED, "protected") \ + V(PUBLIC, "public") \ + V(REGISTER, "register") \ + V(REINTERPRET_CAST, "reinterpret_cast") \ + V(REQUIRES, "requires") \ + V(RETURN, "return") \ + V(SHORT, "short") \ + V(SIGNED, "signed") \ + V(SIZEOF, "sizeof") \ + V(STATIC, "static") \ + V(STATIC_ASSERT, "static_assert") \ + V(STATIC_CAST, "static_cast") \ + V(STRUCT, "struct") \ + V(SWITCH, "switch") \ + V(TEMPLATE, "template") \ + V(THIS, "this") \ + V(THREAD_LOCAL, "thread_local") \ + V(THROW, "throw") \ + V(TRUE, "true") \ + V(TRY, "try") \ + V(TYPEDEF, "typedef") \ + V(TYPEID, "typeid") \ + V(TYPENAME, "typename") \ + V(TYPEOF, "typeof") \ + V(TYPEOF_UNQUAL, "typeof_unqual") \ + V(UNION, "union") \ + V(UNSIGNED, "unsigned") \ + V(USING, "using") \ + V(VIRTUAL, "virtual") \ + V(VOID, "void") \ + V(VOLATILE, "volatile") \ + V(WCHAR_T, "wchar_t") \ V(WHILE, "while") #define FOR_EACH_BUILTIN_TYPE_TRAIT(V) \ diff --git a/src/parser/cxx/type_checker.cc b/src/parser/cxx/type_checker.cc index 80f6140c..a17c195b 100644 --- a/src/parser/cxx/type_checker.cc +++ b/src/parser/cxx/type_checker.cc @@ -152,7 +152,6 @@ struct TypeChecker::Visitor { [[nodiscard]] auto check_pseudo_destructor_access(MemberExpressionAST* ast) -> bool; - void operator()(GeneratedLiteralExpressionAST* ast); void operator()(CharLiteralExpressionAST* ast); void operator()(BoolLiteralExpressionAST* ast); void operator()(IntLiteralExpressionAST* ast); @@ -217,8 +216,6 @@ struct TypeChecker::Visitor { void operator()(ParenInitializerAST* ast); }; -void TypeChecker::Visitor::operator()(GeneratedLiteralExpressionAST* ast) {} - void TypeChecker::Visitor::operator()(CharLiteralExpressionAST* ast) {} void TypeChecker::Visitor::operator()(BoolLiteralExpressionAST* ast) {} @@ -825,15 +822,27 @@ void TypeChecker::Visitor::operator()(TypeidExpressionAST* ast) {} void TypeChecker::Visitor::operator()(TypeidOfTypeExpressionAST* ast) {} -void TypeChecker::Visitor::operator()(SpliceExpressionAST* ast) {} +void TypeChecker::Visitor::operator()(SpliceExpressionAST* ast) { + if (!ast->splicer) return; + if (!ast->splicer->expression) return; + ast->type = ast->splicer->expression->type; +} -void TypeChecker::Visitor::operator()(GlobalScopeReflectExpressionAST* ast) {} +void TypeChecker::Visitor::operator()(GlobalScopeReflectExpressionAST* ast) { + ast->type = control()->getBuiltinMetaInfoType(); +} -void TypeChecker::Visitor::operator()(NamespaceReflectExpressionAST* ast) {} +void TypeChecker::Visitor::operator()(NamespaceReflectExpressionAST* ast) { + ast->type = control()->getBuiltinMetaInfoType(); +} -void TypeChecker::Visitor::operator()(TypeIdReflectExpressionAST* ast) {} +void TypeChecker::Visitor::operator()(TypeIdReflectExpressionAST* ast) { + ast->type = control()->getBuiltinMetaInfoType(); +} -void TypeChecker::Visitor::operator()(ReflectExpressionAST* ast) {} +void TypeChecker::Visitor::operator()(ReflectExpressionAST* ast) { + ast->type = control()->getBuiltinMetaInfoType(); +} void TypeChecker::Visitor::operator()(LabelAddressExpressionAST* ast) { ast->type = control()->getPointerType(control()->getVoidType()); diff --git a/src/parser/cxx/type_printer.cc b/src/parser/cxx/type_printer.cc index 48a815c7..af8e4f21 100644 --- a/src/parser/cxx/type_printer.cc +++ b/src/parser/cxx/type_printer.cc @@ -85,6 +85,10 @@ class TypePrinter { specifiers_.append("__builtin_va_list"); } + void operator()(const BuiltinMetaInfoType* type) { + specifiers_.append("__builtin_meta_info"); + } + void operator()(const VoidType* type) { specifiers_.append("void"); } void operator()(const BoolType* type) { specifiers_.append("bool"); } diff --git a/src/parser/cxx/type_traits.h b/src/parser/cxx/type_traits.h index 4654bd8e..302e5cbd 100644 --- a/src/parser/cxx/type_traits.h +++ b/src/parser/cxx/type_traits.h @@ -1063,6 +1063,11 @@ class TypeTraits { return type->symbol() == otherType->symbol(); } + auto operator()(const BuiltinMetaInfoType*, + const BuiltinMetaInfoType*) const -> bool { + return true; + } + } is_same_{*this}; }; diff --git a/src/parser/cxx/types.h b/src/parser/cxx/types.h index 919fcfb1..afade15d 100644 --- a/src/parser/cxx/types.h +++ b/src/parser/cxx/types.h @@ -47,6 +47,12 @@ class BuiltinVaListType final : public Type { BuiltinVaListType() : Type(Kind) {} }; +class BuiltinMetaInfoType final : public Type { + public: + static constexpr TypeKind Kind = TypeKind::kBuiltinMetaInfo; + BuiltinMetaInfoType() : Type(Kind) {} +}; + class VoidType final : public Type { public: static constexpr TypeKind Kind = TypeKind::kVoid; diff --git a/src/parser/cxx/types_fwd.h b/src/parser/cxx/types_fwd.h index 86c246d2..0c501c18 100644 --- a/src/parser/cxx/types_fwd.h +++ b/src/parser/cxx/types_fwd.h @@ -74,7 +74,8 @@ class Name; V(UnresolvedBoundedArray) \ V(UnresolvedUnderlying) \ V(OverloadSet) \ - V(BuiltinVaList) + V(BuiltinVaList) \ + V(BuiltinMetaInfo) class Type; diff --git a/tests/unit_tests/ast/reflect_01.cc b/tests/unit_tests/ast/reflect_01.cc index 57f8f206..6379cf61 100644 --- a/tests/unit_tests/ast/reflect_01.cc +++ b/tests/unit_tests/ast/reflect_01.cc @@ -2,13 +2,13 @@ // RUN: %cxx -verify -fcheck -ast-dump %s | %filecheck %s --match-full-lines // clang-format on -constexpr auto int_ty = ^int; -constexpr auto ptr_ty = ^const void*; +constexpr auto int_ty = ^^int; +constexpr auto ptr_ty = ^^const void*; constexpr[:int_ty:] i = 0; constexpr[:ptr_ty:] ptr = nullptr; -constexpr auto z = ^123; +constexpr auto z = ^^123; constexpr auto x = [:z:]; // clang-format off @@ -24,8 +24,8 @@ constexpr auto x = [:z:]; // CHECK-NEXT: core-declarator: id-declarator // CHECK-NEXT: unqualified-id: name-id // CHECK-NEXT: identifier: int_ty -// CHECK-NEXT: initializer: equal-initializer -// CHECK-NEXT: expression: type-id-reflect-expression +// CHECK-NEXT: initializer: equal-initializer [prvalue __builtin_meta_info] +// CHECK-NEXT: expression: type-id-reflect-expression [prvalue __builtin_meta_info] // CHECK-NEXT: type-id: type-id // CHECK-NEXT: type-specifier-list // CHECK-NEXT: integral-type-specifier @@ -40,8 +40,8 @@ constexpr auto x = [:z:]; // CHECK-NEXT: core-declarator: id-declarator // CHECK-NEXT: unqualified-id: name-id // CHECK-NEXT: identifier: ptr_ty -// CHECK-NEXT: initializer: equal-initializer -// CHECK-NEXT: expression: type-id-reflect-expression +// CHECK-NEXT: initializer: equal-initializer [prvalue __builtin_meta_info] +// CHECK-NEXT: expression: type-id-reflect-expression [prvalue __builtin_meta_info] // CHECK-NEXT: type-id: type-id // CHECK-NEXT: type-specifier-list // CHECK-NEXT: const-qualifier @@ -54,7 +54,7 @@ constexpr auto x = [:z:]; // CHECK-NEXT: constexpr-specifier // CHECK-NEXT: splicer-type-specifier // CHECK-NEXT: splicer: splicer -// CHECK-NEXT: expression: id-expression [lvalue auto] +// CHECK-NEXT: expression: id-expression [lvalue const __builtin_meta_info] // CHECK-NEXT: unqualified-id: name-id // CHECK-NEXT: identifier: int_ty // CHECK-NEXT: init-declarator-list @@ -71,7 +71,7 @@ constexpr auto x = [:z:]; // CHECK-NEXT: constexpr-specifier // CHECK-NEXT: splicer-type-specifier // CHECK-NEXT: splicer: splicer -// CHECK-NEXT: expression: id-expression [lvalue auto] +// CHECK-NEXT: expression: id-expression [lvalue const __builtin_meta_info] // CHECK-NEXT: unqualified-id: name-id // CHECK-NEXT: identifier: ptr_ty // CHECK-NEXT: init-declarator-list @@ -80,9 +80,11 @@ constexpr auto x = [:z:]; // CHECK-NEXT: core-declarator: id-declarator // CHECK-NEXT: unqualified-id: name-id // CHECK-NEXT: identifier: ptr -// CHECK-NEXT: initializer: equal-initializer [prvalue decltype(nullptr)] -// CHECK-NEXT: expression: nullptr-literal-expression [prvalue decltype(nullptr)] -// CHECK-NEXT: literal: nullptr +// CHECK-NEXT: initializer: implicit-cast-expression [prvalue const void*] +// CHECK-NEXT: cast-kind: pointer-conversion +// CHECK-NEXT: expression: equal-initializer [prvalue decltype(nullptr)] +// CHECK-NEXT: expression: nullptr-literal-expression [prvalue decltype(nullptr)] +// CHECK-NEXT: literal: nullptr // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: constexpr-specifier @@ -93,8 +95,8 @@ constexpr auto x = [:z:]; // CHECK-NEXT: core-declarator: id-declarator // CHECK-NEXT: unqualified-id: name-id // CHECK-NEXT: identifier: z -// CHECK-NEXT: initializer: equal-initializer -// CHECK-NEXT: expression: reflect-expression +// CHECK-NEXT: initializer: equal-initializer [prvalue __builtin_meta_info] +// CHECK-NEXT: expression: reflect-expression [prvalue __builtin_meta_info] // CHECK-NEXT: expression: int-literal-expression [prvalue int] // CHECK-NEXT: literal: 123 // CHECK-NEXT: simple-declaration @@ -107,9 +109,9 @@ constexpr auto x = [:z:]; // CHECK-NEXT: core-declarator: id-declarator // CHECK-NEXT: unqualified-id: name-id // CHECK-NEXT: identifier: x -// CHECK-NEXT: initializer: equal-initializer -// CHECK-NEXT: expression: splice-expression +// CHECK-NEXT: initializer: equal-initializer [prvalue __builtin_meta_info] +// CHECK-NEXT: expression: splice-expression [prvalue const __builtin_meta_info] // CHECK-NEXT: splicer: splicer -// CHECK-NEXT: expression: id-expression [lvalue auto] +// CHECK-NEXT: expression: id-expression [lvalue const __builtin_meta_info] // CHECK-NEXT: unqualified-id: name-id // CHECK-NEXT: identifier: z diff --git a/tests/unit_tests/ast/reflect_02.cc b/tests/unit_tests/ast/reflect_02.cc index 7623bf84..06a802f4 100644 --- a/tests/unit_tests/ast/reflect_02.cc +++ b/tests/unit_tests/ast/reflect_02.cc @@ -6,7 +6,7 @@ struct S { int x; }; -auto main() -> int { return S{.x = 10}.[:^S::x:]; } +auto main() -> int { return S{.x = 10}.[:^^S::x:]; } // clang-format off // CHECK:translation-unit @@ -62,7 +62,7 @@ auto main() -> int { return S{.x = 10}.[:^S::x:]; } // CHECK-NEXT: expression: int-literal-expression [prvalue int] // CHECK-NEXT: literal: 10 // CHECK-NEXT: splicer: splicer -// CHECK-NEXT: expression: reflect-expression +// CHECK-NEXT: expression: reflect-expression [prvalue __builtin_meta_info] // CHECK-NEXT: expression: id-expression [lvalue int] // CHECK-NEXT: nested-name-specifier: simple-nested-name-specifier // CHECK-NEXT: identifier: S diff --git a/tests/unit_tests/ast/variadic_function_02.cc b/tests/unit_tests/ast/variadic_function_02.cc index 4534482d..6d062dee 100644 --- a/tests/unit_tests/ast/variadic_function_02.cc +++ b/tests/unit_tests/ast/variadic_function_02.cc @@ -39,7 +39,7 @@ void ff(int count, ...) { // CHECK-NEXT: declaration-statement // CHECK-NEXT: declaration: simple-declaration // CHECK-NEXT: decl-specifier-list -// CHECK-NEXT: va-list-type-specifier +// CHECK-NEXT: builtin-type-specifier // CHECK-NEXT: specifier: __builtin_va_list // CHECK-NEXT: init-declarator-list // CHECK-NEXT: init-declarator diff --git a/tests/unit_tests/sema/reflect_01.cc b/tests/unit_tests/sema/reflect_01.cc new file mode 100644 index 00000000..d59aa3de --- /dev/null +++ b/tests/unit_tests/sema/reflect_01.cc @@ -0,0 +1,27 @@ +// RUN: %cxx -verify -fcheck %s + +namespace std { +namespace meta { +using info = __builtin_meta_info; +} +} // namespace std + +constexpr std::meta::info int_ty = ^^int; +static_assert(__is_same(decltype(int_ty), const std::meta::info)); + +constexpr std::meta::info ptr_ty = ^^const void*; +static_assert(__is_same(decltype(ptr_ty), const std::meta::info)); + +constexpr std::meta::info z = ^^123; +static_assert(__is_same(decltype(z), const std::meta::info)); + +constexpr int x = [:z:]; +static_assert(x == 123); + +constexpr[:int_ty:] i = 123; +static_assert(__is_same(decltype(i), const int)); + +static_assert(i == 123); + +constexpr[:ptr_ty:] ptr = nullptr; +static_assert(__is_same(decltype(ptr), const void* const));