From 69e8b738c3ce300c55cdfb579b099cf87871107d Mon Sep 17 00:00:00 2001 From: Jan Fellner Date: Tue, 17 Sep 2024 14:53:23 +0200 Subject: [PATCH 1/3] BUILDSYS-446 fix enum to enum typeref creates not needed converter --- compiler/back-ends/ts-gen/gen-ts-code.c | 2 ++ compiler/back-ends/ts-gen/gen-ts-converter.c | 21 ++++++++++++++++++-- compiler/back-ends/ts-gen/gen-ts-converter.h | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/compiler/back-ends/ts-gen/gen-ts-code.c b/compiler/back-ends/ts-gen/gen-ts-code.c index 35000ce..1fb05da 100644 --- a/compiler/back-ends/ts-gen/gen-ts-code.c +++ b/compiler/back-ends/ts-gen/gen-ts-code.c @@ -1244,6 +1244,8 @@ void PrintTSCode(ModuleList* allMods, long longJmpVal, int genTypes, int genValu { if (currMod->ImportedFlag == FALSE) { + if (!ContainsConverters(currMod)) + continue; if (fopen_s(&encdecFilePtr, currMod->tsConverterFileName, "wt") != 0 || encdecFilePtr == NULL) { perror("fopen"); diff --git a/compiler/back-ends/ts-gen/gen-ts-converter.c b/compiler/back-ends/ts-gen/gen-ts-converter.c index 04f552a..ec9514a 100644 --- a/compiler/back-ends/ts-gen/gen-ts-converter.c +++ b/compiler/back-ends/ts-gen/gen-ts-converter.c @@ -1344,8 +1344,7 @@ void PrintTSEncoderDecoderCode(FILE* src, ModuleList* mods, Module* m, TypeDef* // brauchen keinen Encoder Decoder enum BasicTypeChoiceId type = td->type->basicType->choiceId; - - if (!IsSimpleType(type)) + if (!IsSimpleType(type) && ResolveTypeReferencesToRoot(td->type, NULL)->basicType->choiceId != BASICTYPE_ENUMERATED) { fprintf(src, "\n// [%s]\n", __FUNCTION__); fprintf(src, "export class %s_Converter {", szConverted); @@ -1521,6 +1520,24 @@ void PrintTSEncoderDecoderCode(FILE* src, ModuleList* mods, Module* m, TypeDef* free(szConverted); } +bool ContainsConverters(Module* m) +{ + bool bContainsConverters = false; + TypeDef* td; + FOR_EACH_LIST_ELMT(td, m->typeDefs) + { + if (IsDeprecatedNoOutputSequence(m, td->definedName)) + continue; + enum BasicTypeChoiceId type = td->type->basicType->choiceId; + if (!IsSimpleType(type) && ResolveTypeReferencesToRoot(td->type, NULL)->basicType->choiceId != BASICTYPE_ENUMERATED) + { + bContainsConverters = true; + break; + } + } + return bContainsConverters; +} + void PrintTSConverterCode(FILE* src, ModuleList* mods, Module* m, long longJmpVal, int printTypes, int printValues, int printEncoders, int printDecoders, int printTSONEncDec, int novolatilefuncs) { fprintf(src, "// [%s]\n", __FUNCTION__); diff --git a/compiler/back-ends/ts-gen/gen-ts-converter.h b/compiler/back-ends/ts-gen/gen-ts-converter.h index b1b45ca..439de86 100644 --- a/compiler/back-ends/ts-gen/gen-ts-converter.h +++ b/compiler/back-ends/ts-gen/gen-ts-converter.h @@ -9,4 +9,6 @@ void SaveTSConverterFilesToOutputDirectory(const char* szPath); void PrintTSConverterCode(FILE* src, ModuleList* mods, Module* m, long longJmpVal, int printTypes, int printValues, int printEncoders, int printDecoders, int printJSONEncDec, int novolatilefuncs); +bool ContainsConverters(Module* m); + #endif // TSCONVERTER_H_INCLUDED \ No newline at end of file From 4e9adcc0ca2b412dbb0795ce67be3df3ec6da5d6 Mon Sep 17 00:00:00 2001 From: Jan Fellner Date: Tue, 17 Sep 2024 14:53:51 +0200 Subject: [PATCH 2/3] BUILDSYS-446 bumped to 6.0.17 --- version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/version.h b/version.h index 120399a..9eab0df 100644 --- a/version.h +++ b/version.h @@ -1,8 +1,8 @@ #ifndef VERSION_H #define VERSION_H -#define VERSION "6.0.16" -#define VERSION_RC 6, 0, 16 -#define RELDATE "16.09.2024" +#define VERSION "6.0.17" +#define VERSION_RC 6, 0, 17 +#define RELDATE "17.09.2024" #endif // VERSION_H From 6c1100a81c1e25c5701eea5a32dd800be022cb43 Mon Sep 17 00:00:00 2001 From: Jan Fellner Date: Tue, 17 Sep 2024 16:24:11 +0200 Subject: [PATCH 3/3] BUILDSYS-444 Use the enum type instead of number in the type definitions --- compiler/back-ends/ts-gen/gen-ts-code.c | 94 +++++++++++++++---------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/compiler/back-ends/ts-gen/gen-ts-code.c b/compiler/back-ends/ts-gen/gen-ts-code.c index 1fb05da..b004472 100644 --- a/compiler/back-ends/ts-gen/gen-ts-code.c +++ b/compiler/back-ends/ts-gen/gen-ts-code.c @@ -54,6 +54,8 @@ void PrintTSNativeType(FILE* hdr, BasicType* pBasicType) break; case BASICTYPE_INTEGER: case BASICTYPE_REAL: + fprintf(hdr, "number"); + break; case BASICTYPE_ENUMERATED: fprintf(hdr, "number"); break; @@ -97,36 +99,33 @@ void PrintTS_JSON_DefaultValue(FILE* hdr, ModuleList* mods, Module* m, TypeDef* } else { - BasicType* pBasicType = t->basicType; - enum BasicTypeChoiceId choiceId = pBasicType->choiceId; + Type* baset = t; + Module* mod = NULL; + enum BasicTypeChoiceId choiceId = t->basicType->choiceId; if (choiceId == BASICTYPE_IMPORTTYPEREF || choiceId == BASICTYPE_LOCALTYPEREF) { if (strcmp(t->cxxTypeRefInfo->className, "AsnSystemTime") == 0) choiceId = BASICTYPE_UTCTIME; - else if (choiceId == BASICTYPE_IMPORTTYPEREF && t->basicType->a.importTypeRef->link) + else if (t->basicType->choiceId == BASICTYPE_IMPORTTYPEREF) { if (IsSimpleType(t->basicType->a.importTypeRef->link->type->basicType->choiceId)) { - pBasicType = t->basicType->a.importTypeRef->link->type->basicType; - choiceId = pBasicType->choiceId; + mod = GetImportModuleRefByClassName(t->cxxTypeRefInfo->className, mods, m); + t = t->basicType->a.importTypeRef->link->type; + choiceId = t->basicType->choiceId; } } - else if (choiceId == BASICTYPE_LOCALTYPEREF && t->basicType->a.localTypeRef->link) + else if (t->basicType->choiceId == BASICTYPE_LOCALTYPEREF) { if (IsSimpleType(t->basicType->a.localTypeRef->link->type->basicType->choiceId)) { - pBasicType = t->basicType->a.localTypeRef->link->type->basicType; - choiceId = pBasicType->choiceId; + t = t->basicType->a.importTypeRef->link->type; + choiceId = t->basicType->choiceId; } } - else - { - snacc_exit("Invalid parameter, choiceID is %i but the associated link is NULL", choiceId); - return; - } } - if (choiceId == BASICTYPE_OCTETCONTAINING && pBasicType->a.stringContaining->basicType->choiceId == BASICTYPE_UTF8_STR) + if (choiceId == BASICTYPE_OCTETCONTAINING && t->basicType->a.stringContaining->basicType->choiceId == BASICTYPE_UTF8_STR) choiceId = BASICTYPE_UTF8_STR; switch (choiceId) @@ -135,9 +134,14 @@ void PrintTS_JSON_DefaultValue(FILE* hdr, ModuleList* mods, Module* m, TypeDef* fprintf(hdr, "false"); break; case BASICTYPE_INTEGER: - case BASICTYPE_ENUMERATED: fprintf(hdr, "0"); break; + case BASICTYPE_ENUMERATED: + if (mod) + fprintf(hdr, "%s.", mod->moduleName); + ValueDef* e = FIRST_LIST_ELMT(t->basicType->a.enumerated); + fprintf(hdr, "%s.%s", baset->cxxTypeRefInfo->className, e->definedName); + break; case BASICTYPE_OCTETSTRING: case BASICTYPE_OCTETCONTAINING: fprintf(hdr, "new Uint8Array(0)"); @@ -153,7 +157,7 @@ void PrintTS_JSON_DefaultValue(FILE* hdr, ModuleList* mods, Module* m, TypeDef* break; case BASICTYPE_IMPORTTYPEREF: { - Module* mod = GetImportModuleRefByClassName(t->cxxTypeRefInfo->className, mods, m); + mod = GetImportModuleRefByClassName(t->cxxTypeRefInfo->className, mods, m); if (mod) { const char* szNameSpace = GetNameSpace(mod); @@ -206,9 +210,9 @@ void PrintTS_JSON_DefaultValue(FILE* hdr, ModuleList* mods, Module* m, TypeDef* */ void PrintTSType(FILE* hdr, ModuleList* mods, Module* m, TypeDef* td, Type* parent, Type* t) { - BasicType* basicType = t->basicType; - enum BasicTypeChoiceId choiceId = basicType->choiceId; - + Type* baset = t; + Module* mod = NULL; + enum BasicTypeChoiceId choiceId = t->basicType->choiceId; if (choiceId == BASICTYPE_IMPORTTYPEREF || choiceId == BASICTYPE_LOCALTYPEREF) { if (strcmp(t->cxxTypeRefInfo->className, "AsnSystemTime") == 0) @@ -217,56 +221,61 @@ void PrintTSType(FILE* hdr, ModuleList* mods, Module* m, TypeDef* td, Type* pare { if (IsSimpleType(t->basicType->a.importTypeRef->link->type->basicType->choiceId)) { - basicType = t->basicType->a.importTypeRef->link->type->basicType; - choiceId = basicType->choiceId; + mod = GetImportModuleRefByClassName(t->cxxTypeRefInfo->className, mods, m); + t = t->basicType->a.importTypeRef->link->type; + choiceId = t->basicType->choiceId; } } else if (choiceId == BASICTYPE_LOCALTYPEREF) { if (IsSimpleType(t->basicType->a.localTypeRef->link->type->basicType->choiceId)) { - basicType = t->basicType->a.localTypeRef->link->type->basicType; - choiceId = basicType->choiceId; + t = t->basicType->a.importTypeRef->link->type; + choiceId = t->basicType->choiceId; } } } - - if (choiceId == BASICTYPE_OCTETCONTAINING && basicType->a.stringContaining->basicType->choiceId == BASICTYPE_UTF8_STR) + if (choiceId == BASICTYPE_OCTETCONTAINING && t->basicType->a.stringContaining->basicType->choiceId == BASICTYPE_UTF8_STR) choiceId = BASICTYPE_UTF8_STR; + fprintf(hdr, ": "); switch (choiceId) { case BASICTYPE_BOOLEAN: - fprintf(hdr, ": boolean"); + fprintf(hdr, "boolean"); break; case BASICTYPE_INTEGER: case BASICTYPE_REAL: + fprintf(hdr, "number"); + break; case BASICTYPE_ENUMERATED: - fprintf(hdr, ": number"); + if (mod) + fprintf(hdr, "%s.", mod->moduleName); + fprintf(hdr, "%s", baset->cxxTypeRefInfo->className); break; case BASICTYPE_UTF8_STR: - fprintf(hdr, ": string"); + fprintf(hdr, "string"); break; case BASICTYPE_OCTETSTRING: case BASICTYPE_OCTETCONTAINING: - fprintf(hdr, ": Uint8Array"); + fprintf(hdr, "Uint8Array"); break; case BASICTYPE_SEQUENCEOF: - fprintf(hdr, ": %s[]", t->cxxTypeRefInfo->className); + fprintf(hdr, "%s[]", t->cxxTypeRefInfo->className); break; case BASICTYPE_NULL: - fprintf(hdr, ": null"); + fprintf(hdr, "null"); break; case BASICTYPE_UTCTIME: - fprintf(hdr, ": Date"); // AsnSystemTime is defined as REAL in the Asn1 file, but is transmitted as a string in the TS. + fprintf(hdr, "Date"); // AsnSystemTime is defined as REAL in the Asn1 file, but is transmitted as a string in the TS. break; case BASICTYPE_IMPORTTYPEREF: { - Module* mod = GetImportModuleRefByClassName(t->cxxTypeRefInfo->className, mods, m); + mod = GetImportModuleRefByClassName(t->cxxTypeRefInfo->className, mods, m); if (mod) { char* szConverted = FixName(t->cxxTypeRefInfo->className); - fprintf(hdr, ": %s.%s", GetNameSpace(mod), szConverted); + fprintf(hdr, "%s.%s", GetNameSpace(mod), szConverted); free(szConverted); } break; @@ -274,12 +283,12 @@ void PrintTSType(FILE* hdr, ModuleList* mods, Module* m, TypeDef* td, Type* pare case BASICTYPE_LOCALTYPEREF: { char* szConverted = FixName(t->basicType->a.localTypeRef->link->definedName); - fprintf(hdr, ": %s", szConverted); + fprintf(hdr, "%s", szConverted); free(szConverted); break; } case BASICTYPE_ANY: - fprintf(hdr, ": any"); + fprintf(hdr, "any"); break; default: snacc_exit("Unknown choiceId %d", choiceId); @@ -1042,7 +1051,18 @@ void PrintTSCode(ModuleList* allMods, long longJmpVal, int genTypes, int genValu fprintf(typesFile, "export * as %s from \"./%s%s\";\n", varName, szModName, getCommonJSFileExtension()); if (genJSONEncDec) - fprintf(typesFile, "export * as %s_Converter from \"./%s_Converter%s\";\n", varName, szModName, getCommonJSFileExtension()); + { + char szFileName[_MAX_PATH] = {0}; + strcat_s(szFileName, _MAX_PATH - 1, szModName); + strcat_s(szFileName, _MAX_PATH - 1, "_Converter.ts"); + char* szConverterFileName = MakeFileName(szFileName, ""); + FILE* exists = NULL; + if (fopen_s(&exists, szConverterFileName, "r") == 0) + { + fprintf(typesFile, "export * as %s_Converter from \"./%s_Converter%s\";\n", varName, szModName, getCommonJSFileExtension()); + fclose(exists); + } + } free(varName); free(szModName);