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

ncd: allow a statement to forward method calls elsewhere by asking it to resolve an empty string
object. This makes alias() work as expected when a method is called directly on it.

ambrop7 14 лет назад
Родитель
Сommit
d68957f1e6
1 измененных файлов с 9 добавлено и 7 удалено
  1. 9 7
      ncd/ncd.c

+ 9 - 7
ncd/ncd.c

@@ -1299,17 +1299,19 @@ struct process_statement * process_resolve_object (struct process *p, size_t pos
     
     ASSERT(rps->state == SSTATE_ADULT)
     
-    if (!rest) {
-        // this is the target
-        return rps;
-    }
-    
-    // resolve object in referred statement
-    NCDModuleInst *inst = NCDModuleInst_GetObj(&rps->inst, rest);
+    // Resolve object in referred statement. If there is no rest, resolve empty string
+    // instead, or use this statement if it fails. This allows a statement to forward method
+    // calls elsewhere.
+    NCDModuleInst *inst = NCDModuleInst_GetObj(&rps->inst, (rest ? rest : ""));
     if (!inst) {
+        if (!rest) {
+            return rps;
+        }
+        
         process_log(p, BLOG_ERROR, "referred module failed to resolve object: %s", objname);
         return NULL;
     }
+    
     struct process_statement *res_ps = UPPER_OBJECT(inst, struct process_statement, inst);
     ASSERT(res_ps->state == SSTATE_ADULT)