[m-rev.] diff: convert predicate_table to use field accessors

Peter Ross pro at missioncriticalit.com
Fri Oct 24 04:52:04 AEST 2003


Hi,


===================================================================


Estimated hours taken: 2
Branches: main

compiler/hlds_module.m:
    Convert the predicate table type to using field accessors.


Index: compiler/hlds_module.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_module.m,v
retrieving revision 1.90
diff -u -r1.90 hlds_module.m
--- compiler/hlds_module.m	26 Jun 2003 00:26:46 -0000	1.90
+++ compiler/hlds_module.m	23 Oct 2003 18:48:48 -0000
@@ -1352,22 +1352,35 @@
 
 :- type predicate_table --->
 	predicate_table(
-		pred_table,		% map from pred_id to pred_info
-		pred_id,		% next available pred_id
-		list(pred_id),		% the keys of the pred_table -
-					% cached here for efficiency
+		preds		:: pred_table,		% map from pred_id to
+							% pred_info
+		next_pred_id	:: pred_id,		% next available pred_id
+		pred_ids	:: list(pred_id),	% the keys of the
+							% pred_table - cached
+							% here for efficiency
+
 		% indexes on predicates
-		name_index,		% map from pred name to pred_id
-		name_arity_index,	% map from pred name & arity to pred_id
-		module_name_arity_index,
-					% map from pred module, name & arity
-					% to pred_id
+
+		pred_name_index		:: name_index,	% map from pred name
+							% to pred_id
+		pred_name_arity_index	:: name_arity_index,	
+							% map from pred name &
+							% arity to pred_id
+		pred_module_name_arity_index :: module_name_arity_index,
+							% map from pred module,
+							% name & arity to
+							% pred_id
+
 		% indexes on functions
-		name_index,		% map from func name to pred_id
-		name_arity_index,	% map from func name & arity to pred_id
-		module_name_arity_index
-					% map from func module, name & arity
-					% to pred_id
+		func_name_index		:: name_index,	% map from func name
+							% to pred_id
+		func_name_arity_index	:: name_arity_index,	
+							% map from func name &
+							% arity to pred_id
+		func_module_name_arity_index :: module_name_arity_index
+							% map from func module,
+							% name & arity to
+							% pred_id
 	).
 
 :- type name_index	== map(string, list(pred_id)).
@@ -1409,20 +1422,16 @@
 				Pred_N_Index, Pred_NA_Index, Pred_MNA_Index,
 				Func_N_Index, Func_NA_Index, Func_MNA_Index).
 
-predicate_table_get_preds(PredicateTable, Preds) :-
-	PredicateTable = predicate_table(Preds, _, _, _, _, _, _, _, _).
+predicate_table_get_preds(PredicateTable, PredicateTable ^ preds).
 
-predicate_table_set_preds(PredicateTable0, Preds, PredicateTable) :-
-	PredicateTable0 = predicate_table(_, B, C, D, E, F, G, H, I),
-	PredicateTable = predicate_table(Preds, B, C, D, E, F, G, H, I).
+predicate_table_set_preds(PredicateTable, Preds,
+		PredicateTable ^ preds := Preds).
 
-predicate_table_get_predids(PredicateTable, PredIds) :-
-	PredicateTable = predicate_table(_, _, PredIds, _, _, _, _, _, _).
+predicate_table_get_predids(PredicateTable, PredicateTable ^ pred_ids).
 
 predicate_table_remove_predid(PredicateTable0, PredId, PredicateTable) :-
-	PredicateTable0 = predicate_table(A, B, PredIds0, D, E, F, G, H, I),
-	list__delete_all(PredIds0, PredId, PredIds),
-	PredicateTable = predicate_table(A, B, PredIds, D, E, F, G, H, I).
+	list__delete_all(PredicateTable0 ^ pred_ids, PredId, PredIds),
+	PredicateTable = PredicateTable0 ^ pred_ids := PredIds.
 
 predicate_table_remove_predicate(PredicateTable0, PredId, PredicateTable) :-
 	PredicateTable0 = predicate_table(Preds0, NextPredId, PredIds0, 
@@ -1503,9 +1512,8 @@
 :- mode predicate_table_reverse_predids(in, out) is det.
 
 predicate_table_reverse_predids(PredicateTable0, PredicateTable) :-
-	PredicateTable0 = predicate_table(A, B, PredIds0, D, E, F, G, H, I),
-	list__reverse(PredIds0, PredIds),
-	PredicateTable = predicate_table(A, B, PredIds, D, E, F, G, H, I).
+	list__reverse(PredicateTable0 ^ pred_ids, PredIds),
+	PredicateTable = PredicateTable0 ^ pred_ids := PredIds.
 
 %-----------------------------------------------------------------------------%
 
@@ -1593,12 +1601,10 @@
 	PredIds \= [].
 
 predicate_table_search_pred_name(PredicateTable, PredName, PredIds) :-
-	PredicateTable = predicate_table(_, _, _, PredNameIndex, _, _, _, _, _),
-	map__search(PredNameIndex, PredName, PredIds).
+	map__search(PredicateTable ^ pred_name_index, PredName, PredIds).
 
 predicate_table_search_func_name(PredicateTable, FuncName, PredIds) :-
-	PredicateTable = predicate_table(_, _, _, _, _, _, FuncNameIndex, _, _),
-	map__search(FuncNameIndex, FuncName, PredIds).
+	map__search(PredicateTable ^ func_name_index, FuncName, PredIds).
 
 %-----------------------------------------------------------------------------%
 
@@ -1633,7 +1639,7 @@
 
 predicate_table_search_pred_module_name(PredicateTable, IsFullyQualified,
 		Module, PredName, PredIds) :-
-	PredicateTable = predicate_table(_,_,_,_,_, Pred_MNA_Index, _,_,_),
+	Pred_MNA_Index = PredicateTable ^ pred_module_name_arity_index,
 	map__search(Pred_MNA_Index, Module - PredName, Arities),
 	map__values(Arities, PredIdLists),
 	list__condense(PredIdLists, PredIds0),
@@ -1647,7 +1653,7 @@
 
 predicate_table_search_func_module_name(PredicateTable, IsFullyQualified,
 		Module, FuncName, PredIds) :-
-	PredicateTable = predicate_table(_,_,_,_,_,_,_,_, Func_MNA_Index),
+	Func_MNA_Index = PredicateTable ^ func_module_name_arity_index,
 	map__search(Func_MNA_Index, Module - FuncName, Arities),
 	map__values(Arities, PredIdLists),
 	list__condense(PredIdLists, PredIds0),
@@ -1678,14 +1684,12 @@
 
 predicate_table_search_pred_name_arity(PredicateTable, PredName, Arity,
 		PredIds) :-
-	PredicateTable = predicate_table(_, _, _, _, PredNameArityIndex, _,
-					_, _, _),
+	PredNameArityIndex = PredicateTable ^ pred_name_arity_index,
 	map__search(PredNameArityIndex, PredName / Arity, PredIds).
 
 predicate_table_search_func_name_arity(PredicateTable, FuncName, Arity,
 		PredIds) :-
-	PredicateTable = predicate_table(_, _, _, _, _, _,
-					_, FuncNameArityIndex, _),
+	FuncNameArityIndex = PredicateTable ^ func_name_arity_index,
 	map__search(FuncNameArityIndex, FuncName / Arity, PredIds).
 
 %-----------------------------------------------------------------------------%
@@ -1713,7 +1717,7 @@
 
 predicate_table_search_pred_m_n_a(PredicateTable, IsFullyQualified,
 		Module, PredName, Arity, PredIds) :-
-	PredicateTable = predicate_table(_, _, _, _, _, P_MNA_Index, _, _, _),
+	P_MNA_Index = PredicateTable ^ pred_module_name_arity_index,
 	map__search(P_MNA_Index, Module - PredName, ArityIndex),
 	map__search(ArityIndex, Arity, PredIds0),
 	maybe_filter_pred_ids_matching_module(IsFullyQualified,
@@ -1721,7 +1725,7 @@
 
 predicate_table_search_func_m_n_a(PredicateTable, IsFullyQualified,
 		Module, FuncName, Arity, PredIds) :-
-	PredicateTable = predicate_table(_, _, _, _, _, _, _, _, F_MNA_Index),
+	F_MNA_Index = PredicateTable ^ func_module_name_arity_index,
 	map__search(F_MNA_Index, Module - FuncName, ArityIndex),
 	map__search(ArityIndex, Arity, PredIds0),
 	maybe_filter_pred_ids_matching_module(IsFullyQualified,
@@ -1826,7 +1830,7 @@
 :- pred predicate_table_reset(predicate_table::in, predicate_table::out) is det.
 
 predicate_table_reset(PredicateTable0, PredicateTable) :-
-	PredicateTable0 = predicate_table(_, NextPredId, _, _, _, _, _, _, _),
+	NextPredId = PredicateTable0 ^ next_pred_id,
 	PredicateTable = predicate_table(map__init, NextPredId, [], map__init,
 			map__init, map__init, map__init, map__init, map__init).
 

----
Peter Ross
PhD Student University of Melbourne
http://www.cs.mu.oz.au/~petdr/
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list