On Sun, 2 Sep 2012, Lars-Peter Clausen wrote:
Hi,
I'd like to use a virtual identifier as for the length of lists.
E.g.
@@
expression list[virtual.N] Xs;
@@
...
I've come up with the following patch, which seems to work:
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -424,6 +424,14 @@ metadec:
list_len:
pure_ident_or_meta_ident { Common.Left $1 }
| TInt { let (x,clt) = $1 in Common.Right (int_of_string x) }
+| TVirtual TDot pure_ident
+ { let nm = ("virtual",P.id2name $3) in
+ Iteration.parsed_virtual_identifiers :=
+ Common.union_set [snd nm]
+ !Iteration.parsed_virtual_identifiers;
+ Common.Right (int_of_string (
+ List.assoc (snd nm) !Flag.defined_virtual_env))
+ }
%inline metakind_fresh:
TFresh TIdentifier
But to be honest I have not much of an idea what I'm doing and this is mostly a
copy 'n paste of the code which is used to initialize an identifier from a
virtual identifier. There might be a better way to do it. Also I'm not sure how
to handle the 'Not found' for the lookup exception and the int_of_string
exception if the identifier is not a integer.
Thanks for the patch. I will try to integrate it. I think that if the
user provides something that is not an integer for a variable that is used
in this position, the whole thing should just crash. The user wrote the
semantic patch and provided the bad value, so there seems to be no point
to trying to do anything.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)