polyxml 0.36.0__tar.gz → 0.37.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polyxml-0.36.0 → polyxml-0.37.0}/Cargo.lock +6 -6
- {polyxml-0.36.0 → polyxml-0.37.0}/Cargo.toml +1 -1
- {polyxml-0.36.0 → polyxml-0.37.0}/PKG-INFO +1 -1
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/cpp/mod.rs +373 -66
- {polyxml-0.36.0 → polyxml-0.37.0}/pyproject.toml +1 -1
- {polyxml-0.36.0 → polyxml-0.37.0}/README.md +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/Cargo.toml +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/README.md +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/benches/core_benchmarks.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/benches/support/tag_dispatch_fixtures.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/benches/tag_dispatch.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/csharp/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/go/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/java/codec.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/java/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/java/models.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/python/aot.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/python/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/rust/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/codegen/typescript/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/converters.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/error.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/integer.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/ir/chunker.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/ir/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/ir/particle.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/ir/tarjan.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/json.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/lib.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/parser.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/pattern.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/schema.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/schema_parser/mod.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/schema_parser/upa.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/serializer.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/transcoder.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/src/value.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/fixtures/lexical_union.xsd +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/fixtures/mixed_content.xsd +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/fixtures/ts_mixed_content_inheritance.xsd +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_adversarial_identifiers.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_any_attribute.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_any_element.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_conformance.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_core.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_corpus_regressions.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_cpp_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_csharp_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_default_literal_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_enum_literal_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_go_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_inherited_simple_content.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_inherited_text_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_java_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_json.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_lexical_lists.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_lexical_union_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_mixed_branch_lookup.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_mixed_content.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_mixed_nil.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_namespace_entities.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_pattern_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_python_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_qualified_attributes.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_runtime_fast_paths.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_rust_codecs.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_rust_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_schema_attribute_entities.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_schema_audit.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_schema_ir.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_security.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_temporal_union.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_transcoder.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_ts_codegen.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_ubl_csharp.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_unbounded_choice.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_upa.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_value_constraints.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_variant_registry.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_xsi_type.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/Cargo.toml +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/README.md +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/benches/aot_vs_dataclass.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/src/lib.rs +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/tests/test_binary_fields.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/tests/test_conformance.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/tests/test_generated_models.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/tests/test_json.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/tests/test_mixed_content.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/tests/test_polyxml.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-python/tests/test_xsi_type.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/python/polyxml/AGENT_GUIDE.md +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/python/polyxml/__init__.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/python/polyxml/compat/__init__.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/python/polyxml/compat/xsdata.py +0 -0
- {polyxml-0.36.0 → polyxml-0.37.0}/python/polyxml/py.typed +0 -0
|
@@ -610,7 +610,7 @@ dependencies = [
|
|
|
610
610
|
|
|
611
611
|
[[package]]
|
|
612
612
|
name = "polyxml"
|
|
613
|
-
version = "0.
|
|
613
|
+
version = "0.37.0"
|
|
614
614
|
dependencies = [
|
|
615
615
|
"criterion",
|
|
616
616
|
"heck",
|
|
@@ -631,14 +631,14 @@ dependencies = [
|
|
|
631
631
|
|
|
632
632
|
[[package]]
|
|
633
633
|
name = "polyxml-c"
|
|
634
|
-
version = "0.
|
|
634
|
+
version = "0.37.0"
|
|
635
635
|
dependencies = [
|
|
636
636
|
"polyxml",
|
|
637
637
|
]
|
|
638
638
|
|
|
639
639
|
[[package]]
|
|
640
640
|
name = "polyxml-cli"
|
|
641
|
-
version = "0.
|
|
641
|
+
version = "0.37.0"
|
|
642
642
|
dependencies = [
|
|
643
643
|
"clap",
|
|
644
644
|
"glob",
|
|
@@ -652,7 +652,7 @@ dependencies = [
|
|
|
652
652
|
|
|
653
653
|
[[package]]
|
|
654
654
|
name = "polyxml-js"
|
|
655
|
-
version = "0.
|
|
655
|
+
version = "0.37.0"
|
|
656
656
|
dependencies = [
|
|
657
657
|
"napi",
|
|
658
658
|
"napi-build",
|
|
@@ -662,7 +662,7 @@ dependencies = [
|
|
|
662
662
|
|
|
663
663
|
[[package]]
|
|
664
664
|
name = "polyxml-python"
|
|
665
|
-
version = "0.
|
|
665
|
+
version = "0.37.0"
|
|
666
666
|
dependencies = [
|
|
667
667
|
"base64",
|
|
668
668
|
"hex",
|
|
@@ -674,7 +674,7 @@ dependencies = [
|
|
|
674
674
|
|
|
675
675
|
[[package]]
|
|
676
676
|
name = "polyxml-wasm"
|
|
677
|
-
version = "0.
|
|
677
|
+
version = "0.37.0"
|
|
678
678
|
dependencies = [
|
|
679
679
|
"polyxml",
|
|
680
680
|
"quick-xml",
|
|
@@ -244,6 +244,7 @@ pub fn to_cpp_enum_variant(raw: &str) -> String {
|
|
|
244
244
|
pub struct CppCodegen {
|
|
245
245
|
options: CppOptions,
|
|
246
246
|
context: CppLanguageContext,
|
|
247
|
+
split_units: Option<usize>,
|
|
247
248
|
}
|
|
248
249
|
|
|
249
250
|
/// Emitted C++ identifier for a named type, disambiguated across namespaces
|
|
@@ -257,9 +258,16 @@ impl CppCodegen {
|
|
|
257
258
|
Self {
|
|
258
259
|
options,
|
|
259
260
|
context: CppLanguageContext,
|
|
261
|
+
split_units: None,
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
|
|
265
|
+
/// Emit declarations in `.hpp` and out-of-line definitions split into chunked `.cpp` units.
|
|
266
|
+
pub fn with_split_units(mut self, chunk_size: usize) -> Self {
|
|
267
|
+
self.split_units = Some(chunk_size.max(1));
|
|
268
|
+
self
|
|
269
|
+
}
|
|
270
|
+
|
|
263
271
|
fn unique_field_name(
|
|
264
272
|
&self,
|
|
265
273
|
struct_name: &str,
|
|
@@ -399,6 +407,15 @@ impl CppCodegen {
|
|
|
399
407
|
match self.options.mode {
|
|
400
408
|
CppMode::HeaderOnly => {
|
|
401
409
|
files.push((format!("{}.hpp", stem), self.generate_header(ir)));
|
|
410
|
+
if let Some(chunk_size) = self.split_units {
|
|
411
|
+
let plan = ir.partition_topological_chunks(chunk_size);
|
|
412
|
+
for chunk in &plan.chunks {
|
|
413
|
+
files.push((
|
|
414
|
+
format!("{}_{}.cpp", stem, chunk.name),
|
|
415
|
+
self.generate_chunk_impl(ir, stem, &chunk.types),
|
|
416
|
+
));
|
|
417
|
+
}
|
|
418
|
+
}
|
|
402
419
|
}
|
|
403
420
|
CppMode::Module => {
|
|
404
421
|
files.push((
|
|
@@ -423,6 +440,162 @@ impl CppCodegen {
|
|
|
423
440
|
files
|
|
424
441
|
}
|
|
425
442
|
|
|
443
|
+
fn generate_chunk_impl(&self, ir: &SchemaIR, header_stem: &str, types: &[QName]) -> String {
|
|
444
|
+
set_type_name_map(build_type_name_map(ir, to_cpp_type_name));
|
|
445
|
+
let mut out = String::new();
|
|
446
|
+
writeln!(
|
|
447
|
+
out,
|
|
448
|
+
"// @generated by PolyXML Compiler (https://github.com/polyxml/PolyXML)"
|
|
449
|
+
)
|
|
450
|
+
.unwrap();
|
|
451
|
+
writeln!(out, "#include \"{}.hpp\"\n", header_stem).unwrap();
|
|
452
|
+
writeln!(out, "namespace {} {{\n", self.options.namespace).unwrap();
|
|
453
|
+
|
|
454
|
+
for qname in types {
|
|
455
|
+
let Some(type_def) = ir.types.get(qname) else {
|
|
456
|
+
continue;
|
|
457
|
+
};
|
|
458
|
+
match type_def {
|
|
459
|
+
TypeDef::Enum(enum_def) if self.options.emit_enum_converters => {
|
|
460
|
+
let enum_name = type_ident(&enum_def.qname);
|
|
461
|
+
let mut seen = HashSet::new();
|
|
462
|
+
let variant_names: Vec<String> = enum_def
|
|
463
|
+
.variants
|
|
464
|
+
.iter()
|
|
465
|
+
.map(|v| self.unique_enum_variant(&v.name, &mut seen))
|
|
466
|
+
.collect();
|
|
467
|
+
let natural = to_cpp_type_name(&enum_def.qname.local);
|
|
468
|
+
let stem = if enum_name == natural {
|
|
469
|
+
AsSnakeCase(&enum_def.qname.local).to_string()
|
|
470
|
+
} else {
|
|
471
|
+
AsSnakeCase(&enum_name).to_string()
|
|
472
|
+
};
|
|
473
|
+
let func_name = format!("{stem}_from_string");
|
|
474
|
+
self.emit_enum_converters_impl(
|
|
475
|
+
&mut out,
|
|
476
|
+
enum_def,
|
|
477
|
+
&enum_name,
|
|
478
|
+
&variant_names,
|
|
479
|
+
&func_name,
|
|
480
|
+
false,
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
TypeDef::Union(u) => {
|
|
484
|
+
let union_name = type_ident(&u.qname);
|
|
485
|
+
let mut branch_types = Vec::new();
|
|
486
|
+
let mut seen_types = HashSet::new();
|
|
487
|
+
let mut needs_wrappers = false;
|
|
488
|
+
for b in &u.branches {
|
|
489
|
+
let mapped = self.context.map_type_ref(&b.type_ref);
|
|
490
|
+
if matches!(b.type_ref, TypeRef::Primitive(_))
|
|
491
|
+
|| seen_types.contains(&mapped)
|
|
492
|
+
{
|
|
493
|
+
needs_wrappers = true;
|
|
494
|
+
}
|
|
495
|
+
seen_types.insert(mapped.clone());
|
|
496
|
+
branch_types.push((b, mapped));
|
|
497
|
+
}
|
|
498
|
+
let mut variant_params = Vec::new();
|
|
499
|
+
if needs_wrappers {
|
|
500
|
+
let mut seen_wrappers = HashSet::new();
|
|
501
|
+
for (branch, _) in &branch_types {
|
|
502
|
+
let base_wrapper =
|
|
503
|
+
format!("{}{}", union_name, to_cpp_type_name(&branch.variant_name));
|
|
504
|
+
let mut wrapper_name = base_wrapper.clone();
|
|
505
|
+
let mut idx = 2;
|
|
506
|
+
while !seen_wrappers.insert(wrapper_name.clone()) {
|
|
507
|
+
wrapper_name = format!("{base_wrapper}_{idx}");
|
|
508
|
+
idx += 1;
|
|
509
|
+
}
|
|
510
|
+
if self.options.emit_equality_operators {
|
|
511
|
+
writeln!(
|
|
512
|
+
out,
|
|
513
|
+
"bool {}::operator==(const {}&) const = default;",
|
|
514
|
+
wrapper_name, wrapper_name
|
|
515
|
+
)
|
|
516
|
+
.unwrap();
|
|
517
|
+
}
|
|
518
|
+
variant_params.push(wrapper_name);
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
for (_, mapped) in &branch_types {
|
|
522
|
+
variant_params.push(mapped.clone());
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if variant_params.len() > 16 {
|
|
526
|
+
for (idx, param) in variant_params.iter().enumerate() {
|
|
527
|
+
writeln!(
|
|
528
|
+
out,
|
|
529
|
+
"{}::{}({} v) : kind({}), data(std::make_shared<{}>(std::move(v))) {{}}",
|
|
530
|
+
union_name, union_name, param, idx, param
|
|
531
|
+
)
|
|
532
|
+
.unwrap();
|
|
533
|
+
}
|
|
534
|
+
writeln!(
|
|
535
|
+
out,
|
|
536
|
+
"std::size_t {}::index() const noexcept {{ return kind; }}",
|
|
537
|
+
union_name
|
|
538
|
+
)
|
|
539
|
+
.unwrap();
|
|
540
|
+
if self.options.emit_equality_operators {
|
|
541
|
+
writeln!(
|
|
542
|
+
out,
|
|
543
|
+
"bool {}::operator==(const {}& other) const {{",
|
|
544
|
+
union_name, union_name
|
|
545
|
+
)
|
|
546
|
+
.unwrap();
|
|
547
|
+
writeln!(out, " if (kind != other.kind) return false;").unwrap();
|
|
548
|
+
writeln!(out, " if (!data && !other.data) return true;").unwrap();
|
|
549
|
+
writeln!(out, " if (!data || !other.data) return false;").unwrap();
|
|
550
|
+
writeln!(out, " switch (kind) {{").unwrap();
|
|
551
|
+
for (idx, param) in variant_params.iter().enumerate() {
|
|
552
|
+
writeln!(
|
|
553
|
+
out,
|
|
554
|
+
" case {}: return *static_cast<const {}*>(data.get()) == *static_cast<const {}*>(other.data.get());",
|
|
555
|
+
idx, param, param
|
|
556
|
+
)
|
|
557
|
+
.unwrap();
|
|
558
|
+
}
|
|
559
|
+
writeln!(out, " default: return false;").unwrap();
|
|
560
|
+
writeln!(out, " }}").unwrap();
|
|
561
|
+
writeln!(out, "}}\n").unwrap();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
TypeDef::Struct(s) => {
|
|
566
|
+
let struct_name = type_ident(&s.qname);
|
|
567
|
+
if self.options.emit_equality_operators {
|
|
568
|
+
writeln!(
|
|
569
|
+
out,
|
|
570
|
+
"bool {}::operator==(const {}&) const = default;",
|
|
571
|
+
struct_name, struct_name
|
|
572
|
+
)
|
|
573
|
+
.unwrap();
|
|
574
|
+
}
|
|
575
|
+
if self.options.validate_facets {
|
|
576
|
+
let has_simple_content_base =
|
|
577
|
+
s.base_type.as_ref().is_some_and(|base_qname| {
|
|
578
|
+
!matches!(ir.types.get(base_qname), Some(TypeDef::Struct(_)))
|
|
579
|
+
&& (PrimitiveType::from_xsd_name(&base_qname.local).is_some()
|
|
580
|
+
|| matches!(
|
|
581
|
+
ir.types.get(base_qname),
|
|
582
|
+
Some(TypeDef::Simple(_))
|
|
583
|
+
))
|
|
584
|
+
});
|
|
585
|
+
let field_names =
|
|
586
|
+
self.struct_field_names(s, &struct_name, has_simple_content_base);
|
|
587
|
+
let sig = format!("bool {}::validate() const noexcept {{", struct_name);
|
|
588
|
+
self.emit_struct_validator_with_sig(&mut out, s, ir, &field_names, &sig);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
_ => {}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
writeln!(out, "\n}} // namespace {}", self.options.namespace).unwrap();
|
|
596
|
+
out
|
|
597
|
+
}
|
|
598
|
+
|
|
426
599
|
/// Generate CMakeLists.txt definition for integration via add_subdirectory or FetchContent.
|
|
427
600
|
pub fn generate_cmake(&self, project_name: &str) -> String {
|
|
428
601
|
let safe_name = AsSnakeCase(project_name).to_string();
|
|
@@ -779,31 +952,6 @@ inline int polyxml_integer_compare(std::string_view a,std::string_view b) noexce
|
|
|
779
952
|
writeln!(out, "}};\n").unwrap();
|
|
780
953
|
|
|
781
954
|
if self.options.emit_enum_converters {
|
|
782
|
-
// to_string
|
|
783
|
-
writeln!(
|
|
784
|
-
out,
|
|
785
|
-
"[[nodiscard]] inline constexpr std::string_view to_string({} value) noexcept {{",
|
|
786
|
-
enum_name
|
|
787
|
-
)
|
|
788
|
-
.unwrap();
|
|
789
|
-
writeln!(out, " switch (value) {{").unwrap();
|
|
790
|
-
for (variant, var_name) in enum_def.variants.iter().zip(&variant_names) {
|
|
791
|
-
writeln!(
|
|
792
|
-
out,
|
|
793
|
-
" case {}::{}: return {};",
|
|
794
|
-
enum_name,
|
|
795
|
-
var_name,
|
|
796
|
-
super::cpp_string_literal(&variant.value)
|
|
797
|
-
)
|
|
798
|
-
.unwrap();
|
|
799
|
-
}
|
|
800
|
-
writeln!(out, " }}").unwrap();
|
|
801
|
-
writeln!(out, " return \"\";").unwrap();
|
|
802
|
-
writeln!(out, "}}\n").unwrap();
|
|
803
|
-
|
|
804
|
-
// from_string — stem follows the disambiguated type name only when
|
|
805
|
-
// it differs from the natural one, preserving the historical
|
|
806
|
-
// snake-of-local form otherwise.
|
|
807
955
|
let natural = to_cpp_type_name(&enum_def.qname.local);
|
|
808
956
|
let stem = if enum_name == natural {
|
|
809
957
|
AsSnakeCase(&enum_def.qname.local).to_string()
|
|
@@ -811,27 +959,88 @@ inline int polyxml_integer_compare(std::string_view a,std::string_view b) noexce
|
|
|
811
959
|
AsSnakeCase(&enum_name).to_string()
|
|
812
960
|
};
|
|
813
961
|
let func_name = format!("{stem}_from_string");
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
962
|
+
if self.split_units.is_some() {
|
|
963
|
+
writeln!(
|
|
964
|
+
out,
|
|
965
|
+
"[[nodiscard]] std::string_view to_string({} value) noexcept;",
|
|
966
|
+
enum_name
|
|
967
|
+
)
|
|
968
|
+
.unwrap();
|
|
821
969
|
writeln!(
|
|
822
970
|
out,
|
|
823
|
-
"
|
|
824
|
-
|
|
825
|
-
enum_name,
|
|
826
|
-
var_name
|
|
971
|
+
"[[nodiscard]] std::optional<{}> {}(std::string_view s) noexcept;\n",
|
|
972
|
+
enum_name, func_name
|
|
827
973
|
)
|
|
828
974
|
.unwrap();
|
|
975
|
+
} else {
|
|
976
|
+
self.emit_enum_converters_impl(
|
|
977
|
+
out,
|
|
978
|
+
enum_def,
|
|
979
|
+
&enum_name,
|
|
980
|
+
&variant_names,
|
|
981
|
+
&func_name,
|
|
982
|
+
true,
|
|
983
|
+
);
|
|
829
984
|
}
|
|
830
|
-
writeln!(out, " return std::nullopt;").unwrap();
|
|
831
|
-
writeln!(out, "}}\n").unwrap();
|
|
832
985
|
}
|
|
833
986
|
}
|
|
834
987
|
|
|
988
|
+
fn emit_enum_converters_impl(
|
|
989
|
+
&self,
|
|
990
|
+
out: &mut String,
|
|
991
|
+
enum_def: &EnumDef,
|
|
992
|
+
enum_name: &str,
|
|
993
|
+
variant_names: &[String],
|
|
994
|
+
func_name: &str,
|
|
995
|
+
inline: bool,
|
|
996
|
+
) {
|
|
997
|
+
let qualifier = if inline {
|
|
998
|
+
"[[nodiscard]] inline constexpr "
|
|
999
|
+
} else {
|
|
1000
|
+
""
|
|
1001
|
+
};
|
|
1002
|
+
writeln!(
|
|
1003
|
+
out,
|
|
1004
|
+
"{}std::string_view to_string({} value) noexcept {{",
|
|
1005
|
+
qualifier, enum_name
|
|
1006
|
+
)
|
|
1007
|
+
.unwrap();
|
|
1008
|
+
writeln!(out, " switch (value) {{").unwrap();
|
|
1009
|
+
for (variant, var_name) in enum_def.variants.iter().zip(variant_names) {
|
|
1010
|
+
writeln!(
|
|
1011
|
+
out,
|
|
1012
|
+
" case {}::{}: return {};",
|
|
1013
|
+
enum_name,
|
|
1014
|
+
var_name,
|
|
1015
|
+
super::cpp_string_literal(&variant.value)
|
|
1016
|
+
)
|
|
1017
|
+
.unwrap();
|
|
1018
|
+
}
|
|
1019
|
+
writeln!(out, " }}").unwrap();
|
|
1020
|
+
writeln!(out, " return \"\";").unwrap();
|
|
1021
|
+
writeln!(out, "}}\n").unwrap();
|
|
1022
|
+
|
|
1023
|
+
let from_qualifier = if inline { "[[nodiscard]] inline " } else { "" };
|
|
1024
|
+
writeln!(
|
|
1025
|
+
out,
|
|
1026
|
+
"{}std::optional<{}> {}(std::string_view s) noexcept {{",
|
|
1027
|
+
from_qualifier, enum_name, func_name
|
|
1028
|
+
)
|
|
1029
|
+
.unwrap();
|
|
1030
|
+
for (variant, var_name) in enum_def.variants.iter().zip(variant_names) {
|
|
1031
|
+
writeln!(
|
|
1032
|
+
out,
|
|
1033
|
+
" if (s == {}) return {}::{};",
|
|
1034
|
+
super::cpp_string_literal(&variant.value),
|
|
1035
|
+
enum_name,
|
|
1036
|
+
var_name
|
|
1037
|
+
)
|
|
1038
|
+
.unwrap();
|
|
1039
|
+
}
|
|
1040
|
+
writeln!(out, " return std::nullopt;").unwrap();
|
|
1041
|
+
writeln!(out, "}}\n").unwrap();
|
|
1042
|
+
}
|
|
1043
|
+
|
|
835
1044
|
fn emit_union(&self, out: &mut String, u: &UnionDef) {
|
|
836
1045
|
if let Some(ref doc) = u.documentation {
|
|
837
1046
|
for line in doc.lines() {
|
|
@@ -875,10 +1084,15 @@ inline int polyxml_integer_compare(std::string_view a,std::string_view b) noexce
|
|
|
875
1084
|
writeln!(out, "struct {} {{", wrapper_name).unwrap();
|
|
876
1085
|
writeln!(out, " {} value = {{}};", mapped_type).unwrap();
|
|
877
1086
|
if self.options.emit_equality_operators {
|
|
1087
|
+
let eq_suffix = if self.split_units.is_some() {
|
|
1088
|
+
";"
|
|
1089
|
+
} else {
|
|
1090
|
+
" = default;"
|
|
1091
|
+
};
|
|
878
1092
|
writeln!(
|
|
879
1093
|
out,
|
|
880
|
-
" bool operator==(const {}&) const
|
|
881
|
-
wrapper_name
|
|
1094
|
+
" bool operator==(const {}&) const{}",
|
|
1095
|
+
wrapper_name, eq_suffix
|
|
882
1096
|
)
|
|
883
1097
|
.unwrap();
|
|
884
1098
|
}
|
|
@@ -891,13 +1105,72 @@ inline int polyxml_integer_compare(std::string_view a,std::string_view b) noexce
|
|
|
891
1105
|
}
|
|
892
1106
|
}
|
|
893
1107
|
|
|
894
|
-
|
|
895
|
-
out,
|
|
896
|
-
"
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1108
|
+
if variant_params.len() > 16 {
|
|
1109
|
+
writeln!(out, "struct {} {{", union_name).unwrap();
|
|
1110
|
+
writeln!(out, " std::size_t kind = 0;").unwrap();
|
|
1111
|
+
writeln!(out, " std::shared_ptr<const void> data = {{}};").unwrap();
|
|
1112
|
+
writeln!(out, " {}() = default;", union_name).unwrap();
|
|
1113
|
+
if self.split_units.is_some() {
|
|
1114
|
+
for param in &variant_params {
|
|
1115
|
+
writeln!(out, " {}({} v);", union_name, param).unwrap();
|
|
1116
|
+
}
|
|
1117
|
+
writeln!(out, " [[nodiscard]] std::size_t index() const noexcept;").unwrap();
|
|
1118
|
+
if self.options.emit_equality_operators {
|
|
1119
|
+
writeln!(
|
|
1120
|
+
out,
|
|
1121
|
+
" bool operator==(const {}& other) const;",
|
|
1122
|
+
union_name
|
|
1123
|
+
)
|
|
1124
|
+
.unwrap();
|
|
1125
|
+
}
|
|
1126
|
+
} else {
|
|
1127
|
+
for (idx, param) in variant_params.iter().enumerate() {
|
|
1128
|
+
writeln!(
|
|
1129
|
+
out,
|
|
1130
|
+
" {}({} v) : kind({}), data(std::make_shared<{}>(std::move(v))) {{}}",
|
|
1131
|
+
union_name, param, idx, param
|
|
1132
|
+
)
|
|
1133
|
+
.unwrap();
|
|
1134
|
+
}
|
|
1135
|
+
writeln!(
|
|
1136
|
+
out,
|
|
1137
|
+
" [[nodiscard]] std::size_t index() const noexcept {{ return kind; }}"
|
|
1138
|
+
)
|
|
1139
|
+
.unwrap();
|
|
1140
|
+
if self.options.emit_equality_operators {
|
|
1141
|
+
writeln!(
|
|
1142
|
+
out,
|
|
1143
|
+
" bool operator==(const {}& other) const {{",
|
|
1144
|
+
union_name
|
|
1145
|
+
)
|
|
1146
|
+
.unwrap();
|
|
1147
|
+
writeln!(out, " if (kind != other.kind) return false;").unwrap();
|
|
1148
|
+
writeln!(out, " if (!data && !other.data) return true;").unwrap();
|
|
1149
|
+
writeln!(out, " if (!data || !other.data) return false;").unwrap();
|
|
1150
|
+
writeln!(out, " switch (kind) {{").unwrap();
|
|
1151
|
+
for (idx, param) in variant_params.iter().enumerate() {
|
|
1152
|
+
writeln!(
|
|
1153
|
+
out,
|
|
1154
|
+
" case {}: return *static_cast<const {}*>(data.get()) == *static_cast<const {}*>(other.data.get());",
|
|
1155
|
+
idx, param, param
|
|
1156
|
+
)
|
|
1157
|
+
.unwrap();
|
|
1158
|
+
}
|
|
1159
|
+
writeln!(out, " default: return false;").unwrap();
|
|
1160
|
+
writeln!(out, " }}").unwrap();
|
|
1161
|
+
writeln!(out, " }}").unwrap();
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
writeln!(out, "}};\n").unwrap();
|
|
1165
|
+
} else {
|
|
1166
|
+
writeln!(
|
|
1167
|
+
out,
|
|
1168
|
+
"using {} = std::variant<{}>;\n",
|
|
1169
|
+
union_name,
|
|
1170
|
+
variant_params.join(", ")
|
|
1171
|
+
)
|
|
1172
|
+
.unwrap();
|
|
1173
|
+
}
|
|
901
1174
|
}
|
|
902
1175
|
|
|
903
1176
|
fn emit_struct(&self, out: &mut String, s: &StructDef, ir: &SchemaIR) {
|
|
@@ -942,21 +1215,7 @@ inline int polyxml_integer_compare(std::string_view a,std::string_view b) noexce
|
|
|
942
1215
|
}
|
|
943
1216
|
}
|
|
944
1217
|
|
|
945
|
-
let
|
|
946
|
-
if simple_content_base.is_some() {
|
|
947
|
-
let has_value_field = s
|
|
948
|
-
.fields
|
|
949
|
-
.iter()
|
|
950
|
-
.any(|f| f.name == "value" || f.kind == crate::ir::FieldKind::Text);
|
|
951
|
-
if !has_value_field {
|
|
952
|
-
seen.insert("value".to_string());
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
let field_names: Vec<String> = s
|
|
956
|
-
.fields
|
|
957
|
-
.iter()
|
|
958
|
-
.map(|f| self.unique_field_name(&struct_name, &f.name, &mut seen))
|
|
959
|
-
.collect();
|
|
1218
|
+
let field_names = self.struct_field_names(s, &struct_name, simple_content_base.is_some());
|
|
960
1219
|
|
|
961
1220
|
// Fields
|
|
962
1221
|
for (f, field_name) in s.fields.iter().zip(&field_names) {
|
|
@@ -968,16 +1227,25 @@ inline int polyxml_integer_compare(std::string_view a,std::string_view b) noexce
|
|
|
968
1227
|
}
|
|
969
1228
|
|
|
970
1229
|
if self.options.emit_equality_operators {
|
|
1230
|
+
let eq_suffix = if self.split_units.is_some() {
|
|
1231
|
+
";"
|
|
1232
|
+
} else {
|
|
1233
|
+
" = default;"
|
|
1234
|
+
};
|
|
971
1235
|
writeln!(
|
|
972
1236
|
out,
|
|
973
|
-
"\n bool operator==(const {}&) const
|
|
974
|
-
struct_name
|
|
1237
|
+
"\n bool operator==(const {}&) const{}",
|
|
1238
|
+
struct_name, eq_suffix
|
|
975
1239
|
)
|
|
976
1240
|
.unwrap();
|
|
977
1241
|
}
|
|
978
1242
|
|
|
979
1243
|
if self.options.validate_facets {
|
|
980
|
-
self.
|
|
1244
|
+
if self.split_units.is_some() {
|
|
1245
|
+
writeln!(out, "\n [[nodiscard]] bool validate() const noexcept;").unwrap();
|
|
1246
|
+
} else {
|
|
1247
|
+
self.emit_struct_validator(out, s, ir, &field_names);
|
|
1248
|
+
}
|
|
981
1249
|
}
|
|
982
1250
|
|
|
983
1251
|
writeln!(out, "}};\n").unwrap();
|
|
@@ -1086,6 +1354,28 @@ inline int polyxml_integer_compare(std::string_view a,std::string_view b) noexce
|
|
|
1086
1354
|
}
|
|
1087
1355
|
}
|
|
1088
1356
|
|
|
1357
|
+
fn struct_field_names(
|
|
1358
|
+
&self,
|
|
1359
|
+
s: &StructDef,
|
|
1360
|
+
struct_name: &str,
|
|
1361
|
+
has_simple_content_base: bool,
|
|
1362
|
+
) -> Vec<String> {
|
|
1363
|
+
let mut seen = HashSet::new();
|
|
1364
|
+
if has_simple_content_base {
|
|
1365
|
+
let has_value_field = s
|
|
1366
|
+
.fields
|
|
1367
|
+
.iter()
|
|
1368
|
+
.any(|f| f.name == "value" || f.kind == crate::ir::FieldKind::Text);
|
|
1369
|
+
if !has_value_field {
|
|
1370
|
+
seen.insert("value".to_string());
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
s.fields
|
|
1374
|
+
.iter()
|
|
1375
|
+
.map(|f| self.unique_field_name(struct_name, &f.name, &mut seen))
|
|
1376
|
+
.collect()
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1089
1379
|
fn emit_struct_validator(
|
|
1090
1380
|
&self,
|
|
1091
1381
|
out: &mut String,
|
|
@@ -1093,7 +1383,24 @@ inline int polyxml_integer_compare(std::string_view a,std::string_view b) noexce
|
|
|
1093
1383
|
ir: &SchemaIR,
|
|
1094
1384
|
field_names: &[String],
|
|
1095
1385
|
) {
|
|
1096
|
-
|
|
1386
|
+
self.emit_struct_validator_with_sig(
|
|
1387
|
+
out,
|
|
1388
|
+
s,
|
|
1389
|
+
ir,
|
|
1390
|
+
field_names,
|
|
1391
|
+
"\n [[nodiscard]] bool validate() const noexcept {",
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
fn emit_struct_validator_with_sig(
|
|
1396
|
+
&self,
|
|
1397
|
+
out: &mut String,
|
|
1398
|
+
s: &StructDef,
|
|
1399
|
+
ir: &SchemaIR,
|
|
1400
|
+
field_names: &[String],
|
|
1401
|
+
signature: &str,
|
|
1402
|
+
) {
|
|
1403
|
+
writeln!(out, "{}", signature).unwrap();
|
|
1097
1404
|
|
|
1098
1405
|
let mut has_checks = false;
|
|
1099
1406
|
for (f, field_name) in s.fields.iter().zip(field_names) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/benches/support/tag_dispatch_fixtures.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_inherited_simple_content.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyxml-0.36.0 → polyxml-0.37.0}/crates/polyxml-core/tests/test_schema_attribute_entities.rs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|