瀏覽代碼

Prevent reuse of the same variable ID in different coded files

Yentl Van Tendeloo 9 年之前
父節點
當前提交
d2912ca57c
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      model/model.py

+ 15 - 0
model/model.py

@@ -12,11 +12,26 @@ from pypdevs.simulator import Simulator
 
 import json
 
+max_used_id = 0
+
 def get_object_constructor(code):
     with open(".code.alc", "w") as f:
         f.write(code)
         f.flush()
     constructors = do_compile(".code.alc", "interface/HUTN/grammars/actionlanguage.g", "CS")
+    global max_used_id
+    initial_id = max_used_id
+    for i, v in enumerate(constructors):
+        if isinstance(v, int):
+            # Integer, so rename
+            constructors[i] += initial_id
+        v = constructors[i]
+        if v > max_used_id:
+            max_used_id += 1
+
+    # Keep a gap for safety purposes!
+    max_used_id += 10
+
     return constructors
 
 def translate(operation):