Skip to content

Commit 218af55

Browse files
committed
Upgrade Core and Blaze
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 7c1f4eb commit 218af55

251 files changed

Lines changed: 29295 additions & 925 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if(CODEGEN_INSTALL)
3232
endif()
3333

3434
find_package(Core REQUIRED)
35+
find_package(Blaze REQUIRED)
3536

3637
# Don't force downstream consumers on it
3738
if(PROJECT_IS_TOP_LEVEL)

DEPENDENCIES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02
2-
core https://github.com/sourcemeta/core b6640a840bf149edca223c9129a71d64474e12fc
2+
core https://github.com/sourcemeta/core c43332629d71475f44d212f140effbf0a46c1492
3+
blaze https://github.com/sourcemeta/blaze b97dc7b6dca47917f40ff465efa5e068e16e8534

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ compile: .always
2828
--component sourcemeta_core
2929
$(CMAKE) --install ./build --prefix ./build/dist --config $(PRESET) --verbose \
3030
--component sourcemeta_core_dev
31+
$(CMAKE) --install ./build --prefix ./build/dist --config $(PRESET) --verbose \
32+
--component sourcemeta_blaze
33+
$(CMAKE) --install ./build --prefix ./build/dist --config $(PRESET) --verbose \
34+
--component sourcemeta_blaze_dev
3135
$(CMAKE) --install ./build --prefix ./build/dist --config $(PRESET) --verbose \
3236
--component sourcemeta_codegen
3337
$(CMAKE) --install ./build --prefix ./build/dist --config $(PRESET) --verbose \

cmake/FindBlaze.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
if(NOT Blaze_FOUND)
2+
if(CODEGEN_INSTALL)
3+
set(SOURCEMETA_BLAZE_INSTALL ON CACHE BOOL "enable installation")
4+
else()
5+
set(SOURCEMETA_BLAZE_INSTALL OFF CACHE BOOL "disable installation")
6+
endif()
7+
8+
9+
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/blaze")
10+
include(Sourcemeta)
11+
set(Blaze_FOUND ON)
12+
endif()

config.cmake.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ if(NOT CODEGEN_COMPONENTS)
99
endif()
1010

1111
include(CMakeFindDependencyMacro)
12-
find_dependency(Core COMPONENTS regex json jsonschema alterschema)
12+
find_dependency(Core COMPONENTS regex json jsonschema)
13+
find_dependency(Blaze COMPONENTS alterschema)
1314

1415
foreach(component ${CODEGEN_COMPONENTS})
1516
if(component STREQUAL "ir")

src/generator/include/sourcemeta/codegen/generator_typescript.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SOURCEMETA_CODEGEN_GENERATOR_EXPORT TypeScript {
2929
auto operator()(const IRReference &entry) -> void;
3030
auto operator()(const IRTuple &entry) -> void;
3131
auto operator()(const IRUnion &entry) -> void;
32+
auto operator()(const IRIntersection &entry) -> void;
3233

3334
private:
3435
// Exporting symbols that depends on the standard C++ library is considered

src/generator/typescript.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,20 @@ auto TypeScript::operator()(const IRUnion &entry) -> void {
287287
this->output << ";\n";
288288
}
289289

290+
auto TypeScript::operator()(const IRIntersection &entry) -> void {
291+
this->output << "export type "
292+
<< mangle(this->prefix, entry.pointer, entry.symbol, this->cache)
293+
<< " =\n";
294+
295+
const char *separator{""};
296+
for (const auto &value : entry.values) {
297+
this->output << separator << " "
298+
<< mangle(this->prefix, value.pointer, value.symbol,
299+
this->cache);
300+
separator = " &\n";
301+
}
302+
303+
this->output << ";\n";
304+
}
305+
290306
} // namespace sourcemeta::codegen

src/ir/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ target_link_libraries(sourcemeta_codegen_ir PUBLIC
1212
target_link_libraries(sourcemeta_codegen_ir PUBLIC
1313
sourcemeta::core::jsonschema)
1414
target_link_libraries(sourcemeta_codegen_ir PRIVATE
15-
sourcemeta::core::alterschema)
15+
sourcemeta::blaze::alterschema)

src/ir/include/sourcemeta/codegen/ir.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ struct IRUnion : IRType {
5656
std::vector<IRType> values;
5757
};
5858

59+
/// @ingroup ir
60+
struct IRIntersection : IRType {
61+
std::vector<IRType> values;
62+
};
63+
5964
/// @ingroup ir
6065
struct IRObjectValue : IRType {
6166
bool required;
@@ -99,8 +104,8 @@ struct IRReference : IRType {
99104

100105
/// @ingroup ir
101106
using IREntity =
102-
std::variant<IRObject, IRScalar, IREnumeration, IRUnion, IRArray, IRTuple,
103-
IRImpossible, IRAny, IRReference>;
107+
std::variant<IRObject, IRScalar, IREnumeration, IRUnion, IRIntersection,
108+
IRArray, IRTuple, IRImpossible, IRAny, IRReference>;
104109

105110
/// @ingroup ir
106111
using IRResult = std::vector<IREntity>;

src/ir/ir.cc

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
#include <sourcemeta/blaze/alterschema.h>
12
#include <sourcemeta/codegen/ir.h>
2-
#include <sourcemeta/core/alterschema.h>
33

44
#include <algorithm> // std::ranges::sort
55
#include <cassert> // assert
@@ -9,6 +9,29 @@
99

1010
namespace sourcemeta::codegen {
1111

12+
static auto
13+
is_validation_only_location(const sourcemeta::core::WeakPointer &pointer)
14+
-> bool {
15+
static const std::unordered_set<std::string_view> validation_only_keywords{
16+
"propertyNames", "contains"};
17+
static const std::unordered_set<std::string_view> container_keywords{
18+
"properties", "patternProperties", "$defs", "definitions"};
19+
for (std::size_t index = 0; index < pointer.size(); ++index) {
20+
const auto &token{pointer.at(index)};
21+
if (!token.is_property() ||
22+
!validation_only_keywords.contains(token.to_property())) {
23+
continue;
24+
}
25+
26+
if (index == 0 || !pointer.at(index - 1).is_property() ||
27+
!container_keywords.contains(pointer.at(index - 1).to_property())) {
28+
return true;
29+
}
30+
}
31+
32+
return false;
33+
}
34+
1235
auto compile(const sourcemeta::core::JSON &input,
1336
const sourcemeta::core::SchemaWalker &walker,
1437
const sourcemeta::core::SchemaResolver &resolver,
@@ -25,9 +48,9 @@ auto compile(const sourcemeta::core::JSON &input,
2548
// (2) Canonicalize the schema for easier analysis
2649
// --------------------------------------------------------------------------
2750

28-
sourcemeta::core::SchemaTransformer canonicalizer;
29-
sourcemeta::core::add(canonicalizer,
30-
sourcemeta::core::AlterSchemaMode::Canonicalizer);
51+
sourcemeta::blaze::SchemaTransformer canonicalizer;
52+
sourcemeta::blaze::add(canonicalizer,
53+
sourcemeta::blaze::AlterSchemaMode::Canonicalizer);
3154
[[maybe_unused]] const auto canonicalized{canonicalizer.apply(
3255
schema, walker, resolver,
3356
[](const auto &, const auto, const auto, const auto &,
@@ -67,6 +90,12 @@ auto compile(const sourcemeta::core::JSON &input,
6790
continue;
6891
}
6992

93+
// Skip subschemas under validation-only keywords that do not contribute
94+
// to the type structure
95+
if (is_validation_only_location(location.pointer)) {
96+
continue;
97+
}
98+
7099
const auto &subschema{sourcemeta::core::get(schema, location.pointer)};
71100
result.push_back(compiler(schema, frame, location, resolver, subschema));
72101
}

0 commit comments

Comments
 (0)