Преглед изворни кода

ncd: NCDAst: remove unused NCDValue functions

ambrop7 пре 13 година
родитељ
комит
0ce0fa9264
2 измењених фајлова са 1 додато и 470 уклоњено
  1. 1 302
      ncd/NCDAst.c
  2. 0 168
      ncd/NCDAst.h

+ 1 - 302
ncd/NCDAst.c

@@ -29,7 +29,6 @@
 
 #include <stdlib.h>
 #include <limits.h>
-#include <stdarg.h>
 #include <string.h>
 
 #include <misc/offset.h>
@@ -63,80 +62,6 @@ static void value_assert (NCDValue *o)
     }
 }
 
-int NCDValue_InitCopy (NCDValue *o, NCDValue *v)
-{
-    value_assert(v);
-    
-    switch (v->type) {
-        case NCDVALUE_STRING: {
-            return NCDValue_InitStringBin(o, v->string, v->string_len);
-        } break;
-        
-        case NCDVALUE_LIST: {
-            NCDValue_InitList(o);
-            
-            for (LinkedList1Node *n = LinkedList1_GetFirst(&v->list); n; n = LinkedList1Node_Next(n)) {
-                struct NCDValue__list_element *e = UPPER_OBJECT(n, struct NCDValue__list_element, list_node);
-                
-                NCDValue tmp;
-                if (!NCDValue_InitCopy(&tmp, &e->v)) {
-                    goto fail;
-                }
-                
-                if (!NCDValue_ListAppend(o, tmp)) {
-                    NCDValue_Free(&tmp);
-                    goto fail;
-                }
-            }
-            
-            return 1;
-            
-        fail:
-            NCDValue_Free(o);
-            return 0;
-        } break;
-        
-        case NCDVALUE_MAP: {
-            NCDValue_InitMap(o);
-            
-            for (NCDValue *ekey = NCDValue_MapFirstKey(v); ekey; ekey = NCDValue_MapNextKey(v, ekey)) {
-                NCDValue *eval = NCDValue_MapKeyValue(v, ekey);
-                
-                NCDValue tmp_key;
-                NCDValue tmp_val;
-                if (!NCDValue_InitCopy(&tmp_key, ekey)) {
-                    goto mapfail;
-                }
-                if (!NCDValue_InitCopy(&tmp_val, eval)) {
-                    NCDValue_Free(&tmp_key);
-                    goto mapfail;
-                }
-                
-                if (!NCDValue_MapInsert(o, tmp_key, tmp_val)) {
-                    NCDValue_Free(&tmp_key);
-                    NCDValue_Free(&tmp_val);
-                    goto mapfail;
-                }
-            }
-            
-            return 1;
-            
-        mapfail:
-            NCDValue_Free(o);
-            return 0;
-        } break;
-        
-        case NCDVALUE_VAR: {
-            return NCDValue_InitVar(o, v->var_name);
-        } break;
-        
-        default:
-            ASSERT(0);
-    }
-    
-    return 0;
-}
-
 void NCDValue_Free (NCDValue *o)
 {
     switch (o->type) {
@@ -181,18 +106,6 @@ int NCDValue_Type (NCDValue *o)
     return o->type;
 }
 
-int NCDValue_IsString (NCDValue *o)
-{
-    value_assert(o);
-    
-    return o->type == NCDVALUE_STRING;
-}
-
-int NCDValue_IsStringNoNulls (NCDValue *o)
-{
-    return NCDValue_IsString(o) && NCDValue_StringHasNoNulls(o);
-}
-
 int NCDValue_InitString (NCDValue *o, const char *str)
 {
     return NCDValue_InitStringBin(o, (const uint8_t *)str, strlen(str));
@@ -231,34 +144,6 @@ size_t NCDValue_StringLength (NCDValue *o)
     return o->string_len;
 }
 
-int NCDValue_StringHasNoNulls (NCDValue *o)
-{
-    ASSERT(o->type == NCDVALUE_STRING)
-    
-    return strlen((char *)o->string) == o->string_len;
-}
-
-int NCDValue_StringHasNulls (NCDValue *o)
-{
-    ASSERT(o->type == NCDVALUE_STRING)
-    
-    return !NCDValue_StringHasNoNulls(o);
-}
-
-int NCDValue_StringEquals (NCDValue *o, const char *str)
-{
-    ASSERT(o->type == NCDVALUE_STRING)
-    
-    return NCDValue_StringHasNoNulls(o) && !strcmp((const char *)o->string, str);
-}
-
-int NCDValue_IsList (NCDValue *o)
-{
-    value_assert(o);
-    
-    return o->type == NCDVALUE_LIST;
-}
-
 void NCDValue_InitList (NCDValue *o)
 {
     LinkedList1_Init(&o->list);
@@ -311,29 +196,6 @@ int NCDValue_ListPrepend (NCDValue *o, NCDValue v)
     return 1;
 }
 
-int NCDValue_ListAppendList (NCDValue *o, NCDValue l)
-{
-    value_assert(o);
-    value_assert(&l);
-    ASSERT(o->type == NCDVALUE_LIST)
-    ASSERT(l.type == NCDVALUE_LIST)
-    
-    if (l.list_count > SIZE_MAX - o->list_count) {
-        return 0;
-    }
-    
-    LinkedList1Node *n;
-    while (n = LinkedList1_GetFirst(&l.list)) {
-        struct NCDValue__list_element *e = UPPER_OBJECT(n, struct NCDValue__list_element, list_node);
-        LinkedList1_Remove(&l.list, &e->list_node);
-        LinkedList1_Append(&o->list, &e->list_node);
-    }
-    
-    o->list_count += l.list_count;
-    
-    return 1;
-}
-
 size_t NCDValue_ListCount (NCDValue *o)
 {
     value_assert(o);
@@ -375,121 +237,6 @@ NCDValue * NCDValue_ListNext (NCDValue *o, NCDValue *ev)
     return &e->v;
 }
 
-int NCDValue_ListRead (NCDValue *o, int num, ...)
-{
-    value_assert(o);
-    ASSERT(o->type == NCDVALUE_LIST)
-    ASSERT(num >= 0)
-    
-    if (num != NCDValue_ListCount(o)) {
-        return 0;
-    }
-    
-    va_list ap;
-    va_start(ap, num);
-    
-    for (LinkedList1Node *n = LinkedList1_GetFirst(&o->list); n; n = LinkedList1Node_Next(n)) {
-        struct NCDValue__list_element *e = UPPER_OBJECT(n, struct NCDValue__list_element, list_node);
-        
-        NCDValue **dest = va_arg(ap, NCDValue **);
-        *dest = &e->v;
-    }
-    
-    va_end(ap);
-    
-    return 1;
-}
-
-int NCDValue_ListReadHead (NCDValue *o, int num, ...)
-{
-    value_assert(o);
-    ASSERT(o->type == NCDVALUE_LIST)
-    ASSERT(num >= 0)
-    
-    if (num > NCDValue_ListCount(o)) {
-        return 0;
-    }
-    
-    va_list ap;
-    va_start(ap, num);
-    
-    LinkedList1Node *n = LinkedList1_GetFirst(&o->list);
-    while (num > 0) {
-        ASSERT(n)
-        struct NCDValue__list_element *e = UPPER_OBJECT(n, struct NCDValue__list_element, list_node);
-        
-        NCDValue **dest = va_arg(ap, NCDValue **);
-        *dest = &e->v;
-        
-        n = LinkedList1Node_Next(n);
-        num--;
-    }
-    
-    va_end(ap);
-    
-    return 1;
-}
-
-NCDValue * NCDValue_ListGet (NCDValue *o, size_t pos)
-{
-    value_assert(o);
-    ASSERT(o->type == NCDVALUE_LIST)
-    ASSERT(pos < o->list_count)
-    
-    NCDValue *e = NCDValue_ListFirst(o);
-    while (e) {
-        if (pos == 0) {
-            break;
-        }
-        pos--;
-        e = NCDValue_ListNext(o, e);
-    }
-    ASSERT(e)
-    
-    return e;
-}
-
-NCDValue NCDValue_ListShift (NCDValue *o)
-{
-    value_assert(o);
-    ASSERT(o->type == NCDVALUE_LIST)
-    ASSERT(o->list_count > 0)
-    
-    struct NCDValue__list_element *e = UPPER_OBJECT(LinkedList1_GetFirst(&o->list), struct NCDValue__list_element, list_node);
-    
-    NCDValue v = e->v;
-    
-    LinkedList1_Remove(&o->list, &e->list_node);
-    o->list_count--;
-    free(e);
-    
-    return v;
-}
-
-NCDValue NCDValue_ListRemove (NCDValue *o, NCDValue *ev)
-{
-    value_assert(o);
-    ASSERT(o->type == NCDVALUE_LIST)
-    ASSERT(o->list_count > 0)
-    
-    struct NCDValue__list_element *e = UPPER_OBJECT(ev, struct NCDValue__list_element, v);
-    
-    NCDValue v = e->v;
-    
-    LinkedList1_Remove(&o->list, &e->list_node);
-    o->list_count--;
-    free(e);
-    
-    return v;
-}
-
-int NCDValue_IsMap (NCDValue *o)
-{
-    value_assert(o);
-    
-    return o->type == NCDVALUE_MAP;
-}
-
 void NCDValue_InitMap (NCDValue *o)
 {
     o->type = NCDVALUE_MAP;
@@ -598,54 +345,6 @@ NCDValue * NCDValue_MapInsert (NCDValue *o, NCDValue key, NCDValue val)
     return &e->key;
 }
 
-void NCDValue_MapRemove (NCDValue *o, NCDValue *ekey, NCDValue *out_key, NCDValue *out_val)
-{
-    value_assert(o);
-    ASSERT(o->type == NCDVALUE_MAP)
-    ASSERT(out_key)
-    ASSERT(out_val)
-    ASSERT(o->map_count > 0)
-    
-    struct NCDValue__map_element *e = UPPER_OBJECT(ekey, struct NCDValue__map_element, key);
-    value_assert(&e->key);
-    value_assert(&e->val);
-    
-    NCDValue__MapTree_Remove(&o->map_tree, 0, e);
-    
-    *out_key = e->key;
-    *out_val = e->val;
-    
-    o->map_count--;
-    
-    free(e);
-}
-
-NCDValue * NCDValue_MapFindValueByString (NCDValue *o, const char *key_str)
-{
-    value_assert(o);
-    ASSERT(o->type == NCDVALUE_MAP)
-    ASSERT(key_str)
-    
-    NCDValue key;
-    key.type = NCDVALUE_STRING;
-    key.string = (uint8_t *)key_str;
-    key.string_len = strlen(key_str);
-    
-    NCDValue *ekey = NCDValue_MapFindKey(o, &key);
-    if (!ekey) {
-        return NULL;
-    }
-    
-    return NCDValue_MapKeyValue(o, ekey);
-}
-
-int NCDValue_IsVar (NCDValue *o)
-{
-    value_assert(o);
-    
-    return o->type == NCDVALUE_VAR;
-}
-
 int NCDValue_InitVar (NCDValue *o, const char *var_name)
 {
     ASSERT(var_name)
@@ -961,7 +660,7 @@ size_t NCDBlock_NumStatements (NCDBlock *o)
 int NCDStatement_InitReg (NCDStatement *o, const char *name, const char *objname, const char *cmdname, NCDValue args)
 {
     ASSERT(cmdname)
-    ASSERT(NCDValue_IsList(&args))
+    ASSERT(NCDValue_Type(&args) == NCDVALUE_LIST)
     
     o->name = NULL;
     o->reg.objname = NULL;

+ 0 - 168
ncd/NCDAst.h

@@ -147,15 +147,6 @@ struct IfBlockIf {
 #define NCDSTATEMENT_IF 2
 #define NCDSTATEMENT_FOREACH 3
 
-/**
- * Initializes a value by copying an existing value.
- * 
- * @param o value structure to initialize
- * @param v an existing value to copy
- * @return 1 on success, 0 on failure
- */
-int NCDValue_InitCopy (NCDValue *o, NCDValue *v) WARN_UNUSED;
-
 /**
  * Frees a value.
  * 
@@ -171,23 +162,6 @@ void NCDValue_Free (NCDValue *o);
  */
 int NCDValue_Type (NCDValue *o);
 
-/**
- * Checks if the value is a string value.
- * 
- * @param o the value
- * @return 1 if string, 0 if not
- */
-int NCDValue_IsString (NCDValue *o);
-
-/**
- * Checks if the value is a string value and does not contain
- * any null bytes.
- * 
- * @param o the value
- * @return 1 if string with no nulls, 0 if not
- */
-int NCDValue_IsStringNoNulls (NCDValue *o);
-
 /**
  * Initializes a string value from a null-terminated string.
  * This function can only be used to create string values which do
@@ -228,40 +202,6 @@ char * NCDValue_StringValue (NCDValue *o);
  */
 size_t NCDValue_StringLength (NCDValue *o);
 
-/**
- * Checks whether a string contains no null bytes in its data, i.e. strlen(str)==length.
- * 
- * @param o string value
- * @return 1 if no null, 0 if nulls
- */
-int NCDValue_StringHasNoNulls (NCDValue *o);
-
-/**
- * Checks whether a string contains any null bytes in its data, i.e. strlen(str) < length.
- * 
- * @param o string value
- * @return 1 if nulls, 0 if no nulls
- */
-int NCDValue_StringHasNulls (NCDValue *o);
-
-/**
- * Checks whether the string value is equal to the given null-terminated string.
- * Note that this is not equivalent to strcmp()==0, because the string value may
- * 
- * @param o string value
- * @param str null-terminated string to compare against
- * @return 1 if equal, 0 if not
- */
-int NCDValue_StringEquals (NCDValue *o, const char *str);
-
-/**
- * Checks if the value is a list value.
- * 
- * @param o the value
- * @return 1 if list, 0 if not
- */
-int NCDValue_IsList (NCDValue *o);
-
 /**
  * Initializes an empty list value.
  * 
@@ -291,17 +231,6 @@ int NCDValue_ListAppend (NCDValue *o, NCDValue v) WARN_UNUSED;
  */
 int NCDValue_ListPrepend (NCDValue *o, NCDValue v) WARN_UNUSED;
 
-/**
- * Appends values from a list to the end of a list.
- * On success, the list value that was passed with elements for insertion must be
- * assumed freed; on failure, it is unaffected.
- * 
- * @param o list value
- * @param l list value whose elements to append
- * @return 1 on success, 0 on failure
- */
-int NCDValue_ListAppendList (NCDValue *o, NCDValue l) WARN_UNUSED;
-
 /**
  * Returns the number of elements in a list.
  * 
@@ -331,66 +260,6 @@ NCDValue * NCDValue_ListFirst (NCDValue *o);
  */
 NCDValue * NCDValue_ListNext (NCDValue *o, NCDValue *ev);
 
-/**
- * Attempts to retrieve pointers to elements from a list.
- * Pass exactly 'num' extra NCDValue ** arguments. If the list has exactly
- * 'num' elements, this function succeeds, and returns pointers to them via the
- * passed variable arguments; if not, it fails.
- * 
- * @param o list value
- * @param num number of values to read. Must be >=0, and exactly that many
- *            variable arguments of type NCDValue ** must follow, all non-NULL.
- * @return 1 on succees, 0 on failure
- */
-int NCDValue_ListRead (NCDValue *o, int num, ...) WARN_UNUSED;
-
-/**
- * Like {@link NCDValue_ListRead}, but the list only needs to have >= 'num' values,
- * instead of exactly 'num'.
- */
-int NCDValue_ListReadHead (NCDValue *o, int num, ...) WARN_UNUSED;
-
-/**
- * Returns a pointer to the element of the list at the given position.
- * This performs a linear search from the beginning.
- * 
- * @param o list value
- * @param pos index of element to retrieve; must be < length.
- */
-NCDValue * NCDValue_ListGet (NCDValue *o, size_t pos);
-
-/**
- * Removes the first element from a list and returns it.
- * The caller takes ownership of the removed value and is responsible for freeing
- * it.
- * The list must have at least one element.
- * 
- * @param o list value
- * @return value that was the first on the list
- */
-NCDValue NCDValue_ListShift (NCDValue *o);
-
-/**
- * Removes an element from a list and returns it.
- * The caller takes ownership of the removed value and is responsible for freeing
- * it; the passed element pointer becomes invalid.
- * Note that the element pointer must point to a value that is really in the list
- * right now, and not just equal.
- * 
- * @param o list value
- * @param ev pointer to element of list to remove
- * @return value that was just removed
- */
-NCDValue NCDValue_ListRemove (NCDValue *o, NCDValue *ev);
-
-/**
- * Checks if the value is a map value.
- * 
- * @param o the value
- * @return 1 if map, 0 if not
- */
-int NCDValue_IsMap (NCDValue *o);
-
 /**
  * Initializes an empty map value.
  * 
@@ -462,43 +331,6 @@ NCDValue * NCDValue_MapFindKey (NCDValue *o, NCDValue *key);
  */
 NCDValue * NCDValue_MapInsert (NCDValue *o, NCDValue key, NCDValue val) WARN_UNUSED;
 
-/**
- * Removes an entry from the map and returns the key and value that were just removed.
- * The entry to remove is specified by a pointer to an existing key in the map.
- * The caller takes ownership of the removed key and value value and is responsible for
- * freeing them; the passed key pointer becomes invalid.
- * Note that the key pointer must point to a value that is really a key in the map
- * right now, and not just equal to some key.
- * 
- * @param o map value
- * @param ekey pointer to an existing key in the map whose entry to remove
- * @param out_key the key of the removed entry will be returned here; must not be NULL.
- * @param out_val the value of the removed entry will be returned here; must not be NULL.
- */
-void NCDValue_MapRemove (NCDValue *o, NCDValue *ekey, NCDValue *out_key, NCDValue *out_val);
-
-/**
- * Looks for an entry in the map with a string key equal to the given null-terminated
- * string.
- * If such key exists, it returns a pointer to its associated value; if not, it returns
- * NULL.
- * NOTE: this returns a pointer to the value, not the key, unlike
- *       {@link NCDValue_MapFindKey}.
- * 
- * @param o map value
- * @param key_str null-terminated string specifying the key to look for
- * @return pointer to value, or NULL if there is no such key
- */
-NCDValue * NCDValue_MapFindValueByString (NCDValue *o, const char *key_str);
-
-/**
- * Checks if the value is a variable value.
- * 
- * @param o the value
- * @return 1 if variable, 0 if not
- */
-int NCDValue_IsVar (NCDValue *o);
-
 /**
  * Initializes a variable value.
  * WARNING: variable values are only used internally by NCD as part of