quicktype 17.0.4 → 17.0.5
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.
- package/dist/cli/CompressedJSONFromStream.js +38 -26
- package/dist/cli/GraphQLIntrospection.js +41 -33
- package/dist/cli/TypeSource.d.ts +1 -1
- package/dist/cli/URLGrammar.js +3 -4
- package/dist/cli/index.js +364 -363
- package/dist/quicktype-core/Annotation.js +0 -2
- package/dist/quicktype-core/ConvenienceRenderer.d.ts +17 -17
- package/dist/quicktype-core/ConvenienceRenderer.js +81 -104
- package/dist/quicktype-core/DateTime.js +0 -1
- package/dist/quicktype-core/DeclarationIR.d.ts +1 -1
- package/dist/quicktype-core/DeclarationIR.js +10 -13
- package/dist/quicktype-core/EncodedMarkovChain.js +0 -1
- package/dist/quicktype-core/GatherNames.js +25 -47
- package/dist/quicktype-core/Graph.d.ts +2 -2
- package/dist/quicktype-core/Graph.js +19 -23
- package/dist/quicktype-core/GraphRewriting.d.ts +2 -2
- package/dist/quicktype-core/GraphRewriting.js +54 -65
- package/dist/quicktype-core/MakeTransformations.js +22 -23
- package/dist/quicktype-core/MarkovChain.d.ts +3 -3
- package/dist/quicktype-core/MarkovChain.js +8 -9
- package/dist/quicktype-core/Messages.d.ts +3 -3
- package/dist/quicktype-core/Messages.js +3 -8
- package/dist/quicktype-core/Naming.d.ts +11 -11
- package/dist/quicktype-core/Naming.js +61 -76
- package/dist/quicktype-core/Renderer.d.ts +6 -6
- package/dist/quicktype-core/Renderer.js +17 -34
- package/dist/quicktype-core/RendererOptions.d.ts +5 -5
- package/dist/quicktype-core/RendererOptions.js +3 -6
- package/dist/quicktype-core/Run.d.ts +9 -9
- package/dist/quicktype-core/Run.js +67 -72
- package/dist/quicktype-core/Source.d.ts +3 -3
- package/dist/quicktype-core/Source.js +18 -19
- package/dist/quicktype-core/TargetLanguage.d.ts +10 -10
- package/dist/quicktype-core/TargetLanguage.js +2 -6
- package/dist/quicktype-core/Transformers.d.ts +25 -25
- package/dist/quicktype-core/Transformers.js +66 -94
- package/dist/quicktype-core/Type.d.ts +43 -41
- package/dist/quicktype-core/Type.js +71 -96
- package/dist/quicktype-core/TypeBuilder.d.ts +2 -2
- package/dist/quicktype-core/TypeBuilder.js +47 -53
- package/dist/quicktype-core/TypeGraph.d.ts +4 -4
- package/dist/quicktype-core/TypeGraph.js +40 -49
- package/dist/quicktype-core/TypeUtils.d.ts +2 -2
- package/dist/quicktype-core/TypeUtils.js +22 -23
- package/dist/quicktype-core/UnifyClasses.js +12 -16
- package/dist/quicktype-core/UnionBuilder.d.ts +3 -3
- package/dist/quicktype-core/UnionBuilder.js +30 -33
- package/dist/quicktype-core/attributes/AccessorNames.d.ts +2 -2
- package/dist/quicktype-core/attributes/AccessorNames.js +17 -18
- package/dist/quicktype-core/attributes/Constraints.d.ts +3 -3
- package/dist/quicktype-core/attributes/Constraints.js +4 -8
- package/dist/quicktype-core/attributes/Description.js +5 -6
- package/dist/quicktype-core/attributes/EnumValues.js +3 -4
- package/dist/quicktype-core/attributes/StringTypes.d.ts +1 -1
- package/dist/quicktype-core/attributes/StringTypes.js +21 -24
- package/dist/quicktype-core/attributes/TypeAttributes.d.ts +3 -3
- package/dist/quicktype-core/attributes/TypeAttributes.js +10 -12
- package/dist/quicktype-core/attributes/TypeNames.d.ts +9 -9
- package/dist/quicktype-core/attributes/TypeNames.js +21 -49
- package/dist/quicktype-core/attributes/URIAttributes.d.ts +1 -1
- package/dist/quicktype-core/attributes/URIAttributes.js +6 -10
- package/dist/quicktype-core/index.js +125 -128
- package/dist/quicktype-core/input/CompressedJSON.d.ts +7 -7
- package/dist/quicktype-core/input/CompressedJSON.js +54 -49
- package/dist/quicktype-core/input/FetchingJSONSchemaStore.js +13 -5
- package/dist/quicktype-core/input/Inference.d.ts +2 -2
- package/dist/quicktype-core/input/Inference.js +17 -25
- package/dist/quicktype-core/input/Inputs.d.ts +2 -2
- package/dist/quicktype-core/input/Inputs.js +54 -38
- package/dist/quicktype-core/input/JSONSchemaInput.d.ts +11 -11
- package/dist/quicktype-core/input/JSONSchemaInput.js +523 -503
- package/dist/quicktype-core/input/JSONSchemaStore.d.ts +1 -1
- package/dist/quicktype-core/input/JSONSchemaStore.js +35 -24
- package/dist/quicktype-core/input/PostmanCollection.js +1 -2
- package/dist/quicktype-core/input/io/NodeIO.js +44 -55
- package/dist/quicktype-core/input/io/get-stream/index.js +2 -6
- package/dist/quicktype-core/language/All.js +2 -3
- package/dist/quicktype-core/language/CPlusPlus.d.ts +8 -8
- package/dist/quicktype-core/language/CPlusPlus.js +151 -185
- package/dist/quicktype-core/language/CSharp.d.ts +7 -7
- package/dist/quicktype-core/language/CSharp.js +72 -82
- package/dist/quicktype-core/language/Crystal.d.ts +2 -2
- package/dist/quicktype-core/language/Crystal.js +17 -18
- package/dist/quicktype-core/language/Dart.d.ts +4 -4
- package/dist/quicktype-core/language/Dart.js +34 -36
- package/dist/quicktype-core/language/Elm.d.ts +6 -6
- package/dist/quicktype-core/language/Elm.js +45 -47
- package/dist/quicktype-core/language/Golang.d.ts +4 -4
- package/dist/quicktype-core/language/Golang.js +20 -23
- package/dist/quicktype-core/language/Haskell.d.ts +5 -5
- package/dist/quicktype-core/language/Haskell.js +23 -25
- package/dist/quicktype-core/language/JSONSchema.d.ts +3 -3
- package/dist/quicktype-core/language/JSONSchema.js +16 -17
- package/dist/quicktype-core/language/Java.d.ts +2 -2
- package/dist/quicktype-core/language/Java.js +97 -97
- package/dist/quicktype-core/language/JavaScript.d.ts +7 -7
- package/dist/quicktype-core/language/JavaScript.js +17 -19
- package/dist/quicktype-core/language/JavaScriptPropTypes.js +13 -15
- package/dist/quicktype-core/language/JavaScriptUnicodeMaps.js +11 -12
- package/dist/quicktype-core/language/Kotlin.d.ts +2 -2
- package/dist/quicktype-core/language/Kotlin.js +37 -39
- package/dist/quicktype-core/language/Objective-C.d.ts +3 -3
- package/dist/quicktype-core/language/Objective-C.js +41 -45
- package/dist/quicktype-core/language/Php.d.ts +2 -2
- package/dist/quicktype-core/language/Php.js +41 -66
- package/dist/quicktype-core/language/Pike.d.ts +1 -1
- package/dist/quicktype-core/language/Pike.js +17 -18
- package/dist/quicktype-core/language/Python.d.ts +8 -8
- package/dist/quicktype-core/language/Python.js +64 -63
- package/dist/quicktype-core/language/Rust.d.ts +2 -2
- package/dist/quicktype-core/language/Rust.js +19 -21
- package/dist/quicktype-core/language/Swift.d.ts +7 -7
- package/dist/quicktype-core/language/Swift.js +804 -807
- package/dist/quicktype-core/language/TypeScriptFlow.d.ts +7 -7
- package/dist/quicktype-core/language/TypeScriptFlow.js +26 -28
- package/dist/quicktype-core/language/ruby/index.d.ts +4 -4
- package/dist/quicktype-core/language/ruby/index.js +24 -49
- package/dist/quicktype-core/language/ruby/keywords.js +0 -1
- package/dist/quicktype-core/rewrites/CombineClasses.js +8 -9
- package/dist/quicktype-core/rewrites/ExpandStrings.d.ts +1 -1
- package/dist/quicktype-core/rewrites/ExpandStrings.js +17 -18
- package/dist/quicktype-core/rewrites/FlattenStrings.js +6 -7
- package/dist/quicktype-core/rewrites/FlattenUnions.js +8 -9
- package/dist/quicktype-core/rewrites/InferMaps.js +10 -11
- package/dist/quicktype-core/rewrites/ReplaceObjectType.js +7 -8
- package/dist/quicktype-core/rewrites/ResolveIntersections.js +67 -68
- package/dist/quicktype-core/support/Acronyms.js +1 -3
- package/dist/quicktype-core/support/Chance.js +0 -10
- package/dist/quicktype-core/support/Converters.js +0 -1
- package/dist/quicktype-core/support/Strings.d.ts +4 -4
- package/dist/quicktype-core/support/Strings.js +16 -17
- package/dist/quicktype-core/support/Support.d.ts +1 -1
- package/dist/quicktype-core/support/Support.js +6 -30
- package/dist/quicktype-graphql-input/GraphQLSchema.d.ts +4 -4
- package/dist/quicktype-graphql-input/GraphQLSchema.js +0 -1
- package/dist/quicktype-graphql-input/index.d.ts +1 -1
- package/dist/quicktype-graphql-input/index.js +212 -229
- package/dist/quicktype-typescript-input/index.js +4 -28
- package/package.json +19 -25
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CPlusPlusRenderer = exports.MemberNames = exports.GlobalNames = exports.IncludeKind = exports.CPlusPlusTargetLanguage = exports.cPlusPlusOptions = void 0;
|
|
4
3
|
const collection_utils_1 = require("collection-utils");
|
|
5
4
|
const TargetLanguage_1 = require("../TargetLanguage");
|
|
6
5
|
const Type_1 = require("../Type");
|
|
@@ -106,19 +105,19 @@ class CPlusPlusTargetLanguage extends TargetLanguage_1.TargetLanguage {
|
|
|
106
105
|
return true;
|
|
107
106
|
}
|
|
108
107
|
makeRenderer(renderContext, untypedOptionValues) {
|
|
109
|
-
return new CPlusPlusRenderer(this, renderContext,
|
|
108
|
+
return new CPlusPlusRenderer(this, renderContext, RendererOptions_1.getOptionValues(exports.cPlusPlusOptions, untypedOptionValues));
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
exports.CPlusPlusTargetLanguage = CPlusPlusTargetLanguage;
|
|
113
112
|
function constraintsForType(t) {
|
|
114
|
-
const minMax =
|
|
115
|
-
const minMaxLength =
|
|
116
|
-
const pattern =
|
|
113
|
+
const minMax = Constraints_1.minMaxValueForType(t);
|
|
114
|
+
const minMaxLength = Constraints_1.minMaxLengthForType(t);
|
|
115
|
+
const pattern = Constraints_1.patternForType(t);
|
|
117
116
|
if (minMax === undefined && minMaxLength === undefined && pattern === undefined)
|
|
118
117
|
return undefined;
|
|
119
118
|
return { minMax, minMaxLength, pattern };
|
|
120
119
|
}
|
|
121
|
-
const legalizeName =
|
|
120
|
+
const legalizeName = Strings_1.legalizeCharacters(cp => Strings_1.isAscii(cp) && Strings_1.isLetterOrUnderscoreOrDigit(cp));
|
|
122
121
|
const keywords = [
|
|
123
122
|
"alignas",
|
|
124
123
|
"alignof",
|
|
@@ -280,8 +279,6 @@ function addQualifier(qualifier, qualified) {
|
|
|
280
279
|
return [qualifier, qualified];
|
|
281
280
|
}
|
|
282
281
|
class WrappingCode {
|
|
283
|
-
_start;
|
|
284
|
-
_end;
|
|
285
282
|
constructor(start, end) {
|
|
286
283
|
this._start = start;
|
|
287
284
|
this._end = end;
|
|
@@ -291,14 +288,6 @@ class WrappingCode {
|
|
|
291
288
|
}
|
|
292
289
|
}
|
|
293
290
|
class BaseString {
|
|
294
|
-
_stringType;
|
|
295
|
-
_constStringType;
|
|
296
|
-
_smatch;
|
|
297
|
-
_regex;
|
|
298
|
-
_stringLiteralPrefix;
|
|
299
|
-
_toString;
|
|
300
|
-
_encodingClass;
|
|
301
|
-
_encodingFunction;
|
|
302
291
|
constructor(stringType, constStringType, smatch, regex, stringLiteralPrefix, toString, encodingClass, encodingFunction) {
|
|
303
292
|
(this._stringType = stringType),
|
|
304
293
|
(this._constStringType = constStringType),
|
|
@@ -329,39 +318,112 @@ class BaseString {
|
|
|
329
318
|
}
|
|
330
319
|
}
|
|
331
320
|
class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
332
|
-
_options;
|
|
333
|
-
/**
|
|
334
|
-
* For forward declaration practically
|
|
335
|
-
*/
|
|
336
|
-
_enumType;
|
|
337
|
-
_generatedFiles;
|
|
338
|
-
_currentFilename;
|
|
339
|
-
_allTypeNames;
|
|
340
|
-
_gettersAndSettersForPropertyName = new Map();
|
|
341
|
-
_namespaceNames;
|
|
342
|
-
_memberNameStyle;
|
|
343
|
-
_namedTypeNameStyle;
|
|
344
|
-
_generatedGlobalNames;
|
|
345
|
-
_generatedMemberNames;
|
|
346
|
-
_forbiddenGlobalNames;
|
|
347
|
-
_memberNamingFunction;
|
|
348
|
-
_stringType;
|
|
349
|
-
_optionalType;
|
|
350
|
-
_nulloptType;
|
|
351
|
-
_variantType;
|
|
352
|
-
_variantIndexMethodName;
|
|
353
|
-
typeNamingStyle;
|
|
354
|
-
enumeratorNamingStyle;
|
|
355
321
|
constructor(targetLanguage, renderContext, _options) {
|
|
356
322
|
super(targetLanguage, renderContext);
|
|
357
323
|
this._options = _options;
|
|
324
|
+
this._gettersAndSettersForPropertyName = new Map();
|
|
325
|
+
this.NarrowString = new (class extends BaseString {
|
|
326
|
+
constructor() {
|
|
327
|
+
super("std::string", "const std::string & ", "std::smatch", "std::regex", "", new WrappingCode(["std::to_string("], [")"]), "", "");
|
|
328
|
+
}
|
|
329
|
+
wrapEncodingChange(_qualifier, _fromType, _toType, inner) {
|
|
330
|
+
return inner;
|
|
331
|
+
}
|
|
332
|
+
emitHelperFunctions() {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
})();
|
|
336
|
+
this.WideString = new (class extends BaseString {
|
|
337
|
+
constructor(superThis) {
|
|
338
|
+
super("std::wstring", "const std::wstring & ", "std::wsmatch", "std::wregex", "L", new WrappingCode(["std::to_wstring("], [")"]), "Utf16_Utf8", "convert");
|
|
339
|
+
this.superThis = superThis;
|
|
340
|
+
}
|
|
341
|
+
wrapEncodingChange(qualifier, fromType, toType, inner) {
|
|
342
|
+
if (this.superThis.sourcelikeToString(fromType) === this.superThis.sourcelikeToString(toType)) {
|
|
343
|
+
return inner;
|
|
344
|
+
}
|
|
345
|
+
return [
|
|
346
|
+
addQualifier(qualifier, [this._encodingClass]),
|
|
347
|
+
"<",
|
|
348
|
+
fromType,
|
|
349
|
+
", ",
|
|
350
|
+
toType,
|
|
351
|
+
">::",
|
|
352
|
+
this._encodingFunction,
|
|
353
|
+
"(",
|
|
354
|
+
inner,
|
|
355
|
+
")"
|
|
356
|
+
];
|
|
357
|
+
}
|
|
358
|
+
emitHelperFunctions() {
|
|
359
|
+
this.superThis.emitLine("template<typename T>");
|
|
360
|
+
this.superThis.emitLine("struct tag {};");
|
|
361
|
+
this.superThis.ensureBlankLine();
|
|
362
|
+
this.superThis.emitLine("template<typename fromType, typename toType>");
|
|
363
|
+
this.superThis.emitBlock(["class Utf16_Utf8"], true, () => {
|
|
364
|
+
this.superThis.emitLine("private:");
|
|
365
|
+
this.superThis.emitLine("template<typename TF, typename TT>");
|
|
366
|
+
this.superThis.emitBlock(["static toType convert(tag<std::shared_ptr<TF> >, tag<std::shared_ptr<TT> >, fromType ptr)"], false, () => {
|
|
367
|
+
this.superThis.emitLine("if (ptr == nullptr) return std::unique_ptr<TT>(); else return std::unique_ptr<TT>(new TT(Utf16_Utf8<TF,TT>::convert(*ptr)));");
|
|
368
|
+
});
|
|
369
|
+
this.superThis.ensureBlankLine();
|
|
370
|
+
this.superThis.emitLine("template<typename TF, typename TT>");
|
|
371
|
+
this.superThis.emitBlock(["static toType convert(tag<std::vector<TF> >, tag<std::vector<TT> >, fromType v)"], false, () => {
|
|
372
|
+
this.superThis.emitLine("auto it = v.begin();");
|
|
373
|
+
this.superThis.emitLine("auto newVector = std::vector<TT>();");
|
|
374
|
+
this.superThis.emitBlock(["while (it != v.end())"], false, () => {
|
|
375
|
+
this.superThis.emitLine("newVector.push_back(Utf16_Utf8<TF,TT>::convert(*it));");
|
|
376
|
+
this.superThis.emitLine("it++;");
|
|
377
|
+
});
|
|
378
|
+
this.superThis.emitLine("return newVector;");
|
|
379
|
+
});
|
|
380
|
+
this.superThis.ensureBlankLine();
|
|
381
|
+
this.superThis.emitLine("template<typename KF, typename VF, typename KT, typename VT>");
|
|
382
|
+
this.superThis.emitBlock(["static toType convert(tag<std::map<KF,VF> >, tag<std::map<KT,VT> >, fromType m)"], false, () => {
|
|
383
|
+
this.superThis.emitLine("auto it = m.begin();");
|
|
384
|
+
this.superThis.emitLine("auto newMap = std::map<KT, VT>();");
|
|
385
|
+
this.superThis.emitBlock(["while (it != m.end())"], false, () => {
|
|
386
|
+
this.superThis.emitLine("newMap.insert(std::pair<KT, VT>(Utf16_Utf8<KF, KT>::convert(it->first), Utf16_Utf8<VF, VT>::convert(it->second)));");
|
|
387
|
+
this.superThis.emitLine("it++;");
|
|
388
|
+
});
|
|
389
|
+
this.superThis.emitLine("return newMap;");
|
|
390
|
+
});
|
|
391
|
+
this.superThis.ensureBlankLine();
|
|
392
|
+
this.superThis.emitLine("template<typename TF, typename TT>");
|
|
393
|
+
this.superThis.emitBlock(["static fromType convert(tag<TF>, tag<TT>, fromType from)"], false, () => {
|
|
394
|
+
this.superThis.emitLine("return from;");
|
|
395
|
+
});
|
|
396
|
+
this.superThis.ensureBlankLine();
|
|
397
|
+
this.superThis.emitBlock(["static std::wstring convert(tag<std::string>, tag<std::wstring>, std::string str)"], false, () => {
|
|
398
|
+
this.superThis.emitLine("return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t>{}.from_bytes(str.data());");
|
|
399
|
+
});
|
|
400
|
+
this.superThis.ensureBlankLine();
|
|
401
|
+
this.superThis.emitBlock(["static std::string convert(tag<std::wstring>, tag<std::string>, std::wstring str)"], false, () => {
|
|
402
|
+
this.superThis.emitLine("return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t>{}.to_bytes(str.data());");
|
|
403
|
+
});
|
|
404
|
+
this.superThis.ensureBlankLine();
|
|
405
|
+
this.superThis.emitLine("public:");
|
|
406
|
+
this.superThis.emitBlock(["static toType convert(fromType in)"], false, () => {
|
|
407
|
+
this.superThis.emitLine("return convert(tag<fromType>(), tag<toType>(), in);");
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
this.superThis.ensureBlankLine();
|
|
411
|
+
this.superThis.emitLine("template<typename T>");
|
|
412
|
+
this.superThis.emitBlock(["std::wstring wdump(const T& j)"], false, () => {
|
|
413
|
+
this.superThis.emitLine("std::ostringstream s;");
|
|
414
|
+
this.superThis.emitLine("s << j;");
|
|
415
|
+
this.superThis.emitLine("return ", this.superThis.ourQualifier(false), "Utf16_Utf8<std::string, std::wstring>::convert(s.str()); ");
|
|
416
|
+
});
|
|
417
|
+
this.superThis.ensureBlankLine();
|
|
418
|
+
}
|
|
419
|
+
})(this);
|
|
358
420
|
this._enumType = _options.enumType;
|
|
359
421
|
this._namespaceNames = _options.namespace.split("::");
|
|
360
422
|
this.typeNamingStyle = _options.typeNamingStyle;
|
|
361
|
-
this._namedTypeNameStyle =
|
|
423
|
+
this._namedTypeNameStyle = Strings_1.makeNameStyle(this.typeNamingStyle, legalizeName);
|
|
362
424
|
this.enumeratorNamingStyle = _options.enumeratorNamingStyle;
|
|
363
|
-
this._memberNameStyle =
|
|
364
|
-
this._memberNamingFunction =
|
|
425
|
+
this._memberNameStyle = Strings_1.makeNameStyle(_options.memberNamingStyle, legalizeName);
|
|
426
|
+
this._memberNamingFunction = Naming_1.funPrefixNamer("members", this._memberNameStyle);
|
|
365
427
|
this._gettersAndSettersForPropertyName = new Map();
|
|
366
428
|
this._allTypeNames = new Set();
|
|
367
429
|
this._generatedFiles = new Set();
|
|
@@ -424,10 +486,10 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
424
486
|
];
|
|
425
487
|
}
|
|
426
488
|
lookupGlobalName(type) {
|
|
427
|
-
return
|
|
489
|
+
return Support_1.defined(this._generatedGlobalNames.get(type));
|
|
428
490
|
}
|
|
429
491
|
lookupMemberName(type) {
|
|
430
|
-
return
|
|
492
|
+
return Support_1.defined(this._generatedMemberNames.get(type));
|
|
431
493
|
}
|
|
432
494
|
addGlobalName(type) {
|
|
433
495
|
const genName = this._namedTypeNameStyle(GlobalNames[type]);
|
|
@@ -438,10 +500,10 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
438
500
|
this._generatedMemberNames.set(type, this._memberNameStyle(MemberNames[type]));
|
|
439
501
|
}
|
|
440
502
|
setupGlobalNames() {
|
|
441
|
-
for (const v of
|
|
503
|
+
for (const v of Support_1.numberEnumValues(GlobalNames)) {
|
|
442
504
|
this.addGlobalName(v);
|
|
443
505
|
}
|
|
444
|
-
for (const v of
|
|
506
|
+
for (const v of Support_1.numberEnumValues(MemberNames)) {
|
|
445
507
|
this.addMemberName(v);
|
|
446
508
|
}
|
|
447
509
|
}
|
|
@@ -455,7 +517,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
455
517
|
return { names: [], includeGlobalForbidden: true };
|
|
456
518
|
}
|
|
457
519
|
makeNamedTypeNamer() {
|
|
458
|
-
return
|
|
520
|
+
return Naming_1.funPrefixNamer("types", this._namedTypeNameStyle);
|
|
459
521
|
}
|
|
460
522
|
namerForObjectProperty() {
|
|
461
523
|
return this._memberNamingFunction;
|
|
@@ -464,7 +526,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
464
526
|
return null;
|
|
465
527
|
}
|
|
466
528
|
makeEnumCaseNamer() {
|
|
467
|
-
return
|
|
529
|
+
return Naming_1.funPrefixNamer("enumerators", Strings_1.makeNameStyle(this.enumeratorNamingStyle, legalizeName));
|
|
468
530
|
}
|
|
469
531
|
makeNamesForPropertyGetterAndSetter(_c, _className, _p, _jsonName, name) {
|
|
470
532
|
const getterName = new Naming_1.DependencyName(this._memberNamingFunction, name.order, lookup => `get_${lookup(name)}`);
|
|
@@ -489,7 +551,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
489
551
|
this.emitLine("#include ", global ? "<" : '"', name, global ? ">" : '"');
|
|
490
552
|
}
|
|
491
553
|
startFile(basename, includeHelper = true) {
|
|
492
|
-
|
|
554
|
+
Support_2.assert(this._currentFilename === undefined, "Previous file wasn't finished");
|
|
493
555
|
if (basename !== undefined) {
|
|
494
556
|
this._currentFilename = this.sourcelikeToString(basename);
|
|
495
557
|
}
|
|
@@ -549,7 +611,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
549
611
|
this.ensureBlankLine();
|
|
550
612
|
}
|
|
551
613
|
finishFile() {
|
|
552
|
-
super.finishFile(
|
|
614
|
+
super.finishFile(Support_1.defined(this._currentFilename));
|
|
553
615
|
this._currentFilename = undefined;
|
|
554
616
|
}
|
|
555
617
|
get needsTypeDeclarationBeforeUse() {
|
|
@@ -580,7 +642,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
580
642
|
}
|
|
581
643
|
}
|
|
582
644
|
emitNamespaces(namespaceNames, f) {
|
|
583
|
-
const namesArray =
|
|
645
|
+
const namesArray = collection_utils_1.toReadonlyArray(namespaceNames);
|
|
584
646
|
const first = namesArray[0];
|
|
585
647
|
if (first === undefined) {
|
|
586
648
|
f();
|
|
@@ -591,7 +653,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
591
653
|
}
|
|
592
654
|
cppTypeInOptional(nonNulls, ctx, withIssues, forceNarrowString) {
|
|
593
655
|
if (nonNulls.size === 1) {
|
|
594
|
-
return this.cppType(
|
|
656
|
+
return this.cppType(Support_1.defined(collection_utils_1.iterableFirst(nonNulls)), ctx, withIssues, forceNarrowString, false);
|
|
595
657
|
}
|
|
596
658
|
const typeList = [];
|
|
597
659
|
for (const t of nonNulls) {
|
|
@@ -607,8 +669,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
607
669
|
return [this._variantType, "<", typeList, ">"];
|
|
608
670
|
}
|
|
609
671
|
variantType(u, inJsonNamespace) {
|
|
610
|
-
const [maybeNull, nonNulls] =
|
|
611
|
-
|
|
672
|
+
const [maybeNull, nonNulls] = TypeUtils_1.removeNullFromUnion(u, true);
|
|
673
|
+
Support_2.assert(nonNulls.size >= 2, "Variant not needed for less than two types.");
|
|
612
674
|
const indirection = maybeNull !== null;
|
|
613
675
|
const variant = this.cppTypeInOptional(nonNulls, { needsForwardIndirection: !indirection, needsOptionalIndirection: !indirection, inJsonNamespace }, true, false);
|
|
614
676
|
if (!indirection) {
|
|
@@ -618,7 +680,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
618
680
|
}
|
|
619
681
|
ourQualifier(inJsonNamespace) {
|
|
620
682
|
return inJsonNamespace || this._options.msbuildPermissive
|
|
621
|
-
? [
|
|
683
|
+
? [collection_utils_1.arrayIntercalate("::", this._namespaceNames), "::"]
|
|
622
684
|
: [];
|
|
623
685
|
}
|
|
624
686
|
jsonQualifier(inJsonNamespace) {
|
|
@@ -640,15 +702,15 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
640
702
|
}
|
|
641
703
|
}
|
|
642
704
|
}
|
|
643
|
-
let typeSource =
|
|
705
|
+
let typeSource = TypeUtils_1.matchType(t, _anyType => {
|
|
644
706
|
isOptional = false;
|
|
645
|
-
return
|
|
707
|
+
return Source_1.maybeAnnotated(withIssues, Annotation_1.anyTypeIssueAnnotation, [
|
|
646
708
|
this.jsonQualifier(inJsonNamespace),
|
|
647
709
|
"json"
|
|
648
710
|
]);
|
|
649
711
|
}, _nullType => {
|
|
650
712
|
isOptional = false;
|
|
651
|
-
return
|
|
713
|
+
return Source_1.maybeAnnotated(withIssues, Annotation_1.nullTypeIssueAnnotation, [
|
|
652
714
|
this.jsonQualifier(inJsonNamespace),
|
|
653
715
|
"json"
|
|
654
716
|
]);
|
|
@@ -676,7 +738,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
676
738
|
">"
|
|
677
739
|
];
|
|
678
740
|
}, enumType => [this.ourQualifier(inJsonNamespace), this.nameForNamedType(enumType)], unionType => {
|
|
679
|
-
const nullable =
|
|
741
|
+
const nullable = TypeUtils_1.nullableFromUnion(unionType);
|
|
680
742
|
if (nullable === null)
|
|
681
743
|
return [this.ourQualifier(inJsonNamespace), this.nameForNamedType(unionType)];
|
|
682
744
|
isOptional = true;
|
|
@@ -743,7 +805,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
743
805
|
});
|
|
744
806
|
/** intentional "fall-through", add all subtypes as well - but forced include */
|
|
745
807
|
}
|
|
746
|
-
const [hasNull, nonNulls] =
|
|
808
|
+
const [hasNull, nonNulls] = TypeUtils_1.removeNullFromUnion(t);
|
|
747
809
|
isVariant = hasNull !== null;
|
|
748
810
|
/** we need to collect all the subtypes of the union */
|
|
749
811
|
for (const tt of nonNulls) {
|
|
@@ -780,7 +842,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
780
842
|
this.emitMember(this.cppType(property.type, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, true, false, property.isOptional), name);
|
|
781
843
|
}
|
|
782
844
|
else {
|
|
783
|
-
const [getterName, mutableGetterName, setterName] =
|
|
845
|
+
const [getterName, mutableGetterName, setterName] = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
784
846
|
const rendered = this.cppType(property.type, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, true, false, property.isOptional);
|
|
785
847
|
/**
|
|
786
848
|
* fix for optional type -> e.g. unique_ptrs can't be copied
|
|
@@ -839,7 +901,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
839
901
|
: [
|
|
840
902
|
this._stringType.getType(),
|
|
841
903
|
"(",
|
|
842
|
-
this._stringType.createStringLiteral([
|
|
904
|
+
this._stringType.createStringLiteral([Strings_1.stringEscape(pattern)]),
|
|
843
905
|
")"
|
|
844
906
|
],
|
|
845
907
|
")"
|
|
@@ -927,7 +989,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
927
989
|
let toType;
|
|
928
990
|
this.emitBlock(["inline void from_json(", this.withConst("json"), " & j, ", ourQualifier, className, "& x)"], false, () => {
|
|
929
991
|
this.forEachClassProperty(c, "none", (name, json, p) => {
|
|
930
|
-
const [, , setterName] =
|
|
992
|
+
const [, , setterName] = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
931
993
|
const t = p.type;
|
|
932
994
|
let assignment;
|
|
933
995
|
if (this._options.codeFormat) {
|
|
@@ -940,7 +1002,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
940
1002
|
this.emitLine(assignment.wrap([], [
|
|
941
1003
|
ourQualifier,
|
|
942
1004
|
"get_untyped(j, ",
|
|
943
|
-
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([
|
|
1005
|
+
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([Strings_1.stringEscape(json)])]),
|
|
944
1006
|
")"
|
|
945
1007
|
]), ";");
|
|
946
1008
|
return;
|
|
@@ -948,7 +1010,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
948
1010
|
if (p.isOptional || t instanceof Type_1.UnionType) {
|
|
949
1011
|
const [nullOrOptional, typeSet] = (function () {
|
|
950
1012
|
if (t instanceof Type_1.UnionType) {
|
|
951
|
-
const [maybeNull, nonNulls] =
|
|
1013
|
+
const [maybeNull, nonNulls] = TypeUtils_1.removeNullFromUnion(t, true);
|
|
952
1014
|
return [maybeNull !== null || p.isOptional, nonNulls];
|
|
953
1015
|
}
|
|
954
1016
|
else {
|
|
@@ -974,7 +1036,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
974
1036
|
"get_optional<",
|
|
975
1037
|
cppType,
|
|
976
1038
|
">(j, ",
|
|
977
|
-
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([
|
|
1039
|
+
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([Strings_1.stringEscape(json)])]),
|
|
978
1040
|
")"
|
|
979
1041
|
])
|
|
980
1042
|
]), ";");
|
|
@@ -985,7 +1047,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
985
1047
|
toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, p.isOptional);
|
|
986
1048
|
this.emitLine(assignment.wrap([], this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, [
|
|
987
1049
|
"j.at(",
|
|
988
|
-
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), this._stringType.createStringLiteral([
|
|
1050
|
+
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), this._stringType.createStringLiteral([Strings_1.stringEscape(json)])),
|
|
989
1051
|
").get<",
|
|
990
1052
|
cppType,
|
|
991
1053
|
">()"
|
|
@@ -999,7 +1061,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
999
1061
|
const t = p.type;
|
|
1000
1062
|
cppType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, false, p.isOptional);
|
|
1001
1063
|
toType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, true, p.isOptional);
|
|
1002
|
-
const [getterName, ,] =
|
|
1064
|
+
const [getterName, ,] = Support_1.defined(this._gettersAndSettersForPropertyName.get(name));
|
|
1003
1065
|
let getter;
|
|
1004
1066
|
if (this._options.codeFormat) {
|
|
1005
1067
|
getter = [getterName, "()"];
|
|
@@ -1009,7 +1071,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1009
1071
|
}
|
|
1010
1072
|
let assignment = [
|
|
1011
1073
|
"j[",
|
|
1012
|
-
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), this._stringType.createStringLiteral([
|
|
1074
|
+
this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), this._stringType.createStringLiteral([Strings_1.stringEscape(json)])),
|
|
1013
1075
|
"] = ",
|
|
1014
1076
|
this._stringType.wrapEncodingChange([ourQualifier], cppType, toType, ["x.", getter]),
|
|
1015
1077
|
";"
|
|
@@ -1031,13 +1093,13 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1031
1093
|
}
|
|
1032
1094
|
emitEnum(e, enumName) {
|
|
1033
1095
|
const caseNames = [];
|
|
1034
|
-
const enumValues =
|
|
1096
|
+
const enumValues = EnumValues_1.enumCaseValues(e, this.targetLanguage.name);
|
|
1035
1097
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
1036
1098
|
if (caseNames.length > 0)
|
|
1037
1099
|
caseNames.push(", ");
|
|
1038
1100
|
caseNames.push(name);
|
|
1039
1101
|
if (enumValues !== undefined) {
|
|
1040
|
-
const [enumValue] =
|
|
1102
|
+
const [enumValue] = AccessorNames_1.getAccessorName(enumValues, jsonName);
|
|
1041
1103
|
if (enumValue !== undefined) {
|
|
1042
1104
|
caseNames.push(" = ", enumValue.toString());
|
|
1043
1105
|
}
|
|
@@ -1050,7 +1112,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1050
1112
|
this.emitLine("using ", unionName, " = ", this.variantType(u, false), ";");
|
|
1051
1113
|
}
|
|
1052
1114
|
emitUnionHeaders(u) {
|
|
1053
|
-
const nonNulls =
|
|
1115
|
+
const nonNulls = TypeUtils_1.removeNullFromUnion(u, true)[1];
|
|
1054
1116
|
const variantType = this.cppTypeInOptional(nonNulls, { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace: true }, false, false);
|
|
1055
1117
|
this.emitLine("void from_json(", this.withConst("json"), " & j, ", variantType, " & x);");
|
|
1056
1118
|
this.emitLine("void to_json(json & j, ", this.withConst(variantType), " & x);");
|
|
@@ -1067,12 +1129,12 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1067
1129
|
["array", "is_array"],
|
|
1068
1130
|
["enum", "is_string"]
|
|
1069
1131
|
];
|
|
1070
|
-
const nonNulls =
|
|
1132
|
+
const nonNulls = TypeUtils_1.removeNullFromUnion(u, true)[1];
|
|
1071
1133
|
const variantType = this.cppTypeInOptional(nonNulls, { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace: true }, false, false);
|
|
1072
1134
|
this.emitBlock(["inline void from_json(", this.withConst("json"), " & j, ", variantType, " & x)"], false, () => {
|
|
1073
1135
|
let onFirst = true;
|
|
1074
1136
|
for (const [kind, func] of functionForKind) {
|
|
1075
|
-
const typeForKind =
|
|
1137
|
+
const typeForKind = collection_utils_1.iterableFind(nonNulls, t => t.kind === kind);
|
|
1076
1138
|
if (typeForKind === undefined)
|
|
1077
1139
|
continue;
|
|
1078
1140
|
this.emitLine(onFirst ? "if" : "else if", " (j.", func, "())");
|
|
@@ -1142,7 +1204,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1142
1204
|
"> enumValues"
|
|
1143
1205
|
], true, () => {
|
|
1144
1206
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
1145
|
-
this.emitLine("{", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([
|
|
1207
|
+
this.emitLine("{", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([Strings_1.stringEscape(jsonName)])]), ", ", ourQualifier, enumName, "::", name, "},");
|
|
1146
1208
|
});
|
|
1147
1209
|
});
|
|
1148
1210
|
this.emitLine(`auto iter = enumValues.find(j.get<${this._stringType.getType()}>());`);
|
|
@@ -1154,7 +1216,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1154
1216
|
let onFirst = true;
|
|
1155
1217
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
1156
1218
|
const maybeElse = onFirst ? "" : "else ";
|
|
1157
|
-
this.emitLine(maybeElse, "if (j == ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([
|
|
1219
|
+
this.emitLine(maybeElse, "if (j == ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([Strings_1.stringEscape(jsonName)])]), ") x = ", ourQualifier, enumName, "::", name, ";");
|
|
1158
1220
|
onFirst = false;
|
|
1159
1221
|
});
|
|
1160
1222
|
this.emitLine('else throw "Input JSON does not conform to schema";');
|
|
@@ -1164,7 +1226,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1164
1226
|
this.emitBlock(["inline void to_json(json & j, ", this.withConst([ourQualifier, enumName]), " & x)"], false, () => {
|
|
1165
1227
|
this.emitBlock("switch (x)", false, () => {
|
|
1166
1228
|
this.forEachEnumCase(e, "none", (name, jsonName) => {
|
|
1167
|
-
this.emitLine("case ", ourQualifier, enumName, "::", name, ": j = ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([
|
|
1229
|
+
this.emitLine("case ", ourQualifier, enumName, "::", name, ": j = ", this._stringType.wrapEncodingChange([ourQualifier], this._stringType.getType(), this.NarrowString.getType(), [this._stringType.createStringLiteral([Strings_1.stringEscape(jsonName)])]), "; break;");
|
|
1168
1230
|
});
|
|
1169
1231
|
this.emitLine('default: throw "This should not happen";');
|
|
1170
1232
|
});
|
|
@@ -1174,10 +1236,10 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1174
1236
|
this.emitLine("using ", name, " = ", this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: false }, true, false, false), ";");
|
|
1175
1237
|
}
|
|
1176
1238
|
emitAllUnionFunctions() {
|
|
1177
|
-
this.forEachUniqueUnion("interposing", u => this.sourcelikeToString(this.cppTypeInOptional(
|
|
1239
|
+
this.forEachUniqueUnion("interposing", u => this.sourcelikeToString(this.cppTypeInOptional(TypeUtils_1.removeNullFromUnion(u, true)[1], { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace: true }, false, false)), (u) => this.emitUnionFunctions(u));
|
|
1178
1240
|
}
|
|
1179
1241
|
emitAllUnionHeaders() {
|
|
1180
|
-
this.forEachUniqueUnion("interposing", u => this.sourcelikeToString(this.cppTypeInOptional(
|
|
1242
|
+
this.forEachUniqueUnion("interposing", u => this.sourcelikeToString(this.cppTypeInOptional(TypeUtils_1.removeNullFromUnion(u, true)[1], { needsForwardIndirection: false, needsOptionalIndirection: false, inJsonNamespace: true }, false, false)), (u) => this.emitUnionHeaders(u));
|
|
1181
1243
|
}
|
|
1182
1244
|
emitOptionalHelpers() {
|
|
1183
1245
|
this.emitLine("#ifndef NLOHMANN_OPT_HELPER");
|
|
@@ -1218,11 +1280,11 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1218
1280
|
this.emitUnionTypedefs(t, name);
|
|
1219
1281
|
}
|
|
1220
1282
|
else {
|
|
1221
|
-
return
|
|
1283
|
+
return Support_1.panic(`Cannot declare type ${t.kind}`);
|
|
1222
1284
|
}
|
|
1223
1285
|
}
|
|
1224
1286
|
else {
|
|
1225
|
-
return
|
|
1287
|
+
return Support_1.assertNever(decl.kind);
|
|
1226
1288
|
}
|
|
1227
1289
|
}
|
|
1228
1290
|
emitGetterSetter(t, getterName, setterName, memberName) {
|
|
@@ -1256,12 +1318,12 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1256
1318
|
const member = this.lookupMemberName(name);
|
|
1257
1319
|
return [member, "(", member, ")"];
|
|
1258
1320
|
});
|
|
1259
|
-
this.emitLine(") : ",
|
|
1321
|
+
this.emitLine(") : ", collection_utils_1.arrayIntercalate([", "], args), " {}");
|
|
1260
1322
|
this.emitLine(classConstraint, "() = default;");
|
|
1261
1323
|
this.emitLine("virtual ~", classConstraint, "() = default;");
|
|
1262
1324
|
for (const member of constraintMembers) {
|
|
1263
1325
|
this.ensureBlankLine();
|
|
1264
|
-
this.emitGetterSetter(
|
|
1326
|
+
this.emitGetterSetter(collection_utils_1.withDefault(member.cppConstType, member.cppType), this.lookupMemberName(member.getter), this.lookupMemberName(member.setter), this.lookupMemberName(member.name));
|
|
1265
1327
|
}
|
|
1266
1328
|
});
|
|
1267
1329
|
this.ensureBlankLine();
|
|
@@ -1354,7 +1416,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1354
1416
|
emitHelperFunctions() {
|
|
1355
1417
|
this._stringType.emitHelperFunctions();
|
|
1356
1418
|
if (this._options.codeFormat &&
|
|
1357
|
-
|
|
1419
|
+
collection_utils_1.iterableSome(this.typeGraph.allTypesUnordered(), t => constraintsForType(t) !== undefined)) {
|
|
1358
1420
|
this.emitConstraintClasses();
|
|
1359
1421
|
this.ensureBlankLine();
|
|
1360
1422
|
}
|
|
@@ -1534,7 +1596,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1534
1596
|
else if (t.type instanceof Type_1.UnionType) {
|
|
1535
1597
|
propRecord.typeKind = "union";
|
|
1536
1598
|
/** Recurse into the union */
|
|
1537
|
-
const [maybeNull] =
|
|
1599
|
+
const [maybeNull] = TypeUtils_1.removeNullFromUnion(t.type, true);
|
|
1538
1600
|
if (maybeNull !== undefined) {
|
|
1539
1601
|
/** Houston this is a variant, include it */
|
|
1540
1602
|
propRecord.kind = IncludeKind.Include;
|
|
@@ -1618,7 +1680,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1618
1680
|
this.emitLine("enum class ", name, " : ", this._enumType, ";");
|
|
1619
1681
|
}
|
|
1620
1682
|
else {
|
|
1621
|
-
|
|
1683
|
+
Support_1.panic(`Invalid type "${rec.typeKind}" to forward declare`);
|
|
1622
1684
|
}
|
|
1623
1685
|
});
|
|
1624
1686
|
});
|
|
@@ -1689,8 +1751,8 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1689
1751
|
/** Gather all the unique/custom types used by the schema */
|
|
1690
1752
|
this._allTypeNames.clear();
|
|
1691
1753
|
this.forEachDeclaration("none", decl => {
|
|
1692
|
-
const definedTypes =
|
|
1693
|
-
if (
|
|
1754
|
+
const definedTypes = TypeUtils_1.directlyReachableTypes(decl.type, t => {
|
|
1755
|
+
if (TypeUtils_1.isNamedType(t) && (t instanceof Type_1.ClassType || t instanceof Type_1.EnumType || t instanceof Type_1.UnionType)) {
|
|
1694
1756
|
return new Set([
|
|
1695
1757
|
this.sourcelikeToString(this.cppType(t, {
|
|
1696
1758
|
needsForwardIndirection: false,
|
|
@@ -1701,7 +1763,7 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1701
1763
|
}
|
|
1702
1764
|
return null;
|
|
1703
1765
|
});
|
|
1704
|
-
this._allTypeNames =
|
|
1766
|
+
this._allTypeNames = collection_utils_1.setUnion(definedTypes, this._allTypeNames);
|
|
1705
1767
|
});
|
|
1706
1768
|
if (this._options.typeSourceStyle) {
|
|
1707
1769
|
this.emitSingleSourceStructure(proposedFilename);
|
|
@@ -1715,101 +1777,5 @@ class CPlusPlusRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
1715
1777
|
let newType = this.cppType(t, { needsForwardIndirection: true, needsOptionalIndirection: true, inJsonNamespace: true }, false, true, false);
|
|
1716
1778
|
return originalType !== newType;
|
|
1717
1779
|
}
|
|
1718
|
-
NarrowString = new (class extends BaseString {
|
|
1719
|
-
constructor() {
|
|
1720
|
-
super("std::string", "const std::string & ", "std::smatch", "std::regex", "", new WrappingCode(["std::to_string("], [")"]), "", "");
|
|
1721
|
-
}
|
|
1722
|
-
wrapEncodingChange(_qualifier, _fromType, _toType, inner) {
|
|
1723
|
-
return inner;
|
|
1724
|
-
}
|
|
1725
|
-
emitHelperFunctions() {
|
|
1726
|
-
return;
|
|
1727
|
-
}
|
|
1728
|
-
})();
|
|
1729
|
-
WideString = new (class extends BaseString {
|
|
1730
|
-
superThis;
|
|
1731
|
-
constructor(superThis) {
|
|
1732
|
-
super("std::wstring", "const std::wstring & ", "std::wsmatch", "std::wregex", "L", new WrappingCode(["std::to_wstring("], [")"]), "Utf16_Utf8", "convert");
|
|
1733
|
-
this.superThis = superThis;
|
|
1734
|
-
}
|
|
1735
|
-
wrapEncodingChange(qualifier, fromType, toType, inner) {
|
|
1736
|
-
if (this.superThis.sourcelikeToString(fromType) === this.superThis.sourcelikeToString(toType)) {
|
|
1737
|
-
return inner;
|
|
1738
|
-
}
|
|
1739
|
-
return [
|
|
1740
|
-
addQualifier(qualifier, [this._encodingClass]),
|
|
1741
|
-
"<",
|
|
1742
|
-
fromType,
|
|
1743
|
-
", ",
|
|
1744
|
-
toType,
|
|
1745
|
-
">::",
|
|
1746
|
-
this._encodingFunction,
|
|
1747
|
-
"(",
|
|
1748
|
-
inner,
|
|
1749
|
-
")"
|
|
1750
|
-
];
|
|
1751
|
-
}
|
|
1752
|
-
emitHelperFunctions() {
|
|
1753
|
-
this.superThis.emitLine("template<typename T>");
|
|
1754
|
-
this.superThis.emitLine("struct tag {};");
|
|
1755
|
-
this.superThis.ensureBlankLine();
|
|
1756
|
-
this.superThis.emitLine("template<typename fromType, typename toType>");
|
|
1757
|
-
this.superThis.emitBlock(["class Utf16_Utf8"], true, () => {
|
|
1758
|
-
this.superThis.emitLine("private:");
|
|
1759
|
-
this.superThis.emitLine("template<typename TF, typename TT>");
|
|
1760
|
-
this.superThis.emitBlock(["static toType convert(tag<std::shared_ptr<TF> >, tag<std::shared_ptr<TT> >, fromType ptr)"], false, () => {
|
|
1761
|
-
this.superThis.emitLine("if (ptr == nullptr) return std::unique_ptr<TT>(); else return std::unique_ptr<TT>(new TT(Utf16_Utf8<TF,TT>::convert(*ptr)));");
|
|
1762
|
-
});
|
|
1763
|
-
this.superThis.ensureBlankLine();
|
|
1764
|
-
this.superThis.emitLine("template<typename TF, typename TT>");
|
|
1765
|
-
this.superThis.emitBlock(["static toType convert(tag<std::vector<TF> >, tag<std::vector<TT> >, fromType v)"], false, () => {
|
|
1766
|
-
this.superThis.emitLine("auto it = v.begin();");
|
|
1767
|
-
this.superThis.emitLine("auto newVector = std::vector<TT>();");
|
|
1768
|
-
this.superThis.emitBlock(["while (it != v.end())"], false, () => {
|
|
1769
|
-
this.superThis.emitLine("newVector.push_back(Utf16_Utf8<TF,TT>::convert(*it));");
|
|
1770
|
-
this.superThis.emitLine("it++;");
|
|
1771
|
-
});
|
|
1772
|
-
this.superThis.emitLine("return newVector;");
|
|
1773
|
-
});
|
|
1774
|
-
this.superThis.ensureBlankLine();
|
|
1775
|
-
this.superThis.emitLine("template<typename KF, typename VF, typename KT, typename VT>");
|
|
1776
|
-
this.superThis.emitBlock(["static toType convert(tag<std::map<KF,VF> >, tag<std::map<KT,VT> >, fromType m)"], false, () => {
|
|
1777
|
-
this.superThis.emitLine("auto it = m.begin();");
|
|
1778
|
-
this.superThis.emitLine("auto newMap = std::map<KT, VT>();");
|
|
1779
|
-
this.superThis.emitBlock(["while (it != m.end())"], false, () => {
|
|
1780
|
-
this.superThis.emitLine("newMap.insert(std::pair<KT, VT>(Utf16_Utf8<KF, KT>::convert(it->first), Utf16_Utf8<VF, VT>::convert(it->second)));");
|
|
1781
|
-
this.superThis.emitLine("it++;");
|
|
1782
|
-
});
|
|
1783
|
-
this.superThis.emitLine("return newMap;");
|
|
1784
|
-
});
|
|
1785
|
-
this.superThis.ensureBlankLine();
|
|
1786
|
-
this.superThis.emitLine("template<typename TF, typename TT>");
|
|
1787
|
-
this.superThis.emitBlock(["static fromType convert(tag<TF>, tag<TT>, fromType from)"], false, () => {
|
|
1788
|
-
this.superThis.emitLine("return from;");
|
|
1789
|
-
});
|
|
1790
|
-
this.superThis.ensureBlankLine();
|
|
1791
|
-
this.superThis.emitBlock(["static std::wstring convert(tag<std::string>, tag<std::wstring>, std::string str)"], false, () => {
|
|
1792
|
-
this.superThis.emitLine("return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t>{}.from_bytes(str.data());");
|
|
1793
|
-
});
|
|
1794
|
-
this.superThis.ensureBlankLine();
|
|
1795
|
-
this.superThis.emitBlock(["static std::string convert(tag<std::wstring>, tag<std::string>, std::wstring str)"], false, () => {
|
|
1796
|
-
this.superThis.emitLine("return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t>{}.to_bytes(str.data());");
|
|
1797
|
-
});
|
|
1798
|
-
this.superThis.ensureBlankLine();
|
|
1799
|
-
this.superThis.emitLine("public:");
|
|
1800
|
-
this.superThis.emitBlock(["static toType convert(fromType in)"], false, () => {
|
|
1801
|
-
this.superThis.emitLine("return convert(tag<fromType>(), tag<toType>(), in);");
|
|
1802
|
-
});
|
|
1803
|
-
});
|
|
1804
|
-
this.superThis.ensureBlankLine();
|
|
1805
|
-
this.superThis.emitLine("template<typename T>");
|
|
1806
|
-
this.superThis.emitBlock(["std::wstring wdump(const T& j)"], false, () => {
|
|
1807
|
-
this.superThis.emitLine("std::ostringstream s;");
|
|
1808
|
-
this.superThis.emitLine("s << j;");
|
|
1809
|
-
this.superThis.emitLine("return ", this.superThis.ourQualifier(false), "Utf16_Utf8<std::string, std::wstring>::convert(s.str()); ");
|
|
1810
|
-
});
|
|
1811
|
-
this.superThis.ensureBlankLine();
|
|
1812
|
-
}
|
|
1813
|
-
})(this);
|
|
1814
1780
|
}
|
|
1815
1781
|
exports.CPlusPlusRenderer = CPlusPlusRenderer;
|