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.
Indeed, it is rather unfortunate (as is the code that you copied it from), because normally a rule just doesn't apply if a virtual identifier that it depends on is not bound. I'm OK with it crashing if the user doesn't provide an integer, but it would be better if it did not do that when nothing is provided at all.
julia _______________________________________________ Cocci mailing list [email protected] http://lists.diku.dk/mailman/listinfo/cocci (Web access from inside DIKUs LAN only)
