Remove unused internal functions
The internals have surprisingly large number of unused functions at surprising places. This patch cleans them out to make maintenance easier and to prevent dead code having effect on future decisions. The patch intentionally does not try to clean up public API but focuses on internal modules only that are/should not be reachable from "outside". However, unit tests do access private API, thus tests of literal storage had to be adjusted. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
@@ -266,264 +266,6 @@ lit_find_literal_by_num (const ecma_number_t num) /**< a number to search for */
|
||||
return NULL;
|
||||
} /* lit_find_literal_by_num */
|
||||
|
||||
/**
|
||||
* Check if literal equals to charset record
|
||||
*
|
||||
* @return true if is_equal
|
||||
* false otherwise
|
||||
*/
|
||||
static bool
|
||||
lit_literal_equal_charset_rec (lit_literal_t lit, /**< literal to compare */
|
||||
lit_literal_t record) /**< charset record to compare */
|
||||
{
|
||||
switch (lit->type)
|
||||
{
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
return lit_literal_equal_charset (lit,
|
||||
lit_charset_literal_get_charset (record),
|
||||
lit_charset_literal_get_size (record));
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
lit_magic_string_id_t magic_string_id = lit_magic_literal_get_magic_str_id (lit);
|
||||
return lit_literal_equal_charset (record,
|
||||
lit_get_magic_string_utf8 (magic_string_id),
|
||||
lit_get_magic_string_size (magic_string_id));
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
lit_magic_string_ex_id_t magic_string_id = lit_magic_literal_get_magic_str_ex_id (lit);
|
||||
|
||||
return lit_literal_equal_charset (record,
|
||||
lit_get_magic_string_ex_utf8 (magic_string_id),
|
||||
lit_get_magic_string_ex_size (magic_string_id));
|
||||
}
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t num = lit_number_literal_get_number (lit);
|
||||
|
||||
lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
lit_utf8_size_t copied = ecma_number_to_utf8_string (num, buff, sizeof (buff));
|
||||
|
||||
return lit_literal_equal_charset (record, buff, copied);
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} /* lit_literal_equal_charset_rec */
|
||||
|
||||
/**
|
||||
* Check if literal equals to utf-8 string
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_utf8 (lit_literal_t lit, /**< literal to compare */
|
||||
const lit_utf8_byte_t *str_p, /**< utf-8 string to compare */
|
||||
lit_utf8_size_t str_size) /**< string size in bytes */
|
||||
{
|
||||
switch (lit->type)
|
||||
{
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
if (lit_charset_literal_get_size (lit) != str_size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return !strncmp ((const char *) lit_charset_literal_get_charset (lit), (const char *) str_p, str_size);
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
lit_magic_string_id_t magic_id = lit_magic_literal_get_magic_str_id (lit);
|
||||
return lit_compare_utf8_string_and_magic_string (str_p, str_size, magic_id);
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
lit_magic_string_ex_id_t magic_id = lit_magic_literal_get_magic_str_ex_id (lit);
|
||||
return lit_compare_utf8_string_and_magic_string_ex (str_p, str_size, magic_id);
|
||||
}
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t num = lit_number_literal_get_number (lit);
|
||||
|
||||
lit_utf8_byte_t num_buf[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
lit_utf8_size_t num_size = ecma_number_to_utf8_string (num, num_buf, sizeof (num_buf));
|
||||
|
||||
return lit_compare_utf8_strings (str_p, str_size, num_buf, num_size);
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
}
|
||||
}
|
||||
} /* lit_literal_equal_utf8 */
|
||||
|
||||
/**
|
||||
* Check if literal contains the string equal to the passed number
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_num (lit_literal_t lit, /**< literal to check */
|
||||
ecma_number_t num) /**< number to compare with */
|
||||
{
|
||||
lit_utf8_byte_t buff[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER];
|
||||
lit_utf8_size_t copied = ecma_number_to_utf8_string (num, buff, sizeof (buff));
|
||||
|
||||
return lit_literal_equal_utf8 (lit, buff, copied);
|
||||
} /* lit_literal_equal_num */
|
||||
|
||||
|
||||
/**
|
||||
* Check if literal contains the string equal to the buffer
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_charset (lit_literal_t lit, /**< literal to checks */
|
||||
const lit_utf8_byte_t *buff, /**< string buffer */
|
||||
lit_utf8_size_t size) /**< buffer size */
|
||||
{
|
||||
JERRY_ASSERT (lit->type == LIT_RECORD_TYPE_CHARSET);
|
||||
|
||||
if (size != lit_charset_literal_get_size (lit))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return !strncmp ((const char *) buff, (const char *) lit_charset_literal_get_charset (lit), size);
|
||||
} /* lit_literal_equal_charset */
|
||||
|
||||
|
||||
/**
|
||||
* Check if two literals are equal
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal (lit_literal_t lit1, /**< first literal */
|
||||
lit_literal_t lit2) /**< second literal */
|
||||
{
|
||||
switch (lit2->type)
|
||||
{
|
||||
case LIT_RECORD_TYPE_CHARSET:
|
||||
{
|
||||
return lit_literal_equal_charset_rec (lit1, lit2);
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR:
|
||||
{
|
||||
lit_magic_string_id_t magic_str_id = lit_magic_literal_get_magic_str_id (lit2);
|
||||
|
||||
return lit_literal_equal_utf8 (lit1,
|
||||
lit_get_magic_string_utf8 (magic_str_id),
|
||||
lit_get_magic_string_size (magic_str_id));
|
||||
}
|
||||
case LIT_RECORD_TYPE_MAGIC_STR_EX:
|
||||
{
|
||||
lit_magic_string_ex_id_t magic_str_ex_id = lit_magic_literal_get_magic_str_ex_id (lit2);
|
||||
|
||||
return lit_literal_equal_utf8 (lit1,
|
||||
lit_get_magic_string_ex_utf8 (magic_str_ex_id),
|
||||
lit_get_magic_string_ex_size (magic_str_ex_id));
|
||||
}
|
||||
case LIT_RECORD_TYPE_NUMBER:
|
||||
{
|
||||
ecma_number_t num = lit_number_literal_get_number (lit2);
|
||||
return lit_literal_equal_num (lit1, num);
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_UNREACHABLE ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JERRY_UNREACHABLE ();
|
||||
return 0;
|
||||
} /* lit_literal_equal */
|
||||
|
||||
/**
|
||||
* Check if literal equals to utf-8 string.
|
||||
* Check that literal is a string literal before performing detailed comparison.
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_type_utf8 (lit_literal_t lit, /**< literal to compare */
|
||||
const lit_utf8_byte_t *str_p, /**< utf-8 string */
|
||||
lit_utf8_size_t str_size) /**< string size */
|
||||
{
|
||||
const lit_record_type_t type = (const lit_record_type_t) lit->type;
|
||||
|
||||
if (type == LIT_RECORD_TYPE_NUMBER || type == LIT_RECORD_TYPE_FREE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return lit_literal_equal_utf8 (lit, str_p, str_size);
|
||||
} /* lit_literal_equal_type_utf8 */
|
||||
|
||||
/**
|
||||
* Check if literal equals to C string.
|
||||
* Check that literal is a string literal before performing detailed comparison.
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_type_cstr (lit_literal_t lit, /**< literal to compare */
|
||||
const char *c_str_p) /**< zero-terminated C-string */
|
||||
{
|
||||
return lit_literal_equal_type_utf8 (lit, (const lit_utf8_byte_t *) c_str_p, (lit_utf8_size_t) strlen (c_str_p));
|
||||
} /* lit_literal_equal_type_cstr */
|
||||
|
||||
/**
|
||||
* Check if literal contains the string equal to the passed number.
|
||||
* Check that literal is a number literal before performing detailed comparison.
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_type_num (lit_literal_t lit, /**< literal to check */
|
||||
ecma_number_t num) /**< number to compare with */
|
||||
{
|
||||
if (lit->type != LIT_RECORD_TYPE_NUMBER)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return lit_literal_equal_num (lit, num);
|
||||
} /* lit_literal_equal_type_num */
|
||||
|
||||
/**
|
||||
* Check if two literals are equal
|
||||
* Compare types of literals before performing detailed comparison.
|
||||
*
|
||||
* @return true if equal
|
||||
* false otherwise
|
||||
*/
|
||||
bool
|
||||
lit_literal_equal_type (lit_literal_t lit1, /**< first literal */
|
||||
lit_literal_t lit2) /**< second literal */
|
||||
{
|
||||
if (lit1->type != lit2->type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return lit_literal_equal (lit1, lit2);
|
||||
} /* lit_literal_equal_type */
|
||||
|
||||
/**
|
||||
* Check if literal really exists in the storage
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user