Commit 2a2a977d authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Removed unnecessary null pointer checks from JSON codecs


Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
Change-Id: I90d39b55248d6f1232fde6ef0b1939f327007b90
parent b122e31e
......@@ -3242,7 +3242,7 @@ char* generate_json_decoder(char* src, const struct_def* sdef)
if (sdef->nElements == 1) {
if (!sdef->jsonAsValue) {
src = mputstr(src, " if (NULL != p_td.json && p_td.json->as_value) {\n");
src = mputstr(src, " if (p_td.json->as_value) {\n");
}
if (sdef->elements[0].isOptional) {
// can only happen if the record has the 'JSON:object' attribute;
......@@ -4808,7 +4808,7 @@ void defRecordClass1(const struct_def *sdef, output_struct *output)
((sdef->nElements == 1 && !sdef->jsonAsValue) || sdef->jsonAsMapPossible) ? " p_td" : "", dispname);
if (sdef->nElements == 1) {
if (!sdef->jsonAsValue) {
src = mputstr(src, " if (NULL != p_td.json && p_td.json->as_value) {\n");
src = mputstr(src, " if (p_td.json->as_value) {\n");
}
if (sdef->elements[0].isOptional) {
// can only happen if the record has the 'JSON:object' attribute;
......
......@@ -1548,7 +1548,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
" int enc_len = p_tok.put_next_token(p_td.json->as_map ? "
"JSON_TOKEN_OBJECT_START : JSON_TOKEN_ARRAY_START, NULL);\n"
" for (int i = 0; i < val_ptr->n_elements; ++i) {\n"
" if (NULL != p_td.json && p_td.json->metainfo_unbound && !(*this)[i].is_bound()) {\n"
" if (p_td.json->metainfo_unbound && !(*this)[i].is_bound()) {\n"
// unbound elements are encoded as { "metainfo []" : "unbound" }
" enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);\n"
" enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, \"metainfo []\");\n"
......@@ -1591,7 +1591,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output)
" for (int nof_elements = 0; TRUE; ++nof_elements) {\n"
" size_t buf_pos = p_tok.get_buf_pos();\n"
" size_t ret_val;\n"
" if (NULL != p_td.json && p_td.json->metainfo_unbound) {\n"
" if (p_td.json->metainfo_unbound) {\n"
// check for metainfo object
" ret_val = p_tok.get_next_token(&token, NULL, NULL);\n"
" if (JSON_TOKEN_OBJECT_START == token) {\n"
......@@ -3067,7 +3067,7 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
" }\n\n"
" int enc_len = p_tok.put_next_token(JSON_TOKEN_ARRAY_START, NULL);\n"
" for (int i = 0; i < n_elements; ++i) {\n"
" if (NULL != p_td.json && p_td.json->metainfo_unbound && !value_elements[i].is_bound()) {\n"
" if (p_td.json->metainfo_unbound && !value_elements[i].is_bound()) {\n"
// unbound elements are encoded as { "metainfo []" : "unbound" }
" enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);\n"
" enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, \"metainfo []\");\n"
......@@ -3102,7 +3102,7 @@ void defRecordOfClassMemAllocOptimized(const struct_of_def *sdef, output_struct
" for (int nof_elements = 0; TRUE; ++nof_elements) {\n"
" size_t buf_pos = p_tok.get_buf_pos();\n"
" size_t ret_val;\n"
" if (NULL != p_td.json && p_td.json->metainfo_unbound) {\n"
" if (p_td.json->metainfo_unbound) {\n"
// check for metainfo object
" ret_val = p_tok.get_next_token(&token, NULL, NULL);\n"
" if (JSON_TOKEN_OBJECT_START == token) {\n"
......
......@@ -2050,7 +2050,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
// 'as value' is not set for the base type, but it might still be set in
// the type descriptor
src = mputstr(src,
" boolean as_value = NULL != p_td.json && p_td.json->as_value;\n"
" boolean as_value = p_td.json->as_value;\n"
" int enc_len = as_value ? 0 : "
"p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);\n");
} else {
......@@ -2112,7 +2112,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
// 'as value' is not set for the base type, but it might still be set in
// the type descriptor
src = mputstr(src,
" boolean as_value = NULL != p_td.json && p_td.json->as_value;\n"
" boolean as_value = p_td.json->as_value;\n"
" int enc_len = as_value ? 0 : "
"p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);\n");
} else {
......@@ -2217,7 +2217,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
" json_token_t j_token = JSON_TOKEN_NONE;\n");
if (!sdef->jsonAsValue) {
src = mputstr(src,
" if (NULL != p_td.json && p_td.json->as_value) {\n");
" if (p_td.json->as_value) {\n");
}
src = mputstr(src,
" size_t buf_pos = p_tok.get_buf_pos();\n"
......
......@@ -1366,7 +1366,7 @@ int VALUE_ARRAY<T_type,array_size,index_offset>::JSON_encode(
int enc_len = p_tok.put_next_token(JSON_TOKEN_ARRAY_START, NULL);
for (unsigned int i = 0; i < array_size; ++i) {
if (NULL != p_td.json && p_td.json->metainfo_unbound && !array_elements[i].is_bound()) {
if (p_td.json->metainfo_unbound && !array_elements[i].is_bound()) {
// unbound elements are encoded as { "metainfo []" : "unbound" }
enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);
enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "metainfo []");
......@@ -1401,7 +1401,7 @@ int VALUE_ARRAY<T_type,array_size,index_offset>::JSON_decode(
for (unsigned int i = 0; i < array_size; ++i) {
size_t buf_pos = p_tok.get_buf_pos();
size_t ret_val;
if (NULL != p_td.json && p_td.json->metainfo_unbound) {
if (p_td.json->metainfo_unbound) {
// check for metainfo object
ret_val = p_tok.get_next_token(&token, NULL, NULL);
if (JSON_TOKEN_OBJECT_START == token) {
......
......@@ -1481,7 +1481,7 @@ int Record_Of_Type::JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenize
JSON_TOKEN_ARRAY_START, NULL);
for (int i = 0; i < get_nof_elements(); ++i) {
if (NULL != p_td.json && p_td.json->metainfo_unbound && !get_at(i)->is_bound()) {
if (p_td.json->metainfo_unbound && !get_at(i)->is_bound()) {
// unbound elements are encoded as { "metainfo []" : "unbound" }
enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);
enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "metainfo []");
......@@ -1550,7 +1550,7 @@ int Record_Of_Type::JSON_encode_negtest(const Erroneous_descriptor_t* p_err_desc
}
}
}
else if (NULL != p_td.json && p_td.json->metainfo_unbound && !get_at(i)->is_bound()) {
else if (p_td.json->metainfo_unbound && !get_at(i)->is_bound()) {
// unbound elements are encoded as { "metainfo []" : "unbound" }
enc_len += p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);
enc_len += p_tok.put_next_token(JSON_TOKEN_NAME, "metainfo []");
......@@ -1616,7 +1616,7 @@ int Record_Of_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenize
for (int nof_elements = 0; TRUE; ++nof_elements) {
// Read value tokens until we reach some other token
size_t buf_pos = p_tok.get_buf_pos();
if (NULL != p_td.json && p_td.json->metainfo_unbound) {
if (p_td.json->metainfo_unbound) {
// check for metainfo object
size_t ret_val = p_tok.get_next_token(&token, NULL, NULL);
if (JSON_TOKEN_OBJECT_START == token) {
......@@ -5975,7 +5975,7 @@ int Record_Type::JSON_encode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer&
return -1;
}
if (NULL != p_td.json && p_td.json->as_value) {
if (p_td.json->as_value) {
if (get_at(0)->is_optional()) {
// can only happen if the record has the 'JSON:object' attribute;
// in this case 'omit' is the same as if the field was an empty record of
......@@ -6042,7 +6042,7 @@ int Record_Type::JSON_encode_negtest(const Erroneous_descriptor_t* p_err_descr,
return -1;
}
boolean as_value = NULL != p_td.json && p_td.json->as_value;
boolean as_value = p_td.json->as_value;
int enc_len = (as_value || p_parent_is_map) ? 0 : p_tok.put_next_token(JSON_TOKEN_OBJECT_START, NULL);
......@@ -6186,7 +6186,7 @@ int Record_Type::JSON_encode_negtest(const Erroneous_descriptor_t* p_err_descr,
int Record_Type::JSON_decode(const TTCN_Typedescriptor_t& p_td, JSON_Tokenizer& p_tok,
boolean p_silent, boolean p_parent_is_map, int)
{
if (NULL != p_td.json && p_td.json->as_value) {
if (p_td.json->as_value) {
if (get_at(0)->is_optional()) {
// can only happen if the record has the 'JSON:object' attribute;
// in this case the optional class must not be allowed to decode the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment