Просмотр исходного кода

ncd: NCDInterpBlock: add NCDInterpBlock_StatementCmdName() and NCDInterpBlock_StatementObjNames()

ambrop7 13 лет назад
Родитель
Сommit
a1b4d1aeee
2 измененных файлов с 44 добавлено и 0 удалено
  1. 40 0
      ncd/NCDInterpBlock.c
  2. 4 0
      ncd/NCDInterpBlock.h

+ 40 - 0
ncd/NCDInterpBlock.c

@@ -30,8 +30,10 @@
 #include <stdint.h>
 #include <limits.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include <misc/balloc.h>
+#include <misc/split_string.h>
 #include <base/BLog.h>
 
 #include "NCDInterpBlock.h"
@@ -74,9 +76,17 @@ int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block)
     o->num_stmts = 0;
     
     for (NCDStatement *s = NCDBlock_FirstStatement(block); s; s = NCDBlock_NextStatement(block, s)) {
+        ASSERT(NCDStatement_Type(s) == NCDSTATEMENT_REG)
         struct NCDInterpBlock__stmt *e = &o->stmts[o->num_stmts];
         
         e->name = NCDStatement_Name(s);
+        e->cmdname = NCDStatement_RegCmdName(s);
+        e->objnames = NULL;
+        
+        if (NCDStatement_RegObjName(s) && !(e->objnames = split_string(NCDStatement_RegObjName(s), '.'))) {
+            BLog(BLOG_ERROR, "split_string failed");
+            goto fail2;
+        }
         
         if (e->name) {
             NCDInterpBlock__HashRef ref = NCDInterpBlock__Hash_Deref(o->stmts, o->num_stmts);
@@ -91,6 +101,12 @@ int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block)
     DebugObject_Init(&o->d_obj);
     return 1;
     
+fail2:
+    while (o->num_stmts-- > 0) {
+        if (o->stmts[o->num_stmts].objnames) {
+            free_strings(o->stmts[o->num_stmts].objnames);
+        }
+    }
 fail1:
     BFree(o->stmts);
 fail0:
@@ -101,6 +117,12 @@ void NCDInterpBlock_Free (NCDInterpBlock *o)
 {
     DebugObject_Free(&o->d_obj);
     
+    while (o->num_stmts-- > 0) {
+        if (o->stmts[o->num_stmts].objnames) {
+            free_strings(o->stmts[o->num_stmts].objnames);
+        }
+    }
+    
     NCDInterpBlock__Hash_Free(&o->hash);
     
     BFree(o->stmts);
@@ -132,3 +154,21 @@ int NCDInterpBlock_FindStatement (NCDInterpBlock *o, int from_index, const char
     
     return -1;
 }
+
+const char * NCDInterpBlock_StatementCmdName (NCDInterpBlock *o, int i)
+{
+    DebugObject_Access(&o->d_obj);
+    ASSERT(i >= 0)
+    ASSERT(i < o->num_stmts)
+    
+    return o->stmts[i].cmdname;
+}
+
+char ** NCDInterpBlock_StatementObjNames (NCDInterpBlock *o, int i)
+{
+    DebugObject_Access(&o->d_obj);
+    ASSERT(i >= 0)
+    ASSERT(i < o->num_stmts)
+    
+    return o->stmts[i].objnames;
+}

+ 4 - 0
ncd/NCDInterpBlock.h

@@ -37,6 +37,8 @@
 
 struct NCDInterpBlock__stmt {
     const char *name;
+    const char *cmdname;
+    char **objnames;
     int hash_next;
 };
 
@@ -57,5 +59,7 @@ typedef struct {
 int NCDInterpBlock_Init (NCDInterpBlock *o, NCDBlock *block) WARN_UNUSED;
 void NCDInterpBlock_Free (NCDInterpBlock *o);
 int NCDInterpBlock_FindStatement (NCDInterpBlock *o, int from_index, const char *name);
+const char * NCDInterpBlock_StatementCmdName (NCDInterpBlock *o, int i);
+char ** NCDInterpBlock_StatementObjNames (NCDInterpBlock *o, int i);
 
 #endif