for review: unused_args & pragma c_code
Fergus Henderson
fjh at cs.mu.OZ.AU
Sun Jan 25 18:40:12 AEDT 1998
Zoltan, can you please review this one?
compiler/unused_args.m:
If a variable in a `pragma c_code' declaration does not
have a name (i.e. it is an underscore variable), then it
can't be used by the C code.
Index: unused_args.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.43
diff -u -u -r1.43 unused_args.m
--- unused_args.m 1998/01/25 06:05:30 1.43
+++ unused_args.m 1998/01/25 06:34:40
@@ -57,7 +57,7 @@
:- import_module options, prog_data, prog_out, quantification, special_pred.
:- import_module passes_aux, inst_match.
-:- import_module bool, char, int, list, map, require.
+:- import_module assoc_list, bool, char, int, list, map, require.
:- import_module set, std_util, string, term, varset.
% Information about the dependencies of a variable
@@ -445,9 +445,16 @@
traverse_goal(_, class_method_call(PredVar,_,Args,_,_,_), UseInf0, UseInf) :-
set_list_vars_used(UseInf0, [PredVar|Args], UseInf).
-% handle pragma c_code(...) - pragma_c_code uses all its args
-traverse_goal(_, pragma_c_code(_, _, _, Args, _, _, _), UseInf0, UseInf) :-
- set_list_vars_used(UseInf0, Args, UseInf).
+% handle pragma c_code(...) -
+% only those arguments which have C names can be used in the C code.
+traverse_goal(_, pragma_c_code(_, _, _, Args, Names, _, _), UseInf0, UseInf) :-
+ assoc_list__from_corresponding_lists(Args, Names, ArgsAndNames),
+ ArgIsUsed = lambda([ArgAndName::in, Arg::out] is semidet, (
+ ArgAndName = Arg - MaybeName,
+ MaybeName = yes(_)
+ )),
+ list__filter_map(ArgIsUsed, ArgsAndNames, UsedArgs),
+ set_list_vars_used(UseInf0, UsedArgs, UseInf).
% cases to handle all the different types of unification
traverse_goal(_, unify(_, _, _, simple_test(Var1, Var2),_), UseInf0, UseInf)
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list