[C][Client] Define and initialize non-primitive variables at the beginning of function (#10756)

This commit is contained in:
Hui Yu 2021-11-05 10:51:57 +08:00 committed by GitHub
parent 40018c333d
commit 369133a03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -527,6 +527,17 @@ fail:
{{classname}}_t *{{classname}}_local_var = NULL;
{{#vars}}
{{^isPrimitiveType}}
{{#isModel}}
{{^isEnum}}
// define the local variable for {{{classname}}}->{{{name}}}
{{^isFreeFormObject}}{{complexType}}{{/isFreeFormObject}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_t *{{name}}_local_nonprim = NULL;
{{/isEnum}}
{{/isModel}}
{{/isPrimitiveType}}
{{/vars}}
{{#vars}}
// {{{classname}}}->{{{name}}}
cJSON *{{{name}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
@ -614,7 +625,6 @@ fail:
{{{name}}}_local_nonprim_enum = {{datatypeWithEnum}}_parseFromJSON({{{name}}}); //enum model
{{/isEnum}}
{{^isEnum}}
{{^isFreeFormObject}}{{complexType}}{{/isFreeFormObject}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_t *{{name}}_local_nonprim = NULL;
{{^required}}if ({{{name}}}) { {{/required}}
{{{name}}}_local_nonprim = {{complexType}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_parseFromJSON({{{name}}}); //nonprimitive
{{/isEnum}}

View File

@ -168,6 +168,9 @@ pet_t *pet_parseFromJSON(cJSON *petJSON){
pet_t *pet_local_var = NULL;
// define the local variable for pet->category
category_t *category_local_nonprim = NULL;
// pet->id
cJSON *id = cJSON_GetObjectItemCaseSensitive(petJSON, "id");
if (id) {
@ -179,7 +182,6 @@ pet_t *pet_parseFromJSON(cJSON *petJSON){
// pet->category
cJSON *category = cJSON_GetObjectItemCaseSensitive(petJSON, "category");
category_t *category_local_nonprim = NULL;
if (category) {
category_local_nonprim = category_parseFromJSON(category); //nonprimitive
}