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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,8 @@ endif()
# if CMAKE_SYSTEM_NAME is WASI disable the exceptions
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")

set(FMT_OS OFF CACHE BOOL "" FORCE)
endif()

FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 11.0.2
GIT_SHALLOW 1
)

# set FMT_INSTALL to OFF to avoid installing fmt
set(FMT_INSTALL OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(fmt)

FetchContent_Declare(
utfcpp
GIT_REPOSITORY https://github.com/nemtrif/utfcpp
Expand Down
38 changes: 19 additions & 19 deletions packages/cxx-gen-ast/src/gen_ast_dump_cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) {
if (member.kind === "node-list") {
emit(` if (ast->${member.name}) {`);
emit(` ++indent_;`);
emit(` out_ << cxx::format("{:{}}", "", indent_ * 2);`);
emit(` out_ << cxx::format("{}\\n", "${fieldName}");`);
emit(` out_ << std::format("{:{}}", "", indent_ * 2);`);
emit(` out_ << std::format("{}\\n", "${fieldName}");`);
emit(` for (auto it = ast->${member.name}; it; it = it->next) {`);
emit(` accept(it->value);`);
emit(` }`);
Expand All @@ -54,25 +54,25 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) {
} else if (member.kind == "attribute" && member.type === "bool") {
emit(` if (ast->${member.name}) {`);
emit(` ++indent_;`);
emit(` out_ << cxx::format("{:{}}", "", indent_ * 2);`);
emit(` out_ << std::format("{:{}}", "", indent_ * 2);`);
emit(
` out_ << cxx::format("${fieldName}: {}\\n", ast->${member.name});`,
` out_ << std::format("${fieldName}: {}\\n", ast->${member.name});`
);
emit(` --indent_;`);
emit(` }`);
} else if (member.kind == "attribute" && member.type === "int") {
emit(` ++indent_;`);
emit(` out_ << cxx::format("{:{}}", "", indent_ * 2);`);
emit(` out_ << std::format("{:{}}", "", indent_ * 2);`);
emit(
` out_ << cxx::format("${fieldName}: {}\\n", ast->${member.name});`,
` out_ << std::format("${fieldName}: {}\\n", ast->${member.name});`
);
emit(` --indent_;`);
} else if (member.kind == "attribute" && member.type.endsWith("Literal")) {
emit(` if (ast->${member.name}) {`);
emit(` ++indent_;`);
emit(` out_ << cxx::format("{:{}}", "", indent_ * 2);`);
emit(` out_ << std::format("{:{}}", "", indent_ * 2);`);
emit(
` out_ << cxx::format("${fieldName}: {}\\n", ast->${member.name}->value());`,
` out_ << std::format("${fieldName}: {}\\n", ast->${member.name}->value());`
);
emit(` --indent_;`);
emit(` }`);
Expand All @@ -82,9 +82,9 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) {
) {
emit(` if (ast->${member.name} != TokenKind::T_EOF_SYMBOL) {`);
emit(` ++indent_;`);
emit(` out_ << cxx::format("{:{}}", "", indent_ * 2);`);
emit(` out_ << std::format("{:{}}", "", indent_ * 2);`);
emit(
` out_ << cxx::format("${fieldName}: {}\\n", Token::spell(ast->${member.name}));`,
` out_ << std::format("${fieldName}: {}\\n", Token::spell(ast->${member.name}));`
);
emit(` --indent_;`);
emit(` }`);
Expand All @@ -93,9 +93,9 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) {
member.type == "ImplicitCastKind"
) {
emit(` ++indent_;`);
emit(` out_ << cxx::format("{:{}}", "", indent_ * 2);`);
emit(` out_ << std::format("{:{}}", "", indent_ * 2);`);
emit(
` out_ << cxx::format("${fieldName}: {}\\n", to_string(ast->${member.name}));`,
` out_ << std::format("${fieldName}: {}\\n", to_string(ast->${member.name}));`
);
emit(` --indent_;`);
}
Expand All @@ -105,7 +105,7 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) {
nodes.forEach(({ name, base, members }) => {
emit();
emit(`void ASTPrinter::visit(${name}* ast) {`);
emit(` out_ << cxx::format("{}\\n", "${astName(name)}");`);
emit(` out_ << std::format("{}\\n", "${astName(name)}");`);

const baseMembers = ast.baseMembers.get(base);

Expand Down Expand Up @@ -135,7 +135,7 @@ export function gen_ast_dump_cc({ ast, output }: { ast: AST; output: string }) {
#include <cxx/translation_unit.h>
#include <cxx/names.h>
#include <cxx/literals.h>
#include <cxx/private/format.h>
#include <format>

#include <algorithm>
#include <iostream>
Expand All @@ -153,9 +153,9 @@ void ASTPrinter::operator()(AST* ast) {
void ASTPrinter::accept(AST* ast, std::string_view field) {
if (!ast) return;
++indent_;
out_ << cxx::format("{:{}}", "", indent_ * 2);
out_ << std::format("{:{}}", "", indent_ * 2);
if (!field.empty()) {
out_ << cxx::format("{}: ", field);
out_ << std::format("{}: ", field);
}
ast->accept(this);
--indent_;
Expand All @@ -164,9 +164,9 @@ void ASTPrinter::accept(AST* ast, std::string_view field) {
void ASTPrinter::accept(const Identifier* id, std::string_view field) {
if (!id) return;
++indent_;
out_ << cxx::format("{:{}}", "", indent_ * 2);
if (!field.empty()) out_ << cxx::format("{}: ", field);
out_ << cxx::format("{}\\n", id->value());
out_ << std::format("{:{}}", "", indent_ * 2);
if (!field.empty()) out_ << std::format("{}: ", field);
out_ << std::format("{}\\n", id->value());
--indent_;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/cxx-gen-ast/src/gen_ast_encoder_cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function gen_ast_encoder_cc({
const emitLiteral = (
m: Attribute,
table: string,
finalizers: (() => void)[],
finalizers: (() => void)[]
) => {
const fieldName = toSnakeName(m.name);

Expand All @@ -70,7 +70,7 @@ export function gen_ast_encoder_cc({
const className = makeClassName(base);
emit();
emit(
` auto ASTEncoder::accept${className}(${base}* ast) -> std::tuple<flatbuffers::Offset<>, std::uint32_t> {`,
` auto ASTEncoder::accept${className}(${base}* ast) -> std::tuple<flatbuffers::Offset<>, std::uint32_t> {`
);
emit(` if (!ast) return {};`);
emit(` flatbuffers::Offset<> offset;`);
Expand Down Expand Up @@ -201,7 +201,7 @@ export function gen_ast_encoder_cc({
#include <cxx/literals.h>
#include <cxx/names.h>
#include <cxx/translation_unit.h>
#include <cxx/private/format.h>
#include <format>

#include <algorithm>

Expand Down
Loading