Support syntax error feedback in parser.
Now, parser correctly finishes parse procedure if syntax of source code is incorrect (syntax correctness is indicated using return value): - parser-internal memory management is performed using jsp_mm_alloc / jsp_mm_free; - upon detection of incorrect syntax, all parser-allocated memory regions are deallocated using jsp_mm_free_all and parse finishes with corresponding return value. JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
*/
|
||||
|
||||
#include "array-list.h"
|
||||
#include "mem-heap.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
#include "jsp-mm.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -44,14 +44,14 @@ array_list_append (array_list al, void *element)
|
||||
array_list_header *h = extract_header (al);
|
||||
if ((h->len + 1) * h->element_size + sizeof (array_list_header) > h->size)
|
||||
{
|
||||
size_t size = mem_heap_recommend_allocation_size (h->size + h->element_size);
|
||||
size_t size = jsp_mm_recommend_size (h->size + h->element_size);
|
||||
JERRY_ASSERT (size > h->size);
|
||||
|
||||
uint8_t* new_block_p = (uint8_t*) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
uint8_t *new_block_p = (uint8_t *) jsp_mm_alloc (size);
|
||||
memcpy (new_block_p, h, h->size);
|
||||
memset (new_block_p + h->size, 0, size - h->size);
|
||||
|
||||
mem_heap_free_block ((uint8_t *) h);
|
||||
jsp_mm_free (h);
|
||||
|
||||
h = (array_list_header *) new_block_p;
|
||||
h->size = size;
|
||||
@@ -111,8 +111,8 @@ array_list_set_last_element (array_list al, size_t index, void *elem)
|
||||
array_list
|
||||
array_list_init (uint8_t element_size)
|
||||
{
|
||||
size_t size = mem_heap_recommend_allocation_size (sizeof (array_list_header));
|
||||
array_list_header *header = (array_list_header *) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
size_t size = jsp_mm_recommend_size (sizeof (array_list_header));
|
||||
array_list_header *header = (array_list_header *) jsp_mm_alloc (size);
|
||||
memset (header, 0, size);
|
||||
header->element_size = element_size;
|
||||
header->len = 0;
|
||||
@@ -131,5 +131,5 @@ void
|
||||
array_list_free (array_list al)
|
||||
{
|
||||
array_list_header *h = extract_header (al);
|
||||
mem_heap_free_block ((uint8_t *) h);
|
||||
jsp_mm_free (h);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "hash-table.h"
|
||||
#include "array-list.h"
|
||||
#include "mem-heap.h"
|
||||
#include "hash-table.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
#include "jsp-mm.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -25,7 +25,6 @@ typedef struct
|
||||
uint16_t size;
|
||||
uint8_t key_size;
|
||||
uint8_t value_size;
|
||||
mem_heap_alloc_term_t alloc_term;
|
||||
} hash_table_int;
|
||||
|
||||
static hash_table_int *
|
||||
@@ -65,12 +64,12 @@ hash_table_insert (hash_table ht, void *key, void *value)
|
||||
{
|
||||
list = array_list_init (bucket_size (hti));
|
||||
}
|
||||
uint8_t *bucket = (uint8_t*) mem_heap_alloc_block (bucket_size (hti), hti->alloc_term);
|
||||
uint8_t *bucket = (uint8_t *) jsp_mm_alloc (bucket_size (hti));
|
||||
memcpy (bucket, key, hti->key_size);
|
||||
memcpy (bucket + hti->key_size, value, hti->value_size);
|
||||
list = array_list_append (list, bucket);
|
||||
hti->data[index] = list;
|
||||
mem_heap_free_block (bucket);
|
||||
jsp_mm_free (bucket);
|
||||
}
|
||||
|
||||
void *
|
||||
@@ -98,15 +97,14 @@ hash_table_lookup (hash_table ht, void *key)
|
||||
|
||||
hash_table
|
||||
hash_table_init (uint8_t key_size, uint8_t value_size, uint16_t size,
|
||||
uint16_t (*hash) (void *), mem_heap_alloc_term_t alloc_term)
|
||||
uint16_t (*hash) (void *))
|
||||
{
|
||||
hash_table_int *res = (hash_table_int *) mem_heap_alloc_block (sizeof (hash_table_int), alloc_term);
|
||||
hash_table_int *res = (hash_table_int *) jsp_mm_alloc (sizeof (hash_table_int));
|
||||
memset (res, 0, sizeof (hash_table_int));
|
||||
res->key_size = key_size;
|
||||
res->value_size = value_size;
|
||||
res->size = size;
|
||||
res->alloc_term = alloc_term;
|
||||
res->data = (array_list *) mem_heap_alloc_block (size * sizeof (array_list), alloc_term);
|
||||
res->data = (array_list *) jsp_mm_alloc (size * sizeof (array_list));
|
||||
memset (res->data, 0, size * sizeof (array_list));
|
||||
res->hash = hash;
|
||||
return res;
|
||||
@@ -125,6 +123,6 @@ hash_table_free (hash_table ht)
|
||||
set_list (h, i, null_list);
|
||||
}
|
||||
}
|
||||
mem_heap_free_block ((uint8_t *) h->data);
|
||||
mem_heap_free_block ((uint8_t *) h);
|
||||
jsp_mm_free (h->data);
|
||||
jsp_mm_free (h);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
typedef void* hash_table;
|
||||
#define null_hash NULL
|
||||
|
||||
hash_table hash_table_init (uint8_t, uint8_t, uint16_t, uint16_t (*hash) (void *), mem_heap_alloc_term_t);
|
||||
hash_table hash_table_init (uint8_t, uint8_t, uint16_t, uint16_t (*hash) (void *));
|
||||
void hash_table_free (hash_table);
|
||||
void hash_table_insert (hash_table, void *, void *);
|
||||
void *hash_table_lookup (hash_table, void *);
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "linked-list.h"
|
||||
#include "jrt-libc-includes.h"
|
||||
#include "mem-heap.h"
|
||||
#include "jsp-mm.h"
|
||||
#include "linked-list.h"
|
||||
|
||||
typedef struct linked_list_header
|
||||
{
|
||||
@@ -31,14 +31,14 @@ do { \
|
||||
|
||||
static size_t linked_list_block_size (uint16_t element_size)
|
||||
{
|
||||
return mem_heap_recommend_allocation_size (sizeof (linked_list_header) + element_size) - sizeof (linked_list_header);
|
||||
return jsp_mm_recommend_size (sizeof (linked_list_header) + element_size) - sizeof (linked_list_header);
|
||||
}
|
||||
|
||||
linked_list
|
||||
linked_list_init (uint16_t element_size)
|
||||
{
|
||||
size_t size = sizeof (linked_list_header) + linked_list_block_size (element_size);
|
||||
linked_list list = (linked_list) mem_heap_alloc_block (size, MEM_HEAP_ALLOC_SHORT_TERM);
|
||||
linked_list list = (linked_list) jsp_mm_alloc (size);
|
||||
if (list == null_list)
|
||||
{
|
||||
printf ("Out of memory");
|
||||
@@ -60,7 +60,7 @@ linked_list_free (linked_list list)
|
||||
{
|
||||
linked_list_free ((linked_list) header->next);
|
||||
}
|
||||
mem_heap_free_block (list);
|
||||
jsp_mm_free (list);
|
||||
}
|
||||
|
||||
void *
|
||||
|
||||
Reference in New Issue
Block a user