Convert predicates that used to have one clause for each kind of

Estimated hours taken: 12
Branches: main

compiler/*.m:
	Convert predicates that used to have one clause for each kind of
	HLDS goal into explicit disjunctions, since this gives the debugger
	a meaningful name for each argument. In some cases, this exposed
	arguments that were used by *no* clause. In other cases, it allowed
	factoring out common code, as well as code that *should* have been
	common but wasn't.

	Put the disjuncts in a meaningful order. In too many cases, they were
	almost random.

	Merge the resulting predicates into their parents, in places where
	the Prolog indexing one could get from separate clauses was the only
	reason for separating those predicates from their parents in the first
	place. Similarly, merge child predicates handling generic call kinds
	and such back into the main predicate where this improves clarity.
	In some cases, this allows putting the extraction of hlds_goal_expr
	from a hlds_goal into one place, instead of repeating it in lots of
	places.

	Give some predicates more descriptive names. In some cases, rationalize
	argument order. In some cases, rationalize the order of predicates
	in the module.

	Replace some uses of booleans with purpose-specific types.

	Give some fields names, and put type-identifying prefixes on the names
	of other fields, to make tag files work better.

	In some cases, reorder fields to them put into related groups.

	Use more standard and/or more descriptive variable names

	Use a standard syntax for if-then-else in each module.

	Follow our style convention for comments.
This commit is contained in:
Zoltan Somogyi
2008-01-21 00:32:55 +00:00
parent 270314c961
commit 9ad83d648d
37 changed files with 4817 additions and 4619 deletions

View File

@@ -1,25 +1,25 @@
%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 2000-2001, 2003-2007 The University of Melbourne.
% Copyright (C) 2000-2001, 2003-2008 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
%
%
% File: ml_simplify_switch.m.
% Main author: fjh.
%
%
% This module, which is invoked by the various parts of the MLDS code generator
% that generate switches, converts MLDS switches into computed gotos
% or if-then-else chains.
%
%
% We should eventually also handle lookup switches and binary search switches
% here too.
%
%
% The choice of which exactly which simplifications will get
% performed depends on the target (e.g. whether it understands
% switches) and the --prefer-switch option.
%
%
%-----------------------------------------------------------------------------%
:- module ml_backend.ml_simplify_switch.
@@ -324,16 +324,15 @@ generate_dense_switch(Cases, Default, FirstVal, LastVal, NeedRangeCheck,
mlds_defns::out, statements::out,
ml_gen_info::in, ml_gen_info::out) is det.
generate_cases([], _EndLabel, CaseLabelsMap, CaseLabelsMap, [], [], !Info).
generate_cases([Case | Cases], EndLabel, CaseLabelsMap0,
CaseLabelsMap, Decls, Statements, !Info) :-
generate_case(Case, EndLabel, CaseLabelsMap0, CaseLabelsMap1,
generate_cases([], _EndLabel, !CaseLabelsMap, [], [], !Info).
generate_cases([Case | Cases], EndLabel, !CaseLabelsMap, Decls, Statements,
!Info) :-
generate_case(Case, EndLabel, !CaseLabelsMap,
CaseDecls, CaseStatements, !Info),
generate_cases(Cases, EndLabel,
CaseLabelsMap1, CaseLabelsMap,
Decls1, Statements1, !Info),
Decls = CaseDecls ++ Decls1,
Statements = CaseStatements ++ Statements1.
generate_cases(Cases, EndLabel, !CaseLabelsMap,
CasesDecls, CasesStatements, !Info),
Decls = CaseDecls ++ CasesDecls,
Statements = CaseStatements ++ CasesStatements.
% This converts an MLDS switch case into code for a dense switch case,
% by adding a label at the front and a `goto <EndLabel>' at the end.