come posso creare un riferimento a una variabile in Specman?
Domanda
Ho il seguente codice nella Specman:
var x := some.very.long.path.to.a.variable.in.another.struct;
while (x == some_value) {
//do something that uses x;
//wait for something
//get a new value for x
x = some.very.long.path.to.a.variable.in.another.struct;
};
Ora, sembra uno spreco di scrivere il compito di x
due volte; una volta durante l'inizializzazione e una volta durante il ciclo.
Quello che voglio usare è un riferimento al lungo nome della variabile, in modo che potessi fare:
var x := reference to some.very.long.path.to.a.variable.in.another.struct;
while (x == some_value) {
//do something that uses x;
//wait for something
//no need to update x now since it's a reference
};
Può questo essere fatto in Specman?
Soluzione
Specman / e generalmente usa i riferimenti per le strutture e gli elenchi, quindi se il vostro tipo di variabile è uno di esso il tuo secondo esempio dovrebbe funzionare. Per integer
o boolean
non so un modo per utilizzare un riferimento per una variabile. In ogni caso, due idee che potrebbero aiutarvi:
-
Aggiungi un puntatore alla struct altri e associarlo a un file di configurazione:
struct a { other_variable : uint; }; struct b { other_struct : a; some_func() is { var x : uint = other_struct.other_variable; while (x == some_value) { x = other_struct.other_variable; }; }; }; extend cfg { struct_a : a; struct_b : b; keep struct_b.other_struct == struct_a; };
UPDATE: Puoi trovare qualche informazione in più su questa tecnica in questa squadra Specman post .
-
Avvolgete il vostro ciclo while in una funzione, non ci si può passare parametri per riferimento (vedi
help pass reference
):some_func(x : *uint) is { while (x == some_value) { // stuff ... }; };
Spero che questo aiuti!
Daniel