根據1800-2012 specs,如何匹配和刪除隊列中的元素?
Queue::delete([input int index])
刪除隊列元素SystemVerilog中,此外,一個隊列可以執行相同的操作作爲一個解壓縮陣列,給它訪問:
Array::find_first_index()
它返回第一個元素的索引匹配一定的標準。即
find_first_index(x) with (x == 3)
現在我想從隊列中刪除一個唯一的項目,保證存在。將1和1給了我:
queue.delete(queue.find_first_index(x) with (x == obj_to_del));
編譯器不理解的是,雖然說,參數傳遞必須是整數或整數兼容。我大概可以拉兩個相距:
int index = queue.find_first_index(x) with (x == obj_to_del);
queue.delete(index);
或類型轉換find_first_index迫使整數:
queue.delete(int'(queue.find_first_index(x) with (x == obj_to_del))) //Just finished compiling, does not work.
前者看起來不是很優雅的我,而後者似乎有點強迫這讓我很好奇如果有更合適的方法來實現這一點。 find_first_index是否可能返回一個大小爲1的數組,其索引位置爲0?
編輯:我傻傻的沒有提供一個自包含例如:
class parent_task;
endclass;
class child_taskA extends parent_task;
endclass;
class child_taskB extends parent_task;
endclass;
class task_collector;
child_taskA A_queue[$];
child_taskB B_queue[$];
function delete_from_queue(parent_task task_to_del);
case (task_to_del.type):
A: A_queue.delete(A_queue.find_first_index(x) with (x == task_to_del));
B: B_queue.delete(B_queue.find_first_index(x) with (x == task_to_del));
default: $display("This shouldn't happen.");
endfunction
endclass
錯誤消息,一個字一個字是:什麼我做看起來像一個剝例如
Error-[SV-IQDA] Invalid Queue delete argument
"this.A_queue.find_first_index(iterator) with ((iterator == task))"
Queue method delete can take optional integer argument. So, argument passed
to it must be either integer or integer assignment compatible.
在調用delete_from_queue之前,存在檢查以確保有問題的任務存在。
進一步分析它的確看起來像find_first_index返回數組。 'int index = queue.find_first_index(x)其中(x == obj_to_del);' 抱怨將一個int $ [$]分配給int。 –