From c84b9117fa55e4d024cc6c62d1702c2ad820d38b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 15 Aug 2023 17:20:26 +0000 Subject: [PATCH 01/28] chore: Update 3rdpary dependencies --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bac7593d..bfca8143 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ endif() FetchContent_Declare( fmt GIT_REPOSITORY https://github.com/fmtlib/fmt - GIT_TAG 10.0.0 + GIT_TAG 10.1.0 GIT_SHALLOW 1 ) @@ -63,7 +63,7 @@ FetchContent_MakeAvailable(fmt) FetchContent_Declare( utfcpp GIT_REPOSITORY https://github.com/nemtrif/utfcpp - GIT_TAG v3.2.2 + GIT_TAG v3.2.4 GIT_SHALLOW 1 ) From ec19f4fcabdca597aaef5f71915527682509cb71 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 15 Aug 2023 18:04:30 +0000 Subject: [PATCH 02/28] fix: Dump the AST in plain text instead of JSON --- CMakeLists.txt | 11 - packages/cxx-gen-ast/src/gen_ast_dump_cc.ts | 136 +- packages/cxx-gen-ast/src/gen_ast_dump_h.ts | 27 +- src/frontend/CMakeLists.txt | 5 +- src/frontend/cxx/ast_printer.cc | 3598 ++++--------------- src/frontend/cxx/ast_printer.h | 26 +- src/frontend/cxx/frontend.cc | 5 +- 7 files changed, 843 insertions(+), 2965 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfca8143..67a7faa7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,17 +69,6 @@ FetchContent_Declare( FetchContent_MakeAvailable(utfcpp) -FetchContent_Declare( - nlohmann_json - URL https://github.com/nlohmann/json/releases/download/v3.11.2/include.zip - URL_HASH SHA256=e5c7a9f49a16814be27e4ed0ee900ecd0092bfb7dbfca65b5a421b774dccaaed -) - -FetchContent_MakeAvailable(nlohmann_json) - -add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED) -set_target_properties(nlohmann_json::nlohmann_json PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_SOURCE_DIR}/single_include") - FetchContent_Declare( wasi_sysroot URL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sysroot-20.0.tar.gz diff --git a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts index 9ec802ed..d9f24feb 100644 --- a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts +++ b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts @@ -23,73 +23,38 @@ import { AST } from "./parseAST.js"; import { cpy_header } from "./cpy_header.js"; import * as fs from "fs"; -const json_vec = "std::vector"; - export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) { const code: string[] = []; const emit = (line = "") => code.push(line); const by_base = groupNodesByBaseType(ast); - const astName = (name: string) => name.slice(0, -3); + const toKebapName = (name: string) => + name.replace(/([A-Z]+)/g, "-$1").toLocaleLowerCase(); + + const astName = (name: string) => toKebapName(name.slice(0, -3)).slice(1); by_base.forEach((nodes) => { nodes.forEach(({ name, members }) => { emit(); emit(`void ASTPrinter::visit(${name}* ast) {`); - emit(` json_ = nlohmann::json::array();`); - emit(); - emit(` json_.push_back("ast:${astName(name)}");`); - emit(); - members.forEach((m) => { - emit(); - if (m.kind === "node") { - emit(` if(ast->${m.name}) {`); - emit( - ` if (auto childNode = accept(ast->${m.name}); !childNode.is_null()) {` - ); - emit( - ` json_.push_back(${json_vec}{"attr:${m.name}", std::move(childNode)});` - ); - emit(` }`); - emit(` }`); - } else if (m.kind === "node-list") { - emit(` if(ast->${m.name}) {`); - emit(` auto elements = nlohmann::json::array();`); - emit(` elements.push_back("array");`); - emit(` for (auto it = ast->${m.name}; it; it = it->next) {`); - emit( - ` if (auto childNode = accept(it->value); !childNode.is_null()) {` - ); - emit(` elements.push_back(std::move(childNode));`); - emit(` }`); - emit(` }`); - emit(` if (elements.size() > 1) {`); - emit( - ` json_.push_back(${json_vec}{"attr:${m.name}", elements});` - ); - emit(` }`); - emit(` }`); - } else if (m.kind === "attribute" && m.type.endsWith("Literal")) { - const tok = (s: string) => `${json_vec}{"literal", ${s}}`; - const val = tok(`ast->${m.name}->value()`); - emit( - ` if (ast->${m.name}) { json_.push_back(${json_vec}{"attr:${m.name}", ${val}}); }` - ); - } else if (m.kind === "attribute" && m.type === "Identifier") { - const tok = (s: string) => `${json_vec}{"identifier", ${s}}`; - const val = tok(`ast->${m.name}->name()`); - emit( - ` if (ast->${m.name}) { json_.push_back(${json_vec}{"attr:${m.name}", ${val}}); }` - ); - } else if (m.kind === "attribute" && m.type === "TokenKind") { - const tok = (s: string) => `${json_vec}{"token", ${s}}`; - const val = tok(`Token::spell(ast->${m.name})`); - emit(` if (ast->${m.name} != TokenKind::T_EOF_SYMBOL) {`); - emit( - ` json_.push_back(${json_vec}{"attr:${m.name}", ${val}});` - ); + emit(` fmt::print(out_, "{}\\n", "${astName(name)}");`); + members.forEach((member) => { + const fieldName = toKebapName(member.name); + if (member.kind === "node-list") { + emit(` if (ast->${member.name}) {`); + emit(` ++indent_;`); + emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); + emit(` fmt::print(out_, "{}\\n", "${fieldName}");`); + emit(` for (auto it = ast->${member.name}; it; it = it->next) {`); + emit(` accept(it->value);`); emit(` }`); + emit(` --indent_;`); + emit(` }`); + } else if (member.kind === "node") { + emit(` accept(ast->${member.name}, "${fieldName}");`); + } else if (member.kind == "attribute" && member.type === "Identifier") { + emit(` accept(ast->${member.name}, "${fieldName}");`); } }); emit(`}`); @@ -103,51 +68,38 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) { #include #include #include +#include #include namespace cxx { - auto ASTPrinter::operator()(AST* ast, bool printLocations) -> nlohmann::json { - std::vector fileNames; - std::swap(fileNames_, fileNames); - std::swap(printLocations_, printLocations); - auto result = accept(ast); - std::swap(printLocations_, printLocations); - std::swap(fileNames_, fileNames); - result.push_back(std::vector{"$files", std::move(fileNames)}); - return result; - } +ASTPrinter::ASTPrinter(TranslationUnit* unit, std::ostream& out) + : unit_(unit) + , out_(out) {} - auto ASTPrinter::accept(AST* ast) -> nlohmann::json { - nlohmann::json json; - - if (ast) { - std::swap(json_, json); - ast->accept(this); - std::swap(json_, json); - - if (!json.is_null() && printLocations_) { - auto [startLoc, endLoc] = ast->sourceLocationRange(); - if (startLoc && endLoc) { - unsigned startLine = 0, startColumn = 0; - unsigned endLine = 0, endColumn = 0; - std::string_view fileName, endFileName; - - unit_->getTokenStartPosition(startLoc, &startLine, &startColumn, &fileName); - unit_->getTokenEndPosition(endLoc.previous(), &endLine, &endColumn, &endFileName); - - if (fileName == endFileName && !fileName.empty()) { - auto it = std::find(begin(fileNames_), end(fileNames_), fileName); - auto fileId = std::distance(begin(fileNames_), it); - if (it == fileNames_.end()) fileNames_.push_back(fileName); - json.push_back(std::vector{"$range", fileId, startLine, startColumn, endLine, endColumn}); - } - } - } +void ASTPrinter::operator()(AST* ast) { + accept(ast); +} + +void ASTPrinter::accept(AST* ast, std::string_view field) { + if (!ast) return; + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + if (!field.empty()) { + fmt::print(out_, "{}: ", field); } + ast->accept(this); + --indent_; +} - return json; +void ASTPrinter::accept(const Identifier* id, std::string_view field) { + if (!id) return; + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + if (!field.empty()) fmt::print(out_, "{}: ", field); + fmt::print(out_, "{}\\n", id->value()); + --indent_; } ${code.join("\n")} diff --git a/packages/cxx-gen-ast/src/gen_ast_dump_h.ts b/packages/cxx-gen-ast/src/gen_ast_dump_h.ts index e865d61f..82ff76b6 100644 --- a/packages/cxx-gen-ast/src/gen_ast_dump_h.ts +++ b/packages/cxx-gen-ast/src/gen_ast_dump_h.ts @@ -30,34 +30,35 @@ export function gen_ast_dump_h({ ast, output }: { ast: AST; output: string }) { const by_base = groupNodesByBaseType(ast); emit(`class ASTPrinter : ASTVisitor {`); - emit(` TranslationUnit* unit_;`); - emit(` std::vector fileNames_;`); - emit(` nlohmann::json json_;`); - emit(` bool printLocations_ = false;`); - emit(); - emit(` auto accept(AST* ast) -> nlohmann::json;`); - emit(); emit(`public:`); - emit(` explicit ASTPrinter(TranslationUnit* unit): unit_(unit) {}`); + emit(` explicit ASTPrinter(TranslationUnit* unit, std::ostream& out);`); emit(); - emit( - ` auto operator()(AST* ast, bool printLocations = false) -> nlohmann::json;` - ); + emit(` void operator()(AST* ast);`); + emit(`private:`); + emit(` void accept(AST* ast, std::string_view field = {});`); + emit(` void accept(const Identifier* id, std::string_view field = {});`); by_base.forEach((nodes) => { emit(); nodes.forEach(({ name }) => { emit(` void visit(${name}* ast) override;`); }); }); - + emit(`private:`); + emit(` TranslationUnit* unit_;`); + emit(` std::ostream& out_;`); + emit(` int indent_ = -1;`); emit(`};`); const out = `${cpy_header} #pragma once #include -#include +#include +#include +#include +#include +#include namespace cxx { diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index f57dfe84..22f47858 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -21,10 +21,7 @@ aux_source_directory(cxx SOURCES) add_executable(cxx ${SOURCES}) -target_link_libraries(cxx - cxx-parser - nlohmann_json::nlohmann_json -) +target_link_libraries(cxx cxx-parser) if(EMSCRIPTEN) target_link_options(cxx PUBLIC diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 0040a190..929f0499 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -23,3700 +23,1634 @@ #include #include #include +#include #include #include namespace cxx { -auto ASTPrinter::operator()(AST* ast, bool printLocations) -> nlohmann::json { - std::vector fileNames; - std::swap(fileNames_, fileNames); - std::swap(printLocations_, printLocations); - auto result = accept(ast); - std::swap(printLocations_, printLocations); - std::swap(fileNames_, fileNames); - result.push_back(std::vector{"$files", std::move(fileNames)}); - return result; -} - -auto ASTPrinter::accept(AST* ast) -> nlohmann::json { - nlohmann::json json; - - if (ast) { - std::swap(json_, json); - ast->accept(this); - std::swap(json_, json); - - if (!json.is_null() && printLocations_) { - auto [startLoc, endLoc] = ast->sourceLocationRange(); - if (startLoc && endLoc) { - unsigned startLine = 0, startColumn = 0; - unsigned endLine = 0, endColumn = 0; - std::string_view fileName, endFileName; +ASTPrinter::ASTPrinter(TranslationUnit* unit, std::ostream& out) + : unit_(unit), out_(out) {} - unit_->getTokenStartPosition(startLoc, &startLine, &startColumn, - &fileName); - unit_->getTokenEndPosition(endLoc.previous(), &endLine, &endColumn, - &endFileName); +void ASTPrinter::operator()(AST* ast) { accept(ast); } - if (fileName == endFileName && !fileName.empty()) { - auto it = std::find(begin(fileNames_), end(fileNames_), fileName); - auto fileId = std::distance(begin(fileNames_), it); - if (it == fileNames_.end()) fileNames_.push_back(fileName); - json.push_back(std::vector{ - "$range", fileId, startLine, startColumn, endLine, endColumn}); - } - } - } +void ASTPrinter::accept(AST* ast, std::string_view field) { + if (!ast) return; + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + if (!field.empty()) { + fmt::print(out_, "{}: ", field); } + ast->accept(this); + --indent_; +} - return json; +void ASTPrinter::accept(const Identifier* id, std::string_view field) { + if (!id) return; + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + if (!field.empty()) fmt::print(out_, "{}: ", field); + fmt::print(out_, "{}\n", id->value()); + --indent_; } void ASTPrinter::visit(TypeIdAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeId"); - + fmt::print(out_, "{}\n", "type-id"); if (ast->typeSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "type-specifier-list"); for (auto it = ast->typeSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:typeSpecifierList", elements}); - } - } - - if (ast->declarator) { - if (auto childNode = accept(ast->declarator); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:declarator", std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->declarator, "declarator"); } void ASTPrinter::visit(NestedNameSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NestedNameSpecifier"); - + fmt::print(out_, "{}\n", "nested-name-specifier"); if (ast->nameList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "name-list"); for (auto it = ast->nameList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back(std::vector{"attr:nameList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(UsingDeclaratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:UsingDeclarator"); - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "using-declarator"); + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); } void ASTPrinter::visit(HandlerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:Handler"); - - if (ast->exceptionDeclaration) { - if (auto childNode = accept(ast->exceptionDeclaration); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:exceptionDeclaration", - std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "handler"); + accept(ast->exceptionDeclaration, "exception-declaration"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(EnumBaseAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:EnumBase"); - + fmt::print(out_, "{}\n", "enum-base"); if (ast->typeSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "type-specifier-list"); for (auto it = ast->typeSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:typeSpecifierList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(EnumeratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:Enumerator"); - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "enumerator"); + accept(ast->name, "name"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); - } - } - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->expression, "expression"); } void ASTPrinter::visit(DeclaratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:Declarator"); - + fmt::print(out_, "{}\n", "declarator"); if (ast->ptrOpList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "ptr-op-list"); for (auto it = ast->ptrOpList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back(std::vector{"attr:ptrOpList", elements}); + accept(it->value); } + --indent_; } - - if (ast->coreDeclarator) { - if (auto childNode = accept(ast->coreDeclarator); !childNode.is_null()) { - json_.push_back(std::vector{"attr:coreDeclarator", - std::move(childNode)}); - } - } - + accept(ast->coreDeclarator, "core-declarator"); if (ast->modifiers) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "modifiers"); for (auto it = ast->modifiers; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back(std::vector{"attr:modifiers", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(InitDeclaratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:InitDeclarator"); - - if (ast->declarator) { - if (auto childNode = accept(ast->declarator); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:declarator", std::move(childNode)}); - } - } - - if (ast->requiresClause) { - if (auto childNode = accept(ast->requiresClause); !childNode.is_null()) { - json_.push_back(std::vector{"attr:requiresClause", - std::move(childNode)}); - } - } - - if (ast->initializer) { - if (auto childNode = accept(ast->initializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:initializer", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "init-declarator"); + accept(ast->declarator, "declarator"); + accept(ast->requiresClause, "requires-clause"); + accept(ast->initializer, "initializer"); } void ASTPrinter::visit(BaseSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:BaseSpecifier"); - + fmt::print(out_, "{}\n", "base-specifier"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->name, "name"); } void ASTPrinter::visit(BaseClauseAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:BaseClause"); - + fmt::print(out_, "{}\n", "base-clause"); if (ast->baseSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "base-specifier-list"); for (auto it = ast->baseSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:baseSpecifierList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(NewTypeIdAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NewTypeId"); - + fmt::print(out_, "{}\n", "new-type-id"); if (ast->typeSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "type-specifier-list"); for (auto it = ast->typeSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:typeSpecifierList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(RequiresClauseAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:RequiresClause"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "requires-clause"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(ParameterDeclarationClauseAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ParameterDeclarationClause"); - + fmt::print(out_, "{}\n", "parameter-declaration-clause"); if (ast->parameterDeclarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "parameter-declaration-list"); for (auto it = ast->parameterDeclarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back(std::vector{ - "attr:parameterDeclarationList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(ParametersAndQualifiersAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ParametersAndQualifiers"); - - if (ast->parameterDeclarationClause) { - if (auto childNode = accept(ast->parameterDeclarationClause); - !childNode.is_null()) { - json_.push_back(std::vector{ - "attr:parameterDeclarationClause", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "parameters-and-qualifiers"); + accept(ast->parameterDeclarationClause, "parameter-declaration-clause"); if (ast->cvQualifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "cv-qualifier-list"); for (auto it = ast->cvQualifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:cvQualifierList", elements}); + accept(it->value); } + --indent_; } - if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(LambdaIntroducerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:LambdaIntroducer"); - + fmt::print(out_, "{}\n", "lambda-introducer"); if (ast->captureList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "capture-list"); for (auto it = ast->captureList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:captureList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(LambdaDeclaratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:LambdaDeclarator"); - - if (ast->parameterDeclarationClause) { - if (auto childNode = accept(ast->parameterDeclarationClause); - !childNode.is_null()) { - json_.push_back(std::vector{ - "attr:parameterDeclarationClause", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "lambda-declarator"); + accept(ast->parameterDeclarationClause, "parameter-declaration-clause"); if (ast->declSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "decl-specifier-list"); for (auto it = ast->declSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declSpecifierList", elements}); + accept(it->value); } + --indent_; } - if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); - } - } - - if (ast->trailingReturnType) { - if (auto childNode = accept(ast->trailingReturnType); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:trailingReturnType", - std::move(childNode)}); - } - } - - if (ast->requiresClause) { - if (auto childNode = accept(ast->requiresClause); !childNode.is_null()) { - json_.push_back(std::vector{"attr:requiresClause", - std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->trailingReturnType, "trailing-return-type"); + accept(ast->requiresClause, "requires-clause"); } void ASTPrinter::visit(TrailingReturnTypeAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TrailingReturnType"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "trailing-return-type"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(CtorInitializerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CtorInitializer"); - + fmt::print(out_, "{}\n", "ctor-initializer"); if (ast->memInitializerList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "mem-initializer-list"); for (auto it = ast->memInitializerList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:memInitializerList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(RequirementBodyAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:RequirementBody"); - + fmt::print(out_, "{}\n", "requirement-body"); if (ast->requirementList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "requirement-list"); for (auto it = ast->requirementList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:requirementList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(TypeConstraintAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeConstraint"); - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "type-constraint"); + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); } void ASTPrinter::visit(GlobalModuleFragmentAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:GlobalModuleFragment"); - + fmt::print(out_, "{}\n", "global-module-fragment"); if (ast->declarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); for (auto it = ast->declarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declarationList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(PrivateModuleFragmentAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:PrivateModuleFragment"); - + fmt::print(out_, "{}\n", "private-module-fragment"); if (ast->declarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); for (auto it = ast->declarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declarationList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(ModuleDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ModuleDeclaration"); - - if (ast->moduleName) { - if (auto childNode = accept(ast->moduleName); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:moduleName", std::move(childNode)}); - } - } - - if (ast->modulePartition) { - if (auto childNode = accept(ast->modulePartition); !childNode.is_null()) { - json_.push_back(std::vector{"attr:modulePartition", - std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "module-declaration"); + accept(ast->moduleName, "module-name"); + accept(ast->modulePartition, "module-partition"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(ModuleNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ModuleName"); + fmt::print(out_, "{}\n", "module-name"); } void ASTPrinter::visit(ImportNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ImportName"); - - if (ast->modulePartition) { - if (auto childNode = accept(ast->modulePartition); !childNode.is_null()) { - json_.push_back(std::vector{"attr:modulePartition", - std::move(childNode)}); - } - } - - if (ast->moduleName) { - if (auto childNode = accept(ast->moduleName); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:moduleName", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "import-name"); + accept(ast->modulePartition, "module-partition"); + accept(ast->moduleName, "module-name"); } void ASTPrinter::visit(ModulePartitionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ModulePartition"); - - if (ast->moduleName) { - if (auto childNode = accept(ast->moduleName); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:moduleName", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "module-partition"); + accept(ast->moduleName, "module-name"); } void ASTPrinter::visit(AttributeArgumentClauseAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AttributeArgumentClause"); + fmt::print(out_, "{}\n", "attribute-argument-clause"); } void ASTPrinter::visit(AttributeAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:Attribute"); - - if (ast->attributeToken) { - if (auto childNode = accept(ast->attributeToken); !childNode.is_null()) { - json_.push_back(std::vector{"attr:attributeToken", - std::move(childNode)}); - } - } - - if (ast->attributeArgumentClause) { - if (auto childNode = accept(ast->attributeArgumentClause); - !childNode.is_null()) { - json_.push_back(std::vector{ - "attr:attributeArgumentClause", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "attribute"); + accept(ast->attributeToken, "attribute-token"); + accept(ast->attributeArgumentClause, "attribute-argument-clause"); } void ASTPrinter::visit(AttributeUsingPrefixAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AttributeUsingPrefix"); + fmt::print(out_, "{}\n", "attribute-using-prefix"); } void ASTPrinter::visit(SimpleRequirementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SimpleRequirement"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "simple-requirement"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(CompoundRequirementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CompoundRequirement"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } - - if (ast->typeConstraint) { - if (auto childNode = accept(ast->typeConstraint); !childNode.is_null()) { - json_.push_back(std::vector{"attr:typeConstraint", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "compound-requirement"); + accept(ast->expression, "expression"); + accept(ast->typeConstraint, "type-constraint"); } void ASTPrinter::visit(TypeRequirementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeRequirement"); - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "type-requirement"); + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); } void ASTPrinter::visit(NestedRequirementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NestedRequirement"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "nested-requirement"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(TypeTemplateArgumentAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeTemplateArgument"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "type-template-argument"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(ExpressionTemplateArgumentAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ExpressionTemplateArgument"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "expression-template-argument"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(ParenMemInitializerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ParenMemInitializer"); - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "paren-mem-initializer"); + accept(ast->name, "name"); if (ast->expressionList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); for (auto it = ast->expressionList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:expressionList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(BracedMemInitializerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:BracedMemInitializer"); - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - - if (ast->bracedInitList) { - if (auto childNode = accept(ast->bracedInitList); !childNode.is_null()) { - json_.push_back(std::vector{"attr:bracedInitList", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "braced-mem-initializer"); + accept(ast->name, "name"); + accept(ast->bracedInitList, "braced-init-list"); } void ASTPrinter::visit(ThisLambdaCaptureAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ThisLambdaCapture"); + fmt::print(out_, "{}\n", "this-lambda-capture"); } void ASTPrinter::visit(DerefThisLambdaCaptureAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DerefThisLambdaCapture"); + fmt::print(out_, "{}\n", "deref-this-lambda-capture"); } void ASTPrinter::visit(SimpleLambdaCaptureAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SimpleLambdaCapture"); - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "simple-lambda-capture"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(RefLambdaCaptureAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:RefLambdaCapture"); - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "ref-lambda-capture"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(RefInitLambdaCaptureAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:RefInitLambdaCapture"); - - if (ast->initializer) { - if (auto childNode = accept(ast->initializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:initializer", - std::move(childNode)}); - } - } - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "ref-init-lambda-capture"); + accept(ast->initializer, "initializer"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(InitLambdaCaptureAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:InitLambdaCapture"); - - if (ast->initializer) { - if (auto childNode = accept(ast->initializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:initializer", - std::move(childNode)}); - } - } - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "init-lambda-capture"); + accept(ast->initializer, "initializer"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(EqualInitializerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:EqualInitializer"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "equal-initializer"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(BracedInitListAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:BracedInitList"); - + fmt::print(out_, "{}\n", "braced-init-list"); if (ast->expressionList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); for (auto it = ast->expressionList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:expressionList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(ParenInitializerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ParenInitializer"); - + fmt::print(out_, "{}\n", "paren-initializer"); if (ast->expressionList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); for (auto it = ast->expressionList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:expressionList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(NewParenInitializerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NewParenInitializer"); - + fmt::print(out_, "{}\n", "new-paren-initializer"); if (ast->expressionList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); for (auto it = ast->expressionList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:expressionList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(NewBracedInitializerAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NewBracedInitializer"); - - if (ast->bracedInit) { - if (auto childNode = accept(ast->bracedInit); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:bracedInit", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "new-braced-initializer"); + accept(ast->bracedInit, "braced-init"); } void ASTPrinter::visit(EllipsisExceptionDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:EllipsisExceptionDeclaration"); + fmt::print(out_, "{}\n", "ellipsis-exception-declaration"); } void ASTPrinter::visit(TypeExceptionDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeExceptionDeclaration"); - + fmt::print(out_, "{}\n", "type-exception-declaration"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - if (ast->typeSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "type-specifier-list"); for (auto it = ast->typeSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:typeSpecifierList", elements}); - } - } - - if (ast->declarator) { - if (auto childNode = accept(ast->declarator); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:declarator", std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->declarator, "declarator"); } void ASTPrinter::visit(DefaultFunctionBodyAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DefaultFunctionBody"); + fmt::print(out_, "{}\n", "default-function-body"); } void ASTPrinter::visit(CompoundStatementFunctionBodyAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CompoundStatementFunctionBody"); + fmt::print(out_, "{}\n", "compound-statement-function-body"); + accept(ast->ctorInitializer, "ctor-initializer"); + accept(ast->statement, "statement"); +} - if (ast->ctorInitializer) { - if (auto childNode = accept(ast->ctorInitializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:ctorInitializer", - std::move(childNode)}); +void ASTPrinter::visit(TryStatementFunctionBodyAST* ast) { + fmt::print(out_, "{}\n", "try-statement-function-body"); + accept(ast->ctorInitializer, "ctor-initializer"); + accept(ast->statement, "statement"); + if (ast->handlerList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "handler-list"); + for (auto it = ast->handlerList; it; it = it->next) { + accept(it->value); } + --indent_; } +} - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } -} - -void ASTPrinter::visit(TryStatementFunctionBodyAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TryStatementFunctionBody"); - - if (ast->ctorInitializer) { - if (auto childNode = accept(ast->ctorInitializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:ctorInitializer", - std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } - - if (ast->handlerList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); - for (auto it = ast->handlerList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:handlerList", elements}); - } - } -} - -void ASTPrinter::visit(DeleteFunctionBodyAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DeleteFunctionBody"); +void ASTPrinter::visit(DeleteFunctionBodyAST* ast) { + fmt::print(out_, "{}\n", "delete-function-body"); } void ASTPrinter::visit(TranslationUnitAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TranslationUnit"); - + fmt::print(out_, "{}\n", "translation-unit"); if (ast->declarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); for (auto it = ast->declarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declarationList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(ModuleUnitAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ModuleUnit"); - - if (ast->globalModuleFragment) { - if (auto childNode = accept(ast->globalModuleFragment); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:globalModuleFragment", - std::move(childNode)}); - } - } - - if (ast->moduleDeclaration) { - if (auto childNode = accept(ast->moduleDeclaration); !childNode.is_null()) { - json_.push_back(std::vector{"attr:moduleDeclaration", - std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "module-unit"); + accept(ast->globalModuleFragment, "global-module-fragment"); + accept(ast->moduleDeclaration, "module-declaration"); if (ast->declarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); for (auto it = ast->declarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declarationList", elements}); - } - } - - if (ast->privateModuleFragment) { - if (auto childNode = accept(ast->privateModuleFragment); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:privateModuleFragment", - std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->privateModuleFragment, "private-module-fragment"); } void ASTPrinter::visit(ThisExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ThisExpression"); + fmt::print(out_, "{}\n", "this-expression"); } void ASTPrinter::visit(CharLiteralExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CharLiteralExpression"); - - if (ast->literal) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"literal", ast->literal->value()}}); - } + fmt::print(out_, "{}\n", "char-literal-expression"); } void ASTPrinter::visit(BoolLiteralExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:BoolLiteralExpression"); - - if (ast->literal != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"token", Token::spell(ast->literal)}}); - } + fmt::print(out_, "{}\n", "bool-literal-expression"); } void ASTPrinter::visit(IntLiteralExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:IntLiteralExpression"); - - if (ast->literal) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"literal", ast->literal->value()}}); - } + fmt::print(out_, "{}\n", "int-literal-expression"); } void ASTPrinter::visit(FloatLiteralExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:FloatLiteralExpression"); - - if (ast->literal) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"literal", ast->literal->value()}}); - } + fmt::print(out_, "{}\n", "float-literal-expression"); } void ASTPrinter::visit(NullptrLiteralExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NullptrLiteralExpression"); - - if (ast->literal != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"token", Token::spell(ast->literal)}}); - } + fmt::print(out_, "{}\n", "nullptr-literal-expression"); } void ASTPrinter::visit(StringLiteralExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:StringLiteralExpression"); - - if (ast->literal) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"literal", ast->literal->value()}}); - } + fmt::print(out_, "{}\n", "string-literal-expression"); } void ASTPrinter::visit(UserDefinedStringLiteralExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:UserDefinedStringLiteralExpression"); - - if (ast->literal) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"literal", ast->literal->value()}}); - } + fmt::print(out_, "{}\n", "user-defined-string-literal-expression"); } void ASTPrinter::visit(IdExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:IdExpression"); - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "id-expression"); + accept(ast->name, "name"); } void ASTPrinter::visit(RequiresExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:RequiresExpression"); - - if (ast->parameterDeclarationClause) { - if (auto childNode = accept(ast->parameterDeclarationClause); - !childNode.is_null()) { - json_.push_back(std::vector{ - "attr:parameterDeclarationClause", std::move(childNode)}); - } - } - - if (ast->requirementBody) { - if (auto childNode = accept(ast->requirementBody); !childNode.is_null()) { - json_.push_back(std::vector{"attr:requirementBody", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "requires-expression"); + accept(ast->parameterDeclarationClause, "parameter-declaration-clause"); + accept(ast->requirementBody, "requirement-body"); } void ASTPrinter::visit(NestedExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NestedExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "nested-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(RightFoldExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:RightFoldExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } - - if (ast->op != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:op", - std::vector{"token", Token::spell(ast->op)}}); - } + fmt::print(out_, "{}\n", "right-fold-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(LeftFoldExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:LeftFoldExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } - - if (ast->op != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:op", - std::vector{"token", Token::spell(ast->op)}}); - } + fmt::print(out_, "{}\n", "left-fold-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(FoldExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:FoldExpression"); - - if (ast->leftExpression) { - if (auto childNode = accept(ast->leftExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:leftExpression", - std::move(childNode)}); - } - } - - if (ast->rightExpression) { - if (auto childNode = accept(ast->rightExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:rightExpression", - std::move(childNode)}); - } - } - - if (ast->op != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:op", - std::vector{"token", Token::spell(ast->op)}}); - } - - if (ast->foldOp != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:foldOp", - std::vector{"token", Token::spell(ast->foldOp)}}); - } + fmt::print(out_, "{}\n", "fold-expression"); + accept(ast->leftExpression, "left-expression"); + accept(ast->rightExpression, "right-expression"); } void ASTPrinter::visit(LambdaExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:LambdaExpression"); - - if (ast->lambdaIntroducer) { - if (auto childNode = accept(ast->lambdaIntroducer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:lambdaIntroducer", - std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "lambda-expression"); + accept(ast->lambdaIntroducer, "lambda-introducer"); if (ast->templateParameterList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "template-parameter-list"); for (auto it = ast->templateParameterList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:templateParameterList", elements}); - } - } - - if (ast->requiresClause) { - if (auto childNode = accept(ast->requiresClause); !childNode.is_null()) { - json_.push_back(std::vector{"attr:requiresClause", - std::move(childNode)}); - } - } - - if (ast->lambdaDeclarator) { - if (auto childNode = accept(ast->lambdaDeclarator); !childNode.is_null()) { - json_.push_back(std::vector{"attr:lambdaDeclarator", - std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->requiresClause, "requires-clause"); + accept(ast->lambdaDeclarator, "lambda-declarator"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(SizeofExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SizeofExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "sizeof-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(SizeofTypeExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SizeofTypeExpression"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "sizeof-type-expression"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(SizeofPackExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SizeofPackExpression"); - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "sizeof-pack-expression"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(TypeidExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeidExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "typeid-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(TypeidOfTypeExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeidOfTypeExpression"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "typeid-of-type-expression"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(AlignofExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AlignofExpression"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "alignof-expression"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(TypeTraitsExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeTraitsExpression"); - + fmt::print(out_, "{}\n", "type-traits-expression"); if (ast->typeIdList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "type-id-list"); for (auto it = ast->typeIdList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back(std::vector{"attr:typeIdList", elements}); + accept(it->value); } - } - - if (ast->typeTraits != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:typeTraits", - std::vector{"token", Token::spell(ast->typeTraits)}}); + --indent_; } } void ASTPrinter::visit(UnaryExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:UnaryExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } - - if (ast->op != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:op", - std::vector{"token", Token::spell(ast->op)}}); - } + fmt::print(out_, "{}\n", "unary-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(BinaryExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:BinaryExpression"); - - if (ast->leftExpression) { - if (auto childNode = accept(ast->leftExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:leftExpression", - std::move(childNode)}); - } - } - - if (ast->rightExpression) { - if (auto childNode = accept(ast->rightExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:rightExpression", - std::move(childNode)}); - } - } - - if (ast->op != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:op", - std::vector{"token", Token::spell(ast->op)}}); - } + fmt::print(out_, "{}\n", "binary-expression"); + accept(ast->leftExpression, "left-expression"); + accept(ast->rightExpression, "right-expression"); } void ASTPrinter::visit(AssignmentExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AssignmentExpression"); - - if (ast->leftExpression) { - if (auto childNode = accept(ast->leftExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:leftExpression", - std::move(childNode)}); - } - } - - if (ast->rightExpression) { - if (auto childNode = accept(ast->rightExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:rightExpression", - std::move(childNode)}); - } - } - - if (ast->op != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:op", - std::vector{"token", Token::spell(ast->op)}}); - } + fmt::print(out_, "{}\n", "assignment-expression"); + accept(ast->leftExpression, "left-expression"); + accept(ast->rightExpression, "right-expression"); } void ASTPrinter::visit(BracedTypeConstructionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:BracedTypeConstruction"); - - if (ast->typeSpecifier) { - if (auto childNode = accept(ast->typeSpecifier); !childNode.is_null()) { - json_.push_back(std::vector{"attr:typeSpecifier", - std::move(childNode)}); - } - } - - if (ast->bracedInitList) { - if (auto childNode = accept(ast->bracedInitList); !childNode.is_null()) { - json_.push_back(std::vector{"attr:bracedInitList", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "braced-type-construction"); + accept(ast->typeSpecifier, "type-specifier"); + accept(ast->bracedInitList, "braced-init-list"); } void ASTPrinter::visit(TypeConstructionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypeConstruction"); - - if (ast->typeSpecifier) { - if (auto childNode = accept(ast->typeSpecifier); !childNode.is_null()) { - json_.push_back(std::vector{"attr:typeSpecifier", - std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "type-construction"); + accept(ast->typeSpecifier, "type-specifier"); if (ast->expressionList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); for (auto it = ast->expressionList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:expressionList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(CallExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CallExpression"); - - if (ast->baseExpression) { - if (auto childNode = accept(ast->baseExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:baseExpression", - std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "call-expression"); + accept(ast->baseExpression, "base-expression"); if (ast->expressionList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); for (auto it = ast->expressionList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:expressionList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(SubscriptExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SubscriptExpression"); - - if (ast->baseExpression) { - if (auto childNode = accept(ast->baseExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:baseExpression", - std::move(childNode)}); - } - } - - if (ast->indexExpression) { - if (auto childNode = accept(ast->indexExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:indexExpression", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "subscript-expression"); + accept(ast->baseExpression, "base-expression"); + accept(ast->indexExpression, "index-expression"); } void ASTPrinter::visit(MemberExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:MemberExpression"); - - if (ast->baseExpression) { - if (auto childNode = accept(ast->baseExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:baseExpression", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - - if (ast->accessOp != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:accessOp", - std::vector{"token", Token::spell(ast->accessOp)}}); - } + fmt::print(out_, "{}\n", "member-expression"); + accept(ast->baseExpression, "base-expression"); + accept(ast->name, "name"); } void ASTPrinter::visit(PostIncrExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:PostIncrExpression"); - - if (ast->baseExpression) { - if (auto childNode = accept(ast->baseExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:baseExpression", - std::move(childNode)}); - } - } - - if (ast->op != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:op", - std::vector{"token", Token::spell(ast->op)}}); - } + fmt::print(out_, "{}\n", "post-incr-expression"); + accept(ast->baseExpression, "base-expression"); } void ASTPrinter::visit(ConditionalExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ConditionalExpression"); - - if (ast->condition) { - if (auto childNode = accept(ast->condition); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:condition", std::move(childNode)}); - } - } - - if (ast->iftrueExpression) { - if (auto childNode = accept(ast->iftrueExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:iftrueExpression", - std::move(childNode)}); - } - } - - if (ast->iffalseExpression) { - if (auto childNode = accept(ast->iffalseExpression); !childNode.is_null()) { - json_.push_back(std::vector{"attr:iffalseExpression", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "conditional-expression"); + accept(ast->condition, "condition"); + accept(ast->iftrueExpression, "iftrue-expression"); + accept(ast->iffalseExpression, "iffalse-expression"); } void ASTPrinter::visit(ImplicitCastExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ImplicitCastExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "implicit-cast-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(CastExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CastExpression"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "cast-expression"); + accept(ast->typeId, "type-id"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(CppCastExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CppCastExpression"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "cpp-cast-expression"); + accept(ast->typeId, "type-id"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(NewExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NewExpression"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } - - if (ast->newInitalizer) { - if (auto childNode = accept(ast->newInitalizer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:newInitalizer", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "new-expression"); + accept(ast->typeId, "type-id"); + accept(ast->newInitalizer, "new-initalizer"); } void ASTPrinter::visit(DeleteExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DeleteExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "delete-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(ThrowExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ThrowExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "throw-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(NoexceptExpressionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NoexceptExpression"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "noexcept-expression"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(LabeledStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:LabeledStatement"); - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "labeled-statement"); + accept(ast->statement, "statement"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(CaseStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CaseStatement"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "case-statement"); + accept(ast->expression, "expression"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(DefaultStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DefaultStatement"); - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "default-statement"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(ExpressionStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ExpressionStatement"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "expression-statement"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(CompoundStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CompoundStatement"); - + fmt::print(out_, "{}\n", "compound-statement"); if (ast->statementList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "statement-list"); for (auto it = ast->statementList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:statementList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(IfStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:IfStatement"); - - if (ast->initializer) { - if (auto childNode = accept(ast->initializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:initializer", - std::move(childNode)}); - } - } - - if (ast->condition) { - if (auto childNode = accept(ast->condition); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:condition", std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } - - if (ast->elseStatement) { - if (auto childNode = accept(ast->elseStatement); !childNode.is_null()) { - json_.push_back(std::vector{"attr:elseStatement", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "if-statement"); + accept(ast->initializer, "initializer"); + accept(ast->condition, "condition"); + accept(ast->statement, "statement"); + accept(ast->elseStatement, "else-statement"); } void ASTPrinter::visit(SwitchStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SwitchStatement"); - - if (ast->initializer) { - if (auto childNode = accept(ast->initializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:initializer", - std::move(childNode)}); - } - } - - if (ast->condition) { - if (auto childNode = accept(ast->condition); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:condition", std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "switch-statement"); + accept(ast->initializer, "initializer"); + accept(ast->condition, "condition"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(WhileStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:WhileStatement"); - - if (ast->condition) { - if (auto childNode = accept(ast->condition); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:condition", std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "while-statement"); + accept(ast->condition, "condition"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(DoStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DoStatement"); - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "do-statement"); + accept(ast->statement, "statement"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(ForRangeStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ForRangeStatement"); - - if (ast->initializer) { - if (auto childNode = accept(ast->initializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:initializer", - std::move(childNode)}); - } - } - - if (ast->rangeDeclaration) { - if (auto childNode = accept(ast->rangeDeclaration); !childNode.is_null()) { - json_.push_back(std::vector{"attr:rangeDeclaration", - std::move(childNode)}); - } - } - - if (ast->rangeInitializer) { - if (auto childNode = accept(ast->rangeInitializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:rangeInitializer", - std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "for-range-statement"); + accept(ast->initializer, "initializer"); + accept(ast->rangeDeclaration, "range-declaration"); + accept(ast->rangeInitializer, "range-initializer"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(ForStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ForStatement"); - - if (ast->initializer) { - if (auto childNode = accept(ast->initializer); !childNode.is_null()) { - json_.push_back(std::vector{"attr:initializer", - std::move(childNode)}); - } - } - - if (ast->condition) { - if (auto childNode = accept(ast->condition); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:condition", std::move(childNode)}); - } - } - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "for-statement"); + accept(ast->initializer, "initializer"); + accept(ast->condition, "condition"); + accept(ast->expression, "expression"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(BreakStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:BreakStatement"); + fmt::print(out_, "{}\n", "break-statement"); } void ASTPrinter::visit(ContinueStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ContinueStatement"); + fmt::print(out_, "{}\n", "continue-statement"); } void ASTPrinter::visit(ReturnStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ReturnStatement"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "return-statement"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(GotoStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:GotoStatement"); - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "goto-statement"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(CoroutineReturnStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CoroutineReturnStatement"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "coroutine-return-statement"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(DeclarationStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DeclarationStatement"); - - if (ast->declaration) { - if (auto childNode = accept(ast->declaration); !childNode.is_null()) { - json_.push_back(std::vector{"attr:declaration", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "declaration-statement"); + accept(ast->declaration, "declaration"); } void ASTPrinter::visit(TryBlockStatementAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TryBlockStatement"); - - if (ast->statement) { - if (auto childNode = accept(ast->statement); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:statement", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "try-block-statement"); + accept(ast->statement, "statement"); if (ast->handlerList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "handler-list"); for (auto it = ast->handlerList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:handlerList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(AccessDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AccessDeclaration"); + fmt::print(out_, "{}\n", "access-declaration"); } void ASTPrinter::visit(FunctionDefinitionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:FunctionDefinition"); - + fmt::print(out_, "{}\n", "function-definition"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - if (ast->declSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "decl-specifier-list"); for (auto it = ast->declSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declSpecifierList", elements}); - } - } - - if (ast->declarator) { - if (auto childNode = accept(ast->declarator); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:declarator", std::move(childNode)}); - } - } - - if (ast->requiresClause) { - if (auto childNode = accept(ast->requiresClause); !childNode.is_null()) { - json_.push_back(std::vector{"attr:requiresClause", - std::move(childNode)}); - } - } - - if (ast->functionBody) { - if (auto childNode = accept(ast->functionBody); !childNode.is_null()) { - json_.push_back(std::vector{"attr:functionBody", - std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->declarator, "declarator"); + accept(ast->requiresClause, "requires-clause"); + accept(ast->functionBody, "function-body"); } void ASTPrinter::visit(ConceptDefinitionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ConceptDefinition"); - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "concept-definition"); + accept(ast->name, "name"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(ForRangeDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ForRangeDeclaration"); + fmt::print(out_, "{}\n", "for-range-declaration"); } void ASTPrinter::visit(AliasDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AliasDeclaration"); - + fmt::print(out_, "{}\n", "alias-declaration"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + accept(ast->typeId, "type-id"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(SimpleDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SimpleDeclaration"); - + fmt::print(out_, "{}\n", "simple-declaration"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - if (ast->declSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "decl-specifier-list"); for (auto it = ast->declSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declSpecifierList", elements}); + accept(it->value); } + --indent_; } - if (ast->initDeclaratorList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "init-declarator-list"); for (auto it = ast->initDeclaratorList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:initDeclaratorList", elements}); - } - } - - if (ast->requiresClause) { - if (auto childNode = accept(ast->requiresClause); !childNode.is_null()) { - json_.push_back(std::vector{"attr:requiresClause", - std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->requiresClause, "requires-clause"); } void ASTPrinter::visit(StaticAssertDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:StaticAssertDeclaration"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } - - if (ast->literal) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"literal", ast->literal->value()}}); - } + fmt::print(out_, "{}\n", "static-assert-declaration"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(EmptyDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:EmptyDeclaration"); + fmt::print(out_, "{}\n", "empty-declaration"); } void ASTPrinter::visit(AttributeDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AttributeDeclaration"); - + fmt::print(out_, "{}\n", "attribute-declaration"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(OpaqueEnumDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:OpaqueEnumDeclaration"); - + fmt::print(out_, "{}\n", "opaque-enum-declaration"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); - } - } - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - - if (ast->enumBase) { - if (auto childNode = accept(ast->enumBase); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:enumBase", std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); + accept(ast->enumBase, "enum-base"); } void ASTPrinter::visit(UsingEnumDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:UsingEnumDeclaration"); + fmt::print(out_, "{}\n", "using-enum-declaration"); } void ASTPrinter::visit(NamespaceDefinitionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NamespaceDefinition"); - + fmt::print(out_, "{}\n", "namespace-definition"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); if (ast->extraAttributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "extra-attribute-list"); for (auto it = ast->extraAttributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:extraAttributeList", elements}); + accept(it->value); } + --indent_; } - if (ast->declarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); for (auto it = ast->declarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declarationList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(NamespaceAliasDefinitionAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NamespaceAliasDefinition"); - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "namespace-alias-definition"); + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(UsingDirectiveAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:UsingDirective"); - - if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); - for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); - } - } - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); + fmt::print(out_, "{}\n", "using-directive"); + if (ast->attributeList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); + for (auto it = ast->attributeList; it; it = it->next) { + accept(it->value); } + --indent_; } + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); } void ASTPrinter::visit(UsingDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:UsingDeclaration"); - + fmt::print(out_, "{}\n", "using-declaration"); if (ast->usingDeclaratorList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "using-declarator-list"); for (auto it = ast->usingDeclaratorList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:usingDeclaratorList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(AsmDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AsmDeclaration"); - + fmt::print(out_, "{}\n", "asm-declaration"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } - } - - if (ast->literal) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"literal", ast->literal->value()}}); + --indent_; } } void ASTPrinter::visit(ExportDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ExportDeclaration"); - - if (ast->declaration) { - if (auto childNode = accept(ast->declaration); !childNode.is_null()) { - json_.push_back(std::vector{"attr:declaration", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "export-declaration"); + accept(ast->declaration, "declaration"); } void ASTPrinter::visit(ExportCompoundDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ExportCompoundDeclaration"); - + fmt::print(out_, "{}\n", "export-compound-declaration"); if (ast->declarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); for (auto it = ast->declarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declarationList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(ModuleImportDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ModuleImportDeclaration"); - - if (ast->importName) { - if (auto childNode = accept(ast->importName); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:importName", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "module-import-declaration"); + accept(ast->importName, "import-name"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(TemplateDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TemplateDeclaration"); - + fmt::print(out_, "{}\n", "template-declaration"); if (ast->templateParameterList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "template-parameter-list"); for (auto it = ast->templateParameterList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:templateParameterList", elements}); - } - } - - if (ast->requiresClause) { - if (auto childNode = accept(ast->requiresClause); !childNode.is_null()) { - json_.push_back(std::vector{"attr:requiresClause", - std::move(childNode)}); - } - } - - if (ast->declaration) { - if (auto childNode = accept(ast->declaration); !childNode.is_null()) { - json_.push_back(std::vector{"attr:declaration", - std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->requiresClause, "requires-clause"); + accept(ast->declaration, "declaration"); } void ASTPrinter::visit(TypenameTypeParameterAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypenameTypeParameter"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "typename-type-parameter"); + accept(ast->typeId, "type-id"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(TemplateTypeParameterAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TemplateTypeParameter"); - + fmt::print(out_, "{}\n", "template-type-parameter"); if (ast->templateParameterList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "template-parameter-list"); for (auto it = ast->templateParameterList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } + accept(it->value); } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:templateParameterList", elements}); - } - } - - if (ast->requiresClause) { - if (auto childNode = accept(ast->requiresClause); !childNode.is_null()) { - json_.push_back(std::vector{"attr:requiresClause", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); + --indent_; } + accept(ast->requiresClause, "requires-clause"); + accept(ast->name, "name"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(TemplatePackTypeParameterAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TemplatePackTypeParameter"); - + fmt::print(out_, "{}\n", "template-pack-type-parameter"); if (ast->templateParameterList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "template-parameter-list"); for (auto it = ast->templateParameterList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:templateParameterList", elements}); + accept(it->value); } + --indent_; } - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(DeductionGuideAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DeductionGuide"); + fmt::print(out_, "{}\n", "deduction-guide"); } void ASTPrinter::visit(ExplicitInstantiationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ExplicitInstantiation"); - - if (ast->declaration) { - if (auto childNode = accept(ast->declaration); !childNode.is_null()) { - json_.push_back(std::vector{"attr:declaration", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "explicit-instantiation"); + accept(ast->declaration, "declaration"); } void ASTPrinter::visit(ParameterDeclarationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ParameterDeclaration"); - + fmt::print(out_, "{}\n", "parameter-declaration"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - if (ast->typeSpecifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "type-specifier-list"); for (auto it = ast->typeSpecifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:typeSpecifierList", elements}); - } - } - - if (ast->declarator) { - if (auto childNode = accept(ast->declarator); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:declarator", std::move(childNode)}); - } - } - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->declarator, "declarator"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(LinkageSpecificationAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:LinkageSpecification"); - + fmt::print(out_, "{}\n", "linkage-specification"); if (ast->declarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); for (auto it = ast->declarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } + accept(it->value); } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declarationList", elements}); - } - } - - if (ast->stringLiteral) { - json_.push_back(std::vector{ - "attr:stringLiteral", - std::vector{"literal", ast->stringLiteral->value()}}); + --indent_; } } void ASTPrinter::visit(SimpleNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SimpleName"); - - if (ast->identifier) { - json_.push_back(std::vector{ - "attr:identifier", - std::vector{"identifier", ast->identifier->name()}}); - } + fmt::print(out_, "{}\n", "simple-name"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(DestructorNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DestructorName"); - - if (ast->id) { - if (auto childNode = accept(ast->id); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:id", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "destructor-name"); + accept(ast->id, "id"); } void ASTPrinter::visit(DecltypeNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DecltypeName"); - - if (ast->decltypeSpecifier) { - if (auto childNode = accept(ast->decltypeSpecifier); !childNode.is_null()) { - json_.push_back(std::vector{"attr:decltypeSpecifier", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "decltype-name"); + accept(ast->decltypeSpecifier, "decltype-specifier"); } void ASTPrinter::visit(OperatorNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:OperatorName"); - - if (ast->op != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:op", - std::vector{"token", Token::spell(ast->op)}}); - } + fmt::print(out_, "{}\n", "operator-name"); } void ASTPrinter::visit(ConversionNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ConversionName"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "conversion-name"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(TemplateNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TemplateName"); - - if (ast->id) { - if (auto childNode = accept(ast->id); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:id", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "template-name"); + accept(ast->id, "id"); if (ast->templateArgumentList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "template-argument-list"); for (auto it = ast->templateArgumentList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:templateArgumentList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(QualifiedNameAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:QualifiedName"); - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->id) { - if (auto childNode = accept(ast->id); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:id", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "qualified-name"); + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->id, "id"); } void ASTPrinter::visit(TypedefSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypedefSpecifier"); + fmt::print(out_, "{}\n", "typedef-specifier"); } void ASTPrinter::visit(FriendSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:FriendSpecifier"); + fmt::print(out_, "{}\n", "friend-specifier"); } void ASTPrinter::visit(ConstevalSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ConstevalSpecifier"); + fmt::print(out_, "{}\n", "consteval-specifier"); } void ASTPrinter::visit(ConstinitSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ConstinitSpecifier"); + fmt::print(out_, "{}\n", "constinit-specifier"); } void ASTPrinter::visit(ConstexprSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ConstexprSpecifier"); + fmt::print(out_, "{}\n", "constexpr-specifier"); } void ASTPrinter::visit(InlineSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:InlineSpecifier"); + fmt::print(out_, "{}\n", "inline-specifier"); } void ASTPrinter::visit(StaticSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:StaticSpecifier"); + fmt::print(out_, "{}\n", "static-specifier"); } void ASTPrinter::visit(ExternSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ExternSpecifier"); + fmt::print(out_, "{}\n", "extern-specifier"); } void ASTPrinter::visit(ThreadLocalSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ThreadLocalSpecifier"); + fmt::print(out_, "{}\n", "thread-local-specifier"); } void ASTPrinter::visit(ThreadSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ThreadSpecifier"); + fmt::print(out_, "{}\n", "thread-specifier"); } void ASTPrinter::visit(MutableSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:MutableSpecifier"); + fmt::print(out_, "{}\n", "mutable-specifier"); } void ASTPrinter::visit(VirtualSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:VirtualSpecifier"); + fmt::print(out_, "{}\n", "virtual-specifier"); } void ASTPrinter::visit(ExplicitSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ExplicitSpecifier"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "explicit-specifier"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(AutoTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AutoTypeSpecifier"); + fmt::print(out_, "{}\n", "auto-type-specifier"); } void ASTPrinter::visit(VoidTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:VoidTypeSpecifier"); + fmt::print(out_, "{}\n", "void-type-specifier"); } void ASTPrinter::visit(VaListTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:VaListTypeSpecifier"); - - if (ast->specifier != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:specifier", - std::vector{"token", Token::spell(ast->specifier)}}); - } + fmt::print(out_, "{}\n", "va-list-type-specifier"); } void ASTPrinter::visit(IntegralTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:IntegralTypeSpecifier"); - - if (ast->specifier != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:specifier", - std::vector{"token", Token::spell(ast->specifier)}}); - } + fmt::print(out_, "{}\n", "integral-type-specifier"); } void ASTPrinter::visit(FloatingPointTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:FloatingPointTypeSpecifier"); - - if (ast->specifier != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:specifier", - std::vector{"token", Token::spell(ast->specifier)}}); - } + fmt::print(out_, "{}\n", "floating-point-type-specifier"); } void ASTPrinter::visit(ComplexTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ComplexTypeSpecifier"); + fmt::print(out_, "{}\n", "complex-type-specifier"); } void ASTPrinter::visit(NamedTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NamedTypeSpecifier"); - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "named-type-specifier"); + accept(ast->name, "name"); } void ASTPrinter::visit(AtomicTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AtomicTypeSpecifier"); - - if (ast->typeId) { - if (auto childNode = accept(ast->typeId); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:typeId", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "atomic-type-specifier"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(UnderlyingTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:UnderlyingTypeSpecifier"); + fmt::print(out_, "{}\n", "underlying-type-specifier"); } void ASTPrinter::visit(ElaboratedTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ElaboratedTypeSpecifier"); - + fmt::print(out_, "{}\n", "elaborated-type-specifier"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); - } - } - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); + accept(it->value); } + --indent_; } + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); } void ASTPrinter::visit(DecltypeAutoSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DecltypeAutoSpecifier"); + fmt::print(out_, "{}\n", "decltype-auto-specifier"); } void ASTPrinter::visit(DecltypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:DecltypeSpecifier"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "decltype-specifier"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(PlaceholderTypeSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:PlaceholderTypeSpecifier"); - - if (ast->typeConstraint) { - if (auto childNode = accept(ast->typeConstraint); !childNode.is_null()) { - json_.push_back(std::vector{"attr:typeConstraint", - std::move(childNode)}); - } - } - - if (ast->specifier) { - if (auto childNode = accept(ast->specifier); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:specifier", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "placeholder-type-specifier"); + accept(ast->typeConstraint, "type-constraint"); + accept(ast->specifier, "specifier"); } void ASTPrinter::visit(ConstQualifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ConstQualifier"); + fmt::print(out_, "{}\n", "const-qualifier"); } void ASTPrinter::visit(VolatileQualifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:VolatileQualifier"); + fmt::print(out_, "{}\n", "volatile-qualifier"); } void ASTPrinter::visit(RestrictQualifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:RestrictQualifier"); + fmt::print(out_, "{}\n", "restrict-qualifier"); } void ASTPrinter::visit(EnumSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:EnumSpecifier"); - + fmt::print(out_, "{}\n", "enum-specifier"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); - } - } - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); + accept(it->value); } + --indent_; } - - if (ast->enumBase) { - if (auto childNode = accept(ast->enumBase); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:enumBase", std::move(childNode)}); - } - } - + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); + accept(ast->enumBase, "enum-base"); if (ast->enumeratorList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "enumerator-list"); for (auto it = ast->enumeratorList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:enumeratorList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(ClassSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ClassSpecifier"); - + fmt::print(out_, "{}\n", "class-specifier"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - - if (ast->baseClause) { - if (auto childNode = accept(ast->baseClause); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:baseClause", std::move(childNode)}); - } - } - + accept(ast->name, "name"); + accept(ast->baseClause, "base-clause"); if (ast->declarationList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); for (auto it = ast->declarationList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:declarationList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(TypenameSpecifierAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:TypenameSpecifier"); - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "typename-specifier"); + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); } void ASTPrinter::visit(IdDeclaratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:IdDeclarator"); - - if (ast->name) { - if (auto childNode = accept(ast->name); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:name", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "id-declarator"); + accept(ast->name, "name"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(NestedDeclaratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:NestedDeclarator"); - - if (ast->declarator) { - if (auto childNode = accept(ast->declarator); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:declarator", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "nested-declarator"); + accept(ast->declarator, "declarator"); } void ASTPrinter::visit(PointerOperatorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:PointerOperator"); - + fmt::print(out_, "{}\n", "pointer-operator"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - if (ast->cvQualifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "cv-qualifier-list"); for (auto it = ast->cvQualifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:cvQualifierList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(ReferenceOperatorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ReferenceOperator"); - + fmt::print(out_, "{}\n", "reference-operator"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } + accept(it->value); } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); - } - } - - if (ast->refOp != TokenKind::T_EOF_SYMBOL) { - json_.push_back(std::vector{ - "attr:refOp", - std::vector{"token", Token::spell(ast->refOp)}}); + --indent_; } } void ASTPrinter::visit(PtrToMemberOperatorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:PtrToMemberOperator"); - - if (ast->nestedNameSpecifier) { - if (auto childNode = accept(ast->nestedNameSpecifier); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:nestedNameSpecifier", - std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "ptr-to-member-operator"); + accept(ast->nestedNameSpecifier, "nested-name-specifier"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } - if (ast->cvQualifierList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "cv-qualifier-list"); for (auto it = ast->cvQualifierList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:cvQualifierList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(FunctionDeclaratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:FunctionDeclarator"); - - if (ast->parametersAndQualifiers) { - if (auto childNode = accept(ast->parametersAndQualifiers); - !childNode.is_null()) { - json_.push_back(std::vector{ - "attr:parametersAndQualifiers", std::move(childNode)}); - } - } - - if (ast->trailingReturnType) { - if (auto childNode = accept(ast->trailingReturnType); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:trailingReturnType", - std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "function-declarator"); + accept(ast->parametersAndQualifiers, "parameters-and-qualifiers"); + accept(ast->trailingReturnType, "trailing-return-type"); } void ASTPrinter::visit(ArrayDeclaratorAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ArrayDeclarator"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "array-declarator"); + accept(ast->expression, "expression"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(CxxAttributeAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:CxxAttribute"); - - if (ast->attributeUsingPrefix) { - if (auto childNode = accept(ast->attributeUsingPrefix); - !childNode.is_null()) { - json_.push_back(std::vector{"attr:attributeUsingPrefix", - std::move(childNode)}); - } - } - + fmt::print(out_, "{}\n", "cxx-attribute"); + accept(ast->attributeUsingPrefix, "attribute-using-prefix"); if (ast->attributeList) { - auto elements = nlohmann::json::array(); - elements.push_back("array"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); for (auto it = ast->attributeList; it; it = it->next) { - if (auto childNode = accept(it->value); !childNode.is_null()) { - elements.push_back(std::move(childNode)); - } - } - if (elements.size() > 1) { - json_.push_back( - std::vector{"attr:attributeList", elements}); + accept(it->value); } + --indent_; } } void ASTPrinter::visit(GCCAttributeAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:GCCAttribute"); + fmt::print(out_, "{}\n", "gccattribute"); } void ASTPrinter::visit(AlignasAttributeAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AlignasAttribute"); - - if (ast->expression) { - if (auto childNode = accept(ast->expression); !childNode.is_null()) { - json_.push_back( - std::vector{"attr:expression", std::move(childNode)}); - } - } + fmt::print(out_, "{}\n", "alignas-attribute"); + accept(ast->expression, "expression"); } void ASTPrinter::visit(AsmAttributeAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:AsmAttribute"); - - if (ast->literal) { - json_.push_back(std::vector{ - "attr:literal", - std::vector{"literal", ast->literal->value()}}); - } + fmt::print(out_, "{}\n", "asm-attribute"); } void ASTPrinter::visit(ScopedAttributeTokenAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:ScopedAttributeToken"); + fmt::print(out_, "{}\n", "scoped-attribute-token"); } void ASTPrinter::visit(SimpleAttributeTokenAST* ast) { - json_ = nlohmann::json::array(); - - json_.push_back("ast:SimpleAttributeToken"); + fmt::print(out_, "{}\n", "simple-attribute-token"); } } // namespace cxx diff --git a/src/frontend/cxx/ast_printer.h b/src/frontend/cxx/ast_printer.h index fcb02715..c2597c7d 100644 --- a/src/frontend/cxx/ast_printer.h +++ b/src/frontend/cxx/ast_printer.h @@ -21,25 +21,26 @@ #pragma once #include +#include +#include +#include -#include +#include +#include namespace cxx { class TranslationUnit; class ASTPrinter : ASTVisitor { - TranslationUnit* unit_; - std::vector fileNames_; - nlohmann::json json_; - bool printLocations_ = false; - - auto accept(AST* ast) -> nlohmann::json; - public: - explicit ASTPrinter(TranslationUnit* unit) : unit_(unit) {} + explicit ASTPrinter(TranslationUnit* unit, std::ostream& out); - auto operator()(AST* ast, bool printLocations = false) -> nlohmann::json; + void operator()(AST* ast); + + private: + void accept(AST* ast, std::string_view field = {}); + void accept(const Identifier* id, std::string_view field = {}); void visit(TypeIdAST* ast) override; void visit(NestedNameSpecifierAST* ast) override; @@ -252,6 +253,11 @@ class ASTPrinter : ASTVisitor { void visit(ScopedAttributeTokenAST* ast) override; void visit(SimpleAttributeTokenAST* ast) override; + + private: + TranslationUnit* unit_; + std::ostream& out_; + int indent_ = -1; }; } // namespace cxx diff --git a/src/frontend/cxx/frontend.cc b/src/frontend/cxx/frontend.cc index e0023b59..fec629c8 100644 --- a/src/frontend/cxx/frontend.cc +++ b/src/frontend/cxx/frontend.cc @@ -236,9 +236,8 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool { } if (cli.opt_ast_dump) { - ASTPrinter toJSON(&unit); - fmt::print(std::cout, "{}", - toJSON(unit.ast(), /*print locations*/ true).dump(2)); + ASTPrinter printAST(&unit, std::cout); + printAST(unit.ast()); } } From 83da9eb33ea6baa1910e2713bd849536349a6a69 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 15 Aug 2023 18:14:09 +0000 Subject: [PATCH 03/28] chore: Test AST printing --- tests/unit_tests/CMakeLists.txt | 1 + tests/unit_tests/ast/CMakeLists.txt | 21 +++++++++++++++ .../unit_tests/ast/namespace_definition_01.cc | 27 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/unit_tests/ast/CMakeLists.txt create mode 100644 tests/unit_tests/ast/namespace_definition_01.cc diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index edcb6a6c..5b3a24cc 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -54,3 +54,4 @@ file(GENERATE add_subdirectory(tokens) add_subdirectory(preprocessor) add_subdirectory(parser) +add_subdirectory(ast) diff --git a/tests/unit_tests/ast/CMakeLists.txt b/tests/unit_tests/ast/CMakeLists.txt new file mode 100644 index 00000000..6c50180c --- /dev/null +++ b/tests/unit_tests/ast/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) 2023 Roberto Raggi +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +add_test(NAME ast + COMMAND lit::tool --config-prefix $.lit -v ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/unit_tests/ast/namespace_definition_01.cc b/tests/unit_tests/ast/namespace_definition_01.cc new file mode 100644 index 00000000..31c45570 --- /dev/null +++ b/tests/unit_tests/ast/namespace_definition_01.cc @@ -0,0 +1,27 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines --strict-whitespace + +namespace {} + +inline namespace {} + +namespace ns1 {} + +inline namespace ns1 {} + +namespace n2::n3 {} + +namespace n2::inline n4::n5 {} + +// clang-format off +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: namespace-definition +// CHECK-NEXT: namespace-definition +// CHECK-NEXT: namespace-definition +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: ns1 +// CHECK-NEXT: namespace-definition +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: ns1 +// CHECK-NEXT: namespace-definition +// CHECK-NEXT: namespace-definition From 5df694b0a49aeb4d6783c8859d459f85125fc8fd Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 15 Aug 2023 19:02:03 +0000 Subject: [PATCH 04/28] fix: Store the namespace name in the AST --- packages/cxx-frontend/src/AST.ts | 26 ++++++-- packages/cxx-frontend/src/ASTKind.ts | 1 + packages/cxx-frontend/src/ASTVisitor.ts | 1 + .../cxx-frontend/src/RecursiveASTVisitor.ts | 8 ++- packages/cxx-gen-ast/src/gen_ast_dump_cc.ts | 7 +++ src/frontend/cxx/ast_printer.cc | 25 +++++++- src/frontend/cxx/ast_printer.h | 1 + src/parser/cxx/ast.cc | 24 ++++++-- src/parser/cxx/ast.fbs | 13 +++- src/parser/cxx/ast.h | 23 ++++++- src/parser/cxx/ast_cloner.cc | 32 +++++++++- src/parser/cxx/ast_cloner.h | 1 + src/parser/cxx/ast_decoder.cc | 31 +++++++++- src/parser/cxx/ast_encoder.cc | 60 +++++++++++++++++-- src/parser/cxx/ast_fwd.h | 1 + src/parser/cxx/ast_kind.h | 1 + src/parser/cxx/ast_slot.cc | 28 +++++++-- src/parser/cxx/ast_slot.h | 1 + src/parser/cxx/ast_visitor.h | 1 + src/parser/cxx/default_ast_visitor.cc | 4 ++ src/parser/cxx/default_ast_visitor.h | 1 + src/parser/cxx/parser.cc | 59 +++++++++++++----- src/parser/cxx/parser.h | 10 ++++ src/parser/cxx/private/ast_decoder.h | 2 + src/parser/cxx/private/ast_encoder.h | 1 + src/parser/cxx/recursive_ast_visitor.cc | 12 +++- src/parser/cxx/recursive_ast_visitor.h | 2 + .../unit_tests/ast/namespace_definition_01.cc | 28 +++++++-- 28 files changed, 352 insertions(+), 52 deletions(-) diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index f6a6fcf1..faaa2734 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -2137,6 +2137,21 @@ export class UsingEnumDeclarationAST extends DeclarationAST { } } +export class NestedNamespaceSpecifierAST extends DeclarationAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitNestedNamespaceSpecifier(this, context); + } + getInlineToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + getIdentifierToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + } + getScopeToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } +} + export class NamespaceDefinitionAST extends DeclarationAST { accept(visitor: ASTVisitor, context: Context): Result { return visitor.visitNamespaceDefinition(this, context); @@ -2152,11 +2167,13 @@ export class NamespaceDefinitionAST extends DeclarationAST { yield AST.from(cxx.getListValue(it), this.parser); } } - getNestedNameSpecifier(): NestedNameSpecifierAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + *getNestedNamespaceSpecifierList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 3); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } } - getName(): NameAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + getIdentifierToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } *getExtraAttributeList(): Generator { for (let it = cxx.getASTSlot(this.getHandle(), 5); it; it = cxx.getListNext(it)) { @@ -3344,6 +3361,7 @@ const AST_CONSTRUCTORS: Array { abstract visitAttributeDeclaration(node: ast.AttributeDeclarationAST, context: Context): Result; abstract visitOpaqueEnumDeclaration(node: ast.OpaqueEnumDeclarationAST, context: Context): Result; abstract visitUsingEnumDeclaration(node: ast.UsingEnumDeclarationAST, context: Context): Result; + abstract visitNestedNamespaceSpecifier(node: ast.NestedNamespaceSpecifierAST, context: Context): Result; abstract visitNamespaceDefinition(node: ast.NamespaceDefinitionAST, context: Context): Result; abstract visitNamespaceAliasDefinition(node: ast.NamespaceAliasDefinitionAST, context: Context): Result; abstract visitUsingDirective(node: ast.UsingDirectiveAST, context: Context): Result; diff --git a/packages/cxx-frontend/src/RecursiveASTVisitor.ts b/packages/cxx-frontend/src/RecursiveASTVisitor.ts index 179a0f79..322839da 100644 --- a/packages/cxx-frontend/src/RecursiveASTVisitor.ts +++ b/packages/cxx-frontend/src/RecursiveASTVisitor.ts @@ -664,12 +664,16 @@ export class RecursiveASTVisitor extends ASTVisitor { visitUsingEnumDeclaration(node: ast.UsingEnumDeclarationAST, context: Context): void { } + visitNestedNamespaceSpecifier(node: ast.NestedNamespaceSpecifierAST, context: Context): void { + } + visitNamespaceDefinition(node: ast.NamespaceDefinitionAST, context: Context): void { for (const element of node.getAttributeList()) { this.accept(element, context); } - this.accept(node.getNestedNameSpecifier(), context); - this.accept(node.getName(), context); + for (const element of node.getNestedNamespaceSpecifierList()) { + this.accept(element, context); + } for (const element of node.getExtraAttributeList()) { this.accept(element, context); } diff --git a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts index d9f24feb..74d06f60 100644 --- a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts +++ b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts @@ -55,6 +55,13 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) { emit(` accept(ast->${member.name}, "${fieldName}");`); } else if (member.kind == "attribute" && member.type === "Identifier") { emit(` accept(ast->${member.name}, "${fieldName}");`); + } else if (member.kind == "attribute" && member.type === "bool") { + emit(` ++indent_;`); + emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); + emit( + ` fmt::print(out_, "${fieldName}: {}\\n", ast->${member.name});` + ); + emit(` --indent_;`); } }); emit(`}`); diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 929f0499..7bd0b994 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -1079,6 +1079,15 @@ void ASTPrinter::visit(UsingEnumDeclarationAST* ast) { fmt::print(out_, "{}\n", "using-enum-declaration"); } +void ASTPrinter::visit(NestedNamespaceSpecifierAST* ast) { + fmt::print(out_, "{}\n", "nested-namespace-specifier"); + accept(ast->namespaceName, "namespace-name"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "is-inline: {}\n", ast->isInline); + --indent_; +} + void ASTPrinter::visit(NamespaceDefinitionAST* ast) { fmt::print(out_, "{}\n", "namespace-definition"); if (ast->attributeList) { @@ -1090,8 +1099,15 @@ void ASTPrinter::visit(NamespaceDefinitionAST* ast) { } --indent_; } - accept(ast->nestedNameSpecifier, "nested-name-specifier"); - accept(ast->name, "name"); + if (ast->nestedNamespaceSpecifierList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "nested-namespace-specifier-list"); + for (auto it = ast->nestedNamespaceSpecifierList; it; it = it->next) { + accept(it->value); + } + --indent_; + } if (ast->extraAttributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -1110,6 +1126,11 @@ void ASTPrinter::visit(NamespaceDefinitionAST* ast) { } --indent_; } + accept(ast->namespaceName, "namespace-name"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "is-inline: {}\n", ast->isInline); + --indent_; } void ASTPrinter::visit(NamespaceAliasDefinitionAST* ast) { diff --git a/src/frontend/cxx/ast_printer.h b/src/frontend/cxx/ast_printer.h index c2597c7d..79b8a584 100644 --- a/src/frontend/cxx/ast_printer.h +++ b/src/frontend/cxx/ast_printer.h @@ -178,6 +178,7 @@ class ASTPrinter : ASTVisitor { void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; void visit(UsingEnumDeclarationAST* ast) override; + void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index 60371902..60c5c81d 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -1834,12 +1834,27 @@ auto UsingEnumDeclarationAST::lastSourceLocation() -> SourceLocation { return {}; } +auto NestedNamespaceSpecifierAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(inlineLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(scopeLoc)) return loc; + return {}; +} + +auto NestedNamespaceSpecifierAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(scopeLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(inlineLoc)) return loc; + return {}; +} + auto NamespaceDefinitionAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(inlineLoc)) return loc; if (auto loc = cxx::firstSourceLocation(namespaceLoc)) return loc; if (auto loc = cxx::firstSourceLocation(attributeList)) return loc; - if (auto loc = cxx::firstSourceLocation(nestedNameSpecifier)) return loc; - if (auto loc = cxx::firstSourceLocation(name)) return loc; + if (auto loc = cxx::firstSourceLocation(nestedNamespaceSpecifierList)) + return loc; + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; if (auto loc = cxx::firstSourceLocation(extraAttributeList)) return loc; if (auto loc = cxx::firstSourceLocation(lbraceLoc)) return loc; if (auto loc = cxx::firstSourceLocation(declarationList)) return loc; @@ -1852,8 +1867,9 @@ auto NamespaceDefinitionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(declarationList)) return loc; if (auto loc = cxx::lastSourceLocation(lbraceLoc)) return loc; if (auto loc = cxx::lastSourceLocation(extraAttributeList)) return loc; - if (auto loc = cxx::lastSourceLocation(name)) return loc; - if (auto loc = cxx::lastSourceLocation(nestedNameSpecifier)) return loc; + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(nestedNamespaceSpecifierList)) + return loc; if (auto loc = cxx::lastSourceLocation(attributeList)) return loc; if (auto loc = cxx::lastSourceLocation(namespaceLoc)) return loc; if (auto loc = cxx::lastSourceLocation(inlineLoc)) return loc; diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index 664b1983..7df7e67c 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -91,6 +91,7 @@ union Declaration { AttributeDeclaration, OpaqueEnumDeclaration, UsingEnumDeclaration, + NestedNamespaceSpecifier, NamespaceDefinition, NamespaceAliasDefinition, UsingDirective, @@ -585,14 +586,22 @@ table OpaqueEnumDeclaration /* DeclarationAST */ { table UsingEnumDeclaration /* DeclarationAST */ { } +table NestedNamespaceSpecifier /* DeclarationAST */ { + namespace_name: string; + inline_loc: SourceLocation; + identifier_loc: SourceLocation; + scope_loc: SourceLocation; +} + table NamespaceDefinition /* DeclarationAST */ { attribute_list: [AttributeSpecifier]; - nested_name_specifier: NestedNameSpecifier; - name: Name; + nested_namespace_specifier_list: [NestedNamespaceSpecifier]; extra_attribute_list: [AttributeSpecifier]; declaration_list: [Declaration]; + namespace_name: string; inline_loc: SourceLocation; namespace_loc: SourceLocation; + identifier_loc: SourceLocation; lbrace_loc: SourceLocation; rbrace_loc: SourceLocation; } diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index 0dc34779..c6e30d74 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -2010,6 +2010,23 @@ class UsingEnumDeclarationAST final : public DeclarationAST { auto lastSourceLocation() -> SourceLocation override; }; +class NestedNamespaceSpecifierAST final : public DeclarationAST { + public: + NestedNamespaceSpecifierAST() + : DeclarationAST(ASTKind::NestedNamespaceSpecifier) {} + + SourceLocation inlineLoc; + SourceLocation identifierLoc; + SourceLocation scopeLoc; + const Identifier* namespaceName = nullptr; + bool isInline = false; + + void accept(ASTVisitor* visitor) override { visitor->visit(this); } + + auto firstSourceLocation() -> SourceLocation override; + auto lastSourceLocation() -> SourceLocation override; +}; + class NamespaceDefinitionAST final : public DeclarationAST { public: NamespaceDefinitionAST() : DeclarationAST(ASTKind::NamespaceDefinition) {} @@ -2017,12 +2034,14 @@ class NamespaceDefinitionAST final : public DeclarationAST { SourceLocation inlineLoc; SourceLocation namespaceLoc; List* attributeList = nullptr; - NestedNameSpecifierAST* nestedNameSpecifier = nullptr; - NameAST* name = nullptr; + List* nestedNamespaceSpecifierList = nullptr; + SourceLocation identifierLoc; List* extraAttributeList = nullptr; SourceLocation lbraceLoc; List* declarationList = nullptr; SourceLocation rbraceLoc; + const Identifier* namespaceName = nullptr; + bool isInline = false; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 644c5ad2..9905d161 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -2226,6 +2226,23 @@ void ASTCloner::visit(UsingEnumDeclarationAST* ast) { copy->setChecked(ast->checked()); } +void ASTCloner::visit(NestedNamespaceSpecifierAST* ast) { + auto copy = new (arena_) NestedNamespaceSpecifierAST(); + copy_ = copy; + + copy->setChecked(ast->checked()); + + copy->inlineLoc = ast->inlineLoc; + + copy->identifierLoc = ast->identifierLoc; + + copy->scopeLoc = ast->scopeLoc; + + copy->namespaceName = ast->namespaceName; + + copy->isInline = ast->isInline; +} + void ASTCloner::visit(NamespaceDefinitionAST* ast) { auto copy = new (arena_) NamespaceDefinitionAST(); copy_ = copy; @@ -2245,9 +2262,16 @@ void ASTCloner::visit(NamespaceDefinitionAST* ast) { } } - copy->nestedNameSpecifier = accept(ast->nestedNameSpecifier); + if (auto it = ast->nestedNamespaceSpecifierList) { + auto out = ©->nestedNamespaceSpecifierList; - copy->name = accept(ast->name); + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } + + copy->identifierLoc = ast->identifierLoc; if (auto it = ast->extraAttributeList) { auto out = ©->extraAttributeList; @@ -2270,6 +2294,10 @@ void ASTCloner::visit(NamespaceDefinitionAST* ast) { } copy->rbraceLoc = ast->rbraceLoc; + + copy->namespaceName = ast->namespaceName; + + copy->isInline = ast->isInline; } void ASTCloner::visit(NamespaceAliasDefinitionAST* ast) { diff --git a/src/parser/cxx/ast_cloner.h b/src/parser/cxx/ast_cloner.h index b0279e16..af016aa6 100644 --- a/src/parser/cxx/ast_cloner.h +++ b/src/parser/cxx/ast_cloner.h @@ -166,6 +166,7 @@ class ASTCloner : public ASTVisitor { void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; void visit(UsingEnumDeclarationAST* ast) override; + void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index f74546a4..d561698d 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -419,6 +419,9 @@ auto ASTDecoder::decodeDeclaration(const void* ptr, io::Declaration type) case io::Declaration_UsingEnumDeclaration: return decodeUsingEnumDeclaration( reinterpret_cast(ptr)); + case io::Declaration_NestedNamespaceSpecifier: + return decodeNestedNamespaceSpecifier( + reinterpret_cast(ptr)); case io::Declaration_NamespaceDefinition: return decodeNamespaceDefinition( reinterpret_cast(ptr)); @@ -2305,6 +2308,18 @@ auto ASTDecoder::decodeUsingEnumDeclaration( return ast; } +auto ASTDecoder::decodeNestedNamespaceSpecifier( + const io::NestedNamespaceSpecifier* node) -> NestedNamespaceSpecifierAST* { + if (!node) return nullptr; + + auto ast = new (pool_) NestedNamespaceSpecifierAST(); + if (node->namespace_name()) { + ast->namespaceName = + unit_->control()->getIdentifier(node->namespace_name()->str()); + } + return ast; +} + auto ASTDecoder::decodeNamespaceDefinition(const io::NamespaceDefinition* node) -> NamespaceDefinitionAST* { if (!node) return nullptr; @@ -2319,9 +2334,15 @@ auto ASTDecoder::decodeNamespaceDefinition(const io::NamespaceDefinition* node) inserter = &(*inserter)->next; } } - ast->nestedNameSpecifier = - decodeNestedNameSpecifier(node->nested_name_specifier()); - ast->name = decodeName(node->name(), node->name_type()); + if (node->nested_namespace_specifier_list()) { + auto* inserter = &ast->nestedNamespaceSpecifierList; + for (std::size_t i = 0; i < node->nested_namespace_specifier_list()->size(); + ++i) { + *inserter = new (pool_) List(decodeNestedNamespaceSpecifier( + node->nested_namespace_specifier_list()->Get(i))); + inserter = &(*inserter)->next; + } + } if (node->extra_attribute_list()) { auto* inserter = &ast->extraAttributeList; for (std::size_t i = 0; i < node->extra_attribute_list()->size(); ++i) { @@ -2340,6 +2361,10 @@ auto ASTDecoder::decodeNamespaceDefinition(const io::NamespaceDefinition* node) inserter = &(*inserter)->next; } } + if (node->namespace_name()) { + ast->namespaceName = + unit_->control()->getIdentifier(node->namespace_name()->str()); + } return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index da3b1f0e..ca6ae6b7 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -3237,6 +3237,35 @@ void ASTEncoder::visit(UsingEnumDeclarationAST* ast) { type_ = io::Declaration_UsingEnumDeclaration; } +void ASTEncoder::visit(NestedNamespaceSpecifierAST* ast) { + auto inlineLoc = encodeSourceLocation(ast->inlineLoc); + + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); + + auto scopeLoc = encodeSourceLocation(ast->scopeLoc); + + flatbuffers::Offset namespaceName; + if (ast->namespaceName) { + if (identifiers_.contains(ast->namespaceName)) { + namespaceName = identifiers_.at(ast->namespaceName); + } else { + namespaceName = fbb_.CreateString(ast->namespaceName->value()); + identifiers_.emplace(ast->namespaceName, namespaceName); + } + } + + io::NestedNamespaceSpecifier::Builder builder{fbb_}; + builder.add_inline_loc(inlineLoc.o); + builder.add_identifier_loc(identifierLoc.o); + builder.add_scope_loc(scopeLoc.o); + if (ast->namespaceName) { + builder.add_namespace_name(namespaceName); + } + + offset_ = builder.Finish().Union(); + type_ = io::Declaration_NestedNamespaceSpecifier; +} + void ASTEncoder::visit(NamespaceDefinitionAST* ast) { auto inlineLoc = encodeSourceLocation(ast->inlineLoc); @@ -3256,9 +3285,17 @@ void ASTEncoder::visit(NamespaceDefinitionAST* ast) { auto attributeListOffsetsVector = fbb_.CreateVector(attributeListOffsets); auto attributeListTypesVector = fbb_.CreateVector(attributeListTypes); - const auto nestedNameSpecifier = accept(ast->nestedNameSpecifier); + std::vector> + nestedNamespaceSpecifierListOffsets; + for (auto it = ast->nestedNamespaceSpecifierList; it; it = it->next) { + if (!it->value) continue; + nestedNamespaceSpecifierListOffsets.emplace_back(accept(it->value).o); + } - const auto [name, nameType] = acceptName(ast->name); + auto nestedNamespaceSpecifierListOffsetsVector = + fbb_.CreateVector(nestedNamespaceSpecifierListOffsets); + + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); std::vector> extraAttributeListOffsets; std::vector> @@ -3293,20 +3330,33 @@ void ASTEncoder::visit(NamespaceDefinitionAST* ast) { auto rbraceLoc = encodeSourceLocation(ast->rbraceLoc); + flatbuffers::Offset namespaceName; + if (ast->namespaceName) { + if (identifiers_.contains(ast->namespaceName)) { + namespaceName = identifiers_.at(ast->namespaceName); + } else { + namespaceName = fbb_.CreateString(ast->namespaceName->value()); + identifiers_.emplace(ast->namespaceName, namespaceName); + } + } + io::NamespaceDefinition::Builder builder{fbb_}; builder.add_inline_loc(inlineLoc.o); builder.add_namespace_loc(namespaceLoc.o); builder.add_attribute_list(attributeListOffsetsVector); builder.add_attribute_list_type(attributeListTypesVector); - builder.add_nested_name_specifier(nestedNameSpecifier.o); - builder.add_name(name); - builder.add_name_type(static_cast(nameType)); + builder.add_nested_namespace_specifier_list( + nestedNamespaceSpecifierListOffsetsVector); + builder.add_identifier_loc(identifierLoc.o); builder.add_extra_attribute_list(extraAttributeListOffsetsVector); builder.add_extra_attribute_list_type(extraAttributeListTypesVector); builder.add_lbrace_loc(lbraceLoc.o); builder.add_declaration_list(declarationListOffsetsVector); builder.add_declaration_list_type(declarationListTypesVector); builder.add_rbrace_loc(rbraceLoc.o); + if (ast->namespaceName) { + builder.add_namespace_name(namespaceName); + } offset_ = builder.Finish().Union(); type_ = io::Declaration_NamespaceDefinition; diff --git a/src/parser/cxx/ast_fwd.h b/src/parser/cxx/ast_fwd.h index 5b1d9f8f..ef3d59b1 100644 --- a/src/parser/cxx/ast_fwd.h +++ b/src/parser/cxx/ast_fwd.h @@ -221,6 +221,7 @@ class EmptyDeclarationAST; class AttributeDeclarationAST; class OpaqueEnumDeclarationAST; class UsingEnumDeclarationAST; +class NestedNamespaceSpecifierAST; class NamespaceDefinitionAST; class NamespaceAliasDefinitionAST; class UsingDirectiveAST; diff --git a/src/parser/cxx/ast_kind.h b/src/parser/cxx/ast_kind.h index a336fb05..f05d11a2 100644 --- a/src/parser/cxx/ast_kind.h +++ b/src/parser/cxx/ast_kind.h @@ -173,6 +173,7 @@ enum struct ASTKind { AttributeDeclaration, OpaqueEnumDeclaration, UsingEnumDeclaration, + NestedNamespaceSpecifier, NamespaceDefinition, NamespaceAliasDefinition, UsingDirective, diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index f2658866..6eb84700 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -2531,6 +2531,25 @@ void ASTSlot::visit(UsingEnumDeclarationAST* ast) { slotCount_ = 0; } +void ASTSlot::visit(NestedNamespaceSpecifierAST* ast) { + switch (slot_) { + case 0: + value_ = ast->inlineLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = ast->identifierLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 2: + value_ = ast->scopeLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + } // switch + + slotCount_ = 3; +} + void ASTSlot::visit(NamespaceDefinitionAST* ast) { switch (slot_) { case 0: @@ -2546,12 +2565,13 @@ void ASTSlot::visit(NamespaceDefinitionAST* ast) { slotKind_ = ASTSlotKind::kNodeList; break; case 3: - value_ = reinterpret_cast(ast->nestedNameSpecifier); - slotKind_ = ASTSlotKind::kNode; + value_ = + reinterpret_cast(ast->nestedNamespaceSpecifierList); + slotKind_ = ASTSlotKind::kNodeList; break; case 4: - value_ = reinterpret_cast(ast->name); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->identifierLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 5: value_ = reinterpret_cast(ast->extraAttributeList); diff --git a/src/parser/cxx/ast_slot.h b/src/parser/cxx/ast_slot.h index fb0134e8..b0accf4f 100644 --- a/src/parser/cxx/ast_slot.h +++ b/src/parser/cxx/ast_slot.h @@ -177,6 +177,7 @@ class ASTSlot final : ASTVisitor { void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; void visit(UsingEnumDeclarationAST* ast) override; + void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; diff --git a/src/parser/cxx/ast_visitor.h b/src/parser/cxx/ast_visitor.h index 57e1d470..e489c5e0 100644 --- a/src/parser/cxx/ast_visitor.h +++ b/src/parser/cxx/ast_visitor.h @@ -177,6 +177,7 @@ class ASTVisitor { virtual void visit(AttributeDeclarationAST* ast) = 0; virtual void visit(OpaqueEnumDeclarationAST* ast) = 0; virtual void visit(UsingEnumDeclarationAST* ast) = 0; + virtual void visit(NestedNamespaceSpecifierAST* ast) = 0; virtual void visit(NamespaceDefinitionAST* ast) = 0; virtual void visit(NamespaceAliasDefinitionAST* ast) = 0; virtual void visit(UsingDirectiveAST* ast) = 0; diff --git a/src/parser/cxx/default_ast_visitor.cc b/src/parser/cxx/default_ast_visitor.cc index 7cab1824..15b8388f 100644 --- a/src/parser/cxx/default_ast_visitor.cc +++ b/src/parser/cxx/default_ast_visitor.cc @@ -535,6 +535,10 @@ void DefaultASTVisitor::visit(UsingEnumDeclarationAST* ast) { cxx_runtime_error("visit(UsingEnumDeclarationAST): not implemented"); } +void DefaultASTVisitor::visit(NestedNamespaceSpecifierAST* ast) { + cxx_runtime_error("visit(NestedNamespaceSpecifierAST): not implemented"); +} + void DefaultASTVisitor::visit(NamespaceDefinitionAST* ast) { cxx_runtime_error("visit(NamespaceDefinitionAST): not implemented"); } diff --git a/src/parser/cxx/default_ast_visitor.h b/src/parser/cxx/default_ast_visitor.h index 2754e6ea..aeeb5e1e 100644 --- a/src/parser/cxx/default_ast_visitor.h +++ b/src/parser/cxx/default_ast_visitor.h @@ -175,6 +175,7 @@ class DefaultASTVisitor : public ASTVisitor { void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; void visit(UsingEnumDeclarationAST* ast) override; + void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 79dc6bec..6a7aaaac 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -5712,9 +5712,9 @@ auto Parser::parse_using_enum_declaration(DeclarationAST*& yyasts) -> bool { } auto Parser::parse_namespace_definition(DeclarationAST*& yyast) -> bool { - if (LA().is(TokenKind::T_NAMESPACE) && LA(1).is(TokenKind::T_IDENTIFIER) && - LA(2).is(TokenKind::T_EQUAL)) { - // skip namespace alias definitons + if (lookat(TokenKind::T_NAMESPACE, TokenKind::T_IDENTIFIER, + TokenKind::T_EQUAL)) { + // skip namespace alias definition return false; } @@ -5722,7 +5722,7 @@ auto Parser::parse_namespace_definition(DeclarationAST*& yyast) -> bool { SourceLocation inlineLoc; - match(TokenKind::T_INLINE, inlineLoc); + auto isInline = match(TokenKind::T_INLINE, inlineLoc); SourceLocation namespaceLoc; @@ -5734,33 +5734,62 @@ auto Parser::parse_namespace_definition(DeclarationAST*& yyast) -> bool { auto ast = new (pool) NamespaceDefinitionAST(); yyast = ast; + ast->isInline = isInline; ast->inlineLoc = inlineLoc; ast->namespaceLoc = namespaceLoc; parse_attribute_specifier_seq(ast->attributeList); - const Name* namespaceName = nullptr; + if (lookat(TokenKind::T_IDENTIFIER, TokenKind::T_COLON_COLON)) { + auto it = &ast->nestedNamespaceSpecifierList; - if (LA().is(TokenKind::T_IDENTIFIER) && LA(1).is(TokenKind::T_COLON_COLON)) { - SourceLocation identifierLoc = consumeToken(); + auto name = new (pool) NestedNamespaceSpecifierAST(); - auto id = unit->identifier(identifierLoc); + expect(TokenKind::T_IDENTIFIER, name->identifierLoc); + expect(TokenKind::T_COLON_COLON, name->scopeLoc); - SourceLocation scopeLoc; + name->namespaceName = unit->identifier(name->identifierLoc); + + *it = new (pool) List(name); + it = &(*it)->next; + + while (true) { + const auto saved = currentLocation(); - while (match(TokenKind::T_COLON_COLON, scopeLoc)) { SourceLocation inlineLoc; - match(TokenKind::T_INLINE, inlineLoc); + + auto isInline = match(TokenKind::T_INLINE, inlineLoc); SourceLocation identifierLoc; - expect(TokenKind::T_IDENTIFIER, identifierLoc); - auto id = unit->identifier(identifierLoc); + if (!match(TokenKind::T_IDENTIFIER, identifierLoc)) { + rewind(saved); + break; + } + + SourceLocation scopeLoc; + + if (!match(TokenKind::T_COLON_COLON, scopeLoc)) { + rewind(saved); + break; + } + + auto name = new (pool) NestedNamespaceSpecifierAST(); + name->inlineLoc = inlineLoc; + name->identifierLoc = identifierLoc; + name->scopeLoc = scopeLoc; + name->namespaceName = unit->identifier(name->identifierLoc); + name->isInline = isInline; + + *it = new (pool) List(name); + it = &(*it)->next; } - } else if (parse_name_id(ast->name)) { - // } + match(TokenKind::T_IDENTIFIER, ast->identifierLoc); + + ast->namespaceName = unit->identifier(ast->identifierLoc); + parse_attribute_specifier_seq(ast->extraAttributeList); expect(TokenKind::T_LBRACE, ast->lbraceLoc); diff --git a/src/parser/cxx/parser.h b/src/parser/cxx/parser.h index 50a26b9d..625d65e8 100644 --- a/src/parser/cxx/parser.h +++ b/src/parser/cxx/parser.h @@ -445,6 +445,16 @@ class Parser final { auto parse_identifier_list() -> bool; private: + [[nodiscard]] auto lookat(auto... tokens) { + return lookatHelper(0, tokens...); + } + + [[nodiscard]] auto lookatHelper(int) const { return true; } + + [[nodiscard]] auto lookatHelper(int n, TokenKind tk, auto... rest) const { + return LA(n).is(tk) && lookatHelper(n + 1, rest...); + } + [[nodiscard]] auto LA(int n = 0) const -> const Token&; auto match(TokenKind tk, SourceLocation& location) -> bool; diff --git a/src/parser/cxx/private/ast_decoder.h b/src/parser/cxx/private/ast_decoder.h index 427c93d8..340dbdde 100644 --- a/src/parser/cxx/private/ast_decoder.h +++ b/src/parser/cxx/private/ast_decoder.h @@ -319,6 +319,8 @@ class ASTDecoder { -> OpaqueEnumDeclarationAST*; auto decodeUsingEnumDeclaration(const io::UsingEnumDeclaration* node) -> UsingEnumDeclarationAST*; + auto decodeNestedNamespaceSpecifier(const io::NestedNamespaceSpecifier* node) + -> NestedNamespaceSpecifierAST*; auto decodeNamespaceDefinition(const io::NamespaceDefinition* node) -> NamespaceDefinitionAST*; auto decodeNamespaceAliasDefinition(const io::NamespaceAliasDefinition* node) diff --git a/src/parser/cxx/private/ast_encoder.h b/src/parser/cxx/private/ast_encoder.h index 3a4f2c50..4b5da17f 100644 --- a/src/parser/cxx/private/ast_encoder.h +++ b/src/parser/cxx/private/ast_encoder.h @@ -262,6 +262,7 @@ class ASTEncoder : ASTVisitor { void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; void visit(UsingEnumDeclarationAST* ast) override; + void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; diff --git a/src/parser/cxx/recursive_ast_visitor.cc b/src/parser/cxx/recursive_ast_visitor.cc index c1655c9b..6a771c7c 100644 --- a/src/parser/cxx/recursive_ast_visitor.cc +++ b/src/parser/cxx/recursive_ast_visitor.cc @@ -184,6 +184,11 @@ void RecursiveASTVisitor::acceptInitDeclarator(InitDeclaratorAST* ast) { void RecursiveASTVisitor::acceptEnumBase(EnumBaseAST* ast) { accept(ast); } +void RecursiveASTVisitor::acceptNestedNamespaceSpecifier( + NestedNamespaceSpecifierAST* ast) { + accept(ast); +} + void RecursiveASTVisitor::acceptUsingDeclarator(UsingDeclaratorAST* ast) { accept(ast); } @@ -816,12 +821,15 @@ void RecursiveASTVisitor::visit(OpaqueEnumDeclarationAST* ast) { void RecursiveASTVisitor::visit(UsingEnumDeclarationAST* ast) {} +void RecursiveASTVisitor::visit(NestedNamespaceSpecifierAST* ast) {} + void RecursiveASTVisitor::visit(NamespaceDefinitionAST* ast) { for (auto it = ast->attributeList; it; it = it->next) { acceptAttributeSpecifier(it->value); } - acceptNestedNameSpecifier(ast->nestedNameSpecifier); - acceptName(ast->name); + for (auto it = ast->nestedNamespaceSpecifierList; it; it = it->next) { + acceptNestedNamespaceSpecifier(it->value); + } for (auto it = ast->extraAttributeList; it; it = it->next) { acceptAttributeSpecifier(it->value); } diff --git a/src/parser/cxx/recursive_ast_visitor.h b/src/parser/cxx/recursive_ast_visitor.h index 797e4edc..b63cd414 100644 --- a/src/parser/cxx/recursive_ast_visitor.h +++ b/src/parser/cxx/recursive_ast_visitor.h @@ -71,6 +71,7 @@ class RecursiveASTVisitor : public ASTVisitor { virtual void acceptFunctionBody(FunctionBodyAST* ast); virtual void acceptInitDeclarator(InitDeclaratorAST* ast); virtual void acceptEnumBase(EnumBaseAST* ast); + virtual void acceptNestedNamespaceSpecifier(NestedNamespaceSpecifierAST* ast); virtual void acceptUsingDeclarator(UsingDeclaratorAST* ast); virtual void acceptImportName(ImportNameAST* ast); virtual void acceptTemplateArgument(TemplateArgumentAST* ast); @@ -218,6 +219,7 @@ class RecursiveASTVisitor : public ASTVisitor { void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; void visit(UsingEnumDeclarationAST* ast) override; + void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; diff --git a/tests/unit_tests/ast/namespace_definition_01.cc b/tests/unit_tests/ast/namespace_definition_01.cc index 31c45570..498ffb72 100644 --- a/tests/unit_tests/ast/namespace_definition_01.cc +++ b/tests/unit_tests/ast/namespace_definition_01.cc @@ -1,4 +1,5 @@ -// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines --strict-whitespace +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines +// --strict-whitespace namespace {} @@ -16,12 +17,29 @@ namespace n2::inline n4::n5 {} // CHECK:translation-unit // CHECK-NEXT: declaration-list // CHECK-NEXT: namespace-definition +// CHECK-NEXT: is-inline: false // CHECK-NEXT: namespace-definition +// CHECK-NEXT: is-inline: true // CHECK-NEXT: namespace-definition -// CHECK-NEXT: name: simple-name -// CHECK-NEXT: identifier: ns1 +// CHECK-NEXT: namespace-name: ns1 +// CHECK-NEXT: is-inline: false // CHECK-NEXT: namespace-definition -// CHECK-NEXT: name: simple-name -// CHECK-NEXT: identifier: ns1 +// CHECK-NEXT: namespace-name: ns1 +// CHECK-NEXT: is-inline: true // CHECK-NEXT: namespace-definition +// CHECK-NEXT: nested-namespace-specifier-list +// CHECK-NEXT: nested-namespace-specifier +// CHECK-NEXT: namespace-name: n2 +// CHECK-NEXT: is-inline: false +// CHECK-NEXT: namespace-name: n3 +// CHECK-NEXT: is-inline: false // CHECK-NEXT: namespace-definition +// CHECK-NEXT: nested-namespace-specifier-list +// CHECK-NEXT: nested-namespace-specifier +// CHECK-NEXT: namespace-name: n2 +// CHECK-NEXT: is-inline: false +// CHECK-NEXT: nested-namespace-specifier +// CHECK-NEXT: namespace-name: n4 +// CHECK-NEXT: is-inline: true +// CHECK-NEXT: namespace-name: n5 +// CHECK-NEXT: is-inline: false From bd2c9cd4d1a851e0b86432756af8c34ba76fb01d Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 15 Aug 2023 19:50:33 +0000 Subject: [PATCH 05/28] fix: Add missing attributes to the enumerator AST node --- packages/cxx-frontend/src/AST.ts | 4 +- .../cxx-frontend/src/RecursiveASTVisitor.ts | 1 - packages/cxx-gen-ast/src/gen_ast_dump_cc.ts | 12 +++ src/frontend/cxx/ast_printer.cc | 56 +++++++++++++- src/parser/cxx/ast.cc | 4 +- src/parser/cxx/ast.fbs | 3 +- src/parser/cxx/ast.h | 3 +- src/parser/cxx/ast_cloner.cc | 4 +- src/parser/cxx/ast_decoder.cc | 5 +- src/parser/cxx/ast_encoder.cc | 18 ++++- src/parser/cxx/ast_slot.cc | 4 +- src/parser/cxx/parser.cc | 16 +--- src/parser/cxx/recursive_ast_visitor.cc | 1 - tests/unit_tests/ast/enum_definition_01.cc | 74 +++++++++++++++++++ .../unit_tests/ast/namespace_definition_01.cc | 1 - 15 files changed, 177 insertions(+), 29 deletions(-) create mode 100644 tests/unit_tests/ast/enum_definition_01.cc diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index faaa2734..36e1b7db 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -177,8 +177,8 @@ export class EnumeratorAST extends AST { accept(visitor: ASTVisitor, context: Context): Result { return visitor.visitEnumerator(this, context); } - getName(): NameAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getIdentifierToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } *getAttributeList(): Generator { for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { diff --git a/packages/cxx-frontend/src/RecursiveASTVisitor.ts b/packages/cxx-frontend/src/RecursiveASTVisitor.ts index 322839da..a08ea2ce 100644 --- a/packages/cxx-frontend/src/RecursiveASTVisitor.ts +++ b/packages/cxx-frontend/src/RecursiveASTVisitor.ts @@ -60,7 +60,6 @@ export class RecursiveASTVisitor extends ASTVisitor { } visitEnumerator(node: ast.EnumeratorAST, context: Context): void { - this.accept(node.getName(), context); for (const element of node.getAttributeList()) { this.accept(element, context); } diff --git a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts index 74d06f60..597d28ac 100644 --- a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts +++ b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts @@ -62,6 +62,18 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) { ` fmt::print(out_, "${fieldName}: {}\\n", ast->${member.name});` ); emit(` --indent_;`); + } else if ( + member.kind == "attribute" && + member.type.endsWith("Literal") + ) { + emit(` if (ast->${member.name}) {`); + emit(` ++indent_;`); + emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); + emit( + ` fmt::print(out_, "${fieldName}: {}\\n", ast->${member.name}->value());` + ); + emit(` --indent_;`); + emit(` }`); } }); emit(`}`); diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 7bd0b994..f03a06cf 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -109,7 +109,6 @@ void ASTPrinter::visit(EnumBaseAST* ast) { void ASTPrinter::visit(EnumeratorAST* ast) { fmt::print(out_, "{}\n", "enumerator"); - accept(ast->name, "name"); if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -120,6 +119,7 @@ void ASTPrinter::visit(EnumeratorAST* ast) { --indent_; } accept(ast->expression, "expression"); + accept(ast->identifier, "identifier"); } void ASTPrinter::visit(DeclaratorAST* ast) { @@ -600,6 +600,12 @@ void ASTPrinter::visit(ThisExpressionAST* ast) { void ASTPrinter::visit(CharLiteralExpressionAST* ast) { fmt::print(out_, "{}\n", "char-literal-expression"); + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } } void ASTPrinter::visit(BoolLiteralExpressionAST* ast) { @@ -608,10 +614,22 @@ void ASTPrinter::visit(BoolLiteralExpressionAST* ast) { void ASTPrinter::visit(IntLiteralExpressionAST* ast) { fmt::print(out_, "{}\n", "int-literal-expression"); + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } } void ASTPrinter::visit(FloatLiteralExpressionAST* ast) { fmt::print(out_, "{}\n", "float-literal-expression"); + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } } void ASTPrinter::visit(NullptrLiteralExpressionAST* ast) { @@ -620,10 +638,22 @@ void ASTPrinter::visit(NullptrLiteralExpressionAST* ast) { void ASTPrinter::visit(StringLiteralExpressionAST* ast) { fmt::print(out_, "{}\n", "string-literal-expression"); + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } } void ASTPrinter::visit(UserDefinedStringLiteralExpressionAST* ast) { fmt::print(out_, "{}\n", "user-defined-string-literal-expression"); + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } } void ASTPrinter::visit(IdExpressionAST* ast) { @@ -1040,6 +1070,12 @@ void ASTPrinter::visit(SimpleDeclarationAST* ast) { void ASTPrinter::visit(StaticAssertDeclarationAST* ast) { fmt::print(out_, "{}\n", "static-assert-declaration"); accept(ast->expression, "expression"); + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } } void ASTPrinter::visit(EmptyDeclarationAST* ast) { @@ -1179,6 +1215,12 @@ void ASTPrinter::visit(AsmDeclarationAST* ast) { } --indent_; } + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } } void ASTPrinter::visit(ExportDeclarationAST* ast) { @@ -1308,6 +1350,12 @@ void ASTPrinter::visit(LinkageSpecificationAST* ast) { } --indent_; } + if (ast->stringLiteral) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "string-literal: {}\n", ast->stringLiteral->value()); + --indent_; + } } void ASTPrinter::visit(SimpleNameAST* ast) { @@ -1664,6 +1712,12 @@ void ASTPrinter::visit(AlignasAttributeAST* ast) { void ASTPrinter::visit(AsmAttributeAST* ast) { fmt::print(out_, "{}\n", "asm-attribute"); + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } } void ASTPrinter::visit(ScopedAttributeTokenAST* ast) { diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index 60c5c81d..4cad433b 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -93,7 +93,7 @@ auto EnumBaseAST::lastSourceLocation() -> SourceLocation { } auto EnumeratorAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(name)) return loc; + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; if (auto loc = cxx::firstSourceLocation(attributeList)) return loc; if (auto loc = cxx::firstSourceLocation(equalLoc)) return loc; if (auto loc = cxx::firstSourceLocation(expression)) return loc; @@ -104,7 +104,7 @@ auto EnumeratorAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(expression)) return loc; if (auto loc = cxx::lastSourceLocation(equalLoc)) return loc; if (auto loc = cxx::lastSourceLocation(attributeList)) return loc; - if (auto loc = cxx::lastSourceLocation(name)) return loc; + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; return {}; } diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index 7df7e67c..e15eea2e 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -313,9 +313,10 @@ table EnumBase /* AST */ { } table Enumerator /* AST */ { - name: Name; attribute_list: [AttributeSpecifier]; expression: Expression; + identifier: string; + identifier_loc: SourceLocation; equal_loc: SourceLocation; } diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index c6e30d74..f975b108 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -271,10 +271,11 @@ class EnumeratorAST final : public AST { public: EnumeratorAST() : AST(ASTKind::Enumerator) {} - NameAST* name = nullptr; + SourceLocation identifierLoc; List* attributeList = nullptr; SourceLocation equalLoc; ExpressionAST* expression = nullptr; + const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 9905d161..d1b01fbe 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -120,7 +120,7 @@ void ASTCloner::visit(EnumeratorAST* ast) { copy->setChecked(ast->checked()); - copy->name = accept(ast->name); + copy->identifierLoc = ast->identifierLoc; if (auto it = ast->attributeList) { auto out = ©->attributeList; @@ -134,6 +134,8 @@ void ASTCloner::visit(EnumeratorAST* ast) { copy->equalLoc = ast->equalLoc; copy->expression = accept(ast->expression); + + copy->identifier = ast->identifier; } void ASTCloner::visit(DeclaratorAST* ast) { diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index d561698d..7b6713b2 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -755,7 +755,6 @@ auto ASTDecoder::decodeEnumerator(const io::Enumerator* node) if (!node) return nullptr; auto ast = new (pool_) EnumeratorAST(); - ast->name = decodeName(node->name(), node->name_type()); if (node->attribute_list()) { auto* inserter = &ast->attributeList; for (std::size_t i = 0; i < node->attribute_list()->size(); ++i) { @@ -767,6 +766,10 @@ auto ASTDecoder::decodeEnumerator(const io::Enumerator* node) } ast->expression = decodeExpression(node->expression(), node->expression_type()); + if (node->identifier()) { + ast->identifier = + unit_->control()->getIdentifier(node->identifier()->str()); + } return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index ca6ae6b7..6cd9136d 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -488,7 +488,7 @@ void ASTEncoder::visit(EnumBaseAST* ast) { } void ASTEncoder::visit(EnumeratorAST* ast) { - const auto [name, nameType] = acceptName(ast->name); + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); std::vector> attributeListOffsets; std::vector> @@ -508,14 +508,26 @@ void ASTEncoder::visit(EnumeratorAST* ast) { const auto [expression, expressionType] = acceptExpression(ast->expression); + flatbuffers::Offset identifier; + if (ast->identifier) { + if (identifiers_.contains(ast->identifier)) { + identifier = identifiers_.at(ast->identifier); + } else { + identifier = fbb_.CreateString(ast->identifier->value()); + identifiers_.emplace(ast->identifier, identifier); + } + } + io::Enumerator::Builder builder{fbb_}; - builder.add_name(name); - builder.add_name_type(static_cast(nameType)); + builder.add_identifier_loc(identifierLoc.o); builder.add_attribute_list(attributeListOffsetsVector); builder.add_attribute_list_type(attributeListTypesVector); builder.add_equal_loc(equalLoc.o); builder.add_expression(expression); builder.add_expression_type(static_cast(expressionType)); + if (ast->identifier) { + builder.add_identifier(identifier); + } offset_ = builder.Finish().Union(); } diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index 6eb84700..d5f15aa2 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -139,8 +139,8 @@ void ASTSlot::visit(EnumBaseAST* ast) { void ASTSlot::visit(EnumeratorAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->name); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->identifierLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: value_ = reinterpret_cast(ast->attributeList); diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 6a7aaaac..e0e9727c 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -5651,9 +5651,7 @@ auto Parser::parse_enumerator_list(List*& yyast) -> bool { EnumeratorAST* enumerator = nullptr; - if (!parse_enumerator_definition(enumerator)) { - parse_error("expected an enumerator"); - } + parse_enumerator_definition(enumerator); *it = new (pool) List(enumerator); it = &(*it)->next; @@ -5675,18 +5673,12 @@ auto Parser::parse_enumerator_definition(EnumeratorAST*& yyast) -> bool { } auto Parser::parse_enumerator(EnumeratorAST*& yyast) -> bool { - SourceLocation identifierLoc; - - if (!match(TokenKind::T_IDENTIFIER, identifierLoc)) return false; - - auto name = new (pool) SimpleNameAST(); - name->identifierLoc = identifierLoc; - name->identifier = unit->identifier(name->identifierLoc); - auto ast = new (pool) EnumeratorAST(); yyast = ast; - ast->name = name; + expect(TokenKind::T_IDENTIFIER, ast->identifierLoc); + + ast->identifier = unit->identifier(ast->identifierLoc); parse_attribute_specifier_seq(ast->attributeList); diff --git a/src/parser/cxx/recursive_ast_visitor.cc b/src/parser/cxx/recursive_ast_visitor.cc index 6a771c7c..faf0994f 100644 --- a/src/parser/cxx/recursive_ast_visitor.cc +++ b/src/parser/cxx/recursive_ast_visitor.cc @@ -245,7 +245,6 @@ void RecursiveASTVisitor::visit(EnumBaseAST* ast) { } void RecursiveASTVisitor::visit(EnumeratorAST* ast) { - acceptName(ast->name); for (auto it = ast->attributeList; it; it = it->next) { acceptAttributeSpecifier(it->value); } diff --git a/tests/unit_tests/ast/enum_definition_01.cc b/tests/unit_tests/ast/enum_definition_01.cc new file mode 100644 index 00000000..d3a01b73 --- /dev/null +++ b/tests/unit_tests/ast/enum_definition_01.cc @@ -0,0 +1,74 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +enum Kind { + k1, + k2, + k3, +}; + +enum class Kind2 { + k1 = 0, + k2 = 1, + k3 = 2, +}; + +enum class Kind3 : int { + k1 = 0, + k2 = 1, + k3 = 2, +}; + +// clang-format off +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: enum-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Kind +// CHECK-NEXT: enumerator-list +// CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k1 +// CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k2 +// CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k3 +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: enum-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Kind2 +// CHECK-NEXT: enumerator-list +// CHECK-NEXT: enumerator +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 0 +// CHECK-NEXT: identifier: k1 +// CHECK-NEXT: enumerator +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 1 +// CHECK-NEXT: identifier: k2 +// CHECK-NEXT: enumerator +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 2 +// CHECK-NEXT: identifier: k3 +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: enum-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Kind3 +// CHECK-NEXT: enum-base: enum-base +// CHECK-NEXT: type-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: enumerator-list +// CHECK-NEXT: enumerator +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 0 +// CHECK-NEXT: identifier: k1 +// CHECK-NEXT: enumerator +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 1 +// CHECK-NEXT: identifier: k2 +// CHECK-NEXT: enumerator +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 2 +// CHECK-NEXT: identifier: k3 diff --git a/tests/unit_tests/ast/namespace_definition_01.cc b/tests/unit_tests/ast/namespace_definition_01.cc index 498ffb72..c92ae055 100644 --- a/tests/unit_tests/ast/namespace_definition_01.cc +++ b/tests/unit_tests/ast/namespace_definition_01.cc @@ -1,5 +1,4 @@ // RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines -// --strict-whitespace namespace {} From 3ea986f83093275fddcc4889cab04235162a2ffa Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Wed, 16 Aug 2023 17:40:50 +0000 Subject: [PATCH 06/28] fix: stddef.h: add missing typedefs --- src/lib/cxx/include/stddef.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/lib/cxx/include/stddef.h b/src/lib/cxx/include/stddef.h index 69cf20bf..d238d3fe 100644 --- a/src/lib/cxx/include/stddef.h +++ b/src/lib/cxx/include/stddef.h @@ -1,7 +1,35 @@ -#pragma once +#if !defined(__need_ptrdiff_t) && !defined(__need_size_t) && \ + !defined(__need_wchar_t) && !defined(__need_NULL) && \ + !defined(__need_STDDEF_H_misc) +#define __need_ptrdiff_t +#define __need_size_t +#define __need_wchar_t +#define __need_NULL +#define __need_STDDEF_H_misc +#endif +#ifdef __need_ptrdiff_t +#undef __need_ptrdiff_t typedef long int ptrdiff_t; +#endif /* __need_ptrdiff_t */ + +#ifdef __need_size_t +#undef __need_size_t typedef long unsigned int size_t; +#endif /* __need_size_t */ + +#ifdef __need_wchar_t +#undef __need_wchar_t +#endif /* __need_wchar_t */ + +#ifdef __need_NULL +#undef __need_NULL +#undef NULL +#define NULL 0 +#endif /* __need_NULL */ + +#ifdef __need_STDDEF_H_misc +#undef __need_STDDEF_H_misc typedef long unsigned int rsize_t; typedef struct { @@ -11,3 +39,5 @@ typedef struct { long double __clang_max_align_nonce2 __attribute__((__aligned__(__alignof__(long double)))); } max_align_t; + +#endif /* __need_STDDEF_H_misc */ From 80a34cfd252db8e3a6b0b4ef459b0620cf910c3a Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Wed, 16 Aug 2023 17:47:38 +0000 Subject: [PATCH 07/28] fix: Parse of inline for namespace definitions --- src/parser/cxx/parser.cc | 7 ++++++- tests/unit_tests/ast/namespace_definition_01.cc | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index e0e9727c..afd74ede 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -5778,7 +5778,12 @@ auto Parser::parse_namespace_definition(DeclarationAST*& yyast) -> bool { } } - match(TokenKind::T_IDENTIFIER, ast->identifierLoc); + if (ast->nestedNamespaceSpecifierList) { + ast->isInline = match(TokenKind::T_INLINE, ast->inlineLoc); + expect(TokenKind::T_IDENTIFIER, ast->identifierLoc); + } else { + match(TokenKind::T_IDENTIFIER, ast->identifierLoc); + } ast->namespaceName = unit->identifier(ast->identifierLoc); diff --git a/tests/unit_tests/ast/namespace_definition_01.cc b/tests/unit_tests/ast/namespace_definition_01.cc index c92ae055..25b67913 100644 --- a/tests/unit_tests/ast/namespace_definition_01.cc +++ b/tests/unit_tests/ast/namespace_definition_01.cc @@ -12,6 +12,8 @@ namespace n2::n3 {} namespace n2::inline n4::n5 {} +namespace n2::inline n4::inline n6 {} + // clang-format off // CHECK:translation-unit // CHECK-NEXT: declaration-list @@ -42,3 +44,13 @@ namespace n2::inline n4::n5 {} // CHECK-NEXT: is-inline: true // CHECK-NEXT: namespace-name: n5 // CHECK-NEXT: is-inline: false +// CHECK-NEXT: namespace-definition +// CHECK-NEXT: nested-namespace-specifier-list +// CHECK-NEXT: nested-namespace-specifier +// CHECK-NEXT: namespace-name: n2 +// CHECK-NEXT: is-inline: false +// CHECK-NEXT: nested-namespace-specifier +// CHECK-NEXT: namespace-name: n4 +// CHECK-NEXT: is-inline: true +// CHECK-NEXT: namespace-name: n6 +// CHECK-NEXT: is-inline: true \ No newline at end of file From ad55a0dca106edfbb136d58c60efa87feee6d8d8 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Sat, 19 Aug 2023 15:59:03 +0000 Subject: [PATCH 08/28] chore: Prefer to use Parser::lookat() instead of Parser::LA() --- src/parser/cxx/parser.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index afd74ede..43eadc6e 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -1083,7 +1083,7 @@ auto Parser::parse_simple_capture(LambdaCaptureAST*& yyast) -> bool { return true; } - if (LA().is(TokenKind::T_STAR) && LA(1).is(TokenKind::T_THIS)) { + if (lookat(TokenKind::T_STAR, TokenKind::T_THIS)) { auto ast = new (pool) DerefThisLambdaCaptureAST(); yyast = ast; @@ -2723,7 +2723,7 @@ auto Parser::parse_statement(StatementAST*& yyast) -> bool { return false; } default: - if (LA().is(TokenKind::T_IDENTIFIER) && LA(1).is(TokenKind::T_COLON)) { + if (lookat(TokenKind::T_IDENTIFIER, TokenKind::T_COLON)) { return parse_labeled_statement(yyast); } @@ -7698,7 +7698,7 @@ auto Parser::parse_template_type_parameter(DeclarationAST*& yyast) -> bool { parse_error("expected a type parameter"); } - if ((LA().is(TokenKind::T_IDENTIFIER) && LA(1).is(TokenKind::T_EQUAL)) || + if (lookat(TokenKind::T_IDENTIFIER, TokenKind::T_EQUAL) || LA().is(TokenKind::T_EQUAL)) { auto ast = new (pool) TemplateTypeParameterAST(); yyast = ast; @@ -7764,7 +7764,7 @@ auto Parser::parse_constraint_type_parameter(DeclarationAST*& yyast) -> bool { return false; } - if ((LA().is(TokenKind::T_IDENTIFIER) && LA(1).is(TokenKind::T_EQUAL)) || + if (lookat(TokenKind::T_IDENTIFIER, TokenKind::T_EQUAL) || LA().is(TokenKind::T_EQUAL)) { SourceLocation identifierLoc; From a2fbad8614b80c1991407b60251d4bdb11c97983 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Sat, 19 Aug 2023 16:10:01 +0000 Subject: [PATCH 09/28] fix: Store the value of the boolean literals in the AST --- src/frontend/cxx/ast_printer.cc | 4 +++ src/parser/cxx/ast.fbs | 1 - src/parser/cxx/ast.h | 2 +- src/parser/cxx/ast_cloner.cc | 2 +- src/parser/cxx/ast_decoder.cc | 1 - src/parser/cxx/ast_encoder.cc | 1 - src/parser/cxx/parser.cc | 4 ++- tests/unit_tests/ast/bool_literals_01.cc | 33 ++++++++++++++++++++++++ 8 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 tests/unit_tests/ast/bool_literals_01.cc diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index f03a06cf..eaf55689 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -610,6 +610,10 @@ void ASTPrinter::visit(CharLiteralExpressionAST* ast) { void ASTPrinter::visit(BoolLiteralExpressionAST* ast) { fmt::print(out_, "{}\n", "bool-literal-expression"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "value: {}\n", ast->value); + --indent_; } void ASTPrinter::visit(IntLiteralExpressionAST* ast) { diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index e15eea2e..bdef00b3 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -760,7 +760,6 @@ table CharLiteralExpression /* ExpressionAST */ { } table BoolLiteralExpression /* ExpressionAST */ { - literal: uint32; literal_loc: SourceLocation; } diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index f975b108..f9d09742 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -1021,7 +1021,7 @@ class BoolLiteralExpressionAST final : public ExpressionAST { BoolLiteralExpressionAST() : ExpressionAST(ASTKind::BoolLiteralExpression) {} SourceLocation literalLoc; - TokenKind literal = TokenKind::T_EOF_SYMBOL; + bool value = false; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index d1b01fbe..9a509a69 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -1008,7 +1008,7 @@ void ASTCloner::visit(BoolLiteralExpressionAST* ast) { copy->literalLoc = ast->literalLoc; - copy->literal = ast->literal; + copy->value = ast->value; } void ASTCloner::visit(IntLiteralExpressionAST* ast) { diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index 7b6713b2..ef6f7cc2 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -1499,7 +1499,6 @@ auto ASTDecoder::decodeBoolLiteralExpression( if (!node) return nullptr; auto ast = new (pool_) BoolLiteralExpressionAST(); - ast->literal = static_cast(node->literal()); return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index 6cd9136d..38a0a095 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -1702,7 +1702,6 @@ void ASTEncoder::visit(BoolLiteralExpressionAST* ast) { io::BoolLiteralExpression::Builder builder{fbb_}; builder.add_literal_loc(literalLoc.o); - builder.add_literal(static_cast(ast->literal)); offset_ = builder.Finish().Union(); type_ = io::Expression_BoolLiteralExpression; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 43eadc6e..4cdc4031 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -382,8 +382,10 @@ auto Parser::parse_literal(ExpressionAST*& yyast) -> bool { auto ast = new (pool) BoolLiteralExpressionAST(); yyast = ast; + const auto value = LA().is(TokenKind::T_TRUE); + ast->literalLoc = consumeToken(); - ast->literal = unit->tokenKind(ast->literalLoc); + ast->value = value; return true; } diff --git a/tests/unit_tests/ast/bool_literals_01.cc b/tests/unit_tests/ast/bool_literals_01.cc new file mode 100644 index 00000000..c186d81e --- /dev/null +++ b/tests/unit_tests/ast/bool_literals_01.cc @@ -0,0 +1,33 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +const bool ok = true; +const bool ko = false; + +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: const-qualifier +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: ok +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: bool-literal-expression +// CHECK-NEXT: value: true +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: const-qualifier +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: ko +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: bool-literal-expression +// CHECK-NEXT: value: false From 0583d39b2510497d2aa0b2fe6d9df6cd98c36c01 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Sat, 19 Aug 2023 16:30:15 +0000 Subject: [PATCH 10/28] fix: Print TokenKind in AST dump --- packages/cxx-gen-ast/src/gen_ast_dump_cc.ts | 12 +++ src/frontend/cxx/ast_printer.cc | 96 ++++++++++++++++++++ tests/unit_tests/ast/binary_expression_01.cc | 72 +++++++++++++++ tests/unit_tests/ast/bool_literals_01.cc | 6 +- tests/unit_tests/ast/enum_definition_01.cc | 2 +- 5 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 tests/unit_tests/ast/binary_expression_01.cc diff --git a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts index 597d28ac..2ed78c77 100644 --- a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts +++ b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts @@ -74,6 +74,18 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) { ); emit(` --indent_;`); emit(` }`); + } else if ( + member.kind == "attribute" && + member.type.endsWith("TokenKind") + ) { + emit(` if (ast->${member.name} != TokenKind::T_EOF_SYMBOL) {`); + emit(` ++indent_;`); + emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); + emit( + ` fmt::print(out_, "${fieldName}: {}\\n", Token::spell(ast->${member.name}));` + ); + emit(` --indent_;`); + emit(` }`); } }); emit(`}`); diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index eaf55689..bcd39f03 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -638,6 +638,12 @@ void ASTPrinter::visit(FloatLiteralExpressionAST* ast) { void ASTPrinter::visit(NullptrLiteralExpressionAST* ast) { fmt::print(out_, "{}\n", "nullptr-literal-expression"); + if (ast->literal != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", Token::spell(ast->literal)); + --indent_; + } } void ASTPrinter::visit(StringLiteralExpressionAST* ast) { @@ -679,17 +685,41 @@ void ASTPrinter::visit(NestedExpressionAST* ast) { void ASTPrinter::visit(RightFoldExpressionAST* ast) { fmt::print(out_, "{}\n", "right-fold-expression"); accept(ast->expression, "expression"); + if (ast->op != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "op: {}\n", Token::spell(ast->op)); + --indent_; + } } void ASTPrinter::visit(LeftFoldExpressionAST* ast) { fmt::print(out_, "{}\n", "left-fold-expression"); accept(ast->expression, "expression"); + if (ast->op != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "op: {}\n", Token::spell(ast->op)); + --indent_; + } } void ASTPrinter::visit(FoldExpressionAST* ast) { fmt::print(out_, "{}\n", "fold-expression"); accept(ast->leftExpression, "left-expression"); accept(ast->rightExpression, "right-expression"); + if (ast->op != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "op: {}\n", Token::spell(ast->op)); + --indent_; + } + if (ast->foldOp != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "fold-op: {}\n", Token::spell(ast->foldOp)); + --indent_; + } } void ASTPrinter::visit(LambdaExpressionAST* ast) { @@ -750,23 +780,47 @@ void ASTPrinter::visit(TypeTraitsExpressionAST* ast) { } --indent_; } + if (ast->typeTraits != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "type-traits: {}\n", Token::spell(ast->typeTraits)); + --indent_; + } } void ASTPrinter::visit(UnaryExpressionAST* ast) { fmt::print(out_, "{}\n", "unary-expression"); accept(ast->expression, "expression"); + if (ast->op != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "op: {}\n", Token::spell(ast->op)); + --indent_; + } } void ASTPrinter::visit(BinaryExpressionAST* ast) { fmt::print(out_, "{}\n", "binary-expression"); accept(ast->leftExpression, "left-expression"); accept(ast->rightExpression, "right-expression"); + if (ast->op != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "op: {}\n", Token::spell(ast->op)); + --indent_; + } } void ASTPrinter::visit(AssignmentExpressionAST* ast) { fmt::print(out_, "{}\n", "assignment-expression"); accept(ast->leftExpression, "left-expression"); accept(ast->rightExpression, "right-expression"); + if (ast->op != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "op: {}\n", Token::spell(ast->op)); + --indent_; + } } void ASTPrinter::visit(BracedTypeConstructionAST* ast) { @@ -813,11 +867,23 @@ void ASTPrinter::visit(MemberExpressionAST* ast) { fmt::print(out_, "{}\n", "member-expression"); accept(ast->baseExpression, "base-expression"); accept(ast->name, "name"); + if (ast->accessOp != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "access-op: {}\n", Token::spell(ast->accessOp)); + --indent_; + } } void ASTPrinter::visit(PostIncrExpressionAST* ast) { fmt::print(out_, "{}\n", "post-incr-expression"); accept(ast->baseExpression, "base-expression"); + if (ast->op != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "op: {}\n", Token::spell(ast->op)); + --indent_; + } } void ASTPrinter::visit(ConditionalExpressionAST* ast) { @@ -1379,6 +1445,12 @@ void ASTPrinter::visit(DecltypeNameAST* ast) { void ASTPrinter::visit(OperatorNameAST* ast) { fmt::print(out_, "{}\n", "operator-name"); + if (ast->op != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "op: {}\n", Token::spell(ast->op)); + --indent_; + } } void ASTPrinter::visit(ConversionNameAST* ast) { @@ -1469,14 +1541,32 @@ void ASTPrinter::visit(VoidTypeSpecifierAST* ast) { void ASTPrinter::visit(VaListTypeSpecifierAST* ast) { fmt::print(out_, "{}\n", "va-list-type-specifier"); + if (ast->specifier != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "specifier: {}\n", Token::spell(ast->specifier)); + --indent_; + } } void ASTPrinter::visit(IntegralTypeSpecifierAST* ast) { fmt::print(out_, "{}\n", "integral-type-specifier"); + if (ast->specifier != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "specifier: {}\n", Token::spell(ast->specifier)); + --indent_; + } } void ASTPrinter::visit(FloatingPointTypeSpecifierAST* ast) { fmt::print(out_, "{}\n", "floating-point-type-specifier"); + if (ast->specifier != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "specifier: {}\n", Token::spell(ast->specifier)); + --indent_; + } } void ASTPrinter::visit(ComplexTypeSpecifierAST* ast) { @@ -1646,6 +1736,12 @@ void ASTPrinter::visit(ReferenceOperatorAST* ast) { } --indent_; } + if (ast->refOp != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "ref-op: {}\n", Token::spell(ast->refOp)); + --indent_; + } } void ASTPrinter::visit(PtrToMemberOperatorAST* ast) { diff --git a/tests/unit_tests/ast/binary_expression_01.cc b/tests/unit_tests/ast/binary_expression_01.cc new file mode 100644 index 00000000..07e534f0 --- /dev/null +++ b/tests/unit_tests/ast/binary_expression_01.cc @@ -0,0 +1,72 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +int a = 10; +int b = 20; +int c = 30; +int c = a + b * c; + +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: a +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 10 +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: b +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 20 +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: c +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 30 +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: c +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: binary-expression +// CHECK-NEXT: left-expression: id-expression +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: a +// CHECK-NEXT: right-expression: binary-expression +// CHECK-NEXT: left-expression: id-expression +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: b +// CHECK-NEXT: right-expression: id-expression +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: c +// CHECK-NEXT: op: * +// CHECK-NEXT: op: + diff --git a/tests/unit_tests/ast/bool_literals_01.cc b/tests/unit_tests/ast/bool_literals_01.cc index c186d81e..ef9f3632 100644 --- a/tests/unit_tests/ast/bool_literals_01.cc +++ b/tests/unit_tests/ast/bool_literals_01.cc @@ -9,6 +9,7 @@ const bool ko = false; // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: const-qualifier // CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: bool // CHECK-NEXT: init-declarator-list // CHECK-NEXT: init-declarator // CHECK-NEXT: declarator: declarator @@ -17,11 +18,12 @@ const bool ko = false; // CHECK-NEXT: identifier: ok // CHECK-NEXT: initializer: equal-initializer // CHECK-NEXT: expression: bool-literal-expression -// CHECK-NEXT: value: true +// CHECK-NEXT: value: true // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: const-qualifier // CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: bool // CHECK-NEXT: init-declarator-list // CHECK-NEXT: init-declarator // CHECK-NEXT: declarator: declarator @@ -30,4 +32,4 @@ const bool ko = false; // CHECK-NEXT: identifier: ko // CHECK-NEXT: initializer: equal-initializer // CHECK-NEXT: expression: bool-literal-expression -// CHECK-NEXT: value: false +// CHECK-NEXT: value: false \ No newline at end of file diff --git a/tests/unit_tests/ast/enum_definition_01.cc b/tests/unit_tests/ast/enum_definition_01.cc index d3a01b73..f527f6e0 100644 --- a/tests/unit_tests/ast/enum_definition_01.cc +++ b/tests/unit_tests/ast/enum_definition_01.cc @@ -18,7 +18,6 @@ enum class Kind3 : int { k3 = 2, }; -// clang-format off // CHECK:translation-unit // CHECK-NEXT: declaration-list // CHECK-NEXT: simple-declaration @@ -59,6 +58,7 @@ enum class Kind3 : int { // CHECK-NEXT: enum-base: enum-base // CHECK-NEXT: type-specifier-list // CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int // CHECK-NEXT: enumerator-list // CHECK-NEXT: enumerator // CHECK-NEXT: expression: int-literal-expression From c5b13c8a1d61fdc937982a673c8b72e612f62b0b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Sat, 19 Aug 2023 16:43:17 +0000 Subject: [PATCH 11/28] chore: Reorder the AST nodes in the dump --- packages/cxx-gen-ast/src/gen_ast_dump_cc.ts | 102 +++++++++--------- src/frontend/cxx/ast_printer.cc | 102 +++++++++--------- tests/unit_tests/ast/binary_expression_01.cc | 4 +- tests/unit_tests/ast/enum_definition_01.cc | 12 +-- .../unit_tests/ast/namespace_definition_01.cc | 12 +-- 5 files changed, 117 insertions(+), 115 deletions(-) diff --git a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts index 2ed78c77..06ebbb63 100644 --- a/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts +++ b/packages/cxx-gen-ast/src/gen_ast_dump_cc.ts @@ -19,7 +19,7 @@ // SOFTWARE. import { groupNodesByBaseType } from "./groupNodesByBaseType.js"; -import { AST } from "./parseAST.js"; +import { AST, Member } from "./parseAST.js"; import { cpy_header } from "./cpy_header.js"; import * as fs from "fs"; @@ -34,60 +34,62 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) { const astName = (name: string) => toKebapName(name.slice(0, -3)).slice(1); + const dumpMember = (member: Member) => { + const fieldName = toKebapName(member.name); + if (member.kind === "node-list") { + emit(` if (ast->${member.name}) {`); + emit(` ++indent_;`); + emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); + emit(` fmt::print(out_, "{}\\n", "${fieldName}");`); + emit(` for (auto it = ast->${member.name}; it; it = it->next) {`); + emit(` accept(it->value);`); + emit(` }`); + emit(` --indent_;`); + emit(` }`); + } else if (member.kind === "node") { + emit(` accept(ast->${member.name}, "${fieldName}");`); + } else if (member.kind == "attribute" && member.type === "Identifier") { + emit(` accept(ast->${member.name}, "${fieldName}");`); + } else if (member.kind == "attribute" && member.type === "bool") { + emit(` ++indent_;`); + emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); + emit(` fmt::print(out_, "${fieldName}: {}\\n", ast->${member.name});`); + emit(` --indent_;`); + } else if (member.kind == "attribute" && member.type.endsWith("Literal")) { + emit(` if (ast->${member.name}) {`); + emit(` ++indent_;`); + emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); + emit( + ` fmt::print(out_, "${fieldName}: {}\\n", ast->${member.name}->value());` + ); + emit(` --indent_;`); + emit(` }`); + } else if ( + member.kind == "attribute" && + member.type.endsWith("TokenKind") + ) { + emit(` if (ast->${member.name} != TokenKind::T_EOF_SYMBOL) {`); + emit(` ++indent_;`); + emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); + emit( + ` fmt::print(out_, "${fieldName}: {}\\n", Token::spell(ast->${member.name}));` + ); + emit(` --indent_;`); + emit(` }`); + } + }; + by_base.forEach((nodes) => { nodes.forEach(({ name, members }) => { emit(); emit(`void ASTPrinter::visit(${name}* ast) {`); emit(` fmt::print(out_, "{}\\n", "${astName(name)}");`); - members.forEach((member) => { - const fieldName = toKebapName(member.name); - if (member.kind === "node-list") { - emit(` if (ast->${member.name}) {`); - emit(` ++indent_;`); - emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); - emit(` fmt::print(out_, "{}\\n", "${fieldName}");`); - emit(` for (auto it = ast->${member.name}; it; it = it->next) {`); - emit(` accept(it->value);`); - emit(` }`); - emit(` --indent_;`); - emit(` }`); - } else if (member.kind === "node") { - emit(` accept(ast->${member.name}, "${fieldName}");`); - } else if (member.kind == "attribute" && member.type === "Identifier") { - emit(` accept(ast->${member.name}, "${fieldName}");`); - } else if (member.kind == "attribute" && member.type === "bool") { - emit(` ++indent_;`); - emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); - emit( - ` fmt::print(out_, "${fieldName}: {}\\n", ast->${member.name});` - ); - emit(` --indent_;`); - } else if ( - member.kind == "attribute" && - member.type.endsWith("Literal") - ) { - emit(` if (ast->${member.name}) {`); - emit(` ++indent_;`); - emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); - emit( - ` fmt::print(out_, "${fieldName}: {}\\n", ast->${member.name}->value());` - ); - emit(` --indent_;`); - emit(` }`); - } else if ( - member.kind == "attribute" && - member.type.endsWith("TokenKind") - ) { - emit(` if (ast->${member.name} != TokenKind::T_EOF_SYMBOL) {`); - emit(` ++indent_;`); - emit(` fmt::print(out_, "{:{}}", "", indent_ * 2);`); - emit( - ` fmt::print(out_, "${fieldName}: {}\\n", Token::spell(ast->${member.name}));` - ); - emit(` --indent_;`); - emit(` }`); - } - }); + members + .filter((m) => m.kind === "attribute") + .forEach((member) => dumpMember(member)); + members + .filter((m) => m.kind !== "attribute") + .forEach((member) => dumpMember(member)); emit(`}`); }); }); diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index bcd39f03..fc03f5f8 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -109,6 +109,7 @@ void ASTPrinter::visit(EnumBaseAST* ast) { void ASTPrinter::visit(EnumeratorAST* ast) { fmt::print(out_, "{}\n", "enumerator"); + accept(ast->identifier, "identifier"); if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -119,7 +120,6 @@ void ASTPrinter::visit(EnumeratorAST* ast) { --indent_; } accept(ast->expression, "expression"); - accept(ast->identifier, "identifier"); } void ASTPrinter::visit(DeclaratorAST* ast) { @@ -450,14 +450,14 @@ void ASTPrinter::visit(RefLambdaCaptureAST* ast) { void ASTPrinter::visit(RefInitLambdaCaptureAST* ast) { fmt::print(out_, "{}\n", "ref-init-lambda-capture"); - accept(ast->initializer, "initializer"); accept(ast->identifier, "identifier"); + accept(ast->initializer, "initializer"); } void ASTPrinter::visit(InitLambdaCaptureAST* ast) { fmt::print(out_, "{}\n", "init-lambda-capture"); - accept(ast->initializer, "initializer"); accept(ast->identifier, "identifier"); + accept(ast->initializer, "initializer"); } void ASTPrinter::visit(EqualInitializerAST* ast) { @@ -684,30 +684,28 @@ void ASTPrinter::visit(NestedExpressionAST* ast) { void ASTPrinter::visit(RightFoldExpressionAST* ast) { fmt::print(out_, "{}\n", "right-fold-expression"); - accept(ast->expression, "expression"); if (ast->op != TokenKind::T_EOF_SYMBOL) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "op: {}\n", Token::spell(ast->op)); --indent_; } + accept(ast->expression, "expression"); } void ASTPrinter::visit(LeftFoldExpressionAST* ast) { fmt::print(out_, "{}\n", "left-fold-expression"); - accept(ast->expression, "expression"); if (ast->op != TokenKind::T_EOF_SYMBOL) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "op: {}\n", Token::spell(ast->op)); --indent_; } + accept(ast->expression, "expression"); } void ASTPrinter::visit(FoldExpressionAST* ast) { fmt::print(out_, "{}\n", "fold-expression"); - accept(ast->leftExpression, "left-expression"); - accept(ast->rightExpression, "right-expression"); if (ast->op != TokenKind::T_EOF_SYMBOL) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -720,6 +718,8 @@ void ASTPrinter::visit(FoldExpressionAST* ast) { fmt::print(out_, "fold-op: {}\n", Token::spell(ast->foldOp)); --indent_; } + accept(ast->leftExpression, "left-expression"); + accept(ast->rightExpression, "right-expression"); } void ASTPrinter::visit(LambdaExpressionAST* ast) { @@ -771,6 +771,12 @@ void ASTPrinter::visit(AlignofExpressionAST* ast) { void ASTPrinter::visit(TypeTraitsExpressionAST* ast) { fmt::print(out_, "{}\n", "type-traits-expression"); + if (ast->typeTraits != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "type-traits: {}\n", Token::spell(ast->typeTraits)); + --indent_; + } if (ast->typeIdList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -780,47 +786,41 @@ void ASTPrinter::visit(TypeTraitsExpressionAST* ast) { } --indent_; } - if (ast->typeTraits != TokenKind::T_EOF_SYMBOL) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "type-traits: {}\n", Token::spell(ast->typeTraits)); - --indent_; - } } void ASTPrinter::visit(UnaryExpressionAST* ast) { fmt::print(out_, "{}\n", "unary-expression"); - accept(ast->expression, "expression"); if (ast->op != TokenKind::T_EOF_SYMBOL) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "op: {}\n", Token::spell(ast->op)); --indent_; } + accept(ast->expression, "expression"); } void ASTPrinter::visit(BinaryExpressionAST* ast) { fmt::print(out_, "{}\n", "binary-expression"); - accept(ast->leftExpression, "left-expression"); - accept(ast->rightExpression, "right-expression"); if (ast->op != TokenKind::T_EOF_SYMBOL) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "op: {}\n", Token::spell(ast->op)); --indent_; } + accept(ast->leftExpression, "left-expression"); + accept(ast->rightExpression, "right-expression"); } void ASTPrinter::visit(AssignmentExpressionAST* ast) { fmt::print(out_, "{}\n", "assignment-expression"); - accept(ast->leftExpression, "left-expression"); - accept(ast->rightExpression, "right-expression"); if (ast->op != TokenKind::T_EOF_SYMBOL) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "op: {}\n", Token::spell(ast->op)); --indent_; } + accept(ast->leftExpression, "left-expression"); + accept(ast->rightExpression, "right-expression"); } void ASTPrinter::visit(BracedTypeConstructionAST* ast) { @@ -865,25 +865,25 @@ void ASTPrinter::visit(SubscriptExpressionAST* ast) { void ASTPrinter::visit(MemberExpressionAST* ast) { fmt::print(out_, "{}\n", "member-expression"); - accept(ast->baseExpression, "base-expression"); - accept(ast->name, "name"); if (ast->accessOp != TokenKind::T_EOF_SYMBOL) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "access-op: {}\n", Token::spell(ast->accessOp)); --indent_; } + accept(ast->baseExpression, "base-expression"); + accept(ast->name, "name"); } void ASTPrinter::visit(PostIncrExpressionAST* ast) { fmt::print(out_, "{}\n", "post-incr-expression"); - accept(ast->baseExpression, "base-expression"); if (ast->op != TokenKind::T_EOF_SYMBOL) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "op: {}\n", Token::spell(ast->op)); --indent_; } + accept(ast->baseExpression, "base-expression"); } void ASTPrinter::visit(ConditionalExpressionAST* ast) { @@ -933,8 +933,8 @@ void ASTPrinter::visit(NoexceptExpressionAST* ast) { void ASTPrinter::visit(LabeledStatementAST* ast) { fmt::print(out_, "{}\n", "labeled-statement"); - accept(ast->statement, "statement"); accept(ast->identifier, "identifier"); + accept(ast->statement, "statement"); } void ASTPrinter::visit(CaseStatementAST* ast) { @@ -1092,6 +1092,7 @@ void ASTPrinter::visit(ForRangeDeclarationAST* ast) { void ASTPrinter::visit(AliasDeclarationAST* ast) { fmt::print(out_, "{}\n", "alias-declaration"); + accept(ast->identifier, "identifier"); if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -1102,7 +1103,6 @@ void ASTPrinter::visit(AliasDeclarationAST* ast) { --indent_; } accept(ast->typeId, "type-id"); - accept(ast->identifier, "identifier"); } void ASTPrinter::visit(SimpleDeclarationAST* ast) { @@ -1139,13 +1139,13 @@ void ASTPrinter::visit(SimpleDeclarationAST* ast) { void ASTPrinter::visit(StaticAssertDeclarationAST* ast) { fmt::print(out_, "{}\n", "static-assert-declaration"); - accept(ast->expression, "expression"); if (ast->literal) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "literal: {}\n", ast->literal->value()); --indent_; } + accept(ast->expression, "expression"); } void ASTPrinter::visit(EmptyDeclarationAST* ast) { @@ -1196,6 +1196,11 @@ void ASTPrinter::visit(NestedNamespaceSpecifierAST* ast) { void ASTPrinter::visit(NamespaceDefinitionAST* ast) { fmt::print(out_, "{}\n", "namespace-definition"); + accept(ast->namespaceName, "namespace-name"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "is-inline: {}\n", ast->isInline); + --indent_; if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -1232,18 +1237,13 @@ void ASTPrinter::visit(NamespaceDefinitionAST* ast) { } --indent_; } - accept(ast->namespaceName, "namespace-name"); - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "is-inline: {}\n", ast->isInline); - --indent_; } void ASTPrinter::visit(NamespaceAliasDefinitionAST* ast) { fmt::print(out_, "{}\n", "namespace-alias-definition"); + accept(ast->identifier, "identifier"); accept(ast->nestedNameSpecifier, "nested-name-specifier"); accept(ast->name, "name"); - accept(ast->identifier, "identifier"); } void ASTPrinter::visit(UsingDirectiveAST* ast) { @@ -1276,6 +1276,12 @@ void ASTPrinter::visit(UsingDeclarationAST* ast) { void ASTPrinter::visit(AsmDeclarationAST* ast) { fmt::print(out_, "{}\n", "asm-declaration"); + if (ast->literal) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "literal: {}\n", ast->literal->value()); + --indent_; + } if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -1285,12 +1291,6 @@ void ASTPrinter::visit(AsmDeclarationAST* ast) { } --indent_; } - if (ast->literal) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "literal: {}\n", ast->literal->value()); - --indent_; - } } void ASTPrinter::visit(ExportDeclarationAST* ast) { @@ -1342,12 +1342,13 @@ void ASTPrinter::visit(TemplateDeclarationAST* ast) { void ASTPrinter::visit(TypenameTypeParameterAST* ast) { fmt::print(out_, "{}\n", "typename-type-parameter"); - accept(ast->typeId, "type-id"); accept(ast->identifier, "identifier"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(TemplateTypeParameterAST* ast) { fmt::print(out_, "{}\n", "template-type-parameter"); + accept(ast->identifier, "identifier"); if (ast->templateParameterList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -1359,11 +1360,11 @@ void ASTPrinter::visit(TemplateTypeParameterAST* ast) { } accept(ast->requiresClause, "requires-clause"); accept(ast->name, "name"); - accept(ast->identifier, "identifier"); } void ASTPrinter::visit(TemplatePackTypeParameterAST* ast) { fmt::print(out_, "{}\n", "template-pack-type-parameter"); + accept(ast->identifier, "identifier"); if (ast->templateParameterList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -1373,7 +1374,6 @@ void ASTPrinter::visit(TemplatePackTypeParameterAST* ast) { } --indent_; } - accept(ast->identifier, "identifier"); } void ASTPrinter::visit(DeductionGuideAST* ast) { @@ -1411,6 +1411,12 @@ void ASTPrinter::visit(ParameterDeclarationAST* ast) { void ASTPrinter::visit(LinkageSpecificationAST* ast) { fmt::print(out_, "{}\n", "linkage-specification"); + if (ast->stringLiteral) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "string-literal: {}\n", ast->stringLiteral->value()); + --indent_; + } if (ast->declarationList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -1420,12 +1426,6 @@ void ASTPrinter::visit(LinkageSpecificationAST* ast) { } --indent_; } - if (ast->stringLiteral) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "string-literal: {}\n", ast->stringLiteral->value()); - --indent_; - } } void ASTPrinter::visit(SimpleNameAST* ast) { @@ -1727,6 +1727,12 @@ void ASTPrinter::visit(PointerOperatorAST* ast) { void ASTPrinter::visit(ReferenceOperatorAST* ast) { fmt::print(out_, "{}\n", "reference-operator"); + if (ast->refOp != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "ref-op: {}\n", Token::spell(ast->refOp)); + --indent_; + } if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); @@ -1736,12 +1742,6 @@ void ASTPrinter::visit(ReferenceOperatorAST* ast) { } --indent_; } - if (ast->refOp != TokenKind::T_EOF_SYMBOL) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "ref-op: {}\n", Token::spell(ast->refOp)); - --indent_; - } } void ASTPrinter::visit(PtrToMemberOperatorAST* ast) { diff --git a/tests/unit_tests/ast/binary_expression_01.cc b/tests/unit_tests/ast/binary_expression_01.cc index 07e534f0..a599e2a3 100644 --- a/tests/unit_tests/ast/binary_expression_01.cc +++ b/tests/unit_tests/ast/binary_expression_01.cc @@ -58,15 +58,15 @@ int c = a + b * c; // CHECK-NEXT: identifier: c // CHECK-NEXT: initializer: equal-initializer // CHECK-NEXT: expression: binary-expression +// CHECK-NEXT: op: + // CHECK-NEXT: left-expression: id-expression // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: a // CHECK-NEXT: right-expression: binary-expression +// CHECK-NEXT: op: * // CHECK-NEXT: left-expression: id-expression // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: b // CHECK-NEXT: right-expression: id-expression // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: c -// CHECK-NEXT: op: * -// CHECK-NEXT: op: + diff --git a/tests/unit_tests/ast/enum_definition_01.cc b/tests/unit_tests/ast/enum_definition_01.cc index f527f6e0..8368fc5a 100644 --- a/tests/unit_tests/ast/enum_definition_01.cc +++ b/tests/unit_tests/ast/enum_definition_01.cc @@ -39,17 +39,17 @@ enum class Kind3 : int { // CHECK-NEXT: identifier: Kind2 // CHECK-NEXT: enumerator-list // CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k1 // CHECK-NEXT: expression: int-literal-expression // CHECK-NEXT: literal: 0 -// CHECK-NEXT: identifier: k1 // CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k2 // CHECK-NEXT: expression: int-literal-expression // CHECK-NEXT: literal: 1 -// CHECK-NEXT: identifier: k2 // CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k3 // CHECK-NEXT: expression: int-literal-expression // CHECK-NEXT: literal: 2 -// CHECK-NEXT: identifier: k3 // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: enum-specifier @@ -61,14 +61,14 @@ enum class Kind3 : int { // CHECK-NEXT: specifier: int // CHECK-NEXT: enumerator-list // CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k1 // CHECK-NEXT: expression: int-literal-expression // CHECK-NEXT: literal: 0 -// CHECK-NEXT: identifier: k1 // CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k2 // CHECK-NEXT: expression: int-literal-expression // CHECK-NEXT: literal: 1 -// CHECK-NEXT: identifier: k2 // CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: k3 // CHECK-NEXT: expression: int-literal-expression // CHECK-NEXT: literal: 2 -// CHECK-NEXT: identifier: k3 diff --git a/tests/unit_tests/ast/namespace_definition_01.cc b/tests/unit_tests/ast/namespace_definition_01.cc index 25b67913..2f31f611 100644 --- a/tests/unit_tests/ast/namespace_definition_01.cc +++ b/tests/unit_tests/ast/namespace_definition_01.cc @@ -28,13 +28,15 @@ namespace n2::inline n4::inline n6 {} // CHECK-NEXT: namespace-name: ns1 // CHECK-NEXT: is-inline: true // CHECK-NEXT: namespace-definition +// CHECK-NEXT: namespace-name: n3 +// CHECK-NEXT: is-inline: false // CHECK-NEXT: nested-namespace-specifier-list // CHECK-NEXT: nested-namespace-specifier // CHECK-NEXT: namespace-name: n2 // CHECK-NEXT: is-inline: false -// CHECK-NEXT: namespace-name: n3 -// CHECK-NEXT: is-inline: false // CHECK-NEXT: namespace-definition +// CHECK-NEXT: namespace-name: n5 +// CHECK-NEXT: is-inline: false // CHECK-NEXT: nested-namespace-specifier-list // CHECK-NEXT: nested-namespace-specifier // CHECK-NEXT: namespace-name: n2 @@ -42,9 +44,9 @@ namespace n2::inline n4::inline n6 {} // CHECK-NEXT: nested-namespace-specifier // CHECK-NEXT: namespace-name: n4 // CHECK-NEXT: is-inline: true -// CHECK-NEXT: namespace-name: n5 -// CHECK-NEXT: is-inline: false // CHECK-NEXT: namespace-definition +// CHECK-NEXT: namespace-name: n6 +// CHECK-NEXT: is-inline: true // CHECK-NEXT: nested-namespace-specifier-list // CHECK-NEXT: nested-namespace-specifier // CHECK-NEXT: namespace-name: n2 @@ -52,5 +54,3 @@ namespace n2::inline n4::inline n6 {} // CHECK-NEXT: nested-namespace-specifier // CHECK-NEXT: namespace-name: n4 // CHECK-NEXT: is-inline: true -// CHECK-NEXT: namespace-name: n6 -// CHECK-NEXT: is-inline: true \ No newline at end of file From 606acd5d6e71de39c9139671e455e24b8ceab78a Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Sun, 20 Aug 2023 06:43:24 +0000 Subject: [PATCH 12/28] chore: Add test for class definition AST --- tests/unit_tests/ast/class_definition_01.cc | 65 +++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/unit_tests/ast/class_definition_01.cc diff --git a/tests/unit_tests/ast/class_definition_01.cc b/tests/unit_tests/ast/class_definition_01.cc new file mode 100644 index 00000000..f5b6dc55 --- /dev/null +++ b/tests/unit_tests/ast/class_definition_01.cc @@ -0,0 +1,65 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +class EmptyClass {}; + +class OtherEmptyClass {}; + +class FinalClass final {}; + +class DerivedClass : public EmptyClass {}; + +class DerivedClass2 : public EmptyClass, private OtherEmptyClass {}; + +class DerivedClass3 : virtual public EmptyClass {}; + +// clang-format off +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: EmptyClass +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: OtherEmptyClass +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: FinalClass +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: DerivedClass +// CHECK-NEXT: base-clause: base-clause +// CHECK-NEXT: base-specifier-list +// CHECK-NEXT: base-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: EmptyClass +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: DerivedClass2 +// CHECK-NEXT: base-clause: base-clause +// CHECK-NEXT: base-specifier-list +// CHECK-NEXT: base-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: EmptyClass +// CHECK-NEXT: base-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: OtherEmptyClass +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: DerivedClass3 +// CHECK-NEXT: base-clause: base-clause +// CHECK-NEXT: base-specifier-list +// CHECK-NEXT: base-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: EmptyClass From 97cb51e3dc09875cdcd3e9e59e0a073455a1a146 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Sun, 20 Aug 2023 07:06:03 +0000 Subject: [PATCH 13/28] fix: Parse of class virt specifiers --- packages/cxx-frontend/src/AST.ts | 11 ++-- src/frontend/cxx/ast_printer.cc | 4 ++ src/parser/cxx/ast.cc | 2 + src/parser/cxx/ast.fbs | 1 + src/parser/cxx/ast.h | 2 + src/parser/cxx/ast_cloner.cc | 4 ++ src/parser/cxx/ast_encoder.cc | 3 ++ src/parser/cxx/ast_slot.cc | 12 +++-- src/parser/cxx/parser.cc | 56 ++++++++++++--------- src/parser/cxx/parser.h | 12 ++--- tests/unit_tests/ast/class_definition_01.cc | 6 +++ 11 files changed, 76 insertions(+), 37 deletions(-) diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index 36e1b7db..2d4a24b1 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -2976,19 +2976,22 @@ export class ClassSpecifierAST extends SpecifierAST { getName(): NameAST | undefined { return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } + getFinalToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } getBaseClause(): BaseClauseAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } getLbraceToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + return Token.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); } *getDeclarationList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 5); it; it = cxx.getListNext(it)) { + for (let it = cxx.getASTSlot(this.getHandle(), 6); it; it = cxx.getListNext(it)) { yield AST.from(cxx.getListValue(it), this.parser); } } getRbraceToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); + return Token.from(cxx.getASTSlot(this.getHandle(), 7), this.parser); } } diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index fc03f5f8..1585be13 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -1656,6 +1656,10 @@ void ASTPrinter::visit(EnumSpecifierAST* ast) { void ASTPrinter::visit(ClassSpecifierAST* ast) { fmt::print(out_, "{}\n", "class-specifier"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "is-final: {}\n", ast->isFinal); + --indent_; if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index 4cad433b..2a6f86b9 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -2576,6 +2576,7 @@ auto ClassSpecifierAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(classLoc)) return loc; if (auto loc = cxx::firstSourceLocation(attributeList)) return loc; if (auto loc = cxx::firstSourceLocation(name)) return loc; + if (auto loc = cxx::firstSourceLocation(finalLoc)) return loc; if (auto loc = cxx::firstSourceLocation(baseClause)) return loc; if (auto loc = cxx::firstSourceLocation(lbraceLoc)) return loc; if (auto loc = cxx::firstSourceLocation(declarationList)) return loc; @@ -2588,6 +2589,7 @@ auto ClassSpecifierAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(declarationList)) return loc; if (auto loc = cxx::lastSourceLocation(lbraceLoc)) return loc; if (auto loc = cxx::lastSourceLocation(baseClause)) return loc; + if (auto loc = cxx::lastSourceLocation(finalLoc)) return loc; if (auto loc = cxx::lastSourceLocation(name)) return loc; if (auto loc = cxx::lastSourceLocation(attributeList)) return loc; if (auto loc = cxx::lastSourceLocation(classLoc)) return loc; diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index bdef00b3..089e30ed 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -1354,6 +1354,7 @@ table ClassSpecifier /* SpecifierAST */ { base_clause: BaseClause; declaration_list: [Declaration]; class_loc: SourceLocation; + final_loc: SourceLocation; lbrace_loc: SourceLocation; rbrace_loc: SourceLocation; } diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index f9d09742..834eb528 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -2788,10 +2788,12 @@ class ClassSpecifierAST final : public SpecifierAST { SourceLocation classLoc; List* attributeList = nullptr; NameAST* name = nullptr; + SourceLocation finalLoc; BaseClauseAST* baseClause = nullptr; SourceLocation lbraceLoc; List* declarationList = nullptr; SourceLocation rbraceLoc; + bool isFinal = false; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 9a509a69..0bd3fe52 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -3110,6 +3110,8 @@ void ASTCloner::visit(ClassSpecifierAST* ast) { copy->name = accept(ast->name); + copy->finalLoc = ast->finalLoc; + copy->baseClause = accept(ast->baseClause); copy->lbraceLoc = ast->lbraceLoc; @@ -3124,6 +3126,8 @@ void ASTCloner::visit(ClassSpecifierAST* ast) { } copy->rbraceLoc = ast->rbraceLoc; + + copy->isFinal = ast->isFinal; } void ASTCloner::visit(TypenameSpecifierAST* ast) { diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index 38a0a095..5a4c05b2 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -4475,6 +4475,8 @@ void ASTEncoder::visit(ClassSpecifierAST* ast) { const auto [name, nameType] = acceptName(ast->name); + auto finalLoc = encodeSourceLocation(ast->finalLoc); + const auto baseClause = accept(ast->baseClause); auto lbraceLoc = encodeSourceLocation(ast->lbraceLoc); @@ -4500,6 +4502,7 @@ void ASTEncoder::visit(ClassSpecifierAST* ast) { builder.add_attribute_list_type(attributeListTypesVector); builder.add_name(name); builder.add_name_type(static_cast(nameType)); + builder.add_final_loc(finalLoc.o); builder.add_base_clause(baseClause.o); builder.add_lbrace_loc(lbraceLoc.o); builder.add_declaration_list(declarationListOffsetsVector); diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index d5f15aa2..be9406c4 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -3539,24 +3539,28 @@ void ASTSlot::visit(ClassSpecifierAST* ast) { slotKind_ = ASTSlotKind::kNode; break; case 3: + value_ = ast->finalLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 4: value_ = reinterpret_cast(ast->baseClause); slotKind_ = ASTSlotKind::kNode; break; - case 4: + case 5: value_ = ast->lbraceLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 5: + case 6: value_ = reinterpret_cast(ast->declarationList); slotKind_ = ASTSlotKind::kNodeList; break; - case 6: + case 7: value_ = ast->rbraceLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 7; + slotCount_ = 8; } void ASTSlot::visit(TypenameSpecifierAST* ast) { diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 4cdc4031..57bcad69 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -237,16 +237,11 @@ auto Parser::parse(UnitAST*& ast) -> bool { return parsed; } -auto Parser::parse_id(const Identifier* id) -> bool { - SourceLocation identifierLoc; - return parse_id(id, identifierLoc); -} - auto Parser::parse_id(const Identifier* id, SourceLocation& loc) -> bool { - SourceLocation location; - if (!match(TokenKind::T_IDENTIFIER, location)) return false; - if (unit->identifier(location) != id) return false; - loc = location; + loc = {}; + if (LA().isNot(TokenKind::T_IDENTIFIER)) return false; + if (unit->identifier(currentLocation()) != id)return false; + loc = consumeToken(); return true; } @@ -336,9 +331,13 @@ auto Parser::parse_module_keyword(SourceLocation& loc) -> bool { return true; } -auto Parser::parse_final() -> bool { return parse_id(final_id); } +auto Parser::parse_final(SourceLocation& loc) -> bool { + return parse_id(final_id, loc); +} -auto Parser::parse_override() -> bool { return parse_id(override_id); } +auto Parser::parse_override(SourceLocation& loc) -> bool { + return parse_id(override_id, loc); +} auto Parser::parse_type_name(NameAST*& yyast) -> bool { const auto start = currentLocation(); @@ -468,7 +467,9 @@ auto Parser::parse_module_head() -> bool { match(TokenKind::T_EXPORT, exportLoc); - const auto is_module = parse_id(module_id); + SourceLocation moduleLoc; + + const auto is_module = parse_id(module_id, moduleLoc); rewind(start); @@ -5405,9 +5406,11 @@ auto Parser::parse_expr_or_braced_init_list(ExpressionAST*& yyast) -> bool { } auto Parser::parse_virt_specifier_seq() -> bool { - if (!parse_virt_specifier()) return false; + SourceLocation finalLoc; + + if (!parse_virt_specifier(finalLoc)) return false; - while (parse_virt_specifier()) { + while (parse_virt_specifier(finalLoc)) { // } @@ -6624,8 +6627,10 @@ auto Parser::parse_class_specifier(SpecifierAST*& yyast) -> bool { List* attributeList = nullptr; NameAST* className = nullptr; BaseClauseAST* baseClause = nullptr; + SourceLocation finalLoc; - if (!parse_class_head(classLoc, attributeList, className, baseClause)) { + if (!parse_class_head(classLoc, attributeList, className, finalLoc, + baseClause)) { class_specifiers_.emplace( start, std::make_tuple(currentLocation(), @@ -6651,9 +6656,14 @@ auto Parser::parse_class_specifier(SpecifierAST*& yyast) -> bool { ast->classLoc = classLoc; ast->attributeList = attributeList; ast->name = className; + ast->finalLoc = finalLoc; ast->baseClause = baseClause; ast->lbraceLoc = lbraceLoc; + if (finalLoc) { + ast->isFinal = true; + } + if (!match(TokenKind::T_RBRACE, ast->rbraceLoc)) { if (!parse_class_body(ast->declarationList)) { parse_error("expected class body"); @@ -6700,14 +6710,14 @@ auto Parser::parse_class_body(List*& yyast) -> bool { auto Parser::parse_class_head(SourceLocation& classLoc, List*& attributeList, - NameAST*& name, BaseClauseAST*& baseClause) - -> bool { + NameAST*& name, SourceLocation& finalLoc, + BaseClauseAST*& baseClause) -> bool { if (!parse_class_key(classLoc)) return false; parse_attribute_specifier_seq(attributeList); if (parse_class_head_name(name)) { - parse_class_virt_specifier(); + parse_class_virt_specifier(finalLoc); } parse_base_clause(baseClause); @@ -6733,8 +6743,8 @@ auto Parser::parse_class_head_name(NameAST*& yyast) -> bool { return true; } -auto Parser::parse_class_virt_specifier() -> bool { - if (!parse_final()) return false; +auto Parser::parse_class_virt_specifier(SourceLocation& finalLoc) -> bool { + if (!parse_final(finalLoc)) return false; return true; } @@ -7028,10 +7038,10 @@ auto Parser::parse_member_declarator(InitDeclaratorAST*& yyast, return true; } -auto Parser::parse_virt_specifier() -> bool { - if (parse_final()) return true; +auto Parser::parse_virt_specifier(SourceLocation& loc) -> bool { + if (parse_final(loc)) return true; - if (parse_override()) return true; + if (parse_override(loc)) return true; return false; } diff --git a/src/parser/cxx/parser.h b/src/parser/cxx/parser.h index 625d65e8..fc9a5f8a 100644 --- a/src/parser/cxx/parser.h +++ b/src/parser/cxx/parser.h @@ -97,7 +97,6 @@ class Parser final { return true; } - auto parse_id(const Identifier* id) -> bool; auto parse_id(const Identifier* id, SourceLocation& loc) -> bool; auto parse_nospace() -> bool; auto parse_greater_greater() -> bool; @@ -107,8 +106,8 @@ class Parser final { auto parse_export_keyword(SourceLocation& loc) -> bool; auto parse_import_keyword(SourceLocation& loc) -> bool; auto parse_module_keyword(SourceLocation& loc) -> bool; - auto parse_final() -> bool; - auto parse_override() -> bool; + auto parse_final(SourceLocation& loc) -> bool; + auto parse_override(SourceLocation& loc) -> bool; auto parse_name_id(NameAST*& yyast) -> bool; auto parse_literal(ExpressionAST*& yyast) -> bool; auto parse_translation_unit(UnitAST*& yyast) -> bool; @@ -383,9 +382,10 @@ class Parser final { auto parse_class_body(List*& yyast) -> bool; auto parse_class_head(SourceLocation& classLoc, List*& attributeList, - NameAST*& name, BaseClauseAST*& baseClause) -> bool; + NameAST*& name, SourceLocation& finalLoc, + BaseClauseAST*& baseClause) -> bool; auto parse_class_head_name(NameAST*& yyast) -> bool; - auto parse_class_virt_specifier() -> bool; + auto parse_class_virt_specifier(SourceLocation& loc) -> bool; auto parse_class_key(SourceLocation& classLoc) -> bool; auto parse_member_specification(DeclarationAST*& yyast) -> bool; auto parse_member_declaration(DeclarationAST*& yyast) -> bool; @@ -395,7 +395,7 @@ class Parser final { const DeclSpecs& specs) -> bool; auto parse_member_declarator(InitDeclaratorAST*& yyast, const DeclSpecs& specs) -> bool; - auto parse_virt_specifier() -> bool; + auto parse_virt_specifier(SourceLocation& loc) -> bool; auto parse_pure_specifier() -> bool; auto parse_conversion_function_id(NameAST*& yyast) -> bool; auto parse_base_clause(BaseClauseAST*& yyast) -> bool; diff --git a/tests/unit_tests/ast/class_definition_01.cc b/tests/unit_tests/ast/class_definition_01.cc index f5b6dc55..dc5b05cd 100644 --- a/tests/unit_tests/ast/class_definition_01.cc +++ b/tests/unit_tests/ast/class_definition_01.cc @@ -18,21 +18,25 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: EmptyClass // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: OtherEmptyClass // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: is-final: true // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: FinalClass // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: DerivedClass // CHECK-NEXT: base-clause: base-clause @@ -43,6 +47,7 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: DerivedClass2 // CHECK-NEXT: base-clause: base-clause @@ -56,6 +61,7 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: DerivedClass3 // CHECK-NEXT: base-clause: base-clause From edd275e6455bcb8f7e6a18d42be10b62d087e690 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Sun, 20 Aug 2023 07:13:41 +0000 Subject: [PATCH 14/28] ci: Parse the entire source tree --- .github/workflows/ci.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d56404f..3b3280fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,20 @@ jobs: run: | ctest --output-on-failure + - name: Parse C++ source files + run: | + for i in src/parser/cxx/*.cc src/frontend/cxx/*.cc; do + echo "Parsing $i" + ./build/src/frontend/cxx \ + -I src/parser \ + -I build/_deps/fmt-src/include \ + -I build/_deps/utfcpp-src/source \ + -I build/_deps/flatbuffers-src/include \ + -I build/src/parser \ + -DCXX_NO_FILESYSTEM \ + $i + done + build-windows: runs-on: windows-latest From 613a0709b34e25a5b28ddec470d2577c375dad32 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 12:18:28 +0000 Subject: [PATCH 15/28] fix: Set access and virt specifier to the base specifier ast nodes --- src/frontend/cxx/ast_printer.cc | 11 +++++++++++ src/parser/cxx/ast.fbs | 1 + src/parser/cxx/ast.h | 2 ++ src/parser/cxx/ast_cloner.cc | 4 ++++ src/parser/cxx/ast_decoder.cc | 1 + src/parser/cxx/ast_encoder.cc | 2 ++ src/parser/cxx/parser.cc | 9 +++++++-- tests/unit_tests/ast/class_definition_01.cc | 8 ++++++++ 8 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 1585be13..b003ed9c 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -154,6 +154,17 @@ void ASTPrinter::visit(InitDeclaratorAST* ast) { void ASTPrinter::visit(BaseSpecifierAST* ast) { fmt::print(out_, "{}\n", "base-specifier"); + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "is-virtual: {}\n", ast->isVirtual); + --indent_; + if (ast->accessSpecifier != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "access-specifier: {}\n", + Token::spell(ast->accessSpecifier)); + --indent_; + } if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index 089e30ed..65d22c8b 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -335,6 +335,7 @@ table InitDeclarator /* AST */ { table BaseSpecifier /* AST */ { attribute_list: [AttributeSpecifier]; name: Name; + access_specifier: uint32; } table BaseClause /* AST */ { diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index 834eb528..79b2e0f8 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -317,6 +317,8 @@ class BaseSpecifierAST final : public AST { List* attributeList = nullptr; NameAST* name = nullptr; + bool isVirtual = false; + TokenKind accessSpecifier = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 0bd3fe52..b791091a 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -194,6 +194,10 @@ void ASTCloner::visit(BaseSpecifierAST* ast) { } copy->name = accept(ast->name); + + copy->isVirtual = ast->isVirtual; + + copy->accessSpecifier = ast->accessSpecifier; } void ASTCloner::visit(BaseClauseAST* ast) { diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index ef6f7cc2..c567989d 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -828,6 +828,7 @@ auto ASTDecoder::decodeBaseSpecifier(const io::BaseSpecifier* node) } } ast->name = decodeName(node->name(), node->name_type()); + ast->accessSpecifier = static_cast(node->access_specifier()); return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index 5a4c05b2..d3d5e1ea 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -613,6 +613,8 @@ void ASTEncoder::visit(BaseSpecifierAST* ast) { builder.add_attribute_list_type(attributeListTypesVector); builder.add_name(name); builder.add_name_type(static_cast(nameType)); + builder.add_access_specifier( + static_cast(ast->accessSpecifier)); offset_ = builder.Finish().Union(); } diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 57bcad69..14214df3 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -240,7 +240,7 @@ auto Parser::parse(UnitAST*& ast) -> bool { auto Parser::parse_id(const Identifier* id, SourceLocation& loc) -> bool { loc = {}; if (LA().isNot(TokenKind::T_IDENTIFIER)) return false; - if (unit->identifier(currentLocation()) != id)return false; + if (unit->identifier(currentLocation()) != id) return false; loc = consumeToken(); return true; } @@ -7150,9 +7150,14 @@ auto Parser::parse_base_specifier(BaseSpecifierAST*& yyast) -> bool { SourceLocation accessLoc; if (match(TokenKind::T_VIRTUAL, virtualLoc)) { + ast->isVirtual = true; parse_access_specifier(accessLoc); } else if (parse_access_specifier(accessLoc)) { - match(TokenKind::T_VIRTUAL, virtualLoc); + ast->isVirtual = match(TokenKind::T_VIRTUAL, virtualLoc); + } + + if (accessLoc) { + ast->accessSpecifier = unit->tokenKind(accessLoc); } if (!parse_class_or_decltype(ast->name)) return false; diff --git a/tests/unit_tests/ast/class_definition_01.cc b/tests/unit_tests/ast/class_definition_01.cc index dc5b05cd..fdd56d93 100644 --- a/tests/unit_tests/ast/class_definition_01.cc +++ b/tests/unit_tests/ast/class_definition_01.cc @@ -42,6 +42,8 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: base-clause: base-clause // CHECK-NEXT: base-specifier-list // CHECK-NEXT: base-specifier +// CHECK-NEXT: is-virtual: false +// CHECK-NEXT: access-specifier: public // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: EmptyClass // CHECK-NEXT: simple-declaration @@ -53,9 +55,13 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: base-clause: base-clause // CHECK-NEXT: base-specifier-list // CHECK-NEXT: base-specifier +// CHECK-NEXT: is-virtual: false +// CHECK-NEXT: access-specifier: public // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: EmptyClass // CHECK-NEXT: base-specifier +// CHECK-NEXT: is-virtual: false +// CHECK-NEXT: access-specifier: private // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: OtherEmptyClass // CHECK-NEXT: simple-declaration @@ -67,5 +73,7 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: base-clause: base-clause // CHECK-NEXT: base-specifier-list // CHECK-NEXT: base-specifier +// CHECK-NEXT: is-virtual: true +// CHECK-NEXT: access-specifier: public // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: EmptyClass From 35fdf21b1cab38ab142d3fdd5cc2614d39319123 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 12:32:18 +0000 Subject: [PATCH 16/28] fix: Set the name of ctor member initializers --- src/parser/cxx/parser.cc | 17 +++- tests/unit_tests/ast/ctor_initializer_01.cc | 99 +++++++++++++++++++++ 2 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 tests/unit_tests/ast/ctor_initializer_01.cc diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 14214df3..2beca05a 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -7316,15 +7316,26 @@ auto Parser::parse_mem_initializer_id(NameAST*& yyast) -> bool { NameAST* name = nullptr; - if (parse_class_or_decltype(name)) return true; + if (parse_class_or_decltype(name)) { + yyast = name; + return true; + } rewind(start); SourceLocation identifierLoc; - if (!match(TokenKind::T_IDENTIFIER, identifierLoc)) return false; + if (match(TokenKind::T_IDENTIFIER, identifierLoc)) { + auto name = new (pool) SimpleNameAST(); + yyast = name; + name->identifierLoc = identifierLoc; + name->identifier = unit->identifier(identifierLoc); + return true; + } - return true; + rewind(start); + + return false; } auto Parser::parse_operator_function_id(NameAST*& yyast) -> bool { diff --git a/tests/unit_tests/ast/ctor_initializer_01.cc b/tests/unit_tests/ast/ctor_initializer_01.cc new file mode 100644 index 00000000..a8d80c88 --- /dev/null +++ b/tests/unit_tests/ast/ctor_initializer_01.cc @@ -0,0 +1,99 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +struct Handle { + int zero_; + int value_; + int otherValue_; + + Handle(int value, int outerValue) + : zero_(), value_(value), otherValue_{otherValue} {} +}; + +// clang-format off +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: is-final: false +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Handle +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: zero_ +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: value_ +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: otherValue_ +// CHECK-NEXT: function-definition +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Handle +// CHECK-NEXT: modifiers +// CHECK-NEXT: function-declarator +// CHECK-NEXT: parameters-and-qualifiers: parameters-and-qualifiers +// CHECK-NEXT: parameter-declaration-clause: parameter-declaration-clause +// CHECK-NEXT: parameter-declaration-list +// CHECK-NEXT: parameter-declaration +// CHECK-NEXT: type-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: value +// CHECK-NEXT: parameter-declaration +// CHECK-NEXT: type-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: outerValue +// CHECK-NEXT: function-body: compound-statement-function-body +// CHECK-NEXT: ctor-initializer: ctor-initializer +// CHECK-NEXT: mem-initializer-list +// CHECK-NEXT: paren-mem-initializer +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: zero_ +// CHECK-NEXT: paren-mem-initializer +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: value_ +// CHECK-NEXT: expression-list +// CHECK-NEXT: id-expression +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: value +// CHECK-NEXT: braced-mem-initializer +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: otherValue_ +// CHECK-NEXT: braced-init-list: braced-init-list +// CHECK-NEXT: expression-list +// CHECK-NEXT: id-expression +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: otherValue +// CHECK-NEXT: statement: compound-statement From f61025375f9c49cb6f5c25a453266be52b51c981 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 12:41:06 +0000 Subject: [PATCH 17/28] fix: Set class key of class specifier AST nodes --- src/frontend/cxx/ast_printer.cc | 6 ++++++ src/parser/cxx/ast.fbs | 1 + src/parser/cxx/ast.h | 1 + src/parser/cxx/ast_cloner.cc | 2 ++ src/parser/cxx/ast_decoder.cc | 1 + src/parser/cxx/ast_encoder.cc | 1 + src/parser/cxx/parser.cc | 2 ++ tests/unit_tests/ast/class_definition_01.cc | 6 ++++++ tests/unit_tests/ast/ctor_initializer_01.cc | 5 +++-- 9 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index b003ed9c..6837a322 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -1667,6 +1667,12 @@ void ASTPrinter::visit(EnumSpecifierAST* ast) { void ASTPrinter::visit(ClassSpecifierAST* ast) { fmt::print(out_, "{}\n", "class-specifier"); + if (ast->classKey != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "class-key: {}\n", Token::spell(ast->classKey)); + --indent_; + } ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); fmt::print(out_, "is-final: {}\n", ast->isFinal); diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index 65d22c8b..08959390 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -1354,6 +1354,7 @@ table ClassSpecifier /* SpecifierAST */ { name: Name; base_clause: BaseClause; declaration_list: [Declaration]; + class_key: uint32; class_loc: SourceLocation; final_loc: SourceLocation; lbrace_loc: SourceLocation; diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index 79b2e0f8..f7adc49c 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -2795,6 +2795,7 @@ class ClassSpecifierAST final : public SpecifierAST { SourceLocation lbraceLoc; List* declarationList = nullptr; SourceLocation rbraceLoc; + TokenKind classKey = TokenKind::T_EOF_SYMBOL; bool isFinal = false; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index b791091a..07eb295f 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -3131,6 +3131,8 @@ void ASTCloner::visit(ClassSpecifierAST* ast) { copy->rbraceLoc = ast->rbraceLoc; + copy->classKey = ast->classKey; + copy->isFinal = ast->isFinal; } diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index c567989d..b4c10076 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -3019,6 +3019,7 @@ auto ASTDecoder::decodeClassSpecifier(const io::ClassSpecifier* node) inserter = &(*inserter)->next; } } + ast->classKey = static_cast(node->class_key()); return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index d3d5e1ea..28fc9586 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -4510,6 +4510,7 @@ void ASTEncoder::visit(ClassSpecifierAST* ast) { builder.add_declaration_list(declarationListOffsetsVector); builder.add_declaration_list_type(declarationListTypesVector); builder.add_rbrace_loc(rbraceLoc.o); + builder.add_class_key(static_cast(ast->classKey)); offset_ = builder.Finish().Union(); type_ = io::Specifier_ClassSpecifier; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 2beca05a..e2e7c054 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -6660,6 +6660,8 @@ auto Parser::parse_class_specifier(SpecifierAST*& yyast) -> bool { ast->baseClause = baseClause; ast->lbraceLoc = lbraceLoc; + ast->classKey = unit->tokenKind(ast->classLoc); + if (finalLoc) { ast->isFinal = true; } diff --git a/tests/unit_tests/ast/class_definition_01.cc b/tests/unit_tests/ast/class_definition_01.cc index fdd56d93..13be73dd 100644 --- a/tests/unit_tests/ast/class_definition_01.cc +++ b/tests/unit_tests/ast/class_definition_01.cc @@ -18,24 +18,28 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: class // CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: EmptyClass // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: class // CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: OtherEmptyClass // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: class // CHECK-NEXT: is-final: true // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: FinalClass // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: class // CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: DerivedClass @@ -49,6 +53,7 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: class // CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: DerivedClass2 @@ -67,6 +72,7 @@ class DerivedClass3 : virtual public EmptyClass {}; // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: class // CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: DerivedClass3 diff --git a/tests/unit_tests/ast/ctor_initializer_01.cc b/tests/unit_tests/ast/ctor_initializer_01.cc index a8d80c88..c96beb23 100644 --- a/tests/unit_tests/ast/ctor_initializer_01.cc +++ b/tests/unit_tests/ast/ctor_initializer_01.cc @@ -5,7 +5,7 @@ struct Handle { int value_; int otherValue_; - Handle(int value, int outerValue) + Handle(int value, int otherValue) : zero_(), value_(value), otherValue_{otherValue} {} }; @@ -15,6 +15,7 @@ struct Handle { // CHECK-NEXT: simple-declaration // CHECK-NEXT: decl-specifier-list // CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: struct // CHECK-NEXT: is-final: false // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: Handle @@ -74,7 +75,7 @@ struct Handle { // CHECK-NEXT: declarator: declarator // CHECK-NEXT: core-declarator: id-declarator // CHECK-NEXT: name: simple-name -// CHECK-NEXT: identifier: outerValue +// CHECK-NEXT: identifier: otherValue // CHECK-NEXT: function-body: compound-statement-function-body // CHECK-NEXT: ctor-initializer: ctor-initializer // CHECK-NEXT: mem-initializer-list From dc7a545a2a3c614168a38c868ae3d67ba1367e1a Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 12:46:43 +0000 Subject: [PATCH 18/28] fix: Set access specifier of access declaration AST nodes --- src/frontend/cxx/ast_printer.cc | 7 ++++++ src/parser/cxx/ast.fbs | 1 + src/parser/cxx/ast.h | 1 + src/parser/cxx/ast_cloner.cc | 2 ++ src/parser/cxx/ast_decoder.cc | 1 + src/parser/cxx/ast_encoder.cc | 2 ++ src/parser/cxx/parser.cc | 2 ++ tests/unit_tests/ast/access_declaration_01.cc | 25 +++++++++++++++++++ 8 files changed, 41 insertions(+) create mode 100644 tests/unit_tests/ast/access_declaration_01.cc diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 6837a322..3a1e622f 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -1064,6 +1064,13 @@ void ASTPrinter::visit(TryBlockStatementAST* ast) { void ASTPrinter::visit(AccessDeclarationAST* ast) { fmt::print(out_, "{}\n", "access-declaration"); + if (ast->accessSpecifier != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "access-specifier: {}\n", + Token::spell(ast->accessSpecifier)); + --indent_; + } } void ASTPrinter::visit(FunctionDefinitionAST* ast) { diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index 08959390..8073eeee 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -515,6 +515,7 @@ table NestedDeclarator /* CoreDeclaratorAST */ { } table AccessDeclaration /* DeclarationAST */ { + access_specifier: uint32; access_loc: SourceLocation; colon_loc: SourceLocation; } diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index f7adc49c..b3f4a50b 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -1857,6 +1857,7 @@ class AccessDeclarationAST final : public DeclarationAST { SourceLocation accessLoc; SourceLocation colonLoc; + TokenKind accessSpecifier = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 07eb295f..c7088ffd 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -2024,6 +2024,8 @@ void ASTCloner::visit(AccessDeclarationAST* ast) { copy->accessLoc = ast->accessLoc; copy->colonLoc = ast->colonLoc; + + copy->accessSpecifier = ast->accessSpecifier; } void ASTCloner::visit(FunctionDefinitionAST* ast) { diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index b4c10076..3e286f43 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -2138,6 +2138,7 @@ auto ASTDecoder::decodeAccessDeclaration(const io::AccessDeclaration* node) if (!node) return nullptr; auto ast = new (pool_) AccessDeclarationAST(); + ast->accessSpecifier = static_cast(node->access_specifier()); return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index 28fc9586..327f28b4 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -2942,6 +2942,8 @@ void ASTEncoder::visit(AccessDeclarationAST* ast) { io::AccessDeclaration::Builder builder{fbb_}; builder.add_access_loc(accessLoc.o); builder.add_colon_loc(colonLoc.o); + builder.add_access_specifier( + static_cast(ast->accessSpecifier)); offset_ = builder.Finish().Union(); type_ = io::Declaration_AccessDeclaration; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index e2e7c054..cbcc9d41 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -6780,6 +6780,8 @@ auto Parser::parse_member_declaration(DeclarationAST*& yyast) -> bool { ast->accessLoc = accessLoc; expect(TokenKind::T_COLON, ast->colonLoc); + ast->accessSpecifier = unit->tokenKind(ast->accessLoc); + return true; } diff --git a/tests/unit_tests/ast/access_declaration_01.cc b/tests/unit_tests/ast/access_declaration_01.cc new file mode 100644 index 00000000..74315ea4 --- /dev/null +++ b/tests/unit_tests/ast/access_declaration_01.cc @@ -0,0 +1,25 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +class SimpleClass { + private: + protected: + public: +}; + +// clang-format off +// CHECK: translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: class +// CHECK-NEXT: is-final: false +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: SimpleClass +// CHECK-NEXT: declaration-list +// CHECK-NEXT: access-declaration +// CHECK-NEXT: access-specifier: private +// CHECK-NEXT: access-declaration +// CHECK-NEXT: access-specifier: protected +// CHECK-NEXT: access-declaration +// CHECK-NEXT: access-specifier: public From bf5f22a2421fc221c7d295be688c7de11904fb5b Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 16:56:12 +0000 Subject: [PATCH 19/28] fix: Add AST node for using enum declaration --- packages/cxx-frontend/src/AST.ts | 23 +++++++++---- packages/cxx-frontend/src/ASTKind.ts | 2 +- packages/cxx-frontend/src/ASTVisitor.ts | 2 +- .../cxx-frontend/src/RecursiveASTVisitor.ts | 7 ++-- src/frontend/cxx/ast_printer.cc | 9 +++--- src/frontend/cxx/ast_printer.h | 2 +- src/parser/cxx/ast.cc | 22 ++++++++----- src/parser/cxx/ast.fbs | 11 ++++--- src/parser/cxx/ast.h | 24 ++++++++------ src/parser/cxx/ast_cloner.cc | 20 ++++++++---- src/parser/cxx/ast_cloner.h | 2 +- src/parser/cxx/ast_decoder.cc | 24 +++++++------- src/parser/cxx/ast_encoder.cc | 23 +++++++++---- src/parser/cxx/ast_fwd.h | 2 +- src/parser/cxx/ast_kind.h | 2 +- src/parser/cxx/ast_slot.cc | 25 +++++++++++---- src/parser/cxx/ast_slot.h | 2 +- src/parser/cxx/ast_visitor.h | 2 +- src/parser/cxx/default_ast_visitor.cc | 8 ++--- src/parser/cxx/default_ast_visitor.h | 2 +- src/parser/cxx/parser.cc | 19 ++++++----- src/parser/cxx/private/ast_decoder.h | 4 +-- src/parser/cxx/private/ast_encoder.h | 2 +- src/parser/cxx/recursive_ast_visitor.cc | 11 +++++-- src/parser/cxx/recursive_ast_visitor.h | 3 +- .../ast/using_enum_declaration_01.cc | 32 +++++++++++++++++++ 26 files changed, 189 insertions(+), 96 deletions(-) create mode 100644 tests/unit_tests/ast/using_enum_declaration_01.cc diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index 2d4a24b1..6b7a63b5 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -2131,12 +2131,6 @@ export class OpaqueEnumDeclarationAST extends DeclarationAST { } } -export class UsingEnumDeclarationAST extends DeclarationAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitUsingEnumDeclaration(this, context); - } -} - export class NestedNamespaceSpecifierAST extends DeclarationAST { accept(visitor: ASTVisitor, context: Context): Result { return visitor.visitNestedNamespaceSpecifier(this, context); @@ -2260,6 +2254,21 @@ export class UsingDeclarationAST extends DeclarationAST { } } +export class UsingEnumDeclarationAST extends DeclarationAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitUsingEnumDeclaration(this, context); + } + getUsingToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + getEnumTypeSpecifier(): ElaboratedTypeSpecifierAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + } + getSemicolonToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } +} + export class AsmDeclarationAST extends DeclarationAST { accept(visitor: ASTVisitor, context: Context): Result { return visitor.visitAsmDeclaration(this, context); @@ -3363,12 +3372,12 @@ const AST_CONSTRUCTORS: Array { abstract visitEmptyDeclaration(node: ast.EmptyDeclarationAST, context: Context): Result; abstract visitAttributeDeclaration(node: ast.AttributeDeclarationAST, context: Context): Result; abstract visitOpaqueEnumDeclaration(node: ast.OpaqueEnumDeclarationAST, context: Context): Result; - abstract visitUsingEnumDeclaration(node: ast.UsingEnumDeclarationAST, context: Context): Result; abstract visitNestedNamespaceSpecifier(node: ast.NestedNamespaceSpecifierAST, context: Context): Result; abstract visitNamespaceDefinition(node: ast.NamespaceDefinitionAST, context: Context): Result; abstract visitNamespaceAliasDefinition(node: ast.NamespaceAliasDefinitionAST, context: Context): Result; abstract visitUsingDirective(node: ast.UsingDirectiveAST, context: Context): Result; abstract visitUsingDeclaration(node: ast.UsingDeclarationAST, context: Context): Result; + abstract visitUsingEnumDeclaration(node: ast.UsingEnumDeclarationAST, context: Context): Result; abstract visitAsmDeclaration(node: ast.AsmDeclarationAST, context: Context): Result; abstract visitExportDeclaration(node: ast.ExportDeclarationAST, context: Context): Result; abstract visitExportCompoundDeclaration(node: ast.ExportCompoundDeclarationAST, context: Context): Result; diff --git a/packages/cxx-frontend/src/RecursiveASTVisitor.ts b/packages/cxx-frontend/src/RecursiveASTVisitor.ts index a08ea2ce..d3aa40eb 100644 --- a/packages/cxx-frontend/src/RecursiveASTVisitor.ts +++ b/packages/cxx-frontend/src/RecursiveASTVisitor.ts @@ -660,9 +660,6 @@ export class RecursiveASTVisitor extends ASTVisitor { this.accept(node.getEnumBase(), context); } - visitUsingEnumDeclaration(node: ast.UsingEnumDeclarationAST, context: Context): void { - } - visitNestedNamespaceSpecifier(node: ast.NestedNamespaceSpecifierAST, context: Context): void { } @@ -700,6 +697,10 @@ export class RecursiveASTVisitor extends ASTVisitor { } } + visitUsingEnumDeclaration(node: ast.UsingEnumDeclarationAST, context: Context): void { + this.accept(node.getEnumTypeSpecifier(), context); + } + visitAsmDeclaration(node: ast.AsmDeclarationAST, context: Context): void { for (const element of node.getAttributeList()) { this.accept(element, context); diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 3a1e622f..7a401912 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -1199,10 +1199,6 @@ void ASTPrinter::visit(OpaqueEnumDeclarationAST* ast) { accept(ast->enumBase, "enum-base"); } -void ASTPrinter::visit(UsingEnumDeclarationAST* ast) { - fmt::print(out_, "{}\n", "using-enum-declaration"); -} - void ASTPrinter::visit(NestedNamespaceSpecifierAST* ast) { fmt::print(out_, "{}\n", "nested-namespace-specifier"); accept(ast->namespaceName, "namespace-name"); @@ -1292,6 +1288,11 @@ void ASTPrinter::visit(UsingDeclarationAST* ast) { } } +void ASTPrinter::visit(UsingEnumDeclarationAST* ast) { + fmt::print(out_, "{}\n", "using-enum-declaration"); + accept(ast->enumTypeSpecifier, "enum-type-specifier"); +} + void ASTPrinter::visit(AsmDeclarationAST* ast) { fmt::print(out_, "{}\n", "asm-declaration"); if (ast->literal) { diff --git a/src/frontend/cxx/ast_printer.h b/src/frontend/cxx/ast_printer.h index 79b8a584..8acef3f8 100644 --- a/src/frontend/cxx/ast_printer.h +++ b/src/frontend/cxx/ast_printer.h @@ -177,12 +177,12 @@ class ASTPrinter : ASTVisitor { void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; - void visit(UsingEnumDeclarationAST* ast) override; void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; void visit(UsingDeclarationAST* ast) override; + void visit(UsingEnumDeclarationAST* ast) override; void visit(AsmDeclarationAST* ast) override; void visit(ExportDeclarationAST* ast) override; void visit(ExportCompoundDeclarationAST* ast) override; diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index 2a6f86b9..fb3f1725 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -1826,14 +1826,6 @@ auto OpaqueEnumDeclarationAST::lastSourceLocation() -> SourceLocation { return {}; } -auto UsingEnumDeclarationAST::firstSourceLocation() -> SourceLocation { - return {}; -} - -auto UsingEnumDeclarationAST::lastSourceLocation() -> SourceLocation { - return {}; -} - auto NestedNamespaceSpecifierAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(inlineLoc)) return loc; if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; @@ -1930,6 +1922,20 @@ auto UsingDeclarationAST::lastSourceLocation() -> SourceLocation { return {}; } +auto UsingEnumDeclarationAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(usingLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(enumTypeSpecifier)) return loc; + if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; + return {}; +} + +auto UsingEnumDeclarationAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(enumTypeSpecifier)) return loc; + if (auto loc = cxx::lastSourceLocation(usingLoc)) return loc; + return {}; +} + auto AsmDeclarationAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(attributeList)) return loc; if (auto loc = cxx::firstSourceLocation(asmLoc)) return loc; diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index 8073eeee..e7871798 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -90,12 +90,12 @@ union Declaration { EmptyDeclaration, AttributeDeclaration, OpaqueEnumDeclaration, - UsingEnumDeclaration, NestedNamespaceSpecifier, NamespaceDefinition, NamespaceAliasDefinition, UsingDirective, UsingDeclaration, + UsingEnumDeclaration, AsmDeclaration, ExportDeclaration, ExportCompoundDeclaration, @@ -586,9 +586,6 @@ table OpaqueEnumDeclaration /* DeclarationAST */ { emicolon_loc: SourceLocation; } -table UsingEnumDeclaration /* DeclarationAST */ { -} - table NestedNamespaceSpecifier /* DeclarationAST */ { namespace_name: string; inline_loc: SourceLocation; @@ -634,6 +631,12 @@ table UsingDeclaration /* DeclarationAST */ { semicolon_loc: SourceLocation; } +table UsingEnumDeclaration /* DeclarationAST */ { + enum_type_specifier: ElaboratedTypeSpecifier; + using_loc: SourceLocation; + semicolon_loc: SourceLocation; +} + table AsmDeclaration /* DeclarationAST */ { attribute_list: [AttributeSpecifier]; asm_loc: SourceLocation; diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index b3f4a50b..591b4e7a 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -2004,16 +2004,6 @@ class OpaqueEnumDeclarationAST final : public DeclarationAST { auto lastSourceLocation() -> SourceLocation override; }; -class UsingEnumDeclarationAST final : public DeclarationAST { - public: - UsingEnumDeclarationAST() : DeclarationAST(ASTKind::UsingEnumDeclaration) {} - - void accept(ASTVisitor* visitor) override { visitor->visit(this); } - - auto firstSourceLocation() -> SourceLocation override; - auto lastSourceLocation() -> SourceLocation override; -}; - class NestedNamespaceSpecifierAST final : public DeclarationAST { public: NestedNamespaceSpecifierAST() @@ -2103,6 +2093,20 @@ class UsingDeclarationAST final : public DeclarationAST { auto lastSourceLocation() -> SourceLocation override; }; +class UsingEnumDeclarationAST final : public DeclarationAST { + public: + UsingEnumDeclarationAST() : DeclarationAST(ASTKind::UsingEnumDeclaration) {} + + SourceLocation usingLoc; + ElaboratedTypeSpecifierAST* enumTypeSpecifier = nullptr; + SourceLocation semicolonLoc; + + void accept(ASTVisitor* visitor) override { visitor->visit(this); } + + auto firstSourceLocation() -> SourceLocation override; + auto lastSourceLocation() -> SourceLocation override; +}; + class AsmDeclarationAST final : public DeclarationAST { public: AsmDeclarationAST() : DeclarationAST(ASTKind::AsmDeclaration) {} diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index c7088ffd..50c4f1af 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -2227,13 +2227,6 @@ void ASTCloner::visit(OpaqueEnumDeclarationAST* ast) { copy->emicolonLoc = ast->emicolonLoc; } -void ASTCloner::visit(UsingEnumDeclarationAST* ast) { - auto copy = new (arena_) UsingEnumDeclarationAST(); - copy_ = copy; - - copy->setChecked(ast->checked()); -} - void ASTCloner::visit(NestedNamespaceSpecifierAST* ast) { auto copy = new (arena_) NestedNamespaceSpecifierAST(); copy_ = copy; @@ -2375,6 +2368,19 @@ void ASTCloner::visit(UsingDeclarationAST* ast) { copy->semicolonLoc = ast->semicolonLoc; } +void ASTCloner::visit(UsingEnumDeclarationAST* ast) { + auto copy = new (arena_) UsingEnumDeclarationAST(); + copy_ = copy; + + copy->setChecked(ast->checked()); + + copy->usingLoc = ast->usingLoc; + + copy->enumTypeSpecifier = accept(ast->enumTypeSpecifier); + + copy->semicolonLoc = ast->semicolonLoc; +} + void ASTCloner::visit(AsmDeclarationAST* ast) { auto copy = new (arena_) AsmDeclarationAST(); copy_ = copy; diff --git a/src/parser/cxx/ast_cloner.h b/src/parser/cxx/ast_cloner.h index af016aa6..bd00fdcf 100644 --- a/src/parser/cxx/ast_cloner.h +++ b/src/parser/cxx/ast_cloner.h @@ -165,12 +165,12 @@ class ASTCloner : public ASTVisitor { void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; - void visit(UsingEnumDeclarationAST* ast) override; void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; void visit(UsingDeclarationAST* ast) override; + void visit(UsingEnumDeclarationAST* ast) override; void visit(AsmDeclarationAST* ast) override; void visit(ExportDeclarationAST* ast) override; void visit(ExportCompoundDeclarationAST* ast) override; diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index 3e286f43..97440d91 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -416,9 +416,6 @@ auto ASTDecoder::decodeDeclaration(const void* ptr, io::Declaration type) case io::Declaration_OpaqueEnumDeclaration: return decodeOpaqueEnumDeclaration( reinterpret_cast(ptr)); - case io::Declaration_UsingEnumDeclaration: - return decodeUsingEnumDeclaration( - reinterpret_cast(ptr)); case io::Declaration_NestedNamespaceSpecifier: return decodeNestedNamespaceSpecifier( reinterpret_cast(ptr)); @@ -434,6 +431,9 @@ auto ASTDecoder::decodeDeclaration(const void* ptr, io::Declaration type) case io::Declaration_UsingDeclaration: return decodeUsingDeclaration( reinterpret_cast(ptr)); + case io::Declaration_UsingEnumDeclaration: + return decodeUsingEnumDeclaration( + reinterpret_cast(ptr)); case io::Declaration_AsmDeclaration: return decodeAsmDeclaration( reinterpret_cast(ptr)); @@ -2304,14 +2304,6 @@ auto ASTDecoder::decodeOpaqueEnumDeclaration( return ast; } -auto ASTDecoder::decodeUsingEnumDeclaration( - const io::UsingEnumDeclaration* node) -> UsingEnumDeclarationAST* { - if (!node) return nullptr; - - auto ast = new (pool_) UsingEnumDeclarationAST(); - return ast; -} - auto ASTDecoder::decodeNestedNamespaceSpecifier( const io::NestedNamespaceSpecifier* node) -> NestedNamespaceSpecifierAST* { if (!node) return nullptr; @@ -2423,6 +2415,16 @@ auto ASTDecoder::decodeUsingDeclaration(const io::UsingDeclaration* node) return ast; } +auto ASTDecoder::decodeUsingEnumDeclaration( + const io::UsingEnumDeclaration* node) -> UsingEnumDeclarationAST* { + if (!node) return nullptr; + + auto ast = new (pool_) UsingEnumDeclarationAST(); + ast->enumTypeSpecifier = + decodeElaboratedTypeSpecifier(node->enum_type_specifier()); + return ast; +} + auto ASTDecoder::decodeAsmDeclaration(const io::AsmDeclaration* node) -> AsmDeclarationAST* { if (!node) return nullptr; diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index 327f28b4..e75aa003 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -3245,13 +3245,6 @@ void ASTEncoder::visit(OpaqueEnumDeclarationAST* ast) { type_ = io::Declaration_OpaqueEnumDeclaration; } -void ASTEncoder::visit(UsingEnumDeclarationAST* ast) { - io::UsingEnumDeclaration::Builder builder{fbb_}; - - offset_ = builder.Finish().Union(); - type_ = io::Declaration_UsingEnumDeclaration; -} - void ASTEncoder::visit(NestedNamespaceSpecifierAST* ast) { auto inlineLoc = encodeSourceLocation(ast->inlineLoc); @@ -3479,6 +3472,22 @@ void ASTEncoder::visit(UsingDeclarationAST* ast) { type_ = io::Declaration_UsingDeclaration; } +void ASTEncoder::visit(UsingEnumDeclarationAST* ast) { + auto usingLoc = encodeSourceLocation(ast->usingLoc); + + const auto enumTypeSpecifier = accept(ast->enumTypeSpecifier); + + auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); + + io::UsingEnumDeclaration::Builder builder{fbb_}; + builder.add_using_loc(usingLoc.o); + builder.add_enum_type_specifier(enumTypeSpecifier.o); + builder.add_semicolon_loc(semicolonLoc.o); + + offset_ = builder.Finish().Union(); + type_ = io::Declaration_UsingEnumDeclaration; +} + void ASTEncoder::visit(AsmDeclarationAST* ast) { std::vector> attributeListOffsets; std::vector> diff --git a/src/parser/cxx/ast_fwd.h b/src/parser/cxx/ast_fwd.h index ef3d59b1..8a49fb58 100644 --- a/src/parser/cxx/ast_fwd.h +++ b/src/parser/cxx/ast_fwd.h @@ -220,12 +220,12 @@ class StaticAssertDeclarationAST; class EmptyDeclarationAST; class AttributeDeclarationAST; class OpaqueEnumDeclarationAST; -class UsingEnumDeclarationAST; class NestedNamespaceSpecifierAST; class NamespaceDefinitionAST; class NamespaceAliasDefinitionAST; class UsingDirectiveAST; class UsingDeclarationAST; +class UsingEnumDeclarationAST; class AsmDeclarationAST; class ExportDeclarationAST; class ExportCompoundDeclarationAST; diff --git a/src/parser/cxx/ast_kind.h b/src/parser/cxx/ast_kind.h index f05d11a2..c2b9dc6b 100644 --- a/src/parser/cxx/ast_kind.h +++ b/src/parser/cxx/ast_kind.h @@ -172,12 +172,12 @@ enum struct ASTKind { EmptyDeclaration, AttributeDeclaration, OpaqueEnumDeclaration, - UsingEnumDeclaration, NestedNamespaceSpecifier, NamespaceDefinition, NamespaceAliasDefinition, UsingDirective, UsingDeclaration, + UsingEnumDeclaration, AsmDeclaration, ExportDeclaration, ExportCompoundDeclaration, diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index be9406c4..7c4ce5d5 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -2525,12 +2525,6 @@ void ASTSlot::visit(OpaqueEnumDeclarationAST* ast) { slotCount_ = 7; } -void ASTSlot::visit(UsingEnumDeclarationAST* ast) { - switch (slot_) {} // switch - - slotCount_ = 0; -} - void ASTSlot::visit(NestedNamespaceSpecifierAST* ast) { switch (slot_) { case 0: @@ -2675,6 +2669,25 @@ void ASTSlot::visit(UsingDeclarationAST* ast) { slotCount_ = 3; } +void ASTSlot::visit(UsingEnumDeclarationAST* ast) { + switch (slot_) { + case 0: + value_ = ast->usingLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = reinterpret_cast(ast->enumTypeSpecifier); + slotKind_ = ASTSlotKind::kNode; + break; + case 2: + value_ = ast->semicolonLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + } // switch + + slotCount_ = 3; +} + void ASTSlot::visit(AsmDeclarationAST* ast) { switch (slot_) { case 0: diff --git a/src/parser/cxx/ast_slot.h b/src/parser/cxx/ast_slot.h index b0accf4f..af1c3b7c 100644 --- a/src/parser/cxx/ast_slot.h +++ b/src/parser/cxx/ast_slot.h @@ -176,12 +176,12 @@ class ASTSlot final : ASTVisitor { void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; - void visit(UsingEnumDeclarationAST* ast) override; void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; void visit(UsingDeclarationAST* ast) override; + void visit(UsingEnumDeclarationAST* ast) override; void visit(AsmDeclarationAST* ast) override; void visit(ExportDeclarationAST* ast) override; void visit(ExportCompoundDeclarationAST* ast) override; diff --git a/src/parser/cxx/ast_visitor.h b/src/parser/cxx/ast_visitor.h index e489c5e0..e7db921a 100644 --- a/src/parser/cxx/ast_visitor.h +++ b/src/parser/cxx/ast_visitor.h @@ -176,12 +176,12 @@ class ASTVisitor { virtual void visit(EmptyDeclarationAST* ast) = 0; virtual void visit(AttributeDeclarationAST* ast) = 0; virtual void visit(OpaqueEnumDeclarationAST* ast) = 0; - virtual void visit(UsingEnumDeclarationAST* ast) = 0; virtual void visit(NestedNamespaceSpecifierAST* ast) = 0; virtual void visit(NamespaceDefinitionAST* ast) = 0; virtual void visit(NamespaceAliasDefinitionAST* ast) = 0; virtual void visit(UsingDirectiveAST* ast) = 0; virtual void visit(UsingDeclarationAST* ast) = 0; + virtual void visit(UsingEnumDeclarationAST* ast) = 0; virtual void visit(AsmDeclarationAST* ast) = 0; virtual void visit(ExportDeclarationAST* ast) = 0; virtual void visit(ExportCompoundDeclarationAST* ast) = 0; diff --git a/src/parser/cxx/default_ast_visitor.cc b/src/parser/cxx/default_ast_visitor.cc index 15b8388f..a7261260 100644 --- a/src/parser/cxx/default_ast_visitor.cc +++ b/src/parser/cxx/default_ast_visitor.cc @@ -531,10 +531,6 @@ void DefaultASTVisitor::visit(OpaqueEnumDeclarationAST* ast) { cxx_runtime_error("visit(OpaqueEnumDeclarationAST): not implemented"); } -void DefaultASTVisitor::visit(UsingEnumDeclarationAST* ast) { - cxx_runtime_error("visit(UsingEnumDeclarationAST): not implemented"); -} - void DefaultASTVisitor::visit(NestedNamespaceSpecifierAST* ast) { cxx_runtime_error("visit(NestedNamespaceSpecifierAST): not implemented"); } @@ -555,6 +551,10 @@ void DefaultASTVisitor::visit(UsingDeclarationAST* ast) { cxx_runtime_error("visit(UsingDeclarationAST): not implemented"); } +void DefaultASTVisitor::visit(UsingEnumDeclarationAST* ast) { + cxx_runtime_error("visit(UsingEnumDeclarationAST): not implemented"); +} + void DefaultASTVisitor::visit(AsmDeclarationAST* ast) { cxx_runtime_error("visit(AsmDeclarationAST): not implemented"); } diff --git a/src/parser/cxx/default_ast_visitor.h b/src/parser/cxx/default_ast_visitor.h index aeeb5e1e..24c9990f 100644 --- a/src/parser/cxx/default_ast_visitor.h +++ b/src/parser/cxx/default_ast_visitor.h @@ -174,12 +174,12 @@ class DefaultASTVisitor : public ASTVisitor { void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; - void visit(UsingEnumDeclarationAST* ast) override; void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; void visit(UsingDeclarationAST* ast) override; + void visit(UsingEnumDeclarationAST* ast) override; void visit(AsmDeclarationAST* ast) override; void visit(ExportDeclarationAST* ast) override; void visit(ExportCompoundDeclarationAST* ast) override; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index cbcc9d41..20294b69 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -5690,20 +5690,21 @@ auto Parser::parse_enumerator(EnumeratorAST*& yyast) -> bool { return true; } -auto Parser::parse_using_enum_declaration(DeclarationAST*& yyasts) -> bool { - SourceLocation usingLoc; +auto Parser::parse_using_enum_declaration(DeclarationAST*& yyast) -> bool { + if (!lookat(TokenKind::T_USING, TokenKind::T_ENUM)) return false; - if (!match(TokenKind::T_USING, usingLoc)) return false; + auto ast = new (pool) UsingEnumDeclarationAST(); + yyast = ast; - ElaboratedTypeSpecifierAST* enumSpecifier = nullptr; + expect(TokenKind::T_USING, ast->usingLoc); DeclSpecs specs; - if (!parse_elaborated_enum_specifier(enumSpecifier, specs)) return false; - - SourceLocation semicolonLoc; + if (!parse_elaborated_enum_specifier(ast->enumTypeSpecifier, specs)) { + parse_error("expected an elaborated enum specifier"); + } - if (!match(TokenKind::T_SEMICOLON, semicolonLoc)) return false; + expect(TokenKind::T_SEMICOLON, ast->semicolonLoc); return true; } @@ -6790,8 +6791,6 @@ auto Parser::parse_member_declaration(DeclarationAST*& yyast) -> bool { if (LA().is(TokenKind::T_USING)) { if (parse_using_enum_declaration(yyast)) return true; - rewind(start); - if (parse_alias_declaration(yyast)) return true; rewind(start); diff --git a/src/parser/cxx/private/ast_decoder.h b/src/parser/cxx/private/ast_decoder.h index 340dbdde..52231418 100644 --- a/src/parser/cxx/private/ast_decoder.h +++ b/src/parser/cxx/private/ast_decoder.h @@ -317,8 +317,6 @@ class ASTDecoder { -> AttributeDeclarationAST*; auto decodeOpaqueEnumDeclaration(const io::OpaqueEnumDeclaration* node) -> OpaqueEnumDeclarationAST*; - auto decodeUsingEnumDeclaration(const io::UsingEnumDeclaration* node) - -> UsingEnumDeclarationAST*; auto decodeNestedNamespaceSpecifier(const io::NestedNamespaceSpecifier* node) -> NestedNamespaceSpecifierAST*; auto decodeNamespaceDefinition(const io::NamespaceDefinition* node) @@ -329,6 +327,8 @@ class ASTDecoder { -> UsingDirectiveAST*; auto decodeUsingDeclaration(const io::UsingDeclaration* node) -> UsingDeclarationAST*; + auto decodeUsingEnumDeclaration(const io::UsingEnumDeclaration* node) + -> UsingEnumDeclarationAST*; auto decodeAsmDeclaration(const io::AsmDeclaration* node) -> AsmDeclarationAST*; auto decodeExportDeclaration(const io::ExportDeclaration* node) diff --git a/src/parser/cxx/private/ast_encoder.h b/src/parser/cxx/private/ast_encoder.h index 4b5da17f..87856078 100644 --- a/src/parser/cxx/private/ast_encoder.h +++ b/src/parser/cxx/private/ast_encoder.h @@ -261,12 +261,12 @@ class ASTEncoder : ASTVisitor { void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; - void visit(UsingEnumDeclarationAST* ast) override; void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; void visit(UsingDeclarationAST* ast) override; + void visit(UsingEnumDeclarationAST* ast) override; void visit(AsmDeclarationAST* ast) override; void visit(ExportDeclarationAST* ast) override; void visit(ExportCompoundDeclarationAST* ast) override; diff --git a/src/parser/cxx/recursive_ast_visitor.cc b/src/parser/cxx/recursive_ast_visitor.cc index faf0994f..ad8c0f3d 100644 --- a/src/parser/cxx/recursive_ast_visitor.cc +++ b/src/parser/cxx/recursive_ast_visitor.cc @@ -193,6 +193,11 @@ void RecursiveASTVisitor::acceptUsingDeclarator(UsingDeclaratorAST* ast) { accept(ast); } +void RecursiveASTVisitor::acceptElaboratedTypeSpecifier( + ElaboratedTypeSpecifierAST* ast) { + accept(ast); +} + void RecursiveASTVisitor::acceptImportName(ImportNameAST* ast) { accept(ast); } void RecursiveASTVisitor::acceptTemplateArgument(TemplateArgumentAST* ast) { @@ -818,8 +823,6 @@ void RecursiveASTVisitor::visit(OpaqueEnumDeclarationAST* ast) { acceptEnumBase(ast->enumBase); } -void RecursiveASTVisitor::visit(UsingEnumDeclarationAST* ast) {} - void RecursiveASTVisitor::visit(NestedNamespaceSpecifierAST* ast) {} void RecursiveASTVisitor::visit(NamespaceDefinitionAST* ast) { @@ -856,6 +859,10 @@ void RecursiveASTVisitor::visit(UsingDeclarationAST* ast) { } } +void RecursiveASTVisitor::visit(UsingEnumDeclarationAST* ast) { + acceptElaboratedTypeSpecifier(ast->enumTypeSpecifier); +} + void RecursiveASTVisitor::visit(AsmDeclarationAST* ast) { for (auto it = ast->attributeList; it; it = it->next) { acceptAttributeSpecifier(it->value); diff --git a/src/parser/cxx/recursive_ast_visitor.h b/src/parser/cxx/recursive_ast_visitor.h index b63cd414..8a1d6b4d 100644 --- a/src/parser/cxx/recursive_ast_visitor.h +++ b/src/parser/cxx/recursive_ast_visitor.h @@ -73,6 +73,7 @@ class RecursiveASTVisitor : public ASTVisitor { virtual void acceptEnumBase(EnumBaseAST* ast); virtual void acceptNestedNamespaceSpecifier(NestedNamespaceSpecifierAST* ast); virtual void acceptUsingDeclarator(UsingDeclaratorAST* ast); + virtual void acceptElaboratedTypeSpecifier(ElaboratedTypeSpecifierAST* ast); virtual void acceptImportName(ImportNameAST* ast); virtual void acceptTemplateArgument(TemplateArgumentAST* ast); virtual void acceptEnumerator(EnumeratorAST* ast); @@ -218,12 +219,12 @@ class RecursiveASTVisitor : public ASTVisitor { void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; void visit(OpaqueEnumDeclarationAST* ast) override; - void visit(UsingEnumDeclarationAST* ast) override; void visit(NestedNamespaceSpecifierAST* ast) override; void visit(NamespaceDefinitionAST* ast) override; void visit(NamespaceAliasDefinitionAST* ast) override; void visit(UsingDirectiveAST* ast) override; void visit(UsingDeclarationAST* ast) override; + void visit(UsingEnumDeclarationAST* ast) override; void visit(AsmDeclarationAST* ast) override; void visit(ExportDeclarationAST* ast) override; void visit(ExportCompoundDeclarationAST* ast) override; diff --git a/tests/unit_tests/ast/using_enum_declaration_01.cc b/tests/unit_tests/ast/using_enum_declaration_01.cc new file mode 100644 index 00000000..3197fca3 --- /dev/null +++ b/tests/unit_tests/ast/using_enum_declaration_01.cc @@ -0,0 +1,32 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +enum class fruit { orange, apple }; + +struct S { + using enum fruit; +}; + +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: enum-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: fruit +// CHECK-NEXT: enumerator-list +// CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: orange +// CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: apple +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: struct +// CHECK-NEXT: is-final: false +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: S +// CHECK-NEXT: declaration-list +// CHECK-NEXT: using-enum-declaration +// CHECK-NEXT: enum-type-specifier: elaborated-type-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: fruit From a8db10739bf97b379d4bb76846c532392406b872 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 17:00:16 +0000 Subject: [PATCH 20/28] fix: Set class key of elaborated type specifiers --- src/frontend/cxx/ast_printer.cc | 6 ++++++ src/parser/cxx/ast.fbs | 1 + src/parser/cxx/ast.h | 1 + src/parser/cxx/ast_cloner.cc | 2 ++ src/parser/cxx/ast_decoder.cc | 1 + src/parser/cxx/ast_encoder.cc | 1 + src/parser/cxx/parser.cc | 6 ++++++ tests/unit_tests/ast/using_enum_declaration_01.cc | 1 + 8 files changed, 19 insertions(+) diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 7a401912..3c84ee9e 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -1608,6 +1608,12 @@ void ASTPrinter::visit(UnderlyingTypeSpecifierAST* ast) { void ASTPrinter::visit(ElaboratedTypeSpecifierAST* ast) { fmt::print(out_, "{}\n", "elaborated-type-specifier"); + if (ast->classKey != TokenKind::T_EOF_SYMBOL) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "class-key: {}\n", Token::spell(ast->classKey)); + --indent_; + } if (ast->attributeList) { ++indent_; fmt::print(out_, "{:{}}", "", indent_ * 2); diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index e7871798..7bc8659b 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -1306,6 +1306,7 @@ table ElaboratedTypeSpecifier /* SpecifierAST */ { attribute_list: [AttributeSpecifier]; nested_name_specifier: NestedNameSpecifier; name: Name; + class_key: uint32; class_loc: SourceLocation; } diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index 591b4e7a..39e84e19 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -2680,6 +2680,7 @@ class ElaboratedTypeSpecifierAST final : public SpecifierAST { List* attributeList = nullptr; NestedNameSpecifierAST* nestedNameSpecifier = nullptr; NameAST* name = nullptr; + TokenKind classKey = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 50c4f1af..8da6c1fe 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -2992,6 +2992,8 @@ void ASTCloner::visit(ElaboratedTypeSpecifierAST* ast) { copy->nestedNameSpecifier = accept(ast->nestedNameSpecifier); copy->name = accept(ast->name); + + copy->classKey = ast->classKey; } void ASTCloner::visit(DecltypeAutoSpecifierAST* ast) { diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index 97440d91..4fc194d5 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -2913,6 +2913,7 @@ auto ASTDecoder::decodeElaboratedTypeSpecifier( ast->nestedNameSpecifier = decodeNestedNameSpecifier(node->nested_name_specifier()); ast->name = decodeName(node->name(), node->name_type()); + ast->classKey = static_cast(node->class_key()); return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index e75aa003..7cafa0c6 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -4324,6 +4324,7 @@ void ASTEncoder::visit(ElaboratedTypeSpecifierAST* ast) { builder.add_nested_name_specifier(nestedNameSpecifier.o); builder.add_name(name); builder.add_name_type(static_cast(nameType)); + builder.add_class_key(static_cast(ast->classKey)); offset_ = builder.Finish().Union(); type_ = io::Specifier_ElaboratedTypeSpecifier; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 20294b69..12649bf4 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -4343,6 +4343,7 @@ auto Parser::parse_elaborated_type_specifier_helper( ast->classLoc = classLoc; ast->attributeList = attributes; ast->name = name; + ast->classKey = unit->tokenKind(classLoc); return true; } @@ -4369,6 +4370,7 @@ auto Parser::parse_elaborated_type_specifier_helper( ast->classLoc = classLoc; ast->attributeList = attributes; ast->name = name; + ast->classKey = unit->tokenKind(classLoc); return true; } @@ -4391,6 +4393,7 @@ auto Parser::parse_elaborated_type_specifier_helper( ast->attributeList = attributes; ast->nestedNameSpecifier = nestedNameSpecifier; ast->name = name; + ast->classKey = unit->tokenKind(classLoc); return true; } @@ -4406,6 +4409,7 @@ auto Parser::parse_elaborated_type_specifier_helper( ast->attributeList = attributes; ast->nestedNameSpecifier = nestedNameSpecifier; ast->name = nullptr; // error + ast->classKey = unit->tokenKind(classLoc); return true; } @@ -4423,6 +4427,7 @@ auto Parser::parse_elaborated_type_specifier_helper( ast->attributeList = attributes; ast->nestedNameSpecifier = nestedNameSpecifier; ast->name = name; + ast->classKey = unit->tokenKind(classLoc); return true; } @@ -4451,6 +4456,7 @@ auto Parser::parse_elaborated_enum_specifier(ElaboratedTypeSpecifierAST*& yyast, ast->classLoc = enumLoc; ast->nestedNameSpecifier = nestedNameSpecifier; ast->name = name; + ast->classKey = TokenKind::T_ENUM; return true; } diff --git a/tests/unit_tests/ast/using_enum_declaration_01.cc b/tests/unit_tests/ast/using_enum_declaration_01.cc index 3197fca3..bfba48d0 100644 --- a/tests/unit_tests/ast/using_enum_declaration_01.cc +++ b/tests/unit_tests/ast/using_enum_declaration_01.cc @@ -28,5 +28,6 @@ struct S { // CHECK-NEXT: declaration-list // CHECK-NEXT: using-enum-declaration // CHECK-NEXT: enum-type-specifier: elaborated-type-specifier +// CHECK-NEXT: class-key: enum // CHECK-NEXT: name: simple-name // CHECK-NEXT: identifier: fruit From c716cc0dbe5011b836b75d8d7be1614b5cc6398f Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 17:08:22 +0000 Subject: [PATCH 21/28] fix: Add AST node for underlying type specifier --- packages/cxx-frontend/src/AST.ts | 12 +++++++ .../cxx-frontend/src/RecursiveASTVisitor.ts | 1 + src/frontend/cxx/ast_printer.cc | 1 + src/parser/cxx/ast.cc | 8 +++++ src/parser/cxx/ast.fbs | 4 +++ src/parser/cxx/ast.h | 5 +++ src/parser/cxx/ast_cloner.cc | 8 +++++ src/parser/cxx/ast_decoder.cc | 1 + src/parser/cxx/ast_encoder.cc | 12 +++++++ src/parser/cxx/ast_slot.cc | 21 +++++++++++-- src/parser/cxx/parser.cc | 15 +++++---- src/parser/cxx/recursive_ast_visitor.cc | 4 ++- .../ast/underlying_type_specifier_01.cc | 31 +++++++++++++++++++ .../ast/using_enum_declaration_01.cc | 1 + 14 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 tests/unit_tests/ast/underlying_type_specifier_01.cc diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index 6b7a63b5..6babce1f 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -2833,6 +2833,18 @@ export class UnderlyingTypeSpecifierAST extends SpecifierAST { accept(visitor: ASTVisitor, context: Context): Result { return visitor.visitUnderlyingTypeSpecifier(this, context); } + getUnderlyingTypeToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + } + getTypeId(): TypeIdAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } } export class ElaboratedTypeSpecifierAST extends SpecifierAST { diff --git a/packages/cxx-frontend/src/RecursiveASTVisitor.ts b/packages/cxx-frontend/src/RecursiveASTVisitor.ts index d3aa40eb..f222f855 100644 --- a/packages/cxx-frontend/src/RecursiveASTVisitor.ts +++ b/packages/cxx-frontend/src/RecursiveASTVisitor.ts @@ -871,6 +871,7 @@ export class RecursiveASTVisitor extends ASTVisitor { } visitUnderlyingTypeSpecifier(node: ast.UnderlyingTypeSpecifierAST, context: Context): void { + this.accept(node.getTypeId(), context); } visitElaboratedTypeSpecifier(node: ast.ElaboratedTypeSpecifierAST, context: Context): void { diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 3c84ee9e..a9f9b5f4 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -1604,6 +1604,7 @@ void ASTPrinter::visit(AtomicTypeSpecifierAST* ast) { void ASTPrinter::visit(UnderlyingTypeSpecifierAST* ast) { fmt::print(out_, "{}\n", "underlying-type-specifier"); + accept(ast->typeId, "type-id"); } void ASTPrinter::visit(ElaboratedTypeSpecifierAST* ast) { diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index fb3f1725..4d1cb9eb 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -2453,10 +2453,18 @@ auto AtomicTypeSpecifierAST::lastSourceLocation() -> SourceLocation { } auto UnderlyingTypeSpecifierAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(underlyingTypeLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(typeId)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } auto UnderlyingTypeSpecifierAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeId)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(underlyingTypeLoc)) return loc; return {}; } diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index 7bc8659b..feff8d0b 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -1300,6 +1300,10 @@ table AtomicTypeSpecifier /* SpecifierAST */ { } table UnderlyingTypeSpecifier /* SpecifierAST */ { + type_id: TypeId; + underlying_type_loc: SourceLocation; + lparen_loc: SourceLocation; + rparen_loc: SourceLocation; } table ElaboratedTypeSpecifier /* SpecifierAST */ { diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index 39e84e19..930102ab 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -2665,6 +2665,11 @@ class UnderlyingTypeSpecifierAST final : public SpecifierAST { UnderlyingTypeSpecifierAST() : SpecifierAST(ASTKind::UnderlyingTypeSpecifier) {} + SourceLocation underlyingTypeLoc; + SourceLocation lparenLoc; + TypeIdAST* typeId = nullptr; + SourceLocation rparenLoc; + void accept(ASTVisitor* visitor) override { visitor->visit(this); } auto firstSourceLocation() -> SourceLocation override; diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 8da6c1fe..41869c26 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -2970,6 +2970,14 @@ void ASTCloner::visit(UnderlyingTypeSpecifierAST* ast) { copy_ = copy; copy->setChecked(ast->checked()); + + copy->underlyingTypeLoc = ast->underlyingTypeLoc; + + copy->lparenLoc = ast->lparenLoc; + + copy->typeId = accept(ast->typeId); + + copy->rparenLoc = ast->rparenLoc; } void ASTCloner::visit(ElaboratedTypeSpecifierAST* ast) { diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index 4fc194d5..b063079b 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -2893,6 +2893,7 @@ auto ASTDecoder::decodeUnderlyingTypeSpecifier( if (!node) return nullptr; auto ast = new (pool_) UnderlyingTypeSpecifierAST(); + ast->typeId = decodeTypeId(node->type_id()); return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index 7cafa0c6..0f493480 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -4290,7 +4290,19 @@ void ASTEncoder::visit(AtomicTypeSpecifierAST* ast) { } void ASTEncoder::visit(UnderlyingTypeSpecifierAST* ast) { + auto underlyingTypeLoc = encodeSourceLocation(ast->underlyingTypeLoc); + + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + + const auto typeId = accept(ast->typeId); + + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + io::UnderlyingTypeSpecifier::Builder builder{fbb_}; + builder.add_underlying_type_loc(underlyingTypeLoc.o); + builder.add_lparen_loc(lparenLoc.o); + builder.add_type_id(typeId.o); + builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); type_ = io::Specifier_UnderlyingTypeSpecifier; diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index 7c4ce5d5..b0dec71a 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -3368,9 +3368,26 @@ void ASTSlot::visit(AtomicTypeSpecifierAST* ast) { } void ASTSlot::visit(UnderlyingTypeSpecifierAST* ast) { - switch (slot_) {} // switch + switch (slot_) { + case 0: + value_ = ast->underlyingTypeLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 2: + value_ = reinterpret_cast(ast->typeId); + slotKind_ = ASTSlotKind::kNode; + break; + case 3: + value_ = ast->rparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + } // switch - slotCount_ = 0; + slotCount_ = 4; } void ASTSlot::visit(ElaboratedTypeSpecifierAST* ast) { diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 12649bf4..ea9755ed 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -4147,19 +4147,18 @@ auto Parser::parse_underlying_type_specifier(SpecifierAST*& yyast, if (!match(TokenKind::T___UNDERLYING_TYPE, underlyingTypeLoc)) return false; - SourceLocation lparenLoc; - - expect(TokenKind::T_LPAREN, lparenLoc); + specs.has_named_typespec = true; - TypeIdAST* typeId = nullptr; + auto ast = new (pool) UnderlyingTypeSpecifierAST(); + yyast = ast; - if (!parse_type_id(typeId)) parse_error("expected type id"); + ast->underlyingTypeLoc = underlyingTypeLoc; - SourceLocation rparenLoc; + expect(TokenKind::T_LPAREN, ast->lparenLoc); - expect(TokenKind::T_RPAREN, rparenLoc); + if (!parse_type_id(ast->typeId)) parse_error("expected type id"); - specs.has_named_typespec = true; + expect(TokenKind::T_RPAREN, ast->rparenLoc); return true; } diff --git a/src/parser/cxx/recursive_ast_visitor.cc b/src/parser/cxx/recursive_ast_visitor.cc index ad8c0f3d..d88eb244 100644 --- a/src/parser/cxx/recursive_ast_visitor.cc +++ b/src/parser/cxx/recursive_ast_visitor.cc @@ -1009,7 +1009,9 @@ void RecursiveASTVisitor::visit(AtomicTypeSpecifierAST* ast) { acceptTypeId(ast->typeId); } -void RecursiveASTVisitor::visit(UnderlyingTypeSpecifierAST* ast) {} +void RecursiveASTVisitor::visit(UnderlyingTypeSpecifierAST* ast) { + acceptTypeId(ast->typeId); +} void RecursiveASTVisitor::visit(ElaboratedTypeSpecifierAST* ast) { for (auto it = ast->attributeList; it; it = it->next) { diff --git a/tests/unit_tests/ast/underlying_type_specifier_01.cc b/tests/unit_tests/ast/underlying_type_specifier_01.cc new file mode 100644 index 00000000..0fb0dcc6 --- /dev/null +++ b/tests/unit_tests/ast/underlying_type_specifier_01.cc @@ -0,0 +1,31 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +enum class fruit { orange, apple }; + +using I = __underlying_type(fruit); + +// clang-format off +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: enum-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: fruit +// CHECK-NEXT: enumerator-list +// CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: orange +// CHECK-NEXT: enumerator +// CHECK-NEXT: identifier: apple +// CHECK-NEXT: alias-declaration +// CHECK-NEXT: identifier: I +// CHECK-NEXT: type-id: type-id +// CHECK-NEXT: type-specifier-list +// CHECK-NEXT: underlying-type-specifier +// CHECK-NEXT: type-id: type-id +// CHECK-NEXT: type-specifier-list +// CHECK-NEXT: named-type-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: fruit +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: declarator: declarator diff --git a/tests/unit_tests/ast/using_enum_declaration_01.cc b/tests/unit_tests/ast/using_enum_declaration_01.cc index bfba48d0..9b5543fb 100644 --- a/tests/unit_tests/ast/using_enum_declaration_01.cc +++ b/tests/unit_tests/ast/using_enum_declaration_01.cc @@ -6,6 +6,7 @@ struct S { using enum fruit; }; +// clang-format off // CHECK:translation-unit // CHECK-NEXT: declaration-list // CHECK-NEXT: simple-declaration From 8d8e07becea096c21b556913755224ea4cf36283 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 17:10:55 +0000 Subject: [PATCH 22/28] fix: Set location of the atomic type specifier --- src/parser/cxx/parser.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index ea9755ed..63a6a67b 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -4174,6 +4174,8 @@ auto Parser::parse_atomic_type_specifier(SpecifierAST*& yyast, DeclSpecs& specs) auto ast = new (pool) AtomicTypeSpecifierAST(); yyast = ast; + ast->atomicLoc = atomicLoc; + expect(TokenKind::T_LPAREN, ast->lparenLoc); if (!parse_type_id(ast->typeId)) parse_error("expected type id"); From 19639bdea033b151bb54d12863f3a6d2f36a0d77 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 21 Aug 2023 17:18:00 +0000 Subject: [PATCH 23/28] chore: Prefer to use Token::isOneOf() --- src/parser/cxx/parser.cc | 59 ++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 63a6a67b..bba5d824 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -1630,17 +1630,12 @@ auto Parser::parse_postincr_expression(ExpressionAST*& yyast) -> bool { } auto Parser::parse_cpp_cast_head(SourceLocation& castLoc) -> bool { - switch (TokenKind(LA())) { - case TokenKind::T_CONST_CAST: - case TokenKind::T_DYNAMIC_CAST: - case TokenKind::T_REINTERPRET_CAST: - case TokenKind::T_STATIC_CAST: - castLoc = consumeToken(); - return true; - - default: - return false; - } // switch + if (LA().isOneOf(TokenKind::T_CONST_CAST, TokenKind::T_DYNAMIC_CAST, + TokenKind::T_REINTERPRET_CAST, TokenKind::T_STATIC_CAST)) { + castLoc = consumeToken(); + return true; + } + return false; } auto Parser::parse_cpp_cast_expression(ExpressionAST*& yyast) -> bool { @@ -4258,15 +4253,9 @@ auto Parser::parse_primitive_type_specifier(SpecifierAST*& yyast, auto Parser::parse_elaborated_type_specifier(SpecifierAST*& yyast, DeclSpecs& specs) -> bool { - switch (TokenKind(LA())) { - case TokenKind::T_ENUM: - case TokenKind::T_CLASS: - case TokenKind::T_STRUCT: - case TokenKind::T_UNION: - break; - default: - return false; - } // switch + if (!LA().isOneOf(TokenKind::T_ENUM, TokenKind::T_CLASS, TokenKind::T_STRUCT, + TokenKind::T_UNION)) + return false; const auto start = currentLocation(); @@ -6760,16 +6749,13 @@ auto Parser::parse_class_virt_specifier(SourceLocation& finalLoc) -> bool { } auto Parser::parse_class_key(SourceLocation& classLoc) -> bool { - switch (TokenKind(LA())) { - case TokenKind::T_CLASS: - case TokenKind::T_STRUCT: - case TokenKind::T_UNION: - classLoc = consumeToken(); - return true; + if (LA().isOneOf(TokenKind::T_CLASS, TokenKind::T_STRUCT, + TokenKind::T_UNION)) { + classLoc = consumeToken(); + return true; + } - default: - return false; - } // switch + return false; } auto Parser::parse_member_specification(DeclarationAST*& yyast) -> bool { @@ -7225,16 +7211,13 @@ auto Parser::parse_class_or_decltype(NameAST*& yyast) -> bool { } auto Parser::parse_access_specifier(SourceLocation& loc) -> bool { - switch (TokenKind(LA())) { - case TokenKind::T_PRIVATE: - case TokenKind::T_PROTECTED: - case TokenKind::T_PUBLIC: - loc = consumeToken(); - return true; + if (LA().isOneOf(TokenKind::T_PRIVATE, TokenKind::T_PROTECTED, + TokenKind::T_PUBLIC)) { + loc = consumeToken(); + return true; + } - default: - return false; - } // switch + return false; } auto Parser::parse_ctor_initializer(CtorInitializerAST*& yyast) -> bool { From f36c3f4000c64bae5872721f4e0458854e82000d Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 22 Aug 2023 12:25:10 +0000 Subject: [PATCH 24/28] fix: Add AST for designated initializers --- packages/cxx-frontend/src/AST.ts | 1152 +++++----- packages/cxx-frontend/src/ASTKind.ts | 84 +- packages/cxx-frontend/src/ASTVisitor.ts | 84 +- .../cxx-frontend/src/RecursiveASTVisitor.ts | 260 +-- src/frontend/cxx/ast_printer.cc | 431 ++-- src/frontend/cxx/ast_printer.h | 74 +- src/parser/cxx/ast.cc | 24 + src/parser/cxx/ast.fbs | 13 + src/parser/cxx/ast.h | 744 +++---- src/parser/cxx/ast_cloner.cc | 1062 ++++----- src/parser/cxx/ast_cloner.h | 74 +- src/parser/cxx/ast_decoder.cc | 1143 +++++----- src/parser/cxx/ast_encoder.cc | 1906 +++++++++-------- src/parser/cxx/ast_fwd.h | 84 +- src/parser/cxx/ast_kind.h | 84 +- src/parser/cxx/ast_slot.cc | 1074 +++++----- src/parser/cxx/ast_slot.h | 74 +- src/parser/cxx/ast_visitor.h | 84 +- src/parser/cxx/default_ast_visitor.cc | 236 +- src/parser/cxx/default_ast_visitor.h | 84 +- src/parser/cxx/parser.cc | 55 +- src/parser/cxx/parser.h | 5 +- src/parser/cxx/private/ast_decoder.h | 136 +- src/parser/cxx/private/ast_encoder.h | 80 +- src/parser/cxx/recursive_ast_visitor.cc | 249 +-- src/parser/cxx/recursive_ast_visitor.h | 75 +- .../ast/designated_initializer_01.cc | 71 + 27 files changed, 4914 insertions(+), 4528 deletions(-) create mode 100644 tests/unit_tests/ast/designated_initializer_01.cc diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index 6babce1f..97496625 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -570,220 +570,250 @@ export class AttributeUsingPrefixAST extends AST { } } -export class SimpleRequirementAST extends RequirementAST { +export class DesignatorAST extends AST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitSimpleRequirement(this, context); + return visitor.visitDesignator(this, context); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getDotToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getSemicolonToken(): Token | undefined { + getIdentifierToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } } -export class CompoundRequirementAST extends RequirementAST { +export class DesignatedInitializerClauseAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitCompoundRequirement(this, context); - } - getLbraceToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + return visitor.visitDesignatedInitializerClause(this, context); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getDesignator(): DesignatorAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getRbraceToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getInitializer(): InitializerAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getNoexceptToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); +} + +export class ThisExpressionAST extends ExpressionAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitThisExpression(this, context); } - getMinusGreaterToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + getThisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getTypeConstraint(): TypeConstraintAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); +} + +export class CharLiteralExpressionAST extends ExpressionAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitCharLiteralExpression(this, context); } - getSemicolonToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); + getLiteralToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class TypeRequirementAST extends RequirementAST { +export class BoolLiteralExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTypeRequirement(this, context); + return visitor.visitBoolLiteralExpression(this, context); } - getTypenameToken(): Token | undefined { + getLiteralToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getNestedNameSpecifier(): NestedNameSpecifierAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); - } - getName(): NameAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); +} + +export class IntLiteralExpressionAST extends ExpressionAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitIntLiteralExpression(this, context); } - getSemicolonToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getLiteralToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class NestedRequirementAST extends RequirementAST { +export class FloatLiteralExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitNestedRequirement(this, context); + return visitor.visitFloatLiteralExpression(this, context); } - getRequiresToken(): Token | undefined { + getLiteralToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); +} + +export class NullptrLiteralExpressionAST extends ExpressionAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitNullptrLiteralExpression(this, context); } - getSemicolonToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getLiteralToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class TypeTemplateArgumentAST extends TemplateArgumentAST { +export class StringLiteralExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTypeTemplateArgument(this, context); + return visitor.visitStringLiteralExpression(this, context); } - getTypeId(): TypeIdAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLiteralToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class ExpressionTemplateArgumentAST extends TemplateArgumentAST { +export class UserDefinedStringLiteralExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitExpressionTemplateArgument(this, context); + return visitor.visitUserDefinedStringLiteralExpression(this, context); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLiteralToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class ParenMemInitializerAST extends MemInitializerAST { +export class IdExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitParenMemInitializer(this, context); + return visitor.visitIdExpression(this, context); } getName(): NameAST | undefined { return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } +} + +export class RequiresExpressionAST extends ExpressionAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitRequiresExpression(this, context); + } + getRequiresToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - *getExpressionList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getParameterDeclarationClause(): ParameterDeclarationClauseAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } getRparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } - getEllipsisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + getRequirementBody(): RequirementBodyAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } } -export class BracedMemInitializerAST extends MemInitializerAST { +export class NestedExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitBracedMemInitializer(this, context); + return visitor.visitNestedExpression(this, context); } - getName(): NameAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getBracedInitList(): BracedInitListAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getEllipsisToken(): Token | undefined { + getRparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class ThisLambdaCaptureAST extends LambdaCaptureAST { +export class RightFoldExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitThisLambdaCapture(this, context); + return visitor.visitRightFoldExpression(this, context); } - getThisToken(): Token | undefined { + getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } -} - -export class DerefThisLambdaCaptureAST extends LambdaCaptureAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitDerefThisLambdaCapture(this, context); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getStarToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getOpToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getThisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getEllipsisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } } -export class SimpleLambdaCaptureAST extends LambdaCaptureAST { +export class LeftFoldExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitSimpleLambdaCapture(this, context); + return visitor.visitLeftFoldExpression(this, context); } - getIdentifierToken(): Token | undefined { + getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } getEllipsisToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } -} - -export class RefLambdaCaptureAST extends LambdaCaptureAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitRefLambdaCapture(this, context); - } - getAmpToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getOpToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getIdentifierToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } - getEllipsisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } } -export class RefInitLambdaCaptureAST extends LambdaCaptureAST { +export class FoldExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitRefInitLambdaCapture(this, context); + return visitor.visitFoldExpression(this, context); } - getAmpToken(): Token | undefined { + getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getEllipsisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getLeftExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getIdentifierToken(): Token | undefined { + getOpToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getInitializer(): InitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getEllipsisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } + getFoldOpToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + } + getRightExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); } } -export class InitLambdaCaptureAST extends LambdaCaptureAST { +export class LambdaExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitInitLambdaCapture(this, context); + return visitor.visitLambdaExpression(this, context); } - getEllipsisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLambdaIntroducer(): LambdaIntroducerAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getIdentifierToken(): Token | undefined { + getLessToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getInitializer(): InitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + *getTemplateParameterList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + getGreaterToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } + getRequiresClause(): RequiresClauseAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + } + getLambdaDeclarator(): LambdaDeclaratorAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); + } + getStatement(): CompoundStatementAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); } } -export class EqualInitializerAST extends InitializerAST { +export class SizeofExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitEqualInitializer(this, context); + return visitor.visitSizeofExpression(this, context); } - getEqualToken(): Token | undefined { + getSizeofToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } getExpression(): ExpressionAST | undefined { @@ -791,410 +821,380 @@ export class EqualInitializerAST extends InitializerAST { } } -export class BracedInitListAST extends InitializerAST { +export class SizeofTypeExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitBracedInitList(this, context); + return visitor.visitSizeofTypeExpression(this, context); } - getLbraceToken(): Token | undefined { + getSizeofToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - *getExpressionList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getCommaToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getTypeId(): TypeIdAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getRbraceToken(): Token | undefined { + getRparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class ParenInitializerAST extends InitializerAST { +export class SizeofPackExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitParenInitializer(this, context); + return visitor.visitSizeofPackExpression(this, context); } - getLparenToken(): Token | undefined { + getSizeofToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - *getExpressionList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getEllipsisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getRparenToken(): Token | undefined { + getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } + getIdentifierToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + } } -export class NewParenInitializerAST extends NewInitializerAST { +export class TypeidExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitNewParenInitializer(this, context); + return visitor.visitTypeidExpression(this, context); } - getLparenToken(): Token | undefined { + getTypeidToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - *getExpressionList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + } + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class NewBracedInitializerAST extends NewInitializerAST { +export class TypeidOfTypeExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitNewBracedInitializer(this, context); + return visitor.visitTypeidOfTypeExpression(this, context); } - getBracedInit(): BracedInitListAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getTypeidToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } -} - -export class EllipsisExceptionDeclarationAST extends ExceptionDeclarationAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitEllipsisExceptionDeclaration(this, context); + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getEllipsisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getTypeId(): TypeIdAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class TypeExceptionDeclarationAST extends ExceptionDeclarationAST { +export class AlignofExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTypeExceptionDeclaration(this, context); + return visitor.visitAlignofExpression(this, context); } - *getAttributeList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 0); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getAlignofToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - *getTypeSpecifierList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getDeclarator(): DeclaratorAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getTypeId(): TypeIdAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class DefaultFunctionBodyAST extends FunctionBodyAST { +export class TypeTraitsExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitDefaultFunctionBody(this, context); + return visitor.visitTypeTraitsExpression(this, context); } - getEqualToken(): Token | undefined { + getTypeTraitsToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getDefaultToken(): Token | undefined { + getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getSemicolonToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + *getTypeIdList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class CompoundStatementFunctionBodyAST extends FunctionBodyAST { +export class UnaryExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitCompoundStatementFunctionBody(this, context); + return visitor.visitUnaryExpression(this, context); } - getCtorInitializer(): CtorInitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getOpToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getStatement(): CompoundStatementAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } } -export class TryStatementFunctionBodyAST extends FunctionBodyAST { +export class BinaryExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTryStatementFunctionBody(this, context); - } - getTryToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + return visitor.visitBinaryExpression(this, context); } - getCtorInitializer(): CtorInitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getLeftExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getStatement(): CompoundStatementAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getOpToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - *getHandlerList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 3); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getRightExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class DeleteFunctionBodyAST extends FunctionBodyAST { +export class AssignmentExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitDeleteFunctionBody(this, context); + return visitor.visitAssignmentExpression(this, context); } - getEqualToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLeftExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getDeleteToken(): Token | undefined { + getOpToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getSemicolonToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getRightExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class TranslationUnitAST extends UnitAST { +export class BracedTypeConstructionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTranslationUnit(this, context); + return visitor.visitBracedTypeConstruction(this, context); } - *getDeclarationList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 0); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getTypeSpecifier(): SpecifierAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + getBracedInitList(): BracedInitListAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } } -export class ModuleUnitAST extends UnitAST { +export class TypeConstructionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitModuleUnit(this, context); + return visitor.visitTypeConstruction(this, context); } - getGlobalModuleFragment(): GlobalModuleFragmentAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getTypeSpecifier(): SpecifierAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getModuleDeclaration(): ModuleDeclarationAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - *getDeclarationList(): Generator { + *getExpressionList(): Generator { for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); + yield AST.from(cxx.getListValue(it), this.parser); } } - getPrivateModuleFragment(): PrivateModuleFragmentAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class ThisExpressionAST extends ExpressionAST { +export class CallExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitThisExpression(this, context); - } - getThisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + return visitor.visitCallExpression(this, context); } -} - -export class CharLiteralExpressionAST extends ExpressionAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitCharLiteralExpression(this, context); + getBaseExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLiteralToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } -} - -export class BoolLiteralExpressionAST extends ExpressionAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitBoolLiteralExpression(this, context); + *getExpressionList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } } - getLiteralToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class IntLiteralExpressionAST extends ExpressionAST { +export class SubscriptExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitIntLiteralExpression(this, context); - } - getLiteralToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + return visitor.visitSubscriptExpression(this, context); } -} - -export class FloatLiteralExpressionAST extends ExpressionAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitFloatLiteralExpression(this, context); + getBaseExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLiteralToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLbracketToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } -} - -export class NullptrLiteralExpressionAST extends ExpressionAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitNullptrLiteralExpression(this, context); + getIndexExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getLiteralToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getRbracketToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class StringLiteralExpressionAST extends ExpressionAST { +export class MemberExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitStringLiteralExpression(this, context); + return visitor.visitMemberExpression(this, context); } - getLiteralToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getBaseExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } -} - -export class UserDefinedStringLiteralExpressionAST extends ExpressionAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitUserDefinedStringLiteralExpression(this, context); + getAccessToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getLiteralToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getTemplateToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } + getName(): NameAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class IdExpressionAST extends ExpressionAST { +export class PostIncrExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitIdExpression(this, context); + return visitor.visitPostIncrExpression(this, context); } - getName(): NameAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getBaseExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + getOpToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } } -export class RequiresExpressionAST extends ExpressionAST { +export class ConditionalExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitRequiresExpression(this, context); + return visitor.visitConditionalExpression(this, context); } - getRequiresToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getCondition(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLparenToken(): Token | undefined { + getQuestionToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getParameterDeclarationClause(): ParameterDeclarationClauseAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getIftrueExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getRparenToken(): Token | undefined { + getColonToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } - getRequirementBody(): RequirementBodyAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + getIffalseExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } } -export class NestedExpressionAST extends ExpressionAST { +export class ImplicitCastExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitNestedExpression(this, context); - } - getLparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + return visitor.visitImplicitCastExpression(this, context); } getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); - } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class RightFoldExpressionAST extends ExpressionAST { +export class CastExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitRightFoldExpression(this, context); + return visitor.visitCastExpression(this, context); } getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getTypeId(): TypeIdAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getOpToken(): Token | undefined { + getRparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getEllipsisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); - } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class LeftFoldExpressionAST extends ExpressionAST { +export class CppCastExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitLeftFoldExpression(this, context); + return visitor.visitCppCastExpression(this, context); } - getLparenToken(): Token | undefined { + getCastToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getEllipsisToken(): Token | undefined { + getLessToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getOpToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getTypeId(): TypeIdAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } + getGreaterToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + return AST.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); } getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); } } -export class FoldExpressionAST extends ExpressionAST { +export class NewExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitFoldExpression(this, context); + return visitor.visitNewExpression(this, context); } - getLparenToken(): Token | undefined { + getScopeToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLeftExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); - } - getOpToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); - } - getEllipsisToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); - } - getFoldOpToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + getNewToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getRightExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); + getTypeId(): NewTypeIdAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); + getNewInitalizer(): NewInitializerAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class LambdaExpressionAST extends ExpressionAST { +export class DeleteExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitLambdaExpression(this, context); + return visitor.visitDeleteExpression(this, context); } - getLambdaIntroducer(): LambdaIntroducerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getScopeToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLessToken(): Token | undefined { + getDeleteToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - *getTemplateParameterList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getLbracketToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getGreaterToken(): Token | undefined { + getRbracketToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } - getRequiresClause(): RequiresClauseAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); - } - getLambdaDeclarator(): LambdaDeclaratorAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); - } - getStatement(): CompoundStatementAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } } -export class SizeofExpressionAST extends ExpressionAST { +export class ThrowExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitSizeofExpression(this, context); + return visitor.visitThrowExpression(this, context); } - getSizeofToken(): Token | undefined { + getThrowToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } getExpression(): ExpressionAST | undefined { @@ -1202,402 +1202,426 @@ export class SizeofExpressionAST extends ExpressionAST { } } -export class SizeofTypeExpressionAST extends ExpressionAST { +export class NoexceptExpressionAST extends ExpressionAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitSizeofTypeExpression(this, context); + return visitor.visitNoexceptExpression(this, context); } - getSizeofToken(): Token | undefined { + getNoexceptToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getTypeId(): TypeIdAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } getRparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class SizeofPackExpressionAST extends ExpressionAST { +export class SimpleRequirementAST extends RequirementAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitSizeofPackExpression(this, context); + return visitor.visitSimpleRequirement(this, context); } - getSizeofToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getEllipsisToken(): Token | undefined { + getSemicolonToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getLparenToken(): Token | undefined { +} + +export class CompoundRequirementAST extends RequirementAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitCompoundRequirement(this, context); + } + getLbraceToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + } + getRbraceToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getIdentifierToken(): Token | undefined { + getNoexceptToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } - getRparenToken(): Token | undefined { + getMinusGreaterToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); } + getTypeConstraint(): TypeConstraintAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); + } + getSemicolonToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); + } } -export class TypeidExpressionAST extends ExpressionAST { +export class TypeRequirementAST extends RequirementAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTypeidExpression(this, context); + return visitor.visitTypeRequirement(this, context); } - getTypeidToken(): Token | undefined { + getTypenameToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getNestedNameSpecifier(): NestedNameSpecifierAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getName(): NameAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getRparenToken(): Token | undefined { + getSemicolonToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class TypeidOfTypeExpressionAST extends ExpressionAST { +export class NestedRequirementAST extends RequirementAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTypeidOfTypeExpression(this, context); + return visitor.visitNestedRequirement(this, context); } - getTypeidToken(): Token | undefined { + getRequiresToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); - } - getTypeId(): TypeIdAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getSemicolonToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class AlignofExpressionAST extends ExpressionAST { +export class TypeTemplateArgumentAST extends TemplateArgumentAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitAlignofExpression(this, context); - } - getAlignofToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); - } - getLparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + return visitor.visitTypeTemplateArgument(this, context); } getTypeId(): TypeIdAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); +} + +export class ExpressionTemplateArgumentAST extends TemplateArgumentAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitExpressionTemplateArgument(this, context); + } + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class TypeTraitsExpressionAST extends ExpressionAST { +export class ParenMemInitializerAST extends MemInitializerAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTypeTraitsExpression(this, context); + return visitor.visitParenMemInitializer(this, context); } - getTypeTraitsToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getName(): NameAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } getLparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - *getTypeIdList(): Generator { + *getExpressionList(): Generator { for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); + yield AST.from(cxx.getListValue(it), this.parser); } } getRparenToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } + getEllipsisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + } } -export class UnaryExpressionAST extends ExpressionAST { +export class BracedMemInitializerAST extends MemInitializerAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitUnaryExpression(this, context); + return visitor.visitBracedMemInitializer(this, context); } - getOpToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getName(): NameAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getBracedInitList(): BracedInitListAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + } + getEllipsisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class BinaryExpressionAST extends ExpressionAST { +export class ThisLambdaCaptureAST extends LambdaCaptureAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitBinaryExpression(this, context); - } - getLeftExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); - } - getOpToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + return visitor.visitThisLambdaCapture(this, context); } - getRightExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getThisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class AssignmentExpressionAST extends ExpressionAST { +export class DerefThisLambdaCaptureAST extends LambdaCaptureAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitAssignmentExpression(this, context); + return visitor.visitDerefThisLambdaCapture(this, context); } - getLeftExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getStarToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getOpToken(): Token | undefined { + getThisToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getRightExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); - } } -export class BracedTypeConstructionAST extends ExpressionAST { +export class SimpleLambdaCaptureAST extends LambdaCaptureAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitBracedTypeConstruction(this, context); + return visitor.visitSimpleLambdaCapture(this, context); } - getTypeSpecifier(): SpecifierAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getIdentifierToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getBracedInitList(): BracedInitListAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getEllipsisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } } -export class TypeConstructionAST extends ExpressionAST { +export class RefLambdaCaptureAST extends LambdaCaptureAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitTypeConstruction(this, context); + return visitor.visitRefLambdaCapture(this, context); } - getTypeSpecifier(): SpecifierAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getAmpToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLparenToken(): Token | undefined { + getIdentifierToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - *getExpressionList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } - } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getEllipsisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class CallExpressionAST extends ExpressionAST { +export class RefInitLambdaCaptureAST extends LambdaCaptureAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitCallExpression(this, context); + return visitor.visitRefInitLambdaCapture(this, context); } - getBaseExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getAmpToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLparenToken(): Token | undefined { + getEllipsisToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - *getExpressionList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } + getIdentifierToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getInitializer(): InitializerAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class SubscriptExpressionAST extends ExpressionAST { +export class InitLambdaCaptureAST extends LambdaCaptureAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitSubscriptExpression(this, context); + return visitor.visitInitLambdaCapture(this, context); } - getBaseExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getEllipsisToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLbracketToken(): Token | undefined { + getIdentifierToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getIndexExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getInitializer(): InitializerAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } +} + +export class EqualInitializerAST extends InitializerAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitEqualInitializer(this, context); + } + getEqualToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getRbracketToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } } -export class MemberExpressionAST extends ExpressionAST { +export class BracedInitListAST extends InitializerAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitMemberExpression(this, context); + return visitor.visitBracedInitList(this, context); } - getBaseExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLbraceToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getAccessToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + *getExpressionList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } } - getTemplateToken(): Token | undefined { + getCommaToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getName(): NameAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getRbraceToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } -export class PostIncrExpressionAST extends ExpressionAST { +export class ParenInitializerAST extends InitializerAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitPostIncrExpression(this, context); + return visitor.visitParenInitializer(this, context); } - getBaseExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getOpToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + *getExpressionList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class ConditionalExpressionAST extends ExpressionAST { +export class NewParenInitializerAST extends NewInitializerAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitConditionalExpression(this, context); - } - getCondition(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); - } - getQuestionToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + return visitor.visitNewParenInitializer(this, context); } - getIftrueExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getColonToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + *getExpressionList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } } - getIffalseExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class ImplicitCastExpressionAST extends ExpressionAST { +export class NewBracedInitializerAST extends NewInitializerAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitImplicitCastExpression(this, context); + return visitor.visitNewBracedInitializer(this, context); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getBracedInit(): BracedInitListAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } } -export class CastExpressionAST extends ExpressionAST { +export class EllipsisExceptionDeclarationAST extends ExceptionDeclarationAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitCastExpression(this, context); + return visitor.visitEllipsisExceptionDeclaration(this, context); } - getLparenToken(): Token | undefined { + getEllipsisToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getTypeId(): TypeIdAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); +} + +export class TypeExceptionDeclarationAST extends ExceptionDeclarationAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitTypeExceptionDeclaration(this, context); } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + *getAttributeList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 0); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + *getTypeSpecifierList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + getDeclarator(): DeclaratorAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } -export class CppCastExpressionAST extends ExpressionAST { +export class DefaultFunctionBodyAST extends FunctionBodyAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitCppCastExpression(this, context); + return visitor.visitDefaultFunctionBody(this, context); } - getCastToken(): Token | undefined { + getEqualToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLessToken(): Token | undefined { + getDefaultToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getTypeId(): TypeIdAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); - } - getGreaterToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getSemicolonToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getLparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); +} + +export class CompoundStatementFunctionBodyAST extends FunctionBodyAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitCompoundStatementFunctionBody(this, context); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); + getCtorInitializer(): CtorInitializerAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); + getStatement(): CompoundStatementAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } } -export class NewExpressionAST extends ExpressionAST { +export class TryStatementFunctionBodyAST extends FunctionBodyAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitNewExpression(this, context); + return visitor.visitTryStatementFunctionBody(this, context); } - getScopeToken(): Token | undefined { + getTryToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getNewToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getCtorInitializer(): CtorInitializerAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getTypeId(): NewTypeIdAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getStatement(): CompoundStatementAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getNewInitalizer(): NewInitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + *getHandlerList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 3); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } } } -export class DeleteExpressionAST extends ExpressionAST { +export class DeleteFunctionBodyAST extends FunctionBodyAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitDeleteExpression(this, context); + return visitor.visitDeleteFunctionBody(this, context); } - getScopeToken(): Token | undefined { + getEqualToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } getDeleteToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getLbracketToken(): Token | undefined { + getSemicolonToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getRbracketToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); - } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 4), this.parser); - } } -export class ThrowExpressionAST extends ExpressionAST { +export class TranslationUnitAST extends UnitAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitThrowExpression(this, context); - } - getThrowToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + return visitor.visitTranslationUnit(this, context); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + *getDeclarationList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 0); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } } } -export class NoexceptExpressionAST extends ExpressionAST { +export class ModuleUnitAST extends UnitAST { accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitNoexceptExpression(this, context); + return visitor.visitModuleUnit(this, context); } - getNoexceptToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + getGlobalModuleFragment(): GlobalModuleFragmentAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getLparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getModuleDeclaration(): ModuleDeclarationAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + *getDeclarationList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 2); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getPrivateModuleFragment(): PrivateModuleFragmentAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } @@ -3290,33 +3314,8 @@ const AST_CONSTRUCTORS: Array { abstract visitAttributeArgumentClause(node: ast.AttributeArgumentClauseAST, context: Context): Result; abstract visitAttribute(node: ast.AttributeAST, context: Context): Result; abstract visitAttributeUsingPrefix(node: ast.AttributeUsingPrefixAST, context: Context): Result; + abstract visitDesignator(node: ast.DesignatorAST, context: Context): Result; + + // ExpressionAST + abstract visitDesignatedInitializerClause(node: ast.DesignatedInitializerClauseAST, context: Context): Result; + abstract visitThisExpression(node: ast.ThisExpressionAST, context: Context): Result; + abstract visitCharLiteralExpression(node: ast.CharLiteralExpressionAST, context: Context): Result; + abstract visitBoolLiteralExpression(node: ast.BoolLiteralExpressionAST, context: Context): Result; + abstract visitIntLiteralExpression(node: ast.IntLiteralExpressionAST, context: Context): Result; + abstract visitFloatLiteralExpression(node: ast.FloatLiteralExpressionAST, context: Context): Result; + abstract visitNullptrLiteralExpression(node: ast.NullptrLiteralExpressionAST, context: Context): Result; + abstract visitStringLiteralExpression(node: ast.StringLiteralExpressionAST, context: Context): Result; + abstract visitUserDefinedStringLiteralExpression(node: ast.UserDefinedStringLiteralExpressionAST, context: Context): Result; + abstract visitIdExpression(node: ast.IdExpressionAST, context: Context): Result; + abstract visitRequiresExpression(node: ast.RequiresExpressionAST, context: Context): Result; + abstract visitNestedExpression(node: ast.NestedExpressionAST, context: Context): Result; + abstract visitRightFoldExpression(node: ast.RightFoldExpressionAST, context: Context): Result; + abstract visitLeftFoldExpression(node: ast.LeftFoldExpressionAST, context: Context): Result; + abstract visitFoldExpression(node: ast.FoldExpressionAST, context: Context): Result; + abstract visitLambdaExpression(node: ast.LambdaExpressionAST, context: Context): Result; + abstract visitSizeofExpression(node: ast.SizeofExpressionAST, context: Context): Result; + abstract visitSizeofTypeExpression(node: ast.SizeofTypeExpressionAST, context: Context): Result; + abstract visitSizeofPackExpression(node: ast.SizeofPackExpressionAST, context: Context): Result; + abstract visitTypeidExpression(node: ast.TypeidExpressionAST, context: Context): Result; + abstract visitTypeidOfTypeExpression(node: ast.TypeidOfTypeExpressionAST, context: Context): Result; + abstract visitAlignofExpression(node: ast.AlignofExpressionAST, context: Context): Result; + abstract visitTypeTraitsExpression(node: ast.TypeTraitsExpressionAST, context: Context): Result; + abstract visitUnaryExpression(node: ast.UnaryExpressionAST, context: Context): Result; + abstract visitBinaryExpression(node: ast.BinaryExpressionAST, context: Context): Result; + abstract visitAssignmentExpression(node: ast.AssignmentExpressionAST, context: Context): Result; + abstract visitBracedTypeConstruction(node: ast.BracedTypeConstructionAST, context: Context): Result; + abstract visitTypeConstruction(node: ast.TypeConstructionAST, context: Context): Result; + abstract visitCallExpression(node: ast.CallExpressionAST, context: Context): Result; + abstract visitSubscriptExpression(node: ast.SubscriptExpressionAST, context: Context): Result; + abstract visitMemberExpression(node: ast.MemberExpressionAST, context: Context): Result; + abstract visitPostIncrExpression(node: ast.PostIncrExpressionAST, context: Context): Result; + abstract visitConditionalExpression(node: ast.ConditionalExpressionAST, context: Context): Result; + abstract visitImplicitCastExpression(node: ast.ImplicitCastExpressionAST, context: Context): Result; + abstract visitCastExpression(node: ast.CastExpressionAST, context: Context): Result; + abstract visitCppCastExpression(node: ast.CppCastExpressionAST, context: Context): Result; + abstract visitNewExpression(node: ast.NewExpressionAST, context: Context): Result; + abstract visitDeleteExpression(node: ast.DeleteExpressionAST, context: Context): Result; + abstract visitThrowExpression(node: ast.ThrowExpressionAST, context: Context): Result; + abstract visitNoexceptExpression(node: ast.NoexceptExpressionAST, context: Context): Result; // RequirementAST abstract visitSimpleRequirement(node: ast.SimpleRequirementAST, context: Context): Result; @@ -100,47 +143,6 @@ export abstract class ASTVisitor { abstract visitTranslationUnit(node: ast.TranslationUnitAST, context: Context): Result; abstract visitModuleUnit(node: ast.ModuleUnitAST, context: Context): Result; - // ExpressionAST - abstract visitThisExpression(node: ast.ThisExpressionAST, context: Context): Result; - abstract visitCharLiteralExpression(node: ast.CharLiteralExpressionAST, context: Context): Result; - abstract visitBoolLiteralExpression(node: ast.BoolLiteralExpressionAST, context: Context): Result; - abstract visitIntLiteralExpression(node: ast.IntLiteralExpressionAST, context: Context): Result; - abstract visitFloatLiteralExpression(node: ast.FloatLiteralExpressionAST, context: Context): Result; - abstract visitNullptrLiteralExpression(node: ast.NullptrLiteralExpressionAST, context: Context): Result; - abstract visitStringLiteralExpression(node: ast.StringLiteralExpressionAST, context: Context): Result; - abstract visitUserDefinedStringLiteralExpression(node: ast.UserDefinedStringLiteralExpressionAST, context: Context): Result; - abstract visitIdExpression(node: ast.IdExpressionAST, context: Context): Result; - abstract visitRequiresExpression(node: ast.RequiresExpressionAST, context: Context): Result; - abstract visitNestedExpression(node: ast.NestedExpressionAST, context: Context): Result; - abstract visitRightFoldExpression(node: ast.RightFoldExpressionAST, context: Context): Result; - abstract visitLeftFoldExpression(node: ast.LeftFoldExpressionAST, context: Context): Result; - abstract visitFoldExpression(node: ast.FoldExpressionAST, context: Context): Result; - abstract visitLambdaExpression(node: ast.LambdaExpressionAST, context: Context): Result; - abstract visitSizeofExpression(node: ast.SizeofExpressionAST, context: Context): Result; - abstract visitSizeofTypeExpression(node: ast.SizeofTypeExpressionAST, context: Context): Result; - abstract visitSizeofPackExpression(node: ast.SizeofPackExpressionAST, context: Context): Result; - abstract visitTypeidExpression(node: ast.TypeidExpressionAST, context: Context): Result; - abstract visitTypeidOfTypeExpression(node: ast.TypeidOfTypeExpressionAST, context: Context): Result; - abstract visitAlignofExpression(node: ast.AlignofExpressionAST, context: Context): Result; - abstract visitTypeTraitsExpression(node: ast.TypeTraitsExpressionAST, context: Context): Result; - abstract visitUnaryExpression(node: ast.UnaryExpressionAST, context: Context): Result; - abstract visitBinaryExpression(node: ast.BinaryExpressionAST, context: Context): Result; - abstract visitAssignmentExpression(node: ast.AssignmentExpressionAST, context: Context): Result; - abstract visitBracedTypeConstruction(node: ast.BracedTypeConstructionAST, context: Context): Result; - abstract visitTypeConstruction(node: ast.TypeConstructionAST, context: Context): Result; - abstract visitCallExpression(node: ast.CallExpressionAST, context: Context): Result; - abstract visitSubscriptExpression(node: ast.SubscriptExpressionAST, context: Context): Result; - abstract visitMemberExpression(node: ast.MemberExpressionAST, context: Context): Result; - abstract visitPostIncrExpression(node: ast.PostIncrExpressionAST, context: Context): Result; - abstract visitConditionalExpression(node: ast.ConditionalExpressionAST, context: Context): Result; - abstract visitImplicitCastExpression(node: ast.ImplicitCastExpressionAST, context: Context): Result; - abstract visitCastExpression(node: ast.CastExpressionAST, context: Context): Result; - abstract visitCppCastExpression(node: ast.CppCastExpressionAST, context: Context): Result; - abstract visitNewExpression(node: ast.NewExpressionAST, context: Context): Result; - abstract visitDeleteExpression(node: ast.DeleteExpressionAST, context: Context): Result; - abstract visitThrowExpression(node: ast.ThrowExpressionAST, context: Context): Result; - abstract visitNoexceptExpression(node: ast.NoexceptExpressionAST, context: Context): Result; - // StatementAST abstract visitLabeledStatement(node: ast.LabeledStatementAST, context: Context): Result; abstract visitCaseStatement(node: ast.CaseStatementAST, context: Context): Result; diff --git a/packages/cxx-frontend/src/RecursiveASTVisitor.ts b/packages/cxx-frontend/src/RecursiveASTVisitor.ts index f222f855..6adb734d 100644 --- a/packages/cxx-frontend/src/RecursiveASTVisitor.ts +++ b/packages/cxx-frontend/src/RecursiveASTVisitor.ts @@ -203,137 +203,14 @@ export class RecursiveASTVisitor extends ASTVisitor { visitAttributeUsingPrefix(node: ast.AttributeUsingPrefixAST, context: Context): void { } - visitSimpleRequirement(node: ast.SimpleRequirementAST, context: Context): void { - this.accept(node.getExpression(), context); + visitDesignator(node: ast.DesignatorAST, context: Context): void { } - visitCompoundRequirement(node: ast.CompoundRequirementAST, context: Context): void { - this.accept(node.getExpression(), context); - this.accept(node.getTypeConstraint(), context); - } - - visitTypeRequirement(node: ast.TypeRequirementAST, context: Context): void { - this.accept(node.getNestedNameSpecifier(), context); - this.accept(node.getName(), context); - } - - visitNestedRequirement(node: ast.NestedRequirementAST, context: Context): void { - this.accept(node.getExpression(), context); - } - - visitTypeTemplateArgument(node: ast.TypeTemplateArgumentAST, context: Context): void { - this.accept(node.getTypeId(), context); - } - - visitExpressionTemplateArgument(node: ast.ExpressionTemplateArgumentAST, context: Context): void { - this.accept(node.getExpression(), context); - } - - visitParenMemInitializer(node: ast.ParenMemInitializerAST, context: Context): void { - this.accept(node.getName(), context); - for (const element of node.getExpressionList()) { - this.accept(element, context); - } - } - - visitBracedMemInitializer(node: ast.BracedMemInitializerAST, context: Context): void { - this.accept(node.getName(), context); - this.accept(node.getBracedInitList(), context); - } - - visitThisLambdaCapture(node: ast.ThisLambdaCaptureAST, context: Context): void { - } - - visitDerefThisLambdaCapture(node: ast.DerefThisLambdaCaptureAST, context: Context): void { - } - - visitSimpleLambdaCapture(node: ast.SimpleLambdaCaptureAST, context: Context): void { - } - - visitRefLambdaCapture(node: ast.RefLambdaCaptureAST, context: Context): void { - } - - visitRefInitLambdaCapture(node: ast.RefInitLambdaCaptureAST, context: Context): void { + visitDesignatedInitializerClause(node: ast.DesignatedInitializerClauseAST, context: Context): void { + this.accept(node.getDesignator(), context); this.accept(node.getInitializer(), context); } - visitInitLambdaCapture(node: ast.InitLambdaCaptureAST, context: Context): void { - this.accept(node.getInitializer(), context); - } - - visitEqualInitializer(node: ast.EqualInitializerAST, context: Context): void { - this.accept(node.getExpression(), context); - } - - visitBracedInitList(node: ast.BracedInitListAST, context: Context): void { - for (const element of node.getExpressionList()) { - this.accept(element, context); - } - } - - visitParenInitializer(node: ast.ParenInitializerAST, context: Context): void { - for (const element of node.getExpressionList()) { - this.accept(element, context); - } - } - - visitNewParenInitializer(node: ast.NewParenInitializerAST, context: Context): void { - for (const element of node.getExpressionList()) { - this.accept(element, context); - } - } - - visitNewBracedInitializer(node: ast.NewBracedInitializerAST, context: Context): void { - this.accept(node.getBracedInit(), context); - } - - visitEllipsisExceptionDeclaration(node: ast.EllipsisExceptionDeclarationAST, context: Context): void { - } - - visitTypeExceptionDeclaration(node: ast.TypeExceptionDeclarationAST, context: Context): void { - for (const element of node.getAttributeList()) { - this.accept(element, context); - } - for (const element of node.getTypeSpecifierList()) { - this.accept(element, context); - } - this.accept(node.getDeclarator(), context); - } - - visitDefaultFunctionBody(node: ast.DefaultFunctionBodyAST, context: Context): void { - } - - visitCompoundStatementFunctionBody(node: ast.CompoundStatementFunctionBodyAST, context: Context): void { - this.accept(node.getCtorInitializer(), context); - this.accept(node.getStatement(), context); - } - - visitTryStatementFunctionBody(node: ast.TryStatementFunctionBodyAST, context: Context): void { - this.accept(node.getCtorInitializer(), context); - this.accept(node.getStatement(), context); - for (const element of node.getHandlerList()) { - this.accept(element, context); - } - } - - visitDeleteFunctionBody(node: ast.DeleteFunctionBodyAST, context: Context): void { - } - - visitTranslationUnit(node: ast.TranslationUnitAST, context: Context): void { - for (const element of node.getDeclarationList()) { - this.accept(element, context); - } - } - - visitModuleUnit(node: ast.ModuleUnitAST, context: Context): void { - this.accept(node.getGlobalModuleFragment(), context); - this.accept(node.getModuleDeclaration(), context); - for (const element of node.getDeclarationList()) { - this.accept(element, context); - } - this.accept(node.getPrivateModuleFragment(), context); - } - visitThisExpression(node: ast.ThisExpressionAST, context: Context): void { } @@ -507,6 +384,137 @@ export class RecursiveASTVisitor extends ASTVisitor { this.accept(node.getExpression(), context); } + visitSimpleRequirement(node: ast.SimpleRequirementAST, context: Context): void { + this.accept(node.getExpression(), context); + } + + visitCompoundRequirement(node: ast.CompoundRequirementAST, context: Context): void { + this.accept(node.getExpression(), context); + this.accept(node.getTypeConstraint(), context); + } + + visitTypeRequirement(node: ast.TypeRequirementAST, context: Context): void { + this.accept(node.getNestedNameSpecifier(), context); + this.accept(node.getName(), context); + } + + visitNestedRequirement(node: ast.NestedRequirementAST, context: Context): void { + this.accept(node.getExpression(), context); + } + + visitTypeTemplateArgument(node: ast.TypeTemplateArgumentAST, context: Context): void { + this.accept(node.getTypeId(), context); + } + + visitExpressionTemplateArgument(node: ast.ExpressionTemplateArgumentAST, context: Context): void { + this.accept(node.getExpression(), context); + } + + visitParenMemInitializer(node: ast.ParenMemInitializerAST, context: Context): void { + this.accept(node.getName(), context); + for (const element of node.getExpressionList()) { + this.accept(element, context); + } + } + + visitBracedMemInitializer(node: ast.BracedMemInitializerAST, context: Context): void { + this.accept(node.getName(), context); + this.accept(node.getBracedInitList(), context); + } + + visitThisLambdaCapture(node: ast.ThisLambdaCaptureAST, context: Context): void { + } + + visitDerefThisLambdaCapture(node: ast.DerefThisLambdaCaptureAST, context: Context): void { + } + + visitSimpleLambdaCapture(node: ast.SimpleLambdaCaptureAST, context: Context): void { + } + + visitRefLambdaCapture(node: ast.RefLambdaCaptureAST, context: Context): void { + } + + visitRefInitLambdaCapture(node: ast.RefInitLambdaCaptureAST, context: Context): void { + this.accept(node.getInitializer(), context); + } + + visitInitLambdaCapture(node: ast.InitLambdaCaptureAST, context: Context): void { + this.accept(node.getInitializer(), context); + } + + visitEqualInitializer(node: ast.EqualInitializerAST, context: Context): void { + this.accept(node.getExpression(), context); + } + + visitBracedInitList(node: ast.BracedInitListAST, context: Context): void { + for (const element of node.getExpressionList()) { + this.accept(element, context); + } + } + + visitParenInitializer(node: ast.ParenInitializerAST, context: Context): void { + for (const element of node.getExpressionList()) { + this.accept(element, context); + } + } + + visitNewParenInitializer(node: ast.NewParenInitializerAST, context: Context): void { + for (const element of node.getExpressionList()) { + this.accept(element, context); + } + } + + visitNewBracedInitializer(node: ast.NewBracedInitializerAST, context: Context): void { + this.accept(node.getBracedInit(), context); + } + + visitEllipsisExceptionDeclaration(node: ast.EllipsisExceptionDeclarationAST, context: Context): void { + } + + visitTypeExceptionDeclaration(node: ast.TypeExceptionDeclarationAST, context: Context): void { + for (const element of node.getAttributeList()) { + this.accept(element, context); + } + for (const element of node.getTypeSpecifierList()) { + this.accept(element, context); + } + this.accept(node.getDeclarator(), context); + } + + visitDefaultFunctionBody(node: ast.DefaultFunctionBodyAST, context: Context): void { + } + + visitCompoundStatementFunctionBody(node: ast.CompoundStatementFunctionBodyAST, context: Context): void { + this.accept(node.getCtorInitializer(), context); + this.accept(node.getStatement(), context); + } + + visitTryStatementFunctionBody(node: ast.TryStatementFunctionBodyAST, context: Context): void { + this.accept(node.getCtorInitializer(), context); + this.accept(node.getStatement(), context); + for (const element of node.getHandlerList()) { + this.accept(element, context); + } + } + + visitDeleteFunctionBody(node: ast.DeleteFunctionBodyAST, context: Context): void { + } + + visitTranslationUnit(node: ast.TranslationUnitAST, context: Context): void { + for (const element of node.getDeclarationList()) { + this.accept(element, context); + } + } + + visitModuleUnit(node: ast.ModuleUnitAST, context: Context): void { + this.accept(node.getGlobalModuleFragment(), context); + this.accept(node.getModuleDeclaration(), context); + for (const element of node.getDeclarationList()) { + this.accept(element, context); + } + this.accept(node.getPrivateModuleFragment(), context); + } + visitLabeledStatement(node: ast.LabeledStatementAST, context: Context): void { this.accept(node.getStatement(), context); } diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index a9f9b5f4..c2c731cb 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -389,222 +389,17 @@ void ASTPrinter::visit(AttributeUsingPrefixAST* ast) { fmt::print(out_, "{}\n", "attribute-using-prefix"); } -void ASTPrinter::visit(SimpleRequirementAST* ast) { - fmt::print(out_, "{}\n", "simple-requirement"); - accept(ast->expression, "expression"); -} - -void ASTPrinter::visit(CompoundRequirementAST* ast) { - fmt::print(out_, "{}\n", "compound-requirement"); - accept(ast->expression, "expression"); - accept(ast->typeConstraint, "type-constraint"); -} - -void ASTPrinter::visit(TypeRequirementAST* ast) { - fmt::print(out_, "{}\n", "type-requirement"); - accept(ast->nestedNameSpecifier, "nested-name-specifier"); - accept(ast->name, "name"); -} - -void ASTPrinter::visit(NestedRequirementAST* ast) { - fmt::print(out_, "{}\n", "nested-requirement"); - accept(ast->expression, "expression"); -} - -void ASTPrinter::visit(TypeTemplateArgumentAST* ast) { - fmt::print(out_, "{}\n", "type-template-argument"); - accept(ast->typeId, "type-id"); -} - -void ASTPrinter::visit(ExpressionTemplateArgumentAST* ast) { - fmt::print(out_, "{}\n", "expression-template-argument"); - accept(ast->expression, "expression"); -} - -void ASTPrinter::visit(ParenMemInitializerAST* ast) { - fmt::print(out_, "{}\n", "paren-mem-initializer"); - accept(ast->name, "name"); - if (ast->expressionList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "expression-list"); - for (auto it = ast->expressionList; it; it = it->next) { - accept(it->value); - } - --indent_; - } -} - -void ASTPrinter::visit(BracedMemInitializerAST* ast) { - fmt::print(out_, "{}\n", "braced-mem-initializer"); - accept(ast->name, "name"); - accept(ast->bracedInitList, "braced-init-list"); -} - -void ASTPrinter::visit(ThisLambdaCaptureAST* ast) { - fmt::print(out_, "{}\n", "this-lambda-capture"); -} - -void ASTPrinter::visit(DerefThisLambdaCaptureAST* ast) { - fmt::print(out_, "{}\n", "deref-this-lambda-capture"); -} - -void ASTPrinter::visit(SimpleLambdaCaptureAST* ast) { - fmt::print(out_, "{}\n", "simple-lambda-capture"); +void ASTPrinter::visit(DesignatorAST* ast) { + fmt::print(out_, "{}\n", "designator"); accept(ast->identifier, "identifier"); } -void ASTPrinter::visit(RefLambdaCaptureAST* ast) { - fmt::print(out_, "{}\n", "ref-lambda-capture"); - accept(ast->identifier, "identifier"); -} - -void ASTPrinter::visit(RefInitLambdaCaptureAST* ast) { - fmt::print(out_, "{}\n", "ref-init-lambda-capture"); - accept(ast->identifier, "identifier"); +void ASTPrinter::visit(DesignatedInitializerClauseAST* ast) { + fmt::print(out_, "{}\n", "designated-initializer-clause"); + accept(ast->designator, "designator"); accept(ast->initializer, "initializer"); } -void ASTPrinter::visit(InitLambdaCaptureAST* ast) { - fmt::print(out_, "{}\n", "init-lambda-capture"); - accept(ast->identifier, "identifier"); - accept(ast->initializer, "initializer"); -} - -void ASTPrinter::visit(EqualInitializerAST* ast) { - fmt::print(out_, "{}\n", "equal-initializer"); - accept(ast->expression, "expression"); -} - -void ASTPrinter::visit(BracedInitListAST* ast) { - fmt::print(out_, "{}\n", "braced-init-list"); - if (ast->expressionList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "expression-list"); - for (auto it = ast->expressionList; it; it = it->next) { - accept(it->value); - } - --indent_; - } -} - -void ASTPrinter::visit(ParenInitializerAST* ast) { - fmt::print(out_, "{}\n", "paren-initializer"); - if (ast->expressionList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "expression-list"); - for (auto it = ast->expressionList; it; it = it->next) { - accept(it->value); - } - --indent_; - } -} - -void ASTPrinter::visit(NewParenInitializerAST* ast) { - fmt::print(out_, "{}\n", "new-paren-initializer"); - if (ast->expressionList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "expression-list"); - for (auto it = ast->expressionList; it; it = it->next) { - accept(it->value); - } - --indent_; - } -} - -void ASTPrinter::visit(NewBracedInitializerAST* ast) { - fmt::print(out_, "{}\n", "new-braced-initializer"); - accept(ast->bracedInit, "braced-init"); -} - -void ASTPrinter::visit(EllipsisExceptionDeclarationAST* ast) { - fmt::print(out_, "{}\n", "ellipsis-exception-declaration"); -} - -void ASTPrinter::visit(TypeExceptionDeclarationAST* ast) { - fmt::print(out_, "{}\n", "type-exception-declaration"); - if (ast->attributeList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "attribute-list"); - for (auto it = ast->attributeList; it; it = it->next) { - accept(it->value); - } - --indent_; - } - if (ast->typeSpecifierList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "type-specifier-list"); - for (auto it = ast->typeSpecifierList; it; it = it->next) { - accept(it->value); - } - --indent_; - } - accept(ast->declarator, "declarator"); -} - -void ASTPrinter::visit(DefaultFunctionBodyAST* ast) { - fmt::print(out_, "{}\n", "default-function-body"); -} - -void ASTPrinter::visit(CompoundStatementFunctionBodyAST* ast) { - fmt::print(out_, "{}\n", "compound-statement-function-body"); - accept(ast->ctorInitializer, "ctor-initializer"); - accept(ast->statement, "statement"); -} - -void ASTPrinter::visit(TryStatementFunctionBodyAST* ast) { - fmt::print(out_, "{}\n", "try-statement-function-body"); - accept(ast->ctorInitializer, "ctor-initializer"); - accept(ast->statement, "statement"); - if (ast->handlerList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "handler-list"); - for (auto it = ast->handlerList; it; it = it->next) { - accept(it->value); - } - --indent_; - } -} - -void ASTPrinter::visit(DeleteFunctionBodyAST* ast) { - fmt::print(out_, "{}\n", "delete-function-body"); -} - -void ASTPrinter::visit(TranslationUnitAST* ast) { - fmt::print(out_, "{}\n", "translation-unit"); - if (ast->declarationList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "declaration-list"); - for (auto it = ast->declarationList; it; it = it->next) { - accept(it->value); - } - --indent_; - } -} - -void ASTPrinter::visit(ModuleUnitAST* ast) { - fmt::print(out_, "{}\n", "module-unit"); - accept(ast->globalModuleFragment, "global-module-fragment"); - accept(ast->moduleDeclaration, "module-declaration"); - if (ast->declarationList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "declaration-list"); - for (auto it = ast->declarationList; it; it = it->next) { - accept(it->value); - } - --indent_; - } - accept(ast->privateModuleFragment, "private-module-fragment"); -} - void ASTPrinter::visit(ThisExpressionAST* ast) { fmt::print(out_, "{}\n", "this-expression"); } @@ -942,6 +737,222 @@ void ASTPrinter::visit(NoexceptExpressionAST* ast) { accept(ast->expression, "expression"); } +void ASTPrinter::visit(SimpleRequirementAST* ast) { + fmt::print(out_, "{}\n", "simple-requirement"); + accept(ast->expression, "expression"); +} + +void ASTPrinter::visit(CompoundRequirementAST* ast) { + fmt::print(out_, "{}\n", "compound-requirement"); + accept(ast->expression, "expression"); + accept(ast->typeConstraint, "type-constraint"); +} + +void ASTPrinter::visit(TypeRequirementAST* ast) { + fmt::print(out_, "{}\n", "type-requirement"); + accept(ast->nestedNameSpecifier, "nested-name-specifier"); + accept(ast->name, "name"); +} + +void ASTPrinter::visit(NestedRequirementAST* ast) { + fmt::print(out_, "{}\n", "nested-requirement"); + accept(ast->expression, "expression"); +} + +void ASTPrinter::visit(TypeTemplateArgumentAST* ast) { + fmt::print(out_, "{}\n", "type-template-argument"); + accept(ast->typeId, "type-id"); +} + +void ASTPrinter::visit(ExpressionTemplateArgumentAST* ast) { + fmt::print(out_, "{}\n", "expression-template-argument"); + accept(ast->expression, "expression"); +} + +void ASTPrinter::visit(ParenMemInitializerAST* ast) { + fmt::print(out_, "{}\n", "paren-mem-initializer"); + accept(ast->name, "name"); + if (ast->expressionList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); + for (auto it = ast->expressionList; it; it = it->next) { + accept(it->value); + } + --indent_; + } +} + +void ASTPrinter::visit(BracedMemInitializerAST* ast) { + fmt::print(out_, "{}\n", "braced-mem-initializer"); + accept(ast->name, "name"); + accept(ast->bracedInitList, "braced-init-list"); +} + +void ASTPrinter::visit(ThisLambdaCaptureAST* ast) { + fmt::print(out_, "{}\n", "this-lambda-capture"); +} + +void ASTPrinter::visit(DerefThisLambdaCaptureAST* ast) { + fmt::print(out_, "{}\n", "deref-this-lambda-capture"); +} + +void ASTPrinter::visit(SimpleLambdaCaptureAST* ast) { + fmt::print(out_, "{}\n", "simple-lambda-capture"); + accept(ast->identifier, "identifier"); +} + +void ASTPrinter::visit(RefLambdaCaptureAST* ast) { + fmt::print(out_, "{}\n", "ref-lambda-capture"); + accept(ast->identifier, "identifier"); +} + +void ASTPrinter::visit(RefInitLambdaCaptureAST* ast) { + fmt::print(out_, "{}\n", "ref-init-lambda-capture"); + accept(ast->identifier, "identifier"); + accept(ast->initializer, "initializer"); +} + +void ASTPrinter::visit(InitLambdaCaptureAST* ast) { + fmt::print(out_, "{}\n", "init-lambda-capture"); + accept(ast->identifier, "identifier"); + accept(ast->initializer, "initializer"); +} + +void ASTPrinter::visit(EqualInitializerAST* ast) { + fmt::print(out_, "{}\n", "equal-initializer"); + accept(ast->expression, "expression"); +} + +void ASTPrinter::visit(BracedInitListAST* ast) { + fmt::print(out_, "{}\n", "braced-init-list"); + if (ast->expressionList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); + for (auto it = ast->expressionList; it; it = it->next) { + accept(it->value); + } + --indent_; + } +} + +void ASTPrinter::visit(ParenInitializerAST* ast) { + fmt::print(out_, "{}\n", "paren-initializer"); + if (ast->expressionList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); + for (auto it = ast->expressionList; it; it = it->next) { + accept(it->value); + } + --indent_; + } +} + +void ASTPrinter::visit(NewParenInitializerAST* ast) { + fmt::print(out_, "{}\n", "new-paren-initializer"); + if (ast->expressionList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); + for (auto it = ast->expressionList; it; it = it->next) { + accept(it->value); + } + --indent_; + } +} + +void ASTPrinter::visit(NewBracedInitializerAST* ast) { + fmt::print(out_, "{}\n", "new-braced-initializer"); + accept(ast->bracedInit, "braced-init"); +} + +void ASTPrinter::visit(EllipsisExceptionDeclarationAST* ast) { + fmt::print(out_, "{}\n", "ellipsis-exception-declaration"); +} + +void ASTPrinter::visit(TypeExceptionDeclarationAST* ast) { + fmt::print(out_, "{}\n", "type-exception-declaration"); + if (ast->attributeList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); + for (auto it = ast->attributeList; it; it = it->next) { + accept(it->value); + } + --indent_; + } + if (ast->typeSpecifierList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "type-specifier-list"); + for (auto it = ast->typeSpecifierList; it; it = it->next) { + accept(it->value); + } + --indent_; + } + accept(ast->declarator, "declarator"); +} + +void ASTPrinter::visit(DefaultFunctionBodyAST* ast) { + fmt::print(out_, "{}\n", "default-function-body"); +} + +void ASTPrinter::visit(CompoundStatementFunctionBodyAST* ast) { + fmt::print(out_, "{}\n", "compound-statement-function-body"); + accept(ast->ctorInitializer, "ctor-initializer"); + accept(ast->statement, "statement"); +} + +void ASTPrinter::visit(TryStatementFunctionBodyAST* ast) { + fmt::print(out_, "{}\n", "try-statement-function-body"); + accept(ast->ctorInitializer, "ctor-initializer"); + accept(ast->statement, "statement"); + if (ast->handlerList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "handler-list"); + for (auto it = ast->handlerList; it; it = it->next) { + accept(it->value); + } + --indent_; + } +} + +void ASTPrinter::visit(DeleteFunctionBodyAST* ast) { + fmt::print(out_, "{}\n", "delete-function-body"); +} + +void ASTPrinter::visit(TranslationUnitAST* ast) { + fmt::print(out_, "{}\n", "translation-unit"); + if (ast->declarationList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); + for (auto it = ast->declarationList; it; it = it->next) { + accept(it->value); + } + --indent_; + } +} + +void ASTPrinter::visit(ModuleUnitAST* ast) { + fmt::print(out_, "{}\n", "module-unit"); + accept(ast->globalModuleFragment, "global-module-fragment"); + accept(ast->moduleDeclaration, "module-declaration"); + if (ast->declarationList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "declaration-list"); + for (auto it = ast->declarationList; it; it = it->next) { + accept(it->value); + } + --indent_; + } + accept(ast->privateModuleFragment, "private-module-fragment"); +} + void ASTPrinter::visit(LabeledStatementAST* ast) { fmt::print(out_, "{}\n", "labeled-statement"); accept(ast->identifier, "identifier"); diff --git a/src/frontend/cxx/ast_printer.h b/src/frontend/cxx/ast_printer.h index 8acef3f8..31eaa9db 100644 --- a/src/frontend/cxx/ast_printer.h +++ b/src/frontend/cxx/ast_printer.h @@ -71,43 +71,9 @@ class ASTPrinter : ASTVisitor { void visit(AttributeArgumentClauseAST* ast) override; void visit(AttributeAST* ast) override; void visit(AttributeUsingPrefixAST* ast) override; + void visit(DesignatorAST* ast) override; - void visit(SimpleRequirementAST* ast) override; - void visit(CompoundRequirementAST* ast) override; - void visit(TypeRequirementAST* ast) override; - void visit(NestedRequirementAST* ast) override; - - void visit(TypeTemplateArgumentAST* ast) override; - void visit(ExpressionTemplateArgumentAST* ast) override; - - void visit(ParenMemInitializerAST* ast) override; - void visit(BracedMemInitializerAST* ast) override; - - void visit(ThisLambdaCaptureAST* ast) override; - void visit(DerefThisLambdaCaptureAST* ast) override; - void visit(SimpleLambdaCaptureAST* ast) override; - void visit(RefLambdaCaptureAST* ast) override; - void visit(RefInitLambdaCaptureAST* ast) override; - void visit(InitLambdaCaptureAST* ast) override; - - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - - void visit(NewParenInitializerAST* ast) override; - void visit(NewBracedInitializerAST* ast) override; - - void visit(EllipsisExceptionDeclarationAST* ast) override; - void visit(TypeExceptionDeclarationAST* ast) override; - - void visit(DefaultFunctionBodyAST* ast) override; - void visit(CompoundStatementFunctionBodyAST* ast) override; - void visit(TryStatementFunctionBodyAST* ast) override; - void visit(DeleteFunctionBodyAST* ast) override; - - void visit(TranslationUnitAST* ast) override; - void visit(ModuleUnitAST* ast) override; - + void visit(DesignatedInitializerClauseAST* ast) override; void visit(ThisExpressionAST* ast) override; void visit(CharLiteralExpressionAST* ast) override; void visit(BoolLiteralExpressionAST* ast) override; @@ -148,6 +114,42 @@ class ASTPrinter : ASTVisitor { void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(SimpleRequirementAST* ast) override; + void visit(CompoundRequirementAST* ast) override; + void visit(TypeRequirementAST* ast) override; + void visit(NestedRequirementAST* ast) override; + + void visit(TypeTemplateArgumentAST* ast) override; + void visit(ExpressionTemplateArgumentAST* ast) override; + + void visit(ParenMemInitializerAST* ast) override; + void visit(BracedMemInitializerAST* ast) override; + + void visit(ThisLambdaCaptureAST* ast) override; + void visit(DerefThisLambdaCaptureAST* ast) override; + void visit(SimpleLambdaCaptureAST* ast) override; + void visit(RefLambdaCaptureAST* ast) override; + void visit(RefInitLambdaCaptureAST* ast) override; + void visit(InitLambdaCaptureAST* ast) override; + + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; + + void visit(NewParenInitializerAST* ast) override; + void visit(NewBracedInitializerAST* ast) override; + + void visit(EllipsisExceptionDeclarationAST* ast) override; + void visit(TypeExceptionDeclarationAST* ast) override; + + void visit(DefaultFunctionBodyAST* ast) override; + void visit(CompoundStatementFunctionBodyAST* ast) override; + void visit(TryStatementFunctionBodyAST* ast) override; + void visit(DeleteFunctionBodyAST* ast) override; + + void visit(TranslationUnitAST* ast) override; + void visit(ModuleUnitAST* ast) override; + void visit(LabeledStatementAST* ast) override; void visit(CaseStatementAST* ast) override; void visit(DefaultStatementAST* ast) override; diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index 4d1cb9eb..d9f08e4b 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -436,6 +436,30 @@ auto AttributeUsingPrefixAST::lastSourceLocation() -> SourceLocation { return {}; } +auto DesignatorAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(dotLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; + return {}; +} + +auto DesignatorAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(dotLoc)) return loc; + return {}; +} + +auto DesignatedInitializerClauseAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(designator)) return loc; + if (auto loc = cxx::firstSourceLocation(initializer)) return loc; + return {}; +} + +auto DesignatedInitializerClauseAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(initializer)) return loc; + if (auto loc = cxx::lastSourceLocation(designator)) return loc; + return {}; +} + auto SimpleRequirementAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(expression)) return loc; if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index feff8d0b..a7bcf52c 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -60,6 +60,7 @@ union AST { AttributeArgumentClause, Attribute, AttributeUsingPrefix, + Designator, } union AttributeSpecifier { @@ -121,6 +122,7 @@ union ExceptionDeclaration { } union Expression { + DesignatedInitializerClause, ThisExpression, CharLiteralExpression, BoolLiteralExpression, @@ -460,6 +462,12 @@ table AttributeUsingPrefix /* AST */ { colon_loc: SourceLocation; } +table Designator /* AST */ { + identifier: string; + dot_loc: SourceLocation; + identifier_loc: SourceLocation; +} + table CxxAttribute /* AttributeSpecifierAST */ { attribute_using_prefix: AttributeUsingPrefix; attribute_list: [Attribute]; @@ -755,6 +763,11 @@ table TypeExceptionDeclaration /* ExceptionDeclarationAST */ { declarator: Declarator; } +table DesignatedInitializerClause /* ExpressionAST */ { + designator: Designator; + initializer: Initializer; +} + table ThisExpression /* ExpressionAST */ { this_loc: SourceLocation; } diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index 930102ab..482d8ceb 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -608,12 +608,13 @@ class AttributeUsingPrefixAST final : public AST { auto lastSourceLocation() -> SourceLocation override; }; -class SimpleRequirementAST final : public RequirementAST { +class DesignatorAST final : public AST { public: - SimpleRequirementAST() : RequirementAST(ASTKind::SimpleRequirement) {} + DesignatorAST() : AST(ASTKind::Designator) {} - ExpressionAST* expression = nullptr; - SourceLocation semicolonLoc; + SourceLocation dotLoc; + SourceLocation identifierLoc; + const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -621,17 +622,13 @@ class SimpleRequirementAST final : public RequirementAST { auto lastSourceLocation() -> SourceLocation override; }; -class CompoundRequirementAST final : public RequirementAST { +class DesignatedInitializerClauseAST final : public ExpressionAST { public: - CompoundRequirementAST() : RequirementAST(ASTKind::CompoundRequirement) {} + DesignatedInitializerClauseAST() + : ExpressionAST(ASTKind::DesignatedInitializerClause) {} - SourceLocation lbraceLoc; - ExpressionAST* expression = nullptr; - SourceLocation rbraceLoc; - SourceLocation noexceptLoc; - SourceLocation minusGreaterLoc; - TypeConstraintAST* typeConstraint = nullptr; - SourceLocation semicolonLoc; + DesignatorAST* designator = nullptr; + InitializerAST* initializer = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -639,14 +636,11 @@ class CompoundRequirementAST final : public RequirementAST { auto lastSourceLocation() -> SourceLocation override; }; -class TypeRequirementAST final : public RequirementAST { +class ThisExpressionAST final : public ExpressionAST { public: - TypeRequirementAST() : RequirementAST(ASTKind::TypeRequirement) {} + ThisExpressionAST() : ExpressionAST(ASTKind::ThisExpression) {} - SourceLocation typenameLoc; - NestedNameSpecifierAST* nestedNameSpecifier = nullptr; - NameAST* name = nullptr; - SourceLocation semicolonLoc; + SourceLocation thisLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -654,13 +648,12 @@ class TypeRequirementAST final : public RequirementAST { auto lastSourceLocation() -> SourceLocation override; }; -class NestedRequirementAST final : public RequirementAST { +class CharLiteralExpressionAST final : public ExpressionAST { public: - NestedRequirementAST() : RequirementAST(ASTKind::NestedRequirement) {} + CharLiteralExpressionAST() : ExpressionAST(ASTKind::CharLiteralExpression) {} - SourceLocation requiresLoc; - ExpressionAST* expression = nullptr; - SourceLocation semicolonLoc; + SourceLocation literalLoc; + const CharLiteral* literal = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -668,12 +661,12 @@ class NestedRequirementAST final : public RequirementAST { auto lastSourceLocation() -> SourceLocation override; }; -class TypeTemplateArgumentAST final : public TemplateArgumentAST { +class BoolLiteralExpressionAST final : public ExpressionAST { public: - TypeTemplateArgumentAST() - : TemplateArgumentAST(ASTKind::TypeTemplateArgument) {} + BoolLiteralExpressionAST() : ExpressionAST(ASTKind::BoolLiteralExpression) {} - TypeIdAST* typeId = nullptr; + SourceLocation literalLoc; + bool value = false; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -681,12 +674,12 @@ class TypeTemplateArgumentAST final : public TemplateArgumentAST { auto lastSourceLocation() -> SourceLocation override; }; -class ExpressionTemplateArgumentAST final : public TemplateArgumentAST { +class IntLiteralExpressionAST final : public ExpressionAST { public: - ExpressionTemplateArgumentAST() - : TemplateArgumentAST(ASTKind::ExpressionTemplateArgument) {} + IntLiteralExpressionAST() : ExpressionAST(ASTKind::IntLiteralExpression) {} - ExpressionAST* expression = nullptr; + SourceLocation literalLoc; + const IntegerLiteral* literal = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -694,15 +687,13 @@ class ExpressionTemplateArgumentAST final : public TemplateArgumentAST { auto lastSourceLocation() -> SourceLocation override; }; -class ParenMemInitializerAST final : public MemInitializerAST { +class FloatLiteralExpressionAST final : public ExpressionAST { public: - ParenMemInitializerAST() : MemInitializerAST(ASTKind::ParenMemInitializer) {} + FloatLiteralExpressionAST() + : ExpressionAST(ASTKind::FloatLiteralExpression) {} - NameAST* name = nullptr; - SourceLocation lparenLoc; - List* expressionList = nullptr; - SourceLocation rparenLoc; - SourceLocation ellipsisLoc; + SourceLocation literalLoc; + const FloatLiteral* literal = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -710,14 +701,13 @@ class ParenMemInitializerAST final : public MemInitializerAST { auto lastSourceLocation() -> SourceLocation override; }; -class BracedMemInitializerAST final : public MemInitializerAST { +class NullptrLiteralExpressionAST final : public ExpressionAST { public: - BracedMemInitializerAST() - : MemInitializerAST(ASTKind::BracedMemInitializer) {} + NullptrLiteralExpressionAST() + : ExpressionAST(ASTKind::NullptrLiteralExpression) {} - NameAST* name = nullptr; - BracedInitListAST* bracedInitList = nullptr; - SourceLocation ellipsisLoc; + SourceLocation literalLoc; + TokenKind literal = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -725,11 +715,13 @@ class BracedMemInitializerAST final : public MemInitializerAST { auto lastSourceLocation() -> SourceLocation override; }; -class ThisLambdaCaptureAST final : public LambdaCaptureAST { +class StringLiteralExpressionAST final : public ExpressionAST { public: - ThisLambdaCaptureAST() : LambdaCaptureAST(ASTKind::ThisLambdaCapture) {} + StringLiteralExpressionAST() + : ExpressionAST(ASTKind::StringLiteralExpression) {} - SourceLocation thisLoc; + SourceLocation literalLoc; + const Literal* literal = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -737,13 +729,13 @@ class ThisLambdaCaptureAST final : public LambdaCaptureAST { auto lastSourceLocation() -> SourceLocation override; }; -class DerefThisLambdaCaptureAST final : public LambdaCaptureAST { +class UserDefinedStringLiteralExpressionAST final : public ExpressionAST { public: - DerefThisLambdaCaptureAST() - : LambdaCaptureAST(ASTKind::DerefThisLambdaCapture) {} + UserDefinedStringLiteralExpressionAST() + : ExpressionAST(ASTKind::UserDefinedStringLiteralExpression) {} - SourceLocation starLoc; - SourceLocation thisLoc; + SourceLocation literalLoc; + const StringLiteral* literal = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -751,13 +743,11 @@ class DerefThisLambdaCaptureAST final : public LambdaCaptureAST { auto lastSourceLocation() -> SourceLocation override; }; -class SimpleLambdaCaptureAST final : public LambdaCaptureAST { +class IdExpressionAST final : public ExpressionAST { public: - SimpleLambdaCaptureAST() : LambdaCaptureAST(ASTKind::SimpleLambdaCapture) {} + IdExpressionAST() : ExpressionAST(ASTKind::IdExpression) {} - SourceLocation identifierLoc; - SourceLocation ellipsisLoc; - const Identifier* identifier = nullptr; + NameAST* name = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -765,14 +755,15 @@ class SimpleLambdaCaptureAST final : public LambdaCaptureAST { auto lastSourceLocation() -> SourceLocation override; }; -class RefLambdaCaptureAST final : public LambdaCaptureAST { +class RequiresExpressionAST final : public ExpressionAST { public: - RefLambdaCaptureAST() : LambdaCaptureAST(ASTKind::RefLambdaCapture) {} + RequiresExpressionAST() : ExpressionAST(ASTKind::RequiresExpression) {} - SourceLocation ampLoc; - SourceLocation identifierLoc; - SourceLocation ellipsisLoc; - const Identifier* identifier = nullptr; + SourceLocation requiresLoc; + SourceLocation lparenLoc; + ParameterDeclarationClauseAST* parameterDeclarationClause = nullptr; + SourceLocation rparenLoc; + RequirementBodyAST* requirementBody = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -780,15 +771,13 @@ class RefLambdaCaptureAST final : public LambdaCaptureAST { auto lastSourceLocation() -> SourceLocation override; }; -class RefInitLambdaCaptureAST final : public LambdaCaptureAST { +class NestedExpressionAST final : public ExpressionAST { public: - RefInitLambdaCaptureAST() : LambdaCaptureAST(ASTKind::RefInitLambdaCapture) {} + NestedExpressionAST() : ExpressionAST(ASTKind::NestedExpression) {} - SourceLocation ampLoc; - SourceLocation ellipsisLoc; - SourceLocation identifierLoc; - InitializerAST* initializer = nullptr; - const Identifier* identifier = nullptr; + SourceLocation lparenLoc; + ExpressionAST* expression = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -796,14 +785,16 @@ class RefInitLambdaCaptureAST final : public LambdaCaptureAST { auto lastSourceLocation() -> SourceLocation override; }; -class InitLambdaCaptureAST final : public LambdaCaptureAST { +class RightFoldExpressionAST final : public ExpressionAST { public: - InitLambdaCaptureAST() : LambdaCaptureAST(ASTKind::InitLambdaCapture) {} + RightFoldExpressionAST() : ExpressionAST(ASTKind::RightFoldExpression) {} + SourceLocation lparenLoc; + ExpressionAST* expression = nullptr; + SourceLocation opLoc; SourceLocation ellipsisLoc; - SourceLocation identifierLoc; - InitializerAST* initializer = nullptr; - const Identifier* identifier = nullptr; + SourceLocation rparenLoc; + TokenKind op = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -811,12 +802,16 @@ class InitLambdaCaptureAST final : public LambdaCaptureAST { auto lastSourceLocation() -> SourceLocation override; }; -class EqualInitializerAST final : public InitializerAST { +class LeftFoldExpressionAST final : public ExpressionAST { public: - EqualInitializerAST() : InitializerAST(ASTKind::EqualInitializer) {} + LeftFoldExpressionAST() : ExpressionAST(ASTKind::LeftFoldExpression) {} - SourceLocation equalLoc; + SourceLocation lparenLoc; + SourceLocation ellipsisLoc; + SourceLocation opLoc; ExpressionAST* expression = nullptr; + SourceLocation rparenLoc; + TokenKind op = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -824,14 +819,19 @@ class EqualInitializerAST final : public InitializerAST { auto lastSourceLocation() -> SourceLocation override; }; -class BracedInitListAST final : public InitializerAST { +class FoldExpressionAST final : public ExpressionAST { public: - BracedInitListAST() : InitializerAST(ASTKind::BracedInitList) {} + FoldExpressionAST() : ExpressionAST(ASTKind::FoldExpression) {} - SourceLocation lbraceLoc; - List* expressionList = nullptr; - SourceLocation commaLoc; - SourceLocation rbraceLoc; + SourceLocation lparenLoc; + ExpressionAST* leftExpression = nullptr; + SourceLocation opLoc; + SourceLocation ellipsisLoc; + SourceLocation foldOpLoc; + ExpressionAST* rightExpression = nullptr; + SourceLocation rparenLoc; + TokenKind op = TokenKind::T_EOF_SYMBOL; + TokenKind foldOp = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -839,13 +839,17 @@ class BracedInitListAST final : public InitializerAST { auto lastSourceLocation() -> SourceLocation override; }; -class ParenInitializerAST final : public InitializerAST { +class LambdaExpressionAST final : public ExpressionAST { public: - ParenInitializerAST() : InitializerAST(ASTKind::ParenInitializer) {} + LambdaExpressionAST() : ExpressionAST(ASTKind::LambdaExpression) {} - SourceLocation lparenLoc; - List* expressionList = nullptr; - SourceLocation rparenLoc; + LambdaIntroducerAST* lambdaIntroducer = nullptr; + SourceLocation lessLoc; + List* templateParameterList = nullptr; + SourceLocation greaterLoc; + RequiresClauseAST* requiresClause = nullptr; + LambdaDeclaratorAST* lambdaDeclarator = nullptr; + CompoundStatementAST* statement = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -853,13 +857,12 @@ class ParenInitializerAST final : public InitializerAST { auto lastSourceLocation() -> SourceLocation override; }; -class NewParenInitializerAST final : public NewInitializerAST { +class SizeofExpressionAST final : public ExpressionAST { public: - NewParenInitializerAST() : NewInitializerAST(ASTKind::NewParenInitializer) {} + SizeofExpressionAST() : ExpressionAST(ASTKind::SizeofExpression) {} - SourceLocation lparenLoc; - List* expressionList = nullptr; - SourceLocation rparenLoc; + SourceLocation sizeofLoc; + ExpressionAST* expression = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -867,12 +870,14 @@ class NewParenInitializerAST final : public NewInitializerAST { auto lastSourceLocation() -> SourceLocation override; }; -class NewBracedInitializerAST final : public NewInitializerAST { +class SizeofTypeExpressionAST final : public ExpressionAST { public: - NewBracedInitializerAST() - : NewInitializerAST(ASTKind::NewBracedInitializer) {} + SizeofTypeExpressionAST() : ExpressionAST(ASTKind::SizeofTypeExpression) {} - BracedInitListAST* bracedInit = nullptr; + SourceLocation sizeofLoc; + SourceLocation lparenLoc; + TypeIdAST* typeId = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -880,12 +885,16 @@ class NewBracedInitializerAST final : public NewInitializerAST { auto lastSourceLocation() -> SourceLocation override; }; -class EllipsisExceptionDeclarationAST final : public ExceptionDeclarationAST { +class SizeofPackExpressionAST final : public ExpressionAST { public: - EllipsisExceptionDeclarationAST() - : ExceptionDeclarationAST(ASTKind::EllipsisExceptionDeclaration) {} + SizeofPackExpressionAST() : ExpressionAST(ASTKind::SizeofPackExpression) {} + SourceLocation sizeofLoc; SourceLocation ellipsisLoc; + SourceLocation lparenLoc; + SourceLocation identifierLoc; + SourceLocation rparenLoc; + const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -893,14 +902,14 @@ class EllipsisExceptionDeclarationAST final : public ExceptionDeclarationAST { auto lastSourceLocation() -> SourceLocation override; }; -class TypeExceptionDeclarationAST final : public ExceptionDeclarationAST { +class TypeidExpressionAST final : public ExpressionAST { public: - TypeExceptionDeclarationAST() - : ExceptionDeclarationAST(ASTKind::TypeExceptionDeclaration) {} + TypeidExpressionAST() : ExpressionAST(ASTKind::TypeidExpression) {} - List* attributeList = nullptr; - List* typeSpecifierList = nullptr; - DeclaratorAST* declarator = nullptr; + SourceLocation typeidLoc; + SourceLocation lparenLoc; + ExpressionAST* expression = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -908,13 +917,15 @@ class TypeExceptionDeclarationAST final : public ExceptionDeclarationAST { auto lastSourceLocation() -> SourceLocation override; }; -class DefaultFunctionBodyAST final : public FunctionBodyAST { +class TypeidOfTypeExpressionAST final : public ExpressionAST { public: - DefaultFunctionBodyAST() : FunctionBodyAST(ASTKind::DefaultFunctionBody) {} + TypeidOfTypeExpressionAST() + : ExpressionAST(ASTKind::TypeidOfTypeExpression) {} - SourceLocation equalLoc; - SourceLocation defaultLoc; - SourceLocation semicolonLoc; + SourceLocation typeidLoc; + SourceLocation lparenLoc; + TypeIdAST* typeId = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -922,13 +933,14 @@ class DefaultFunctionBodyAST final : public FunctionBodyAST { auto lastSourceLocation() -> SourceLocation override; }; -class CompoundStatementFunctionBodyAST final : public FunctionBodyAST { +class AlignofExpressionAST final : public ExpressionAST { public: - CompoundStatementFunctionBodyAST() - : FunctionBodyAST(ASTKind::CompoundStatementFunctionBody) {} + AlignofExpressionAST() : ExpressionAST(ASTKind::AlignofExpression) {} - CtorInitializerAST* ctorInitializer = nullptr; - CompoundStatementAST* statement = nullptr; + SourceLocation alignofLoc; + SourceLocation lparenLoc; + TypeIdAST* typeId = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -936,15 +948,15 @@ class CompoundStatementFunctionBodyAST final : public FunctionBodyAST { auto lastSourceLocation() -> SourceLocation override; }; -class TryStatementFunctionBodyAST final : public FunctionBodyAST { +class TypeTraitsExpressionAST final : public ExpressionAST { public: - TryStatementFunctionBodyAST() - : FunctionBodyAST(ASTKind::TryStatementFunctionBody) {} + TypeTraitsExpressionAST() : ExpressionAST(ASTKind::TypeTraitsExpression) {} - SourceLocation tryLoc; - CtorInitializerAST* ctorInitializer = nullptr; - CompoundStatementAST* statement = nullptr; - List* handlerList = nullptr; + SourceLocation typeTraitsLoc; + SourceLocation lparenLoc; + List* typeIdList = nullptr; + SourceLocation rparenLoc; + TokenKind typeTraits = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -952,13 +964,13 @@ class TryStatementFunctionBodyAST final : public FunctionBodyAST { auto lastSourceLocation() -> SourceLocation override; }; -class DeleteFunctionBodyAST final : public FunctionBodyAST { +class UnaryExpressionAST final : public ExpressionAST { public: - DeleteFunctionBodyAST() : FunctionBodyAST(ASTKind::DeleteFunctionBody) {} + UnaryExpressionAST() : ExpressionAST(ASTKind::UnaryExpression) {} - SourceLocation equalLoc; - SourceLocation deleteLoc; - SourceLocation semicolonLoc; + SourceLocation opLoc; + ExpressionAST* expression = nullptr; + TokenKind op = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -966,11 +978,14 @@ class DeleteFunctionBodyAST final : public FunctionBodyAST { auto lastSourceLocation() -> SourceLocation override; }; -class TranslationUnitAST final : public UnitAST { +class BinaryExpressionAST final : public ExpressionAST { public: - TranslationUnitAST() : UnitAST(ASTKind::TranslationUnit) {} + BinaryExpressionAST() : ExpressionAST(ASTKind::BinaryExpression) {} - List* declarationList = nullptr; + ExpressionAST* leftExpression = nullptr; + SourceLocation opLoc; + ExpressionAST* rightExpression = nullptr; + TokenKind op = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -978,14 +993,14 @@ class TranslationUnitAST final : public UnitAST { auto lastSourceLocation() -> SourceLocation override; }; -class ModuleUnitAST final : public UnitAST { +class AssignmentExpressionAST final : public ExpressionAST { public: - ModuleUnitAST() : UnitAST(ASTKind::ModuleUnit) {} + AssignmentExpressionAST() : ExpressionAST(ASTKind::AssignmentExpression) {} - GlobalModuleFragmentAST* globalModuleFragment = nullptr; - ModuleDeclarationAST* moduleDeclaration = nullptr; - List* declarationList = nullptr; - PrivateModuleFragmentAST* privateModuleFragment = nullptr; + ExpressionAST* leftExpression = nullptr; + SourceLocation opLoc; + ExpressionAST* rightExpression = nullptr; + TokenKind op = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -993,11 +1008,13 @@ class ModuleUnitAST final : public UnitAST { auto lastSourceLocation() -> SourceLocation override; }; -class ThisExpressionAST final : public ExpressionAST { +class BracedTypeConstructionAST final : public ExpressionAST { public: - ThisExpressionAST() : ExpressionAST(ASTKind::ThisExpression) {} + BracedTypeConstructionAST() + : ExpressionAST(ASTKind::BracedTypeConstruction) {} - SourceLocation thisLoc; + SpecifierAST* typeSpecifier = nullptr; + BracedInitListAST* bracedInitList = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1005,12 +1022,14 @@ class ThisExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class CharLiteralExpressionAST final : public ExpressionAST { +class TypeConstructionAST final : public ExpressionAST { public: - CharLiteralExpressionAST() : ExpressionAST(ASTKind::CharLiteralExpression) {} + TypeConstructionAST() : ExpressionAST(ASTKind::TypeConstruction) {} - SourceLocation literalLoc; - const CharLiteral* literal = nullptr; + SpecifierAST* typeSpecifier = nullptr; + SourceLocation lparenLoc; + List* expressionList = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1018,12 +1037,14 @@ class CharLiteralExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class BoolLiteralExpressionAST final : public ExpressionAST { +class CallExpressionAST final : public ExpressionAST { public: - BoolLiteralExpressionAST() : ExpressionAST(ASTKind::BoolLiteralExpression) {} + CallExpressionAST() : ExpressionAST(ASTKind::CallExpression) {} - SourceLocation literalLoc; - bool value = false; + ExpressionAST* baseExpression = nullptr; + SourceLocation lparenLoc; + List* expressionList = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1031,12 +1052,14 @@ class BoolLiteralExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class IntLiteralExpressionAST final : public ExpressionAST { +class SubscriptExpressionAST final : public ExpressionAST { public: - IntLiteralExpressionAST() : ExpressionAST(ASTKind::IntLiteralExpression) {} + SubscriptExpressionAST() : ExpressionAST(ASTKind::SubscriptExpression) {} - SourceLocation literalLoc; - const IntegerLiteral* literal = nullptr; + ExpressionAST* baseExpression = nullptr; + SourceLocation lbracketLoc; + ExpressionAST* indexExpression = nullptr; + SourceLocation rbracketLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1044,13 +1067,15 @@ class IntLiteralExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class FloatLiteralExpressionAST final : public ExpressionAST { +class MemberExpressionAST final : public ExpressionAST { public: - FloatLiteralExpressionAST() - : ExpressionAST(ASTKind::FloatLiteralExpression) {} + MemberExpressionAST() : ExpressionAST(ASTKind::MemberExpression) {} - SourceLocation literalLoc; - const FloatLiteral* literal = nullptr; + ExpressionAST* baseExpression = nullptr; + SourceLocation accessLoc; + SourceLocation templateLoc; + NameAST* name = nullptr; + TokenKind accessOp = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1058,13 +1083,13 @@ class FloatLiteralExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class NullptrLiteralExpressionAST final : public ExpressionAST { +class PostIncrExpressionAST final : public ExpressionAST { public: - NullptrLiteralExpressionAST() - : ExpressionAST(ASTKind::NullptrLiteralExpression) {} + PostIncrExpressionAST() : ExpressionAST(ASTKind::PostIncrExpression) {} - SourceLocation literalLoc; - TokenKind literal = TokenKind::T_EOF_SYMBOL; + ExpressionAST* baseExpression = nullptr; + SourceLocation opLoc; + TokenKind op = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1072,13 +1097,15 @@ class NullptrLiteralExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class StringLiteralExpressionAST final : public ExpressionAST { +class ConditionalExpressionAST final : public ExpressionAST { public: - StringLiteralExpressionAST() - : ExpressionAST(ASTKind::StringLiteralExpression) {} + ConditionalExpressionAST() : ExpressionAST(ASTKind::ConditionalExpression) {} - SourceLocation literalLoc; - const Literal* literal = nullptr; + ExpressionAST* condition = nullptr; + SourceLocation questionLoc; + ExpressionAST* iftrueExpression = nullptr; + SourceLocation colonLoc; + ExpressionAST* iffalseExpression = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1086,13 +1113,13 @@ class StringLiteralExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class UserDefinedStringLiteralExpressionAST final : public ExpressionAST { +class ImplicitCastExpressionAST final : public ExpressionAST { public: - UserDefinedStringLiteralExpressionAST() - : ExpressionAST(ASTKind::UserDefinedStringLiteralExpression) {} + ImplicitCastExpressionAST() + : ExpressionAST(ASTKind::ImplicitCastExpression) {} - SourceLocation literalLoc; - const StringLiteral* literal = nullptr; + ExpressionAST* expression = nullptr; + ImplicitCastKind castKind = ImplicitCastKind::kIdentity; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1100,11 +1127,14 @@ class UserDefinedStringLiteralExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class IdExpressionAST final : public ExpressionAST { +class CastExpressionAST final : public ExpressionAST { public: - IdExpressionAST() : ExpressionAST(ASTKind::IdExpression) {} + CastExpressionAST() : ExpressionAST(ASTKind::CastExpression) {} - NameAST* name = nullptr; + SourceLocation lparenLoc; + TypeIdAST* typeId = nullptr; + SourceLocation rparenLoc; + ExpressionAST* expression = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1112,15 +1142,17 @@ class IdExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class RequiresExpressionAST final : public ExpressionAST { +class CppCastExpressionAST final : public ExpressionAST { public: - RequiresExpressionAST() : ExpressionAST(ASTKind::RequiresExpression) {} + CppCastExpressionAST() : ExpressionAST(ASTKind::CppCastExpression) {} - SourceLocation requiresLoc; + SourceLocation castLoc; + SourceLocation lessLoc; + TypeIdAST* typeId = nullptr; + SourceLocation greaterLoc; SourceLocation lparenLoc; - ParameterDeclarationClauseAST* parameterDeclarationClause = nullptr; + ExpressionAST* expression = nullptr; SourceLocation rparenLoc; - RequirementBodyAST* requirementBody = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1128,13 +1160,30 @@ class RequiresExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class NestedExpressionAST final : public ExpressionAST { +class NewExpressionAST final : public ExpressionAST { public: - NestedExpressionAST() : ExpressionAST(ASTKind::NestedExpression) {} + NewExpressionAST() : ExpressionAST(ASTKind::NewExpression) {} - SourceLocation lparenLoc; + SourceLocation scopeLoc; + SourceLocation newLoc; + NewTypeIdAST* typeId = nullptr; + NewInitializerAST* newInitalizer = nullptr; + + void accept(ASTVisitor* visitor) override { visitor->visit(this); } + + auto firstSourceLocation() -> SourceLocation override; + auto lastSourceLocation() -> SourceLocation override; +}; + +class DeleteExpressionAST final : public ExpressionAST { + public: + DeleteExpressionAST() : ExpressionAST(ASTKind::DeleteExpression) {} + + SourceLocation scopeLoc; + SourceLocation deleteLoc; + SourceLocation lbracketLoc; + SourceLocation rbracketLoc; ExpressionAST* expression = nullptr; - SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1142,16 +1191,12 @@ class NestedExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class RightFoldExpressionAST final : public ExpressionAST { +class ThrowExpressionAST final : public ExpressionAST { public: - RightFoldExpressionAST() : ExpressionAST(ASTKind::RightFoldExpression) {} + ThrowExpressionAST() : ExpressionAST(ASTKind::ThrowExpression) {} - SourceLocation lparenLoc; + SourceLocation throwLoc; ExpressionAST* expression = nullptr; - SourceLocation opLoc; - SourceLocation ellipsisLoc; - SourceLocation rparenLoc; - TokenKind op = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1159,16 +1204,14 @@ class RightFoldExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class LeftFoldExpressionAST final : public ExpressionAST { +class NoexceptExpressionAST final : public ExpressionAST { public: - LeftFoldExpressionAST() : ExpressionAST(ASTKind::LeftFoldExpression) {} + NoexceptExpressionAST() : ExpressionAST(ASTKind::NoexceptExpression) {} + SourceLocation noexceptLoc; SourceLocation lparenLoc; - SourceLocation ellipsisLoc; - SourceLocation opLoc; ExpressionAST* expression = nullptr; SourceLocation rparenLoc; - TokenKind op = TokenKind::T_EOF_SYMBOL; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1176,19 +1219,12 @@ class LeftFoldExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class FoldExpressionAST final : public ExpressionAST { +class SimpleRequirementAST final : public RequirementAST { public: - FoldExpressionAST() : ExpressionAST(ASTKind::FoldExpression) {} + SimpleRequirementAST() : RequirementAST(ASTKind::SimpleRequirement) {} - SourceLocation lparenLoc; - ExpressionAST* leftExpression = nullptr; - SourceLocation opLoc; - SourceLocation ellipsisLoc; - SourceLocation foldOpLoc; - ExpressionAST* rightExpression = nullptr; - SourceLocation rparenLoc; - TokenKind op = TokenKind::T_EOF_SYMBOL; - TokenKind foldOp = TokenKind::T_EOF_SYMBOL; + ExpressionAST* expression = nullptr; + SourceLocation semicolonLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1196,17 +1232,17 @@ class FoldExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class LambdaExpressionAST final : public ExpressionAST { +class CompoundRequirementAST final : public RequirementAST { public: - LambdaExpressionAST() : ExpressionAST(ASTKind::LambdaExpression) {} + CompoundRequirementAST() : RequirementAST(ASTKind::CompoundRequirement) {} - LambdaIntroducerAST* lambdaIntroducer = nullptr; - SourceLocation lessLoc; - List* templateParameterList = nullptr; - SourceLocation greaterLoc; - RequiresClauseAST* requiresClause = nullptr; - LambdaDeclaratorAST* lambdaDeclarator = nullptr; - CompoundStatementAST* statement = nullptr; + SourceLocation lbraceLoc; + ExpressionAST* expression = nullptr; + SourceLocation rbraceLoc; + SourceLocation noexceptLoc; + SourceLocation minusGreaterLoc; + TypeConstraintAST* typeConstraint = nullptr; + SourceLocation semicolonLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1214,12 +1250,28 @@ class LambdaExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class SizeofExpressionAST final : public ExpressionAST { +class TypeRequirementAST final : public RequirementAST { public: - SizeofExpressionAST() : ExpressionAST(ASTKind::SizeofExpression) {} + TypeRequirementAST() : RequirementAST(ASTKind::TypeRequirement) {} - SourceLocation sizeofLoc; + SourceLocation typenameLoc; + NestedNameSpecifierAST* nestedNameSpecifier = nullptr; + NameAST* name = nullptr; + SourceLocation semicolonLoc; + + void accept(ASTVisitor* visitor) override { visitor->visit(this); } + + auto firstSourceLocation() -> SourceLocation override; + auto lastSourceLocation() -> SourceLocation override; +}; + +class NestedRequirementAST final : public RequirementAST { + public: + NestedRequirementAST() : RequirementAST(ASTKind::NestedRequirement) {} + + SourceLocation requiresLoc; ExpressionAST* expression = nullptr; + SourceLocation semicolonLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1227,14 +1279,12 @@ class SizeofExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class SizeofTypeExpressionAST final : public ExpressionAST { +class TypeTemplateArgumentAST final : public TemplateArgumentAST { public: - SizeofTypeExpressionAST() : ExpressionAST(ASTKind::SizeofTypeExpression) {} + TypeTemplateArgumentAST() + : TemplateArgumentAST(ASTKind::TypeTemplateArgument) {} - SourceLocation sizeofLoc; - SourceLocation lparenLoc; TypeIdAST* typeId = nullptr; - SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1242,16 +1292,12 @@ class SizeofTypeExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class SizeofPackExpressionAST final : public ExpressionAST { +class ExpressionTemplateArgumentAST final : public TemplateArgumentAST { public: - SizeofPackExpressionAST() : ExpressionAST(ASTKind::SizeofPackExpression) {} + ExpressionTemplateArgumentAST() + : TemplateArgumentAST(ASTKind::ExpressionTemplateArgument) {} - SourceLocation sizeofLoc; - SourceLocation ellipsisLoc; - SourceLocation lparenLoc; - SourceLocation identifierLoc; - SourceLocation rparenLoc; - const Identifier* identifier = nullptr; + ExpressionAST* expression = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1259,14 +1305,15 @@ class SizeofPackExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class TypeidExpressionAST final : public ExpressionAST { +class ParenMemInitializerAST final : public MemInitializerAST { public: - TypeidExpressionAST() : ExpressionAST(ASTKind::TypeidExpression) {} + ParenMemInitializerAST() : MemInitializerAST(ASTKind::ParenMemInitializer) {} - SourceLocation typeidLoc; + NameAST* name = nullptr; SourceLocation lparenLoc; - ExpressionAST* expression = nullptr; + List* expressionList = nullptr; SourceLocation rparenLoc; + SourceLocation ellipsisLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1274,15 +1321,14 @@ class TypeidExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class TypeidOfTypeExpressionAST final : public ExpressionAST { +class BracedMemInitializerAST final : public MemInitializerAST { public: - TypeidOfTypeExpressionAST() - : ExpressionAST(ASTKind::TypeidOfTypeExpression) {} + BracedMemInitializerAST() + : MemInitializerAST(ASTKind::BracedMemInitializer) {} - SourceLocation typeidLoc; - SourceLocation lparenLoc; - TypeIdAST* typeId = nullptr; - SourceLocation rparenLoc; + NameAST* name = nullptr; + BracedInitListAST* bracedInitList = nullptr; + SourceLocation ellipsisLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1290,14 +1336,11 @@ class TypeidOfTypeExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class AlignofExpressionAST final : public ExpressionAST { +class ThisLambdaCaptureAST final : public LambdaCaptureAST { public: - AlignofExpressionAST() : ExpressionAST(ASTKind::AlignofExpression) {} + ThisLambdaCaptureAST() : LambdaCaptureAST(ASTKind::ThisLambdaCapture) {} - SourceLocation alignofLoc; - SourceLocation lparenLoc; - TypeIdAST* typeId = nullptr; - SourceLocation rparenLoc; + SourceLocation thisLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1305,15 +1348,13 @@ class AlignofExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class TypeTraitsExpressionAST final : public ExpressionAST { +class DerefThisLambdaCaptureAST final : public LambdaCaptureAST { public: - TypeTraitsExpressionAST() : ExpressionAST(ASTKind::TypeTraitsExpression) {} + DerefThisLambdaCaptureAST() + : LambdaCaptureAST(ASTKind::DerefThisLambdaCapture) {} - SourceLocation typeTraitsLoc; - SourceLocation lparenLoc; - List* typeIdList = nullptr; - SourceLocation rparenLoc; - TokenKind typeTraits = TokenKind::T_EOF_SYMBOL; + SourceLocation starLoc; + SourceLocation thisLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1321,13 +1362,13 @@ class TypeTraitsExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class UnaryExpressionAST final : public ExpressionAST { +class SimpleLambdaCaptureAST final : public LambdaCaptureAST { public: - UnaryExpressionAST() : ExpressionAST(ASTKind::UnaryExpression) {} + SimpleLambdaCaptureAST() : LambdaCaptureAST(ASTKind::SimpleLambdaCapture) {} - SourceLocation opLoc; - ExpressionAST* expression = nullptr; - TokenKind op = TokenKind::T_EOF_SYMBOL; + SourceLocation identifierLoc; + SourceLocation ellipsisLoc; + const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1335,14 +1376,14 @@ class UnaryExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class BinaryExpressionAST final : public ExpressionAST { +class RefLambdaCaptureAST final : public LambdaCaptureAST { public: - BinaryExpressionAST() : ExpressionAST(ASTKind::BinaryExpression) {} + RefLambdaCaptureAST() : LambdaCaptureAST(ASTKind::RefLambdaCapture) {} - ExpressionAST* leftExpression = nullptr; - SourceLocation opLoc; - ExpressionAST* rightExpression = nullptr; - TokenKind op = TokenKind::T_EOF_SYMBOL; + SourceLocation ampLoc; + SourceLocation identifierLoc; + SourceLocation ellipsisLoc; + const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1350,14 +1391,15 @@ class BinaryExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class AssignmentExpressionAST final : public ExpressionAST { +class RefInitLambdaCaptureAST final : public LambdaCaptureAST { public: - AssignmentExpressionAST() : ExpressionAST(ASTKind::AssignmentExpression) {} + RefInitLambdaCaptureAST() : LambdaCaptureAST(ASTKind::RefInitLambdaCapture) {} - ExpressionAST* leftExpression = nullptr; - SourceLocation opLoc; - ExpressionAST* rightExpression = nullptr; - TokenKind op = TokenKind::T_EOF_SYMBOL; + SourceLocation ampLoc; + SourceLocation ellipsisLoc; + SourceLocation identifierLoc; + InitializerAST* initializer = nullptr; + const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1365,13 +1407,14 @@ class AssignmentExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class BracedTypeConstructionAST final : public ExpressionAST { +class InitLambdaCaptureAST final : public LambdaCaptureAST { public: - BracedTypeConstructionAST() - : ExpressionAST(ASTKind::BracedTypeConstruction) {} + InitLambdaCaptureAST() : LambdaCaptureAST(ASTKind::InitLambdaCapture) {} - SpecifierAST* typeSpecifier = nullptr; - BracedInitListAST* bracedInitList = nullptr; + SourceLocation ellipsisLoc; + SourceLocation identifierLoc; + InitializerAST* initializer = nullptr; + const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1379,14 +1422,12 @@ class BracedTypeConstructionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class TypeConstructionAST final : public ExpressionAST { +class EqualInitializerAST final : public InitializerAST { public: - TypeConstructionAST() : ExpressionAST(ASTKind::TypeConstruction) {} + EqualInitializerAST() : InitializerAST(ASTKind::EqualInitializer) {} - SpecifierAST* typeSpecifier = nullptr; - SourceLocation lparenLoc; - List* expressionList = nullptr; - SourceLocation rparenLoc; + SourceLocation equalLoc; + ExpressionAST* expression = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1394,14 +1435,14 @@ class TypeConstructionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class CallExpressionAST final : public ExpressionAST { +class BracedInitListAST final : public InitializerAST { public: - CallExpressionAST() : ExpressionAST(ASTKind::CallExpression) {} + BracedInitListAST() : InitializerAST(ASTKind::BracedInitList) {} - ExpressionAST* baseExpression = nullptr; - SourceLocation lparenLoc; + SourceLocation lbraceLoc; List* expressionList = nullptr; - SourceLocation rparenLoc; + SourceLocation commaLoc; + SourceLocation rbraceLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1409,14 +1450,13 @@ class CallExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class SubscriptExpressionAST final : public ExpressionAST { +class ParenInitializerAST final : public InitializerAST { public: - SubscriptExpressionAST() : ExpressionAST(ASTKind::SubscriptExpression) {} + ParenInitializerAST() : InitializerAST(ASTKind::ParenInitializer) {} - ExpressionAST* baseExpression = nullptr; - SourceLocation lbracketLoc; - ExpressionAST* indexExpression = nullptr; - SourceLocation rbracketLoc; + SourceLocation lparenLoc; + List* expressionList = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1424,15 +1464,13 @@ class SubscriptExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class MemberExpressionAST final : public ExpressionAST { +class NewParenInitializerAST final : public NewInitializerAST { public: - MemberExpressionAST() : ExpressionAST(ASTKind::MemberExpression) {} + NewParenInitializerAST() : NewInitializerAST(ASTKind::NewParenInitializer) {} - ExpressionAST* baseExpression = nullptr; - SourceLocation accessLoc; - SourceLocation templateLoc; - NameAST* name = nullptr; - TokenKind accessOp = TokenKind::T_EOF_SYMBOL; + SourceLocation lparenLoc; + List* expressionList = nullptr; + SourceLocation rparenLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1440,13 +1478,12 @@ class MemberExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class PostIncrExpressionAST final : public ExpressionAST { +class NewBracedInitializerAST final : public NewInitializerAST { public: - PostIncrExpressionAST() : ExpressionAST(ASTKind::PostIncrExpression) {} + NewBracedInitializerAST() + : NewInitializerAST(ASTKind::NewBracedInitializer) {} - ExpressionAST* baseExpression = nullptr; - SourceLocation opLoc; - TokenKind op = TokenKind::T_EOF_SYMBOL; + BracedInitListAST* bracedInit = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1454,15 +1491,12 @@ class PostIncrExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class ConditionalExpressionAST final : public ExpressionAST { +class EllipsisExceptionDeclarationAST final : public ExceptionDeclarationAST { public: - ConditionalExpressionAST() : ExpressionAST(ASTKind::ConditionalExpression) {} + EllipsisExceptionDeclarationAST() + : ExceptionDeclarationAST(ASTKind::EllipsisExceptionDeclaration) {} - ExpressionAST* condition = nullptr; - SourceLocation questionLoc; - ExpressionAST* iftrueExpression = nullptr; - SourceLocation colonLoc; - ExpressionAST* iffalseExpression = nullptr; + SourceLocation ellipsisLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1470,13 +1504,14 @@ class ConditionalExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class ImplicitCastExpressionAST final : public ExpressionAST { +class TypeExceptionDeclarationAST final : public ExceptionDeclarationAST { public: - ImplicitCastExpressionAST() - : ExpressionAST(ASTKind::ImplicitCastExpression) {} + TypeExceptionDeclarationAST() + : ExceptionDeclarationAST(ASTKind::TypeExceptionDeclaration) {} - ExpressionAST* expression = nullptr; - ImplicitCastKind castKind = ImplicitCastKind::kIdentity; + List* attributeList = nullptr; + List* typeSpecifierList = nullptr; + DeclaratorAST* declarator = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1484,14 +1519,13 @@ class ImplicitCastExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class CastExpressionAST final : public ExpressionAST { +class DefaultFunctionBodyAST final : public FunctionBodyAST { public: - CastExpressionAST() : ExpressionAST(ASTKind::CastExpression) {} + DefaultFunctionBodyAST() : FunctionBodyAST(ASTKind::DefaultFunctionBody) {} - SourceLocation lparenLoc; - TypeIdAST* typeId = nullptr; - SourceLocation rparenLoc; - ExpressionAST* expression = nullptr; + SourceLocation equalLoc; + SourceLocation defaultLoc; + SourceLocation semicolonLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1499,17 +1533,13 @@ class CastExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class CppCastExpressionAST final : public ExpressionAST { +class CompoundStatementFunctionBodyAST final : public FunctionBodyAST { public: - CppCastExpressionAST() : ExpressionAST(ASTKind::CppCastExpression) {} + CompoundStatementFunctionBodyAST() + : FunctionBodyAST(ASTKind::CompoundStatementFunctionBody) {} - SourceLocation castLoc; - SourceLocation lessLoc; - TypeIdAST* typeId = nullptr; - SourceLocation greaterLoc; - SourceLocation lparenLoc; - ExpressionAST* expression = nullptr; - SourceLocation rparenLoc; + CtorInitializerAST* ctorInitializer = nullptr; + CompoundStatementAST* statement = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1517,14 +1547,15 @@ class CppCastExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class NewExpressionAST final : public ExpressionAST { +class TryStatementFunctionBodyAST final : public FunctionBodyAST { public: - NewExpressionAST() : ExpressionAST(ASTKind::NewExpression) {} + TryStatementFunctionBodyAST() + : FunctionBodyAST(ASTKind::TryStatementFunctionBody) {} - SourceLocation scopeLoc; - SourceLocation newLoc; - NewTypeIdAST* typeId = nullptr; - NewInitializerAST* newInitalizer = nullptr; + SourceLocation tryLoc; + CtorInitializerAST* ctorInitializer = nullptr; + CompoundStatementAST* statement = nullptr; + List* handlerList = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1532,15 +1563,13 @@ class NewExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class DeleteExpressionAST final : public ExpressionAST { +class DeleteFunctionBodyAST final : public FunctionBodyAST { public: - DeleteExpressionAST() : ExpressionAST(ASTKind::DeleteExpression) {} + DeleteFunctionBodyAST() : FunctionBodyAST(ASTKind::DeleteFunctionBody) {} - SourceLocation scopeLoc; + SourceLocation equalLoc; SourceLocation deleteLoc; - SourceLocation lbracketLoc; - SourceLocation rbracketLoc; - ExpressionAST* expression = nullptr; + SourceLocation semicolonLoc; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1548,12 +1577,11 @@ class DeleteExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class ThrowExpressionAST final : public ExpressionAST { +class TranslationUnitAST final : public UnitAST { public: - ThrowExpressionAST() : ExpressionAST(ASTKind::ThrowExpression) {} + TranslationUnitAST() : UnitAST(ASTKind::TranslationUnit) {} - SourceLocation throwLoc; - ExpressionAST* expression = nullptr; + List* declarationList = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1561,14 +1589,14 @@ class ThrowExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; -class NoexceptExpressionAST final : public ExpressionAST { +class ModuleUnitAST final : public UnitAST { public: - NoexceptExpressionAST() : ExpressionAST(ASTKind::NoexceptExpression) {} + ModuleUnitAST() : UnitAST(ASTKind::ModuleUnit) {} - SourceLocation noexceptLoc; - SourceLocation lparenLoc; - ExpressionAST* expression = nullptr; - SourceLocation rparenLoc; + GlobalModuleFragmentAST* globalModuleFragment = nullptr; + ModuleDeclarationAST* moduleDeclaration = nullptr; + List* declarationList = nullptr; + PrivateModuleFragmentAST* privateModuleFragment = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 41869c26..f9021ab0 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -562,418 +562,346 @@ void ASTCloner::visit(AttributeUsingPrefixAST* ast) { copy->colonLoc = ast->colonLoc; } -void ASTCloner::visit(SimpleRequirementAST* ast) { - auto copy = new (arena_) SimpleRequirementAST(); +void ASTCloner::visit(DesignatorAST* ast) { + auto copy = new (arena_) DesignatorAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->expression = accept(ast->expression); + copy->dotLoc = ast->dotLoc; - copy->semicolonLoc = ast->semicolonLoc; + copy->identifierLoc = ast->identifierLoc; + + copy->identifier = ast->identifier; } -void ASTCloner::visit(CompoundRequirementAST* ast) { - auto copy = new (arena_) CompoundRequirementAST(); +void ASTCloner::visit(DesignatedInitializerClauseAST* ast) { + auto copy = new (arena_) DesignatedInitializerClauseAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->lbraceLoc = ast->lbraceLoc; - - copy->expression = accept(ast->expression); - - copy->rbraceLoc = ast->rbraceLoc; - - copy->noexceptLoc = ast->noexceptLoc; + copy->valueCategory = ast->valueCategory; - copy->minusGreaterLoc = ast->minusGreaterLoc; + copy->constValue = ast->constValue; - copy->typeConstraint = accept(ast->typeConstraint); + copy->designator = accept(ast->designator); - copy->semicolonLoc = ast->semicolonLoc; + copy->initializer = accept(ast->initializer); } -void ASTCloner::visit(TypeRequirementAST* ast) { - auto copy = new (arena_) TypeRequirementAST(); +void ASTCloner::visit(ThisExpressionAST* ast) { + auto copy = new (arena_) ThisExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->typenameLoc = ast->typenameLoc; - - copy->nestedNameSpecifier = accept(ast->nestedNameSpecifier); + copy->valueCategory = ast->valueCategory; - copy->name = accept(ast->name); + copy->constValue = ast->constValue; - copy->semicolonLoc = ast->semicolonLoc; + copy->thisLoc = ast->thisLoc; } -void ASTCloner::visit(NestedRequirementAST* ast) { - auto copy = new (arena_) NestedRequirementAST(); +void ASTCloner::visit(CharLiteralExpressionAST* ast) { + auto copy = new (arena_) CharLiteralExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->requiresLoc = ast->requiresLoc; + copy->valueCategory = ast->valueCategory; - copy->expression = accept(ast->expression); + copy->constValue = ast->constValue; - copy->semicolonLoc = ast->semicolonLoc; + copy->literalLoc = ast->literalLoc; + + copy->literal = ast->literal; } -void ASTCloner::visit(TypeTemplateArgumentAST* ast) { - auto copy = new (arena_) TypeTemplateArgumentAST(); +void ASTCloner::visit(BoolLiteralExpressionAST* ast) { + auto copy = new (arena_) BoolLiteralExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->typeId = accept(ast->typeId); -} + copy->valueCategory = ast->valueCategory; -void ASTCloner::visit(ExpressionTemplateArgumentAST* ast) { - auto copy = new (arena_) ExpressionTemplateArgumentAST(); - copy_ = copy; + copy->constValue = ast->constValue; - copy->setChecked(ast->checked()); + copy->literalLoc = ast->literalLoc; - copy->expression = accept(ast->expression); + copy->value = ast->value; } -void ASTCloner::visit(ParenMemInitializerAST* ast) { - auto copy = new (arena_) ParenMemInitializerAST(); +void ASTCloner::visit(IntLiteralExpressionAST* ast) { + auto copy = new (arena_) IntLiteralExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->name = accept(ast->name); - - copy->lparenLoc = ast->lparenLoc; - - if (auto it = ast->expressionList) { - auto out = ©->expressionList; + copy->valueCategory = ast->valueCategory; - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->constValue = ast->constValue; - copy->rparenLoc = ast->rparenLoc; + copy->literalLoc = ast->literalLoc; - copy->ellipsisLoc = ast->ellipsisLoc; + copy->literal = ast->literal; } -void ASTCloner::visit(BracedMemInitializerAST* ast) { - auto copy = new (arena_) BracedMemInitializerAST(); +void ASTCloner::visit(FloatLiteralExpressionAST* ast) { + auto copy = new (arena_) FloatLiteralExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->name = accept(ast->name); + copy->valueCategory = ast->valueCategory; - copy->bracedInitList = accept(ast->bracedInitList); + copy->constValue = ast->constValue; - copy->ellipsisLoc = ast->ellipsisLoc; + copy->literalLoc = ast->literalLoc; + + copy->literal = ast->literal; } -void ASTCloner::visit(ThisLambdaCaptureAST* ast) { - auto copy = new (arena_) ThisLambdaCaptureAST(); +void ASTCloner::visit(NullptrLiteralExpressionAST* ast) { + auto copy = new (arena_) NullptrLiteralExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->thisLoc = ast->thisLoc; -} - -void ASTCloner::visit(DerefThisLambdaCaptureAST* ast) { - auto copy = new (arena_) DerefThisLambdaCaptureAST(); - copy_ = copy; + copy->valueCategory = ast->valueCategory; - copy->setChecked(ast->checked()); + copy->constValue = ast->constValue; - copy->starLoc = ast->starLoc; + copy->literalLoc = ast->literalLoc; - copy->thisLoc = ast->thisLoc; + copy->literal = ast->literal; } -void ASTCloner::visit(SimpleLambdaCaptureAST* ast) { - auto copy = new (arena_) SimpleLambdaCaptureAST(); +void ASTCloner::visit(StringLiteralExpressionAST* ast) { + auto copy = new (arena_) StringLiteralExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->identifierLoc = ast->identifierLoc; + copy->valueCategory = ast->valueCategory; - copy->ellipsisLoc = ast->ellipsisLoc; + copy->constValue = ast->constValue; - copy->identifier = ast->identifier; + copy->literalLoc = ast->literalLoc; + + copy->literal = ast->literal; } -void ASTCloner::visit(RefLambdaCaptureAST* ast) { - auto copy = new (arena_) RefLambdaCaptureAST(); +void ASTCloner::visit(UserDefinedStringLiteralExpressionAST* ast) { + auto copy = new (arena_) UserDefinedStringLiteralExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->ampLoc = ast->ampLoc; + copy->valueCategory = ast->valueCategory; - copy->identifierLoc = ast->identifierLoc; + copy->constValue = ast->constValue; - copy->ellipsisLoc = ast->ellipsisLoc; + copy->literalLoc = ast->literalLoc; - copy->identifier = ast->identifier; + copy->literal = ast->literal; } -void ASTCloner::visit(RefInitLambdaCaptureAST* ast) { - auto copy = new (arena_) RefInitLambdaCaptureAST(); +void ASTCloner::visit(IdExpressionAST* ast) { + auto copy = new (arena_) IdExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->ampLoc = ast->ampLoc; - - copy->ellipsisLoc = ast->ellipsisLoc; - - copy->identifierLoc = ast->identifierLoc; + copy->valueCategory = ast->valueCategory; - copy->initializer = accept(ast->initializer); + copy->constValue = ast->constValue; - copy->identifier = ast->identifier; + copy->name = accept(ast->name); } -void ASTCloner::visit(InitLambdaCaptureAST* ast) { - auto copy = new (arena_) InitLambdaCaptureAST(); +void ASTCloner::visit(RequiresExpressionAST* ast) { + auto copy = new (arena_) RequiresExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->ellipsisLoc = ast->ellipsisLoc; - - copy->identifierLoc = ast->identifierLoc; + copy->valueCategory = ast->valueCategory; - copy->initializer = accept(ast->initializer); + copy->constValue = ast->constValue; - copy->identifier = ast->identifier; -} + copy->requiresLoc = ast->requiresLoc; -void ASTCloner::visit(EqualInitializerAST* ast) { - auto copy = new (arena_) EqualInitializerAST(); - copy_ = copy; + copy->lparenLoc = ast->lparenLoc; - copy->setChecked(ast->checked()); + copy->parameterDeclarationClause = accept(ast->parameterDeclarationClause); - copy->equalLoc = ast->equalLoc; + copy->rparenLoc = ast->rparenLoc; - copy->expression = accept(ast->expression); + copy->requirementBody = accept(ast->requirementBody); } -void ASTCloner::visit(BracedInitListAST* ast) { - auto copy = new (arena_) BracedInitListAST(); +void ASTCloner::visit(NestedExpressionAST* ast) { + auto copy = new (arena_) NestedExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->lbraceLoc = ast->lbraceLoc; + copy->valueCategory = ast->valueCategory; - if (auto it = ast->expressionList) { - auto out = ©->expressionList; + copy->constValue = ast->constValue; - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->lparenLoc = ast->lparenLoc; - copy->commaLoc = ast->commaLoc; + copy->expression = accept(ast->expression); - copy->rbraceLoc = ast->rbraceLoc; + copy->rparenLoc = ast->rparenLoc; } -void ASTCloner::visit(ParenInitializerAST* ast) { - auto copy = new (arena_) ParenInitializerAST(); +void ASTCloner::visit(RightFoldExpressionAST* ast) { + auto copy = new (arena_) RightFoldExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); + copy->valueCategory = ast->valueCategory; + + copy->constValue = ast->constValue; + copy->lparenLoc = ast->lparenLoc; - if (auto it = ast->expressionList) { - auto out = ©->expressionList; + copy->expression = accept(ast->expression); - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->opLoc = ast->opLoc; + + copy->ellipsisLoc = ast->ellipsisLoc; copy->rparenLoc = ast->rparenLoc; + + copy->op = ast->op; } -void ASTCloner::visit(NewParenInitializerAST* ast) { - auto copy = new (arena_) NewParenInitializerAST(); +void ASTCloner::visit(LeftFoldExpressionAST* ast) { + auto copy = new (arena_) LeftFoldExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); + copy->valueCategory = ast->valueCategory; + + copy->constValue = ast->constValue; + copy->lparenLoc = ast->lparenLoc; - if (auto it = ast->expressionList) { - auto out = ©->expressionList; + copy->ellipsisLoc = ast->ellipsisLoc; - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->opLoc = ast->opLoc; + + copy->expression = accept(ast->expression); copy->rparenLoc = ast->rparenLoc; + + copy->op = ast->op; } -void ASTCloner::visit(NewBracedInitializerAST* ast) { - auto copy = new (arena_) NewBracedInitializerAST(); +void ASTCloner::visit(FoldExpressionAST* ast) { + auto copy = new (arena_) FoldExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->bracedInit = accept(ast->bracedInit); -} + copy->valueCategory = ast->valueCategory; -void ASTCloner::visit(EllipsisExceptionDeclarationAST* ast) { - auto copy = new (arena_) EllipsisExceptionDeclarationAST(); - copy_ = copy; + copy->constValue = ast->constValue; - copy->setChecked(ast->checked()); + copy->lparenLoc = ast->lparenLoc; - copy->ellipsisLoc = ast->ellipsisLoc; -} + copy->leftExpression = accept(ast->leftExpression); -void ASTCloner::visit(TypeExceptionDeclarationAST* ast) { - auto copy = new (arena_) TypeExceptionDeclarationAST(); - copy_ = copy; + copy->opLoc = ast->opLoc; - copy->setChecked(ast->checked()); + copy->ellipsisLoc = ast->ellipsisLoc; - if (auto it = ast->attributeList) { - auto out = ©->attributeList; - - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } - - if (auto it = ast->typeSpecifierList) { - auto out = ©->typeSpecifierList; - - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } - - copy->declarator = accept(ast->declarator); -} - -void ASTCloner::visit(DefaultFunctionBodyAST* ast) { - auto copy = new (arena_) DefaultFunctionBodyAST(); - copy_ = copy; + copy->foldOpLoc = ast->foldOpLoc; - copy->setChecked(ast->checked()); + copy->rightExpression = accept(ast->rightExpression); - copy->equalLoc = ast->equalLoc; + copy->rparenLoc = ast->rparenLoc; - copy->defaultLoc = ast->defaultLoc; + copy->op = ast->op; - copy->semicolonLoc = ast->semicolonLoc; + copy->foldOp = ast->foldOp; } -void ASTCloner::visit(CompoundStatementFunctionBodyAST* ast) { - auto copy = new (arena_) CompoundStatementFunctionBodyAST(); +void ASTCloner::visit(LambdaExpressionAST* ast) { + auto copy = new (arena_) LambdaExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->ctorInitializer = accept(ast->ctorInitializer); - - copy->statement = accept(ast->statement); -} - -void ASTCloner::visit(TryStatementFunctionBodyAST* ast) { - auto copy = new (arena_) TryStatementFunctionBodyAST(); - copy_ = copy; - - copy->setChecked(ast->checked()); + copy->valueCategory = ast->valueCategory; - copy->tryLoc = ast->tryLoc; + copy->constValue = ast->constValue; - copy->ctorInitializer = accept(ast->ctorInitializer); + copy->lambdaIntroducer = accept(ast->lambdaIntroducer); - copy->statement = accept(ast->statement); + copy->lessLoc = ast->lessLoc; - if (auto it = ast->handlerList) { - auto out = ©->handlerList; + if (auto it = ast->templateParameterList) { + auto out = ©->templateParameterList; for (; it; it = it->next) { *out = new (arena_) List(accept(it->value)); out = &(*out)->next; } } -} - -void ASTCloner::visit(DeleteFunctionBodyAST* ast) { - auto copy = new (arena_) DeleteFunctionBodyAST(); - copy_ = copy; - copy->setChecked(ast->checked()); + copy->greaterLoc = ast->greaterLoc; - copy->equalLoc = ast->equalLoc; + copy->requiresClause = accept(ast->requiresClause); - copy->deleteLoc = ast->deleteLoc; + copy->lambdaDeclarator = accept(ast->lambdaDeclarator); - copy->semicolonLoc = ast->semicolonLoc; + copy->statement = accept(ast->statement); } -void ASTCloner::visit(TranslationUnitAST* ast) { - auto copy = new (arena_) TranslationUnitAST(); +void ASTCloner::visit(SizeofExpressionAST* ast) { + auto copy = new (arena_) SizeofExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - if (auto it = ast->declarationList) { - auto out = ©->declarationList; + copy->valueCategory = ast->valueCategory; - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->constValue = ast->constValue; + + copy->sizeofLoc = ast->sizeofLoc; + + copy->expression = accept(ast->expression); } -void ASTCloner::visit(ModuleUnitAST* ast) { - auto copy = new (arena_) ModuleUnitAST(); +void ASTCloner::visit(SizeofTypeExpressionAST* ast) { + auto copy = new (arena_) SizeofTypeExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->globalModuleFragment = accept(ast->globalModuleFragment); + copy->valueCategory = ast->valueCategory; - copy->moduleDeclaration = accept(ast->moduleDeclaration); + copy->constValue = ast->constValue; - if (auto it = ast->declarationList) { - auto out = ©->declarationList; + copy->sizeofLoc = ast->sizeofLoc; - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->lparenLoc = ast->lparenLoc; - copy->privateModuleFragment = accept(ast->privateModuleFragment); + copy->typeId = accept(ast->typeId); + + copy->rparenLoc = ast->rparenLoc; } -void ASTCloner::visit(ThisExpressionAST* ast) { - auto copy = new (arena_) ThisExpressionAST(); +void ASTCloner::visit(SizeofPackExpressionAST* ast) { + auto copy = new (arena_) SizeofPackExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -982,26 +910,21 @@ void ASTCloner::visit(ThisExpressionAST* ast) { copy->constValue = ast->constValue; - copy->thisLoc = ast->thisLoc; -} - -void ASTCloner::visit(CharLiteralExpressionAST* ast) { - auto copy = new (arena_) CharLiteralExpressionAST(); - copy_ = copy; + copy->sizeofLoc = ast->sizeofLoc; - copy->setChecked(ast->checked()); + copy->ellipsisLoc = ast->ellipsisLoc; - copy->valueCategory = ast->valueCategory; + copy->lparenLoc = ast->lparenLoc; - copy->constValue = ast->constValue; + copy->identifierLoc = ast->identifierLoc; - copy->literalLoc = ast->literalLoc; + copy->rparenLoc = ast->rparenLoc; - copy->literal = ast->literal; + copy->identifier = ast->identifier; } -void ASTCloner::visit(BoolLiteralExpressionAST* ast) { - auto copy = new (arena_) BoolLiteralExpressionAST(); +void ASTCloner::visit(TypeidExpressionAST* ast) { + auto copy = new (arena_) TypeidExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1010,13 +933,17 @@ void ASTCloner::visit(BoolLiteralExpressionAST* ast) { copy->constValue = ast->constValue; - copy->literalLoc = ast->literalLoc; + copy->typeidLoc = ast->typeidLoc; - copy->value = ast->value; + copy->lparenLoc = ast->lparenLoc; + + copy->expression = accept(ast->expression); + + copy->rparenLoc = ast->rparenLoc; } -void ASTCloner::visit(IntLiteralExpressionAST* ast) { - auto copy = new (arena_) IntLiteralExpressionAST(); +void ASTCloner::visit(TypeidOfTypeExpressionAST* ast) { + auto copy = new (arena_) TypeidOfTypeExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1025,13 +952,17 @@ void ASTCloner::visit(IntLiteralExpressionAST* ast) { copy->constValue = ast->constValue; - copy->literalLoc = ast->literalLoc; + copy->typeidLoc = ast->typeidLoc; - copy->literal = ast->literal; + copy->lparenLoc = ast->lparenLoc; + + copy->typeId = accept(ast->typeId); + + copy->rparenLoc = ast->rparenLoc; } -void ASTCloner::visit(FloatLiteralExpressionAST* ast) { - auto copy = new (arena_) FloatLiteralExpressionAST(); +void ASTCloner::visit(AlignofExpressionAST* ast) { + auto copy = new (arena_) AlignofExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1040,13 +971,17 @@ void ASTCloner::visit(FloatLiteralExpressionAST* ast) { copy->constValue = ast->constValue; - copy->literalLoc = ast->literalLoc; + copy->alignofLoc = ast->alignofLoc; - copy->literal = ast->literal; + copy->lparenLoc = ast->lparenLoc; + + copy->typeId = accept(ast->typeId); + + copy->rparenLoc = ast->rparenLoc; } -void ASTCloner::visit(NullptrLiteralExpressionAST* ast) { - auto copy = new (arena_) NullptrLiteralExpressionAST(); +void ASTCloner::visit(TypeTraitsExpressionAST* ast) { + auto copy = new (arena_) TypeTraitsExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1055,13 +990,26 @@ void ASTCloner::visit(NullptrLiteralExpressionAST* ast) { copy->constValue = ast->constValue; - copy->literalLoc = ast->literalLoc; + copy->typeTraitsLoc = ast->typeTraitsLoc; - copy->literal = ast->literal; + copy->lparenLoc = ast->lparenLoc; + + if (auto it = ast->typeIdList) { + auto out = ©->typeIdList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } + + copy->rparenLoc = ast->rparenLoc; + + copy->typeTraits = ast->typeTraits; } -void ASTCloner::visit(StringLiteralExpressionAST* ast) { - auto copy = new (arena_) StringLiteralExpressionAST(); +void ASTCloner::visit(UnaryExpressionAST* ast) { + auto copy = new (arena_) UnaryExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1070,13 +1018,15 @@ void ASTCloner::visit(StringLiteralExpressionAST* ast) { copy->constValue = ast->constValue; - copy->literalLoc = ast->literalLoc; + copy->opLoc = ast->opLoc; - copy->literal = ast->literal; + copy->expression = accept(ast->expression); + + copy->op = ast->op; } -void ASTCloner::visit(UserDefinedStringLiteralExpressionAST* ast) { - auto copy = new (arena_) UserDefinedStringLiteralExpressionAST(); +void ASTCloner::visit(BinaryExpressionAST* ast) { + auto copy = new (arena_) BinaryExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1085,13 +1035,17 @@ void ASTCloner::visit(UserDefinedStringLiteralExpressionAST* ast) { copy->constValue = ast->constValue; - copy->literalLoc = ast->literalLoc; + copy->leftExpression = accept(ast->leftExpression); - copy->literal = ast->literal; + copy->opLoc = ast->opLoc; + + copy->rightExpression = accept(ast->rightExpression); + + copy->op = ast->op; } -void ASTCloner::visit(IdExpressionAST* ast) { - auto copy = new (arena_) IdExpressionAST(); +void ASTCloner::visit(AssignmentExpressionAST* ast) { + auto copy = new (arena_) AssignmentExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1100,11 +1054,17 @@ void ASTCloner::visit(IdExpressionAST* ast) { copy->constValue = ast->constValue; - copy->name = accept(ast->name); + copy->leftExpression = accept(ast->leftExpression); + + copy->opLoc = ast->opLoc; + + copy->rightExpression = accept(ast->rightExpression); + + copy->op = ast->op; } -void ASTCloner::visit(RequiresExpressionAST* ast) { - auto copy = new (arena_) RequiresExpressionAST(); +void ASTCloner::visit(BracedTypeConstructionAST* ast) { + auto copy = new (arena_) BracedTypeConstructionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1113,19 +1073,13 @@ void ASTCloner::visit(RequiresExpressionAST* ast) { copy->constValue = ast->constValue; - copy->requiresLoc = ast->requiresLoc; - - copy->lparenLoc = ast->lparenLoc; - - copy->parameterDeclarationClause = accept(ast->parameterDeclarationClause); - - copy->rparenLoc = ast->rparenLoc; + copy->typeSpecifier = accept(ast->typeSpecifier); - copy->requirementBody = accept(ast->requirementBody); + copy->bracedInitList = accept(ast->bracedInitList); } -void ASTCloner::visit(NestedExpressionAST* ast) { - auto copy = new (arena_) NestedExpressionAST(); +void ASTCloner::visit(TypeConstructionAST* ast) { + auto copy = new (arena_) TypeConstructionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1134,15 +1088,24 @@ void ASTCloner::visit(NestedExpressionAST* ast) { copy->constValue = ast->constValue; + copy->typeSpecifier = accept(ast->typeSpecifier); + copy->lparenLoc = ast->lparenLoc; - copy->expression = accept(ast->expression); + if (auto it = ast->expressionList) { + auto out = ©->expressionList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } copy->rparenLoc = ast->rparenLoc; } -void ASTCloner::visit(RightFoldExpressionAST* ast) { - auto copy = new (arena_) RightFoldExpressionAST(); +void ASTCloner::visit(CallExpressionAST* ast) { + auto copy = new (arena_) CallExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1151,21 +1114,24 @@ void ASTCloner::visit(RightFoldExpressionAST* ast) { copy->constValue = ast->constValue; + copy->baseExpression = accept(ast->baseExpression); + copy->lparenLoc = ast->lparenLoc; - copy->expression = accept(ast->expression); - - copy->opLoc = ast->opLoc; + if (auto it = ast->expressionList) { + auto out = ©->expressionList; - copy->ellipsisLoc = ast->ellipsisLoc; + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } copy->rparenLoc = ast->rparenLoc; - - copy->op = ast->op; } -void ASTCloner::visit(LeftFoldExpressionAST* ast) { - auto copy = new (arena_) LeftFoldExpressionAST(); +void ASTCloner::visit(SubscriptExpressionAST* ast) { + auto copy = new (arena_) SubscriptExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1174,21 +1140,17 @@ void ASTCloner::visit(LeftFoldExpressionAST* ast) { copy->constValue = ast->constValue; - copy->lparenLoc = ast->lparenLoc; - - copy->ellipsisLoc = ast->ellipsisLoc; - - copy->opLoc = ast->opLoc; + copy->baseExpression = accept(ast->baseExpression); - copy->expression = accept(ast->expression); + copy->lbracketLoc = ast->lbracketLoc; - copy->rparenLoc = ast->rparenLoc; + copy->indexExpression = accept(ast->indexExpression); - copy->op = ast->op; + copy->rbracketLoc = ast->rbracketLoc; } -void ASTCloner::visit(FoldExpressionAST* ast) { - auto copy = new (arena_) FoldExpressionAST(); +void ASTCloner::visit(MemberExpressionAST* ast) { + auto copy = new (arena_) MemberExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1197,27 +1159,36 @@ void ASTCloner::visit(FoldExpressionAST* ast) { copy->constValue = ast->constValue; - copy->lparenLoc = ast->lparenLoc; + copy->baseExpression = accept(ast->baseExpression); - copy->leftExpression = accept(ast->leftExpression); + copy->accessLoc = ast->accessLoc; - copy->opLoc = ast->opLoc; + copy->templateLoc = ast->templateLoc; - copy->ellipsisLoc = ast->ellipsisLoc; + copy->name = accept(ast->name); - copy->foldOpLoc = ast->foldOpLoc; + copy->accessOp = ast->accessOp; +} - copy->rightExpression = accept(ast->rightExpression); +void ASTCloner::visit(PostIncrExpressionAST* ast) { + auto copy = new (arena_) PostIncrExpressionAST(); + copy_ = copy; - copy->rparenLoc = ast->rparenLoc; + copy->setChecked(ast->checked()); - copy->op = ast->op; + copy->valueCategory = ast->valueCategory; - copy->foldOp = ast->foldOp; + copy->constValue = ast->constValue; + + copy->baseExpression = accept(ast->baseExpression); + + copy->opLoc = ast->opLoc; + + copy->op = ast->op; } -void ASTCloner::visit(LambdaExpressionAST* ast) { - auto copy = new (arena_) LambdaExpressionAST(); +void ASTCloner::visit(ConditionalExpressionAST* ast) { + auto copy = new (arena_) ConditionalExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1226,30 +1197,19 @@ void ASTCloner::visit(LambdaExpressionAST* ast) { copy->constValue = ast->constValue; - copy->lambdaIntroducer = accept(ast->lambdaIntroducer); - - copy->lessLoc = ast->lessLoc; - - if (auto it = ast->templateParameterList) { - auto out = ©->templateParameterList; - - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->condition = accept(ast->condition); - copy->greaterLoc = ast->greaterLoc; + copy->questionLoc = ast->questionLoc; - copy->requiresClause = accept(ast->requiresClause); + copy->iftrueExpression = accept(ast->iftrueExpression); - copy->lambdaDeclarator = accept(ast->lambdaDeclarator); + copy->colonLoc = ast->colonLoc; - copy->statement = accept(ast->statement); + copy->iffalseExpression = accept(ast->iffalseExpression); } -void ASTCloner::visit(SizeofExpressionAST* ast) { - auto copy = new (arena_) SizeofExpressionAST(); +void ASTCloner::visit(ImplicitCastExpressionAST* ast) { + auto copy = new (arena_) ImplicitCastExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1258,13 +1218,13 @@ void ASTCloner::visit(SizeofExpressionAST* ast) { copy->constValue = ast->constValue; - copy->sizeofLoc = ast->sizeofLoc; - copy->expression = accept(ast->expression); + + copy->castKind = ast->castKind; } -void ASTCloner::visit(SizeofTypeExpressionAST* ast) { - auto copy = new (arena_) SizeofTypeExpressionAST(); +void ASTCloner::visit(CastExpressionAST* ast) { + auto copy = new (arena_) CastExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1273,17 +1233,17 @@ void ASTCloner::visit(SizeofTypeExpressionAST* ast) { copy->constValue = ast->constValue; - copy->sizeofLoc = ast->sizeofLoc; - copy->lparenLoc = ast->lparenLoc; copy->typeId = accept(ast->typeId); copy->rparenLoc = ast->rparenLoc; + + copy->expression = accept(ast->expression); } -void ASTCloner::visit(SizeofPackExpressionAST* ast) { - auto copy = new (arena_) SizeofPackExpressionAST(); +void ASTCloner::visit(CppCastExpressionAST* ast) { + auto copy = new (arena_) CppCastExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1292,21 +1252,23 @@ void ASTCloner::visit(SizeofPackExpressionAST* ast) { copy->constValue = ast->constValue; - copy->sizeofLoc = ast->sizeofLoc; + copy->castLoc = ast->castLoc; - copy->ellipsisLoc = ast->ellipsisLoc; + copy->lessLoc = ast->lessLoc; + + copy->typeId = accept(ast->typeId); + + copy->greaterLoc = ast->greaterLoc; copy->lparenLoc = ast->lparenLoc; - copy->identifierLoc = ast->identifierLoc; + copy->expression = accept(ast->expression); copy->rparenLoc = ast->rparenLoc; - - copy->identifier = ast->identifier; } -void ASTCloner::visit(TypeidExpressionAST* ast) { - auto copy = new (arena_) TypeidExpressionAST(); +void ASTCloner::visit(NewExpressionAST* ast) { + auto copy = new (arena_) NewExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1315,17 +1277,17 @@ void ASTCloner::visit(TypeidExpressionAST* ast) { copy->constValue = ast->constValue; - copy->typeidLoc = ast->typeidLoc; + copy->scopeLoc = ast->scopeLoc; - copy->lparenLoc = ast->lparenLoc; + copy->newLoc = ast->newLoc; - copy->expression = accept(ast->expression); + copy->typeId = accept(ast->typeId); - copy->rparenLoc = ast->rparenLoc; + copy->newInitalizer = accept(ast->newInitalizer); } -void ASTCloner::visit(TypeidOfTypeExpressionAST* ast) { - auto copy = new (arena_) TypeidOfTypeExpressionAST(); +void ASTCloner::visit(DeleteExpressionAST* ast) { + auto copy = new (arena_) DeleteExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1334,17 +1296,19 @@ void ASTCloner::visit(TypeidOfTypeExpressionAST* ast) { copy->constValue = ast->constValue; - copy->typeidLoc = ast->typeidLoc; + copy->scopeLoc = ast->scopeLoc; - copy->lparenLoc = ast->lparenLoc; + copy->deleteLoc = ast->deleteLoc; - copy->typeId = accept(ast->typeId); + copy->lbracketLoc = ast->lbracketLoc; - copy->rparenLoc = ast->rparenLoc; + copy->rbracketLoc = ast->rbracketLoc; + + copy->expression = accept(ast->expression); } -void ASTCloner::visit(AlignofExpressionAST* ast) { - auto copy = new (arena_) AlignofExpressionAST(); +void ASTCloner::visit(ThrowExpressionAST* ast) { + auto copy = new (arena_) ThrowExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1353,17 +1317,13 @@ void ASTCloner::visit(AlignofExpressionAST* ast) { copy->constValue = ast->constValue; - copy->alignofLoc = ast->alignofLoc; - - copy->lparenLoc = ast->lparenLoc; - - copy->typeId = accept(ast->typeId); + copy->throwLoc = ast->throwLoc; - copy->rparenLoc = ast->rparenLoc; + copy->expression = accept(ast->expression); } -void ASTCloner::visit(TypeTraitsExpressionAST* ast) { - auto copy = new (arena_) TypeTraitsExpressionAST(); +void ASTCloner::visit(NoexceptExpressionAST* ast) { + auto copy = new (arena_) NoexceptExpressionAST(); copy_ = copy; copy->setChecked(ast->checked()); @@ -1372,105 +1332,100 @@ void ASTCloner::visit(TypeTraitsExpressionAST* ast) { copy->constValue = ast->constValue; - copy->typeTraitsLoc = ast->typeTraitsLoc; + copy->noexceptLoc = ast->noexceptLoc; copy->lparenLoc = ast->lparenLoc; - if (auto it = ast->typeIdList) { - auto out = ©->typeIdList; - - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->expression = accept(ast->expression); copy->rparenLoc = ast->rparenLoc; - - copy->typeTraits = ast->typeTraits; } -void ASTCloner::visit(UnaryExpressionAST* ast) { - auto copy = new (arena_) UnaryExpressionAST(); +void ASTCloner::visit(SimpleRequirementAST* ast) { + auto copy = new (arena_) SimpleRequirementAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; - - copy->constValue = ast->constValue; - - copy->opLoc = ast->opLoc; - copy->expression = accept(ast->expression); - copy->op = ast->op; + copy->semicolonLoc = ast->semicolonLoc; } -void ASTCloner::visit(BinaryExpressionAST* ast) { - auto copy = new (arena_) BinaryExpressionAST(); +void ASTCloner::visit(CompoundRequirementAST* ast) { + auto copy = new (arena_) CompoundRequirementAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->lbraceLoc = ast->lbraceLoc; - copy->constValue = ast->constValue; + copy->expression = accept(ast->expression); - copy->leftExpression = accept(ast->leftExpression); + copy->rbraceLoc = ast->rbraceLoc; - copy->opLoc = ast->opLoc; + copy->noexceptLoc = ast->noexceptLoc; - copy->rightExpression = accept(ast->rightExpression); + copy->minusGreaterLoc = ast->minusGreaterLoc; - copy->op = ast->op; + copy->typeConstraint = accept(ast->typeConstraint); + + copy->semicolonLoc = ast->semicolonLoc; } -void ASTCloner::visit(AssignmentExpressionAST* ast) { - auto copy = new (arena_) AssignmentExpressionAST(); +void ASTCloner::visit(TypeRequirementAST* ast) { + auto copy = new (arena_) TypeRequirementAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; - - copy->constValue = ast->constValue; - - copy->leftExpression = accept(ast->leftExpression); + copy->typenameLoc = ast->typenameLoc; - copy->opLoc = ast->opLoc; + copy->nestedNameSpecifier = accept(ast->nestedNameSpecifier); - copy->rightExpression = accept(ast->rightExpression); + copy->name = accept(ast->name); - copy->op = ast->op; + copy->semicolonLoc = ast->semicolonLoc; } -void ASTCloner::visit(BracedTypeConstructionAST* ast) { - auto copy = new (arena_) BracedTypeConstructionAST(); +void ASTCloner::visit(NestedRequirementAST* ast) { + auto copy = new (arena_) NestedRequirementAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->requiresLoc = ast->requiresLoc; - copy->constValue = ast->constValue; + copy->expression = accept(ast->expression); - copy->typeSpecifier = accept(ast->typeSpecifier); + copy->semicolonLoc = ast->semicolonLoc; +} - copy->bracedInitList = accept(ast->bracedInitList); +void ASTCloner::visit(TypeTemplateArgumentAST* ast) { + auto copy = new (arena_) TypeTemplateArgumentAST(); + copy_ = copy; + + copy->setChecked(ast->checked()); + + copy->typeId = accept(ast->typeId); } -void ASTCloner::visit(TypeConstructionAST* ast) { - auto copy = new (arena_) TypeConstructionAST(); +void ASTCloner::visit(ExpressionTemplateArgumentAST* ast) { + auto copy = new (arena_) ExpressionTemplateArgumentAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->expression = accept(ast->expression); +} - copy->constValue = ast->constValue; +void ASTCloner::visit(ParenMemInitializerAST* ast) { + auto copy = new (arena_) ParenMemInitializerAST(); + copy_ = copy; - copy->typeSpecifier = accept(ast->typeSpecifier); + copy->setChecked(ast->checked()); + + copy->name = accept(ast->name); copy->lparenLoc = ast->lparenLoc; @@ -1484,243 +1439,316 @@ void ASTCloner::visit(TypeConstructionAST* ast) { } copy->rparenLoc = ast->rparenLoc; + + copy->ellipsisLoc = ast->ellipsisLoc; } -void ASTCloner::visit(CallExpressionAST* ast) { - auto copy = new (arena_) CallExpressionAST(); - copy_ = copy; +void ASTCloner::visit(BracedMemInitializerAST* ast) { + auto copy = new (arena_) BracedMemInitializerAST(); + copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; - - copy->constValue = ast->constValue; + copy->name = accept(ast->name); - copy->baseExpression = accept(ast->baseExpression); + copy->bracedInitList = accept(ast->bracedInitList); - copy->lparenLoc = ast->lparenLoc; + copy->ellipsisLoc = ast->ellipsisLoc; +} - if (auto it = ast->expressionList) { - auto out = ©->expressionList; +void ASTCloner::visit(ThisLambdaCaptureAST* ast) { + auto copy = new (arena_) ThisLambdaCaptureAST(); + copy_ = copy; - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } + copy->setChecked(ast->checked()); - copy->rparenLoc = ast->rparenLoc; + copy->thisLoc = ast->thisLoc; } -void ASTCloner::visit(SubscriptExpressionAST* ast) { - auto copy = new (arena_) SubscriptExpressionAST(); +void ASTCloner::visit(DerefThisLambdaCaptureAST* ast) { + auto copy = new (arena_) DerefThisLambdaCaptureAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->starLoc = ast->starLoc; - copy->constValue = ast->constValue; + copy->thisLoc = ast->thisLoc; +} - copy->baseExpression = accept(ast->baseExpression); +void ASTCloner::visit(SimpleLambdaCaptureAST* ast) { + auto copy = new (arena_) SimpleLambdaCaptureAST(); + copy_ = copy; - copy->lbracketLoc = ast->lbracketLoc; + copy->setChecked(ast->checked()); - copy->indexExpression = accept(ast->indexExpression); + copy->identifierLoc = ast->identifierLoc; - copy->rbracketLoc = ast->rbracketLoc; + copy->ellipsisLoc = ast->ellipsisLoc; + + copy->identifier = ast->identifier; } -void ASTCloner::visit(MemberExpressionAST* ast) { - auto copy = new (arena_) MemberExpressionAST(); +void ASTCloner::visit(RefLambdaCaptureAST* ast) { + auto copy = new (arena_) RefLambdaCaptureAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; - - copy->constValue = ast->constValue; - - copy->baseExpression = accept(ast->baseExpression); - - copy->accessLoc = ast->accessLoc; + copy->ampLoc = ast->ampLoc; - copy->templateLoc = ast->templateLoc; + copy->identifierLoc = ast->identifierLoc; - copy->name = accept(ast->name); + copy->ellipsisLoc = ast->ellipsisLoc; - copy->accessOp = ast->accessOp; + copy->identifier = ast->identifier; } -void ASTCloner::visit(PostIncrExpressionAST* ast) { - auto copy = new (arena_) PostIncrExpressionAST(); +void ASTCloner::visit(RefInitLambdaCaptureAST* ast) { + auto copy = new (arena_) RefInitLambdaCaptureAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->ampLoc = ast->ampLoc; - copy->constValue = ast->constValue; + copy->ellipsisLoc = ast->ellipsisLoc; - copy->baseExpression = accept(ast->baseExpression); + copy->identifierLoc = ast->identifierLoc; - copy->opLoc = ast->opLoc; + copy->initializer = accept(ast->initializer); - copy->op = ast->op; + copy->identifier = ast->identifier; } -void ASTCloner::visit(ConditionalExpressionAST* ast) { - auto copy = new (arena_) ConditionalExpressionAST(); +void ASTCloner::visit(InitLambdaCaptureAST* ast) { + auto copy = new (arena_) InitLambdaCaptureAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->ellipsisLoc = ast->ellipsisLoc; - copy->constValue = ast->constValue; + copy->identifierLoc = ast->identifierLoc; - copy->condition = accept(ast->condition); + copy->initializer = accept(ast->initializer); - copy->questionLoc = ast->questionLoc; + copy->identifier = ast->identifier; +} - copy->iftrueExpression = accept(ast->iftrueExpression); +void ASTCloner::visit(EqualInitializerAST* ast) { + auto copy = new (arena_) EqualInitializerAST(); + copy_ = copy; - copy->colonLoc = ast->colonLoc; + copy->setChecked(ast->checked()); - copy->iffalseExpression = accept(ast->iffalseExpression); + copy->equalLoc = ast->equalLoc; + + copy->expression = accept(ast->expression); } -void ASTCloner::visit(ImplicitCastExpressionAST* ast) { - auto copy = new (arena_) ImplicitCastExpressionAST(); +void ASTCloner::visit(BracedInitListAST* ast) { + auto copy = new (arena_) BracedInitListAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->lbraceLoc = ast->lbraceLoc; - copy->constValue = ast->constValue; + if (auto it = ast->expressionList) { + auto out = ©->expressionList; - copy->expression = accept(ast->expression); + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } - copy->castKind = ast->castKind; + copy->commaLoc = ast->commaLoc; + + copy->rbraceLoc = ast->rbraceLoc; } -void ASTCloner::visit(CastExpressionAST* ast) { - auto copy = new (arena_) CastExpressionAST(); +void ASTCloner::visit(ParenInitializerAST* ast) { + auto copy = new (arena_) ParenInitializerAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; - - copy->constValue = ast->constValue; - copy->lparenLoc = ast->lparenLoc; - copy->typeId = accept(ast->typeId); + if (auto it = ast->expressionList) { + auto out = ©->expressionList; - copy->rparenLoc = ast->rparenLoc; + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } - copy->expression = accept(ast->expression); + copy->rparenLoc = ast->rparenLoc; } -void ASTCloner::visit(CppCastExpressionAST* ast) { - auto copy = new (arena_) CppCastExpressionAST(); +void ASTCloner::visit(NewParenInitializerAST* ast) { + auto copy = new (arena_) NewParenInitializerAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->lparenLoc = ast->lparenLoc; - copy->constValue = ast->constValue; + if (auto it = ast->expressionList) { + auto out = ©->expressionList; - copy->castLoc = ast->castLoc; + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } - copy->lessLoc = ast->lessLoc; + copy->rparenLoc = ast->rparenLoc; +} - copy->typeId = accept(ast->typeId); +void ASTCloner::visit(NewBracedInitializerAST* ast) { + auto copy = new (arena_) NewBracedInitializerAST(); + copy_ = copy; - copy->greaterLoc = ast->greaterLoc; + copy->setChecked(ast->checked()); - copy->lparenLoc = ast->lparenLoc; + copy->bracedInit = accept(ast->bracedInit); +} - copy->expression = accept(ast->expression); +void ASTCloner::visit(EllipsisExceptionDeclarationAST* ast) { + auto copy = new (arena_) EllipsisExceptionDeclarationAST(); + copy_ = copy; - copy->rparenLoc = ast->rparenLoc; + copy->setChecked(ast->checked()); + + copy->ellipsisLoc = ast->ellipsisLoc; } -void ASTCloner::visit(NewExpressionAST* ast) { - auto copy = new (arena_) NewExpressionAST(); +void ASTCloner::visit(TypeExceptionDeclarationAST* ast) { + auto copy = new (arena_) TypeExceptionDeclarationAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; - - copy->constValue = ast->constValue; + if (auto it = ast->attributeList) { + auto out = ©->attributeList; - copy->scopeLoc = ast->scopeLoc; + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } - copy->newLoc = ast->newLoc; + if (auto it = ast->typeSpecifierList) { + auto out = ©->typeSpecifierList; - copy->typeId = accept(ast->typeId); + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } - copy->newInitalizer = accept(ast->newInitalizer); + copy->declarator = accept(ast->declarator); } -void ASTCloner::visit(DeleteExpressionAST* ast) { - auto copy = new (arena_) DeleteExpressionAST(); +void ASTCloner::visit(DefaultFunctionBodyAST* ast) { + auto copy = new (arena_) DefaultFunctionBodyAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->equalLoc = ast->equalLoc; - copy->constValue = ast->constValue; + copy->defaultLoc = ast->defaultLoc; - copy->scopeLoc = ast->scopeLoc; + copy->semicolonLoc = ast->semicolonLoc; +} - copy->deleteLoc = ast->deleteLoc; +void ASTCloner::visit(CompoundStatementFunctionBodyAST* ast) { + auto copy = new (arena_) CompoundStatementFunctionBodyAST(); + copy_ = copy; - copy->lbracketLoc = ast->lbracketLoc; + copy->setChecked(ast->checked()); - copy->rbracketLoc = ast->rbracketLoc; + copy->ctorInitializer = accept(ast->ctorInitializer); - copy->expression = accept(ast->expression); + copy->statement = accept(ast->statement); } -void ASTCloner::visit(ThrowExpressionAST* ast) { - auto copy = new (arena_) ThrowExpressionAST(); +void ASTCloner::visit(TryStatementFunctionBodyAST* ast) { + auto copy = new (arena_) TryStatementFunctionBodyAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->tryLoc = ast->tryLoc; - copy->constValue = ast->constValue; + copy->ctorInitializer = accept(ast->ctorInitializer); - copy->throwLoc = ast->throwLoc; + copy->statement = accept(ast->statement); - copy->expression = accept(ast->expression); + if (auto it = ast->handlerList) { + auto out = ©->handlerList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } } -void ASTCloner::visit(NoexceptExpressionAST* ast) { - auto copy = new (arena_) NoexceptExpressionAST(); +void ASTCloner::visit(DeleteFunctionBodyAST* ast) { + auto copy = new (arena_) DeleteFunctionBodyAST(); copy_ = copy; copy->setChecked(ast->checked()); - copy->valueCategory = ast->valueCategory; + copy->equalLoc = ast->equalLoc; - copy->constValue = ast->constValue; + copy->deleteLoc = ast->deleteLoc; - copy->noexceptLoc = ast->noexceptLoc; + copy->semicolonLoc = ast->semicolonLoc; +} - copy->lparenLoc = ast->lparenLoc; +void ASTCloner::visit(TranslationUnitAST* ast) { + auto copy = new (arena_) TranslationUnitAST(); + copy_ = copy; - copy->expression = accept(ast->expression); + copy->setChecked(ast->checked()); - copy->rparenLoc = ast->rparenLoc; + if (auto it = ast->declarationList) { + auto out = ©->declarationList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } +} + +void ASTCloner::visit(ModuleUnitAST* ast) { + auto copy = new (arena_) ModuleUnitAST(); + copy_ = copy; + + copy->setChecked(ast->checked()); + + copy->globalModuleFragment = accept(ast->globalModuleFragment); + + copy->moduleDeclaration = accept(ast->moduleDeclaration); + + if (auto it = ast->declarationList) { + auto out = ©->declarationList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } + + copy->privateModuleFragment = accept(ast->privateModuleFragment); } void ASTCloner::visit(LabeledStatementAST* ast) { diff --git a/src/parser/cxx/ast_cloner.h b/src/parser/cxx/ast_cloner.h index bd00fdcf..66dcfdf3 100644 --- a/src/parser/cxx/ast_cloner.h +++ b/src/parser/cxx/ast_cloner.h @@ -59,43 +59,9 @@ class ASTCloner : public ASTVisitor { void visit(AttributeArgumentClauseAST* ast) override; void visit(AttributeAST* ast) override; void visit(AttributeUsingPrefixAST* ast) override; + void visit(DesignatorAST* ast) override; - void visit(SimpleRequirementAST* ast) override; - void visit(CompoundRequirementAST* ast) override; - void visit(TypeRequirementAST* ast) override; - void visit(NestedRequirementAST* ast) override; - - void visit(TypeTemplateArgumentAST* ast) override; - void visit(ExpressionTemplateArgumentAST* ast) override; - - void visit(ParenMemInitializerAST* ast) override; - void visit(BracedMemInitializerAST* ast) override; - - void visit(ThisLambdaCaptureAST* ast) override; - void visit(DerefThisLambdaCaptureAST* ast) override; - void visit(SimpleLambdaCaptureAST* ast) override; - void visit(RefLambdaCaptureAST* ast) override; - void visit(RefInitLambdaCaptureAST* ast) override; - void visit(InitLambdaCaptureAST* ast) override; - - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - - void visit(NewParenInitializerAST* ast) override; - void visit(NewBracedInitializerAST* ast) override; - - void visit(EllipsisExceptionDeclarationAST* ast) override; - void visit(TypeExceptionDeclarationAST* ast) override; - - void visit(DefaultFunctionBodyAST* ast) override; - void visit(CompoundStatementFunctionBodyAST* ast) override; - void visit(TryStatementFunctionBodyAST* ast) override; - void visit(DeleteFunctionBodyAST* ast) override; - - void visit(TranslationUnitAST* ast) override; - void visit(ModuleUnitAST* ast) override; - + void visit(DesignatedInitializerClauseAST* ast) override; void visit(ThisExpressionAST* ast) override; void visit(CharLiteralExpressionAST* ast) override; void visit(BoolLiteralExpressionAST* ast) override; @@ -136,6 +102,42 @@ class ASTCloner : public ASTVisitor { void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(SimpleRequirementAST* ast) override; + void visit(CompoundRequirementAST* ast) override; + void visit(TypeRequirementAST* ast) override; + void visit(NestedRequirementAST* ast) override; + + void visit(TypeTemplateArgumentAST* ast) override; + void visit(ExpressionTemplateArgumentAST* ast) override; + + void visit(ParenMemInitializerAST* ast) override; + void visit(BracedMemInitializerAST* ast) override; + + void visit(ThisLambdaCaptureAST* ast) override; + void visit(DerefThisLambdaCaptureAST* ast) override; + void visit(SimpleLambdaCaptureAST* ast) override; + void visit(RefLambdaCaptureAST* ast) override; + void visit(RefInitLambdaCaptureAST* ast) override; + void visit(InitLambdaCaptureAST* ast) override; + + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; + + void visit(NewParenInitializerAST* ast) override; + void visit(NewBracedInitializerAST* ast) override; + + void visit(EllipsisExceptionDeclarationAST* ast) override; + void visit(TypeExceptionDeclarationAST* ast) override; + + void visit(DefaultFunctionBodyAST* ast) override; + void visit(CompoundStatementFunctionBodyAST* ast) override; + void visit(TryStatementFunctionBodyAST* ast) override; + void visit(DeleteFunctionBodyAST* ast) override; + + void visit(TranslationUnitAST* ast) override; + void visit(ModuleUnitAST* ast) override; + void visit(LabeledStatementAST* ast) override; void visit(CaseStatementAST* ast) override; void visit(DefaultStatementAST* ast) override; diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index b063079b..13912e3a 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -47,6 +47,133 @@ auto ASTDecoder::operator()(std::span bytes) -> bool { return true; } +auto ASTDecoder::decodeExpression(const void* ptr, io::Expression type) + -> ExpressionAST* { + switch (type) { + case io::Expression_DesignatedInitializerClause: + return decodeDesignatedInitializerClause( + reinterpret_cast(ptr)); + case io::Expression_ThisExpression: + return decodeThisExpression( + reinterpret_cast(ptr)); + case io::Expression_CharLiteralExpression: + return decodeCharLiteralExpression( + reinterpret_cast(ptr)); + case io::Expression_BoolLiteralExpression: + return decodeBoolLiteralExpression( + reinterpret_cast(ptr)); + case io::Expression_IntLiteralExpression: + return decodeIntLiteralExpression( + reinterpret_cast(ptr)); + case io::Expression_FloatLiteralExpression: + return decodeFloatLiteralExpression( + reinterpret_cast(ptr)); + case io::Expression_NullptrLiteralExpression: + return decodeNullptrLiteralExpression( + reinterpret_cast(ptr)); + case io::Expression_StringLiteralExpression: + return decodeStringLiteralExpression( + reinterpret_cast(ptr)); + case io::Expression_UserDefinedStringLiteralExpression: + return decodeUserDefinedStringLiteralExpression( + reinterpret_cast(ptr)); + case io::Expression_IdExpression: + return decodeIdExpression(reinterpret_cast(ptr)); + case io::Expression_RequiresExpression: + return decodeRequiresExpression( + reinterpret_cast(ptr)); + case io::Expression_NestedExpression: + return decodeNestedExpression( + reinterpret_cast(ptr)); + case io::Expression_RightFoldExpression: + return decodeRightFoldExpression( + reinterpret_cast(ptr)); + case io::Expression_LeftFoldExpression: + return decodeLeftFoldExpression( + reinterpret_cast(ptr)); + case io::Expression_FoldExpression: + return decodeFoldExpression( + reinterpret_cast(ptr)); + case io::Expression_LambdaExpression: + return decodeLambdaExpression( + reinterpret_cast(ptr)); + case io::Expression_SizeofExpression: + return decodeSizeofExpression( + reinterpret_cast(ptr)); + case io::Expression_SizeofTypeExpression: + return decodeSizeofTypeExpression( + reinterpret_cast(ptr)); + case io::Expression_SizeofPackExpression: + return decodeSizeofPackExpression( + reinterpret_cast(ptr)); + case io::Expression_TypeidExpression: + return decodeTypeidExpression( + reinterpret_cast(ptr)); + case io::Expression_TypeidOfTypeExpression: + return decodeTypeidOfTypeExpression( + reinterpret_cast(ptr)); + case io::Expression_AlignofExpression: + return decodeAlignofExpression( + reinterpret_cast(ptr)); + case io::Expression_TypeTraitsExpression: + return decodeTypeTraitsExpression( + reinterpret_cast(ptr)); + case io::Expression_UnaryExpression: + return decodeUnaryExpression( + reinterpret_cast(ptr)); + case io::Expression_BinaryExpression: + return decodeBinaryExpression( + reinterpret_cast(ptr)); + case io::Expression_AssignmentExpression: + return decodeAssignmentExpression( + reinterpret_cast(ptr)); + case io::Expression_BracedTypeConstruction: + return decodeBracedTypeConstruction( + reinterpret_cast(ptr)); + case io::Expression_TypeConstruction: + return decodeTypeConstruction( + reinterpret_cast(ptr)); + case io::Expression_CallExpression: + return decodeCallExpression( + reinterpret_cast(ptr)); + case io::Expression_SubscriptExpression: + return decodeSubscriptExpression( + reinterpret_cast(ptr)); + case io::Expression_MemberExpression: + return decodeMemberExpression( + reinterpret_cast(ptr)); + case io::Expression_PostIncrExpression: + return decodePostIncrExpression( + reinterpret_cast(ptr)); + case io::Expression_ConditionalExpression: + return decodeConditionalExpression( + reinterpret_cast(ptr)); + case io::Expression_ImplicitCastExpression: + return decodeImplicitCastExpression( + reinterpret_cast(ptr)); + case io::Expression_CastExpression: + return decodeCastExpression( + reinterpret_cast(ptr)); + case io::Expression_CppCastExpression: + return decodeCppCastExpression( + reinterpret_cast(ptr)); + case io::Expression_NewExpression: + return decodeNewExpression( + reinterpret_cast(ptr)); + case io::Expression_DeleteExpression: + return decodeDeleteExpression( + reinterpret_cast(ptr)); + case io::Expression_ThrowExpression: + return decodeThrowExpression( + reinterpret_cast(ptr)); + case io::Expression_NoexceptExpression: + return decodeNoexceptExpression( + reinterpret_cast(ptr)); + default: + return nullptr; + } // switch +} + auto ASTDecoder::decodeRequirement(const void* ptr, io::Requirement type) -> RequirementAST* { switch (type) { @@ -200,130 +327,6 @@ auto ASTDecoder::decodeUnit(const void* ptr, io::Unit type) -> UnitAST* { } // switch } -auto ASTDecoder::decodeExpression(const void* ptr, io::Expression type) - -> ExpressionAST* { - switch (type) { - case io::Expression_ThisExpression: - return decodeThisExpression( - reinterpret_cast(ptr)); - case io::Expression_CharLiteralExpression: - return decodeCharLiteralExpression( - reinterpret_cast(ptr)); - case io::Expression_BoolLiteralExpression: - return decodeBoolLiteralExpression( - reinterpret_cast(ptr)); - case io::Expression_IntLiteralExpression: - return decodeIntLiteralExpression( - reinterpret_cast(ptr)); - case io::Expression_FloatLiteralExpression: - return decodeFloatLiteralExpression( - reinterpret_cast(ptr)); - case io::Expression_NullptrLiteralExpression: - return decodeNullptrLiteralExpression( - reinterpret_cast(ptr)); - case io::Expression_StringLiteralExpression: - return decodeStringLiteralExpression( - reinterpret_cast(ptr)); - case io::Expression_UserDefinedStringLiteralExpression: - return decodeUserDefinedStringLiteralExpression( - reinterpret_cast(ptr)); - case io::Expression_IdExpression: - return decodeIdExpression(reinterpret_cast(ptr)); - case io::Expression_RequiresExpression: - return decodeRequiresExpression( - reinterpret_cast(ptr)); - case io::Expression_NestedExpression: - return decodeNestedExpression( - reinterpret_cast(ptr)); - case io::Expression_RightFoldExpression: - return decodeRightFoldExpression( - reinterpret_cast(ptr)); - case io::Expression_LeftFoldExpression: - return decodeLeftFoldExpression( - reinterpret_cast(ptr)); - case io::Expression_FoldExpression: - return decodeFoldExpression( - reinterpret_cast(ptr)); - case io::Expression_LambdaExpression: - return decodeLambdaExpression( - reinterpret_cast(ptr)); - case io::Expression_SizeofExpression: - return decodeSizeofExpression( - reinterpret_cast(ptr)); - case io::Expression_SizeofTypeExpression: - return decodeSizeofTypeExpression( - reinterpret_cast(ptr)); - case io::Expression_SizeofPackExpression: - return decodeSizeofPackExpression( - reinterpret_cast(ptr)); - case io::Expression_TypeidExpression: - return decodeTypeidExpression( - reinterpret_cast(ptr)); - case io::Expression_TypeidOfTypeExpression: - return decodeTypeidOfTypeExpression( - reinterpret_cast(ptr)); - case io::Expression_AlignofExpression: - return decodeAlignofExpression( - reinterpret_cast(ptr)); - case io::Expression_TypeTraitsExpression: - return decodeTypeTraitsExpression( - reinterpret_cast(ptr)); - case io::Expression_UnaryExpression: - return decodeUnaryExpression( - reinterpret_cast(ptr)); - case io::Expression_BinaryExpression: - return decodeBinaryExpression( - reinterpret_cast(ptr)); - case io::Expression_AssignmentExpression: - return decodeAssignmentExpression( - reinterpret_cast(ptr)); - case io::Expression_BracedTypeConstruction: - return decodeBracedTypeConstruction( - reinterpret_cast(ptr)); - case io::Expression_TypeConstruction: - return decodeTypeConstruction( - reinterpret_cast(ptr)); - case io::Expression_CallExpression: - return decodeCallExpression( - reinterpret_cast(ptr)); - case io::Expression_SubscriptExpression: - return decodeSubscriptExpression( - reinterpret_cast(ptr)); - case io::Expression_MemberExpression: - return decodeMemberExpression( - reinterpret_cast(ptr)); - case io::Expression_PostIncrExpression: - return decodePostIncrExpression( - reinterpret_cast(ptr)); - case io::Expression_ConditionalExpression: - return decodeConditionalExpression( - reinterpret_cast(ptr)); - case io::Expression_ImplicitCastExpression: - return decodeImplicitCastExpression( - reinterpret_cast(ptr)); - case io::Expression_CastExpression: - return decodeCastExpression( - reinterpret_cast(ptr)); - case io::Expression_CppCastExpression: - return decodeCppCastExpression( - reinterpret_cast(ptr)); - case io::Expression_NewExpression: - return decodeNewExpression( - reinterpret_cast(ptr)); - case io::Expression_DeleteExpression: - return decodeDeleteExpression( - reinterpret_cast(ptr)); - case io::Expression_ThrowExpression: - return decodeThrowExpression( - reinterpret_cast(ptr)); - case io::Expression_NoexceptExpression: - return decodeNoexceptExpression( - reinterpret_cast(ptr)); - default: - return nullptr; - } // switch -} - auto ASTDecoder::decodeStatement(const void* ptr, io::Statement type) -> StatementAST* { switch (type) { @@ -1129,648 +1132,650 @@ auto ASTDecoder::decodeAttributeUsingPrefix( return ast; } -auto ASTDecoder::decodeSimpleRequirement(const io::SimpleRequirement* node) - -> SimpleRequirementAST* { +auto ASTDecoder::decodeDesignator(const io::Designator* node) + -> DesignatorAST* { if (!node) return nullptr; - auto ast = new (pool_) SimpleRequirementAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); - return ast; -} - -auto ASTDecoder::decodeCompoundRequirement(const io::CompoundRequirement* node) - -> CompoundRequirementAST* { - if (!node) return nullptr; - - auto ast = new (pool_) CompoundRequirementAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); - ast->typeConstraint = decodeTypeConstraint(node->type_constraint()); + auto ast = new (pool_) DesignatorAST(); + if (node->identifier()) { + ast->identifier = + unit_->control()->getIdentifier(node->identifier()->str()); + } return ast; } -auto ASTDecoder::decodeTypeRequirement(const io::TypeRequirement* node) - -> TypeRequirementAST* { +auto ASTDecoder::decodeDesignatedInitializerClause( + const io::DesignatedInitializerClause* node) + -> DesignatedInitializerClauseAST* { if (!node) return nullptr; - auto ast = new (pool_) TypeRequirementAST(); - ast->nestedNameSpecifier = - decodeNestedNameSpecifier(node->nested_name_specifier()); - ast->name = decodeName(node->name(), node->name_type()); + auto ast = new (pool_) DesignatedInitializerClauseAST(); + ast->designator = decodeDesignator(node->designator()); + ast->initializer = + decodeInitializer(node->initializer(), node->initializer_type()); return ast; } -auto ASTDecoder::decodeNestedRequirement(const io::NestedRequirement* node) - -> NestedRequirementAST* { +auto ASTDecoder::decodeThisExpression(const io::ThisExpression* node) + -> ThisExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) NestedRequirementAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); + auto ast = new (pool_) ThisExpressionAST(); return ast; } -auto ASTDecoder::decodeTypeTemplateArgument( - const io::TypeTemplateArgument* node) -> TypeTemplateArgumentAST* { +auto ASTDecoder::decodeCharLiteralExpression( + const io::CharLiteralExpression* node) -> CharLiteralExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) TypeTemplateArgumentAST(); - ast->typeId = decodeTypeId(node->type_id()); + auto ast = new (pool_) CharLiteralExpressionAST(); + if (node->literal()) { + ast->literal = unit_->control()->charLiteral(node->literal()->str()); + } return ast; } -auto ASTDecoder::decodeExpressionTemplateArgument( - const io::ExpressionTemplateArgument* node) - -> ExpressionTemplateArgumentAST* { +auto ASTDecoder::decodeBoolLiteralExpression( + const io::BoolLiteralExpression* node) -> BoolLiteralExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) ExpressionTemplateArgumentAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); + auto ast = new (pool_) BoolLiteralExpressionAST(); return ast; } -auto ASTDecoder::decodeParenMemInitializer(const io::ParenMemInitializer* node) - -> ParenMemInitializerAST* { +auto ASTDecoder::decodeIntLiteralExpression( + const io::IntLiteralExpression* node) -> IntLiteralExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) ParenMemInitializerAST(); - ast->name = decodeName(node->name(), node->name_type()); - if (node->expression_list()) { - auto* inserter = &ast->expressionList; - for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { - *inserter = new (pool_) List(decodeExpression( - node->expression_list()->Get(i), - io::Expression(node->expression_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } + auto ast = new (pool_) IntLiteralExpressionAST(); + if (node->literal()) { + ast->literal = unit_->control()->integerLiteral(node->literal()->str()); } return ast; } -auto ASTDecoder::decodeBracedMemInitializer( - const io::BracedMemInitializer* node) -> BracedMemInitializerAST* { +auto ASTDecoder::decodeFloatLiteralExpression( + const io::FloatLiteralExpression* node) -> FloatLiteralExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) BracedMemInitializerAST(); - ast->name = decodeName(node->name(), node->name_type()); - ast->bracedInitList = decodeBracedInitList(node->braced_init_list()); + auto ast = new (pool_) FloatLiteralExpressionAST(); + if (node->literal()) { + ast->literal = unit_->control()->floatLiteral(node->literal()->str()); + } return ast; } -auto ASTDecoder::decodeThisLambdaCapture(const io::ThisLambdaCapture* node) - -> ThisLambdaCaptureAST* { +auto ASTDecoder::decodeNullptrLiteralExpression( + const io::NullptrLiteralExpression* node) -> NullptrLiteralExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) ThisLambdaCaptureAST(); + auto ast = new (pool_) NullptrLiteralExpressionAST(); + ast->literal = static_cast(node->literal()); return ast; } -auto ASTDecoder::decodeDerefThisLambdaCapture( - const io::DerefThisLambdaCapture* node) -> DerefThisLambdaCaptureAST* { +auto ASTDecoder::decodeStringLiteralExpression( + const io::StringLiteralExpression* node) -> StringLiteralExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) DerefThisLambdaCaptureAST(); + auto ast = new (pool_) StringLiteralExpressionAST(); return ast; } -auto ASTDecoder::decodeSimpleLambdaCapture(const io::SimpleLambdaCapture* node) - -> SimpleLambdaCaptureAST* { +auto ASTDecoder::decodeUserDefinedStringLiteralExpression( + const io::UserDefinedStringLiteralExpression* node) + -> UserDefinedStringLiteralExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) SimpleLambdaCaptureAST(); - if (node->identifier()) { - ast->identifier = - unit_->control()->getIdentifier(node->identifier()->str()); + auto ast = new (pool_) UserDefinedStringLiteralExpressionAST(); + if (node->literal()) { + ast->literal = unit_->control()->stringLiteral(node->literal()->str()); } return ast; } -auto ASTDecoder::decodeRefLambdaCapture(const io::RefLambdaCapture* node) - -> RefLambdaCaptureAST* { +auto ASTDecoder::decodeIdExpression(const io::IdExpression* node) + -> IdExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) RefLambdaCaptureAST(); - if (node->identifier()) { - ast->identifier = - unit_->control()->getIdentifier(node->identifier()->str()); - } + auto ast = new (pool_) IdExpressionAST(); + ast->name = decodeName(node->name(), node->name_type()); return ast; } -auto ASTDecoder::decodeRefInitLambdaCapture( - const io::RefInitLambdaCapture* node) -> RefInitLambdaCaptureAST* { +auto ASTDecoder::decodeRequiresExpression(const io::RequiresExpression* node) + -> RequiresExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) RefInitLambdaCaptureAST(); - ast->initializer = - decodeInitializer(node->initializer(), node->initializer_type()); - if (node->identifier()) { - ast->identifier = - unit_->control()->getIdentifier(node->identifier()->str()); - } + auto ast = new (pool_) RequiresExpressionAST(); + ast->parameterDeclarationClause = + decodeParameterDeclarationClause(node->parameter_declaration_clause()); + ast->requirementBody = decodeRequirementBody(node->requirement_body()); return ast; } -auto ASTDecoder::decodeInitLambdaCapture(const io::InitLambdaCapture* node) - -> InitLambdaCaptureAST* { +auto ASTDecoder::decodeNestedExpression(const io::NestedExpression* node) + -> NestedExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) InitLambdaCaptureAST(); - ast->initializer = - decodeInitializer(node->initializer(), node->initializer_type()); - if (node->identifier()) { - ast->identifier = - unit_->control()->getIdentifier(node->identifier()->str()); - } + auto ast = new (pool_) NestedExpressionAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeEqualInitializer(const io::EqualInitializer* node) - -> EqualInitializerAST* { +auto ASTDecoder::decodeRightFoldExpression(const io::RightFoldExpression* node) + -> RightFoldExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) EqualInitializerAST(); + auto ast = new (pool_) RightFoldExpressionAST(); ast->expression = decodeExpression(node->expression(), node->expression_type()); + ast->op = static_cast(node->op()); return ast; } -auto ASTDecoder::decodeBracedInitList(const io::BracedInitList* node) - -> BracedInitListAST* { +auto ASTDecoder::decodeLeftFoldExpression(const io::LeftFoldExpression* node) + -> LeftFoldExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) BracedInitListAST(); - if (node->expression_list()) { - auto* inserter = &ast->expressionList; - for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { - *inserter = new (pool_) List(decodeExpression( - node->expression_list()->Get(i), - io::Expression(node->expression_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } - } + auto ast = new (pool_) LeftFoldExpressionAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); + ast->op = static_cast(node->op()); return ast; } -auto ASTDecoder::decodeParenInitializer(const io::ParenInitializer* node) - -> ParenInitializerAST* { +auto ASTDecoder::decodeFoldExpression(const io::FoldExpression* node) + -> FoldExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) ParenInitializerAST(); - if (node->expression_list()) { - auto* inserter = &ast->expressionList; - for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { - *inserter = new (pool_) List(decodeExpression( - node->expression_list()->Get(i), - io::Expression(node->expression_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } - } + auto ast = new (pool_) FoldExpressionAST(); + ast->leftExpression = + decodeExpression(node->left_expression(), node->left_expression_type()); + ast->rightExpression = + decodeExpression(node->right_expression(), node->right_expression_type()); + ast->op = static_cast(node->op()); + ast->foldOp = static_cast(node->fold_op()); return ast; } -auto ASTDecoder::decodeNewParenInitializer(const io::NewParenInitializer* node) - -> NewParenInitializerAST* { +auto ASTDecoder::decodeLambdaExpression(const io::LambdaExpression* node) + -> LambdaExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) NewParenInitializerAST(); - if (node->expression_list()) { - auto* inserter = &ast->expressionList; - for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { - *inserter = new (pool_) List(decodeExpression( - node->expression_list()->Get(i), - io::Expression(node->expression_list_type()->Get(i)))); + auto ast = new (pool_) LambdaExpressionAST(); + ast->lambdaIntroducer = decodeLambdaIntroducer(node->lambda_introducer()); + if (node->template_parameter_list()) { + auto* inserter = &ast->templateParameterList; + for (std::size_t i = 0; i < node->template_parameter_list()->size(); ++i) { + *inserter = new (pool_) List(decodeDeclaration( + node->template_parameter_list()->Get(i), + io::Declaration(node->template_parameter_list_type()->Get(i)))); inserter = &(*inserter)->next; } } + ast->requiresClause = decodeRequiresClause(node->requires_clause()); + ast->lambdaDeclarator = decodeLambdaDeclarator(node->lambda_declarator()); + ast->statement = decodeCompoundStatement(node->statement()); return ast; } -auto ASTDecoder::decodeNewBracedInitializer( - const io::NewBracedInitializer* node) -> NewBracedInitializerAST* { +auto ASTDecoder::decodeSizeofExpression(const io::SizeofExpression* node) + -> SizeofExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) NewBracedInitializerAST(); - ast->bracedInit = decodeBracedInitList(node->braced_init()); + auto ast = new (pool_) SizeofExpressionAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeEllipsisExceptionDeclaration( - const io::EllipsisExceptionDeclaration* node) - -> EllipsisExceptionDeclarationAST* { +auto ASTDecoder::decodeSizeofTypeExpression( + const io::SizeofTypeExpression* node) -> SizeofTypeExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) EllipsisExceptionDeclarationAST(); + auto ast = new (pool_) SizeofTypeExpressionAST(); + ast->typeId = decodeTypeId(node->type_id()); return ast; } -auto ASTDecoder::decodeTypeExceptionDeclaration( - const io::TypeExceptionDeclaration* node) -> TypeExceptionDeclarationAST* { +auto ASTDecoder::decodeSizeofPackExpression( + const io::SizeofPackExpression* node) -> SizeofPackExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) TypeExceptionDeclarationAST(); - if (node->attribute_list()) { - auto* inserter = &ast->attributeList; - for (std::size_t i = 0; i < node->attribute_list()->size(); ++i) { - *inserter = new (pool_) List(decodeAttributeSpecifier( - node->attribute_list()->Get(i), - io::AttributeSpecifier(node->attribute_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } - } - if (node->type_specifier_list()) { - auto* inserter = &ast->typeSpecifierList; - for (std::size_t i = 0; i < node->type_specifier_list()->size(); ++i) { - *inserter = new (pool_) List(decodeSpecifier( - node->type_specifier_list()->Get(i), - io::Specifier(node->type_specifier_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } + auto ast = new (pool_) SizeofPackExpressionAST(); + if (node->identifier()) { + ast->identifier = + unit_->control()->getIdentifier(node->identifier()->str()); } - ast->declarator = decodeDeclarator(node->declarator()); return ast; } -auto ASTDecoder::decodeDefaultFunctionBody(const io::DefaultFunctionBody* node) - -> DefaultFunctionBodyAST* { +auto ASTDecoder::decodeTypeidExpression(const io::TypeidExpression* node) + -> TypeidExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) DefaultFunctionBodyAST(); - return ast; -} - -auto ASTDecoder::decodeCompoundStatementFunctionBody( - const io::CompoundStatementFunctionBody* node) - -> CompoundStatementFunctionBodyAST* { - if (!node) return nullptr; - - auto ast = new (pool_) CompoundStatementFunctionBodyAST(); - ast->ctorInitializer = decodeCtorInitializer(node->ctor_initializer()); - ast->statement = decodeCompoundStatement(node->statement()); + auto ast = new (pool_) TypeidExpressionAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeTryStatementFunctionBody( - const io::TryStatementFunctionBody* node) -> TryStatementFunctionBodyAST* { +auto ASTDecoder::decodeTypeidOfTypeExpression( + const io::TypeidOfTypeExpression* node) -> TypeidOfTypeExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) TryStatementFunctionBodyAST(); - ast->ctorInitializer = decodeCtorInitializer(node->ctor_initializer()); - ast->statement = decodeCompoundStatement(node->statement()); - if (node->handler_list()) { - auto* inserter = &ast->handlerList; - for (std::size_t i = 0; i < node->handler_list()->size(); ++i) { - *inserter = new (pool_) List(decodeHandler(node->handler_list()->Get(i))); - inserter = &(*inserter)->next; - } - } + auto ast = new (pool_) TypeidOfTypeExpressionAST(); + ast->typeId = decodeTypeId(node->type_id()); return ast; } -auto ASTDecoder::decodeDeleteFunctionBody(const io::DeleteFunctionBody* node) - -> DeleteFunctionBodyAST* { +auto ASTDecoder::decodeAlignofExpression(const io::AlignofExpression* node) + -> AlignofExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) DeleteFunctionBodyAST(); + auto ast = new (pool_) AlignofExpressionAST(); + ast->typeId = decodeTypeId(node->type_id()); return ast; } -auto ASTDecoder::decodeTranslationUnit(const io::TranslationUnit* node) - -> TranslationUnitAST* { +auto ASTDecoder::decodeTypeTraitsExpression( + const io::TypeTraitsExpression* node) -> TypeTraitsExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) TranslationUnitAST(); - if (node->declaration_list()) { - auto* inserter = &ast->declarationList; - for (std::size_t i = 0; i < node->declaration_list()->size(); ++i) { - *inserter = new (pool_) List(decodeDeclaration( - node->declaration_list()->Get(i), - io::Declaration(node->declaration_list_type()->Get(i)))); + auto ast = new (pool_) TypeTraitsExpressionAST(); + if (node->type_id_list()) { + auto* inserter = &ast->typeIdList; + for (std::size_t i = 0; i < node->type_id_list()->size(); ++i) { + *inserter = new (pool_) List(decodeTypeId(node->type_id_list()->Get(i))); inserter = &(*inserter)->next; } } + ast->typeTraits = static_cast(node->type_traits()); return ast; } -auto ASTDecoder::decodeModuleUnit(const io::ModuleUnit* node) - -> ModuleUnitAST* { +auto ASTDecoder::decodeUnaryExpression(const io::UnaryExpression* node) + -> UnaryExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) ModuleUnitAST(); - ast->globalModuleFragment = - decodeGlobalModuleFragment(node->global_module_fragment()); - ast->moduleDeclaration = decodeModuleDeclaration(node->module_declaration()); - if (node->declaration_list()) { - auto* inserter = &ast->declarationList; - for (std::size_t i = 0; i < node->declaration_list()->size(); ++i) { - *inserter = new (pool_) List(decodeDeclaration( - node->declaration_list()->Get(i), - io::Declaration(node->declaration_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } - } - ast->privateModuleFragment = - decodePrivateModuleFragment(node->private_module_fragment()); + auto ast = new (pool_) UnaryExpressionAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); + ast->op = static_cast(node->op()); return ast; } -auto ASTDecoder::decodeThisExpression(const io::ThisExpression* node) - -> ThisExpressionAST* { +auto ASTDecoder::decodeBinaryExpression(const io::BinaryExpression* node) + -> BinaryExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) ThisExpressionAST(); + auto ast = new (pool_) BinaryExpressionAST(); + ast->leftExpression = + decodeExpression(node->left_expression(), node->left_expression_type()); + ast->rightExpression = + decodeExpression(node->right_expression(), node->right_expression_type()); + ast->op = static_cast(node->op()); return ast; } -auto ASTDecoder::decodeCharLiteralExpression( - const io::CharLiteralExpression* node) -> CharLiteralExpressionAST* { +auto ASTDecoder::decodeAssignmentExpression( + const io::AssignmentExpression* node) -> AssignmentExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) CharLiteralExpressionAST(); - if (node->literal()) { - ast->literal = unit_->control()->charLiteral(node->literal()->str()); - } + auto ast = new (pool_) AssignmentExpressionAST(); + ast->leftExpression = + decodeExpression(node->left_expression(), node->left_expression_type()); + ast->rightExpression = + decodeExpression(node->right_expression(), node->right_expression_type()); + ast->op = static_cast(node->op()); return ast; } -auto ASTDecoder::decodeBoolLiteralExpression( - const io::BoolLiteralExpression* node) -> BoolLiteralExpressionAST* { +auto ASTDecoder::decodeBracedTypeConstruction( + const io::BracedTypeConstruction* node) -> BracedTypeConstructionAST* { if (!node) return nullptr; - auto ast = new (pool_) BoolLiteralExpressionAST(); + auto ast = new (pool_) BracedTypeConstructionAST(); + ast->typeSpecifier = + decodeSpecifier(node->type_specifier(), node->type_specifier_type()); + ast->bracedInitList = decodeBracedInitList(node->braced_init_list()); return ast; } -auto ASTDecoder::decodeIntLiteralExpression( - const io::IntLiteralExpression* node) -> IntLiteralExpressionAST* { +auto ASTDecoder::decodeTypeConstruction(const io::TypeConstruction* node) + -> TypeConstructionAST* { if (!node) return nullptr; - auto ast = new (pool_) IntLiteralExpressionAST(); - if (node->literal()) { - ast->literal = unit_->control()->integerLiteral(node->literal()->str()); + auto ast = new (pool_) TypeConstructionAST(); + ast->typeSpecifier = + decodeSpecifier(node->type_specifier(), node->type_specifier_type()); + if (node->expression_list()) { + auto* inserter = &ast->expressionList; + for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { + *inserter = new (pool_) List(decodeExpression( + node->expression_list()->Get(i), + io::Expression(node->expression_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } } return ast; } -auto ASTDecoder::decodeFloatLiteralExpression( - const io::FloatLiteralExpression* node) -> FloatLiteralExpressionAST* { +auto ASTDecoder::decodeCallExpression(const io::CallExpression* node) + -> CallExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) FloatLiteralExpressionAST(); - if (node->literal()) { - ast->literal = unit_->control()->floatLiteral(node->literal()->str()); + auto ast = new (pool_) CallExpressionAST(); + ast->baseExpression = + decodeExpression(node->base_expression(), node->base_expression_type()); + if (node->expression_list()) { + auto* inserter = &ast->expressionList; + for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { + *inserter = new (pool_) List(decodeExpression( + node->expression_list()->Get(i), + io::Expression(node->expression_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } } return ast; } -auto ASTDecoder::decodeNullptrLiteralExpression( - const io::NullptrLiteralExpression* node) -> NullptrLiteralExpressionAST* { +auto ASTDecoder::decodeSubscriptExpression(const io::SubscriptExpression* node) + -> SubscriptExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) NullptrLiteralExpressionAST(); - ast->literal = static_cast(node->literal()); + auto ast = new (pool_) SubscriptExpressionAST(); + ast->baseExpression = + decodeExpression(node->base_expression(), node->base_expression_type()); + ast->indexExpression = + decodeExpression(node->index_expression(), node->index_expression_type()); return ast; } -auto ASTDecoder::decodeStringLiteralExpression( - const io::StringLiteralExpression* node) -> StringLiteralExpressionAST* { +auto ASTDecoder::decodeMemberExpression(const io::MemberExpression* node) + -> MemberExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) StringLiteralExpressionAST(); + auto ast = new (pool_) MemberExpressionAST(); + ast->baseExpression = + decodeExpression(node->base_expression(), node->base_expression_type()); + ast->name = decodeName(node->name(), node->name_type()); + ast->accessOp = static_cast(node->access_op()); return ast; } -auto ASTDecoder::decodeUserDefinedStringLiteralExpression( - const io::UserDefinedStringLiteralExpression* node) - -> UserDefinedStringLiteralExpressionAST* { +auto ASTDecoder::decodePostIncrExpression(const io::PostIncrExpression* node) + -> PostIncrExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) UserDefinedStringLiteralExpressionAST(); - if (node->literal()) { - ast->literal = unit_->control()->stringLiteral(node->literal()->str()); - } + auto ast = new (pool_) PostIncrExpressionAST(); + ast->baseExpression = + decodeExpression(node->base_expression(), node->base_expression_type()); + ast->op = static_cast(node->op()); return ast; } -auto ASTDecoder::decodeIdExpression(const io::IdExpression* node) - -> IdExpressionAST* { +auto ASTDecoder::decodeConditionalExpression( + const io::ConditionalExpression* node) -> ConditionalExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) IdExpressionAST(); - ast->name = decodeName(node->name(), node->name_type()); + auto ast = new (pool_) ConditionalExpressionAST(); + ast->condition = decodeExpression(node->condition(), node->condition_type()); + ast->iftrueExpression = decodeExpression(node->iftrue_expression(), + node->iftrue_expression_type()); + ast->iffalseExpression = decodeExpression(node->iffalse_expression(), + node->iffalse_expression_type()); return ast; } -auto ASTDecoder::decodeRequiresExpression(const io::RequiresExpression* node) - -> RequiresExpressionAST* { +auto ASTDecoder::decodeImplicitCastExpression( + const io::ImplicitCastExpression* node) -> ImplicitCastExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) RequiresExpressionAST(); - ast->parameterDeclarationClause = - decodeParameterDeclarationClause(node->parameter_declaration_clause()); - ast->requirementBody = decodeRequirementBody(node->requirement_body()); + auto ast = new (pool_) ImplicitCastExpressionAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeNestedExpression(const io::NestedExpression* node) - -> NestedExpressionAST* { +auto ASTDecoder::decodeCastExpression(const io::CastExpression* node) + -> CastExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) NestedExpressionAST(); + auto ast = new (pool_) CastExpressionAST(); + ast->typeId = decodeTypeId(node->type_id()); ast->expression = decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeRightFoldExpression(const io::RightFoldExpression* node) - -> RightFoldExpressionAST* { +auto ASTDecoder::decodeCppCastExpression(const io::CppCastExpression* node) + -> CppCastExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) RightFoldExpressionAST(); + auto ast = new (pool_) CppCastExpressionAST(); + ast->typeId = decodeTypeId(node->type_id()); ast->expression = decodeExpression(node->expression(), node->expression_type()); - ast->op = static_cast(node->op()); return ast; } -auto ASTDecoder::decodeLeftFoldExpression(const io::LeftFoldExpression* node) - -> LeftFoldExpressionAST* { +auto ASTDecoder::decodeNewExpression(const io::NewExpression* node) + -> NewExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) LeftFoldExpressionAST(); + auto ast = new (pool_) NewExpressionAST(); + ast->typeId = decodeNewTypeId(node->type_id()); + ast->newInitalizer = + decodeNewInitializer(node->new_initalizer(), node->new_initalizer_type()); + return ast; +} + +auto ASTDecoder::decodeDeleteExpression(const io::DeleteExpression* node) + -> DeleteExpressionAST* { + if (!node) return nullptr; + + auto ast = new (pool_) DeleteExpressionAST(); ast->expression = decodeExpression(node->expression(), node->expression_type()); - ast->op = static_cast(node->op()); return ast; } -auto ASTDecoder::decodeFoldExpression(const io::FoldExpression* node) - -> FoldExpressionAST* { +auto ASTDecoder::decodeThrowExpression(const io::ThrowExpression* node) + -> ThrowExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) FoldExpressionAST(); - ast->leftExpression = - decodeExpression(node->left_expression(), node->left_expression_type()); - ast->rightExpression = - decodeExpression(node->right_expression(), node->right_expression_type()); - ast->op = static_cast(node->op()); - ast->foldOp = static_cast(node->fold_op()); + auto ast = new (pool_) ThrowExpressionAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeLambdaExpression(const io::LambdaExpression* node) - -> LambdaExpressionAST* { +auto ASTDecoder::decodeNoexceptExpression(const io::NoexceptExpression* node) + -> NoexceptExpressionAST* { if (!node) return nullptr; - auto ast = new (pool_) LambdaExpressionAST(); - ast->lambdaIntroducer = decodeLambdaIntroducer(node->lambda_introducer()); - if (node->template_parameter_list()) { - auto* inserter = &ast->templateParameterList; - for (std::size_t i = 0; i < node->template_parameter_list()->size(); ++i) { - *inserter = new (pool_) List(decodeDeclaration( - node->template_parameter_list()->Get(i), - io::Declaration(node->template_parameter_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } - } - ast->requiresClause = decodeRequiresClause(node->requires_clause()); - ast->lambdaDeclarator = decodeLambdaDeclarator(node->lambda_declarator()); - ast->statement = decodeCompoundStatement(node->statement()); + auto ast = new (pool_) NoexceptExpressionAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeSizeofExpression(const io::SizeofExpression* node) - -> SizeofExpressionAST* { +auto ASTDecoder::decodeSimpleRequirement(const io::SimpleRequirement* node) + -> SimpleRequirementAST* { if (!node) return nullptr; - auto ast = new (pool_) SizeofExpressionAST(); + auto ast = new (pool_) SimpleRequirementAST(); ast->expression = decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeSizeofTypeExpression( - const io::SizeofTypeExpression* node) -> SizeofTypeExpressionAST* { +auto ASTDecoder::decodeCompoundRequirement(const io::CompoundRequirement* node) + -> CompoundRequirementAST* { if (!node) return nullptr; - auto ast = new (pool_) SizeofTypeExpressionAST(); - ast->typeId = decodeTypeId(node->type_id()); + auto ast = new (pool_) CompoundRequirementAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); + ast->typeConstraint = decodeTypeConstraint(node->type_constraint()); return ast; } -auto ASTDecoder::decodeSizeofPackExpression( - const io::SizeofPackExpression* node) -> SizeofPackExpressionAST* { +auto ASTDecoder::decodeTypeRequirement(const io::TypeRequirement* node) + -> TypeRequirementAST* { if (!node) return nullptr; - auto ast = new (pool_) SizeofPackExpressionAST(); - if (node->identifier()) { - ast->identifier = - unit_->control()->getIdentifier(node->identifier()->str()); - } + auto ast = new (pool_) TypeRequirementAST(); + ast->nestedNameSpecifier = + decodeNestedNameSpecifier(node->nested_name_specifier()); + ast->name = decodeName(node->name(), node->name_type()); return ast; } -auto ASTDecoder::decodeTypeidExpression(const io::TypeidExpression* node) - -> TypeidExpressionAST* { +auto ASTDecoder::decodeNestedRequirement(const io::NestedRequirement* node) + -> NestedRequirementAST* { if (!node) return nullptr; - auto ast = new (pool_) TypeidExpressionAST(); + auto ast = new (pool_) NestedRequirementAST(); ast->expression = decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeTypeidOfTypeExpression( - const io::TypeidOfTypeExpression* node) -> TypeidOfTypeExpressionAST* { +auto ASTDecoder::decodeTypeTemplateArgument( + const io::TypeTemplateArgument* node) -> TypeTemplateArgumentAST* { if (!node) return nullptr; - auto ast = new (pool_) TypeidOfTypeExpressionAST(); + auto ast = new (pool_) TypeTemplateArgumentAST(); ast->typeId = decodeTypeId(node->type_id()); return ast; } -auto ASTDecoder::decodeAlignofExpression(const io::AlignofExpression* node) - -> AlignofExpressionAST* { +auto ASTDecoder::decodeExpressionTemplateArgument( + const io::ExpressionTemplateArgument* node) + -> ExpressionTemplateArgumentAST* { if (!node) return nullptr; - auto ast = new (pool_) AlignofExpressionAST(); - ast->typeId = decodeTypeId(node->type_id()); + auto ast = new (pool_) ExpressionTemplateArgumentAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); return ast; } -auto ASTDecoder::decodeTypeTraitsExpression( - const io::TypeTraitsExpression* node) -> TypeTraitsExpressionAST* { +auto ASTDecoder::decodeParenMemInitializer(const io::ParenMemInitializer* node) + -> ParenMemInitializerAST* { if (!node) return nullptr; - auto ast = new (pool_) TypeTraitsExpressionAST(); - if (node->type_id_list()) { - auto* inserter = &ast->typeIdList; - for (std::size_t i = 0; i < node->type_id_list()->size(); ++i) { - *inserter = new (pool_) List(decodeTypeId(node->type_id_list()->Get(i))); + auto ast = new (pool_) ParenMemInitializerAST(); + ast->name = decodeName(node->name(), node->name_type()); + if (node->expression_list()) { + auto* inserter = &ast->expressionList; + for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { + *inserter = new (pool_) List(decodeExpression( + node->expression_list()->Get(i), + io::Expression(node->expression_list_type()->Get(i)))); inserter = &(*inserter)->next; } } - ast->typeTraits = static_cast(node->type_traits()); return ast; } -auto ASTDecoder::decodeUnaryExpression(const io::UnaryExpression* node) - -> UnaryExpressionAST* { +auto ASTDecoder::decodeBracedMemInitializer( + const io::BracedMemInitializer* node) -> BracedMemInitializerAST* { if (!node) return nullptr; - auto ast = new (pool_) UnaryExpressionAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); - ast->op = static_cast(node->op()); + auto ast = new (pool_) BracedMemInitializerAST(); + ast->name = decodeName(node->name(), node->name_type()); + ast->bracedInitList = decodeBracedInitList(node->braced_init_list()); return ast; } -auto ASTDecoder::decodeBinaryExpression(const io::BinaryExpression* node) - -> BinaryExpressionAST* { +auto ASTDecoder::decodeThisLambdaCapture(const io::ThisLambdaCapture* node) + -> ThisLambdaCaptureAST* { if (!node) return nullptr; - auto ast = new (pool_) BinaryExpressionAST(); - ast->leftExpression = - decodeExpression(node->left_expression(), node->left_expression_type()); - ast->rightExpression = - decodeExpression(node->right_expression(), node->right_expression_type()); - ast->op = static_cast(node->op()); + auto ast = new (pool_) ThisLambdaCaptureAST(); return ast; } -auto ASTDecoder::decodeAssignmentExpression( - const io::AssignmentExpression* node) -> AssignmentExpressionAST* { +auto ASTDecoder::decodeDerefThisLambdaCapture( + const io::DerefThisLambdaCapture* node) -> DerefThisLambdaCaptureAST* { if (!node) return nullptr; - auto ast = new (pool_) AssignmentExpressionAST(); - ast->leftExpression = - decodeExpression(node->left_expression(), node->left_expression_type()); - ast->rightExpression = - decodeExpression(node->right_expression(), node->right_expression_type()); - ast->op = static_cast(node->op()); + auto ast = new (pool_) DerefThisLambdaCaptureAST(); return ast; } -auto ASTDecoder::decodeBracedTypeConstruction( - const io::BracedTypeConstruction* node) -> BracedTypeConstructionAST* { +auto ASTDecoder::decodeSimpleLambdaCapture(const io::SimpleLambdaCapture* node) + -> SimpleLambdaCaptureAST* { if (!node) return nullptr; - auto ast = new (pool_) BracedTypeConstructionAST(); - ast->typeSpecifier = - decodeSpecifier(node->type_specifier(), node->type_specifier_type()); - ast->bracedInitList = decodeBracedInitList(node->braced_init_list()); + auto ast = new (pool_) SimpleLambdaCaptureAST(); + if (node->identifier()) { + ast->identifier = + unit_->control()->getIdentifier(node->identifier()->str()); + } return ast; } -auto ASTDecoder::decodeTypeConstruction(const io::TypeConstruction* node) - -> TypeConstructionAST* { +auto ASTDecoder::decodeRefLambdaCapture(const io::RefLambdaCapture* node) + -> RefLambdaCaptureAST* { if (!node) return nullptr; - auto ast = new (pool_) TypeConstructionAST(); - ast->typeSpecifier = - decodeSpecifier(node->type_specifier(), node->type_specifier_type()); + auto ast = new (pool_) RefLambdaCaptureAST(); + if (node->identifier()) { + ast->identifier = + unit_->control()->getIdentifier(node->identifier()->str()); + } + return ast; +} + +auto ASTDecoder::decodeRefInitLambdaCapture( + const io::RefInitLambdaCapture* node) -> RefInitLambdaCaptureAST* { + if (!node) return nullptr; + + auto ast = new (pool_) RefInitLambdaCaptureAST(); + ast->initializer = + decodeInitializer(node->initializer(), node->initializer_type()); + if (node->identifier()) { + ast->identifier = + unit_->control()->getIdentifier(node->identifier()->str()); + } + return ast; +} + +auto ASTDecoder::decodeInitLambdaCapture(const io::InitLambdaCapture* node) + -> InitLambdaCaptureAST* { + if (!node) return nullptr; + + auto ast = new (pool_) InitLambdaCaptureAST(); + ast->initializer = + decodeInitializer(node->initializer(), node->initializer_type()); + if (node->identifier()) { + ast->identifier = + unit_->control()->getIdentifier(node->identifier()->str()); + } + return ast; +} + +auto ASTDecoder::decodeEqualInitializer(const io::EqualInitializer* node) + -> EqualInitializerAST* { + if (!node) return nullptr; + + auto ast = new (pool_) EqualInitializerAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); + return ast; +} + +auto ASTDecoder::decodeBracedInitList(const io::BracedInitList* node) + -> BracedInitListAST* { + if (!node) return nullptr; + + auto ast = new (pool_) BracedInitListAST(); if (node->expression_list()) { auto* inserter = &ast->expressionList; for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { @@ -1783,13 +1788,11 @@ auto ASTDecoder::decodeTypeConstruction(const io::TypeConstruction* node) return ast; } -auto ASTDecoder::decodeCallExpression(const io::CallExpression* node) - -> CallExpressionAST* { +auto ASTDecoder::decodeParenInitializer(const io::ParenInitializer* node) + -> ParenInitializerAST* { if (!node) return nullptr; - auto ast = new (pool_) CallExpressionAST(); - ast->baseExpression = - decodeExpression(node->base_expression(), node->base_expression_type()); + auto ast = new (pool_) ParenInitializerAST(); if (node->expression_list()) { auto* inserter = &ast->expressionList; for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { @@ -1802,124 +1805,148 @@ auto ASTDecoder::decodeCallExpression(const io::CallExpression* node) return ast; } -auto ASTDecoder::decodeSubscriptExpression(const io::SubscriptExpression* node) - -> SubscriptExpressionAST* { - if (!node) return nullptr; - - auto ast = new (pool_) SubscriptExpressionAST(); - ast->baseExpression = - decodeExpression(node->base_expression(), node->base_expression_type()); - ast->indexExpression = - decodeExpression(node->index_expression(), node->index_expression_type()); - return ast; -} - -auto ASTDecoder::decodeMemberExpression(const io::MemberExpression* node) - -> MemberExpressionAST* { +auto ASTDecoder::decodeNewParenInitializer(const io::NewParenInitializer* node) + -> NewParenInitializerAST* { if (!node) return nullptr; - auto ast = new (pool_) MemberExpressionAST(); - ast->baseExpression = - decodeExpression(node->base_expression(), node->base_expression_type()); - ast->name = decodeName(node->name(), node->name_type()); - ast->accessOp = static_cast(node->access_op()); + auto ast = new (pool_) NewParenInitializerAST(); + if (node->expression_list()) { + auto* inserter = &ast->expressionList; + for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { + *inserter = new (pool_) List(decodeExpression( + node->expression_list()->Get(i), + io::Expression(node->expression_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } return ast; } -auto ASTDecoder::decodePostIncrExpression(const io::PostIncrExpression* node) - -> PostIncrExpressionAST* { +auto ASTDecoder::decodeNewBracedInitializer( + const io::NewBracedInitializer* node) -> NewBracedInitializerAST* { if (!node) return nullptr; - auto ast = new (pool_) PostIncrExpressionAST(); - ast->baseExpression = - decodeExpression(node->base_expression(), node->base_expression_type()); - ast->op = static_cast(node->op()); + auto ast = new (pool_) NewBracedInitializerAST(); + ast->bracedInit = decodeBracedInitList(node->braced_init()); return ast; } -auto ASTDecoder::decodeConditionalExpression( - const io::ConditionalExpression* node) -> ConditionalExpressionAST* { +auto ASTDecoder::decodeEllipsisExceptionDeclaration( + const io::EllipsisExceptionDeclaration* node) + -> EllipsisExceptionDeclarationAST* { if (!node) return nullptr; - auto ast = new (pool_) ConditionalExpressionAST(); - ast->condition = decodeExpression(node->condition(), node->condition_type()); - ast->iftrueExpression = decodeExpression(node->iftrue_expression(), - node->iftrue_expression_type()); - ast->iffalseExpression = decodeExpression(node->iffalse_expression(), - node->iffalse_expression_type()); + auto ast = new (pool_) EllipsisExceptionDeclarationAST(); return ast; } -auto ASTDecoder::decodeImplicitCastExpression( - const io::ImplicitCastExpression* node) -> ImplicitCastExpressionAST* { +auto ASTDecoder::decodeTypeExceptionDeclaration( + const io::TypeExceptionDeclaration* node) -> TypeExceptionDeclarationAST* { if (!node) return nullptr; - auto ast = new (pool_) ImplicitCastExpressionAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); + auto ast = new (pool_) TypeExceptionDeclarationAST(); + if (node->attribute_list()) { + auto* inserter = &ast->attributeList; + for (std::size_t i = 0; i < node->attribute_list()->size(); ++i) { + *inserter = new (pool_) List(decodeAttributeSpecifier( + node->attribute_list()->Get(i), + io::AttributeSpecifier(node->attribute_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } + if (node->type_specifier_list()) { + auto* inserter = &ast->typeSpecifierList; + for (std::size_t i = 0; i < node->type_specifier_list()->size(); ++i) { + *inserter = new (pool_) List(decodeSpecifier( + node->type_specifier_list()->Get(i), + io::Specifier(node->type_specifier_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } + ast->declarator = decodeDeclarator(node->declarator()); return ast; } -auto ASTDecoder::decodeCastExpression(const io::CastExpression* node) - -> CastExpressionAST* { +auto ASTDecoder::decodeDefaultFunctionBody(const io::DefaultFunctionBody* node) + -> DefaultFunctionBodyAST* { if (!node) return nullptr; - auto ast = new (pool_) CastExpressionAST(); - ast->typeId = decodeTypeId(node->type_id()); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); + auto ast = new (pool_) DefaultFunctionBodyAST(); return ast; } -auto ASTDecoder::decodeCppCastExpression(const io::CppCastExpression* node) - -> CppCastExpressionAST* { +auto ASTDecoder::decodeCompoundStatementFunctionBody( + const io::CompoundStatementFunctionBody* node) + -> CompoundStatementFunctionBodyAST* { if (!node) return nullptr; - auto ast = new (pool_) CppCastExpressionAST(); - ast->typeId = decodeTypeId(node->type_id()); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); + auto ast = new (pool_) CompoundStatementFunctionBodyAST(); + ast->ctorInitializer = decodeCtorInitializer(node->ctor_initializer()); + ast->statement = decodeCompoundStatement(node->statement()); return ast; } -auto ASTDecoder::decodeNewExpression(const io::NewExpression* node) - -> NewExpressionAST* { +auto ASTDecoder::decodeTryStatementFunctionBody( + const io::TryStatementFunctionBody* node) -> TryStatementFunctionBodyAST* { if (!node) return nullptr; - auto ast = new (pool_) NewExpressionAST(); - ast->typeId = decodeNewTypeId(node->type_id()); - ast->newInitalizer = - decodeNewInitializer(node->new_initalizer(), node->new_initalizer_type()); + auto ast = new (pool_) TryStatementFunctionBodyAST(); + ast->ctorInitializer = decodeCtorInitializer(node->ctor_initializer()); + ast->statement = decodeCompoundStatement(node->statement()); + if (node->handler_list()) { + auto* inserter = &ast->handlerList; + for (std::size_t i = 0; i < node->handler_list()->size(); ++i) { + *inserter = new (pool_) List(decodeHandler(node->handler_list()->Get(i))); + inserter = &(*inserter)->next; + } + } return ast; } -auto ASTDecoder::decodeDeleteExpression(const io::DeleteExpression* node) - -> DeleteExpressionAST* { +auto ASTDecoder::decodeDeleteFunctionBody(const io::DeleteFunctionBody* node) + -> DeleteFunctionBodyAST* { if (!node) return nullptr; - auto ast = new (pool_) DeleteExpressionAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); + auto ast = new (pool_) DeleteFunctionBodyAST(); return ast; } -auto ASTDecoder::decodeThrowExpression(const io::ThrowExpression* node) - -> ThrowExpressionAST* { +auto ASTDecoder::decodeTranslationUnit(const io::TranslationUnit* node) + -> TranslationUnitAST* { if (!node) return nullptr; - auto ast = new (pool_) ThrowExpressionAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); + auto ast = new (pool_) TranslationUnitAST(); + if (node->declaration_list()) { + auto* inserter = &ast->declarationList; + for (std::size_t i = 0; i < node->declaration_list()->size(); ++i) { + *inserter = new (pool_) List(decodeDeclaration( + node->declaration_list()->Get(i), + io::Declaration(node->declaration_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } return ast; } -auto ASTDecoder::decodeNoexceptExpression(const io::NoexceptExpression* node) - -> NoexceptExpressionAST* { +auto ASTDecoder::decodeModuleUnit(const io::ModuleUnit* node) + -> ModuleUnitAST* { if (!node) return nullptr; - auto ast = new (pool_) NoexceptExpressionAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); + auto ast = new (pool_) ModuleUnitAST(); + ast->globalModuleFragment = + decodeGlobalModuleFragment(node->global_module_fragment()); + ast->moduleDeclaration = decodeModuleDeclaration(node->module_declaration()); + if (node->declaration_list()) { + auto* inserter = &ast->declarationList; + for (std::size_t i = 0; i < node->declaration_list()->size(); ++i) { + *inserter = new (pool_) List(decodeDeclaration( + node->declaration_list()->Get(i), + io::Declaration(node->declaration_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } + ast->privateModuleFragment = + decodePrivateModuleFragment(node->private_module_fragment()); return ast; } diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index 0f493480..84b9ba78 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -126,7 +126,7 @@ auto ASTEncoder::encodeSourceLocation(const SourceLocation& loc) return offset.Union(); } -auto ASTEncoder::acceptRequirement(RequirementAST* ast) +auto ASTEncoder::acceptExpression(ExpressionAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -139,7 +139,7 @@ auto ASTEncoder::acceptRequirement(RequirementAST* ast) return {offset, type}; } -auto ASTEncoder::acceptTemplateArgument(TemplateArgumentAST* ast) +auto ASTEncoder::acceptRequirement(RequirementAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -152,7 +152,7 @@ auto ASTEncoder::acceptTemplateArgument(TemplateArgumentAST* ast) return {offset, type}; } -auto ASTEncoder::acceptMemInitializer(MemInitializerAST* ast) +auto ASTEncoder::acceptTemplateArgument(TemplateArgumentAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -165,7 +165,7 @@ auto ASTEncoder::acceptMemInitializer(MemInitializerAST* ast) return {offset, type}; } -auto ASTEncoder::acceptLambdaCapture(LambdaCaptureAST* ast) +auto ASTEncoder::acceptMemInitializer(MemInitializerAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -178,7 +178,7 @@ auto ASTEncoder::acceptLambdaCapture(LambdaCaptureAST* ast) return {offset, type}; } -auto ASTEncoder::acceptInitializer(InitializerAST* ast) +auto ASTEncoder::acceptLambdaCapture(LambdaCaptureAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -191,7 +191,7 @@ auto ASTEncoder::acceptInitializer(InitializerAST* ast) return {offset, type}; } -auto ASTEncoder::acceptNewInitializer(NewInitializerAST* ast) +auto ASTEncoder::acceptInitializer(InitializerAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -204,7 +204,7 @@ auto ASTEncoder::acceptNewInitializer(NewInitializerAST* ast) return {offset, type}; } -auto ASTEncoder::acceptExceptionDeclaration(ExceptionDeclarationAST* ast) +auto ASTEncoder::acceptNewInitializer(NewInitializerAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -217,7 +217,7 @@ auto ASTEncoder::acceptExceptionDeclaration(ExceptionDeclarationAST* ast) return {offset, type}; } -auto ASTEncoder::acceptFunctionBody(FunctionBodyAST* ast) +auto ASTEncoder::acceptExceptionDeclaration(ExceptionDeclarationAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -230,7 +230,7 @@ auto ASTEncoder::acceptFunctionBody(FunctionBodyAST* ast) return {offset, type}; } -auto ASTEncoder::acceptUnit(UnitAST* ast) +auto ASTEncoder::acceptFunctionBody(FunctionBodyAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -243,7 +243,7 @@ auto ASTEncoder::acceptUnit(UnitAST* ast) return {offset, type}; } -auto ASTEncoder::acceptExpression(ExpressionAST* ast) +auto ASTEncoder::acceptUnit(UnitAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; flatbuffers::Offset<> offset; @@ -1084,278 +1084,400 @@ void ASTEncoder::visit(AttributeUsingPrefixAST* ast) { offset_ = builder.Finish().Union(); } -void ASTEncoder::visit(SimpleRequirementAST* ast) { - const auto [expression, expressionType] = acceptExpression(ast->expression); +void ASTEncoder::visit(DesignatorAST* ast) { + auto dotLoc = encodeSourceLocation(ast->dotLoc); - auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); - io::SimpleRequirement::Builder builder{fbb_}; - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); - builder.add_semicolon_loc(semicolonLoc.o); + flatbuffers::Offset identifier; + if (ast->identifier) { + if (identifiers_.contains(ast->identifier)) { + identifier = identifiers_.at(ast->identifier); + } else { + identifier = fbb_.CreateString(ast->identifier->value()); + identifiers_.emplace(ast->identifier, identifier); + } + } + + io::Designator::Builder builder{fbb_}; + builder.add_dot_loc(dotLoc.o); + builder.add_identifier_loc(identifierLoc.o); + if (ast->identifier) { + builder.add_identifier(identifier); + } offset_ = builder.Finish().Union(); - type_ = io::Requirement_SimpleRequirement; } -void ASTEncoder::visit(CompoundRequirementAST* ast) { - auto lbraceLoc = encodeSourceLocation(ast->lbraceLoc); - - const auto [expression, expressionType] = acceptExpression(ast->expression); - - auto rbraceLoc = encodeSourceLocation(ast->rbraceLoc); +void ASTEncoder::visit(DesignatedInitializerClauseAST* ast) { + const auto designator = accept(ast->designator); - auto noexceptLoc = encodeSourceLocation(ast->noexceptLoc); + const auto [initializer, initializerType] = + acceptInitializer(ast->initializer); - auto minusGreaterLoc = encodeSourceLocation(ast->minusGreaterLoc); + io::DesignatedInitializerClause::Builder builder{fbb_}; + builder.add_designator(designator.o); + builder.add_initializer(initializer); + builder.add_initializer_type(static_cast(initializerType)); - const auto typeConstraint = accept(ast->typeConstraint); + offset_ = builder.Finish().Union(); + type_ = io::Expression_DesignatedInitializerClause; +} - auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); +void ASTEncoder::visit(ThisExpressionAST* ast) { + auto thisLoc = encodeSourceLocation(ast->thisLoc); - io::CompoundRequirement::Builder builder{fbb_}; - builder.add_lbrace_loc(lbraceLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); - builder.add_rbrace_loc(rbraceLoc.o); - builder.add_noexcept_loc(noexceptLoc.o); - builder.add_minus_greater_loc(minusGreaterLoc.o); - builder.add_type_constraint(typeConstraint.o); - builder.add_semicolon_loc(semicolonLoc.o); + io::ThisExpression::Builder builder{fbb_}; + builder.add_this_loc(thisLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Requirement_CompoundRequirement; + type_ = io::Expression_ThisExpression; } -void ASTEncoder::visit(TypeRequirementAST* ast) { - auto typenameLoc = encodeSourceLocation(ast->typenameLoc); +void ASTEncoder::visit(CharLiteralExpressionAST* ast) { + auto literalLoc = encodeSourceLocation(ast->literalLoc); - const auto nestedNameSpecifier = accept(ast->nestedNameSpecifier); + flatbuffers::Offset literal; + if (ast->literal) { + if (charLiterals_.contains(ast->literal)) { + literal = charLiterals_.at(ast->literal); + } else { + literal = fbb_.CreateString(ast->literal->value()); + charLiterals_.emplace(ast->literal, literal); + } + } - const auto [name, nameType] = acceptName(ast->name); + io::CharLiteralExpression::Builder builder{fbb_}; + builder.add_literal_loc(literalLoc.o); + if (ast->literal) { + builder.add_literal(literal); + } - auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); + offset_ = builder.Finish().Union(); + type_ = io::Expression_CharLiteralExpression; +} - io::TypeRequirement::Builder builder{fbb_}; - builder.add_typename_loc(typenameLoc.o); - builder.add_nested_name_specifier(nestedNameSpecifier.o); - builder.add_name(name); - builder.add_name_type(static_cast(nameType)); - builder.add_semicolon_loc(semicolonLoc.o); +void ASTEncoder::visit(BoolLiteralExpressionAST* ast) { + auto literalLoc = encodeSourceLocation(ast->literalLoc); + + io::BoolLiteralExpression::Builder builder{fbb_}; + builder.add_literal_loc(literalLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Requirement_TypeRequirement; + type_ = io::Expression_BoolLiteralExpression; } -void ASTEncoder::visit(NestedRequirementAST* ast) { - auto requiresLoc = encodeSourceLocation(ast->requiresLoc); - - const auto [expression, expressionType] = acceptExpression(ast->expression); +void ASTEncoder::visit(IntLiteralExpressionAST* ast) { + auto literalLoc = encodeSourceLocation(ast->literalLoc); - auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); + flatbuffers::Offset literal; + if (ast->literal) { + if (integerLiterals_.contains(ast->literal)) { + literal = integerLiterals_.at(ast->literal); + } else { + literal = fbb_.CreateString(ast->literal->value()); + integerLiterals_.emplace(ast->literal, literal); + } + } - io::NestedRequirement::Builder builder{fbb_}; - builder.add_requires_loc(requiresLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); - builder.add_semicolon_loc(semicolonLoc.o); + io::IntLiteralExpression::Builder builder{fbb_}; + builder.add_literal_loc(literalLoc.o); + if (ast->literal) { + builder.add_literal(literal); + } offset_ = builder.Finish().Union(); - type_ = io::Requirement_NestedRequirement; + type_ = io::Expression_IntLiteralExpression; } -void ASTEncoder::visit(TypeTemplateArgumentAST* ast) { - const auto typeId = accept(ast->typeId); +void ASTEncoder::visit(FloatLiteralExpressionAST* ast) { + auto literalLoc = encodeSourceLocation(ast->literalLoc); - io::TypeTemplateArgument::Builder builder{fbb_}; - builder.add_type_id(typeId.o); + flatbuffers::Offset literal; + if (ast->literal) { + if (floatLiterals_.contains(ast->literal)) { + literal = floatLiterals_.at(ast->literal); + } else { + literal = fbb_.CreateString(ast->literal->value()); + floatLiterals_.emplace(ast->literal, literal); + } + } + + io::FloatLiteralExpression::Builder builder{fbb_}; + builder.add_literal_loc(literalLoc.o); + if (ast->literal) { + builder.add_literal(literal); + } offset_ = builder.Finish().Union(); - type_ = io::TemplateArgument_TypeTemplateArgument; + type_ = io::Expression_FloatLiteralExpression; } -void ASTEncoder::visit(ExpressionTemplateArgumentAST* ast) { - const auto [expression, expressionType] = acceptExpression(ast->expression); +void ASTEncoder::visit(NullptrLiteralExpressionAST* ast) { + auto literalLoc = encodeSourceLocation(ast->literalLoc); - io::ExpressionTemplateArgument::Builder builder{fbb_}; - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); + io::NullptrLiteralExpression::Builder builder{fbb_}; + builder.add_literal_loc(literalLoc.o); + builder.add_literal(static_cast(ast->literal)); offset_ = builder.Finish().Union(); - type_ = io::TemplateArgument_ExpressionTemplateArgument; + type_ = io::Expression_NullptrLiteralExpression; } -void ASTEncoder::visit(ParenMemInitializerAST* ast) { - const auto [name, nameType] = acceptName(ast->name); - - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - - std::vector> expressionListOffsets; - std::vector> expressionListTypes; +void ASTEncoder::visit(StringLiteralExpressionAST* ast) { + auto literalLoc = encodeSourceLocation(ast->literalLoc); - for (auto it = ast->expressionList; it; it = it->next) { - if (!it->value) continue; - const auto [offset, type] = acceptExpression(it->value); - expressionListOffsets.push_back(offset); - expressionListTypes.push_back(type); - } + io::StringLiteralExpression::Builder builder{fbb_}; + builder.add_literal_loc(literalLoc.o); - auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); - auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); + offset_ = builder.Finish().Union(); + type_ = io::Expression_StringLiteralExpression; +} - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); +void ASTEncoder::visit(UserDefinedStringLiteralExpressionAST* ast) { + auto literalLoc = encodeSourceLocation(ast->literalLoc); - auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); + flatbuffers::Offset literal; + if (ast->literal) { + if (stringLiterals_.contains(ast->literal)) { + literal = stringLiterals_.at(ast->literal); + } else { + literal = fbb_.CreateString(ast->literal->value()); + stringLiterals_.emplace(ast->literal, literal); + } + } - io::ParenMemInitializer::Builder builder{fbb_}; - builder.add_name(name); - builder.add_name_type(static_cast(nameType)); - builder.add_lparen_loc(lparenLoc.o); - builder.add_expression_list(expressionListOffsetsVector); - builder.add_expression_list_type(expressionListTypesVector); - builder.add_rparen_loc(rparenLoc.o); - builder.add_ellipsis_loc(ellipsisLoc.o); + io::UserDefinedStringLiteralExpression::Builder builder{fbb_}; + builder.add_literal_loc(literalLoc.o); + if (ast->literal) { + builder.add_literal(literal); + } offset_ = builder.Finish().Union(); - type_ = io::MemInitializer_ParenMemInitializer; + type_ = io::Expression_UserDefinedStringLiteralExpression; } -void ASTEncoder::visit(BracedMemInitializerAST* ast) { +void ASTEncoder::visit(IdExpressionAST* ast) { const auto [name, nameType] = acceptName(ast->name); - const auto bracedInitList = accept(ast->bracedInitList); - - auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - - io::BracedMemInitializer::Builder builder{fbb_}; + io::IdExpression::Builder builder{fbb_}; builder.add_name(name); builder.add_name_type(static_cast(nameType)); - builder.add_braced_init_list(bracedInitList.o); - builder.add_ellipsis_loc(ellipsisLoc.o); offset_ = builder.Finish().Union(); - type_ = io::MemInitializer_BracedMemInitializer; + type_ = io::Expression_IdExpression; } -void ASTEncoder::visit(ThisLambdaCaptureAST* ast) { - auto thisLoc = encodeSourceLocation(ast->thisLoc); +void ASTEncoder::visit(RequiresExpressionAST* ast) { + auto requiresLoc = encodeSourceLocation(ast->requiresLoc); - io::ThisLambdaCapture::Builder builder{fbb_}; - builder.add_this_loc(thisLoc.o); + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - offset_ = builder.Finish().Union(); - type_ = io::LambdaCapture_ThisLambdaCapture; -} + const auto parameterDeclarationClause = + accept(ast->parameterDeclarationClause); -void ASTEncoder::visit(DerefThisLambdaCaptureAST* ast) { - auto starLoc = encodeSourceLocation(ast->starLoc); + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - auto thisLoc = encodeSourceLocation(ast->thisLoc); + const auto requirementBody = accept(ast->requirementBody); - io::DerefThisLambdaCapture::Builder builder{fbb_}; - builder.add_star_loc(starLoc.o); - builder.add_this_loc(thisLoc.o); + io::RequiresExpression::Builder builder{fbb_}; + builder.add_requires_loc(requiresLoc.o); + builder.add_lparen_loc(lparenLoc.o); + builder.add_parameter_declaration_clause(parameterDeclarationClause.o); + builder.add_rparen_loc(rparenLoc.o); + builder.add_requirement_body(requirementBody.o); offset_ = builder.Finish().Union(); - type_ = io::LambdaCapture_DerefThisLambdaCapture; + type_ = io::Expression_RequiresExpression; } -void ASTEncoder::visit(SimpleLambdaCaptureAST* ast) { - auto identifierLoc = encodeSourceLocation(ast->identifierLoc); +void ASTEncoder::visit(NestedExpressionAST* ast) { + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + + const auto [expression, expressionType] = acceptExpression(ast->expression); + + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + + io::NestedExpression::Builder builder{fbb_}; + builder.add_lparen_loc(lparenLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + builder.add_rparen_loc(rparenLoc.o); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_NestedExpression; +} + +void ASTEncoder::visit(RightFoldExpressionAST* ast) { + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + + const auto [expression, expressionType] = acceptExpression(ast->expression); + + auto opLoc = encodeSourceLocation(ast->opLoc); auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - flatbuffers::Offset identifier; - if (ast->identifier) { - if (identifiers_.contains(ast->identifier)) { - identifier = identifiers_.at(ast->identifier); - } else { - identifier = fbb_.CreateString(ast->identifier->value()); - identifiers_.emplace(ast->identifier, identifier); - } - } + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - io::SimpleLambdaCapture::Builder builder{fbb_}; - builder.add_identifier_loc(identifierLoc.o); + io::RightFoldExpression::Builder builder{fbb_}; + builder.add_lparen_loc(lparenLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + builder.add_op_loc(opLoc.o); builder.add_ellipsis_loc(ellipsisLoc.o); - if (ast->identifier) { - builder.add_identifier(identifier); - } + builder.add_rparen_loc(rparenLoc.o); + builder.add_op(static_cast(ast->op)); offset_ = builder.Finish().Union(); - type_ = io::LambdaCapture_SimpleLambdaCapture; + type_ = io::Expression_RightFoldExpression; } -void ASTEncoder::visit(RefLambdaCaptureAST* ast) { - auto ampLoc = encodeSourceLocation(ast->ampLoc); - - auto identifierLoc = encodeSourceLocation(ast->identifierLoc); +void ASTEncoder::visit(LeftFoldExpressionAST* ast) { + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - flatbuffers::Offset identifier; - if (ast->identifier) { - if (identifiers_.contains(ast->identifier)) { - identifier = identifiers_.at(ast->identifier); - } else { - identifier = fbb_.CreateString(ast->identifier->value()); - identifiers_.emplace(ast->identifier, identifier); - } - } + auto opLoc = encodeSourceLocation(ast->opLoc); - io::RefLambdaCapture::Builder builder{fbb_}; - builder.add_amp_loc(ampLoc.o); - builder.add_identifier_loc(identifierLoc.o); + const auto [expression, expressionType] = acceptExpression(ast->expression); + + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + + io::LeftFoldExpression::Builder builder{fbb_}; + builder.add_lparen_loc(lparenLoc.o); builder.add_ellipsis_loc(ellipsisLoc.o); - if (ast->identifier) { - builder.add_identifier(identifier); - } + builder.add_op_loc(opLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + builder.add_rparen_loc(rparenLoc.o); + builder.add_op(static_cast(ast->op)); offset_ = builder.Finish().Union(); - type_ = io::LambdaCapture_RefLambdaCapture; + type_ = io::Expression_LeftFoldExpression; } -void ASTEncoder::visit(RefInitLambdaCaptureAST* ast) { - auto ampLoc = encodeSourceLocation(ast->ampLoc); +void ASTEncoder::visit(FoldExpressionAST* ast) { + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + + const auto [leftExpression, leftExpressionType] = + acceptExpression(ast->leftExpression); + + auto opLoc = encodeSourceLocation(ast->opLoc); auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - auto identifierLoc = encodeSourceLocation(ast->identifierLoc); + auto foldOpLoc = encodeSourceLocation(ast->foldOpLoc); - const auto [initializer, initializerType] = - acceptInitializer(ast->initializer); + const auto [rightExpression, rightExpressionType] = + acceptExpression(ast->rightExpression); - flatbuffers::Offset identifier; - if (ast->identifier) { - if (identifiers_.contains(ast->identifier)) { - identifier = identifiers_.at(ast->identifier); - } else { - identifier = fbb_.CreateString(ast->identifier->value()); - identifiers_.emplace(ast->identifier, identifier); - } - } + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - io::RefInitLambdaCapture::Builder builder{fbb_}; - builder.add_amp_loc(ampLoc.o); + io::FoldExpression::Builder builder{fbb_}; + builder.add_lparen_loc(lparenLoc.o); + builder.add_left_expression(leftExpression); + builder.add_left_expression_type( + static_cast(leftExpressionType)); + builder.add_op_loc(opLoc.o); builder.add_ellipsis_loc(ellipsisLoc.o); - builder.add_identifier_loc(identifierLoc.o); - builder.add_initializer(initializer); - builder.add_initializer_type(static_cast(initializerType)); - if (ast->identifier) { - builder.add_identifier(identifier); + builder.add_fold_op_loc(foldOpLoc.o); + builder.add_right_expression(rightExpression); + builder.add_right_expression_type( + static_cast(rightExpressionType)); + builder.add_rparen_loc(rparenLoc.o); + builder.add_op(static_cast(ast->op)); + builder.add_fold_op(static_cast(ast->foldOp)); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_FoldExpression; +} + +void ASTEncoder::visit(LambdaExpressionAST* ast) { + const auto lambdaIntroducer = accept(ast->lambdaIntroducer); + + auto lessLoc = encodeSourceLocation(ast->lessLoc); + + std::vector> templateParameterListOffsets; + std::vector> + templateParameterListTypes; + + for (auto it = ast->templateParameterList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptDeclaration(it->value); + templateParameterListOffsets.push_back(offset); + templateParameterListTypes.push_back(type); } + auto templateParameterListOffsetsVector = + fbb_.CreateVector(templateParameterListOffsets); + auto templateParameterListTypesVector = + fbb_.CreateVector(templateParameterListTypes); + + auto greaterLoc = encodeSourceLocation(ast->greaterLoc); + + const auto requiresClause = accept(ast->requiresClause); + + const auto lambdaDeclarator = accept(ast->lambdaDeclarator); + + const auto statement = accept(ast->statement); + + io::LambdaExpression::Builder builder{fbb_}; + builder.add_lambda_introducer(lambdaIntroducer.o); + builder.add_less_loc(lessLoc.o); + builder.add_template_parameter_list(templateParameterListOffsetsVector); + builder.add_template_parameter_list_type(templateParameterListTypesVector); + builder.add_greater_loc(greaterLoc.o); + builder.add_requires_clause(requiresClause.o); + builder.add_lambda_declarator(lambdaDeclarator.o); + builder.add_statement(statement.o); + offset_ = builder.Finish().Union(); - type_ = io::LambdaCapture_RefInitLambdaCapture; + type_ = io::Expression_LambdaExpression; } -void ASTEncoder::visit(InitLambdaCaptureAST* ast) { +void ASTEncoder::visit(SizeofExpressionAST* ast) { + auto sizeofLoc = encodeSourceLocation(ast->sizeofLoc); + + const auto [expression, expressionType] = acceptExpression(ast->expression); + + io::SizeofExpression::Builder builder{fbb_}; + builder.add_sizeof_loc(sizeofLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_SizeofExpression; +} + +void ASTEncoder::visit(SizeofTypeExpressionAST* ast) { + auto sizeofLoc = encodeSourceLocation(ast->sizeofLoc); + + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + + const auto typeId = accept(ast->typeId); + + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + + io::SizeofTypeExpression::Builder builder{fbb_}; + builder.add_sizeof_loc(sizeofLoc.o); + builder.add_lparen_loc(lparenLoc.o); + builder.add_type_id(typeId.o); + builder.add_rparen_loc(rparenLoc.o); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_SizeofTypeExpression; +} + +void ASTEncoder::visit(SizeofPackExpressionAST* ast) { + auto sizeofLoc = encodeSourceLocation(ast->sizeofLoc); + auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); - const auto [initializer, initializerType] = - acceptInitializer(ast->initializer); + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); flatbuffers::Offset identifier; if (ast->identifier) { @@ -1367,65 +1489,185 @@ void ASTEncoder::visit(InitLambdaCaptureAST* ast) { } } - io::InitLambdaCapture::Builder builder{fbb_}; + io::SizeofPackExpression::Builder builder{fbb_}; + builder.add_sizeof_loc(sizeofLoc.o); builder.add_ellipsis_loc(ellipsisLoc.o); + builder.add_lparen_loc(lparenLoc.o); builder.add_identifier_loc(identifierLoc.o); - builder.add_initializer(initializer); - builder.add_initializer_type(static_cast(initializerType)); + builder.add_rparen_loc(rparenLoc.o); if (ast->identifier) { builder.add_identifier(identifier); } offset_ = builder.Finish().Union(); - type_ = io::LambdaCapture_InitLambdaCapture; + type_ = io::Expression_SizeofPackExpression; } -void ASTEncoder::visit(EqualInitializerAST* ast) { - auto equalLoc = encodeSourceLocation(ast->equalLoc); +void ASTEncoder::visit(TypeidExpressionAST* ast) { + auto typeidLoc = encodeSourceLocation(ast->typeidLoc); + + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); const auto [expression, expressionType] = acceptExpression(ast->expression); - io::EqualInitializer::Builder builder{fbb_}; - builder.add_equal_loc(equalLoc.o); + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + + io::TypeidExpression::Builder builder{fbb_}; + builder.add_typeid_loc(typeidLoc.o); + builder.add_lparen_loc(lparenLoc.o); builder.add_expression(expression); builder.add_expression_type(static_cast(expressionType)); + builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Initializer_EqualInitializer; + type_ = io::Expression_TypeidExpression; } -void ASTEncoder::visit(BracedInitListAST* ast) { - auto lbraceLoc = encodeSourceLocation(ast->lbraceLoc); +void ASTEncoder::visit(TypeidOfTypeExpressionAST* ast) { + auto typeidLoc = encodeSourceLocation(ast->typeidLoc); - std::vector> expressionListOffsets; - std::vector> expressionListTypes; + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - for (auto it = ast->expressionList; it; it = it->next) { + const auto typeId = accept(ast->typeId); + + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + + io::TypeidOfTypeExpression::Builder builder{fbb_}; + builder.add_typeid_loc(typeidLoc.o); + builder.add_lparen_loc(lparenLoc.o); + builder.add_type_id(typeId.o); + builder.add_rparen_loc(rparenLoc.o); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_TypeidOfTypeExpression; +} + +void ASTEncoder::visit(AlignofExpressionAST* ast) { + auto alignofLoc = encodeSourceLocation(ast->alignofLoc); + + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + + const auto typeId = accept(ast->typeId); + + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + + io::AlignofExpression::Builder builder{fbb_}; + builder.add_alignof_loc(alignofLoc.o); + builder.add_lparen_loc(lparenLoc.o); + builder.add_type_id(typeId.o); + builder.add_rparen_loc(rparenLoc.o); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_AlignofExpression; +} + +void ASTEncoder::visit(TypeTraitsExpressionAST* ast) { + auto typeTraitsLoc = encodeSourceLocation(ast->typeTraitsLoc); + + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + + std::vector> typeIdListOffsets; + for (auto it = ast->typeIdList; it; it = it->next) { if (!it->value) continue; - const auto [offset, type] = acceptExpression(it->value); - expressionListOffsets.push_back(offset); - expressionListTypes.push_back(type); + typeIdListOffsets.emplace_back(accept(it->value).o); } - auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); - auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); + auto typeIdListOffsetsVector = fbb_.CreateVector(typeIdListOffsets); - auto commaLoc = encodeSourceLocation(ast->commaLoc); + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - auto rbraceLoc = encodeSourceLocation(ast->rbraceLoc); + io::TypeTraitsExpression::Builder builder{fbb_}; + builder.add_type_traits_loc(typeTraitsLoc.o); + builder.add_lparen_loc(lparenLoc.o); + builder.add_type_id_list(typeIdListOffsetsVector); + builder.add_rparen_loc(rparenLoc.o); + builder.add_type_traits(static_cast(ast->typeTraits)); - io::BracedInitList::Builder builder{fbb_}; - builder.add_lbrace_loc(lbraceLoc.o); - builder.add_expression_list(expressionListOffsetsVector); - builder.add_expression_list_type(expressionListTypesVector); - builder.add_comma_loc(commaLoc.o); - builder.add_rbrace_loc(rbraceLoc.o); + offset_ = builder.Finish().Union(); + type_ = io::Expression_TypeTraitsExpression; +} + +void ASTEncoder::visit(UnaryExpressionAST* ast) { + auto opLoc = encodeSourceLocation(ast->opLoc); + + const auto [expression, expressionType] = acceptExpression(ast->expression); + + io::UnaryExpression::Builder builder{fbb_}; + builder.add_op_loc(opLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + builder.add_op(static_cast(ast->op)); offset_ = builder.Finish().Union(); - type_ = io::Initializer_BracedInitList; + type_ = io::Expression_UnaryExpression; } -void ASTEncoder::visit(ParenInitializerAST* ast) { +void ASTEncoder::visit(BinaryExpressionAST* ast) { + const auto [leftExpression, leftExpressionType] = + acceptExpression(ast->leftExpression); + + auto opLoc = encodeSourceLocation(ast->opLoc); + + const auto [rightExpression, rightExpressionType] = + acceptExpression(ast->rightExpression); + + io::BinaryExpression::Builder builder{fbb_}; + builder.add_left_expression(leftExpression); + builder.add_left_expression_type( + static_cast(leftExpressionType)); + builder.add_op_loc(opLoc.o); + builder.add_right_expression(rightExpression); + builder.add_right_expression_type( + static_cast(rightExpressionType)); + builder.add_op(static_cast(ast->op)); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_BinaryExpression; +} + +void ASTEncoder::visit(AssignmentExpressionAST* ast) { + const auto [leftExpression, leftExpressionType] = + acceptExpression(ast->leftExpression); + + auto opLoc = encodeSourceLocation(ast->opLoc); + + const auto [rightExpression, rightExpressionType] = + acceptExpression(ast->rightExpression); + + io::AssignmentExpression::Builder builder{fbb_}; + builder.add_left_expression(leftExpression); + builder.add_left_expression_type( + static_cast(leftExpressionType)); + builder.add_op_loc(opLoc.o); + builder.add_right_expression(rightExpression); + builder.add_right_expression_type( + static_cast(rightExpressionType)); + builder.add_op(static_cast(ast->op)); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_AssignmentExpression; +} + +void ASTEncoder::visit(BracedTypeConstructionAST* ast) { + const auto [typeSpecifier, typeSpecifierType] = + acceptSpecifier(ast->typeSpecifier); + + const auto bracedInitList = accept(ast->bracedInitList); + + io::BracedTypeConstruction::Builder builder{fbb_}; + builder.add_type_specifier(typeSpecifier); + builder.add_type_specifier_type( + static_cast(typeSpecifierType)); + builder.add_braced_init_list(bracedInitList.o); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_BracedTypeConstruction; +} + +void ASTEncoder::visit(TypeConstructionAST* ast) { + const auto [typeSpecifier, typeSpecifierType] = + acceptSpecifier(ast->typeSpecifier); + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); std::vector> expressionListOffsets; @@ -1443,17 +1685,23 @@ void ASTEncoder::visit(ParenInitializerAST* ast) { auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - io::ParenInitializer::Builder builder{fbb_}; + io::TypeConstruction::Builder builder{fbb_}; + builder.add_type_specifier(typeSpecifier); + builder.add_type_specifier_type( + static_cast(typeSpecifierType)); builder.add_lparen_loc(lparenLoc.o); builder.add_expression_list(expressionListOffsetsVector); builder.add_expression_list_type(expressionListTypesVector); builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Initializer_ParenInitializer; + type_ = io::Expression_TypeConstruction; } -void ASTEncoder::visit(NewParenInitializerAST* ast) { +void ASTEncoder::visit(CallExpressionAST* ast) { + const auto [baseExpression, baseExpressionType] = + acceptExpression(ast->baseExpression); + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); std::vector> expressionListOffsets; @@ -1471,746 +1719,565 @@ void ASTEncoder::visit(NewParenInitializerAST* ast) { auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - io::NewParenInitializer::Builder builder{fbb_}; + io::CallExpression::Builder builder{fbb_}; + builder.add_base_expression(baseExpression); + builder.add_base_expression_type( + static_cast(baseExpressionType)); builder.add_lparen_loc(lparenLoc.o); builder.add_expression_list(expressionListOffsetsVector); builder.add_expression_list_type(expressionListTypesVector); builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); - type_ = io::NewInitializer_NewParenInitializer; + type_ = io::Expression_CallExpression; } -void ASTEncoder::visit(NewBracedInitializerAST* ast) { - const auto bracedInit = accept(ast->bracedInit); +void ASTEncoder::visit(SubscriptExpressionAST* ast) { + const auto [baseExpression, baseExpressionType] = + acceptExpression(ast->baseExpression); - io::NewBracedInitializer::Builder builder{fbb_}; - builder.add_braced_init(bracedInit.o); + auto lbracketLoc = encodeSourceLocation(ast->lbracketLoc); - offset_ = builder.Finish().Union(); - type_ = io::NewInitializer_NewBracedInitializer; -} + const auto [indexExpression, indexExpressionType] = + acceptExpression(ast->indexExpression); -void ASTEncoder::visit(EllipsisExceptionDeclarationAST* ast) { - auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); + auto rbracketLoc = encodeSourceLocation(ast->rbracketLoc); - io::EllipsisExceptionDeclaration::Builder builder{fbb_}; - builder.add_ellipsis_loc(ellipsisLoc.o); + io::SubscriptExpression::Builder builder{fbb_}; + builder.add_base_expression(baseExpression); + builder.add_base_expression_type( + static_cast(baseExpressionType)); + builder.add_lbracket_loc(lbracketLoc.o); + builder.add_index_expression(indexExpression); + builder.add_index_expression_type( + static_cast(indexExpressionType)); + builder.add_rbracket_loc(rbracketLoc.o); offset_ = builder.Finish().Union(); - type_ = io::ExceptionDeclaration_EllipsisExceptionDeclaration; + type_ = io::Expression_SubscriptExpression; } -void ASTEncoder::visit(TypeExceptionDeclarationAST* ast) { - std::vector> attributeListOffsets; - std::vector> - attributeListTypes; +void ASTEncoder::visit(MemberExpressionAST* ast) { + const auto [baseExpression, baseExpressionType] = + acceptExpression(ast->baseExpression); - for (auto it = ast->attributeList; it; it = it->next) { - if (!it->value) continue; - const auto [offset, type] = acceptAttributeSpecifier(it->value); - attributeListOffsets.push_back(offset); - attributeListTypes.push_back(type); - } + auto accessLoc = encodeSourceLocation(ast->accessLoc); - auto attributeListOffsetsVector = fbb_.CreateVector(attributeListOffsets); - auto attributeListTypesVector = fbb_.CreateVector(attributeListTypes); + auto templateLoc = encodeSourceLocation(ast->templateLoc); - std::vector> typeSpecifierListOffsets; - std::vector> typeSpecifierListTypes; + const auto [name, nameType] = acceptName(ast->name); - for (auto it = ast->typeSpecifierList; it; it = it->next) { - if (!it->value) continue; - const auto [offset, type] = acceptSpecifier(it->value); - typeSpecifierListOffsets.push_back(offset); - typeSpecifierListTypes.push_back(type); - } + io::MemberExpression::Builder builder{fbb_}; + builder.add_base_expression(baseExpression); + builder.add_base_expression_type( + static_cast(baseExpressionType)); + builder.add_access_loc(accessLoc.o); + builder.add_template_loc(templateLoc.o); + builder.add_name(name); + builder.add_name_type(static_cast(nameType)); + builder.add_access_op(static_cast(ast->accessOp)); - auto typeSpecifierListOffsetsVector = - fbb_.CreateVector(typeSpecifierListOffsets); - auto typeSpecifierListTypesVector = fbb_.CreateVector(typeSpecifierListTypes); + offset_ = builder.Finish().Union(); + type_ = io::Expression_MemberExpression; +} - const auto declarator = accept(ast->declarator); +void ASTEncoder::visit(PostIncrExpressionAST* ast) { + const auto [baseExpression, baseExpressionType] = + acceptExpression(ast->baseExpression); - io::TypeExceptionDeclaration::Builder builder{fbb_}; - builder.add_attribute_list(attributeListOffsetsVector); - builder.add_attribute_list_type(attributeListTypesVector); - builder.add_type_specifier_list(typeSpecifierListOffsetsVector); - builder.add_type_specifier_list_type(typeSpecifierListTypesVector); - builder.add_declarator(declarator.o); + auto opLoc = encodeSourceLocation(ast->opLoc); + + io::PostIncrExpression::Builder builder{fbb_}; + builder.add_base_expression(baseExpression); + builder.add_base_expression_type( + static_cast(baseExpressionType)); + builder.add_op_loc(opLoc.o); + builder.add_op(static_cast(ast->op)); offset_ = builder.Finish().Union(); - type_ = io::ExceptionDeclaration_TypeExceptionDeclaration; + type_ = io::Expression_PostIncrExpression; } -void ASTEncoder::visit(DefaultFunctionBodyAST* ast) { - auto equalLoc = encodeSourceLocation(ast->equalLoc); - - auto defaultLoc = encodeSourceLocation(ast->defaultLoc); - - auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); - - io::DefaultFunctionBody::Builder builder{fbb_}; - builder.add_equal_loc(equalLoc.o); - builder.add_default_loc(defaultLoc.o); - builder.add_semicolon_loc(semicolonLoc.o); - - offset_ = builder.Finish().Union(); - type_ = io::FunctionBody_DefaultFunctionBody; -} - -void ASTEncoder::visit(CompoundStatementFunctionBodyAST* ast) { - const auto ctorInitializer = accept(ast->ctorInitializer); - - const auto statement = accept(ast->statement); - - io::CompoundStatementFunctionBody::Builder builder{fbb_}; - builder.add_ctor_initializer(ctorInitializer.o); - builder.add_statement(statement.o); - - offset_ = builder.Finish().Union(); - type_ = io::FunctionBody_CompoundStatementFunctionBody; -} - -void ASTEncoder::visit(TryStatementFunctionBodyAST* ast) { - auto tryLoc = encodeSourceLocation(ast->tryLoc); - - const auto ctorInitializer = accept(ast->ctorInitializer); - - const auto statement = accept(ast->statement); - - std::vector> handlerListOffsets; - for (auto it = ast->handlerList; it; it = it->next) { - if (!it->value) continue; - handlerListOffsets.emplace_back(accept(it->value).o); - } - - auto handlerListOffsetsVector = fbb_.CreateVector(handlerListOffsets); - - io::TryStatementFunctionBody::Builder builder{fbb_}; - builder.add_try_loc(tryLoc.o); - builder.add_ctor_initializer(ctorInitializer.o); - builder.add_statement(statement.o); - builder.add_handler_list(handlerListOffsetsVector); - - offset_ = builder.Finish().Union(); - type_ = io::FunctionBody_TryStatementFunctionBody; -} - -void ASTEncoder::visit(DeleteFunctionBodyAST* ast) { - auto equalLoc = encodeSourceLocation(ast->equalLoc); - - auto deleteLoc = encodeSourceLocation(ast->deleteLoc); - - auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); - - io::DeleteFunctionBody::Builder builder{fbb_}; - builder.add_equal_loc(equalLoc.o); - builder.add_delete_loc(deleteLoc.o); - builder.add_semicolon_loc(semicolonLoc.o); - - offset_ = builder.Finish().Union(); - type_ = io::FunctionBody_DeleteFunctionBody; -} - -void ASTEncoder::visit(TranslationUnitAST* ast) { - std::vector> declarationListOffsets; - std::vector> declarationListTypes; - - for (auto it = ast->declarationList; it; it = it->next) { - if (!it->value) continue; - const auto [offset, type] = acceptDeclaration(it->value); - declarationListOffsets.push_back(offset); - declarationListTypes.push_back(type); - } - - auto declarationListOffsetsVector = fbb_.CreateVector(declarationListOffsets); - auto declarationListTypesVector = fbb_.CreateVector(declarationListTypes); - - io::TranslationUnit::Builder builder{fbb_}; - builder.add_declaration_list(declarationListOffsetsVector); - builder.add_declaration_list_type(declarationListTypesVector); - - offset_ = builder.Finish().Union(); - type_ = io::Unit_TranslationUnit; -} - -void ASTEncoder::visit(ModuleUnitAST* ast) { - const auto globalModuleFragment = accept(ast->globalModuleFragment); - - const auto moduleDeclaration = accept(ast->moduleDeclaration); - - std::vector> declarationListOffsets; - std::vector> declarationListTypes; - - for (auto it = ast->declarationList; it; it = it->next) { - if (!it->value) continue; - const auto [offset, type] = acceptDeclaration(it->value); - declarationListOffsets.push_back(offset); - declarationListTypes.push_back(type); - } - - auto declarationListOffsetsVector = fbb_.CreateVector(declarationListOffsets); - auto declarationListTypesVector = fbb_.CreateVector(declarationListTypes); +void ASTEncoder::visit(ConditionalExpressionAST* ast) { + const auto [condition, conditionType] = acceptExpression(ast->condition); - const auto privateModuleFragment = accept(ast->privateModuleFragment); + auto questionLoc = encodeSourceLocation(ast->questionLoc); - io::ModuleUnit::Builder builder{fbb_}; - builder.add_global_module_fragment(globalModuleFragment.o); - builder.add_module_declaration(moduleDeclaration.o); - builder.add_declaration_list(declarationListOffsetsVector); - builder.add_declaration_list_type(declarationListTypesVector); - builder.add_private_module_fragment(privateModuleFragment.o); + const auto [iftrueExpression, iftrueExpressionType] = + acceptExpression(ast->iftrueExpression); - offset_ = builder.Finish().Union(); - type_ = io::Unit_ModuleUnit; -} + auto colonLoc = encodeSourceLocation(ast->colonLoc); -void ASTEncoder::visit(ThisExpressionAST* ast) { - auto thisLoc = encodeSourceLocation(ast->thisLoc); + const auto [iffalseExpression, iffalseExpressionType] = + acceptExpression(ast->iffalseExpression); - io::ThisExpression::Builder builder{fbb_}; - builder.add_this_loc(thisLoc.o); + io::ConditionalExpression::Builder builder{fbb_}; + builder.add_condition(condition); + builder.add_condition_type(static_cast(conditionType)); + builder.add_question_loc(questionLoc.o); + builder.add_iftrue_expression(iftrueExpression); + builder.add_iftrue_expression_type( + static_cast(iftrueExpressionType)); + builder.add_colon_loc(colonLoc.o); + builder.add_iffalse_expression(iffalseExpression); + builder.add_iffalse_expression_type( + static_cast(iffalseExpressionType)); offset_ = builder.Finish().Union(); - type_ = io::Expression_ThisExpression; + type_ = io::Expression_ConditionalExpression; } -void ASTEncoder::visit(CharLiteralExpressionAST* ast) { - auto literalLoc = encodeSourceLocation(ast->literalLoc); - - flatbuffers::Offset literal; - if (ast->literal) { - if (charLiterals_.contains(ast->literal)) { - literal = charLiterals_.at(ast->literal); - } else { - literal = fbb_.CreateString(ast->literal->value()); - charLiterals_.emplace(ast->literal, literal); - } - } +void ASTEncoder::visit(ImplicitCastExpressionAST* ast) { + const auto [expression, expressionType] = acceptExpression(ast->expression); - io::CharLiteralExpression::Builder builder{fbb_}; - builder.add_literal_loc(literalLoc.o); - if (ast->literal) { - builder.add_literal(literal); - } + io::ImplicitCastExpression::Builder builder{fbb_}; + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); offset_ = builder.Finish().Union(); - type_ = io::Expression_CharLiteralExpression; + type_ = io::Expression_ImplicitCastExpression; } -void ASTEncoder::visit(BoolLiteralExpressionAST* ast) { - auto literalLoc = encodeSourceLocation(ast->literalLoc); - - io::BoolLiteralExpression::Builder builder{fbb_}; - builder.add_literal_loc(literalLoc.o); +void ASTEncoder::visit(CastExpressionAST* ast) { + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - offset_ = builder.Finish().Union(); - type_ = io::Expression_BoolLiteralExpression; -} + const auto typeId = accept(ast->typeId); -void ASTEncoder::visit(IntLiteralExpressionAST* ast) { - auto literalLoc = encodeSourceLocation(ast->literalLoc); + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - flatbuffers::Offset literal; - if (ast->literal) { - if (integerLiterals_.contains(ast->literal)) { - literal = integerLiterals_.at(ast->literal); - } else { - literal = fbb_.CreateString(ast->literal->value()); - integerLiterals_.emplace(ast->literal, literal); - } - } + const auto [expression, expressionType] = acceptExpression(ast->expression); - io::IntLiteralExpression::Builder builder{fbb_}; - builder.add_literal_loc(literalLoc.o); - if (ast->literal) { - builder.add_literal(literal); - } + io::CastExpression::Builder builder{fbb_}; + builder.add_lparen_loc(lparenLoc.o); + builder.add_type_id(typeId.o); + builder.add_rparen_loc(rparenLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); offset_ = builder.Finish().Union(); - type_ = io::Expression_IntLiteralExpression; + type_ = io::Expression_CastExpression; } -void ASTEncoder::visit(FloatLiteralExpressionAST* ast) { - auto literalLoc = encodeSourceLocation(ast->literalLoc); - - flatbuffers::Offset literal; - if (ast->literal) { - if (floatLiterals_.contains(ast->literal)) { - literal = floatLiterals_.at(ast->literal); - } else { - literal = fbb_.CreateString(ast->literal->value()); - floatLiterals_.emplace(ast->literal, literal); - } - } +void ASTEncoder::visit(CppCastExpressionAST* ast) { + auto castLoc = encodeSourceLocation(ast->castLoc); - io::FloatLiteralExpression::Builder builder{fbb_}; - builder.add_literal_loc(literalLoc.o); - if (ast->literal) { - builder.add_literal(literal); - } + auto lessLoc = encodeSourceLocation(ast->lessLoc); - offset_ = builder.Finish().Union(); - type_ = io::Expression_FloatLiteralExpression; -} + const auto typeId = accept(ast->typeId); -void ASTEncoder::visit(NullptrLiteralExpressionAST* ast) { - auto literalLoc = encodeSourceLocation(ast->literalLoc); + auto greaterLoc = encodeSourceLocation(ast->greaterLoc); - io::NullptrLiteralExpression::Builder builder{fbb_}; - builder.add_literal_loc(literalLoc.o); - builder.add_literal(static_cast(ast->literal)); + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - offset_ = builder.Finish().Union(); - type_ = io::Expression_NullptrLiteralExpression; -} + const auto [expression, expressionType] = acceptExpression(ast->expression); -void ASTEncoder::visit(StringLiteralExpressionAST* ast) { - auto literalLoc = encodeSourceLocation(ast->literalLoc); + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - io::StringLiteralExpression::Builder builder{fbb_}; - builder.add_literal_loc(literalLoc.o); + io::CppCastExpression::Builder builder{fbb_}; + builder.add_cast_loc(castLoc.o); + builder.add_less_loc(lessLoc.o); + builder.add_type_id(typeId.o); + builder.add_greater_loc(greaterLoc.o); + builder.add_lparen_loc(lparenLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_StringLiteralExpression; + type_ = io::Expression_CppCastExpression; } -void ASTEncoder::visit(UserDefinedStringLiteralExpressionAST* ast) { - auto literalLoc = encodeSourceLocation(ast->literalLoc); - - flatbuffers::Offset literal; - if (ast->literal) { - if (stringLiterals_.contains(ast->literal)) { - literal = stringLiterals_.at(ast->literal); - } else { - literal = fbb_.CreateString(ast->literal->value()); - stringLiterals_.emplace(ast->literal, literal); - } - } +void ASTEncoder::visit(NewExpressionAST* ast) { + auto scopeLoc = encodeSourceLocation(ast->scopeLoc); - io::UserDefinedStringLiteralExpression::Builder builder{fbb_}; - builder.add_literal_loc(literalLoc.o); - if (ast->literal) { - builder.add_literal(literal); - } + auto newLoc = encodeSourceLocation(ast->newLoc); - offset_ = builder.Finish().Union(); - type_ = io::Expression_UserDefinedStringLiteralExpression; -} + const auto typeId = accept(ast->typeId); -void ASTEncoder::visit(IdExpressionAST* ast) { - const auto [name, nameType] = acceptName(ast->name); + const auto [newInitalizer, newInitalizerType] = + acceptNewInitializer(ast->newInitalizer); - io::IdExpression::Builder builder{fbb_}; - builder.add_name(name); - builder.add_name_type(static_cast(nameType)); + io::NewExpression::Builder builder{fbb_}; + builder.add_scope_loc(scopeLoc.o); + builder.add_new_loc(newLoc.o); + builder.add_type_id(typeId.o); + builder.add_new_initalizer(newInitalizer); + builder.add_new_initalizer_type( + static_cast(newInitalizerType)); offset_ = builder.Finish().Union(); - type_ = io::Expression_IdExpression; + type_ = io::Expression_NewExpression; } -void ASTEncoder::visit(RequiresExpressionAST* ast) { - auto requiresLoc = encodeSourceLocation(ast->requiresLoc); +void ASTEncoder::visit(DeleteExpressionAST* ast) { + auto scopeLoc = encodeSourceLocation(ast->scopeLoc); - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + auto deleteLoc = encodeSourceLocation(ast->deleteLoc); - const auto parameterDeclarationClause = - accept(ast->parameterDeclarationClause); + auto lbracketLoc = encodeSourceLocation(ast->lbracketLoc); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + auto rbracketLoc = encodeSourceLocation(ast->rbracketLoc); - const auto requirementBody = accept(ast->requirementBody); + const auto [expression, expressionType] = acceptExpression(ast->expression); - io::RequiresExpression::Builder builder{fbb_}; - builder.add_requires_loc(requiresLoc.o); - builder.add_lparen_loc(lparenLoc.o); - builder.add_parameter_declaration_clause(parameterDeclarationClause.o); - builder.add_rparen_loc(rparenLoc.o); - builder.add_requirement_body(requirementBody.o); + io::DeleteExpression::Builder builder{fbb_}; + builder.add_scope_loc(scopeLoc.o); + builder.add_delete_loc(deleteLoc.o); + builder.add_lbracket_loc(lbracketLoc.o); + builder.add_rbracket_loc(rbracketLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); offset_ = builder.Finish().Union(); - type_ = io::Expression_RequiresExpression; + type_ = io::Expression_DeleteExpression; } -void ASTEncoder::visit(NestedExpressionAST* ast) { - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); +void ASTEncoder::visit(ThrowExpressionAST* ast) { + auto throwLoc = encodeSourceLocation(ast->throwLoc); const auto [expression, expressionType] = acceptExpression(ast->expression); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - - io::NestedExpression::Builder builder{fbb_}; - builder.add_lparen_loc(lparenLoc.o); + io::ThrowExpression::Builder builder{fbb_}; + builder.add_throw_loc(throwLoc.o); builder.add_expression(expression); builder.add_expression_type(static_cast(expressionType)); - builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_NestedExpression; + type_ = io::Expression_ThrowExpression; } -void ASTEncoder::visit(RightFoldExpressionAST* ast) { +void ASTEncoder::visit(NoexceptExpressionAST* ast) { + auto noexceptLoc = encodeSourceLocation(ast->noexceptLoc); + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); const auto [expression, expressionType] = acceptExpression(ast->expression); - auto opLoc = encodeSourceLocation(ast->opLoc); - - auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - io::RightFoldExpression::Builder builder{fbb_}; + io::NoexceptExpression::Builder builder{fbb_}; + builder.add_noexcept_loc(noexceptLoc.o); builder.add_lparen_loc(lparenLoc.o); builder.add_expression(expression); builder.add_expression_type(static_cast(expressionType)); - builder.add_op_loc(opLoc.o); - builder.add_ellipsis_loc(ellipsisLoc.o); builder.add_rparen_loc(rparenLoc.o); - builder.add_op(static_cast(ast->op)); offset_ = builder.Finish().Union(); - type_ = io::Expression_RightFoldExpression; + type_ = io::Expression_NoexceptExpression; } -void ASTEncoder::visit(LeftFoldExpressionAST* ast) { - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - - auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - - auto opLoc = encodeSourceLocation(ast->opLoc); - +void ASTEncoder::visit(SimpleRequirementAST* ast) { const auto [expression, expressionType] = acceptExpression(ast->expression); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); - io::LeftFoldExpression::Builder builder{fbb_}; - builder.add_lparen_loc(lparenLoc.o); - builder.add_ellipsis_loc(ellipsisLoc.o); - builder.add_op_loc(opLoc.o); + io::SimpleRequirement::Builder builder{fbb_}; builder.add_expression(expression); builder.add_expression_type(static_cast(expressionType)); - builder.add_rparen_loc(rparenLoc.o); - builder.add_op(static_cast(ast->op)); + builder.add_semicolon_loc(semicolonLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_LeftFoldExpression; + type_ = io::Requirement_SimpleRequirement; } -void ASTEncoder::visit(FoldExpressionAST* ast) { - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); +void ASTEncoder::visit(CompoundRequirementAST* ast) { + auto lbraceLoc = encodeSourceLocation(ast->lbraceLoc); - const auto [leftExpression, leftExpressionType] = - acceptExpression(ast->leftExpression); + const auto [expression, expressionType] = acceptExpression(ast->expression); - auto opLoc = encodeSourceLocation(ast->opLoc); + auto rbraceLoc = encodeSourceLocation(ast->rbraceLoc); - auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); + auto noexceptLoc = encodeSourceLocation(ast->noexceptLoc); - auto foldOpLoc = encodeSourceLocation(ast->foldOpLoc); + auto minusGreaterLoc = encodeSourceLocation(ast->minusGreaterLoc); - const auto [rightExpression, rightExpressionType] = - acceptExpression(ast->rightExpression); + const auto typeConstraint = accept(ast->typeConstraint); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); - io::FoldExpression::Builder builder{fbb_}; - builder.add_lparen_loc(lparenLoc.o); - builder.add_left_expression(leftExpression); - builder.add_left_expression_type( - static_cast(leftExpressionType)); - builder.add_op_loc(opLoc.o); - builder.add_ellipsis_loc(ellipsisLoc.o); - builder.add_fold_op_loc(foldOpLoc.o); - builder.add_right_expression(rightExpression); - builder.add_right_expression_type( - static_cast(rightExpressionType)); - builder.add_rparen_loc(rparenLoc.o); - builder.add_op(static_cast(ast->op)); - builder.add_fold_op(static_cast(ast->foldOp)); + io::CompoundRequirement::Builder builder{fbb_}; + builder.add_lbrace_loc(lbraceLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + builder.add_rbrace_loc(rbraceLoc.o); + builder.add_noexcept_loc(noexceptLoc.o); + builder.add_minus_greater_loc(minusGreaterLoc.o); + builder.add_type_constraint(typeConstraint.o); + builder.add_semicolon_loc(semicolonLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_FoldExpression; + type_ = io::Requirement_CompoundRequirement; } -void ASTEncoder::visit(LambdaExpressionAST* ast) { - const auto lambdaIntroducer = accept(ast->lambdaIntroducer); - - auto lessLoc = encodeSourceLocation(ast->lessLoc); - - std::vector> templateParameterListOffsets; - std::vector> - templateParameterListTypes; - - for (auto it = ast->templateParameterList; it; it = it->next) { - if (!it->value) continue; - const auto [offset, type] = acceptDeclaration(it->value); - templateParameterListOffsets.push_back(offset); - templateParameterListTypes.push_back(type); - } - - auto templateParameterListOffsetsVector = - fbb_.CreateVector(templateParameterListOffsets); - auto templateParameterListTypesVector = - fbb_.CreateVector(templateParameterListTypes); - - auto greaterLoc = encodeSourceLocation(ast->greaterLoc); +void ASTEncoder::visit(TypeRequirementAST* ast) { + auto typenameLoc = encodeSourceLocation(ast->typenameLoc); - const auto requiresClause = accept(ast->requiresClause); + const auto nestedNameSpecifier = accept(ast->nestedNameSpecifier); - const auto lambdaDeclarator = accept(ast->lambdaDeclarator); + const auto [name, nameType] = acceptName(ast->name); - const auto statement = accept(ast->statement); + auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); - io::LambdaExpression::Builder builder{fbb_}; - builder.add_lambda_introducer(lambdaIntroducer.o); - builder.add_less_loc(lessLoc.o); - builder.add_template_parameter_list(templateParameterListOffsetsVector); - builder.add_template_parameter_list_type(templateParameterListTypesVector); - builder.add_greater_loc(greaterLoc.o); - builder.add_requires_clause(requiresClause.o); - builder.add_lambda_declarator(lambdaDeclarator.o); - builder.add_statement(statement.o); + io::TypeRequirement::Builder builder{fbb_}; + builder.add_typename_loc(typenameLoc.o); + builder.add_nested_name_specifier(nestedNameSpecifier.o); + builder.add_name(name); + builder.add_name_type(static_cast(nameType)); + builder.add_semicolon_loc(semicolonLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_LambdaExpression; + type_ = io::Requirement_TypeRequirement; } -void ASTEncoder::visit(SizeofExpressionAST* ast) { - auto sizeofLoc = encodeSourceLocation(ast->sizeofLoc); +void ASTEncoder::visit(NestedRequirementAST* ast) { + auto requiresLoc = encodeSourceLocation(ast->requiresLoc); const auto [expression, expressionType] = acceptExpression(ast->expression); - io::SizeofExpression::Builder builder{fbb_}; - builder.add_sizeof_loc(sizeofLoc.o); + auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); + + io::NestedRequirement::Builder builder{fbb_}; + builder.add_requires_loc(requiresLoc.o); builder.add_expression(expression); builder.add_expression_type(static_cast(expressionType)); + builder.add_semicolon_loc(semicolonLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_SizeofExpression; + type_ = io::Requirement_NestedRequirement; } -void ASTEncoder::visit(SizeofTypeExpressionAST* ast) { - auto sizeofLoc = encodeSourceLocation(ast->sizeofLoc); - - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - +void ASTEncoder::visit(TypeTemplateArgumentAST* ast) { const auto typeId = accept(ast->typeId); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - - io::SizeofTypeExpression::Builder builder{fbb_}; - builder.add_sizeof_loc(sizeofLoc.o); - builder.add_lparen_loc(lparenLoc.o); + io::TypeTemplateArgument::Builder builder{fbb_}; builder.add_type_id(typeId.o); - builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_SizeofTypeExpression; + type_ = io::TemplateArgument_TypeTemplateArgument; } -void ASTEncoder::visit(SizeofPackExpressionAST* ast) { - auto sizeofLoc = encodeSourceLocation(ast->sizeofLoc); +void ASTEncoder::visit(ExpressionTemplateArgumentAST* ast) { + const auto [expression, expressionType] = acceptExpression(ast->expression); - auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); + io::ExpressionTemplateArgument::Builder builder{fbb_}; + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + + offset_ = builder.Finish().Union(); + type_ = io::TemplateArgument_ExpressionTemplateArgument; +} + +void ASTEncoder::visit(ParenMemInitializerAST* ast) { + const auto [name, nameType] = acceptName(ast->name); auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - auto identifierLoc = encodeSourceLocation(ast->identifierLoc); + std::vector> expressionListOffsets; + std::vector> expressionListTypes; + + for (auto it = ast->expressionList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptExpression(it->value); + expressionListOffsets.push_back(offset); + expressionListTypes.push_back(type); + } + + auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); + auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - flatbuffers::Offset identifier; - if (ast->identifier) { - if (identifiers_.contains(ast->identifier)) { - identifier = identifiers_.at(ast->identifier); - } else { - identifier = fbb_.CreateString(ast->identifier->value()); - identifiers_.emplace(ast->identifier, identifier); - } - } + auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - io::SizeofPackExpression::Builder builder{fbb_}; - builder.add_sizeof_loc(sizeofLoc.o); - builder.add_ellipsis_loc(ellipsisLoc.o); + io::ParenMemInitializer::Builder builder{fbb_}; + builder.add_name(name); + builder.add_name_type(static_cast(nameType)); builder.add_lparen_loc(lparenLoc.o); - builder.add_identifier_loc(identifierLoc.o); + builder.add_expression_list(expressionListOffsetsVector); + builder.add_expression_list_type(expressionListTypesVector); builder.add_rparen_loc(rparenLoc.o); - if (ast->identifier) { - builder.add_identifier(identifier); - } + builder.add_ellipsis_loc(ellipsisLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_SizeofPackExpression; + type_ = io::MemInitializer_ParenMemInitializer; } -void ASTEncoder::visit(TypeidExpressionAST* ast) { - auto typeidLoc = encodeSourceLocation(ast->typeidLoc); - - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); +void ASTEncoder::visit(BracedMemInitializerAST* ast) { + const auto [name, nameType] = acceptName(ast->name); - const auto [expression, expressionType] = acceptExpression(ast->expression); + const auto bracedInitList = accept(ast->bracedInitList); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - io::TypeidExpression::Builder builder{fbb_}; - builder.add_typeid_loc(typeidLoc.o); - builder.add_lparen_loc(lparenLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); - builder.add_rparen_loc(rparenLoc.o); + io::BracedMemInitializer::Builder builder{fbb_}; + builder.add_name(name); + builder.add_name_type(static_cast(nameType)); + builder.add_braced_init_list(bracedInitList.o); + builder.add_ellipsis_loc(ellipsisLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_TypeidExpression; + type_ = io::MemInitializer_BracedMemInitializer; } -void ASTEncoder::visit(TypeidOfTypeExpressionAST* ast) { - auto typeidLoc = encodeSourceLocation(ast->typeidLoc); +void ASTEncoder::visit(ThisLambdaCaptureAST* ast) { + auto thisLoc = encodeSourceLocation(ast->thisLoc); - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + io::ThisLambdaCapture::Builder builder{fbb_}; + builder.add_this_loc(thisLoc.o); - const auto typeId = accept(ast->typeId); + offset_ = builder.Finish().Union(); + type_ = io::LambdaCapture_ThisLambdaCapture; +} - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); +void ASTEncoder::visit(DerefThisLambdaCaptureAST* ast) { + auto starLoc = encodeSourceLocation(ast->starLoc); - io::TypeidOfTypeExpression::Builder builder{fbb_}; - builder.add_typeid_loc(typeidLoc.o); - builder.add_lparen_loc(lparenLoc.o); - builder.add_type_id(typeId.o); - builder.add_rparen_loc(rparenLoc.o); + auto thisLoc = encodeSourceLocation(ast->thisLoc); + + io::DerefThisLambdaCapture::Builder builder{fbb_}; + builder.add_star_loc(starLoc.o); + builder.add_this_loc(thisLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_TypeidOfTypeExpression; + type_ = io::LambdaCapture_DerefThisLambdaCapture; } -void ASTEncoder::visit(AlignofExpressionAST* ast) { - auto alignofLoc = encodeSourceLocation(ast->alignofLoc); - - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); +void ASTEncoder::visit(SimpleLambdaCaptureAST* ast) { + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); - const auto typeId = accept(ast->typeId); + auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + flatbuffers::Offset identifier; + if (ast->identifier) { + if (identifiers_.contains(ast->identifier)) { + identifier = identifiers_.at(ast->identifier); + } else { + identifier = fbb_.CreateString(ast->identifier->value()); + identifiers_.emplace(ast->identifier, identifier); + } + } - io::AlignofExpression::Builder builder{fbb_}; - builder.add_alignof_loc(alignofLoc.o); - builder.add_lparen_loc(lparenLoc.o); - builder.add_type_id(typeId.o); - builder.add_rparen_loc(rparenLoc.o); + io::SimpleLambdaCapture::Builder builder{fbb_}; + builder.add_identifier_loc(identifierLoc.o); + builder.add_ellipsis_loc(ellipsisLoc.o); + if (ast->identifier) { + builder.add_identifier(identifier); + } offset_ = builder.Finish().Union(); - type_ = io::Expression_AlignofExpression; + type_ = io::LambdaCapture_SimpleLambdaCapture; } -void ASTEncoder::visit(TypeTraitsExpressionAST* ast) { - auto typeTraitsLoc = encodeSourceLocation(ast->typeTraitsLoc); - - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); +void ASTEncoder::visit(RefLambdaCaptureAST* ast) { + auto ampLoc = encodeSourceLocation(ast->ampLoc); - std::vector> typeIdListOffsets; - for (auto it = ast->typeIdList; it; it = it->next) { - if (!it->value) continue; - typeIdListOffsets.emplace_back(accept(it->value).o); - } + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); - auto typeIdListOffsetsVector = fbb_.CreateVector(typeIdListOffsets); + auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + flatbuffers::Offset identifier; + if (ast->identifier) { + if (identifiers_.contains(ast->identifier)) { + identifier = identifiers_.at(ast->identifier); + } else { + identifier = fbb_.CreateString(ast->identifier->value()); + identifiers_.emplace(ast->identifier, identifier); + } + } - io::TypeTraitsExpression::Builder builder{fbb_}; - builder.add_type_traits_loc(typeTraitsLoc.o); - builder.add_lparen_loc(lparenLoc.o); - builder.add_type_id_list(typeIdListOffsetsVector); - builder.add_rparen_loc(rparenLoc.o); - builder.add_type_traits(static_cast(ast->typeTraits)); + io::RefLambdaCapture::Builder builder{fbb_}; + builder.add_amp_loc(ampLoc.o); + builder.add_identifier_loc(identifierLoc.o); + builder.add_ellipsis_loc(ellipsisLoc.o); + if (ast->identifier) { + builder.add_identifier(identifier); + } offset_ = builder.Finish().Union(); - type_ = io::Expression_TypeTraitsExpression; + type_ = io::LambdaCapture_RefLambdaCapture; } -void ASTEncoder::visit(UnaryExpressionAST* ast) { - auto opLoc = encodeSourceLocation(ast->opLoc); - - const auto [expression, expressionType] = acceptExpression(ast->expression); - - io::UnaryExpression::Builder builder{fbb_}; - builder.add_op_loc(opLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); - builder.add_op(static_cast(ast->op)); +void ASTEncoder::visit(RefInitLambdaCaptureAST* ast) { + auto ampLoc = encodeSourceLocation(ast->ampLoc); - offset_ = builder.Finish().Union(); - type_ = io::Expression_UnaryExpression; -} + auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); -void ASTEncoder::visit(BinaryExpressionAST* ast) { - const auto [leftExpression, leftExpressionType] = - acceptExpression(ast->leftExpression); + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); - auto opLoc = encodeSourceLocation(ast->opLoc); + const auto [initializer, initializerType] = + acceptInitializer(ast->initializer); - const auto [rightExpression, rightExpressionType] = - acceptExpression(ast->rightExpression); + flatbuffers::Offset identifier; + if (ast->identifier) { + if (identifiers_.contains(ast->identifier)) { + identifier = identifiers_.at(ast->identifier); + } else { + identifier = fbb_.CreateString(ast->identifier->value()); + identifiers_.emplace(ast->identifier, identifier); + } + } - io::BinaryExpression::Builder builder{fbb_}; - builder.add_left_expression(leftExpression); - builder.add_left_expression_type( - static_cast(leftExpressionType)); - builder.add_op_loc(opLoc.o); - builder.add_right_expression(rightExpression); - builder.add_right_expression_type( - static_cast(rightExpressionType)); - builder.add_op(static_cast(ast->op)); + io::RefInitLambdaCapture::Builder builder{fbb_}; + builder.add_amp_loc(ampLoc.o); + builder.add_ellipsis_loc(ellipsisLoc.o); + builder.add_identifier_loc(identifierLoc.o); + builder.add_initializer(initializer); + builder.add_initializer_type(static_cast(initializerType)); + if (ast->identifier) { + builder.add_identifier(identifier); + } offset_ = builder.Finish().Union(); - type_ = io::Expression_BinaryExpression; + type_ = io::LambdaCapture_RefInitLambdaCapture; } -void ASTEncoder::visit(AssignmentExpressionAST* ast) { - const auto [leftExpression, leftExpressionType] = - acceptExpression(ast->leftExpression); +void ASTEncoder::visit(InitLambdaCaptureAST* ast) { + auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - auto opLoc = encodeSourceLocation(ast->opLoc); + auto identifierLoc = encodeSourceLocation(ast->identifierLoc); - const auto [rightExpression, rightExpressionType] = - acceptExpression(ast->rightExpression); + const auto [initializer, initializerType] = + acceptInitializer(ast->initializer); - io::AssignmentExpression::Builder builder{fbb_}; - builder.add_left_expression(leftExpression); - builder.add_left_expression_type( - static_cast(leftExpressionType)); - builder.add_op_loc(opLoc.o); - builder.add_right_expression(rightExpression); - builder.add_right_expression_type( - static_cast(rightExpressionType)); - builder.add_op(static_cast(ast->op)); + flatbuffers::Offset identifier; + if (ast->identifier) { + if (identifiers_.contains(ast->identifier)) { + identifier = identifiers_.at(ast->identifier); + } else { + identifier = fbb_.CreateString(ast->identifier->value()); + identifiers_.emplace(ast->identifier, identifier); + } + } + + io::InitLambdaCapture::Builder builder{fbb_}; + builder.add_ellipsis_loc(ellipsisLoc.o); + builder.add_identifier_loc(identifierLoc.o); + builder.add_initializer(initializer); + builder.add_initializer_type(static_cast(initializerType)); + if (ast->identifier) { + builder.add_identifier(identifier); + } offset_ = builder.Finish().Union(); - type_ = io::Expression_AssignmentExpression; + type_ = io::LambdaCapture_InitLambdaCapture; } -void ASTEncoder::visit(BracedTypeConstructionAST* ast) { - const auto [typeSpecifier, typeSpecifierType] = - acceptSpecifier(ast->typeSpecifier); +void ASTEncoder::visit(EqualInitializerAST* ast) { + auto equalLoc = encodeSourceLocation(ast->equalLoc); - const auto bracedInitList = accept(ast->bracedInitList); + const auto [expression, expressionType] = acceptExpression(ast->expression); - io::BracedTypeConstruction::Builder builder{fbb_}; - builder.add_type_specifier(typeSpecifier); - builder.add_type_specifier_type( - static_cast(typeSpecifierType)); - builder.add_braced_init_list(bracedInitList.o); + io::EqualInitializer::Builder builder{fbb_}; + builder.add_equal_loc(equalLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); offset_ = builder.Finish().Union(); - type_ = io::Expression_BracedTypeConstruction; + type_ = io::Initializer_EqualInitializer; } -void ASTEncoder::visit(TypeConstructionAST* ast) { - const auto [typeSpecifier, typeSpecifierType] = - acceptSpecifier(ast->typeSpecifier); - - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); +void ASTEncoder::visit(BracedInitListAST* ast) { + auto lbraceLoc = encodeSourceLocation(ast->lbraceLoc); std::vector> expressionListOffsets; std::vector> expressionListTypes; @@ -2225,25 +2292,22 @@ void ASTEncoder::visit(TypeConstructionAST* ast) { auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + auto commaLoc = encodeSourceLocation(ast->commaLoc); - io::TypeConstruction::Builder builder{fbb_}; - builder.add_type_specifier(typeSpecifier); - builder.add_type_specifier_type( - static_cast(typeSpecifierType)); - builder.add_lparen_loc(lparenLoc.o); + auto rbraceLoc = encodeSourceLocation(ast->rbraceLoc); + + io::BracedInitList::Builder builder{fbb_}; + builder.add_lbrace_loc(lbraceLoc.o); builder.add_expression_list(expressionListOffsetsVector); builder.add_expression_list_type(expressionListTypesVector); - builder.add_rparen_loc(rparenLoc.o); + builder.add_comma_loc(commaLoc.o); + builder.add_rbrace_loc(rbraceLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_TypeConstruction; + type_ = io::Initializer_BracedInitList; } -void ASTEncoder::visit(CallExpressionAST* ast) { - const auto [baseExpression, baseExpressionType] = - acceptExpression(ast->baseExpression); - +void ASTEncoder::visit(ParenInitializerAST* ast) { auto lparenLoc = encodeSourceLocation(ast->lparenLoc); std::vector> expressionListOffsets; @@ -2261,251 +2325,227 @@ void ASTEncoder::visit(CallExpressionAST* ast) { auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - io::CallExpression::Builder builder{fbb_}; - builder.add_base_expression(baseExpression); - builder.add_base_expression_type( - static_cast(baseExpressionType)); + io::ParenInitializer::Builder builder{fbb_}; builder.add_lparen_loc(lparenLoc.o); builder.add_expression_list(expressionListOffsetsVector); builder.add_expression_list_type(expressionListTypesVector); - builder.add_rparen_loc(rparenLoc.o); - - offset_ = builder.Finish().Union(); - type_ = io::Expression_CallExpression; -} - -void ASTEncoder::visit(SubscriptExpressionAST* ast) { - const auto [baseExpression, baseExpressionType] = - acceptExpression(ast->baseExpression); - - auto lbracketLoc = encodeSourceLocation(ast->lbracketLoc); - - const auto [indexExpression, indexExpressionType] = - acceptExpression(ast->indexExpression); - - auto rbracketLoc = encodeSourceLocation(ast->rbracketLoc); - - io::SubscriptExpression::Builder builder{fbb_}; - builder.add_base_expression(baseExpression); - builder.add_base_expression_type( - static_cast(baseExpressionType)); - builder.add_lbracket_loc(lbracketLoc.o); - builder.add_index_expression(indexExpression); - builder.add_index_expression_type( - static_cast(indexExpressionType)); - builder.add_rbracket_loc(rbracketLoc.o); - - offset_ = builder.Finish().Union(); - type_ = io::Expression_SubscriptExpression; -} - -void ASTEncoder::visit(MemberExpressionAST* ast) { - const auto [baseExpression, baseExpressionType] = - acceptExpression(ast->baseExpression); - - auto accessLoc = encodeSourceLocation(ast->accessLoc); - - auto templateLoc = encodeSourceLocation(ast->templateLoc); - - const auto [name, nameType] = acceptName(ast->name); - - io::MemberExpression::Builder builder{fbb_}; - builder.add_base_expression(baseExpression); - builder.add_base_expression_type( - static_cast(baseExpressionType)); - builder.add_access_loc(accessLoc.o); - builder.add_template_loc(templateLoc.o); - builder.add_name(name); - builder.add_name_type(static_cast(nameType)); - builder.add_access_op(static_cast(ast->accessOp)); - - offset_ = builder.Finish().Union(); - type_ = io::Expression_MemberExpression; -} - -void ASTEncoder::visit(PostIncrExpressionAST* ast) { - const auto [baseExpression, baseExpressionType] = - acceptExpression(ast->baseExpression); - - auto opLoc = encodeSourceLocation(ast->opLoc); - - io::PostIncrExpression::Builder builder{fbb_}; - builder.add_base_expression(baseExpression); - builder.add_base_expression_type( - static_cast(baseExpressionType)); - builder.add_op_loc(opLoc.o); - builder.add_op(static_cast(ast->op)); + builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_PostIncrExpression; + type_ = io::Initializer_ParenInitializer; } -void ASTEncoder::visit(ConditionalExpressionAST* ast) { - const auto [condition, conditionType] = acceptExpression(ast->condition); +void ASTEncoder::visit(NewParenInitializerAST* ast) { + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - auto questionLoc = encodeSourceLocation(ast->questionLoc); + std::vector> expressionListOffsets; + std::vector> expressionListTypes; - const auto [iftrueExpression, iftrueExpressionType] = - acceptExpression(ast->iftrueExpression); + for (auto it = ast->expressionList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptExpression(it->value); + expressionListOffsets.push_back(offset); + expressionListTypes.push_back(type); + } - auto colonLoc = encodeSourceLocation(ast->colonLoc); + auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); + auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); - const auto [iffalseExpression, iffalseExpressionType] = - acceptExpression(ast->iffalseExpression); + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - io::ConditionalExpression::Builder builder{fbb_}; - builder.add_condition(condition); - builder.add_condition_type(static_cast(conditionType)); - builder.add_question_loc(questionLoc.o); - builder.add_iftrue_expression(iftrueExpression); - builder.add_iftrue_expression_type( - static_cast(iftrueExpressionType)); - builder.add_colon_loc(colonLoc.o); - builder.add_iffalse_expression(iffalseExpression); - builder.add_iffalse_expression_type( - static_cast(iffalseExpressionType)); + io::NewParenInitializer::Builder builder{fbb_}; + builder.add_lparen_loc(lparenLoc.o); + builder.add_expression_list(expressionListOffsetsVector); + builder.add_expression_list_type(expressionListTypesVector); + builder.add_rparen_loc(rparenLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_ConditionalExpression; + type_ = io::NewInitializer_NewParenInitializer; } -void ASTEncoder::visit(ImplicitCastExpressionAST* ast) { - const auto [expression, expressionType] = acceptExpression(ast->expression); +void ASTEncoder::visit(NewBracedInitializerAST* ast) { + const auto bracedInit = accept(ast->bracedInit); - io::ImplicitCastExpression::Builder builder{fbb_}; - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); + io::NewBracedInitializer::Builder builder{fbb_}; + builder.add_braced_init(bracedInit.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_ImplicitCastExpression; + type_ = io::NewInitializer_NewBracedInitializer; } -void ASTEncoder::visit(CastExpressionAST* ast) { - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); +void ASTEncoder::visit(EllipsisExceptionDeclarationAST* ast) { + auto ellipsisLoc = encodeSourceLocation(ast->ellipsisLoc); - const auto typeId = accept(ast->typeId); + io::EllipsisExceptionDeclaration::Builder builder{fbb_}; + builder.add_ellipsis_loc(ellipsisLoc.o); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + offset_ = builder.Finish().Union(); + type_ = io::ExceptionDeclaration_EllipsisExceptionDeclaration; +} - const auto [expression, expressionType] = acceptExpression(ast->expression); +void ASTEncoder::visit(TypeExceptionDeclarationAST* ast) { + std::vector> attributeListOffsets; + std::vector> + attributeListTypes; - io::CastExpression::Builder builder{fbb_}; - builder.add_lparen_loc(lparenLoc.o); - builder.add_type_id(typeId.o); - builder.add_rparen_loc(rparenLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); + for (auto it = ast->attributeList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptAttributeSpecifier(it->value); + attributeListOffsets.push_back(offset); + attributeListTypes.push_back(type); + } + + auto attributeListOffsetsVector = fbb_.CreateVector(attributeListOffsets); + auto attributeListTypesVector = fbb_.CreateVector(attributeListTypes); + + std::vector> typeSpecifierListOffsets; + std::vector> typeSpecifierListTypes; + + for (auto it = ast->typeSpecifierList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptSpecifier(it->value); + typeSpecifierListOffsets.push_back(offset); + typeSpecifierListTypes.push_back(type); + } + + auto typeSpecifierListOffsetsVector = + fbb_.CreateVector(typeSpecifierListOffsets); + auto typeSpecifierListTypesVector = fbb_.CreateVector(typeSpecifierListTypes); + + const auto declarator = accept(ast->declarator); + + io::TypeExceptionDeclaration::Builder builder{fbb_}; + builder.add_attribute_list(attributeListOffsetsVector); + builder.add_attribute_list_type(attributeListTypesVector); + builder.add_type_specifier_list(typeSpecifierListOffsetsVector); + builder.add_type_specifier_list_type(typeSpecifierListTypesVector); + builder.add_declarator(declarator.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_CastExpression; + type_ = io::ExceptionDeclaration_TypeExceptionDeclaration; } -void ASTEncoder::visit(CppCastExpressionAST* ast) { - auto castLoc = encodeSourceLocation(ast->castLoc); +void ASTEncoder::visit(DefaultFunctionBodyAST* ast) { + auto equalLoc = encodeSourceLocation(ast->equalLoc); - auto lessLoc = encodeSourceLocation(ast->lessLoc); + auto defaultLoc = encodeSourceLocation(ast->defaultLoc); - const auto typeId = accept(ast->typeId); + auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); - auto greaterLoc = encodeSourceLocation(ast->greaterLoc); + io::DefaultFunctionBody::Builder builder{fbb_}; + builder.add_equal_loc(equalLoc.o); + builder.add_default_loc(defaultLoc.o); + builder.add_semicolon_loc(semicolonLoc.o); - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + offset_ = builder.Finish().Union(); + type_ = io::FunctionBody_DefaultFunctionBody; +} - const auto [expression, expressionType] = acceptExpression(ast->expression); +void ASTEncoder::visit(CompoundStatementFunctionBodyAST* ast) { + const auto ctorInitializer = accept(ast->ctorInitializer); - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + const auto statement = accept(ast->statement); - io::CppCastExpression::Builder builder{fbb_}; - builder.add_cast_loc(castLoc.o); - builder.add_less_loc(lessLoc.o); - builder.add_type_id(typeId.o); - builder.add_greater_loc(greaterLoc.o); - builder.add_lparen_loc(lparenLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); - builder.add_rparen_loc(rparenLoc.o); + io::CompoundStatementFunctionBody::Builder builder{fbb_}; + builder.add_ctor_initializer(ctorInitializer.o); + builder.add_statement(statement.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_CppCastExpression; + type_ = io::FunctionBody_CompoundStatementFunctionBody; } -void ASTEncoder::visit(NewExpressionAST* ast) { - auto scopeLoc = encodeSourceLocation(ast->scopeLoc); +void ASTEncoder::visit(TryStatementFunctionBodyAST* ast) { + auto tryLoc = encodeSourceLocation(ast->tryLoc); - auto newLoc = encodeSourceLocation(ast->newLoc); + const auto ctorInitializer = accept(ast->ctorInitializer); - const auto typeId = accept(ast->typeId); + const auto statement = accept(ast->statement); - const auto [newInitalizer, newInitalizerType] = - acceptNewInitializer(ast->newInitalizer); + std::vector> handlerListOffsets; + for (auto it = ast->handlerList; it; it = it->next) { + if (!it->value) continue; + handlerListOffsets.emplace_back(accept(it->value).o); + } - io::NewExpression::Builder builder{fbb_}; - builder.add_scope_loc(scopeLoc.o); - builder.add_new_loc(newLoc.o); - builder.add_type_id(typeId.o); - builder.add_new_initalizer(newInitalizer); - builder.add_new_initalizer_type( - static_cast(newInitalizerType)); + auto handlerListOffsetsVector = fbb_.CreateVector(handlerListOffsets); + + io::TryStatementFunctionBody::Builder builder{fbb_}; + builder.add_try_loc(tryLoc.o); + builder.add_ctor_initializer(ctorInitializer.o); + builder.add_statement(statement.o); + builder.add_handler_list(handlerListOffsetsVector); offset_ = builder.Finish().Union(); - type_ = io::Expression_NewExpression; + type_ = io::FunctionBody_TryStatementFunctionBody; } -void ASTEncoder::visit(DeleteExpressionAST* ast) { - auto scopeLoc = encodeSourceLocation(ast->scopeLoc); +void ASTEncoder::visit(DeleteFunctionBodyAST* ast) { + auto equalLoc = encodeSourceLocation(ast->equalLoc); auto deleteLoc = encodeSourceLocation(ast->deleteLoc); - auto lbracketLoc = encodeSourceLocation(ast->lbracketLoc); - - auto rbracketLoc = encodeSourceLocation(ast->rbracketLoc); - - const auto [expression, expressionType] = acceptExpression(ast->expression); + auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); - io::DeleteExpression::Builder builder{fbb_}; - builder.add_scope_loc(scopeLoc.o); + io::DeleteFunctionBody::Builder builder{fbb_}; + builder.add_equal_loc(equalLoc.o); builder.add_delete_loc(deleteLoc.o); - builder.add_lbracket_loc(lbracketLoc.o); - builder.add_rbracket_loc(rbracketLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); + builder.add_semicolon_loc(semicolonLoc.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_DeleteExpression; + type_ = io::FunctionBody_DeleteFunctionBody; } -void ASTEncoder::visit(ThrowExpressionAST* ast) { - auto throwLoc = encodeSourceLocation(ast->throwLoc); +void ASTEncoder::visit(TranslationUnitAST* ast) { + std::vector> declarationListOffsets; + std::vector> declarationListTypes; - const auto [expression, expressionType] = acceptExpression(ast->expression); + for (auto it = ast->declarationList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptDeclaration(it->value); + declarationListOffsets.push_back(offset); + declarationListTypes.push_back(type); + } - io::ThrowExpression::Builder builder{fbb_}; - builder.add_throw_loc(throwLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); + auto declarationListOffsetsVector = fbb_.CreateVector(declarationListOffsets); + auto declarationListTypesVector = fbb_.CreateVector(declarationListTypes); + + io::TranslationUnit::Builder builder{fbb_}; + builder.add_declaration_list(declarationListOffsetsVector); + builder.add_declaration_list_type(declarationListTypesVector); offset_ = builder.Finish().Union(); - type_ = io::Expression_ThrowExpression; + type_ = io::Unit_TranslationUnit; } -void ASTEncoder::visit(NoexceptExpressionAST* ast) { - auto noexceptLoc = encodeSourceLocation(ast->noexceptLoc); +void ASTEncoder::visit(ModuleUnitAST* ast) { + const auto globalModuleFragment = accept(ast->globalModuleFragment); - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + const auto moduleDeclaration = accept(ast->moduleDeclaration); - const auto [expression, expressionType] = acceptExpression(ast->expression); + std::vector> declarationListOffsets; + std::vector> declarationListTypes; - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + for (auto it = ast->declarationList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptDeclaration(it->value); + declarationListOffsets.push_back(offset); + declarationListTypes.push_back(type); + } - io::NoexceptExpression::Builder builder{fbb_}; - builder.add_noexcept_loc(noexceptLoc.o); - builder.add_lparen_loc(lparenLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); - builder.add_rparen_loc(rparenLoc.o); + auto declarationListOffsetsVector = fbb_.CreateVector(declarationListOffsets); + auto declarationListTypesVector = fbb_.CreateVector(declarationListTypes); + + const auto privateModuleFragment = accept(ast->privateModuleFragment); + + io::ModuleUnit::Builder builder{fbb_}; + builder.add_global_module_fragment(globalModuleFragment.o); + builder.add_module_declaration(moduleDeclaration.o); + builder.add_declaration_list(declarationListOffsetsVector); + builder.add_declaration_list_type(declarationListTypesVector); + builder.add_private_module_fragment(privateModuleFragment.o); offset_ = builder.Finish().Union(); - type_ = io::Expression_NoexceptExpression; + type_ = io::Unit_ModuleUnit; } void ASTEncoder::visit(LabeledStatementAST* ast) { diff --git a/src/parser/cxx/ast_fwd.h b/src/parser/cxx/ast_fwd.h index 8a49fb58..1a0890d9 100644 --- a/src/parser/cxx/ast_fwd.h +++ b/src/parser/cxx/ast_fwd.h @@ -102,6 +102,49 @@ class ModulePartitionAST; class AttributeArgumentClauseAST; class AttributeAST; class AttributeUsingPrefixAST; +class DesignatorAST; + +// ExpressionAST +class DesignatedInitializerClauseAST; +class ThisExpressionAST; +class CharLiteralExpressionAST; +class BoolLiteralExpressionAST; +class IntLiteralExpressionAST; +class FloatLiteralExpressionAST; +class NullptrLiteralExpressionAST; +class StringLiteralExpressionAST; +class UserDefinedStringLiteralExpressionAST; +class IdExpressionAST; +class RequiresExpressionAST; +class NestedExpressionAST; +class RightFoldExpressionAST; +class LeftFoldExpressionAST; +class FoldExpressionAST; +class LambdaExpressionAST; +class SizeofExpressionAST; +class SizeofTypeExpressionAST; +class SizeofPackExpressionAST; +class TypeidExpressionAST; +class TypeidOfTypeExpressionAST; +class AlignofExpressionAST; +class TypeTraitsExpressionAST; +class UnaryExpressionAST; +class BinaryExpressionAST; +class AssignmentExpressionAST; +class BracedTypeConstructionAST; +class TypeConstructionAST; +class CallExpressionAST; +class SubscriptExpressionAST; +class MemberExpressionAST; +class PostIncrExpressionAST; +class ConditionalExpressionAST; +class ImplicitCastExpressionAST; +class CastExpressionAST; +class CppCastExpressionAST; +class NewExpressionAST; +class DeleteExpressionAST; +class ThrowExpressionAST; +class NoexceptExpressionAST; // RequirementAST class SimpleRequirementAST; @@ -148,47 +191,6 @@ class DeleteFunctionBodyAST; class TranslationUnitAST; class ModuleUnitAST; -// ExpressionAST -class ThisExpressionAST; -class CharLiteralExpressionAST; -class BoolLiteralExpressionAST; -class IntLiteralExpressionAST; -class FloatLiteralExpressionAST; -class NullptrLiteralExpressionAST; -class StringLiteralExpressionAST; -class UserDefinedStringLiteralExpressionAST; -class IdExpressionAST; -class RequiresExpressionAST; -class NestedExpressionAST; -class RightFoldExpressionAST; -class LeftFoldExpressionAST; -class FoldExpressionAST; -class LambdaExpressionAST; -class SizeofExpressionAST; -class SizeofTypeExpressionAST; -class SizeofPackExpressionAST; -class TypeidExpressionAST; -class TypeidOfTypeExpressionAST; -class AlignofExpressionAST; -class TypeTraitsExpressionAST; -class UnaryExpressionAST; -class BinaryExpressionAST; -class AssignmentExpressionAST; -class BracedTypeConstructionAST; -class TypeConstructionAST; -class CallExpressionAST; -class SubscriptExpressionAST; -class MemberExpressionAST; -class PostIncrExpressionAST; -class ConditionalExpressionAST; -class ImplicitCastExpressionAST; -class CastExpressionAST; -class CppCastExpressionAST; -class NewExpressionAST; -class DeleteExpressionAST; -class ThrowExpressionAST; -class NoexceptExpressionAST; - // StatementAST class LabeledStatementAST; class CaseStatementAST; diff --git a/src/parser/cxx/ast_kind.h b/src/parser/cxx/ast_kind.h index c2b9dc6b..7c64d141 100644 --- a/src/parser/cxx/ast_kind.h +++ b/src/parser/cxx/ast_kind.h @@ -54,6 +54,49 @@ enum struct ASTKind { AttributeArgumentClause, Attribute, AttributeUsingPrefix, + Designator, + + // ExpressionAST + DesignatedInitializerClause, + ThisExpression, + CharLiteralExpression, + BoolLiteralExpression, + IntLiteralExpression, + FloatLiteralExpression, + NullptrLiteralExpression, + StringLiteralExpression, + UserDefinedStringLiteralExpression, + IdExpression, + RequiresExpression, + NestedExpression, + RightFoldExpression, + LeftFoldExpression, + FoldExpression, + LambdaExpression, + SizeofExpression, + SizeofTypeExpression, + SizeofPackExpression, + TypeidExpression, + TypeidOfTypeExpression, + AlignofExpression, + TypeTraitsExpression, + UnaryExpression, + BinaryExpression, + AssignmentExpression, + BracedTypeConstruction, + TypeConstruction, + CallExpression, + SubscriptExpression, + MemberExpression, + PostIncrExpression, + ConditionalExpression, + ImplicitCastExpression, + CastExpression, + CppCastExpression, + NewExpression, + DeleteExpression, + ThrowExpression, + NoexceptExpression, // RequirementAST SimpleRequirement, @@ -100,47 +143,6 @@ enum struct ASTKind { TranslationUnit, ModuleUnit, - // ExpressionAST - ThisExpression, - CharLiteralExpression, - BoolLiteralExpression, - IntLiteralExpression, - FloatLiteralExpression, - NullptrLiteralExpression, - StringLiteralExpression, - UserDefinedStringLiteralExpression, - IdExpression, - RequiresExpression, - NestedExpression, - RightFoldExpression, - LeftFoldExpression, - FoldExpression, - LambdaExpression, - SizeofExpression, - SizeofTypeExpression, - SizeofPackExpression, - TypeidExpression, - TypeidOfTypeExpression, - AlignofExpression, - TypeTraitsExpression, - UnaryExpression, - BinaryExpression, - AssignmentExpression, - BracedTypeConstruction, - TypeConstruction, - CallExpression, - SubscriptExpression, - MemberExpression, - PostIncrExpression, - ConditionalExpression, - ImplicitCastExpression, - CastExpression, - CppCastExpression, - NewExpression, - DeleteExpression, - ThrowExpression, - NoexceptExpression, - // StatementAST LabeledStatement, CaseStatement, diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index b0dec71a..9360e3cc 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -600,14 +600,14 @@ void ASTSlot::visit(AttributeUsingPrefixAST* ast) { slotCount_ = 3; } -void ASTSlot::visit(SimpleRequirementAST* ast) { +void ASTSlot::visit(DesignatorAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->dotLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->semicolonLoc.index(); + value_ = ast->identifierLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch @@ -615,98 +615,113 @@ void ASTSlot::visit(SimpleRequirementAST* ast) { slotCount_ = 2; } -void ASTSlot::visit(CompoundRequirementAST* ast) { +void ASTSlot::visit(DesignatedInitializerClauseAST* ast) { switch (slot_) { case 0: - value_ = ast->lbraceLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->designator); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = reinterpret_cast(ast->expression); + value_ = reinterpret_cast(ast->initializer); slotKind_ = ASTSlotKind::kNode; break; - case 2: - value_ = ast->rbraceLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 3: - value_ = ast->noexceptLoc.index(); + } // switch + + slotCount_ = 2; +} + +void ASTSlot::visit(ThisExpressionAST* ast) { + switch (slot_) { + case 0: + value_ = ast->thisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 4: - value_ = ast->minusGreaterLoc.index(); + } // switch + + slotCount_ = 1; +} + +void ASTSlot::visit(CharLiteralExpressionAST* ast) { + switch (slot_) { + case 0: + value_ = ast->literalLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 5: - value_ = reinterpret_cast(ast->typeConstraint); - slotKind_ = ASTSlotKind::kNode; - break; - case 6: - value_ = ast->semicolonLoc.index(); + } // switch + + slotCount_ = 1; +} + +void ASTSlot::visit(BoolLiteralExpressionAST* ast) { + switch (slot_) { + case 0: + value_ = ast->literalLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 7; + slotCount_ = 1; } -void ASTSlot::visit(TypeRequirementAST* ast) { +void ASTSlot::visit(IntLiteralExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->typenameLoc.index(); + value_ = ast->literalLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 1: - value_ = reinterpret_cast(ast->nestedNameSpecifier); - slotKind_ = ASTSlotKind::kNode; - break; - case 2: - value_ = reinterpret_cast(ast->name); - slotKind_ = ASTSlotKind::kNode; - break; - case 3: - value_ = ast->semicolonLoc.index(); + } // switch + + slotCount_ = 1; +} + +void ASTSlot::visit(FloatLiteralExpressionAST* ast) { + switch (slot_) { + case 0: + value_ = ast->literalLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 4; + slotCount_ = 1; } -void ASTSlot::visit(NestedRequirementAST* ast) { +void ASTSlot::visit(NullptrLiteralExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->requiresLoc.index(); + value_ = ast->literalLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 1: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; - break; - case 2: - value_ = ast->semicolonLoc.index(); + } // switch + + slotCount_ = 1; +} + +void ASTSlot::visit(StringLiteralExpressionAST* ast) { + switch (slot_) { + case 0: + value_ = ast->literalLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 3; + slotCount_ = 1; } -void ASTSlot::visit(TypeTemplateArgumentAST* ast) { +void ASTSlot::visit(UserDefinedStringLiteralExpressionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->typeId); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->literalLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; } // switch slotCount_ = 1; } -void ASTSlot::visit(ExpressionTemplateArgumentAST* ast) { +void ASTSlot::visit(IdExpressionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->expression); + value_ = reinterpret_cast(ast->name); slotKind_ = ASTSlotKind::kNode; break; } // switch @@ -714,45 +729,45 @@ void ASTSlot::visit(ExpressionTemplateArgumentAST* ast) { slotCount_ = 1; } -void ASTSlot::visit(ParenMemInitializerAST* ast) { +void ASTSlot::visit(RequiresExpressionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->name); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->requiresLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: value_ = ast->lparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = reinterpret_cast(ast->expressionList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = reinterpret_cast(ast->parameterDeclarationClause); + slotKind_ = ASTSlotKind::kNode; break; case 3: value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 4: - value_ = ast->ellipsisLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->requirementBody); + slotKind_ = ASTSlotKind::kNode; break; } // switch slotCount_ = 5; } -void ASTSlot::visit(BracedMemInitializerAST* ast) { +void ASTSlot::visit(NestedExpressionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->name); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = reinterpret_cast(ast->bracedInitList); + value_ = reinterpret_cast(ast->expression); slotKind_ = ASTSlotKind::kNode; break; case 2: - value_ = ast->ellipsisLoc.index(); + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch @@ -760,139 +775,234 @@ void ASTSlot::visit(BracedMemInitializerAST* ast) { slotCount_ = 3; } -void ASTSlot::visit(ThisLambdaCaptureAST* ast) { +void ASTSlot::visit(RightFoldExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->thisLoc.index(); + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; + break; + case 2: + value_ = ast->opLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 3: + value_ = ast->ellipsisLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 4: + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 1; + slotCount_ = 5; } -void ASTSlot::visit(DerefThisLambdaCaptureAST* ast) { +void ASTSlot::visit(LeftFoldExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->starLoc.index(); + value_ = ast->lparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->thisLoc.index(); + value_ = ast->ellipsisLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 2: + value_ = ast->opLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 3: + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; + break; + case 4: + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 2; + slotCount_ = 5; } -void ASTSlot::visit(SimpleLambdaCaptureAST* ast) { +void ASTSlot::visit(FoldExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->identifierLoc.index(); + value_ = ast->lparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: + value_ = reinterpret_cast(ast->leftExpression); + slotKind_ = ASTSlotKind::kNode; + break; + case 2: + value_ = ast->opLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 3: value_ = ast->ellipsisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; + case 4: + value_ = ast->foldOpLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 5: + value_ = reinterpret_cast(ast->rightExpression); + slotKind_ = ASTSlotKind::kNode; + break; + case 6: + value_ = ast->rparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; } // switch - slotCount_ = 2; + slotCount_ = 7; } -void ASTSlot::visit(RefLambdaCaptureAST* ast) { +void ASTSlot::visit(LambdaExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->ampLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->lambdaIntroducer); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = ast->identifierLoc.index(); + value_ = ast->lessLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = ast->ellipsisLoc.index(); + value_ = reinterpret_cast(ast->templateParameterList); + slotKind_ = ASTSlotKind::kNodeList; + break; + case 3: + value_ = ast->greaterLoc.index(); slotKind_ = ASTSlotKind::kToken; break; + case 4: + value_ = reinterpret_cast(ast->requiresClause); + slotKind_ = ASTSlotKind::kNode; + break; + case 5: + value_ = reinterpret_cast(ast->lambdaDeclarator); + slotKind_ = ASTSlotKind::kNode; + break; + case 6: + value_ = reinterpret_cast(ast->statement); + slotKind_ = ASTSlotKind::kNode; + break; } // switch - slotCount_ = 3; + slotCount_ = 7; } -void ASTSlot::visit(RefInitLambdaCaptureAST* ast) { +void ASTSlot::visit(SizeofExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->ampLoc.index(); + value_ = ast->sizeofLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->ellipsisLoc.index(); + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; + break; + } // switch + + slotCount_ = 2; +} + +void ASTSlot::visit(SizeofTypeExpressionAST* ast) { + switch (slot_) { + case 0: + value_ = ast->sizeofLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 2: - value_ = ast->identifierLoc.index(); + case 1: + value_ = ast->lparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 3: - value_ = reinterpret_cast(ast->initializer); + case 2: + value_ = reinterpret_cast(ast->typeId); slotKind_ = ASTSlotKind::kNode; break; + case 3: + value_ = ast->rparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; } // switch slotCount_ = 4; } -void ASTSlot::visit(InitLambdaCaptureAST* ast) { +void ASTSlot::visit(SizeofPackExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->ellipsisLoc.index(); + value_ = ast->sizeofLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->identifierLoc.index(); + value_ = ast->ellipsisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = reinterpret_cast(ast->initializer); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 3: + value_ = ast->identifierLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 4: + value_ = ast->rparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 3; + slotCount_ = 5; } -void ASTSlot::visit(EqualInitializerAST* ast) { +void ASTSlot::visit(TypeidExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->equalLoc.index(); + value_ = ast->typeidLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 2: value_ = reinterpret_cast(ast->expression); slotKind_ = ASTSlotKind::kNode; break; + case 3: + value_ = ast->rparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; } // switch - slotCount_ = 2; + slotCount_ = 4; } -void ASTSlot::visit(BracedInitListAST* ast) { +void ASTSlot::visit(TypeidOfTypeExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->lbraceLoc.index(); + value_ = ast->typeidLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = reinterpret_cast(ast->expressionList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = ast->commaLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->typeId); + slotKind_ = ASTSlotKind::kNode; break; case 3: - value_ = ast->rbraceLoc.index(); + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch @@ -900,78 +1010,79 @@ void ASTSlot::visit(BracedInitListAST* ast) { slotCount_ = 4; } -void ASTSlot::visit(ParenInitializerAST* ast) { +void ASTSlot::visit(AlignofExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->lparenLoc.index(); + value_ = ast->alignofLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = reinterpret_cast(ast->expressionList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 2: + value_ = reinterpret_cast(ast->typeId); + slotKind_ = ASTSlotKind::kNode; + break; + case 3: value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 3; + slotCount_ = 4; } -void ASTSlot::visit(NewParenInitializerAST* ast) { +void ASTSlot::visit(TypeTraitsExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->lparenLoc.index(); + value_ = ast->typeTraitsLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = reinterpret_cast(ast->expressionList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 2: + value_ = reinterpret_cast(ast->typeIdList); + slotKind_ = ASTSlotKind::kNodeList; + break; + case 3: value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 3; -} - -void ASTSlot::visit(NewBracedInitializerAST* ast) { - switch (slot_) { - case 0: - value_ = reinterpret_cast(ast->bracedInit); - slotKind_ = ASTSlotKind::kNode; - break; - } // switch - - slotCount_ = 1; + slotCount_ = 4; } -void ASTSlot::visit(EllipsisExceptionDeclarationAST* ast) { +void ASTSlot::visit(UnaryExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->ellipsisLoc.index(); + value_ = ast->opLoc.index(); slotKind_ = ASTSlotKind::kToken; break; + case 1: + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; + break; } // switch - slotCount_ = 1; + slotCount_ = 2; } -void ASTSlot::visit(TypeExceptionDeclarationAST* ast) { +void ASTSlot::visit(BinaryExpressionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->attributeList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = reinterpret_cast(ast->leftExpression); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = reinterpret_cast(ast->typeSpecifierList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = ast->opLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = reinterpret_cast(ast->declarator); + value_ = reinterpret_cast(ast->rightExpression); slotKind_ = ASTSlotKind::kNode; break; } // switch @@ -979,33 +1090,33 @@ void ASTSlot::visit(TypeExceptionDeclarationAST* ast) { slotCount_ = 3; } -void ASTSlot::visit(DefaultFunctionBodyAST* ast) { +void ASTSlot::visit(AssignmentExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->equalLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->leftExpression); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = ast->defaultLoc.index(); + value_ = ast->opLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = ast->semicolonLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->rightExpression); + slotKind_ = ASTSlotKind::kNode; break; } // switch slotCount_ = 3; } -void ASTSlot::visit(CompoundStatementFunctionBodyAST* ast) { +void ASTSlot::visit(BracedTypeConstructionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->ctorInitializer); + value_ = reinterpret_cast(ast->typeSpecifier); slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = reinterpret_cast(ast->statement); + value_ = reinterpret_cast(ast->bracedInitList); slotKind_ = ASTSlotKind::kNode; break; } // switch @@ -1013,75 +1124,91 @@ void ASTSlot::visit(CompoundStatementFunctionBodyAST* ast) { slotCount_ = 2; } -void ASTSlot::visit(TryStatementFunctionBodyAST* ast) { +void ASTSlot::visit(TypeConstructionAST* ast) { switch (slot_) { case 0: - value_ = ast->tryLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->typeSpecifier); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = reinterpret_cast(ast->ctorInitializer); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = reinterpret_cast(ast->statement); - slotKind_ = ASTSlotKind::kNode; + value_ = reinterpret_cast(ast->expressionList); + slotKind_ = ASTSlotKind::kNodeList; break; case 3: - value_ = reinterpret_cast(ast->handlerList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = ast->rparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; } // switch slotCount_ = 4; } -void ASTSlot::visit(DeleteFunctionBodyAST* ast) { +void ASTSlot::visit(CallExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->equalLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->baseExpression); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = ast->deleteLoc.index(); + value_ = ast->lparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = ast->semicolonLoc.index(); + value_ = reinterpret_cast(ast->expressionList); + slotKind_ = ASTSlotKind::kNodeList; + break; + case 3: + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 3; + slotCount_ = 4; } -void ASTSlot::visit(TranslationUnitAST* ast) { +void ASTSlot::visit(SubscriptExpressionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->declarationList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = reinterpret_cast(ast->baseExpression); + slotKind_ = ASTSlotKind::kNode; + break; + case 1: + value_ = ast->lbracketLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 2: + value_ = reinterpret_cast(ast->indexExpression); + slotKind_ = ASTSlotKind::kNode; + break; + case 3: + value_ = ast->rbracketLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 1; + slotCount_ = 4; } -void ASTSlot::visit(ModuleUnitAST* ast) { +void ASTSlot::visit(MemberExpressionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->globalModuleFragment); + value_ = reinterpret_cast(ast->baseExpression); slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = reinterpret_cast(ast->moduleDeclaration); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->accessLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = reinterpret_cast(ast->declarationList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = ast->templateLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 3: - value_ = reinterpret_cast(ast->privateModuleFragment); + value_ = reinterpret_cast(ast->name); slotKind_ = ASTSlotKind::kNode; break; } // switch @@ -1089,125 +1216,160 @@ void ASTSlot::visit(ModuleUnitAST* ast) { slotCount_ = 4; } -void ASTSlot::visit(ThisExpressionAST* ast) { +void ASTSlot::visit(PostIncrExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->thisLoc.index(); + value_ = reinterpret_cast(ast->baseExpression); + slotKind_ = ASTSlotKind::kNode; + break; + case 1: + value_ = ast->opLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 1; + slotCount_ = 2; } -void ASTSlot::visit(CharLiteralExpressionAST* ast) { +void ASTSlot::visit(ConditionalExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->literalLoc.index(); + value_ = reinterpret_cast(ast->condition); + slotKind_ = ASTSlotKind::kNode; + break; + case 1: + value_ = ast->questionLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - } // switch - - slotCount_ = 1; -} - -void ASTSlot::visit(BoolLiteralExpressionAST* ast) { - switch (slot_) { - case 0: - value_ = ast->literalLoc.index(); + case 2: + value_ = reinterpret_cast(ast->iftrueExpression); + slotKind_ = ASTSlotKind::kNode; + break; + case 3: + value_ = ast->colonLoc.index(); slotKind_ = ASTSlotKind::kToken; break; + case 4: + value_ = reinterpret_cast(ast->iffalseExpression); + slotKind_ = ASTSlotKind::kNode; + break; } // switch - slotCount_ = 1; + slotCount_ = 5; } -void ASTSlot::visit(IntLiteralExpressionAST* ast) { +void ASTSlot::visit(ImplicitCastExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->literalLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; break; } // switch slotCount_ = 1; } -void ASTSlot::visit(FloatLiteralExpressionAST* ast) { +void ASTSlot::visit(CastExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->literalLoc.index(); + value_ = ast->lparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - } // switch - - slotCount_ = 1; -} - -void ASTSlot::visit(NullptrLiteralExpressionAST* ast) { - switch (slot_) { - case 0: - value_ = ast->literalLoc.index(); + case 1: + value_ = reinterpret_cast(ast->typeId); + slotKind_ = ASTSlotKind::kNode; + break; + case 2: + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; + case 3: + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; + break; } // switch - slotCount_ = 1; + slotCount_ = 4; } -void ASTSlot::visit(StringLiteralExpressionAST* ast) { +void ASTSlot::visit(CppCastExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->literalLoc.index(); + value_ = ast->castLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - } // switch - - slotCount_ = 1; -} - -void ASTSlot::visit(UserDefinedStringLiteralExpressionAST* ast) { - switch (slot_) { - case 0: - value_ = ast->literalLoc.index(); + case 1: + value_ = ast->lessLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 2: + value_ = reinterpret_cast(ast->typeId); + slotKind_ = ASTSlotKind::kNode; + break; + case 3: + value_ = ast->greaterLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 4: + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 5: + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; + break; + case 6: + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 1; + slotCount_ = 7; } -void ASTSlot::visit(IdExpressionAST* ast) { +void ASTSlot::visit(NewExpressionAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->name); + value_ = ast->scopeLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = ast->newLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 2: + value_ = reinterpret_cast(ast->typeId); + slotKind_ = ASTSlotKind::kNode; + break; + case 3: + value_ = reinterpret_cast(ast->newInitalizer); slotKind_ = ASTSlotKind::kNode; break; } // switch - slotCount_ = 1; + slotCount_ = 4; } -void ASTSlot::visit(RequiresExpressionAST* ast) { +void ASTSlot::visit(DeleteExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->requiresLoc.index(); + value_ = ast->scopeLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->lparenLoc.index(); + value_ = ast->deleteLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = reinterpret_cast(ast->parameterDeclarationClause); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->lbracketLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 3: - value_ = ast->rparenLoc.index(); + value_ = ast->rbracketLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 4: - value_ = reinterpret_cast(ast->requirementBody); + value_ = reinterpret_cast(ast->expression); slotKind_ = ASTSlotKind::kNode; break; } // switch @@ -1215,107 +1377,87 @@ void ASTSlot::visit(RequiresExpressionAST* ast) { slotCount_ = 5; } -void ASTSlot::visit(NestedExpressionAST* ast) { +void ASTSlot::visit(ThrowExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->lparenLoc.index(); + value_ = ast->throwLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: value_ = reinterpret_cast(ast->expression); slotKind_ = ASTSlotKind::kNode; break; - case 2: - value_ = ast->rparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; } // switch - slotCount_ = 3; + slotCount_ = 2; } -void ASTSlot::visit(RightFoldExpressionAST* ast) { +void ASTSlot::visit(NoexceptExpressionAST* ast) { switch (slot_) { case 0: - value_ = ast->lparenLoc.index(); + value_ = ast->noexceptLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = ast->opLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; break; case 3: - value_ = ast->ellipsisLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 4: value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 5; + slotCount_ = 4; } -void ASTSlot::visit(LeftFoldExpressionAST* ast) { +void ASTSlot::visit(SimpleRequirementAST* ast) { switch (slot_) { case 0: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 1: - value_ = ast->ellipsisLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 2: - value_ = ast->opLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 3: value_ = reinterpret_cast(ast->expression); slotKind_ = ASTSlotKind::kNode; break; - case 4: - value_ = ast->rparenLoc.index(); + case 1: + value_ = ast->semicolonLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 5; + slotCount_ = 2; } -void ASTSlot::visit(FoldExpressionAST* ast) { +void ASTSlot::visit(CompoundRequirementAST* ast) { switch (slot_) { case 0: - value_ = ast->lparenLoc.index(); + value_ = ast->lbraceLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = reinterpret_cast(ast->leftExpression); + value_ = reinterpret_cast(ast->expression); slotKind_ = ASTSlotKind::kNode; break; case 2: - value_ = ast->opLoc.index(); + value_ = ast->rbraceLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 3: - value_ = ast->ellipsisLoc.index(); + value_ = ast->noexceptLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 4: - value_ = ast->foldOpLoc.index(); + value_ = ast->minusGreaterLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 5: - value_ = reinterpret_cast(ast->rightExpression); + value_ = reinterpret_cast(ast->typeConstraint); slotKind_ = ASTSlotKind::kNode; break; case 6: - value_ = ast->rparenLoc.index(); + value_ = ast->semicolonLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch @@ -1323,99 +1465,90 @@ void ASTSlot::visit(FoldExpressionAST* ast) { slotCount_ = 7; } -void ASTSlot::visit(LambdaExpressionAST* ast) { +void ASTSlot::visit(TypeRequirementAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->lambdaIntroducer); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->typenameLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->lessLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->nestedNameSpecifier); + slotKind_ = ASTSlotKind::kNode; break; case 2: - value_ = reinterpret_cast(ast->templateParameterList); - slotKind_ = ASTSlotKind::kNodeList; + value_ = reinterpret_cast(ast->name); + slotKind_ = ASTSlotKind::kNode; break; case 3: - value_ = ast->greaterLoc.index(); + value_ = ast->semicolonLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 4: - value_ = reinterpret_cast(ast->requiresClause); - slotKind_ = ASTSlotKind::kNode; - break; - case 5: - value_ = reinterpret_cast(ast->lambdaDeclarator); - slotKind_ = ASTSlotKind::kNode; - break; - case 6: - value_ = reinterpret_cast(ast->statement); - slotKind_ = ASTSlotKind::kNode; - break; } // switch - slotCount_ = 7; + slotCount_ = 4; } -void ASTSlot::visit(SizeofExpressionAST* ast) { +void ASTSlot::visit(NestedRequirementAST* ast) { switch (slot_) { case 0: - value_ = ast->sizeofLoc.index(); + value_ = ast->requiresLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: value_ = reinterpret_cast(ast->expression); slotKind_ = ASTSlotKind::kNode; break; + case 2: + value_ = ast->semicolonLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; } // switch - slotCount_ = 2; + slotCount_ = 3; } -void ASTSlot::visit(SizeofTypeExpressionAST* ast) { +void ASTSlot::visit(TypeTemplateArgumentAST* ast) { switch (slot_) { case 0: - value_ = ast->sizeofLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 1: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 2: value_ = reinterpret_cast(ast->typeId); slotKind_ = ASTSlotKind::kNode; break; - case 3: - value_ = ast->rparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; + } // switch + + slotCount_ = 1; +} + +void ASTSlot::visit(ExpressionTemplateArgumentAST* ast) { + switch (slot_) { + case 0: + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; break; } // switch - slotCount_ = 4; + slotCount_ = 1; } -void ASTSlot::visit(SizeofPackExpressionAST* ast) { +void ASTSlot::visit(ParenMemInitializerAST* ast) { switch (slot_) { case 0: - value_ = ast->sizeofLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->name); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = ast->ellipsisLoc.index(); + value_ = ast->lparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->expressionList); + slotKind_ = ASTSlotKind::kNodeList; break; case 3: - value_ = ast->identifierLoc.index(); + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 4: - value_ = ast->rparenLoc.index(); + value_ = ast->ellipsisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch @@ -1423,144 +1556,120 @@ void ASTSlot::visit(SizeofPackExpressionAST* ast) { slotCount_ = 5; } -void ASTSlot::visit(TypeidExpressionAST* ast) { +void ASTSlot::visit(BracedMemInitializerAST* ast) { switch (slot_) { case 0: - value_ = ast->typeidLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->name); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 2: - value_ = reinterpret_cast(ast->expression); + value_ = reinterpret_cast(ast->bracedInitList); slotKind_ = ASTSlotKind::kNode; break; - case 3: - value_ = ast->rparenLoc.index(); + case 2: + value_ = ast->ellipsisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 4; + slotCount_ = 3; } -void ASTSlot::visit(TypeidOfTypeExpressionAST* ast) { +void ASTSlot::visit(ThisLambdaCaptureAST* ast) { switch (slot_) { case 0: - value_ = ast->typeidLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 1: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 2: - value_ = reinterpret_cast(ast->typeId); - slotKind_ = ASTSlotKind::kNode; - break; - case 3: - value_ = ast->rparenLoc.index(); + value_ = ast->thisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 4; + slotCount_ = 1; } -void ASTSlot::visit(AlignofExpressionAST* ast) { +void ASTSlot::visit(DerefThisLambdaCaptureAST* ast) { switch (slot_) { case 0: - value_ = ast->alignofLoc.index(); + value_ = ast->starLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 2: - value_ = reinterpret_cast(ast->typeId); - slotKind_ = ASTSlotKind::kNode; - break; - case 3: - value_ = ast->rparenLoc.index(); + value_ = ast->thisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 4; + slotCount_ = 2; } -void ASTSlot::visit(TypeTraitsExpressionAST* ast) { +void ASTSlot::visit(SimpleLambdaCaptureAST* ast) { switch (slot_) { case 0: - value_ = ast->typeTraitsLoc.index(); + value_ = ast->identifierLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 2: - value_ = reinterpret_cast(ast->typeIdList); - slotKind_ = ASTSlotKind::kNodeList; - break; - case 3: - value_ = ast->rparenLoc.index(); + value_ = ast->ellipsisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 4; + slotCount_ = 2; } -void ASTSlot::visit(UnaryExpressionAST* ast) { +void ASTSlot::visit(RefLambdaCaptureAST* ast) { switch (slot_) { case 0: - value_ = ast->opLoc.index(); + value_ = ast->ampLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = ast->identifierLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 1: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; + case 2: + value_ = ast->ellipsisLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 2; + slotCount_ = 3; } -void ASTSlot::visit(BinaryExpressionAST* ast) { +void ASTSlot::visit(RefInitLambdaCaptureAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->leftExpression); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->ampLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->opLoc.index(); + value_ = ast->ellipsisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = reinterpret_cast(ast->rightExpression); + value_ = ast->identifierLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 3: + value_ = reinterpret_cast(ast->initializer); slotKind_ = ASTSlotKind::kNode; break; } // switch - slotCount_ = 3; + slotCount_ = 4; } -void ASTSlot::visit(AssignmentExpressionAST* ast) { +void ASTSlot::visit(InitLambdaCaptureAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->leftExpression); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->ellipsisLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->opLoc.index(); + value_ = ast->identifierLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = reinterpret_cast(ast->rightExpression); + value_ = reinterpret_cast(ast->initializer); slotKind_ = ASTSlotKind::kNode; break; } // switch @@ -1568,14 +1677,14 @@ void ASTSlot::visit(AssignmentExpressionAST* ast) { slotCount_ = 3; } -void ASTSlot::visit(BracedTypeConstructionAST* ast) { +void ASTSlot::visit(EqualInitializerAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->typeSpecifier); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->equalLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = reinterpret_cast(ast->bracedInitList); + value_ = reinterpret_cast(ast->expression); slotKind_ = ASTSlotKind::kNode; break; } // switch @@ -1583,22 +1692,22 @@ void ASTSlot::visit(BracedTypeConstructionAST* ast) { slotCount_ = 2; } -void ASTSlot::visit(TypeConstructionAST* ast) { +void ASTSlot::visit(BracedInitListAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->typeSpecifier); - slotKind_ = ASTSlotKind::kNode; - break; - case 1: - value_ = ast->lparenLoc.index(); + value_ = ast->lbraceLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 2: + case 1: value_ = reinterpret_cast(ast->expressionList); slotKind_ = ASTSlotKind::kNodeList; break; + case 2: + value_ = ast->commaLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; case 3: - value_ = ast->rparenLoc.index(); + value_ = ast->rbraceLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch @@ -1606,213 +1715,146 @@ void ASTSlot::visit(TypeConstructionAST* ast) { slotCount_ = 4; } -void ASTSlot::visit(CallExpressionAST* ast) { +void ASTSlot::visit(ParenInitializerAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->baseExpression); - slotKind_ = ASTSlotKind::kNode; - break; - case 1: value_ = ast->lparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 2: + case 1: value_ = reinterpret_cast(ast->expressionList); slotKind_ = ASTSlotKind::kNodeList; break; - case 3: + case 2: value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 4; + slotCount_ = 3; } -void ASTSlot::visit(SubscriptExpressionAST* ast) { +void ASTSlot::visit(NewParenInitializerAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->baseExpression); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->lbracketLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->expressionList); + slotKind_ = ASTSlotKind::kNodeList; break; case 2: - value_ = reinterpret_cast(ast->indexExpression); - slotKind_ = ASTSlotKind::kNode; - break; - case 3: - value_ = ast->rbracketLoc.index(); + value_ = ast->rparenLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 4; + slotCount_ = 3; } -void ASTSlot::visit(MemberExpressionAST* ast) { +void ASTSlot::visit(NewBracedInitializerAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->baseExpression); - slotKind_ = ASTSlotKind::kNode; - break; - case 1: - value_ = ast->accessLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 2: - value_ = ast->templateLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 3: - value_ = reinterpret_cast(ast->name); + value_ = reinterpret_cast(ast->bracedInit); slotKind_ = ASTSlotKind::kNode; break; } // switch - slotCount_ = 4; + slotCount_ = 1; } -void ASTSlot::visit(PostIncrExpressionAST* ast) { +void ASTSlot::visit(EllipsisExceptionDeclarationAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->baseExpression); - slotKind_ = ASTSlotKind::kNode; - break; - case 1: - value_ = ast->opLoc.index(); + value_ = ast->ellipsisLoc.index(); slotKind_ = ASTSlotKind::kToken; break; } // switch - slotCount_ = 2; + slotCount_ = 1; } -void ASTSlot::visit(ConditionalExpressionAST* ast) { +void ASTSlot::visit(TypeExceptionDeclarationAST* ast) { switch (slot_) { case 0: - value_ = reinterpret_cast(ast->condition); - slotKind_ = ASTSlotKind::kNode; + value_ = reinterpret_cast(ast->attributeList); + slotKind_ = ASTSlotKind::kNodeList; break; case 1: - value_ = ast->questionLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->typeSpecifierList); + slotKind_ = ASTSlotKind::kNodeList; break; case 2: - value_ = reinterpret_cast(ast->iftrueExpression); - slotKind_ = ASTSlotKind::kNode; - break; - case 3: - value_ = ast->colonLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 4: - value_ = reinterpret_cast(ast->iffalseExpression); - slotKind_ = ASTSlotKind::kNode; - break; - } // switch - - slotCount_ = 5; -} - -void ASTSlot::visit(ImplicitCastExpressionAST* ast) { - switch (slot_) { - case 0: - value_ = reinterpret_cast(ast->expression); + value_ = reinterpret_cast(ast->declarator); slotKind_ = ASTSlotKind::kNode; break; } // switch - slotCount_ = 1; + slotCount_ = 3; } -void ASTSlot::visit(CastExpressionAST* ast) { +void ASTSlot::visit(DefaultFunctionBodyAST* ast) { switch (slot_) { case 0: - value_ = ast->lparenLoc.index(); + value_ = ast->equalLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = reinterpret_cast(ast->typeId); - slotKind_ = ASTSlotKind::kNode; + value_ = ast->defaultLoc.index(); + slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = ast->rparenLoc.index(); + value_ = ast->semicolonLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 3: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; - break; } // switch - slotCount_ = 4; + slotCount_ = 3; } -void ASTSlot::visit(CppCastExpressionAST* ast) { +void ASTSlot::visit(CompoundStatementFunctionBodyAST* ast) { switch (slot_) { case 0: - value_ = ast->castLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 1: - value_ = ast->lessLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 2: - value_ = reinterpret_cast(ast->typeId); + value_ = reinterpret_cast(ast->ctorInitializer); slotKind_ = ASTSlotKind::kNode; break; - case 3: - value_ = ast->greaterLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 4: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 5: - value_ = reinterpret_cast(ast->expression); + case 1: + value_ = reinterpret_cast(ast->statement); slotKind_ = ASTSlotKind::kNode; break; - case 6: - value_ = ast->rparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; } // switch - slotCount_ = 7; + slotCount_ = 2; } -void ASTSlot::visit(NewExpressionAST* ast) { +void ASTSlot::visit(TryStatementFunctionBodyAST* ast) { switch (slot_) { case 0: - value_ = ast->scopeLoc.index(); + value_ = ast->tryLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: - value_ = ast->newLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->ctorInitializer); + slotKind_ = ASTSlotKind::kNode; break; case 2: - value_ = reinterpret_cast(ast->typeId); + value_ = reinterpret_cast(ast->statement); slotKind_ = ASTSlotKind::kNode; break; case 3: - value_ = reinterpret_cast(ast->newInitalizer); - slotKind_ = ASTSlotKind::kNode; + value_ = reinterpret_cast(ast->handlerList); + slotKind_ = ASTSlotKind::kNodeList; break; } // switch slotCount_ = 4; } -void ASTSlot::visit(DeleteExpressionAST* ast) { +void ASTSlot::visit(DeleteFunctionBodyAST* ast) { switch (slot_) { case 0: - value_ = ast->scopeLoc.index(); + value_ = ast->equalLoc.index(); slotKind_ = ASTSlotKind::kToken; break; case 1: @@ -1820,54 +1862,42 @@ void ASTSlot::visit(DeleteExpressionAST* ast) { slotKind_ = ASTSlotKind::kToken; break; case 2: - value_ = ast->lbracketLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 3: - value_ = ast->rbracketLoc.index(); + value_ = ast->semicolonLoc.index(); slotKind_ = ASTSlotKind::kToken; break; - case 4: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; - break; } // switch - slotCount_ = 5; + slotCount_ = 3; } -void ASTSlot::visit(ThrowExpressionAST* ast) { +void ASTSlot::visit(TranslationUnitAST* ast) { switch (slot_) { case 0: - value_ = ast->throwLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 1: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; + value_ = reinterpret_cast(ast->declarationList); + slotKind_ = ASTSlotKind::kNodeList; break; } // switch - slotCount_ = 2; + slotCount_ = 1; } -void ASTSlot::visit(NoexceptExpressionAST* ast) { +void ASTSlot::visit(ModuleUnitAST* ast) { switch (slot_) { case 0: - value_ = ast->noexceptLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->globalModuleFragment); + slotKind_ = ASTSlotKind::kNode; break; case 1: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->moduleDeclaration); + slotKind_ = ASTSlotKind::kNode; break; case 2: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; + value_ = reinterpret_cast(ast->declarationList); + slotKind_ = ASTSlotKind::kNodeList; break; case 3: - value_ = ast->rparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; + value_ = reinterpret_cast(ast->privateModuleFragment); + slotKind_ = ASTSlotKind::kNode; break; } // switch diff --git a/src/parser/cxx/ast_slot.h b/src/parser/cxx/ast_slot.h index af1c3b7c..c78943e9 100644 --- a/src/parser/cxx/ast_slot.h +++ b/src/parser/cxx/ast_slot.h @@ -70,43 +70,9 @@ class ASTSlot final : ASTVisitor { void visit(AttributeArgumentClauseAST* ast) override; void visit(AttributeAST* ast) override; void visit(AttributeUsingPrefixAST* ast) override; + void visit(DesignatorAST* ast) override; - void visit(SimpleRequirementAST* ast) override; - void visit(CompoundRequirementAST* ast) override; - void visit(TypeRequirementAST* ast) override; - void visit(NestedRequirementAST* ast) override; - - void visit(TypeTemplateArgumentAST* ast) override; - void visit(ExpressionTemplateArgumentAST* ast) override; - - void visit(ParenMemInitializerAST* ast) override; - void visit(BracedMemInitializerAST* ast) override; - - void visit(ThisLambdaCaptureAST* ast) override; - void visit(DerefThisLambdaCaptureAST* ast) override; - void visit(SimpleLambdaCaptureAST* ast) override; - void visit(RefLambdaCaptureAST* ast) override; - void visit(RefInitLambdaCaptureAST* ast) override; - void visit(InitLambdaCaptureAST* ast) override; - - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - - void visit(NewParenInitializerAST* ast) override; - void visit(NewBracedInitializerAST* ast) override; - - void visit(EllipsisExceptionDeclarationAST* ast) override; - void visit(TypeExceptionDeclarationAST* ast) override; - - void visit(DefaultFunctionBodyAST* ast) override; - void visit(CompoundStatementFunctionBodyAST* ast) override; - void visit(TryStatementFunctionBodyAST* ast) override; - void visit(DeleteFunctionBodyAST* ast) override; - - void visit(TranslationUnitAST* ast) override; - void visit(ModuleUnitAST* ast) override; - + void visit(DesignatedInitializerClauseAST* ast) override; void visit(ThisExpressionAST* ast) override; void visit(CharLiteralExpressionAST* ast) override; void visit(BoolLiteralExpressionAST* ast) override; @@ -147,6 +113,42 @@ class ASTSlot final : ASTVisitor { void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(SimpleRequirementAST* ast) override; + void visit(CompoundRequirementAST* ast) override; + void visit(TypeRequirementAST* ast) override; + void visit(NestedRequirementAST* ast) override; + + void visit(TypeTemplateArgumentAST* ast) override; + void visit(ExpressionTemplateArgumentAST* ast) override; + + void visit(ParenMemInitializerAST* ast) override; + void visit(BracedMemInitializerAST* ast) override; + + void visit(ThisLambdaCaptureAST* ast) override; + void visit(DerefThisLambdaCaptureAST* ast) override; + void visit(SimpleLambdaCaptureAST* ast) override; + void visit(RefLambdaCaptureAST* ast) override; + void visit(RefInitLambdaCaptureAST* ast) override; + void visit(InitLambdaCaptureAST* ast) override; + + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; + + void visit(NewParenInitializerAST* ast) override; + void visit(NewBracedInitializerAST* ast) override; + + void visit(EllipsisExceptionDeclarationAST* ast) override; + void visit(TypeExceptionDeclarationAST* ast) override; + + void visit(DefaultFunctionBodyAST* ast) override; + void visit(CompoundStatementFunctionBodyAST* ast) override; + void visit(TryStatementFunctionBodyAST* ast) override; + void visit(DeleteFunctionBodyAST* ast) override; + + void visit(TranslationUnitAST* ast) override; + void visit(ModuleUnitAST* ast) override; + void visit(LabeledStatementAST* ast) override; void visit(CaseStatementAST* ast) override; void visit(DefaultStatementAST* ast) override; diff --git a/src/parser/cxx/ast_visitor.h b/src/parser/cxx/ast_visitor.h index e7db921a..b24678a0 100644 --- a/src/parser/cxx/ast_visitor.h +++ b/src/parser/cxx/ast_visitor.h @@ -58,6 +58,49 @@ class ASTVisitor { virtual void visit(AttributeArgumentClauseAST* ast) = 0; virtual void visit(AttributeAST* ast) = 0; virtual void visit(AttributeUsingPrefixAST* ast) = 0; + virtual void visit(DesignatorAST* ast) = 0; + + // ExpressionAST + virtual void visit(DesignatedInitializerClauseAST* ast) = 0; + virtual void visit(ThisExpressionAST* ast) = 0; + virtual void visit(CharLiteralExpressionAST* ast) = 0; + virtual void visit(BoolLiteralExpressionAST* ast) = 0; + virtual void visit(IntLiteralExpressionAST* ast) = 0; + virtual void visit(FloatLiteralExpressionAST* ast) = 0; + virtual void visit(NullptrLiteralExpressionAST* ast) = 0; + virtual void visit(StringLiteralExpressionAST* ast) = 0; + virtual void visit(UserDefinedStringLiteralExpressionAST* ast) = 0; + virtual void visit(IdExpressionAST* ast) = 0; + virtual void visit(RequiresExpressionAST* ast) = 0; + virtual void visit(NestedExpressionAST* ast) = 0; + virtual void visit(RightFoldExpressionAST* ast) = 0; + virtual void visit(LeftFoldExpressionAST* ast) = 0; + virtual void visit(FoldExpressionAST* ast) = 0; + virtual void visit(LambdaExpressionAST* ast) = 0; + virtual void visit(SizeofExpressionAST* ast) = 0; + virtual void visit(SizeofTypeExpressionAST* ast) = 0; + virtual void visit(SizeofPackExpressionAST* ast) = 0; + virtual void visit(TypeidExpressionAST* ast) = 0; + virtual void visit(TypeidOfTypeExpressionAST* ast) = 0; + virtual void visit(AlignofExpressionAST* ast) = 0; + virtual void visit(TypeTraitsExpressionAST* ast) = 0; + virtual void visit(UnaryExpressionAST* ast) = 0; + virtual void visit(BinaryExpressionAST* ast) = 0; + virtual void visit(AssignmentExpressionAST* ast) = 0; + virtual void visit(BracedTypeConstructionAST* ast) = 0; + virtual void visit(TypeConstructionAST* ast) = 0; + virtual void visit(CallExpressionAST* ast) = 0; + virtual void visit(SubscriptExpressionAST* ast) = 0; + virtual void visit(MemberExpressionAST* ast) = 0; + virtual void visit(PostIncrExpressionAST* ast) = 0; + virtual void visit(ConditionalExpressionAST* ast) = 0; + virtual void visit(ImplicitCastExpressionAST* ast) = 0; + virtual void visit(CastExpressionAST* ast) = 0; + virtual void visit(CppCastExpressionAST* ast) = 0; + virtual void visit(NewExpressionAST* ast) = 0; + virtual void visit(DeleteExpressionAST* ast) = 0; + virtual void visit(ThrowExpressionAST* ast) = 0; + virtual void visit(NoexceptExpressionAST* ast) = 0; // RequirementAST virtual void visit(SimpleRequirementAST* ast) = 0; @@ -104,47 +147,6 @@ class ASTVisitor { virtual void visit(TranslationUnitAST* ast) = 0; virtual void visit(ModuleUnitAST* ast) = 0; - // ExpressionAST - virtual void visit(ThisExpressionAST* ast) = 0; - virtual void visit(CharLiteralExpressionAST* ast) = 0; - virtual void visit(BoolLiteralExpressionAST* ast) = 0; - virtual void visit(IntLiteralExpressionAST* ast) = 0; - virtual void visit(FloatLiteralExpressionAST* ast) = 0; - virtual void visit(NullptrLiteralExpressionAST* ast) = 0; - virtual void visit(StringLiteralExpressionAST* ast) = 0; - virtual void visit(UserDefinedStringLiteralExpressionAST* ast) = 0; - virtual void visit(IdExpressionAST* ast) = 0; - virtual void visit(RequiresExpressionAST* ast) = 0; - virtual void visit(NestedExpressionAST* ast) = 0; - virtual void visit(RightFoldExpressionAST* ast) = 0; - virtual void visit(LeftFoldExpressionAST* ast) = 0; - virtual void visit(FoldExpressionAST* ast) = 0; - virtual void visit(LambdaExpressionAST* ast) = 0; - virtual void visit(SizeofExpressionAST* ast) = 0; - virtual void visit(SizeofTypeExpressionAST* ast) = 0; - virtual void visit(SizeofPackExpressionAST* ast) = 0; - virtual void visit(TypeidExpressionAST* ast) = 0; - virtual void visit(TypeidOfTypeExpressionAST* ast) = 0; - virtual void visit(AlignofExpressionAST* ast) = 0; - virtual void visit(TypeTraitsExpressionAST* ast) = 0; - virtual void visit(UnaryExpressionAST* ast) = 0; - virtual void visit(BinaryExpressionAST* ast) = 0; - virtual void visit(AssignmentExpressionAST* ast) = 0; - virtual void visit(BracedTypeConstructionAST* ast) = 0; - virtual void visit(TypeConstructionAST* ast) = 0; - virtual void visit(CallExpressionAST* ast) = 0; - virtual void visit(SubscriptExpressionAST* ast) = 0; - virtual void visit(MemberExpressionAST* ast) = 0; - virtual void visit(PostIncrExpressionAST* ast) = 0; - virtual void visit(ConditionalExpressionAST* ast) = 0; - virtual void visit(ImplicitCastExpressionAST* ast) = 0; - virtual void visit(CastExpressionAST* ast) = 0; - virtual void visit(CppCastExpressionAST* ast) = 0; - virtual void visit(NewExpressionAST* ast) = 0; - virtual void visit(DeleteExpressionAST* ast) = 0; - virtual void visit(ThrowExpressionAST* ast) = 0; - virtual void visit(NoexceptExpressionAST* ast) = 0; - // StatementAST virtual void visit(LabeledStatementAST* ast) = 0; virtual void visit(CaseStatementAST* ast) = 0; diff --git a/src/parser/cxx/default_ast_visitor.cc b/src/parser/cxx/default_ast_visitor.cc index a7261260..062fad86 100644 --- a/src/parser/cxx/default_ast_visitor.cc +++ b/src/parser/cxx/default_ast_visitor.cc @@ -142,124 +142,15 @@ void DefaultASTVisitor::visit(AttributeUsingPrefixAST* ast) { cxx_runtime_error("visit(AttributeUsingPrefixAST): not implemented"); } -// RequirementAST -void DefaultASTVisitor::visit(SimpleRequirementAST* ast) { - cxx_runtime_error("visit(SimpleRequirementAST): not implemented"); -} - -void DefaultASTVisitor::visit(CompoundRequirementAST* ast) { - cxx_runtime_error("visit(CompoundRequirementAST): not implemented"); -} - -void DefaultASTVisitor::visit(TypeRequirementAST* ast) { - cxx_runtime_error("visit(TypeRequirementAST): not implemented"); -} - -void DefaultASTVisitor::visit(NestedRequirementAST* ast) { - cxx_runtime_error("visit(NestedRequirementAST): not implemented"); -} - -// TemplateArgumentAST -void DefaultASTVisitor::visit(TypeTemplateArgumentAST* ast) { - cxx_runtime_error("visit(TypeTemplateArgumentAST): not implemented"); -} - -void DefaultASTVisitor::visit(ExpressionTemplateArgumentAST* ast) { - cxx_runtime_error("visit(ExpressionTemplateArgumentAST): not implemented"); -} - -// MemInitializerAST -void DefaultASTVisitor::visit(ParenMemInitializerAST* ast) { - cxx_runtime_error("visit(ParenMemInitializerAST): not implemented"); -} - -void DefaultASTVisitor::visit(BracedMemInitializerAST* ast) { - cxx_runtime_error("visit(BracedMemInitializerAST): not implemented"); -} - -// LambdaCaptureAST -void DefaultASTVisitor::visit(ThisLambdaCaptureAST* ast) { - cxx_runtime_error("visit(ThisLambdaCaptureAST): not implemented"); -} - -void DefaultASTVisitor::visit(DerefThisLambdaCaptureAST* ast) { - cxx_runtime_error("visit(DerefThisLambdaCaptureAST): not implemented"); -} - -void DefaultASTVisitor::visit(SimpleLambdaCaptureAST* ast) { - cxx_runtime_error("visit(SimpleLambdaCaptureAST): not implemented"); -} - -void DefaultASTVisitor::visit(RefLambdaCaptureAST* ast) { - cxx_runtime_error("visit(RefLambdaCaptureAST): not implemented"); -} - -void DefaultASTVisitor::visit(RefInitLambdaCaptureAST* ast) { - cxx_runtime_error("visit(RefInitLambdaCaptureAST): not implemented"); -} - -void DefaultASTVisitor::visit(InitLambdaCaptureAST* ast) { - cxx_runtime_error("visit(InitLambdaCaptureAST): not implemented"); +void DefaultASTVisitor::visit(DesignatorAST* ast) { + cxx_runtime_error("visit(DesignatorAST): not implemented"); } -// InitializerAST -void DefaultASTVisitor::visit(EqualInitializerAST* ast) { - cxx_runtime_error("visit(EqualInitializerAST): not implemented"); -} - -void DefaultASTVisitor::visit(BracedInitListAST* ast) { - cxx_runtime_error("visit(BracedInitListAST): not implemented"); -} - -void DefaultASTVisitor::visit(ParenInitializerAST* ast) { - cxx_runtime_error("visit(ParenInitializerAST): not implemented"); -} - -// NewInitializerAST -void DefaultASTVisitor::visit(NewParenInitializerAST* ast) { - cxx_runtime_error("visit(NewParenInitializerAST): not implemented"); -} - -void DefaultASTVisitor::visit(NewBracedInitializerAST* ast) { - cxx_runtime_error("visit(NewBracedInitializerAST): not implemented"); -} - -// ExceptionDeclarationAST -void DefaultASTVisitor::visit(EllipsisExceptionDeclarationAST* ast) { - cxx_runtime_error("visit(EllipsisExceptionDeclarationAST): not implemented"); -} - -void DefaultASTVisitor::visit(TypeExceptionDeclarationAST* ast) { - cxx_runtime_error("visit(TypeExceptionDeclarationAST): not implemented"); -} - -// FunctionBodyAST -void DefaultASTVisitor::visit(DefaultFunctionBodyAST* ast) { - cxx_runtime_error("visit(DefaultFunctionBodyAST): not implemented"); -} - -void DefaultASTVisitor::visit(CompoundStatementFunctionBodyAST* ast) { - cxx_runtime_error("visit(CompoundStatementFunctionBodyAST): not implemented"); -} - -void DefaultASTVisitor::visit(TryStatementFunctionBodyAST* ast) { - cxx_runtime_error("visit(TryStatementFunctionBodyAST): not implemented"); -} - -void DefaultASTVisitor::visit(DeleteFunctionBodyAST* ast) { - cxx_runtime_error("visit(DeleteFunctionBodyAST): not implemented"); -} - -// UnitAST -void DefaultASTVisitor::visit(TranslationUnitAST* ast) { - cxx_runtime_error("visit(TranslationUnitAST): not implemented"); -} - -void DefaultASTVisitor::visit(ModuleUnitAST* ast) { - cxx_runtime_error("visit(ModuleUnitAST): not implemented"); +// ExpressionAST +void DefaultASTVisitor::visit(DesignatedInitializerClauseAST* ast) { + cxx_runtime_error("visit(DesignatedInitializerClauseAST): not implemented"); } -// ExpressionAST void DefaultASTVisitor::visit(ThisExpressionAST* ast) { cxx_runtime_error("visit(ThisExpressionAST): not implemented"); } @@ -417,6 +308,123 @@ void DefaultASTVisitor::visit(NoexceptExpressionAST* ast) { cxx_runtime_error("visit(NoexceptExpressionAST): not implemented"); } +// RequirementAST +void DefaultASTVisitor::visit(SimpleRequirementAST* ast) { + cxx_runtime_error("visit(SimpleRequirementAST): not implemented"); +} + +void DefaultASTVisitor::visit(CompoundRequirementAST* ast) { + cxx_runtime_error("visit(CompoundRequirementAST): not implemented"); +} + +void DefaultASTVisitor::visit(TypeRequirementAST* ast) { + cxx_runtime_error("visit(TypeRequirementAST): not implemented"); +} + +void DefaultASTVisitor::visit(NestedRequirementAST* ast) { + cxx_runtime_error("visit(NestedRequirementAST): not implemented"); +} + +// TemplateArgumentAST +void DefaultASTVisitor::visit(TypeTemplateArgumentAST* ast) { + cxx_runtime_error("visit(TypeTemplateArgumentAST): not implemented"); +} + +void DefaultASTVisitor::visit(ExpressionTemplateArgumentAST* ast) { + cxx_runtime_error("visit(ExpressionTemplateArgumentAST): not implemented"); +} + +// MemInitializerAST +void DefaultASTVisitor::visit(ParenMemInitializerAST* ast) { + cxx_runtime_error("visit(ParenMemInitializerAST): not implemented"); +} + +void DefaultASTVisitor::visit(BracedMemInitializerAST* ast) { + cxx_runtime_error("visit(BracedMemInitializerAST): not implemented"); +} + +// LambdaCaptureAST +void DefaultASTVisitor::visit(ThisLambdaCaptureAST* ast) { + cxx_runtime_error("visit(ThisLambdaCaptureAST): not implemented"); +} + +void DefaultASTVisitor::visit(DerefThisLambdaCaptureAST* ast) { + cxx_runtime_error("visit(DerefThisLambdaCaptureAST): not implemented"); +} + +void DefaultASTVisitor::visit(SimpleLambdaCaptureAST* ast) { + cxx_runtime_error("visit(SimpleLambdaCaptureAST): not implemented"); +} + +void DefaultASTVisitor::visit(RefLambdaCaptureAST* ast) { + cxx_runtime_error("visit(RefLambdaCaptureAST): not implemented"); +} + +void DefaultASTVisitor::visit(RefInitLambdaCaptureAST* ast) { + cxx_runtime_error("visit(RefInitLambdaCaptureAST): not implemented"); +} + +void DefaultASTVisitor::visit(InitLambdaCaptureAST* ast) { + cxx_runtime_error("visit(InitLambdaCaptureAST): not implemented"); +} + +// InitializerAST +void DefaultASTVisitor::visit(EqualInitializerAST* ast) { + cxx_runtime_error("visit(EqualInitializerAST): not implemented"); +} + +void DefaultASTVisitor::visit(BracedInitListAST* ast) { + cxx_runtime_error("visit(BracedInitListAST): not implemented"); +} + +void DefaultASTVisitor::visit(ParenInitializerAST* ast) { + cxx_runtime_error("visit(ParenInitializerAST): not implemented"); +} + +// NewInitializerAST +void DefaultASTVisitor::visit(NewParenInitializerAST* ast) { + cxx_runtime_error("visit(NewParenInitializerAST): not implemented"); +} + +void DefaultASTVisitor::visit(NewBracedInitializerAST* ast) { + cxx_runtime_error("visit(NewBracedInitializerAST): not implemented"); +} + +// ExceptionDeclarationAST +void DefaultASTVisitor::visit(EllipsisExceptionDeclarationAST* ast) { + cxx_runtime_error("visit(EllipsisExceptionDeclarationAST): not implemented"); +} + +void DefaultASTVisitor::visit(TypeExceptionDeclarationAST* ast) { + cxx_runtime_error("visit(TypeExceptionDeclarationAST): not implemented"); +} + +// FunctionBodyAST +void DefaultASTVisitor::visit(DefaultFunctionBodyAST* ast) { + cxx_runtime_error("visit(DefaultFunctionBodyAST): not implemented"); +} + +void DefaultASTVisitor::visit(CompoundStatementFunctionBodyAST* ast) { + cxx_runtime_error("visit(CompoundStatementFunctionBodyAST): not implemented"); +} + +void DefaultASTVisitor::visit(TryStatementFunctionBodyAST* ast) { + cxx_runtime_error("visit(TryStatementFunctionBodyAST): not implemented"); +} + +void DefaultASTVisitor::visit(DeleteFunctionBodyAST* ast) { + cxx_runtime_error("visit(DeleteFunctionBodyAST): not implemented"); +} + +// UnitAST +void DefaultASTVisitor::visit(TranslationUnitAST* ast) { + cxx_runtime_error("visit(TranslationUnitAST): not implemented"); +} + +void DefaultASTVisitor::visit(ModuleUnitAST* ast) { + cxx_runtime_error("visit(ModuleUnitAST): not implemented"); +} + // StatementAST void DefaultASTVisitor::visit(LabeledStatementAST* ast) { cxx_runtime_error("visit(LabeledStatementAST): not implemented"); diff --git a/src/parser/cxx/default_ast_visitor.h b/src/parser/cxx/default_ast_visitor.h index 24c9990f..77e120eb 100644 --- a/src/parser/cxx/default_ast_visitor.h +++ b/src/parser/cxx/default_ast_visitor.h @@ -56,6 +56,49 @@ class DefaultASTVisitor : public ASTVisitor { void visit(AttributeArgumentClauseAST* ast) override; void visit(AttributeAST* ast) override; void visit(AttributeUsingPrefixAST* ast) override; + void visit(DesignatorAST* ast) override; + + // ExpressionAST + void visit(DesignatedInitializerClauseAST* ast) override; + void visit(ThisExpressionAST* ast) override; + void visit(CharLiteralExpressionAST* ast) override; + void visit(BoolLiteralExpressionAST* ast) override; + void visit(IntLiteralExpressionAST* ast) override; + void visit(FloatLiteralExpressionAST* ast) override; + void visit(NullptrLiteralExpressionAST* ast) override; + void visit(StringLiteralExpressionAST* ast) override; + void visit(UserDefinedStringLiteralExpressionAST* ast) override; + void visit(IdExpressionAST* ast) override; + void visit(RequiresExpressionAST* ast) override; + void visit(NestedExpressionAST* ast) override; + void visit(RightFoldExpressionAST* ast) override; + void visit(LeftFoldExpressionAST* ast) override; + void visit(FoldExpressionAST* ast) override; + void visit(LambdaExpressionAST* ast) override; + void visit(SizeofExpressionAST* ast) override; + void visit(SizeofTypeExpressionAST* ast) override; + void visit(SizeofPackExpressionAST* ast) override; + void visit(TypeidExpressionAST* ast) override; + void visit(TypeidOfTypeExpressionAST* ast) override; + void visit(AlignofExpressionAST* ast) override; + void visit(TypeTraitsExpressionAST* ast) override; + void visit(UnaryExpressionAST* ast) override; + void visit(BinaryExpressionAST* ast) override; + void visit(AssignmentExpressionAST* ast) override; + void visit(BracedTypeConstructionAST* ast) override; + void visit(TypeConstructionAST* ast) override; + void visit(CallExpressionAST* ast) override; + void visit(SubscriptExpressionAST* ast) override; + void visit(MemberExpressionAST* ast) override; + void visit(PostIncrExpressionAST* ast) override; + void visit(ConditionalExpressionAST* ast) override; + void visit(ImplicitCastExpressionAST* ast) override; + void visit(CastExpressionAST* ast) override; + void visit(CppCastExpressionAST* ast) override; + void visit(NewExpressionAST* ast) override; + void visit(DeleteExpressionAST* ast) override; + void visit(ThrowExpressionAST* ast) override; + void visit(NoexceptExpressionAST* ast) override; // RequirementAST void visit(SimpleRequirementAST* ast) override; @@ -102,47 +145,6 @@ class DefaultASTVisitor : public ASTVisitor { void visit(TranslationUnitAST* ast) override; void visit(ModuleUnitAST* ast) override; - // ExpressionAST - void visit(ThisExpressionAST* ast) override; - void visit(CharLiteralExpressionAST* ast) override; - void visit(BoolLiteralExpressionAST* ast) override; - void visit(IntLiteralExpressionAST* ast) override; - void visit(FloatLiteralExpressionAST* ast) override; - void visit(NullptrLiteralExpressionAST* ast) override; - void visit(StringLiteralExpressionAST* ast) override; - void visit(UserDefinedStringLiteralExpressionAST* ast) override; - void visit(IdExpressionAST* ast) override; - void visit(RequiresExpressionAST* ast) override; - void visit(NestedExpressionAST* ast) override; - void visit(RightFoldExpressionAST* ast) override; - void visit(LeftFoldExpressionAST* ast) override; - void visit(FoldExpressionAST* ast) override; - void visit(LambdaExpressionAST* ast) override; - void visit(SizeofExpressionAST* ast) override; - void visit(SizeofTypeExpressionAST* ast) override; - void visit(SizeofPackExpressionAST* ast) override; - void visit(TypeidExpressionAST* ast) override; - void visit(TypeidOfTypeExpressionAST* ast) override; - void visit(AlignofExpressionAST* ast) override; - void visit(TypeTraitsExpressionAST* ast) override; - void visit(UnaryExpressionAST* ast) override; - void visit(BinaryExpressionAST* ast) override; - void visit(AssignmentExpressionAST* ast) override; - void visit(BracedTypeConstructionAST* ast) override; - void visit(TypeConstructionAST* ast) override; - void visit(CallExpressionAST* ast) override; - void visit(SubscriptExpressionAST* ast) override; - void visit(MemberExpressionAST* ast) override; - void visit(PostIncrExpressionAST* ast) override; - void visit(ConditionalExpressionAST* ast) override; - void visit(ImplicitCastExpressionAST* ast) override; - void visit(CastExpressionAST* ast) override; - void visit(CppCastExpressionAST* ast) override; - void visit(NewExpressionAST* ast) override; - void visit(DeleteExpressionAST* ast) override; - void visit(ThrowExpressionAST* ast) override; - void visit(NoexceptExpressionAST* ast) override; - // StatementAST void visit(LabeledStatementAST* ast) override; void visit(CaseStatementAST* ast) override; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index bba5d824..6c4c269c 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -5271,31 +5271,53 @@ auto Parser::parse_initializer_clause(ExpressionAST*& yyast, bool templParam) auto Parser::parse_braced_init_list(BracedInitListAST*& yyast) -> bool { SourceLocation lbraceLoc; - SourceLocation commaLoc; SourceLocation rbraceLoc; if (!match(TokenKind::T_LBRACE, lbraceLoc)) return false; if (LA().is(TokenKind::T_DOT)) { - if (!parse_designated_initializer_clause()) { + auto ast = new (pool) BracedInitListAST(); + yyast = ast; + + ast->lbraceLoc = lbraceLoc; + + auto it = &ast->expressionList; + + DesignatedInitializerClauseAST* designatedInitializerClause = nullptr; + + if (!parse_designated_initializer_clause(designatedInitializerClause)) { parse_error("expected designated initializer clause"); } + if (designatedInitializerClause) { + *it = new (pool) List(designatedInitializerClause); + it = &(*it)->next; + } + SourceLocation commaLoc; while (match(TokenKind::T_COMMA, commaLoc)) { if (LA().is(TokenKind::T_RBRACE)) break; - if (!parse_designated_initializer_clause()) { + DesignatedInitializerClauseAST* designatedInitializerClause = nullptr; + + if (!parse_designated_initializer_clause(designatedInitializerClause)) { parse_error("expected designated initializer clause"); } + + if (designatedInitializerClause) { + *it = new (pool) List(designatedInitializerClause); + it = &(*it)->next; + } } - expect(TokenKind::T_RBRACE, rbraceLoc); + expect(TokenKind::T_RBRACE, ast->rbraceLoc); return true; } + SourceLocation commaLoc; + if (match(TokenKind::T_COMMA, commaLoc)) { expect(TokenKind::T_RBRACE, rbraceLoc); @@ -5365,26 +5387,39 @@ auto Parser::parse_initializer_list(List*& yyast) -> bool { return true; } -auto Parser::parse_designated_initializer_clause() -> bool { - if (!parse_designator()) return false; +auto Parser::parse_designated_initializer_clause( + DesignatedInitializerClauseAST*& yyast) -> bool { + DesignatorAST* designator = nullptr; - InitializerAST* initializer = nullptr; + if (!parse_designator(designator)) return false; + + auto ast = new (pool) DesignatedInitializerClauseAST(); + yyast = ast; + + ast->designator = designator; - if (!parse_brace_or_equal_initializer(initializer)) { + if (!parse_brace_or_equal_initializer(ast->initializer)) { parse_error("expected an initializer"); } return true; } -auto Parser::parse_designator() -> bool { +auto Parser::parse_designator(DesignatorAST*& yyast) -> bool { SourceLocation dotLoc; if (!match(TokenKind::T_DOT, dotLoc)) return false; + auto ast = new (pool) DesignatorAST(); + yyast = ast; + + ast->dotLoc = dotLoc; + SourceLocation identifierLoc; - if (!match(TokenKind::T_IDENTIFIER, identifierLoc)) return false; + expect(TokenKind::T_IDENTIFIER, ast->identifierLoc); + + ast->identifier = unit->identifier(ast->identifierLoc); return true; } diff --git a/src/parser/cxx/parser.h b/src/parser/cxx/parser.h index fc9a5f8a..e21c9fd9 100644 --- a/src/parser/cxx/parser.h +++ b/src/parser/cxx/parser.h @@ -324,8 +324,9 @@ class Parser final { -> bool; auto parse_braced_init_list(BracedInitListAST*& yyast) -> bool; auto parse_initializer_list(List*& yyast) -> bool; - auto parse_designated_initializer_clause() -> bool; - auto parse_designator() -> bool; + auto parse_designated_initializer_clause( + DesignatedInitializerClauseAST*& yyast) -> bool; + auto parse_designator(DesignatorAST*& yyast) -> bool; auto parse_expr_or_braced_init_list(ExpressionAST*& yyast) -> bool; auto parse_virt_specifier_seq() -> bool; auto lookat_function_body() -> bool; diff --git a/src/parser/cxx/private/ast_decoder.h b/src/parser/cxx/private/ast_decoder.h index 52231418..bdd07cf7 100644 --- a/src/parser/cxx/private/ast_decoder.h +++ b/src/parser/cxx/private/ast_decoder.h @@ -38,6 +38,7 @@ class ASTDecoder { auto operator()(std::span data) -> bool; private: + auto decodeExpression(const void* ptr, io::Expression type) -> ExpressionAST*; auto decodeRequirement(const void* ptr, io::Requirement type) -> RequirementAST*; auto decodeTemplateArgument(const void* ptr, io::TemplateArgument type) @@ -56,7 +57,6 @@ class ASTDecoder { auto decodeFunctionBody(const void* ptr, io::FunctionBody type) -> FunctionBodyAST*; auto decodeUnit(const void* ptr, io::Unit type) -> UnitAST*; - auto decodeExpression(const void* ptr, io::Expression type) -> ExpressionAST*; auto decodeStatement(const void* ptr, io::Statement type) -> StatementAST*; auto decodeDeclaration(const void* ptr, io::Declaration type) -> DeclarationAST*; @@ -121,72 +121,11 @@ class ASTDecoder { auto decodeAttribute(const io::Attribute* node) -> AttributeAST*; auto decodeAttributeUsingPrefix(const io::AttributeUsingPrefix* node) -> AttributeUsingPrefixAST*; + auto decodeDesignator(const io::Designator* node) -> DesignatorAST*; - auto decodeSimpleRequirement(const io::SimpleRequirement* node) - -> SimpleRequirementAST*; - auto decodeCompoundRequirement(const io::CompoundRequirement* node) - -> CompoundRequirementAST*; - auto decodeTypeRequirement(const io::TypeRequirement* node) - -> TypeRequirementAST*; - auto decodeNestedRequirement(const io::NestedRequirement* node) - -> NestedRequirementAST*; - - auto decodeTypeTemplateArgument(const io::TypeTemplateArgument* node) - -> TypeTemplateArgumentAST*; - auto decodeExpressionTemplateArgument( - const io::ExpressionTemplateArgument* node) - -> ExpressionTemplateArgumentAST*; - - auto decodeParenMemInitializer(const io::ParenMemInitializer* node) - -> ParenMemInitializerAST*; - auto decodeBracedMemInitializer(const io::BracedMemInitializer* node) - -> BracedMemInitializerAST*; - - auto decodeThisLambdaCapture(const io::ThisLambdaCapture* node) - -> ThisLambdaCaptureAST*; - auto decodeDerefThisLambdaCapture(const io::DerefThisLambdaCapture* node) - -> DerefThisLambdaCaptureAST*; - auto decodeSimpleLambdaCapture(const io::SimpleLambdaCapture* node) - -> SimpleLambdaCaptureAST*; - auto decodeRefLambdaCapture(const io::RefLambdaCapture* node) - -> RefLambdaCaptureAST*; - auto decodeRefInitLambdaCapture(const io::RefInitLambdaCapture* node) - -> RefInitLambdaCaptureAST*; - auto decodeInitLambdaCapture(const io::InitLambdaCapture* node) - -> InitLambdaCaptureAST*; - - auto decodeEqualInitializer(const io::EqualInitializer* node) - -> EqualInitializerAST*; - auto decodeBracedInitList(const io::BracedInitList* node) - -> BracedInitListAST*; - auto decodeParenInitializer(const io::ParenInitializer* node) - -> ParenInitializerAST*; - - auto decodeNewParenInitializer(const io::NewParenInitializer* node) - -> NewParenInitializerAST*; - auto decodeNewBracedInitializer(const io::NewBracedInitializer* node) - -> NewBracedInitializerAST*; - - auto decodeEllipsisExceptionDeclaration( - const io::EllipsisExceptionDeclaration* node) - -> EllipsisExceptionDeclarationAST*; - auto decodeTypeExceptionDeclaration(const io::TypeExceptionDeclaration* node) - -> TypeExceptionDeclarationAST*; - - auto decodeDefaultFunctionBody(const io::DefaultFunctionBody* node) - -> DefaultFunctionBodyAST*; - auto decodeCompoundStatementFunctionBody( - const io::CompoundStatementFunctionBody* node) - -> CompoundStatementFunctionBodyAST*; - auto decodeTryStatementFunctionBody(const io::TryStatementFunctionBody* node) - -> TryStatementFunctionBodyAST*; - auto decodeDeleteFunctionBody(const io::DeleteFunctionBody* node) - -> DeleteFunctionBodyAST*; - - auto decodeTranslationUnit(const io::TranslationUnit* node) - -> TranslationUnitAST*; - auto decodeModuleUnit(const io::ModuleUnit* node) -> ModuleUnitAST*; - + auto decodeDesignatedInitializerClause( + const io::DesignatedInitializerClause* node) + -> DesignatedInitializerClauseAST*; auto decodeThisExpression(const io::ThisExpression* node) -> ThisExpressionAST*; auto decodeCharLiteralExpression(const io::CharLiteralExpression* node) @@ -265,6 +204,71 @@ class ASTDecoder { auto decodeNoexceptExpression(const io::NoexceptExpression* node) -> NoexceptExpressionAST*; + auto decodeSimpleRequirement(const io::SimpleRequirement* node) + -> SimpleRequirementAST*; + auto decodeCompoundRequirement(const io::CompoundRequirement* node) + -> CompoundRequirementAST*; + auto decodeTypeRequirement(const io::TypeRequirement* node) + -> TypeRequirementAST*; + auto decodeNestedRequirement(const io::NestedRequirement* node) + -> NestedRequirementAST*; + + auto decodeTypeTemplateArgument(const io::TypeTemplateArgument* node) + -> TypeTemplateArgumentAST*; + auto decodeExpressionTemplateArgument( + const io::ExpressionTemplateArgument* node) + -> ExpressionTemplateArgumentAST*; + + auto decodeParenMemInitializer(const io::ParenMemInitializer* node) + -> ParenMemInitializerAST*; + auto decodeBracedMemInitializer(const io::BracedMemInitializer* node) + -> BracedMemInitializerAST*; + + auto decodeThisLambdaCapture(const io::ThisLambdaCapture* node) + -> ThisLambdaCaptureAST*; + auto decodeDerefThisLambdaCapture(const io::DerefThisLambdaCapture* node) + -> DerefThisLambdaCaptureAST*; + auto decodeSimpleLambdaCapture(const io::SimpleLambdaCapture* node) + -> SimpleLambdaCaptureAST*; + auto decodeRefLambdaCapture(const io::RefLambdaCapture* node) + -> RefLambdaCaptureAST*; + auto decodeRefInitLambdaCapture(const io::RefInitLambdaCapture* node) + -> RefInitLambdaCaptureAST*; + auto decodeInitLambdaCapture(const io::InitLambdaCapture* node) + -> InitLambdaCaptureAST*; + + auto decodeEqualInitializer(const io::EqualInitializer* node) + -> EqualInitializerAST*; + auto decodeBracedInitList(const io::BracedInitList* node) + -> BracedInitListAST*; + auto decodeParenInitializer(const io::ParenInitializer* node) + -> ParenInitializerAST*; + + auto decodeNewParenInitializer(const io::NewParenInitializer* node) + -> NewParenInitializerAST*; + auto decodeNewBracedInitializer(const io::NewBracedInitializer* node) + -> NewBracedInitializerAST*; + + auto decodeEllipsisExceptionDeclaration( + const io::EllipsisExceptionDeclaration* node) + -> EllipsisExceptionDeclarationAST*; + auto decodeTypeExceptionDeclaration(const io::TypeExceptionDeclaration* node) + -> TypeExceptionDeclarationAST*; + + auto decodeDefaultFunctionBody(const io::DefaultFunctionBody* node) + -> DefaultFunctionBodyAST*; + auto decodeCompoundStatementFunctionBody( + const io::CompoundStatementFunctionBody* node) + -> CompoundStatementFunctionBodyAST*; + auto decodeTryStatementFunctionBody(const io::TryStatementFunctionBody* node) + -> TryStatementFunctionBodyAST*; + auto decodeDeleteFunctionBody(const io::DeleteFunctionBody* node) + -> DeleteFunctionBodyAST*; + + auto decodeTranslationUnit(const io::TranslationUnit* node) + -> TranslationUnitAST*; + auto decodeModuleUnit(const io::ModuleUnit* node) -> ModuleUnitAST*; + auto decodeLabeledStatement(const io::LabeledStatement* node) -> LabeledStatementAST*; auto decodeCaseStatement(const io::CaseStatement* node) -> CaseStatementAST*; diff --git a/src/parser/cxx/private/ast_encoder.h b/src/parser/cxx/private/ast_encoder.h index 87856078..7dc11615 100644 --- a/src/parser/cxx/private/ast_encoder.h +++ b/src/parser/cxx/private/ast_encoder.h @@ -69,6 +69,9 @@ class ASTEncoder : ASTVisitor { auto accept(AST* ast) -> flatbuffers::Offset<>; + auto acceptExpression(ExpressionAST* ast) + -> std::tuple, std::uint32_t>; + auto acceptRequirement(RequirementAST* ast) -> std::tuple, std::uint32_t>; @@ -96,9 +99,6 @@ class ASTEncoder : ASTVisitor { auto acceptUnit(UnitAST* ast) -> std::tuple, std::uint32_t>; - auto acceptExpression(ExpressionAST* ast) - -> std::tuple, std::uint32_t>; - auto acceptStatement(StatementAST* ast) -> std::tuple, std::uint32_t>; @@ -155,43 +155,9 @@ class ASTEncoder : ASTVisitor { void visit(AttributeArgumentClauseAST* ast) override; void visit(AttributeAST* ast) override; void visit(AttributeUsingPrefixAST* ast) override; + void visit(DesignatorAST* ast) override; - void visit(SimpleRequirementAST* ast) override; - void visit(CompoundRequirementAST* ast) override; - void visit(TypeRequirementAST* ast) override; - void visit(NestedRequirementAST* ast) override; - - void visit(TypeTemplateArgumentAST* ast) override; - void visit(ExpressionTemplateArgumentAST* ast) override; - - void visit(ParenMemInitializerAST* ast) override; - void visit(BracedMemInitializerAST* ast) override; - - void visit(ThisLambdaCaptureAST* ast) override; - void visit(DerefThisLambdaCaptureAST* ast) override; - void visit(SimpleLambdaCaptureAST* ast) override; - void visit(RefLambdaCaptureAST* ast) override; - void visit(RefInitLambdaCaptureAST* ast) override; - void visit(InitLambdaCaptureAST* ast) override; - - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - - void visit(NewParenInitializerAST* ast) override; - void visit(NewBracedInitializerAST* ast) override; - - void visit(EllipsisExceptionDeclarationAST* ast) override; - void visit(TypeExceptionDeclarationAST* ast) override; - - void visit(DefaultFunctionBodyAST* ast) override; - void visit(CompoundStatementFunctionBodyAST* ast) override; - void visit(TryStatementFunctionBodyAST* ast) override; - void visit(DeleteFunctionBodyAST* ast) override; - - void visit(TranslationUnitAST* ast) override; - void visit(ModuleUnitAST* ast) override; - + void visit(DesignatedInitializerClauseAST* ast) override; void visit(ThisExpressionAST* ast) override; void visit(CharLiteralExpressionAST* ast) override; void visit(BoolLiteralExpressionAST* ast) override; @@ -232,6 +198,42 @@ class ASTEncoder : ASTVisitor { void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(SimpleRequirementAST* ast) override; + void visit(CompoundRequirementAST* ast) override; + void visit(TypeRequirementAST* ast) override; + void visit(NestedRequirementAST* ast) override; + + void visit(TypeTemplateArgumentAST* ast) override; + void visit(ExpressionTemplateArgumentAST* ast) override; + + void visit(ParenMemInitializerAST* ast) override; + void visit(BracedMemInitializerAST* ast) override; + + void visit(ThisLambdaCaptureAST* ast) override; + void visit(DerefThisLambdaCaptureAST* ast) override; + void visit(SimpleLambdaCaptureAST* ast) override; + void visit(RefLambdaCaptureAST* ast) override; + void visit(RefInitLambdaCaptureAST* ast) override; + void visit(InitLambdaCaptureAST* ast) override; + + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; + + void visit(NewParenInitializerAST* ast) override; + void visit(NewBracedInitializerAST* ast) override; + + void visit(EllipsisExceptionDeclarationAST* ast) override; + void visit(TypeExceptionDeclarationAST* ast) override; + + void visit(DefaultFunctionBodyAST* ast) override; + void visit(CompoundStatementFunctionBodyAST* ast) override; + void visit(TryStatementFunctionBodyAST* ast) override; + void visit(DeleteFunctionBodyAST* ast) override; + + void visit(TranslationUnitAST* ast) override; + void visit(ModuleUnitAST* ast) override; + void visit(LabeledStatementAST* ast) override; void visit(CaseStatementAST* ast) override; void visit(DefaultStatementAST* ast) override; diff --git a/src/parser/cxx/recursive_ast_visitor.cc b/src/parser/cxx/recursive_ast_visitor.cc index d88eb244..65ab078f 100644 --- a/src/parser/cxx/recursive_ast_visitor.cc +++ b/src/parser/cxx/recursive_ast_visitor.cc @@ -126,6 +126,8 @@ void RecursiveASTVisitor::acceptAttributeArgumentClause( accept(ast); } +void RecursiveASTVisitor::acceptDesignator(DesignatorAST* ast) { accept(ast); } + void RecursiveASTVisitor::acceptTypeConstraint(TypeConstraintAST* ast) { accept(ast); } @@ -390,130 +392,13 @@ void RecursiveASTVisitor::visit(AttributeAST* ast) { void RecursiveASTVisitor::visit(AttributeUsingPrefixAST* ast) {} -void RecursiveASTVisitor::visit(SimpleRequirementAST* ast) { - acceptExpression(ast->expression); -} - -void RecursiveASTVisitor::visit(CompoundRequirementAST* ast) { - acceptExpression(ast->expression); - acceptTypeConstraint(ast->typeConstraint); -} - -void RecursiveASTVisitor::visit(TypeRequirementAST* ast) { - acceptNestedNameSpecifier(ast->nestedNameSpecifier); - acceptName(ast->name); -} - -void RecursiveASTVisitor::visit(NestedRequirementAST* ast) { - acceptExpression(ast->expression); -} - -void RecursiveASTVisitor::visit(TypeTemplateArgumentAST* ast) { - acceptTypeId(ast->typeId); -} - -void RecursiveASTVisitor::visit(ExpressionTemplateArgumentAST* ast) { - acceptExpression(ast->expression); -} - -void RecursiveASTVisitor::visit(ParenMemInitializerAST* ast) { - acceptName(ast->name); - for (auto it = ast->expressionList; it; it = it->next) { - acceptExpression(it->value); - } -} - -void RecursiveASTVisitor::visit(BracedMemInitializerAST* ast) { - acceptName(ast->name); - acceptBracedInitList(ast->bracedInitList); -} - -void RecursiveASTVisitor::visit(ThisLambdaCaptureAST* ast) {} - -void RecursiveASTVisitor::visit(DerefThisLambdaCaptureAST* ast) {} - -void RecursiveASTVisitor::visit(SimpleLambdaCaptureAST* ast) {} - -void RecursiveASTVisitor::visit(RefLambdaCaptureAST* ast) {} +void RecursiveASTVisitor::visit(DesignatorAST* ast) {} -void RecursiveASTVisitor::visit(RefInitLambdaCaptureAST* ast) { +void RecursiveASTVisitor::visit(DesignatedInitializerClauseAST* ast) { + acceptDesignator(ast->designator); acceptInitializer(ast->initializer); } -void RecursiveASTVisitor::visit(InitLambdaCaptureAST* ast) { - acceptInitializer(ast->initializer); -} - -void RecursiveASTVisitor::visit(EqualInitializerAST* ast) { - acceptExpression(ast->expression); -} - -void RecursiveASTVisitor::visit(BracedInitListAST* ast) { - for (auto it = ast->expressionList; it; it = it->next) { - acceptExpression(it->value); - } -} - -void RecursiveASTVisitor::visit(ParenInitializerAST* ast) { - for (auto it = ast->expressionList; it; it = it->next) { - acceptExpression(it->value); - } -} - -void RecursiveASTVisitor::visit(NewParenInitializerAST* ast) { - for (auto it = ast->expressionList; it; it = it->next) { - acceptExpression(it->value); - } -} - -void RecursiveASTVisitor::visit(NewBracedInitializerAST* ast) { - acceptBracedInitList(ast->bracedInit); -} - -void RecursiveASTVisitor::visit(EllipsisExceptionDeclarationAST* ast) {} - -void RecursiveASTVisitor::visit(TypeExceptionDeclarationAST* ast) { - for (auto it = ast->attributeList; it; it = it->next) { - acceptAttributeSpecifier(it->value); - } - for (auto it = ast->typeSpecifierList; it; it = it->next) { - acceptSpecifier(it->value); - } - acceptDeclarator(ast->declarator); -} - -void RecursiveASTVisitor::visit(DefaultFunctionBodyAST* ast) {} - -void RecursiveASTVisitor::visit(CompoundStatementFunctionBodyAST* ast) { - acceptCtorInitializer(ast->ctorInitializer); - acceptCompoundStatement(ast->statement); -} - -void RecursiveASTVisitor::visit(TryStatementFunctionBodyAST* ast) { - acceptCtorInitializer(ast->ctorInitializer); - acceptCompoundStatement(ast->statement); - for (auto it = ast->handlerList; it; it = it->next) { - acceptHandler(it->value); - } -} - -void RecursiveASTVisitor::visit(DeleteFunctionBodyAST* ast) {} - -void RecursiveASTVisitor::visit(TranslationUnitAST* ast) { - for (auto it = ast->declarationList; it; it = it->next) { - acceptDeclaration(it->value); - } -} - -void RecursiveASTVisitor::visit(ModuleUnitAST* ast) { - acceptGlobalModuleFragment(ast->globalModuleFragment); - acceptModuleDeclaration(ast->moduleDeclaration); - for (auto it = ast->declarationList; it; it = it->next) { - acceptDeclaration(it->value); - } - acceptPrivateModuleFragment(ast->privateModuleFragment); -} - void RecursiveASTVisitor::visit(ThisExpressionAST* ast) {} void RecursiveASTVisitor::visit(CharLiteralExpressionAST* ast) {} @@ -676,6 +561,130 @@ void RecursiveASTVisitor::visit(NoexceptExpressionAST* ast) { acceptExpression(ast->expression); } +void RecursiveASTVisitor::visit(SimpleRequirementAST* ast) { + acceptExpression(ast->expression); +} + +void RecursiveASTVisitor::visit(CompoundRequirementAST* ast) { + acceptExpression(ast->expression); + acceptTypeConstraint(ast->typeConstraint); +} + +void RecursiveASTVisitor::visit(TypeRequirementAST* ast) { + acceptNestedNameSpecifier(ast->nestedNameSpecifier); + acceptName(ast->name); +} + +void RecursiveASTVisitor::visit(NestedRequirementAST* ast) { + acceptExpression(ast->expression); +} + +void RecursiveASTVisitor::visit(TypeTemplateArgumentAST* ast) { + acceptTypeId(ast->typeId); +} + +void RecursiveASTVisitor::visit(ExpressionTemplateArgumentAST* ast) { + acceptExpression(ast->expression); +} + +void RecursiveASTVisitor::visit(ParenMemInitializerAST* ast) { + acceptName(ast->name); + for (auto it = ast->expressionList; it; it = it->next) { + acceptExpression(it->value); + } +} + +void RecursiveASTVisitor::visit(BracedMemInitializerAST* ast) { + acceptName(ast->name); + acceptBracedInitList(ast->bracedInitList); +} + +void RecursiveASTVisitor::visit(ThisLambdaCaptureAST* ast) {} + +void RecursiveASTVisitor::visit(DerefThisLambdaCaptureAST* ast) {} + +void RecursiveASTVisitor::visit(SimpleLambdaCaptureAST* ast) {} + +void RecursiveASTVisitor::visit(RefLambdaCaptureAST* ast) {} + +void RecursiveASTVisitor::visit(RefInitLambdaCaptureAST* ast) { + acceptInitializer(ast->initializer); +} + +void RecursiveASTVisitor::visit(InitLambdaCaptureAST* ast) { + acceptInitializer(ast->initializer); +} + +void RecursiveASTVisitor::visit(EqualInitializerAST* ast) { + acceptExpression(ast->expression); +} + +void RecursiveASTVisitor::visit(BracedInitListAST* ast) { + for (auto it = ast->expressionList; it; it = it->next) { + acceptExpression(it->value); + } +} + +void RecursiveASTVisitor::visit(ParenInitializerAST* ast) { + for (auto it = ast->expressionList; it; it = it->next) { + acceptExpression(it->value); + } +} + +void RecursiveASTVisitor::visit(NewParenInitializerAST* ast) { + for (auto it = ast->expressionList; it; it = it->next) { + acceptExpression(it->value); + } +} + +void RecursiveASTVisitor::visit(NewBracedInitializerAST* ast) { + acceptBracedInitList(ast->bracedInit); +} + +void RecursiveASTVisitor::visit(EllipsisExceptionDeclarationAST* ast) {} + +void RecursiveASTVisitor::visit(TypeExceptionDeclarationAST* ast) { + for (auto it = ast->attributeList; it; it = it->next) { + acceptAttributeSpecifier(it->value); + } + for (auto it = ast->typeSpecifierList; it; it = it->next) { + acceptSpecifier(it->value); + } + acceptDeclarator(ast->declarator); +} + +void RecursiveASTVisitor::visit(DefaultFunctionBodyAST* ast) {} + +void RecursiveASTVisitor::visit(CompoundStatementFunctionBodyAST* ast) { + acceptCtorInitializer(ast->ctorInitializer); + acceptCompoundStatement(ast->statement); +} + +void RecursiveASTVisitor::visit(TryStatementFunctionBodyAST* ast) { + acceptCtorInitializer(ast->ctorInitializer); + acceptCompoundStatement(ast->statement); + for (auto it = ast->handlerList; it; it = it->next) { + acceptHandler(it->value); + } +} + +void RecursiveASTVisitor::visit(DeleteFunctionBodyAST* ast) {} + +void RecursiveASTVisitor::visit(TranslationUnitAST* ast) { + for (auto it = ast->declarationList; it; it = it->next) { + acceptDeclaration(it->value); + } +} + +void RecursiveASTVisitor::visit(ModuleUnitAST* ast) { + acceptGlobalModuleFragment(ast->globalModuleFragment); + acceptModuleDeclaration(ast->moduleDeclaration); + for (auto it = ast->declarationList; it; it = it->next) { + acceptDeclaration(it->value); + } + acceptPrivateModuleFragment(ast->privateModuleFragment); +} + void RecursiveASTVisitor::visit(LabeledStatementAST* ast) { acceptStatement(ast->statement); } diff --git a/src/parser/cxx/recursive_ast_visitor.h b/src/parser/cxx/recursive_ast_visitor.h index 8a1d6b4d..d0b9b3e7 100644 --- a/src/parser/cxx/recursive_ast_visitor.h +++ b/src/parser/cxx/recursive_ast_visitor.h @@ -55,6 +55,7 @@ class RecursiveASTVisitor : public ASTVisitor { virtual void acceptModulePartition(ModulePartitionAST* ast); virtual void acceptAttributeToken(AttributeTokenAST* ast); virtual void acceptAttributeArgumentClause(AttributeArgumentClauseAST* ast); + virtual void acceptDesignator(DesignatorAST* ast); virtual void acceptTypeConstraint(TypeConstraintAST* ast); virtual void acceptBracedInitList(BracedInitListAST* ast); virtual void acceptCtorInitializer(CtorInitializerAST* ast); @@ -113,43 +114,9 @@ class RecursiveASTVisitor : public ASTVisitor { void visit(AttributeArgumentClauseAST* ast) override; void visit(AttributeAST* ast) override; void visit(AttributeUsingPrefixAST* ast) override; + void visit(DesignatorAST* ast) override; - void visit(SimpleRequirementAST* ast) override; - void visit(CompoundRequirementAST* ast) override; - void visit(TypeRequirementAST* ast) override; - void visit(NestedRequirementAST* ast) override; - - void visit(TypeTemplateArgumentAST* ast) override; - void visit(ExpressionTemplateArgumentAST* ast) override; - - void visit(ParenMemInitializerAST* ast) override; - void visit(BracedMemInitializerAST* ast) override; - - void visit(ThisLambdaCaptureAST* ast) override; - void visit(DerefThisLambdaCaptureAST* ast) override; - void visit(SimpleLambdaCaptureAST* ast) override; - void visit(RefLambdaCaptureAST* ast) override; - void visit(RefInitLambdaCaptureAST* ast) override; - void visit(InitLambdaCaptureAST* ast) override; - - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - - void visit(NewParenInitializerAST* ast) override; - void visit(NewBracedInitializerAST* ast) override; - - void visit(EllipsisExceptionDeclarationAST* ast) override; - void visit(TypeExceptionDeclarationAST* ast) override; - - void visit(DefaultFunctionBodyAST* ast) override; - void visit(CompoundStatementFunctionBodyAST* ast) override; - void visit(TryStatementFunctionBodyAST* ast) override; - void visit(DeleteFunctionBodyAST* ast) override; - - void visit(TranslationUnitAST* ast) override; - void visit(ModuleUnitAST* ast) override; - + void visit(DesignatedInitializerClauseAST* ast) override; void visit(ThisExpressionAST* ast) override; void visit(CharLiteralExpressionAST* ast) override; void visit(BoolLiteralExpressionAST* ast) override; @@ -190,6 +157,42 @@ class RecursiveASTVisitor : public ASTVisitor { void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(SimpleRequirementAST* ast) override; + void visit(CompoundRequirementAST* ast) override; + void visit(TypeRequirementAST* ast) override; + void visit(NestedRequirementAST* ast) override; + + void visit(TypeTemplateArgumentAST* ast) override; + void visit(ExpressionTemplateArgumentAST* ast) override; + + void visit(ParenMemInitializerAST* ast) override; + void visit(BracedMemInitializerAST* ast) override; + + void visit(ThisLambdaCaptureAST* ast) override; + void visit(DerefThisLambdaCaptureAST* ast) override; + void visit(SimpleLambdaCaptureAST* ast) override; + void visit(RefLambdaCaptureAST* ast) override; + void visit(RefInitLambdaCaptureAST* ast) override; + void visit(InitLambdaCaptureAST* ast) override; + + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; + + void visit(NewParenInitializerAST* ast) override; + void visit(NewBracedInitializerAST* ast) override; + + void visit(EllipsisExceptionDeclarationAST* ast) override; + void visit(TypeExceptionDeclarationAST* ast) override; + + void visit(DefaultFunctionBodyAST* ast) override; + void visit(CompoundStatementFunctionBodyAST* ast) override; + void visit(TryStatementFunctionBodyAST* ast) override; + void visit(DeleteFunctionBodyAST* ast) override; + + void visit(TranslationUnitAST* ast) override; + void visit(ModuleUnitAST* ast) override; + void visit(LabeledStatementAST* ast) override; void visit(CaseStatementAST* ast) override; void visit(DefaultStatementAST* ast) override; diff --git a/tests/unit_tests/ast/designated_initializer_01.cc b/tests/unit_tests/ast/designated_initializer_01.cc new file mode 100644 index 00000000..d2dd144b --- /dev/null +++ b/tests/unit_tests/ast/designated_initializer_01.cc @@ -0,0 +1,71 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +struct Pair { + int first; + int second; +}; + +auto pair = Pair{ + .first = 1, + .second = 2, +}; + +// clang-format off +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: struct +// CHECK-NEXT: is-final: false +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Pair +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: first +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: second +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: auto-type-specifier +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: pair +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: braced-type-construction +// CHECK-NEXT: type-specifier: named-type-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Pair +// CHECK-NEXT: braced-init-list: braced-init-list +// CHECK-NEXT: expression-list +// CHECK-NEXT: designated-initializer-clause +// CHECK-NEXT: designator: designator +// CHECK-NEXT: identifier: first +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 1 +// CHECK-NEXT: designated-initializer-clause +// CHECK-NEXT: designator: designator +// CHECK-NEXT: identifier: second +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: int-literal-expression +// CHECK-NEXT: literal: 2 From 629ca3c31b3475a89f94cc1f6bcf9a9c25fe3f18 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 22 Aug 2023 12:51:18 +0000 Subject: [PATCH 25/28] fix: Represent intiializers as expressions in the AST --- packages/cxx-frontend/src/AST.ts | 121 +- packages/cxx-frontend/src/ASTKind.ts | 8 +- packages/cxx-frontend/src/ASTVisitor.ts | 8 +- .../cxx-frontend/src/RecursiveASTVisitor.ts | 32 +- src/frontend/cxx/ast_printer.cc | 62 +- src/frontend/cxx/ast_printer.h | 7 +- src/parser/cxx/ast.cc | 1012 ++++++++--------- src/parser/cxx/ast.fbs | 53 +- src/parser/cxx/ast.h | 97 +- src/parser/cxx/ast_cloner.cc | 118 +- src/parser/cxx/ast_cloner.h | 7 +- src/parser/cxx/ast_decoder.cc | 122 +- src/parser/cxx/ast_encoder.cc | 175 ++- src/parser/cxx/ast_fwd.h | 9 +- src/parser/cxx/ast_kind.h | 8 +- src/parser/cxx/ast_slot.cc | 114 +- src/parser/cxx/ast_slot.h | 7 +- src/parser/cxx/ast_visitor.h | 8 +- src/parser/cxx/default_ast_visitor.cc | 25 +- src/parser/cxx/default_ast_visitor.h | 8 +- src/parser/cxx/parser.cc | 23 +- src/parser/cxx/parser.h | 6 +- src/parser/cxx/private/ast_decoder.h | 15 +- src/parser/cxx/private/ast_encoder.h | 10 +- src/parser/cxx/recursive_ast_visitor.cc | 76 +- src/parser/cxx/recursive_ast_visitor.h | 20 +- tests/unit_tests/ast/return_statement_01.cc | 68 ++ 27 files changed, 1121 insertions(+), 1098 deletions(-) create mode 100644 tests/unit_tests/ast/return_statement_01.cc diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index 97496625..bb35b408 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -83,7 +83,6 @@ export abstract class DeclaratorModifierAST extends AST { } export abstract class ExceptionDeclarationAST extends AST { } export abstract class ExpressionAST extends AST { } export abstract class FunctionBodyAST extends AST { } -export abstract class InitializerAST extends AST { } export abstract class LambdaCaptureAST extends AST { } export abstract class MemInitializerAST extends AST { } export abstract class NameAST extends AST { } @@ -222,8 +221,8 @@ export class InitDeclaratorAST extends AST { getRequiresClause(): RequiresClauseAST | undefined { return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getInitializer(): InitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getInitializer(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } @@ -589,8 +588,8 @@ export class DesignatedInitializerClauseAST extends ExpressionAST { getDesignator(): DesignatorAST | undefined { return AST.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); } - getInitializer(): InitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + getInitializer(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } } @@ -1220,6 +1219,55 @@ export class NoexceptExpressionAST extends ExpressionAST { } } +export class EqualInitializerAST extends ExpressionAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitEqualInitializer(this, context); + } + getEqualToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + getExpression(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); + } +} + +export class BracedInitListAST extends ExpressionAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitBracedInitList(this, context); + } + getLbraceToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + *getExpressionList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + getCommaToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } + getRbraceToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } +} + +export class ParenInitializerAST extends ExpressionAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitParenInitializer(this, context); + } + getLparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); + } + *getExpressionList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + getRparenToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } +} + export class SimpleRequirementAST extends RequirementAST { accept(visitor: ASTVisitor, context: Context): Result { return visitor.visitSimpleRequirement(this, context); @@ -1409,8 +1457,8 @@ export class RefInitLambdaCaptureAST extends LambdaCaptureAST { getIdentifierToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } - getInitializer(): InitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + getInitializer(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); } } @@ -1424,57 +1472,8 @@ export class InitLambdaCaptureAST extends LambdaCaptureAST { getIdentifierToken(): Token | undefined { return Token.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); } - getInitializer(): InitializerAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); - } -} - -export class EqualInitializerAST extends InitializerAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitEqualInitializer(this, context); - } - getEqualToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); - } - getExpression(): ExpressionAST | undefined { - return AST.from(cxx.getASTSlot(this.getHandle(), 1), this.parser); - } -} - -export class BracedInitListAST extends InitializerAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitBracedInitList(this, context); - } - getLbraceToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); - } - *getExpressionList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } - } - getCommaToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); - } - getRbraceToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); - } -} - -export class ParenInitializerAST extends InitializerAST { - accept(visitor: ASTVisitor, context: Context): Result { - return visitor.visitParenInitializer(this, context); - } - getLparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 0), this.parser); - } - *getExpressionList(): Generator { - for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { - yield AST.from(cxx.getListValue(it), this.parser); - } - } - getRparenToken(): Token | undefined { - return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + getInitializer(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); } } @@ -3355,6 +3354,9 @@ const AST_CONSTRUCTORS: Array { abstract visitDeleteExpression(node: ast.DeleteExpressionAST, context: Context): Result; abstract visitThrowExpression(node: ast.ThrowExpressionAST, context: Context): Result; abstract visitNoexceptExpression(node: ast.NoexceptExpressionAST, context: Context): Result; + abstract visitEqualInitializer(node: ast.EqualInitializerAST, context: Context): Result; + abstract visitBracedInitList(node: ast.BracedInitListAST, context: Context): Result; + abstract visitParenInitializer(node: ast.ParenInitializerAST, context: Context): Result; // RequirementAST abstract visitSimpleRequirement(node: ast.SimpleRequirementAST, context: Context): Result; @@ -120,11 +123,6 @@ export abstract class ASTVisitor { abstract visitRefInitLambdaCapture(node: ast.RefInitLambdaCaptureAST, context: Context): Result; abstract visitInitLambdaCapture(node: ast.InitLambdaCaptureAST, context: Context): Result; - // InitializerAST - abstract visitEqualInitializer(node: ast.EqualInitializerAST, context: Context): Result; - abstract visitBracedInitList(node: ast.BracedInitListAST, context: Context): Result; - abstract visitParenInitializer(node: ast.ParenInitializerAST, context: Context): Result; - // NewInitializerAST abstract visitNewParenInitializer(node: ast.NewParenInitializerAST, context: Context): Result; abstract visitNewBracedInitializer(node: ast.NewBracedInitializerAST, context: Context): Result; diff --git a/packages/cxx-frontend/src/RecursiveASTVisitor.ts b/packages/cxx-frontend/src/RecursiveASTVisitor.ts index 6adb734d..c347afc4 100644 --- a/packages/cxx-frontend/src/RecursiveASTVisitor.ts +++ b/packages/cxx-frontend/src/RecursiveASTVisitor.ts @@ -384,6 +384,22 @@ export class RecursiveASTVisitor extends ASTVisitor { this.accept(node.getExpression(), context); } + visitEqualInitializer(node: ast.EqualInitializerAST, context: Context): void { + this.accept(node.getExpression(), context); + } + + visitBracedInitList(node: ast.BracedInitListAST, context: Context): void { + for (const element of node.getExpressionList()) { + this.accept(element, context); + } + } + + visitParenInitializer(node: ast.ParenInitializerAST, context: Context): void { + for (const element of node.getExpressionList()) { + this.accept(element, context); + } + } + visitSimpleRequirement(node: ast.SimpleRequirementAST, context: Context): void { this.accept(node.getExpression(), context); } @@ -442,22 +458,6 @@ export class RecursiveASTVisitor extends ASTVisitor { this.accept(node.getInitializer(), context); } - visitEqualInitializer(node: ast.EqualInitializerAST, context: Context): void { - this.accept(node.getExpression(), context); - } - - visitBracedInitList(node: ast.BracedInitListAST, context: Context): void { - for (const element of node.getExpressionList()) { - this.accept(element, context); - } - } - - visitParenInitializer(node: ast.ParenInitializerAST, context: Context): void { - for (const element of node.getExpressionList()) { - this.accept(element, context); - } - } - visitNewParenInitializer(node: ast.NewParenInitializerAST, context: Context): void { for (const element of node.getExpressionList()) { this.accept(element, context); diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index c2c731cb..746784db 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -737,6 +737,37 @@ void ASTPrinter::visit(NoexceptExpressionAST* ast) { accept(ast->expression, "expression"); } +void ASTPrinter::visit(EqualInitializerAST* ast) { + fmt::print(out_, "{}\n", "equal-initializer"); + accept(ast->expression, "expression"); +} + +void ASTPrinter::visit(BracedInitListAST* ast) { + fmt::print(out_, "{}\n", "braced-init-list"); + if (ast->expressionList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); + for (auto it = ast->expressionList; it; it = it->next) { + accept(it->value); + } + --indent_; + } +} + +void ASTPrinter::visit(ParenInitializerAST* ast) { + fmt::print(out_, "{}\n", "paren-initializer"); + if (ast->expressionList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "expression-list"); + for (auto it = ast->expressionList; it; it = it->next) { + accept(it->value); + } + --indent_; + } +} + void ASTPrinter::visit(SimpleRequirementAST* ast) { fmt::print(out_, "{}\n", "simple-requirement"); accept(ast->expression, "expression"); @@ -819,37 +850,6 @@ void ASTPrinter::visit(InitLambdaCaptureAST* ast) { accept(ast->initializer, "initializer"); } -void ASTPrinter::visit(EqualInitializerAST* ast) { - fmt::print(out_, "{}\n", "equal-initializer"); - accept(ast->expression, "expression"); -} - -void ASTPrinter::visit(BracedInitListAST* ast) { - fmt::print(out_, "{}\n", "braced-init-list"); - if (ast->expressionList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "expression-list"); - for (auto it = ast->expressionList; it; it = it->next) { - accept(it->value); - } - --indent_; - } -} - -void ASTPrinter::visit(ParenInitializerAST* ast) { - fmt::print(out_, "{}\n", "paren-initializer"); - if (ast->expressionList) { - ++indent_; - fmt::print(out_, "{:{}}", "", indent_ * 2); - fmt::print(out_, "{}\n", "expression-list"); - for (auto it = ast->expressionList; it; it = it->next) { - accept(it->value); - } - --indent_; - } -} - void ASTPrinter::visit(NewParenInitializerAST* ast) { fmt::print(out_, "{}\n", "new-paren-initializer"); if (ast->expressionList) { diff --git a/src/frontend/cxx/ast_printer.h b/src/frontend/cxx/ast_printer.h index 31eaa9db..e257d2e8 100644 --- a/src/frontend/cxx/ast_printer.h +++ b/src/frontend/cxx/ast_printer.h @@ -113,6 +113,9 @@ class ASTPrinter : ASTVisitor { void visit(DeleteExpressionAST* ast) override; void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; void visit(SimpleRequirementAST* ast) override; void visit(CompoundRequirementAST* ast) override; @@ -132,10 +135,6 @@ class ASTPrinter : ASTVisitor { void visit(RefInitLambdaCaptureAST* ast) override; void visit(InitLambdaCaptureAST* ast) override; - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - void visit(NewParenInitializerAST* ast) override; void visit(NewBracedInitializerAST* ast) override; diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index d9f08e4b..ba43a001 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -460,941 +460,941 @@ auto DesignatedInitializerClauseAST::lastSourceLocation() -> SourceLocation { return {}; } -auto SimpleRequirementAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; +auto ThisExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(thisLoc)) return loc; return {}; } -auto SimpleRequirementAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expression)) return loc; +auto ThisExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(thisLoc)) return loc; return {}; } -auto CompoundRequirementAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(lbraceLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(rbraceLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(noexceptLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(minusGreaterLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(typeConstraint)) return loc; - if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; +auto CharLiteralExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; return {}; } -auto CompoundRequirementAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeConstraint)) return loc; - if (auto loc = cxx::lastSourceLocation(minusGreaterLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(noexceptLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(rbraceLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(lbraceLoc)) return loc; +auto CharLiteralExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; return {}; } -auto TypeRequirementAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(typenameLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(nestedNameSpecifier)) return loc; - if (auto loc = cxx::firstSourceLocation(name)) return loc; - if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; +auto BoolLiteralExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; return {}; } -auto TypeRequirementAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(name)) return loc; - if (auto loc = cxx::lastSourceLocation(nestedNameSpecifier)) return loc; - if (auto loc = cxx::lastSourceLocation(typenameLoc)) return loc; +auto BoolLiteralExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; return {}; } -auto NestedRequirementAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(requiresLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; +auto IntLiteralExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; return {}; } -auto NestedRequirementAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(requiresLoc)) return loc; +auto IntLiteralExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; return {}; } -auto TypeTemplateArgumentAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(typeId)) return loc; +auto FloatLiteralExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; return {}; } -auto TypeTemplateArgumentAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(typeId)) return loc; +auto FloatLiteralExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; return {}; } -auto ExpressionTemplateArgumentAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(expression)) return loc; +auto NullptrLiteralExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; return {}; } -auto ExpressionTemplateArgumentAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(expression)) return loc; +auto NullptrLiteralExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; return {}; } -auto ParenMemInitializerAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(name)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; +auto StringLiteralExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; return {}; } -auto ParenMemInitializerAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(name)) return loc; +auto StringLiteralExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; return {}; } -auto BracedMemInitializerAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(name)) return loc; - if (auto loc = cxx::firstSourceLocation(bracedInitList)) return loc; - if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; +auto UserDefinedStringLiteralExpressionAST::firstSourceLocation() + -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; return {}; } -auto BracedMemInitializerAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(bracedInitList)) return loc; - if (auto loc = cxx::lastSourceLocation(name)) return loc; +auto UserDefinedStringLiteralExpressionAST::lastSourceLocation() + -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; return {}; } -auto ThisLambdaCaptureAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(thisLoc)) return loc; +auto IdExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(name)) return loc; return {}; } -auto ThisLambdaCaptureAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(thisLoc)) return loc; +auto IdExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(name)) return loc; return {}; } -auto DerefThisLambdaCaptureAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(starLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(thisLoc)) return loc; +auto RequiresExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(requiresLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(parameterDeclarationClause)) + return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(requirementBody)) return loc; return {}; } -auto DerefThisLambdaCaptureAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(thisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(starLoc)) return loc; +auto RequiresExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(requirementBody)) return loc; + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(parameterDeclarationClause)) + return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(requiresLoc)) return loc; return {}; } -auto SimpleLambdaCaptureAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; +auto NestedExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto SimpleLambdaCaptureAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; +auto NestedExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; return {}; } -auto RefLambdaCaptureAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(ampLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; +auto RightFoldExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; + if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto RefLambdaCaptureAST::lastSourceLocation() -> SourceLocation { +auto RightFoldExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(ampLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; return {}; } -auto RefInitLambdaCaptureAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(ampLoc)) return loc; +auto LeftFoldExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(initializer)) return loc; + if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto RefInitLambdaCaptureAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(initializer)) return loc; - if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; +auto LeftFoldExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(ampLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; return {}; } -auto InitLambdaCaptureAST::firstSourceLocation() -> SourceLocation { +auto FoldExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(leftExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(initializer)) return loc; + if (auto loc = cxx::firstSourceLocation(foldOpLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(rightExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto InitLambdaCaptureAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(initializer)) return loc; - if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; +auto FoldExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(rightExpression)) return loc; + if (auto loc = cxx::lastSourceLocation(foldOpLoc)) return loc; if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(leftExpression)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; return {}; } -auto EqualInitializerAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(equalLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; +auto LambdaExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lambdaIntroducer)) return loc; + if (auto loc = cxx::firstSourceLocation(lessLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(templateParameterList)) return loc; + if (auto loc = cxx::firstSourceLocation(greaterLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(requiresClause)) return loc; + if (auto loc = cxx::firstSourceLocation(lambdaDeclarator)) return loc; + if (auto loc = cxx::firstSourceLocation(statement)) return loc; return {}; } -auto EqualInitializerAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(equalLoc)) return loc; +auto LambdaExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(statement)) return loc; + if (auto loc = cxx::lastSourceLocation(lambdaDeclarator)) return loc; + if (auto loc = cxx::lastSourceLocation(requiresClause)) return loc; + if (auto loc = cxx::lastSourceLocation(greaterLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(templateParameterList)) return loc; + if (auto loc = cxx::lastSourceLocation(lessLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(lambdaIntroducer)) return loc; return {}; } -auto BracedInitListAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(lbraceLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; - if (auto loc = cxx::firstSourceLocation(commaLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(rbraceLoc)) return loc; +auto SizeofExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(sizeofLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; return {}; } -auto BracedInitListAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rbraceLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(commaLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; - if (auto loc = cxx::lastSourceLocation(lbraceLoc)) return loc; +auto SizeofExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(sizeofLoc)) return loc; return {}; } -auto ParenInitializerAST::firstSourceLocation() -> SourceLocation { +auto SizeofTypeExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(sizeofLoc)) return loc; if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; + if (auto loc = cxx::firstSourceLocation(typeId)) return loc; if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto ParenInitializerAST::lastSourceLocation() -> SourceLocation { +auto SizeofTypeExpressionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; + if (auto loc = cxx::lastSourceLocation(typeId)) return loc; if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(sizeofLoc)) return loc; return {}; } -auto NewParenInitializerAST::firstSourceLocation() -> SourceLocation { +auto SizeofPackExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(sizeofLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto NewParenInitializerAST::lastSourceLocation() -> SourceLocation { +auto SizeofPackExpressionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(sizeofLoc)) return loc; return {}; } -auto NewBracedInitializerAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(bracedInit)) return loc; +auto TypeidExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(typeidLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto NewBracedInitializerAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(bracedInit)) return loc; +auto TypeidExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeidLoc)) return loc; return {}; } -auto EllipsisExceptionDeclarationAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; +auto TypeidOfTypeExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(typeidLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(typeId)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto EllipsisExceptionDeclarationAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; +auto TypeidOfTypeExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeId)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeidLoc)) return loc; return {}; } -auto TypeExceptionDeclarationAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(attributeList)) return loc; - if (auto loc = cxx::firstSourceLocation(typeSpecifierList)) return loc; - if (auto loc = cxx::firstSourceLocation(declarator)) return loc; +auto AlignofExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(alignofLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(typeId)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto TypeExceptionDeclarationAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(declarator)) return loc; - if (auto loc = cxx::lastSourceLocation(typeSpecifierList)) return loc; - if (auto loc = cxx::lastSourceLocation(attributeList)) return loc; +auto AlignofExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeId)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(alignofLoc)) return loc; return {}; } -auto DefaultFunctionBodyAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(equalLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(defaultLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; +auto TypeTraitsExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(typeTraitsLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(typeIdList)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto DefaultFunctionBodyAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(defaultLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(equalLoc)) return loc; +auto TypeTraitsExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeIdList)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeTraitsLoc)) return loc; return {}; } -auto CompoundStatementFunctionBodyAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(ctorInitializer)) return loc; - if (auto loc = cxx::firstSourceLocation(statement)) return loc; +auto UnaryExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; return {}; } -auto CompoundStatementFunctionBodyAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(statement)) return loc; - if (auto loc = cxx::lastSourceLocation(ctorInitializer)) return loc; +auto UnaryExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; return {}; } -auto TryStatementFunctionBodyAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(tryLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(ctorInitializer)) return loc; - if (auto loc = cxx::firstSourceLocation(statement)) return loc; - if (auto loc = cxx::firstSourceLocation(handlerList)) return loc; +auto BinaryExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(leftExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(rightExpression)) return loc; return {}; } -auto TryStatementFunctionBodyAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(handlerList)) return loc; - if (auto loc = cxx::lastSourceLocation(statement)) return loc; - if (auto loc = cxx::lastSourceLocation(ctorInitializer)) return loc; - if (auto loc = cxx::lastSourceLocation(tryLoc)) return loc; +auto BinaryExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rightExpression)) return loc; + if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(leftExpression)) return loc; return {}; } -auto DeleteFunctionBodyAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(equalLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(deleteLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; +auto AssignmentExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(leftExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(rightExpression)) return loc; return {}; } -auto DeleteFunctionBodyAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(deleteLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(equalLoc)) return loc; +auto AssignmentExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rightExpression)) return loc; + if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(leftExpression)) return loc; return {}; } -auto TranslationUnitAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(declarationList)) return loc; +auto BracedTypeConstructionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(typeSpecifier)) return loc; + if (auto loc = cxx::firstSourceLocation(bracedInitList)) return loc; return {}; } -auto TranslationUnitAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(declarationList)) return loc; +auto BracedTypeConstructionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(bracedInitList)) return loc; + if (auto loc = cxx::lastSourceLocation(typeSpecifier)) return loc; return {}; } -auto ModuleUnitAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(globalModuleFragment)) return loc; - if (auto loc = cxx::firstSourceLocation(moduleDeclaration)) return loc; - if (auto loc = cxx::firstSourceLocation(declarationList)) return loc; - if (auto loc = cxx::firstSourceLocation(privateModuleFragment)) return loc; +auto TypeConstructionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(typeSpecifier)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto ModuleUnitAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(privateModuleFragment)) return loc; - if (auto loc = cxx::lastSourceLocation(declarationList)) return loc; - if (auto loc = cxx::lastSourceLocation(moduleDeclaration)) return loc; - if (auto loc = cxx::lastSourceLocation(globalModuleFragment)) return loc; +auto TypeConstructionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeSpecifier)) return loc; return {}; } -auto ThisExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(thisLoc)) return loc; +auto CallExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(baseExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto ThisExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(thisLoc)) return loc; +auto CallExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(baseExpression)) return loc; return {}; } -auto CharLiteralExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; +auto SubscriptExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(baseExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(lbracketLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(indexExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(rbracketLoc)) return loc; return {}; } -auto CharLiteralExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; +auto SubscriptExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rbracketLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(indexExpression)) return loc; + if (auto loc = cxx::lastSourceLocation(lbracketLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(baseExpression)) return loc; return {}; } -auto BoolLiteralExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; +auto MemberExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(baseExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(accessLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(templateLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(name)) return loc; return {}; } -auto BoolLiteralExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; +auto MemberExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(name)) return loc; + if (auto loc = cxx::lastSourceLocation(templateLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(accessLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(baseExpression)) return loc; return {}; } -auto IntLiteralExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; +auto PostIncrExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(baseExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; return {}; } -auto IntLiteralExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; +auto PostIncrExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(baseExpression)) return loc; return {}; } -auto FloatLiteralExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; +auto ConditionalExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(condition)) return loc; + if (auto loc = cxx::firstSourceLocation(questionLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(iftrueExpression)) return loc; + if (auto loc = cxx::firstSourceLocation(colonLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(iffalseExpression)) return loc; return {}; } -auto FloatLiteralExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; +auto ConditionalExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(iffalseExpression)) return loc; + if (auto loc = cxx::lastSourceLocation(colonLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(iftrueExpression)) return loc; + if (auto loc = cxx::lastSourceLocation(questionLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(condition)) return loc; return {}; } -auto NullptrLiteralExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; +auto ImplicitCastExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(expression)) return loc; return {}; } -auto NullptrLiteralExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; +auto ImplicitCastExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(expression)) return loc; return {}; } -auto StringLiteralExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; +auto CastExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(typeId)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; return {}; } -auto StringLiteralExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; +auto CastExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeId)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; return {}; } -auto UserDefinedStringLiteralExpressionAST::firstSourceLocation() - -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(literalLoc)) return loc; +auto CppCastExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(castLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lessLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(typeId)) return loc; + if (auto loc = cxx::firstSourceLocation(greaterLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto UserDefinedStringLiteralExpressionAST::lastSourceLocation() - -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(literalLoc)) return loc; +auto CppCastExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(greaterLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeId)) return loc; + if (auto loc = cxx::lastSourceLocation(lessLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(castLoc)) return loc; return {}; } -auto IdExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(name)) return loc; +auto NewExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(scopeLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(newLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(typeId)) return loc; + if (auto loc = cxx::firstSourceLocation(newInitalizer)) return loc; return {}; } -auto IdExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(name)) return loc; +auto NewExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(newInitalizer)) return loc; + if (auto loc = cxx::lastSourceLocation(typeId)) return loc; + if (auto loc = cxx::lastSourceLocation(newLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(scopeLoc)) return loc; return {}; } -auto RequiresExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(requiresLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(parameterDeclarationClause)) - return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(requirementBody)) return loc; +auto DeleteExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(scopeLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(deleteLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lbracketLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(rbracketLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; return {}; } -auto RequiresExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(requirementBody)) return loc; - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(parameterDeclarationClause)) - return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(requiresLoc)) return loc; +auto DeleteExpressionAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(rbracketLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(lbracketLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(deleteLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(scopeLoc)) return loc; return {}; } -auto NestedExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; +auto ThrowExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(throwLoc)) return loc; if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto NestedExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; +auto ThrowExpressionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(throwLoc)) return loc; return {}; } -auto RightFoldExpressionAST::firstSourceLocation() -> SourceLocation { +auto NoexceptExpressionAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(noexceptLoc)) return loc; if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto RightFoldExpressionAST::lastSourceLocation() -> SourceLocation { +auto NoexceptExpressionAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; if (auto loc = cxx::lastSourceLocation(expression)) return loc; if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(noexceptLoc)) return loc; return {}; } -auto LeftFoldExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; +auto EqualInitializerAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(equalLoc)) return loc; if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto LeftFoldExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; +auto EqualInitializerAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(equalLoc)) return loc; return {}; } -auto FoldExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(leftExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(foldOpLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(rightExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; +auto BracedInitListAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lbraceLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; + if (auto loc = cxx::firstSourceLocation(commaLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(rbraceLoc)) return loc; return {}; } -auto FoldExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(rightExpression)) return loc; - if (auto loc = cxx::lastSourceLocation(foldOpLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(leftExpression)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; +auto BracedInitListAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rbraceLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(commaLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; + if (auto loc = cxx::lastSourceLocation(lbraceLoc)) return loc; return {}; } -auto LambdaExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(lambdaIntroducer)) return loc; - if (auto loc = cxx::firstSourceLocation(lessLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(templateParameterList)) return loc; - if (auto loc = cxx::firstSourceLocation(greaterLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(requiresClause)) return loc; - if (auto loc = cxx::firstSourceLocation(lambdaDeclarator)) return loc; - if (auto loc = cxx::firstSourceLocation(statement)) return loc; +auto ParenInitializerAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto LambdaExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(statement)) return loc; - if (auto loc = cxx::lastSourceLocation(lambdaDeclarator)) return loc; - if (auto loc = cxx::lastSourceLocation(requiresClause)) return loc; - if (auto loc = cxx::lastSourceLocation(greaterLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(templateParameterList)) return loc; - if (auto loc = cxx::lastSourceLocation(lessLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(lambdaIntroducer)) return loc; +auto ParenInitializerAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; return {}; } -auto SizeofExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(sizeofLoc)) return loc; +auto SimpleRequirementAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(expression)) return loc; + if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; return {}; } -auto SizeofExpressionAST::lastSourceLocation() -> SourceLocation { +auto SimpleRequirementAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(sizeofLoc)) return loc; return {}; } -auto SizeofTypeExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(sizeofLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(typeId)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; +auto CompoundRequirementAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lbraceLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expression)) return loc; + if (auto loc = cxx::firstSourceLocation(rbraceLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(noexceptLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(minusGreaterLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(typeConstraint)) return loc; + if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; return {}; } -auto SizeofTypeExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeId)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(sizeofLoc)) return loc; +auto CompoundRequirementAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(typeConstraint)) return loc; + if (auto loc = cxx::lastSourceLocation(minusGreaterLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(noexceptLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(rbraceLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expression)) return loc; + if (auto loc = cxx::lastSourceLocation(lbraceLoc)) return loc; return {}; } -auto SizeofPackExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(sizeofLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; +auto TypeRequirementAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(typenameLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(nestedNameSpecifier)) return loc; + if (auto loc = cxx::firstSourceLocation(name)) return loc; + if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; return {}; } -auto SizeofPackExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(sizeofLoc)) return loc; +auto TypeRequirementAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(name)) return loc; + if (auto loc = cxx::lastSourceLocation(nestedNameSpecifier)) return loc; + if (auto loc = cxx::lastSourceLocation(typenameLoc)) return loc; return {}; } -auto TypeidExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(typeidLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; +auto NestedRequirementAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(requiresLoc)) return loc; if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; return {}; } -auto TypeidExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; +auto NestedRequirementAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeidLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(requiresLoc)) return loc; return {}; } -auto TypeidOfTypeExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(typeidLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; +auto TypeTemplateArgumentAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(typeId)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto TypeidOfTypeExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; +auto TypeTemplateArgumentAST::lastSourceLocation() -> SourceLocation { if (auto loc = cxx::lastSourceLocation(typeId)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeidLoc)) return loc; return {}; } -auto AlignofExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(alignofLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(typeId)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; +auto ExpressionTemplateArgumentAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(expression)) return loc; return {}; } -auto AlignofExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeId)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(alignofLoc)) return loc; +auto ExpressionTemplateArgumentAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(expression)) return loc; return {}; } -auto TypeTraitsExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(typeTraitsLoc)) return loc; +auto ParenMemInitializerAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(name)) return loc; if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(typeIdList)) return loc; + if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; return {}; } -auto TypeTraitsExpressionAST::lastSourceLocation() -> SourceLocation { +auto ParenMemInitializerAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeIdList)) return loc; + if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeTraitsLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(name)) return loc; return {}; } -auto UnaryExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; +auto BracedMemInitializerAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(name)) return loc; + if (auto loc = cxx::firstSourceLocation(bracedInitList)) return loc; + if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; return {}; } -auto UnaryExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; +auto BracedMemInitializerAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(bracedInitList)) return loc; + if (auto loc = cxx::lastSourceLocation(name)) return loc; return {}; } -auto BinaryExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(leftExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(rightExpression)) return loc; +auto ThisLambdaCaptureAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(thisLoc)) return loc; return {}; } -auto BinaryExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rightExpression)) return loc; - if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(leftExpression)) return loc; +auto ThisLambdaCaptureAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(thisLoc)) return loc; return {}; } -auto AssignmentExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(leftExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(rightExpression)) return loc; +auto DerefThisLambdaCaptureAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(starLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(thisLoc)) return loc; return {}; } -auto AssignmentExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rightExpression)) return loc; - if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(leftExpression)) return loc; +auto DerefThisLambdaCaptureAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(thisLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(starLoc)) return loc; return {}; } -auto BracedTypeConstructionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(typeSpecifier)) return loc; - if (auto loc = cxx::firstSourceLocation(bracedInitList)) return loc; +auto SimpleLambdaCaptureAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; return {}; } -auto BracedTypeConstructionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(bracedInitList)) return loc; - if (auto loc = cxx::lastSourceLocation(typeSpecifier)) return loc; +auto SimpleLambdaCaptureAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; return {}; } -auto TypeConstructionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(typeSpecifier)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; +auto RefLambdaCaptureAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(ampLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; return {}; } -auto TypeConstructionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeSpecifier)) return loc; +auto RefLambdaCaptureAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(ampLoc)) return loc; return {}; } -auto CallExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(baseExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; +auto RefInitLambdaCaptureAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(ampLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(initializer)) return loc; return {}; } -auto CallExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(baseExpression)) return loc; +auto RefInitLambdaCaptureAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(initializer)) return loc; + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(ampLoc)) return loc; return {}; } -auto SubscriptExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(baseExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(lbracketLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(indexExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(rbracketLoc)) return loc; +auto InitLambdaCaptureAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(initializer)) return loc; return {}; } -auto SubscriptExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rbracketLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(indexExpression)) return loc; - if (auto loc = cxx::lastSourceLocation(lbracketLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(baseExpression)) return loc; +auto InitLambdaCaptureAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(initializer)) return loc; + if (auto loc = cxx::lastSourceLocation(identifierLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; return {}; } -auto MemberExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(baseExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(accessLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(templateLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(name)) return loc; +auto NewParenInitializerAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(expressionList)) return loc; + if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; return {}; } -auto MemberExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(name)) return loc; - if (auto loc = cxx::lastSourceLocation(templateLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(accessLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(baseExpression)) return loc; +auto NewParenInitializerAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(expressionList)) return loc; + if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; return {}; } -auto PostIncrExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(baseExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(opLoc)) return loc; +auto NewBracedInitializerAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(bracedInit)) return loc; return {}; } -auto PostIncrExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(opLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(baseExpression)) return loc; +auto NewBracedInitializerAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(bracedInit)) return loc; return {}; } -auto ConditionalExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(condition)) return loc; - if (auto loc = cxx::firstSourceLocation(questionLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(iftrueExpression)) return loc; - if (auto loc = cxx::firstSourceLocation(colonLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(iffalseExpression)) return loc; +auto EllipsisExceptionDeclarationAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(ellipsisLoc)) return loc; return {}; } -auto ConditionalExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(iffalseExpression)) return loc; - if (auto loc = cxx::lastSourceLocation(colonLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(iftrueExpression)) return loc; - if (auto loc = cxx::lastSourceLocation(questionLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(condition)) return loc; +auto EllipsisExceptionDeclarationAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(ellipsisLoc)) return loc; return {}; } -auto ImplicitCastExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(expression)) return loc; +auto TypeExceptionDeclarationAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(attributeList)) return loc; + if (auto loc = cxx::firstSourceLocation(typeSpecifierList)) return loc; + if (auto loc = cxx::firstSourceLocation(declarator)) return loc; return {}; } -auto ImplicitCastExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(expression)) return loc; +auto TypeExceptionDeclarationAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(declarator)) return loc; + if (auto loc = cxx::lastSourceLocation(typeSpecifierList)) return loc; + if (auto loc = cxx::lastSourceLocation(attributeList)) return loc; return {}; } -auto CastExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(typeId)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; +auto DefaultFunctionBodyAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(equalLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(defaultLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; return {}; } -auto CastExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeId)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; +auto DefaultFunctionBodyAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(defaultLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(equalLoc)) return loc; return {}; } -auto CppCastExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(castLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lessLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(typeId)) return loc; - if (auto loc = cxx::firstSourceLocation(greaterLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; +auto CompoundStatementFunctionBodyAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(ctorInitializer)) return loc; + if (auto loc = cxx::firstSourceLocation(statement)) return loc; return {}; } -auto CppCastExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(greaterLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(typeId)) return loc; - if (auto loc = cxx::lastSourceLocation(lessLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(castLoc)) return loc; +auto CompoundStatementFunctionBodyAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(statement)) return loc; + if (auto loc = cxx::lastSourceLocation(ctorInitializer)) return loc; return {}; } -auto NewExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(scopeLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(newLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(typeId)) return loc; - if (auto loc = cxx::firstSourceLocation(newInitalizer)) return loc; +auto TryStatementFunctionBodyAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(tryLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(ctorInitializer)) return loc; + if (auto loc = cxx::firstSourceLocation(statement)) return loc; + if (auto loc = cxx::firstSourceLocation(handlerList)) return loc; return {}; } -auto NewExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(newInitalizer)) return loc; - if (auto loc = cxx::lastSourceLocation(typeId)) return loc; - if (auto loc = cxx::lastSourceLocation(newLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(scopeLoc)) return loc; +auto TryStatementFunctionBodyAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(handlerList)) return loc; + if (auto loc = cxx::lastSourceLocation(statement)) return loc; + if (auto loc = cxx::lastSourceLocation(ctorInitializer)) return loc; + if (auto loc = cxx::lastSourceLocation(tryLoc)) return loc; return {}; } -auto DeleteExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(scopeLoc)) return loc; +auto DeleteFunctionBodyAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(equalLoc)) return loc; if (auto loc = cxx::firstSourceLocation(deleteLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lbracketLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(rbracketLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; + if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; return {}; } -auto DeleteExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(rbracketLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(lbracketLoc)) return loc; +auto DeleteFunctionBodyAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; if (auto loc = cxx::lastSourceLocation(deleteLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(scopeLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(equalLoc)) return loc; return {}; } -auto ThrowExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(throwLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; +auto TranslationUnitAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(declarationList)) return loc; return {}; } -auto ThrowExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(throwLoc)) return loc; +auto TranslationUnitAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(declarationList)) return loc; return {}; } -auto NoexceptExpressionAST::firstSourceLocation() -> SourceLocation { - if (auto loc = cxx::firstSourceLocation(noexceptLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::firstSourceLocation(expression)) return loc; - if (auto loc = cxx::firstSourceLocation(rparenLoc)) return loc; +auto ModuleUnitAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(globalModuleFragment)) return loc; + if (auto loc = cxx::firstSourceLocation(moduleDeclaration)) return loc; + if (auto loc = cxx::firstSourceLocation(declarationList)) return loc; + if (auto loc = cxx::firstSourceLocation(privateModuleFragment)) return loc; return {}; } -auto NoexceptExpressionAST::lastSourceLocation() -> SourceLocation { - if (auto loc = cxx::lastSourceLocation(rparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(expression)) return loc; - if (auto loc = cxx::lastSourceLocation(lparenLoc)) return loc; - if (auto loc = cxx::lastSourceLocation(noexceptLoc)) return loc; +auto ModuleUnitAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(privateModuleFragment)) return loc; + if (auto loc = cxx::lastSourceLocation(declarationList)) return loc; + if (auto loc = cxx::lastSourceLocation(moduleDeclaration)) return loc; + if (auto loc = cxx::lastSourceLocation(globalModuleFragment)) return loc; return {}; } diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index a7bcf52c..e078b8e8 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -162,6 +162,9 @@ union Expression { DeleteExpression, ThrowExpression, NoexceptExpression, + EqualInitializer, + BracedInitList, + ParenInitializer, } union FunctionBody { @@ -171,12 +174,6 @@ union FunctionBody { DeleteFunctionBody, } -union Initializer { - EqualInitializer, - BracedInitList, - ParenInitializer, -} - union LambdaCapture { ThisLambdaCapture, DerefThisLambdaCapture, @@ -331,7 +328,7 @@ table Declarator /* AST */ { table InitDeclarator /* AST */ { declarator: Declarator; requires_clause: RequiresClause; - initializer: Initializer; + initializer: Expression; } table BaseSpecifier /* AST */ { @@ -765,7 +762,7 @@ table TypeExceptionDeclaration /* ExceptionDeclarationAST */ { table DesignatedInitializerClause /* ExpressionAST */ { designator: Designator; - initializer: Initializer; + initializer: Expression; } table ThisExpression /* ExpressionAST */ { @@ -1029,6 +1026,24 @@ table NoexceptExpression /* ExpressionAST */ { rparen_loc: SourceLocation; } +table EqualInitializer /* ExpressionAST */ { + expression: Expression; + equal_loc: SourceLocation; +} + +table BracedInitList /* ExpressionAST */ { + expression_list: [Expression]; + lbrace_loc: SourceLocation; + comma_loc: SourceLocation; + rbrace_loc: SourceLocation; +} + +table ParenInitializer /* ExpressionAST */ { + expression_list: [Expression]; + lparen_loc: SourceLocation; + rparen_loc: SourceLocation; +} + table DefaultFunctionBody /* FunctionBodyAST */ { equal_loc: SourceLocation; default_loc: SourceLocation; @@ -1053,24 +1068,6 @@ table DeleteFunctionBody /* FunctionBodyAST */ { semicolon_loc: SourceLocation; } -table EqualInitializer /* InitializerAST */ { - expression: Expression; - equal_loc: SourceLocation; -} - -table BracedInitList /* InitializerAST */ { - expression_list: [Expression]; - lbrace_loc: SourceLocation; - comma_loc: SourceLocation; - rbrace_loc: SourceLocation; -} - -table ParenInitializer /* InitializerAST */ { - expression_list: [Expression]; - lparen_loc: SourceLocation; - rparen_loc: SourceLocation; -} - table ThisLambdaCapture /* LambdaCaptureAST */ { this_loc: SourceLocation; } @@ -1094,7 +1091,7 @@ table RefLambdaCapture /* LambdaCaptureAST */ { } table RefInitLambdaCapture /* LambdaCaptureAST */ { - initializer: Initializer; + initializer: Expression; identifier: string; amp_loc: SourceLocation; ellipsis_loc: SourceLocation; @@ -1102,7 +1099,7 @@ table RefInitLambdaCapture /* LambdaCaptureAST */ { } table InitLambdaCapture /* LambdaCaptureAST */ { - initializer: Initializer; + initializer: Expression; identifier: string; ellipsis_loc: SourceLocation; identifier_loc: SourceLocation; diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index 482d8ceb..e03ed93a 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -142,11 +142,6 @@ class FunctionBodyAST : public AST { using AST::AST; }; -class InitializerAST : public AST { - public: - using AST::AST; -}; - class LambdaCaptureAST : public AST { public: using AST::AST; @@ -303,7 +298,7 @@ class InitDeclaratorAST final : public AST { DeclaratorAST* declarator = nullptr; RequiresClauseAST* requiresClause = nullptr; - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -628,7 +623,7 @@ class DesignatedInitializerClauseAST final : public ExpressionAST { : ExpressionAST(ASTKind::DesignatedInitializerClause) {} DesignatorAST* designator = nullptr; - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1219,6 +1214,48 @@ class NoexceptExpressionAST final : public ExpressionAST { auto lastSourceLocation() -> SourceLocation override; }; +class EqualInitializerAST final : public ExpressionAST { + public: + EqualInitializerAST() : ExpressionAST(ASTKind::EqualInitializer) {} + + SourceLocation equalLoc; + ExpressionAST* expression = nullptr; + + void accept(ASTVisitor* visitor) override { visitor->visit(this); } + + auto firstSourceLocation() -> SourceLocation override; + auto lastSourceLocation() -> SourceLocation override; +}; + +class BracedInitListAST final : public ExpressionAST { + public: + BracedInitListAST() : ExpressionAST(ASTKind::BracedInitList) {} + + SourceLocation lbraceLoc; + List* expressionList = nullptr; + SourceLocation commaLoc; + SourceLocation rbraceLoc; + + void accept(ASTVisitor* visitor) override { visitor->visit(this); } + + auto firstSourceLocation() -> SourceLocation override; + auto lastSourceLocation() -> SourceLocation override; +}; + +class ParenInitializerAST final : public ExpressionAST { + public: + ParenInitializerAST() : ExpressionAST(ASTKind::ParenInitializer) {} + + SourceLocation lparenLoc; + List* expressionList = nullptr; + SourceLocation rparenLoc; + + void accept(ASTVisitor* visitor) override { visitor->visit(this); } + + auto firstSourceLocation() -> SourceLocation override; + auto lastSourceLocation() -> SourceLocation override; +}; + class SimpleRequirementAST final : public RequirementAST { public: SimpleRequirementAST() : RequirementAST(ASTKind::SimpleRequirement) {} @@ -1398,7 +1435,7 @@ class RefInitLambdaCaptureAST final : public LambdaCaptureAST { SourceLocation ampLoc; SourceLocation ellipsisLoc; SourceLocation identifierLoc; - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1413,7 +1450,7 @@ class InitLambdaCaptureAST final : public LambdaCaptureAST { SourceLocation ellipsisLoc; SourceLocation identifierLoc; - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; const Identifier* identifier = nullptr; void accept(ASTVisitor* visitor) override { visitor->visit(this); } @@ -1422,48 +1459,6 @@ class InitLambdaCaptureAST final : public LambdaCaptureAST { auto lastSourceLocation() -> SourceLocation override; }; -class EqualInitializerAST final : public InitializerAST { - public: - EqualInitializerAST() : InitializerAST(ASTKind::EqualInitializer) {} - - SourceLocation equalLoc; - ExpressionAST* expression = nullptr; - - void accept(ASTVisitor* visitor) override { visitor->visit(this); } - - auto firstSourceLocation() -> SourceLocation override; - auto lastSourceLocation() -> SourceLocation override; -}; - -class BracedInitListAST final : public InitializerAST { - public: - BracedInitListAST() : InitializerAST(ASTKind::BracedInitList) {} - - SourceLocation lbraceLoc; - List* expressionList = nullptr; - SourceLocation commaLoc; - SourceLocation rbraceLoc; - - void accept(ASTVisitor* visitor) override { visitor->visit(this); } - - auto firstSourceLocation() -> SourceLocation override; - auto lastSourceLocation() -> SourceLocation override; -}; - -class ParenInitializerAST final : public InitializerAST { - public: - ParenInitializerAST() : InitializerAST(ASTKind::ParenInitializer) {} - - SourceLocation lparenLoc; - List* expressionList = nullptr; - SourceLocation rparenLoc; - - void accept(ASTVisitor* visitor) override { visitor->visit(this); } - - auto firstSourceLocation() -> SourceLocation override; - auto lastSourceLocation() -> SourceLocation override; -}; - class NewParenInitializerAST final : public NewInitializerAST { public: NewParenInitializerAST() : NewInitializerAST(ASTKind::NewParenInitializer) {} diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index f9021ab0..27c40465 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -1341,6 +1341,71 @@ void ASTCloner::visit(NoexceptExpressionAST* ast) { copy->rparenLoc = ast->rparenLoc; } +void ASTCloner::visit(EqualInitializerAST* ast) { + auto copy = new (arena_) EqualInitializerAST(); + copy_ = copy; + + copy->setChecked(ast->checked()); + + copy->valueCategory = ast->valueCategory; + + copy->constValue = ast->constValue; + + copy->equalLoc = ast->equalLoc; + + copy->expression = accept(ast->expression); +} + +void ASTCloner::visit(BracedInitListAST* ast) { + auto copy = new (arena_) BracedInitListAST(); + copy_ = copy; + + copy->setChecked(ast->checked()); + + copy->valueCategory = ast->valueCategory; + + copy->constValue = ast->constValue; + + copy->lbraceLoc = ast->lbraceLoc; + + if (auto it = ast->expressionList) { + auto out = ©->expressionList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } + + copy->commaLoc = ast->commaLoc; + + copy->rbraceLoc = ast->rbraceLoc; +} + +void ASTCloner::visit(ParenInitializerAST* ast) { + auto copy = new (arena_) ParenInitializerAST(); + copy_ = copy; + + copy->setChecked(ast->checked()); + + copy->valueCategory = ast->valueCategory; + + copy->constValue = ast->constValue; + + copy->lparenLoc = ast->lparenLoc; + + if (auto it = ast->expressionList) { + auto out = ©->expressionList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } + + copy->rparenLoc = ast->rparenLoc; +} + void ASTCloner::visit(SimpleRequirementAST* ast) { auto copy = new (arena_) SimpleRequirementAST(); copy_ = copy; @@ -1536,59 +1601,6 @@ void ASTCloner::visit(InitLambdaCaptureAST* ast) { copy->identifier = ast->identifier; } -void ASTCloner::visit(EqualInitializerAST* ast) { - auto copy = new (arena_) EqualInitializerAST(); - copy_ = copy; - - copy->setChecked(ast->checked()); - - copy->equalLoc = ast->equalLoc; - - copy->expression = accept(ast->expression); -} - -void ASTCloner::visit(BracedInitListAST* ast) { - auto copy = new (arena_) BracedInitListAST(); - copy_ = copy; - - copy->setChecked(ast->checked()); - - copy->lbraceLoc = ast->lbraceLoc; - - if (auto it = ast->expressionList) { - auto out = ©->expressionList; - - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } - - copy->commaLoc = ast->commaLoc; - - copy->rbraceLoc = ast->rbraceLoc; -} - -void ASTCloner::visit(ParenInitializerAST* ast) { - auto copy = new (arena_) ParenInitializerAST(); - copy_ = copy; - - copy->setChecked(ast->checked()); - - copy->lparenLoc = ast->lparenLoc; - - if (auto it = ast->expressionList) { - auto out = ©->expressionList; - - for (; it; it = it->next) { - *out = new (arena_) List(accept(it->value)); - out = &(*out)->next; - } - } - - copy->rparenLoc = ast->rparenLoc; -} - void ASTCloner::visit(NewParenInitializerAST* ast) { auto copy = new (arena_) NewParenInitializerAST(); copy_ = copy; diff --git a/src/parser/cxx/ast_cloner.h b/src/parser/cxx/ast_cloner.h index 66dcfdf3..39f4de6e 100644 --- a/src/parser/cxx/ast_cloner.h +++ b/src/parser/cxx/ast_cloner.h @@ -101,6 +101,9 @@ class ASTCloner : public ASTVisitor { void visit(DeleteExpressionAST* ast) override; void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; void visit(SimpleRequirementAST* ast) override; void visit(CompoundRequirementAST* ast) override; @@ -120,10 +123,6 @@ class ASTCloner : public ASTVisitor { void visit(RefInitLambdaCaptureAST* ast) override; void visit(InitLambdaCaptureAST* ast) override; - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - void visit(NewParenInitializerAST* ast) override; void visit(NewBracedInitializerAST* ast) override; diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index 13912e3a..1bad1779 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -169,6 +169,15 @@ auto ASTDecoder::decodeExpression(const void* ptr, io::Expression type) case io::Expression_NoexceptExpression: return decodeNoexceptExpression( reinterpret_cast(ptr)); + case io::Expression_EqualInitializer: + return decodeEqualInitializer( + reinterpret_cast(ptr)); + case io::Expression_BracedInitList: + return decodeBracedInitList( + reinterpret_cast(ptr)); + case io::Expression_ParenInitializer: + return decodeParenInitializer( + reinterpret_cast(ptr)); default: return nullptr; } // switch @@ -249,23 +258,6 @@ auto ASTDecoder::decodeLambdaCapture(const void* ptr, io::LambdaCapture type) } // switch } -auto ASTDecoder::decodeInitializer(const void* ptr, io::Initializer type) - -> InitializerAST* { - switch (type) { - case io::Initializer_EqualInitializer: - return decodeEqualInitializer( - reinterpret_cast(ptr)); - case io::Initializer_BracedInitList: - return decodeBracedInitList( - reinterpret_cast(ptr)); - case io::Initializer_ParenInitializer: - return decodeParenInitializer( - reinterpret_cast(ptr)); - default: - return nullptr; - } // switch -} - auto ASTDecoder::decodeNewInitializer(const void* ptr, io::NewInitializer type) -> NewInitializerAST* { switch (type) { @@ -812,7 +804,7 @@ auto ASTDecoder::decodeInitDeclarator(const io::InitDeclarator* node) ast->declarator = decodeDeclarator(node->declarator()); ast->requiresClause = decodeRequiresClause(node->requires_clause()); ast->initializer = - decodeInitializer(node->initializer(), node->initializer_type()); + decodeExpression(node->initializer(), node->initializer_type()); return ast; } @@ -1152,7 +1144,7 @@ auto ASTDecoder::decodeDesignatedInitializerClause( auto ast = new (pool_) DesignatedInitializerClauseAST(); ast->designator = decodeDesignator(node->designator()); ast->initializer = - decodeInitializer(node->initializer(), node->initializer_type()); + decodeExpression(node->initializer(), node->initializer_type()); return ast; } @@ -1603,6 +1595,50 @@ auto ASTDecoder::decodeNoexceptExpression(const io::NoexceptExpression* node) return ast; } +auto ASTDecoder::decodeEqualInitializer(const io::EqualInitializer* node) + -> EqualInitializerAST* { + if (!node) return nullptr; + + auto ast = new (pool_) EqualInitializerAST(); + ast->expression = + decodeExpression(node->expression(), node->expression_type()); + return ast; +} + +auto ASTDecoder::decodeBracedInitList(const io::BracedInitList* node) + -> BracedInitListAST* { + if (!node) return nullptr; + + auto ast = new (pool_) BracedInitListAST(); + if (node->expression_list()) { + auto* inserter = &ast->expressionList; + for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { + *inserter = new (pool_) List(decodeExpression( + node->expression_list()->Get(i), + io::Expression(node->expression_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } + return ast; +} + +auto ASTDecoder::decodeParenInitializer(const io::ParenInitializer* node) + -> ParenInitializerAST* { + if (!node) return nullptr; + + auto ast = new (pool_) ParenInitializerAST(); + if (node->expression_list()) { + auto* inserter = &ast->expressionList; + for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { + *inserter = new (pool_) List(decodeExpression( + node->expression_list()->Get(i), + io::Expression(node->expression_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } + return ast; +} + auto ASTDecoder::decodeSimpleRequirement(const io::SimpleRequirement* node) -> SimpleRequirementAST* { if (!node) return nullptr; @@ -1739,7 +1775,7 @@ auto ASTDecoder::decodeRefInitLambdaCapture( auto ast = new (pool_) RefInitLambdaCaptureAST(); ast->initializer = - decodeInitializer(node->initializer(), node->initializer_type()); + decodeExpression(node->initializer(), node->initializer_type()); if (node->identifier()) { ast->identifier = unit_->control()->getIdentifier(node->identifier()->str()); @@ -1753,7 +1789,7 @@ auto ASTDecoder::decodeInitLambdaCapture(const io::InitLambdaCapture* node) auto ast = new (pool_) InitLambdaCaptureAST(); ast->initializer = - decodeInitializer(node->initializer(), node->initializer_type()); + decodeExpression(node->initializer(), node->initializer_type()); if (node->identifier()) { ast->identifier = unit_->control()->getIdentifier(node->identifier()->str()); @@ -1761,50 +1797,6 @@ auto ASTDecoder::decodeInitLambdaCapture(const io::InitLambdaCapture* node) return ast; } -auto ASTDecoder::decodeEqualInitializer(const io::EqualInitializer* node) - -> EqualInitializerAST* { - if (!node) return nullptr; - - auto ast = new (pool_) EqualInitializerAST(); - ast->expression = - decodeExpression(node->expression(), node->expression_type()); - return ast; -} - -auto ASTDecoder::decodeBracedInitList(const io::BracedInitList* node) - -> BracedInitListAST* { - if (!node) return nullptr; - - auto ast = new (pool_) BracedInitListAST(); - if (node->expression_list()) { - auto* inserter = &ast->expressionList; - for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { - *inserter = new (pool_) List(decodeExpression( - node->expression_list()->Get(i), - io::Expression(node->expression_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } - } - return ast; -} - -auto ASTDecoder::decodeParenInitializer(const io::ParenInitializer* node) - -> ParenInitializerAST* { - if (!node) return nullptr; - - auto ast = new (pool_) ParenInitializerAST(); - if (node->expression_list()) { - auto* inserter = &ast->expressionList; - for (std::size_t i = 0; i < node->expression_list()->size(); ++i) { - *inserter = new (pool_) List(decodeExpression( - node->expression_list()->Get(i), - io::Expression(node->expression_list_type()->Get(i)))); - inserter = &(*inserter)->next; - } - } - return ast; -} - auto ASTDecoder::decodeNewParenInitializer(const io::NewParenInitializer* node) -> NewParenInitializerAST* { if (!node) return nullptr; diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index 84b9ba78..a2c7fe8e 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -191,19 +191,6 @@ auto ASTEncoder::acceptLambdaCapture(LambdaCaptureAST* ast) return {offset, type}; } -auto ASTEncoder::acceptInitializer(InitializerAST* ast) - -> std::tuple, std::uint32_t> { - if (!ast) return {}; - flatbuffers::Offset<> offset; - std::uint32_t type = 0; - std::swap(offset, offset_); - std::swap(type, type_); - ast->accept(this); - std::swap(offset, offset_); - std::swap(type, type_); - return {offset, type}; -} - auto ASTEncoder::acceptNewInitializer(NewInitializerAST* ast) -> std::tuple, std::uint32_t> { if (!ast) return {}; @@ -580,13 +567,13 @@ void ASTEncoder::visit(InitDeclaratorAST* ast) { const auto requiresClause = accept(ast->requiresClause); const auto [initializer, initializerType] = - acceptInitializer(ast->initializer); + acceptExpression(ast->initializer); io::InitDeclarator::Builder builder{fbb_}; builder.add_declarator(declarator.o); builder.add_requires_clause(requiresClause.o); builder.add_initializer(initializer); - builder.add_initializer_type(static_cast(initializerType)); + builder.add_initializer_type(static_cast(initializerType)); offset_ = builder.Finish().Union(); } @@ -1113,12 +1100,12 @@ void ASTEncoder::visit(DesignatedInitializerClauseAST* ast) { const auto designator = accept(ast->designator); const auto [initializer, initializerType] = - acceptInitializer(ast->initializer); + acceptExpression(ast->initializer); io::DesignatedInitializerClause::Builder builder{fbb_}; builder.add_designator(designator.o); builder.add_initializer(initializer); - builder.add_initializer_type(static_cast(initializerType)); + builder.add_initializer_type(static_cast(initializerType)); offset_ = builder.Finish().Union(); type_ = io::Expression_DesignatedInitializerClause; @@ -1966,6 +1953,79 @@ void ASTEncoder::visit(NoexceptExpressionAST* ast) { type_ = io::Expression_NoexceptExpression; } +void ASTEncoder::visit(EqualInitializerAST* ast) { + auto equalLoc = encodeSourceLocation(ast->equalLoc); + + const auto [expression, expressionType] = acceptExpression(ast->expression); + + io::EqualInitializer::Builder builder{fbb_}; + builder.add_equal_loc(equalLoc.o); + builder.add_expression(expression); + builder.add_expression_type(static_cast(expressionType)); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_EqualInitializer; +} + +void ASTEncoder::visit(BracedInitListAST* ast) { + auto lbraceLoc = encodeSourceLocation(ast->lbraceLoc); + + std::vector> expressionListOffsets; + std::vector> expressionListTypes; + + for (auto it = ast->expressionList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptExpression(it->value); + expressionListOffsets.push_back(offset); + expressionListTypes.push_back(type); + } + + auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); + auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); + + auto commaLoc = encodeSourceLocation(ast->commaLoc); + + auto rbraceLoc = encodeSourceLocation(ast->rbraceLoc); + + io::BracedInitList::Builder builder{fbb_}; + builder.add_lbrace_loc(lbraceLoc.o); + builder.add_expression_list(expressionListOffsetsVector); + builder.add_expression_list_type(expressionListTypesVector); + builder.add_comma_loc(commaLoc.o); + builder.add_rbrace_loc(rbraceLoc.o); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_BracedInitList; +} + +void ASTEncoder::visit(ParenInitializerAST* ast) { + auto lparenLoc = encodeSourceLocation(ast->lparenLoc); + + std::vector> expressionListOffsets; + std::vector> expressionListTypes; + + for (auto it = ast->expressionList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptExpression(it->value); + expressionListOffsets.push_back(offset); + expressionListTypes.push_back(type); + } + + auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); + auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); + + auto rparenLoc = encodeSourceLocation(ast->rparenLoc); + + io::ParenInitializer::Builder builder{fbb_}; + builder.add_lparen_loc(lparenLoc.o); + builder.add_expression_list(expressionListOffsetsVector); + builder.add_expression_list_type(expressionListTypesVector); + builder.add_rparen_loc(rparenLoc.o); + + offset_ = builder.Finish().Union(); + type_ = io::Expression_ParenInitializer; +} + void ASTEncoder::visit(SimpleRequirementAST* ast) { const auto [expression, expressionType] = acceptExpression(ast->expression); @@ -2205,7 +2265,7 @@ void ASTEncoder::visit(RefInitLambdaCaptureAST* ast) { auto identifierLoc = encodeSourceLocation(ast->identifierLoc); const auto [initializer, initializerType] = - acceptInitializer(ast->initializer); + acceptExpression(ast->initializer); flatbuffers::Offset identifier; if (ast->identifier) { @@ -2222,7 +2282,7 @@ void ASTEncoder::visit(RefInitLambdaCaptureAST* ast) { builder.add_ellipsis_loc(ellipsisLoc.o); builder.add_identifier_loc(identifierLoc.o); builder.add_initializer(initializer); - builder.add_initializer_type(static_cast(initializerType)); + builder.add_initializer_type(static_cast(initializerType)); if (ast->identifier) { builder.add_identifier(identifier); } @@ -2237,7 +2297,7 @@ void ASTEncoder::visit(InitLambdaCaptureAST* ast) { auto identifierLoc = encodeSourceLocation(ast->identifierLoc); const auto [initializer, initializerType] = - acceptInitializer(ast->initializer); + acceptExpression(ast->initializer); flatbuffers::Offset identifier; if (ast->identifier) { @@ -2253,7 +2313,7 @@ void ASTEncoder::visit(InitLambdaCaptureAST* ast) { builder.add_ellipsis_loc(ellipsisLoc.o); builder.add_identifier_loc(identifierLoc.o); builder.add_initializer(initializer); - builder.add_initializer_type(static_cast(initializerType)); + builder.add_initializer_type(static_cast(initializerType)); if (ast->identifier) { builder.add_identifier(identifier); } @@ -2262,79 +2322,6 @@ void ASTEncoder::visit(InitLambdaCaptureAST* ast) { type_ = io::LambdaCapture_InitLambdaCapture; } -void ASTEncoder::visit(EqualInitializerAST* ast) { - auto equalLoc = encodeSourceLocation(ast->equalLoc); - - const auto [expression, expressionType] = acceptExpression(ast->expression); - - io::EqualInitializer::Builder builder{fbb_}; - builder.add_equal_loc(equalLoc.o); - builder.add_expression(expression); - builder.add_expression_type(static_cast(expressionType)); - - offset_ = builder.Finish().Union(); - type_ = io::Initializer_EqualInitializer; -} - -void ASTEncoder::visit(BracedInitListAST* ast) { - auto lbraceLoc = encodeSourceLocation(ast->lbraceLoc); - - std::vector> expressionListOffsets; - std::vector> expressionListTypes; - - for (auto it = ast->expressionList; it; it = it->next) { - if (!it->value) continue; - const auto [offset, type] = acceptExpression(it->value); - expressionListOffsets.push_back(offset); - expressionListTypes.push_back(type); - } - - auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); - auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); - - auto commaLoc = encodeSourceLocation(ast->commaLoc); - - auto rbraceLoc = encodeSourceLocation(ast->rbraceLoc); - - io::BracedInitList::Builder builder{fbb_}; - builder.add_lbrace_loc(lbraceLoc.o); - builder.add_expression_list(expressionListOffsetsVector); - builder.add_expression_list_type(expressionListTypesVector); - builder.add_comma_loc(commaLoc.o); - builder.add_rbrace_loc(rbraceLoc.o); - - offset_ = builder.Finish().Union(); - type_ = io::Initializer_BracedInitList; -} - -void ASTEncoder::visit(ParenInitializerAST* ast) { - auto lparenLoc = encodeSourceLocation(ast->lparenLoc); - - std::vector> expressionListOffsets; - std::vector> expressionListTypes; - - for (auto it = ast->expressionList; it; it = it->next) { - if (!it->value) continue; - const auto [offset, type] = acceptExpression(it->value); - expressionListOffsets.push_back(offset); - expressionListTypes.push_back(type); - } - - auto expressionListOffsetsVector = fbb_.CreateVector(expressionListOffsets); - auto expressionListTypesVector = fbb_.CreateVector(expressionListTypes); - - auto rparenLoc = encodeSourceLocation(ast->rparenLoc); - - io::ParenInitializer::Builder builder{fbb_}; - builder.add_lparen_loc(lparenLoc.o); - builder.add_expression_list(expressionListOffsetsVector); - builder.add_expression_list_type(expressionListTypesVector); - builder.add_rparen_loc(rparenLoc.o); - - offset_ = builder.Finish().Union(); - type_ = io::Initializer_ParenInitializer; -} - void ASTEncoder::visit(NewParenInitializerAST* ast) { auto lparenLoc = encodeSourceLocation(ast->lparenLoc); diff --git a/src/parser/cxx/ast_fwd.h b/src/parser/cxx/ast_fwd.h index 1a0890d9..e5d2c31a 100644 --- a/src/parser/cxx/ast_fwd.h +++ b/src/parser/cxx/ast_fwd.h @@ -60,7 +60,6 @@ class DeclaratorModifierAST; class ExceptionDeclarationAST; class ExpressionAST; class FunctionBodyAST; -class InitializerAST; class LambdaCaptureAST; class MemInitializerAST; class NameAST; @@ -145,6 +144,9 @@ class NewExpressionAST; class DeleteExpressionAST; class ThrowExpressionAST; class NoexceptExpressionAST; +class EqualInitializerAST; +class BracedInitListAST; +class ParenInitializerAST; // RequirementAST class SimpleRequirementAST; @@ -168,11 +170,6 @@ class RefLambdaCaptureAST; class RefInitLambdaCaptureAST; class InitLambdaCaptureAST; -// InitializerAST -class EqualInitializerAST; -class BracedInitListAST; -class ParenInitializerAST; - // NewInitializerAST class NewParenInitializerAST; class NewBracedInitializerAST; diff --git a/src/parser/cxx/ast_kind.h b/src/parser/cxx/ast_kind.h index 7c64d141..c40e9eeb 100644 --- a/src/parser/cxx/ast_kind.h +++ b/src/parser/cxx/ast_kind.h @@ -97,6 +97,9 @@ enum struct ASTKind { DeleteExpression, ThrowExpression, NoexceptExpression, + EqualInitializer, + BracedInitList, + ParenInitializer, // RequirementAST SimpleRequirement, @@ -120,11 +123,6 @@ enum struct ASTKind { RefInitLambdaCapture, InitLambdaCapture, - // InitializerAST - EqualInitializer, - BracedInitList, - ParenInitializer, - // NewInitializerAST NewParenInitializer, NewBracedInitializer, diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index 9360e3cc..0bf50f42 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -1415,6 +1415,63 @@ void ASTSlot::visit(NoexceptExpressionAST* ast) { slotCount_ = 4; } +void ASTSlot::visit(EqualInitializerAST* ast) { + switch (slot_) { + case 0: + value_ = ast->equalLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = reinterpret_cast(ast->expression); + slotKind_ = ASTSlotKind::kNode; + break; + } // switch + + slotCount_ = 2; +} + +void ASTSlot::visit(BracedInitListAST* ast) { + switch (slot_) { + case 0: + value_ = ast->lbraceLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = reinterpret_cast(ast->expressionList); + slotKind_ = ASTSlotKind::kNodeList; + break; + case 2: + value_ = ast->commaLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 3: + value_ = ast->rbraceLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + } // switch + + slotCount_ = 4; +} + +void ASTSlot::visit(ParenInitializerAST* ast) { + switch (slot_) { + case 0: + value_ = ast->lparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 1: + value_ = reinterpret_cast(ast->expressionList); + slotKind_ = ASTSlotKind::kNodeList; + break; + case 2: + value_ = ast->rparenLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + } // switch + + slotCount_ = 3; +} + void ASTSlot::visit(SimpleRequirementAST* ast) { switch (slot_) { case 0: @@ -1677,63 +1734,6 @@ void ASTSlot::visit(InitLambdaCaptureAST* ast) { slotCount_ = 3; } -void ASTSlot::visit(EqualInitializerAST* ast) { - switch (slot_) { - case 0: - value_ = ast->equalLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 1: - value_ = reinterpret_cast(ast->expression); - slotKind_ = ASTSlotKind::kNode; - break; - } // switch - - slotCount_ = 2; -} - -void ASTSlot::visit(BracedInitListAST* ast) { - switch (slot_) { - case 0: - value_ = ast->lbraceLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 1: - value_ = reinterpret_cast(ast->expressionList); - slotKind_ = ASTSlotKind::kNodeList; - break; - case 2: - value_ = ast->commaLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 3: - value_ = ast->rbraceLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - } // switch - - slotCount_ = 4; -} - -void ASTSlot::visit(ParenInitializerAST* ast) { - switch (slot_) { - case 0: - value_ = ast->lparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - case 1: - value_ = reinterpret_cast(ast->expressionList); - slotKind_ = ASTSlotKind::kNodeList; - break; - case 2: - value_ = ast->rparenLoc.index(); - slotKind_ = ASTSlotKind::kToken; - break; - } // switch - - slotCount_ = 3; -} - void ASTSlot::visit(NewParenInitializerAST* ast) { switch (slot_) { case 0: diff --git a/src/parser/cxx/ast_slot.h b/src/parser/cxx/ast_slot.h index c78943e9..8302652a 100644 --- a/src/parser/cxx/ast_slot.h +++ b/src/parser/cxx/ast_slot.h @@ -112,6 +112,9 @@ class ASTSlot final : ASTVisitor { void visit(DeleteExpressionAST* ast) override; void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; void visit(SimpleRequirementAST* ast) override; void visit(CompoundRequirementAST* ast) override; @@ -131,10 +134,6 @@ class ASTSlot final : ASTVisitor { void visit(RefInitLambdaCaptureAST* ast) override; void visit(InitLambdaCaptureAST* ast) override; - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - void visit(NewParenInitializerAST* ast) override; void visit(NewBracedInitializerAST* ast) override; diff --git a/src/parser/cxx/ast_visitor.h b/src/parser/cxx/ast_visitor.h index b24678a0..7581b72b 100644 --- a/src/parser/cxx/ast_visitor.h +++ b/src/parser/cxx/ast_visitor.h @@ -101,6 +101,9 @@ class ASTVisitor { virtual void visit(DeleteExpressionAST* ast) = 0; virtual void visit(ThrowExpressionAST* ast) = 0; virtual void visit(NoexceptExpressionAST* ast) = 0; + virtual void visit(EqualInitializerAST* ast) = 0; + virtual void visit(BracedInitListAST* ast) = 0; + virtual void visit(ParenInitializerAST* ast) = 0; // RequirementAST virtual void visit(SimpleRequirementAST* ast) = 0; @@ -124,11 +127,6 @@ class ASTVisitor { virtual void visit(RefInitLambdaCaptureAST* ast) = 0; virtual void visit(InitLambdaCaptureAST* ast) = 0; - // InitializerAST - virtual void visit(EqualInitializerAST* ast) = 0; - virtual void visit(BracedInitListAST* ast) = 0; - virtual void visit(ParenInitializerAST* ast) = 0; - // NewInitializerAST virtual void visit(NewParenInitializerAST* ast) = 0; virtual void visit(NewBracedInitializerAST* ast) = 0; diff --git a/src/parser/cxx/default_ast_visitor.cc b/src/parser/cxx/default_ast_visitor.cc index 062fad86..a529ab7b 100644 --- a/src/parser/cxx/default_ast_visitor.cc +++ b/src/parser/cxx/default_ast_visitor.cc @@ -308,6 +308,18 @@ void DefaultASTVisitor::visit(NoexceptExpressionAST* ast) { cxx_runtime_error("visit(NoexceptExpressionAST): not implemented"); } +void DefaultASTVisitor::visit(EqualInitializerAST* ast) { + cxx_runtime_error("visit(EqualInitializerAST): not implemented"); +} + +void DefaultASTVisitor::visit(BracedInitListAST* ast) { + cxx_runtime_error("visit(BracedInitListAST): not implemented"); +} + +void DefaultASTVisitor::visit(ParenInitializerAST* ast) { + cxx_runtime_error("visit(ParenInitializerAST): not implemented"); +} + // RequirementAST void DefaultASTVisitor::visit(SimpleRequirementAST* ast) { cxx_runtime_error("visit(SimpleRequirementAST): not implemented"); @@ -368,19 +380,6 @@ void DefaultASTVisitor::visit(InitLambdaCaptureAST* ast) { cxx_runtime_error("visit(InitLambdaCaptureAST): not implemented"); } -// InitializerAST -void DefaultASTVisitor::visit(EqualInitializerAST* ast) { - cxx_runtime_error("visit(EqualInitializerAST): not implemented"); -} - -void DefaultASTVisitor::visit(BracedInitListAST* ast) { - cxx_runtime_error("visit(BracedInitListAST): not implemented"); -} - -void DefaultASTVisitor::visit(ParenInitializerAST* ast) { - cxx_runtime_error("visit(ParenInitializerAST): not implemented"); -} - // NewInitializerAST void DefaultASTVisitor::visit(NewParenInitializerAST* ast) { cxx_runtime_error("visit(NewParenInitializerAST): not implemented"); diff --git a/src/parser/cxx/default_ast_visitor.h b/src/parser/cxx/default_ast_visitor.h index 77e120eb..3605fdb5 100644 --- a/src/parser/cxx/default_ast_visitor.h +++ b/src/parser/cxx/default_ast_visitor.h @@ -99,6 +99,9 @@ class DefaultASTVisitor : public ASTVisitor { void visit(DeleteExpressionAST* ast) override; void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; // RequirementAST void visit(SimpleRequirementAST* ast) override; @@ -122,11 +125,6 @@ class DefaultASTVisitor : public ASTVisitor { void visit(RefInitLambdaCaptureAST* ast) override; void visit(InitLambdaCaptureAST* ast) override; - // InitializerAST - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - // NewInitializerAST void visit(NewParenInitializerAST* ast) override; void visit(NewBracedInitializerAST* ast) override; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 6c4c269c..72006963 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -1126,7 +1126,7 @@ auto Parser::parse_init_capture(LambdaCaptureAST*& yyast) -> bool { if (!match(TokenKind::T_IDENTIFIER, identifierLoc)) return false; - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; if (!parse_initializer(initializer)) return false; @@ -1150,7 +1150,7 @@ auto Parser::parse_init_capture(LambdaCaptureAST*& yyast) -> bool { if (!match(TokenKind::T_IDENTIFIER, identifierLoc)) return false; - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; if (!parse_initializer(initializer)) return false; @@ -2783,7 +2783,7 @@ auto Parser::parse_condition(ExpressionAST*& yyast) -> bool { DeclaratorAST* declarator = nullptr; if (parse_declarator(declarator)) { - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; if (parse_brace_or_equal_initializer(initializer)) return true; } @@ -3507,7 +3507,7 @@ auto Parser::parse_simple_declaration(DeclarationAST*& yyast, SourceLocation rbracketLoc; if (parse_identifier_list() && match(TokenKind::T_RBRACKET, rbracketLoc)) { - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; SourceLocation semicolonLoc; @@ -4549,7 +4549,7 @@ auto Parser::parse_init_declarator(InitDeclaratorAST*& yyast, const auto saved = currentLocation(); RequiresClauseAST* requiresClause = nullptr; - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; if (!parse_declarator_initializer(requiresClause, initializer)) rewind(saved); @@ -4564,7 +4564,7 @@ auto Parser::parse_init_declarator(InitDeclaratorAST*& yyast, } auto Parser::parse_declarator_initializer(RequiresClauseAST*& requiresClause, - InitializerAST*& yyast) -> bool { + ExpressionAST*& yyast) -> bool { if (parse_requires_clause(requiresClause)) return true; return parse_initializer(yyast); @@ -5205,7 +5205,7 @@ auto Parser::parse_parameter_declaration(ParameterDeclarationAST*& yyast, return true; } -auto Parser::parse_initializer(InitializerAST*& yyast) -> bool { +auto Parser::parse_initializer(ExpressionAST*& yyast) -> bool { SourceLocation lparenLoc; if (match(TokenKind::T_LPAREN, lparenLoc)) { @@ -5228,7 +5228,7 @@ auto Parser::parse_initializer(InitializerAST*& yyast) -> bool { return parse_brace_or_equal_initializer(yyast); } -auto Parser::parse_brace_or_equal_initializer(InitializerAST*& yyast) -> bool { +auto Parser::parse_brace_or_equal_initializer(ExpressionAST*& yyast) -> bool { BracedInitListAST* bracedInitList = nullptr; if (LA().is(TokenKind::T_LBRACE)) { @@ -5428,7 +5428,10 @@ auto Parser::parse_expr_or_braced_init_list(ExpressionAST*& yyast) -> bool { if (LA().is(TokenKind::T_LBRACE)) { BracedInitListAST* bracedInitList = nullptr; - return parse_braced_init_list(bracedInitList); + if (parse_braced_init_list(bracedInitList)) { + yyast = bracedInitList; + return true; + } } if (!parse_expression(yyast)) parse_error("expected an expression"); @@ -7027,7 +7030,7 @@ auto Parser::parse_member_declarator(InitDeclaratorAST*& yyast, parse_error("expected an expression"); } - InitializerAST* initializer = nullptr; + ExpressionAST* initializer = nullptr; parse_brace_or_equal_initializer(initializer); diff --git a/src/parser/cxx/parser.h b/src/parser/cxx/parser.h index e21c9fd9..9e699066 100644 --- a/src/parser/cxx/parser.h +++ b/src/parser/cxx/parser.h @@ -291,7 +291,7 @@ class Parser final { auto parse_init_declarator(InitDeclaratorAST*& yyast, const DeclSpecs& specs) -> bool; auto parse_declarator_initializer(RequiresClauseAST*& requiresClause, - InitializerAST*& yyast) -> bool; + ExpressionAST*& yyast) -> bool; auto parse_declarator(DeclaratorAST*& yyastl) -> bool; auto parse_ptr_operator_seq(List*& yyast) -> bool; auto parse_core_declarator(CoreDeclaratorAST*& yyast) -> bool; @@ -318,8 +318,8 @@ class Parser final { -> bool; auto parse_parameter_declaration(ParameterDeclarationAST*& yyast, bool templParam) -> bool; - auto parse_initializer(InitializerAST*& yyast) -> bool; - auto parse_brace_or_equal_initializer(InitializerAST*& yyast) -> bool; + auto parse_initializer(ExpressionAST*& yyast) -> bool; + auto parse_brace_or_equal_initializer(ExpressionAST*& yyast) -> bool; auto parse_initializer_clause(ExpressionAST*& yyast, bool templParam = false) -> bool; auto parse_braced_init_list(BracedInitListAST*& yyast) -> bool; diff --git a/src/parser/cxx/private/ast_decoder.h b/src/parser/cxx/private/ast_decoder.h index bdd07cf7..5b8805b2 100644 --- a/src/parser/cxx/private/ast_decoder.h +++ b/src/parser/cxx/private/ast_decoder.h @@ -47,8 +47,6 @@ class ASTDecoder { -> MemInitializerAST*; auto decodeLambdaCapture(const void* ptr, io::LambdaCapture type) -> LambdaCaptureAST*; - auto decodeInitializer(const void* ptr, io::Initializer type) - -> InitializerAST*; auto decodeNewInitializer(const void* ptr, io::NewInitializer type) -> NewInitializerAST*; auto decodeExceptionDeclaration(const void* ptr, @@ -203,6 +201,12 @@ class ASTDecoder { -> ThrowExpressionAST*; auto decodeNoexceptExpression(const io::NoexceptExpression* node) -> NoexceptExpressionAST*; + auto decodeEqualInitializer(const io::EqualInitializer* node) + -> EqualInitializerAST*; + auto decodeBracedInitList(const io::BracedInitList* node) + -> BracedInitListAST*; + auto decodeParenInitializer(const io::ParenInitializer* node) + -> ParenInitializerAST*; auto decodeSimpleRequirement(const io::SimpleRequirement* node) -> SimpleRequirementAST*; @@ -237,13 +241,6 @@ class ASTDecoder { auto decodeInitLambdaCapture(const io::InitLambdaCapture* node) -> InitLambdaCaptureAST*; - auto decodeEqualInitializer(const io::EqualInitializer* node) - -> EqualInitializerAST*; - auto decodeBracedInitList(const io::BracedInitList* node) - -> BracedInitListAST*; - auto decodeParenInitializer(const io::ParenInitializer* node) - -> ParenInitializerAST*; - auto decodeNewParenInitializer(const io::NewParenInitializer* node) -> NewParenInitializerAST*; auto decodeNewBracedInitializer(const io::NewBracedInitializer* node) diff --git a/src/parser/cxx/private/ast_encoder.h b/src/parser/cxx/private/ast_encoder.h index 7dc11615..cb304e1d 100644 --- a/src/parser/cxx/private/ast_encoder.h +++ b/src/parser/cxx/private/ast_encoder.h @@ -84,9 +84,6 @@ class ASTEncoder : ASTVisitor { auto acceptLambdaCapture(LambdaCaptureAST* ast) -> std::tuple, std::uint32_t>; - auto acceptInitializer(InitializerAST* ast) - -> std::tuple, std::uint32_t>; - auto acceptNewInitializer(NewInitializerAST* ast) -> std::tuple, std::uint32_t>; @@ -197,6 +194,9 @@ class ASTEncoder : ASTVisitor { void visit(DeleteExpressionAST* ast) override; void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; void visit(SimpleRequirementAST* ast) override; void visit(CompoundRequirementAST* ast) override; @@ -216,10 +216,6 @@ class ASTEncoder : ASTVisitor { void visit(RefInitLambdaCaptureAST* ast) override; void visit(InitLambdaCaptureAST* ast) override; - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - void visit(NewParenInitializerAST* ast) override; void visit(NewBracedInitializerAST* ast) override; diff --git a/src/parser/cxx/recursive_ast_visitor.cc b/src/parser/cxx/recursive_ast_visitor.cc index 65ab078f..8d2ea6b8 100644 --- a/src/parser/cxx/recursive_ast_visitor.cc +++ b/src/parser/cxx/recursive_ast_visitor.cc @@ -71,10 +71,6 @@ void RecursiveASTVisitor::acceptRequiresClause(RequiresClauseAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptInitializer(InitializerAST* ast) { - accept(ast); -} - void RecursiveASTVisitor::acceptBaseSpecifier(BaseSpecifierAST* ast) { accept(ast); } @@ -128,49 +124,49 @@ void RecursiveASTVisitor::acceptAttributeArgumentClause( void RecursiveASTVisitor::acceptDesignator(DesignatorAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptTypeConstraint(TypeConstraintAST* ast) { +void RecursiveASTVisitor::acceptRequirementBody(RequirementBodyAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptBracedInitList(BracedInitListAST* ast) { +void RecursiveASTVisitor::acceptLambdaIntroducer(LambdaIntroducerAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptCtorInitializer(CtorInitializerAST* ast) { +void RecursiveASTVisitor::acceptLambdaDeclarator(LambdaDeclaratorAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptHandler(HandlerAST* ast) { accept(ast); } - -void RecursiveASTVisitor::acceptGlobalModuleFragment( - GlobalModuleFragmentAST* ast) { +void RecursiveASTVisitor::acceptBracedInitList(BracedInitListAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptModuleDeclaration(ModuleDeclarationAST* ast) { +void RecursiveASTVisitor::acceptNewTypeId(NewTypeIdAST* ast) { accept(ast); } + +void RecursiveASTVisitor::acceptNewInitializer(NewInitializerAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptPrivateModuleFragment( - PrivateModuleFragmentAST* ast) { +void RecursiveASTVisitor::acceptTypeConstraint(TypeConstraintAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptRequirementBody(RequirementBodyAST* ast) { +void RecursiveASTVisitor::acceptCtorInitializer(CtorInitializerAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptLambdaIntroducer(LambdaIntroducerAST* ast) { +void RecursiveASTVisitor::acceptHandler(HandlerAST* ast) { accept(ast); } + +void RecursiveASTVisitor::acceptGlobalModuleFragment( + GlobalModuleFragmentAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptLambdaDeclarator(LambdaDeclaratorAST* ast) { +void RecursiveASTVisitor::acceptModuleDeclaration(ModuleDeclarationAST* ast) { accept(ast); } -void RecursiveASTVisitor::acceptNewTypeId(NewTypeIdAST* ast) { accept(ast); } - -void RecursiveASTVisitor::acceptNewInitializer(NewInitializerAST* ast) { +void RecursiveASTVisitor::acceptPrivateModuleFragment( + PrivateModuleFragmentAST* ast) { accept(ast); } @@ -271,7 +267,7 @@ void RecursiveASTVisitor::visit(DeclaratorAST* ast) { void RecursiveASTVisitor::visit(InitDeclaratorAST* ast) { acceptDeclarator(ast->declarator); acceptRequiresClause(ast->requiresClause); - acceptInitializer(ast->initializer); + acceptExpression(ast->initializer); } void RecursiveASTVisitor::visit(BaseSpecifierAST* ast) { @@ -396,7 +392,7 @@ void RecursiveASTVisitor::visit(DesignatorAST* ast) {} void RecursiveASTVisitor::visit(DesignatedInitializerClauseAST* ast) { acceptDesignator(ast->designator); - acceptInitializer(ast->initializer); + acceptExpression(ast->initializer); } void RecursiveASTVisitor::visit(ThisExpressionAST* ast) {} @@ -561,6 +557,22 @@ void RecursiveASTVisitor::visit(NoexceptExpressionAST* ast) { acceptExpression(ast->expression); } +void RecursiveASTVisitor::visit(EqualInitializerAST* ast) { + acceptExpression(ast->expression); +} + +void RecursiveASTVisitor::visit(BracedInitListAST* ast) { + for (auto it = ast->expressionList; it; it = it->next) { + acceptExpression(it->value); + } +} + +void RecursiveASTVisitor::visit(ParenInitializerAST* ast) { + for (auto it = ast->expressionList; it; it = it->next) { + acceptExpression(it->value); + } +} + void RecursiveASTVisitor::visit(SimpleRequirementAST* ast) { acceptExpression(ast->expression); } @@ -608,27 +620,11 @@ void RecursiveASTVisitor::visit(SimpleLambdaCaptureAST* ast) {} void RecursiveASTVisitor::visit(RefLambdaCaptureAST* ast) {} void RecursiveASTVisitor::visit(RefInitLambdaCaptureAST* ast) { - acceptInitializer(ast->initializer); + acceptExpression(ast->initializer); } void RecursiveASTVisitor::visit(InitLambdaCaptureAST* ast) { - acceptInitializer(ast->initializer); -} - -void RecursiveASTVisitor::visit(EqualInitializerAST* ast) { - acceptExpression(ast->expression); -} - -void RecursiveASTVisitor::visit(BracedInitListAST* ast) { - for (auto it = ast->expressionList; it; it = it->next) { - acceptExpression(it->value); - } -} - -void RecursiveASTVisitor::visit(ParenInitializerAST* ast) { - for (auto it = ast->expressionList; it; it = it->next) { - acceptExpression(it->value); - } + acceptExpression(ast->initializer); } void RecursiveASTVisitor::visit(NewParenInitializerAST* ast) { diff --git a/src/parser/cxx/recursive_ast_visitor.h b/src/parser/cxx/recursive_ast_visitor.h index d0b9b3e7..627e874d 100644 --- a/src/parser/cxx/recursive_ast_visitor.h +++ b/src/parser/cxx/recursive_ast_visitor.h @@ -40,7 +40,6 @@ class RecursiveASTVisitor : public ASTVisitor { virtual void acceptCoreDeclarator(CoreDeclaratorAST* ast); virtual void acceptDeclaratorModifier(DeclaratorModifierAST* ast); virtual void acceptRequiresClause(RequiresClauseAST* ast); - virtual void acceptInitializer(InitializerAST* ast); virtual void acceptBaseSpecifier(BaseSpecifierAST* ast); virtual void acceptParameterDeclaration(ParameterDeclarationAST* ast); virtual void acceptParameterDeclarationClause( @@ -56,18 +55,18 @@ class RecursiveASTVisitor : public ASTVisitor { virtual void acceptAttributeToken(AttributeTokenAST* ast); virtual void acceptAttributeArgumentClause(AttributeArgumentClauseAST* ast); virtual void acceptDesignator(DesignatorAST* ast); - virtual void acceptTypeConstraint(TypeConstraintAST* ast); + virtual void acceptRequirementBody(RequirementBodyAST* ast); + virtual void acceptLambdaIntroducer(LambdaIntroducerAST* ast); + virtual void acceptLambdaDeclarator(LambdaDeclaratorAST* ast); virtual void acceptBracedInitList(BracedInitListAST* ast); + virtual void acceptNewTypeId(NewTypeIdAST* ast); + virtual void acceptNewInitializer(NewInitializerAST* ast); + virtual void acceptTypeConstraint(TypeConstraintAST* ast); virtual void acceptCtorInitializer(CtorInitializerAST* ast); virtual void acceptHandler(HandlerAST* ast); virtual void acceptGlobalModuleFragment(GlobalModuleFragmentAST* ast); virtual void acceptModuleDeclaration(ModuleDeclarationAST* ast); virtual void acceptPrivateModuleFragment(PrivateModuleFragmentAST* ast); - virtual void acceptRequirementBody(RequirementBodyAST* ast); - virtual void acceptLambdaIntroducer(LambdaIntroducerAST* ast); - virtual void acceptLambdaDeclarator(LambdaDeclaratorAST* ast); - virtual void acceptNewTypeId(NewTypeIdAST* ast); - virtual void acceptNewInitializer(NewInitializerAST* ast); virtual void acceptStatement(StatementAST* ast); virtual void acceptFunctionBody(FunctionBodyAST* ast); virtual void acceptInitDeclarator(InitDeclaratorAST* ast); @@ -156,6 +155,9 @@ class RecursiveASTVisitor : public ASTVisitor { void visit(DeleteExpressionAST* ast) override; void visit(ThrowExpressionAST* ast) override; void visit(NoexceptExpressionAST* ast) override; + void visit(EqualInitializerAST* ast) override; + void visit(BracedInitListAST* ast) override; + void visit(ParenInitializerAST* ast) override; void visit(SimpleRequirementAST* ast) override; void visit(CompoundRequirementAST* ast) override; @@ -175,10 +177,6 @@ class RecursiveASTVisitor : public ASTVisitor { void visit(RefInitLambdaCaptureAST* ast) override; void visit(InitLambdaCaptureAST* ast) override; - void visit(EqualInitializerAST* ast) override; - void visit(BracedInitListAST* ast) override; - void visit(ParenInitializerAST* ast) override; - void visit(NewParenInitializerAST* ast) override; void visit(NewBracedInitializerAST* ast) override; diff --git a/tests/unit_tests/ast/return_statement_01.cc b/tests/unit_tests/ast/return_statement_01.cc new file mode 100644 index 00000000..47f2ac70 --- /dev/null +++ b/tests/unit_tests/ast/return_statement_01.cc @@ -0,0 +1,68 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +struct Pair { + int first; + int second; + + static auto zero() -> Pair { return {0, 0}; } +}; + +// clang-format off +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: struct +// CHECK-NEXT: is-final: false +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Pair +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: first +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: second +// CHECK-NEXT: function-definition +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: static-specifier +// CHECK-NEXT: auto-type-specifier +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: zero +// CHECK-NEXT: modifiers +// CHECK-NEXT: function-declarator +// CHECK-NEXT: parameters-and-qualifiers: parameters-and-qualifiers +// CHECK-NEXT: trailing-return-type: trailing-return-type +// CHECK-NEXT: type-id: type-id +// CHECK-NEXT: type-specifier-list +// CHECK-NEXT: named-type-specifier +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Pair +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: function-body: compound-statement-function-body +// CHECK-NEXT: statement: compound-statement +// CHECK-NEXT: statement-list +// CHECK-NEXT: return-statement +// CHECK-NEXT: expression: braced-init-list +// CHECK-NEXT: expression-list +// CHECK-NEXT: int-literal-expression +// CHECK-NEXT: literal: 0 +// CHECK-NEXT: int-literal-expression +// CHECK-NEXT: literal: 0 From 3cbbc6aee2201c7d91db7a488c7ae87a39f9f832 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 22 Aug 2023 13:14:24 +0000 Subject: [PATCH 26/28] fix: Add structured binding declaration AST nodes --- packages/cxx-frontend/src/AST.ts | 37 ++++++++ packages/cxx-frontend/src/ASTKind.ts | 1 + packages/cxx-frontend/src/ASTVisitor.ts | 1 + .../cxx-frontend/src/RecursiveASTVisitor.ts | 13 +++ src/frontend/cxx/ast_printer.cc | 32 +++++++ src/frontend/cxx/ast_printer.h | 1 + src/parser/cxx/ast.cc | 24 ++++++ src/parser/cxx/ast.fbs | 12 +++ src/parser/cxx/ast.h | 20 +++++ src/parser/cxx/ast_cloner.cc | 44 ++++++++++ src/parser/cxx/ast_cloner.h | 1 + src/parser/cxx/ast_decoder.cc | 41 +++++++++ src/parser/cxx/ast_encoder.cc | 71 ++++++++++++++++ src/parser/cxx/ast_fwd.h | 1 + src/parser/cxx/ast_kind.h | 1 + src/parser/cxx/ast_slot.cc | 39 +++++++++ src/parser/cxx/ast_slot.h | 1 + src/parser/cxx/ast_visitor.h | 1 + src/parser/cxx/default_ast_visitor.cc | 4 + src/parser/cxx/default_ast_visitor.h | 1 + src/parser/cxx/parser.cc | 56 +++++++++++-- src/parser/cxx/parser.h | 2 +- src/parser/cxx/private/ast_decoder.h | 3 + src/parser/cxx/private/ast_encoder.h | 1 + src/parser/cxx/recursive_ast_visitor.cc | 13 +++ src/parser/cxx/recursive_ast_visitor.h | 1 + .../ast/structured_binding_declaration_01.cc | 84 +++++++++++++++++++ 27 files changed, 497 insertions(+), 9 deletions(-) create mode 100644 tests/unit_tests/ast/structured_binding_declaration_01.cc diff --git a/packages/cxx-frontend/src/AST.ts b/packages/cxx-frontend/src/AST.ts index bb35b408..da7f8d4b 100644 --- a/packages/cxx-frontend/src/AST.ts +++ b/packages/cxx-frontend/src/AST.ts @@ -2075,6 +2075,42 @@ export class SimpleDeclarationAST extends DeclarationAST { } } +export class StructuredBindingDeclarationAST extends DeclarationAST { + accept(visitor: ASTVisitor, context: Context): Result { + return visitor.visitStructuredBindingDeclaration(this, context); + } + *getAttributeList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 0); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + *getDeclSpecifierList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 1); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + getRefQualifierToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 2), this.parser); + } + getLbracketToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 3), this.parser); + } + *getBindingList(): Generator { + for (let it = cxx.getASTSlot(this.getHandle(), 4); it; it = cxx.getListNext(it)) { + yield AST.from(cxx.getListValue(it), this.parser); + } + } + getRbracketToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 5), this.parser); + } + getInitializer(): ExpressionAST | undefined { + return AST.from(cxx.getASTSlot(this.getHandle(), 6), this.parser); + } + getSemicolonToken(): Token | undefined { + return Token.from(cxx.getASTSlot(this.getHandle(), 7), this.parser); + } +} + export class StaticAssertDeclarationAST extends DeclarationAST { accept(visitor: ASTVisitor, context: Context): Result { return visitor.visitStaticAssertDeclaration(this, context); @@ -3405,6 +3441,7 @@ const AST_CONSTRUCTORS: Array { abstract visitForRangeDeclaration(node: ast.ForRangeDeclarationAST, context: Context): Result; abstract visitAliasDeclaration(node: ast.AliasDeclarationAST, context: Context): Result; abstract visitSimpleDeclaration(node: ast.SimpleDeclarationAST, context: Context): Result; + abstract visitStructuredBindingDeclaration(node: ast.StructuredBindingDeclarationAST, context: Context): Result; abstract visitStaticAssertDeclaration(node: ast.StaticAssertDeclarationAST, context: Context): Result; abstract visitEmptyDeclaration(node: ast.EmptyDeclarationAST, context: Context): Result; abstract visitAttributeDeclaration(node: ast.AttributeDeclarationAST, context: Context): Result; diff --git a/packages/cxx-frontend/src/RecursiveASTVisitor.ts b/packages/cxx-frontend/src/RecursiveASTVisitor.ts index c347afc4..e4bda192 100644 --- a/packages/cxx-frontend/src/RecursiveASTVisitor.ts +++ b/packages/cxx-frontend/src/RecursiveASTVisitor.ts @@ -646,6 +646,19 @@ export class RecursiveASTVisitor extends ASTVisitor { this.accept(node.getRequiresClause(), context); } + visitStructuredBindingDeclaration(node: ast.StructuredBindingDeclarationAST, context: Context): void { + for (const element of node.getAttributeList()) { + this.accept(element, context); + } + for (const element of node.getDeclSpecifierList()) { + this.accept(element, context); + } + for (const element of node.getBindingList()) { + this.accept(element, context); + } + this.accept(node.getInitializer(), context); + } + visitStaticAssertDeclaration(node: ast.StaticAssertDeclarationAST, context: Context): void { this.accept(node.getExpression(), context); } diff --git a/src/frontend/cxx/ast_printer.cc b/src/frontend/cxx/ast_printer.cc index 746784db..7711f995 100644 --- a/src/frontend/cxx/ast_printer.cc +++ b/src/frontend/cxx/ast_printer.cc @@ -1166,6 +1166,38 @@ void ASTPrinter::visit(SimpleDeclarationAST* ast) { accept(ast->requiresClause, "requires-clause"); } +void ASTPrinter::visit(StructuredBindingDeclarationAST* ast) { + fmt::print(out_, "{}\n", "structured-binding-declaration"); + if (ast->attributeList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "attribute-list"); + for (auto it = ast->attributeList; it; it = it->next) { + accept(it->value); + } + --indent_; + } + if (ast->declSpecifierList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "decl-specifier-list"); + for (auto it = ast->declSpecifierList; it; it = it->next) { + accept(it->value); + } + --indent_; + } + if (ast->bindingList) { + ++indent_; + fmt::print(out_, "{:{}}", "", indent_ * 2); + fmt::print(out_, "{}\n", "binding-list"); + for (auto it = ast->bindingList; it; it = it->next) { + accept(it->value); + } + --indent_; + } + accept(ast->initializer, "initializer"); +} + void ASTPrinter::visit(StaticAssertDeclarationAST* ast) { fmt::print(out_, "{}\n", "static-assert-declaration"); if (ast->literal) { diff --git a/src/frontend/cxx/ast_printer.h b/src/frontend/cxx/ast_printer.h index e257d2e8..1045ec2f 100644 --- a/src/frontend/cxx/ast_printer.h +++ b/src/frontend/cxx/ast_printer.h @@ -174,6 +174,7 @@ class ASTPrinter : ASTVisitor { void visit(ForRangeDeclarationAST* ast) override; void visit(AliasDeclarationAST* ast) override; void visit(SimpleDeclarationAST* ast) override; + void visit(StructuredBindingDeclarationAST* ast) override; void visit(StaticAssertDeclarationAST* ast) override; void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; diff --git a/src/parser/cxx/ast.cc b/src/parser/cxx/ast.cc index ba43a001..10338196 100644 --- a/src/parser/cxx/ast.cc +++ b/src/parser/cxx/ast.cc @@ -1784,6 +1784,30 @@ auto SimpleDeclarationAST::lastSourceLocation() -> SourceLocation { return {}; } +auto StructuredBindingDeclarationAST::firstSourceLocation() -> SourceLocation { + if (auto loc = cxx::firstSourceLocation(attributeList)) return loc; + if (auto loc = cxx::firstSourceLocation(declSpecifierList)) return loc; + if (auto loc = cxx::firstSourceLocation(refQualifierLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(lbracketLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(bindingList)) return loc; + if (auto loc = cxx::firstSourceLocation(rbracketLoc)) return loc; + if (auto loc = cxx::firstSourceLocation(initializer)) return loc; + if (auto loc = cxx::firstSourceLocation(semicolonLoc)) return loc; + return {}; +} + +auto StructuredBindingDeclarationAST::lastSourceLocation() -> SourceLocation { + if (auto loc = cxx::lastSourceLocation(semicolonLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(initializer)) return loc; + if (auto loc = cxx::lastSourceLocation(rbracketLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(bindingList)) return loc; + if (auto loc = cxx::lastSourceLocation(lbracketLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(refQualifierLoc)) return loc; + if (auto loc = cxx::lastSourceLocation(declSpecifierList)) return loc; + if (auto loc = cxx::lastSourceLocation(attributeList)) return loc; + return {}; +} + auto StaticAssertDeclarationAST::firstSourceLocation() -> SourceLocation { if (auto loc = cxx::firstSourceLocation(staticAssertLoc)) return loc; if (auto loc = cxx::firstSourceLocation(lparenLoc)) return loc; diff --git a/src/parser/cxx/ast.fbs b/src/parser/cxx/ast.fbs index e078b8e8..f23df34f 100644 --- a/src/parser/cxx/ast.fbs +++ b/src/parser/cxx/ast.fbs @@ -87,6 +87,7 @@ union Declaration { ForRangeDeclaration, AliasDeclaration, SimpleDeclaration, + StructuredBindingDeclaration, StaticAssertDeclaration, EmptyDeclaration, AttributeDeclaration, @@ -562,6 +563,17 @@ table SimpleDeclaration /* DeclarationAST */ { semicolon_loc: SourceLocation; } +table StructuredBindingDeclaration /* DeclarationAST */ { + attribute_list: [AttributeSpecifier]; + decl_specifier_list: [Specifier]; + binding_list: [Name]; + initializer: Expression; + ref_qualifier_loc: SourceLocation; + lbracket_loc: SourceLocation; + rbracket_loc: SourceLocation; + semicolon_loc: SourceLocation; +} + table StaticAssertDeclaration /* DeclarationAST */ { expression: Expression; static_assert_loc: SourceLocation; diff --git a/src/parser/cxx/ast.h b/src/parser/cxx/ast.h index e03ed93a..9c412f5e 100644 --- a/src/parser/cxx/ast.h +++ b/src/parser/cxx/ast.h @@ -1964,6 +1964,26 @@ class SimpleDeclarationAST final : public DeclarationAST { auto lastSourceLocation() -> SourceLocation override; }; +class StructuredBindingDeclarationAST final : public DeclarationAST { + public: + StructuredBindingDeclarationAST() + : DeclarationAST(ASTKind::StructuredBindingDeclaration) {} + + List* attributeList = nullptr; + List* declSpecifierList = nullptr; + SourceLocation refQualifierLoc; + SourceLocation lbracketLoc; + List* bindingList = nullptr; + SourceLocation rbracketLoc; + ExpressionAST* initializer = nullptr; + SourceLocation semicolonLoc; + + void accept(ASTVisitor* visitor) override { visitor->visit(this); } + + auto firstSourceLocation() -> SourceLocation override; + auto lastSourceLocation() -> SourceLocation override; +}; + class StaticAssertDeclarationAST final : public DeclarationAST { public: StaticAssertDeclarationAST() diff --git a/src/parser/cxx/ast_cloner.cc b/src/parser/cxx/ast_cloner.cc index 27c40465..41c12dab 100644 --- a/src/parser/cxx/ast_cloner.cc +++ b/src/parser/cxx/ast_cloner.cc @@ -2189,6 +2189,50 @@ void ASTCloner::visit(SimpleDeclarationAST* ast) { copy->semicolonLoc = ast->semicolonLoc; } +void ASTCloner::visit(StructuredBindingDeclarationAST* ast) { + auto copy = new (arena_) StructuredBindingDeclarationAST(); + copy_ = copy; + + copy->setChecked(ast->checked()); + + if (auto it = ast->attributeList) { + auto out = ©->attributeList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } + + if (auto it = ast->declSpecifierList) { + auto out = ©->declSpecifierList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } + + copy->refQualifierLoc = ast->refQualifierLoc; + + copy->lbracketLoc = ast->lbracketLoc; + + if (auto it = ast->bindingList) { + auto out = ©->bindingList; + + for (; it; it = it->next) { + *out = new (arena_) List(accept(it->value)); + out = &(*out)->next; + } + } + + copy->rbracketLoc = ast->rbracketLoc; + + copy->initializer = accept(ast->initializer); + + copy->semicolonLoc = ast->semicolonLoc; +} + void ASTCloner::visit(StaticAssertDeclarationAST* ast) { auto copy = new (arena_) StaticAssertDeclarationAST(); copy_ = copy; diff --git a/src/parser/cxx/ast_cloner.h b/src/parser/cxx/ast_cloner.h index 39f4de6e..79f008fc 100644 --- a/src/parser/cxx/ast_cloner.h +++ b/src/parser/cxx/ast_cloner.h @@ -162,6 +162,7 @@ class ASTCloner : public ASTVisitor { void visit(ForRangeDeclarationAST* ast) override; void visit(AliasDeclarationAST* ast) override; void visit(SimpleDeclarationAST* ast) override; + void visit(StructuredBindingDeclarationAST* ast) override; void visit(StaticAssertDeclarationAST* ast) override; void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; diff --git a/src/parser/cxx/ast_decoder.cc b/src/parser/cxx/ast_decoder.cc index 1bad1779..cf393552 100644 --- a/src/parser/cxx/ast_decoder.cc +++ b/src/parser/cxx/ast_decoder.cc @@ -399,6 +399,9 @@ auto ASTDecoder::decodeDeclaration(const void* ptr, io::Declaration type) case io::Declaration_SimpleDeclaration: return decodeSimpleDeclaration( reinterpret_cast(ptr)); + case io::Declaration_StructuredBindingDeclaration: + return decodeStructuredBindingDeclaration( + reinterpret_cast(ptr)); case io::Declaration_StaticAssertDeclaration: return decodeStaticAssertDeclaration( reinterpret_cast(ptr)); @@ -2267,6 +2270,44 @@ auto ASTDecoder::decodeSimpleDeclaration(const io::SimpleDeclaration* node) return ast; } +auto ASTDecoder::decodeStructuredBindingDeclaration( + const io::StructuredBindingDeclaration* node) + -> StructuredBindingDeclarationAST* { + if (!node) return nullptr; + + auto ast = new (pool_) StructuredBindingDeclarationAST(); + if (node->attribute_list()) { + auto* inserter = &ast->attributeList; + for (std::size_t i = 0; i < node->attribute_list()->size(); ++i) { + *inserter = new (pool_) List(decodeAttributeSpecifier( + node->attribute_list()->Get(i), + io::AttributeSpecifier(node->attribute_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } + if (node->decl_specifier_list()) { + auto* inserter = &ast->declSpecifierList; + for (std::size_t i = 0; i < node->decl_specifier_list()->size(); ++i) { + *inserter = new (pool_) List(decodeSpecifier( + node->decl_specifier_list()->Get(i), + io::Specifier(node->decl_specifier_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } + if (node->binding_list()) { + auto* inserter = &ast->bindingList; + for (std::size_t i = 0; i < node->binding_list()->size(); ++i) { + *inserter = new (pool_) + List(decodeName(node->binding_list()->Get(i), + io::Name(node->binding_list_type()->Get(i)))); + inserter = &(*inserter)->next; + } + } + ast->initializer = + decodeExpression(node->initializer(), node->initializer_type()); + return ast; +} + auto ASTDecoder::decodeStaticAssertDeclaration( const io::StaticAssertDeclaration* node) -> StaticAssertDeclarationAST* { if (!node) return nullptr; diff --git a/src/parser/cxx/ast_encoder.cc b/src/parser/cxx/ast_encoder.cc index a2c7fe8e..e9f71dc7 100644 --- a/src/parser/cxx/ast_encoder.cc +++ b/src/parser/cxx/ast_encoder.cc @@ -3165,6 +3165,77 @@ void ASTEncoder::visit(SimpleDeclarationAST* ast) { type_ = io::Declaration_SimpleDeclaration; } +void ASTEncoder::visit(StructuredBindingDeclarationAST* ast) { + std::vector> attributeListOffsets; + std::vector> + attributeListTypes; + + for (auto it = ast->attributeList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptAttributeSpecifier(it->value); + attributeListOffsets.push_back(offset); + attributeListTypes.push_back(type); + } + + auto attributeListOffsetsVector = fbb_.CreateVector(attributeListOffsets); + auto attributeListTypesVector = fbb_.CreateVector(attributeListTypes); + + std::vector> declSpecifierListOffsets; + std::vector> declSpecifierListTypes; + + for (auto it = ast->declSpecifierList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptSpecifier(it->value); + declSpecifierListOffsets.push_back(offset); + declSpecifierListTypes.push_back(type); + } + + auto declSpecifierListOffsetsVector = + fbb_.CreateVector(declSpecifierListOffsets); + auto declSpecifierListTypesVector = fbb_.CreateVector(declSpecifierListTypes); + + auto refQualifierLoc = encodeSourceLocation(ast->refQualifierLoc); + + auto lbracketLoc = encodeSourceLocation(ast->lbracketLoc); + + std::vector> bindingListOffsets; + std::vector> bindingListTypes; + + for (auto it = ast->bindingList; it; it = it->next) { + if (!it->value) continue; + const auto [offset, type] = acceptName(it->value); + bindingListOffsets.push_back(offset); + bindingListTypes.push_back(type); + } + + auto bindingListOffsetsVector = fbb_.CreateVector(bindingListOffsets); + auto bindingListTypesVector = fbb_.CreateVector(bindingListTypes); + + auto rbracketLoc = encodeSourceLocation(ast->rbracketLoc); + + const auto [initializer, initializerType] = + acceptExpression(ast->initializer); + + auto semicolonLoc = encodeSourceLocation(ast->semicolonLoc); + + io::StructuredBindingDeclaration::Builder builder{fbb_}; + builder.add_attribute_list(attributeListOffsetsVector); + builder.add_attribute_list_type(attributeListTypesVector); + builder.add_decl_specifier_list(declSpecifierListOffsetsVector); + builder.add_decl_specifier_list_type(declSpecifierListTypesVector); + builder.add_ref_qualifier_loc(refQualifierLoc.o); + builder.add_lbracket_loc(lbracketLoc.o); + builder.add_binding_list(bindingListOffsetsVector); + builder.add_binding_list_type(bindingListTypesVector); + builder.add_rbracket_loc(rbracketLoc.o); + builder.add_initializer(initializer); + builder.add_initializer_type(static_cast(initializerType)); + builder.add_semicolon_loc(semicolonLoc.o); + + offset_ = builder.Finish().Union(); + type_ = io::Declaration_StructuredBindingDeclaration; +} + void ASTEncoder::visit(StaticAssertDeclarationAST* ast) { auto staticAssertLoc = encodeSourceLocation(ast->staticAssertLoc); diff --git a/src/parser/cxx/ast_fwd.h b/src/parser/cxx/ast_fwd.h index e5d2c31a..0298cc1d 100644 --- a/src/parser/cxx/ast_fwd.h +++ b/src/parser/cxx/ast_fwd.h @@ -215,6 +215,7 @@ class ConceptDefinitionAST; class ForRangeDeclarationAST; class AliasDeclarationAST; class SimpleDeclarationAST; +class StructuredBindingDeclarationAST; class StaticAssertDeclarationAST; class EmptyDeclarationAST; class AttributeDeclarationAST; diff --git a/src/parser/cxx/ast_kind.h b/src/parser/cxx/ast_kind.h index c40e9eeb..c26f067b 100644 --- a/src/parser/cxx/ast_kind.h +++ b/src/parser/cxx/ast_kind.h @@ -168,6 +168,7 @@ enum struct ASTKind { ForRangeDeclaration, AliasDeclaration, SimpleDeclaration, + StructuredBindingDeclaration, StaticAssertDeclaration, EmptyDeclaration, AttributeDeclaration, diff --git a/src/parser/cxx/ast_slot.cc b/src/parser/cxx/ast_slot.cc index 0bf50f42..d4c5aa70 100644 --- a/src/parser/cxx/ast_slot.cc +++ b/src/parser/cxx/ast_slot.cc @@ -2459,6 +2459,45 @@ void ASTSlot::visit(SimpleDeclarationAST* ast) { slotCount_ = 5; } +void ASTSlot::visit(StructuredBindingDeclarationAST* ast) { + switch (slot_) { + case 0: + value_ = reinterpret_cast(ast->attributeList); + slotKind_ = ASTSlotKind::kNodeList; + break; + case 1: + value_ = reinterpret_cast(ast->declSpecifierList); + slotKind_ = ASTSlotKind::kNodeList; + break; + case 2: + value_ = ast->refQualifierLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 3: + value_ = ast->lbracketLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 4: + value_ = reinterpret_cast(ast->bindingList); + slotKind_ = ASTSlotKind::kNodeList; + break; + case 5: + value_ = ast->rbracketLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + case 6: + value_ = reinterpret_cast(ast->initializer); + slotKind_ = ASTSlotKind::kNode; + break; + case 7: + value_ = ast->semicolonLoc.index(); + slotKind_ = ASTSlotKind::kToken; + break; + } // switch + + slotCount_ = 8; +} + void ASTSlot::visit(StaticAssertDeclarationAST* ast) { switch (slot_) { case 0: diff --git a/src/parser/cxx/ast_slot.h b/src/parser/cxx/ast_slot.h index 8302652a..fcad6665 100644 --- a/src/parser/cxx/ast_slot.h +++ b/src/parser/cxx/ast_slot.h @@ -173,6 +173,7 @@ class ASTSlot final : ASTVisitor { void visit(ForRangeDeclarationAST* ast) override; void visit(AliasDeclarationAST* ast) override; void visit(SimpleDeclarationAST* ast) override; + void visit(StructuredBindingDeclarationAST* ast) override; void visit(StaticAssertDeclarationAST* ast) override; void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; diff --git a/src/parser/cxx/ast_visitor.h b/src/parser/cxx/ast_visitor.h index 7581b72b..d451d798 100644 --- a/src/parser/cxx/ast_visitor.h +++ b/src/parser/cxx/ast_visitor.h @@ -172,6 +172,7 @@ class ASTVisitor { virtual void visit(ForRangeDeclarationAST* ast) = 0; virtual void visit(AliasDeclarationAST* ast) = 0; virtual void visit(SimpleDeclarationAST* ast) = 0; + virtual void visit(StructuredBindingDeclarationAST* ast) = 0; virtual void visit(StaticAssertDeclarationAST* ast) = 0; virtual void visit(EmptyDeclarationAST* ast) = 0; virtual void visit(AttributeDeclarationAST* ast) = 0; diff --git a/src/parser/cxx/default_ast_visitor.cc b/src/parser/cxx/default_ast_visitor.cc index a529ab7b..a1cd34ea 100644 --- a/src/parser/cxx/default_ast_visitor.cc +++ b/src/parser/cxx/default_ast_visitor.cc @@ -522,6 +522,10 @@ void DefaultASTVisitor::visit(SimpleDeclarationAST* ast) { cxx_runtime_error("visit(SimpleDeclarationAST): not implemented"); } +void DefaultASTVisitor::visit(StructuredBindingDeclarationAST* ast) { + cxx_runtime_error("visit(StructuredBindingDeclarationAST): not implemented"); +} + void DefaultASTVisitor::visit(StaticAssertDeclarationAST* ast) { cxx_runtime_error("visit(StaticAssertDeclarationAST): not implemented"); } diff --git a/src/parser/cxx/default_ast_visitor.h b/src/parser/cxx/default_ast_visitor.h index 3605fdb5..a7803214 100644 --- a/src/parser/cxx/default_ast_visitor.h +++ b/src/parser/cxx/default_ast_visitor.h @@ -170,6 +170,7 @@ class DefaultASTVisitor : public ASTVisitor { void visit(ForRangeDeclarationAST* ast) override; void visit(AliasDeclarationAST* ast) override; void visit(SimpleDeclarationAST* ast) override; + void visit(StructuredBindingDeclarationAST* ast) override; void visit(StaticAssertDeclarationAST* ast) override; void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 72006963..85063b8a 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -3167,11 +3167,22 @@ auto Parser::parse_for_range_declaration(DeclarationAST*& yyast) -> bool { if (!match(TokenKind::T_LBRACKET, lbracketLoc)) return false; - if (!parse_identifier_list()) parse_error("expected an identifier"); + List* bindings = nullptr; + + if (!parse_identifier_list(bindings)) parse_error("expected an identifier"); SourceLocation rbracketLoc; expect(TokenKind::T_RBRACKET, rbracketLoc); + + auto ast = new (pool) StructuredBindingDeclarationAST(); + yyast = ast; + ast->attributeList = attributeList; + ast->declSpecifierList = declSpecifierList; + ast->refQualifierLoc = refLoc; + ast->lbracketLoc = lbracketLoc; + ast->bindingList = bindings; + ast->rbracketLoc = rbracketLoc; } else { DeclaratorAST* declarator = nullptr; @@ -3504,15 +3515,28 @@ auto Parser::parse_simple_declaration(DeclarationAST*& yyast, SourceLocation lbracketLoc; if (match(TokenKind::T_LBRACKET, lbracketLoc)) { + List* bindings = nullptr; SourceLocation rbracketLoc; - if (parse_identifier_list() && match(TokenKind::T_RBRACKET, rbracketLoc)) { + if (parse_identifier_list(bindings) && + match(TokenKind::T_RBRACKET, rbracketLoc)) { ExpressionAST* initializer = nullptr; - SourceLocation semicolonLoc; if (parse_initializer(initializer) && match(TokenKind::T_SEMICOLON, semicolonLoc)) { + auto ast = new (pool) StructuredBindingDeclarationAST(); + yyast = ast; + + ast->attributeList = attributes; + ast->declSpecifierList = declSpecifierList; + ast->refQualifierLoc = refLoc; + ast->lbracketLoc = lbracketLoc; + ast->bindingList = bindings; + ast->rbracketLoc = rbracketLoc; + ast->initializer = initializer; + ast->semicolonLoc = semicolonLoc; + return true; } } @@ -8412,15 +8436,31 @@ auto Parser::parse_noexcept_specifier() -> bool { return true; } -auto Parser::parse_identifier_list() -> bool { - SourceLocation identifierLoc; - if (!match(TokenKind::T_IDENTIFIER, identifierLoc)) return false; +auto Parser::parse_identifier_list(List*& yyast) -> bool { + auto it = &yyast; + + NameAST* id = nullptr; + + if (!parse_name_id(id)) return false; + + if (id) { + *it = new (pool) List(id); + it = &(*it)->next; + } SourceLocation commaLoc; while (match(TokenKind::T_COMMA, commaLoc)) { - SourceLocation identifierLoc; - expect(TokenKind::T_IDENTIFIER, identifierLoc); + NameAST* id = nullptr; + + if (!parse_name_id(id)) { + parse_error("expected an identifier"); + } + + if (id) { + *it = new (pool) List(id); + it = &(*it)->next; + } } return true; diff --git a/src/parser/cxx/parser.h b/src/parser/cxx/parser.h index 9e699066..f0b0ddde 100644 --- a/src/parser/cxx/parser.h +++ b/src/parser/cxx/parser.h @@ -443,7 +443,7 @@ class Parser final { auto parse_handler_seq(List*& yyast) -> bool; auto parse_exception_declaration(ExceptionDeclarationAST*& yyast) -> bool; auto parse_noexcept_specifier() -> bool; - auto parse_identifier_list() -> bool; + auto parse_identifier_list(List*& yyast) -> bool; private: [[nodiscard]] auto lookat(auto... tokens) { diff --git a/src/parser/cxx/private/ast_decoder.h b/src/parser/cxx/private/ast_decoder.h index 5b8805b2..6366cccb 100644 --- a/src/parser/cxx/private/ast_decoder.h +++ b/src/parser/cxx/private/ast_decoder.h @@ -310,6 +310,9 @@ class ASTDecoder { -> AliasDeclarationAST*; auto decodeSimpleDeclaration(const io::SimpleDeclaration* node) -> SimpleDeclarationAST*; + auto decodeStructuredBindingDeclaration( + const io::StructuredBindingDeclaration* node) + -> StructuredBindingDeclarationAST*; auto decodeStaticAssertDeclaration(const io::StaticAssertDeclaration* node) -> StaticAssertDeclarationAST*; auto decodeEmptyDeclaration(const io::EmptyDeclaration* node) diff --git a/src/parser/cxx/private/ast_encoder.h b/src/parser/cxx/private/ast_encoder.h index cb304e1d..72e6ec2c 100644 --- a/src/parser/cxx/private/ast_encoder.h +++ b/src/parser/cxx/private/ast_encoder.h @@ -255,6 +255,7 @@ class ASTEncoder : ASTVisitor { void visit(ForRangeDeclarationAST* ast) override; void visit(AliasDeclarationAST* ast) override; void visit(SimpleDeclarationAST* ast) override; + void visit(StructuredBindingDeclarationAST* ast) override; void visit(StaticAssertDeclarationAST* ast) override; void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; diff --git a/src/parser/cxx/recursive_ast_visitor.cc b/src/parser/cxx/recursive_ast_visitor.cc index 8d2ea6b8..05019ec3 100644 --- a/src/parser/cxx/recursive_ast_visitor.cc +++ b/src/parser/cxx/recursive_ast_visitor.cc @@ -807,6 +807,19 @@ void RecursiveASTVisitor::visit(SimpleDeclarationAST* ast) { acceptRequiresClause(ast->requiresClause); } +void RecursiveASTVisitor::visit(StructuredBindingDeclarationAST* ast) { + for (auto it = ast->attributeList; it; it = it->next) { + acceptAttributeSpecifier(it->value); + } + for (auto it = ast->declSpecifierList; it; it = it->next) { + acceptSpecifier(it->value); + } + for (auto it = ast->bindingList; it; it = it->next) { + acceptName(it->value); + } + acceptExpression(ast->initializer); +} + void RecursiveASTVisitor::visit(StaticAssertDeclarationAST* ast) { acceptExpression(ast->expression); } diff --git a/src/parser/cxx/recursive_ast_visitor.h b/src/parser/cxx/recursive_ast_visitor.h index 627e874d..7e1348b0 100644 --- a/src/parser/cxx/recursive_ast_visitor.h +++ b/src/parser/cxx/recursive_ast_visitor.h @@ -216,6 +216,7 @@ class RecursiveASTVisitor : public ASTVisitor { void visit(ForRangeDeclarationAST* ast) override; void visit(AliasDeclarationAST* ast) override; void visit(SimpleDeclarationAST* ast) override; + void visit(StructuredBindingDeclarationAST* ast) override; void visit(StaticAssertDeclarationAST* ast) override; void visit(EmptyDeclarationAST* ast) override; void visit(AttributeDeclarationAST* ast) override; diff --git a/tests/unit_tests/ast/structured_binding_declaration_01.cc b/tests/unit_tests/ast/structured_binding_declaration_01.cc new file mode 100644 index 00000000..3ea81841 --- /dev/null +++ b/tests/unit_tests/ast/structured_binding_declaration_01.cc @@ -0,0 +1,84 @@ +// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines + +struct Pair { + int first; + int second; + + auto sum() -> int { + auto [a, b] = *this; + return a + b; + } +}; + +// clang-format off +// CHECK:translation-unit +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: class-specifier +// CHECK-NEXT: class-key: struct +// CHECK-NEXT: is-final: false +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: Pair +// CHECK-NEXT: declaration-list +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: first +// CHECK-NEXT: simple-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: init-declarator-list +// CHECK-NEXT: init-declarator +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: second +// CHECK-NEXT: function-definition +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: auto-type-specifier +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: core-declarator: id-declarator +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: sum +// CHECK-NEXT: modifiers +// CHECK-NEXT: function-declarator +// CHECK-NEXT: parameters-and-qualifiers: parameters-and-qualifiers +// CHECK-NEXT: trailing-return-type: trailing-return-type +// CHECK-NEXT: type-id: type-id +// CHECK-NEXT: type-specifier-list +// CHECK-NEXT: integral-type-specifier +// CHECK-NEXT: specifier: int +// CHECK-NEXT: declarator: declarator +// CHECK-NEXT: function-body: compound-statement-function-body +// CHECK-NEXT: statement: compound-statement +// CHECK-NEXT: statement-list +// CHECK-NEXT: declaration-statement +// CHECK-NEXT: declaration: structured-binding-declaration +// CHECK-NEXT: decl-specifier-list +// CHECK-NEXT: auto-type-specifier +// CHECK-NEXT: binding-list +// CHECK-NEXT: simple-name +// CHECK-NEXT: identifier: a +// CHECK-NEXT: simple-name +// CHECK-NEXT: identifier: b +// CHECK-NEXT: initializer: equal-initializer +// CHECK-NEXT: expression: unary-expression +// CHECK-NEXT: op: * +// CHECK-NEXT: expression: this-expression +// CHECK-NEXT: return-statement +// CHECK-NEXT: expression: binary-expression +// CHECK-NEXT: op: + +// CHECK-NEXT: left-expression: id-expression +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: a +// CHECK-NEXT: right-expression: id-expression +// CHECK-NEXT: name: simple-name +// CHECK-NEXT: identifier: b \ No newline at end of file From e71166ab01f7d00d90634ebd750f2ada250911a3 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 22 Aug 2023 13:28:15 +0000 Subject: [PATCH 27/28] chore: Update npm package version --- packages/cxx-frontend/package-lock.json | 4 ++-- packages/cxx-frontend/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cxx-frontend/package-lock.json b/packages/cxx-frontend/package-lock.json index 62f7c8ca..1cec1012 100644 --- a/packages/cxx-frontend/package-lock.json +++ b/packages/cxx-frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "cxx-frontend", - "version": "1.1.18", + "version": "1.1.19", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cxx-frontend", - "version": "1.1.18", + "version": "1.1.19", "license": "MIT", "devDependencies": { "@types/node": "^20.2.1", diff --git a/packages/cxx-frontend/package.json b/packages/cxx-frontend/package.json index 01248473..2f9c80a0 100644 --- a/packages/cxx-frontend/package.json +++ b/packages/cxx-frontend/package.json @@ -1,6 +1,6 @@ { "name": "cxx-frontend", - "version": "1.1.18", + "version": "1.1.19", "description": "A compiler front end for the C++ language", "main": "dist/index.js", "types": "dist/index.d.ts", From 0b1726ebdee4ec846f6c175348034d84c88068aa Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Tue, 22 Aug 2023 15:26:43 +0200 Subject: [PATCH 28/28] chore(main): release 1.1.19 --- CHANGELOG.md | 25 +++++++++++++++++++++++++ version.txt | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d20ca25a..c80fbec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## [1.1.19](https://github.com/robertoraggi/cplusplus/compare/v1.1.18...v1.1.19) (2023-08-22) + + +### Bug Fixes + +* Add AST for designated initializers ([f36c3f4](https://github.com/robertoraggi/cplusplus/commit/f36c3f4000c64bae5872721f4e0458854e82000d)) +* Add AST node for underlying type specifier ([c716cc0](https://github.com/robertoraggi/cplusplus/commit/c716cc0dbe5011b836b75d8d7be1614b5cc6398f)) +* Add AST node for using enum declaration ([bf5f22a](https://github.com/robertoraggi/cplusplus/commit/bf5f22a2421fc221c7d295be688c7de11904fb5b)) +* Add missing attributes to the enumerator AST node ([bd2c9cd](https://github.com/robertoraggi/cplusplus/commit/bd2c9cd4d1a851e0b86432756af8c34ba76fb01d)) +* Add structured binding declaration AST nodes ([3cbbc6a](https://github.com/robertoraggi/cplusplus/commit/3cbbc6aee2201c7d91db7a488c7ae87a39f9f832)) +* Dump the AST in plain text instead of JSON ([ec19f4f](https://github.com/robertoraggi/cplusplus/commit/ec19f4fcabdca597aaef5f71915527682509cb71)) +* Parse of class virt specifiers ([97cb51e](https://github.com/robertoraggi/cplusplus/commit/97cb51e3dc09875cdcd3e9e59e0a073455a1a146)) +* Parse of inline for namespace definitions ([80a34cf](https://github.com/robertoraggi/cplusplus/commit/80a34cfd252db8e3a6b0b4ef459b0620cf910c3a)) +* Print TokenKind in AST dump ([0583d39](https://github.com/robertoraggi/cplusplus/commit/0583d39b2510497d2aa0b2fe6d9df6cd98c36c01)) +* Represent intiializers as expressions in the AST ([629ca3c](https://github.com/robertoraggi/cplusplus/commit/629ca3c31b3475a89f94cc1f6bcf9a9c25fe3f18)) +* Set access and virt specifier to the base specifier ast nodes ([613a070](https://github.com/robertoraggi/cplusplus/commit/613a0709b34e25a5b28ddec470d2577c375dad32)) +* Set access specifier of access declaration AST nodes ([dc7a545](https://github.com/robertoraggi/cplusplus/commit/dc7a545a2a3c614168a38c868ae3d67ba1367e1a)) +* Set class key of class specifier AST nodes ([f610253](https://github.com/robertoraggi/cplusplus/commit/f61025375f9c49cb6f5c25a453266be52b51c981)) +* Set class key of elaborated type specifiers ([a8db107](https://github.com/robertoraggi/cplusplus/commit/a8db10739bf97b379d4bb76846c532392406b872)) +* Set location of the atomic type specifier ([8d8e07b](https://github.com/robertoraggi/cplusplus/commit/8d8e07becea096c21b556913755224ea4cf36283)) +* Set the name of ctor member initializers ([35fdf21](https://github.com/robertoraggi/cplusplus/commit/35fdf21b1cab38ab142d3fdd5cc2614d39319123)) +* stddef.h: add missing typedefs ([3ea986f](https://github.com/robertoraggi/cplusplus/commit/3ea986f83093275fddcc4889cab04235162a2ffa)) +* Store the namespace name in the AST ([5df694b](https://github.com/robertoraggi/cplusplus/commit/5df694b0a49aeb4d6783c8859d459f85125fc8fd)) +* Store the value of the boolean literals in the AST ([a2fbad8](https://github.com/robertoraggi/cplusplus/commit/a2fbad8614b80c1991407b60251d4bdb11c97983)) + ## [1.1.18](https://github.com/robertoraggi/cplusplus/compare/v1.1.17...v1.1.18) (2023-08-14) diff --git a/version.txt b/version.txt index 852ed67c..4e036596 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.1.18 +1.1.19