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

NCDInterpProg: make NCDInterpProg_FindProcess() only return an NCDInterpProcess.

ambrop7 пре 13 година
родитељ
комит
9f9d4bae9e
3 измењених фајлова са 19 додато и 19 уклоњено
  1. 3 7
      ncd/NCDInterpProg.c
  2. 1 1
      ncd/NCDInterpProg.h
  3. 15 11
      ncd/ncd.c

+ 3 - 7
ncd/NCDInterpProg.c

@@ -117,21 +117,17 @@ void NCDInterpProg_Free (NCDInterpProg *o)
     BFree(o->procs);
 }
 
-int NCDInterpProg_FindProcess (NCDInterpProg *o, const char *name, NCDProcess **out_proc, NCDInterpProcess **out_iprocess)
+NCDInterpProcess * NCDInterpProg_FindProcess (NCDInterpProg *o, const char *name)
 {
     DebugObject_Access(&o->d_obj);
     ASSERT(name)
-    ASSERT(out_proc)
-    ASSERT(out_iprocess)
     
     NCDInterpProg__HashRef ref = NCDInterpProg__Hash_Lookup(&o->hash, o->procs, name);
     if (ref.link == NCDInterpProg__HashNullLink()) {
-        return 0;
+        return NULL;
     }
     
     ASSERT(!strcmp(ref.ptr->name, name))
     
-    *out_proc = ref.ptr->proc;
-    *out_iprocess = &ref.ptr->iprocess;
-    return 1;
+    return &ref.ptr->iprocess;
 }

+ 1 - 1
ncd/NCDInterpProg.h

@@ -59,6 +59,6 @@ typedef struct {
 
 int NCDInterpProg_Init (NCDInterpProg *o, NCDProgram *prog, NCDPlaceholderDb *pdb, NCDModuleIndex *module_index, NCDMethodIndex *method_index) WARN_UNUSED;
 void NCDInterpProg_Free (NCDInterpProg *o);
-int NCDInterpProg_FindProcess (NCDInterpProg *o, const char *name, NCDProcess **out_proc, NCDInterpProcess **out_iprocess) WARN_UNUSED;
+NCDInterpProcess * NCDInterpProg_FindProcess (NCDInterpProg *o, const char *name);
 
 #endif

+ 15 - 11
ncd/ncd.c

@@ -372,13 +372,11 @@ int main (int argc, char **argv)
         }
         
         // find iblock
-        NCDProcess *f_proc;
-        NCDInterpProcess *iblock;
-        int res = NCDInterpProg_FindProcess(&iprogram, NCDProcess_Name(p), &f_proc, &iblock);
-        ASSERT(res)
-        ASSERT(f_proc == p)
+        NCDInterpProcess *iprocess = NCDInterpProg_FindProcess(&iprogram, NCDProcess_Name(p));
+        ASSERT(iprocess)
+        ASSERT(NCDInterpProcess_Process(iprocess) == p)
         
-        if (!process_new(p, iblock, NULL)) {
+        if (!process_new(p, iprocess, NULL)) {
             BLog(BLOG_ERROR, "failed to initialize process, exiting");
             goto fail6;
         }
@@ -1298,16 +1296,22 @@ int statement_instance_func_initprocess (struct statement *ps, NCDModuleProcess
 {
     ASSERT(ps->state != SSTATE_FORGOTTEN)
     
-    // find template
-    NCDProcess *p_ast;
-    NCDInterpProcess *iblock;
-    if (!NCDInterpProg_FindProcess(&iprogram, template_name, &p_ast, &iblock) || !NCDProcess_IsTemplate(p_ast)) {
+    // find process
+    NCDInterpProcess *iprocess = NCDInterpProg_FindProcess(&iprogram, template_name);
+    if (!iprocess) {
         statement_log(ps, BLOG_ERROR, "no template named %s", template_name);
         return 0;
     }
     
+    // make sure it's a template
+    NCDProcess *p_ast = NCDInterpProcess_Process(iprocess);
+    if (!NCDProcess_IsTemplate(p_ast)) {
+        statement_log(ps, BLOG_ERROR, "need template to create a process, but %s is a process", template_name);
+        return 0;
+    }
+    
     // create process
-    if (!process_new(p_ast, iblock, mp)) {
+    if (!process_new(p_ast, iprocess, mp)) {
         statement_log(ps, BLOG_ERROR, "failed to create process from template %s", template_name);
         return 0;
     }