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