[m-dev.] for review: keeping trace namespace-clean

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Feb 13 18:23:11 AEDT 2001


On 10-Jan-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Is there any reason why you didn't also copy the `check_headers' and
> `check_headers_macros' rules too?

Here is a revised diff to address this comment.
Check the trace directory for namespace cleanliness.

Mmake.common.in:
runtime/Mmakefile:
	Move the rules for checking namespace violations from runtime/Mmakefile
	to Mmake.common.

trace/Mmakefile:
	Add entries for checking the name-space cleanliness of the trace
	directory, using the rules now in Mmake.common. These entries follow
	the same rules as the ones in the runtime directory. Note that the
	the header files of the trace directory must be allowed to define
	all the macros that the runtime directory's header files can, since
	some trace directory header files include header files from the runtime
	directory.

trace/*.h:
	Make these header files self-contained.

tools/bootcheck:
	Check the trace directory for namespace cleanliness as well as the
	runtime directory.

Zoltan.

cvs diff: Diffing .
Index: Mmake.common.in
===================================================================
RCS file: /home/mercury1/repository/mercury/Mmake.common.in,v
retrieving revision 1.52
diff -u -b -r1.52 Mmake.common.in
--- Mmake.common.in	2001/02/11 04:58:26	1.52
+++ Mmake.common.in	2001/02/12 02:51:47
@@ -237,3 +237,56 @@
 -include $(MERCURY_DIR)/Mmake.params
 
 #-----------------------------------------------------------------------------#
+
+# This rule checks that object files are properly namespace-clean, with
+# regard to the global symbols that they define.
+# For an object file foo.o, it produces a file foo.o.obj_check that
+# contains a list of all the globals defined by that object that
+# do not start with `MR_', `mercury_', or `entry_'.
+
+%.obj_check: %
+	nm -g $< | awk '$$1 != "U" { print $$3; }' | \
+		grep -v -e '^_entry' -e '^MR_' -e '^mercury_' | \
+		sort -u > $@
+	@if cmp -s /dev/null $@; then \
+		true; \
+	else \
+		echo "** Global symbols in user namespace:"; \
+		cat $@; \
+		echo "(You may need to add MR_ prefixes to these names.)"; \
+		exit 1; \
+	fi
+
+# This rule helps to check that header files is self-contained, i.e. that each
+# header file foo.h includes any other header files that define types
+# used by foo.h. It creates a foo_check.c file that contains only a single
+# `#include' statement that includes foo.h; compiling foo_check.c will fail
+# if foo.h is not self-contained.
+
+%_check.c : %.h
+	echo "#include \"$*.h\"" > $*_check.c
+
+# This rule checks whether a header file defines any macros it shouldn't.
+# It generates the list of macros defined in the header file, and filters this
+# list through a command that is intended to filter out all references to macro
+# names that are all right. Each directory that uses this rule must set
+# the HEADER_CLEAN_FILTER make variable to contain this command.
+
+AWK = awk
+%_check.macros: %.h %_check.c
+	-$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) \
+		-DMERCURY_BOOTSTRAP_H \
+		-E $*_check.c \
+		-nostdinc -dN \
+		2> /dev/null | $(AWK) '/^#define/ { print $$2; }' | \
+		$(HEADER_CLEAN_FILTER) | sort -u > $@
+	@if cmp -s /dev/null $@; then \
+		true; \
+	else \
+		echo "** Macro name(s) in user namespace:"; \
+		cat $@; \
+		echo "(You may need to add a distinguishing prefix to these names.)"; \
+		exit 1; \
+	fi
+
+#-----------------------------------------------------------------------------#
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing library
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.68
diff -u -b -r1.68 Mmakefile
--- runtime/Mmakefile	2001/02/07 14:37:37	1.68
+++ runtime/Mmakefile	2001/02/08 04:36:18
@@ -264,57 +264,13 @@
 
 #-----------------------------------------------------------------------------#
 #
-# `mmake check_headers' performs various checks on the header files
-# to make sure that the conform with our coding standards.
+# `mmake check_namespace' performs various checks on the header files
+# and object files to make sure that they conform with our coding standards.
 #
 
-#
-# $(HDR_CHECK_OBJS) is used to check that the header files are self-contained.
-# The rule for foo_check.$O checks that the header file foo.h is properly
-# self-contained, i.e. that the header file foo.h includes any other
-# header files that define types used by foo.h.
-# It does this by compiling a foo_check.c file that contains only a single
-# `#include' statement that includes foo.h.
-#
-
-%_check.c : %.h
-	echo "#include \"$*.h\"" > $*_check.c
-
-# The mercury_deep_copy_body.h header is not meant to be self-contained.
-# So the following rule is used to suppress that check for this header.
-mercury_deep_copy_body_check.$O:
-	@true
-	
-#
-# $(HDR_CHECK_MACROS) is used to check that the headers are properly
-# namespace-clean, with regard to the macros that they define.
-# For each header file foo.h, the rule below produces a file
-# foo_check.macros that contains a list of all the macros defined
-# by the header file (or by headers that it includes, excluding
-# standard headers) that do not start with `GC_', `MR_', or `MERCURY_'.
-# We define MERCURY_BOOTSTRAP_H to avoid including the contents of
-# that header; stuff there is for backwards compatibility and is
-# therefore excluded from these checks.
-# 
-
-AWK = awk
-%_check.macros: %.h %_check.c
-	-$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) \
-		-DMERCURY_BOOTSTRAP_H \
-		-E $*_check.c \
-		-nostdinc -dN \
-		2> /dev/null | $(AWK) '/^#define/ { print $$2; }' | \
+HEADER_CLEAN_FILTER = \
 		grep -v -e '^MR_' -e '^GC_' -e '^MERCURY_' | \
-		fgrep -v -x -f RESERVED_MACRO_NAMES | \
-		sort -u > $@
-	@if cmp -s /dev/null $@; then \
-		true; \
-	else \
-		echo "** Macro name(s) in user namespace:"; \
-		cat $@; \
-		echo "(You may need to add MR_ prefixes to these names.)"; \
-		exit 1; \
-	fi
+	fgrep -v -x -f RESERVED_MACRO_NAMES
 
 .PHONY: check_headers_self_contained
 check_headers_self_contained: $(HDR_CHECK_OBJS)
@@ -325,27 +281,6 @@
 .PHONY: check_headers
 check_headers: check_headers_self_contained check_headers_macros
 
-#
-# $(OBJ_CHECKS) is used to check that the objects are properly
-# namespace-clean, with regard to the global symbols that they define.
-# For each object file foo.o, the rule below produces a file
-# foo.o.obj_check that contains a list of all the globals defined
-# by that object that do not start with `MR_', `mercury_', or `entry_'.
-# 
-
-%.obj_check: %
-	nm -g $< | awk '$$1 != "U" { print $$3; }' | \
-		grep -v -e '^_entry' -e '^MR_' -e '^mercury_' | \
-		sort -u > $@
-	@if cmp -s /dev/null $@; then \
-		true; \
-	else \
-		echo "** Global symbols in user namespace:"; \
-		cat $@; \
-		echo "(You may need to add MR_ prefixes to these names.)"; \
-		exit 1; \
-	fi
-
 .PHONY: check_objs
 check_objs: $(OBJ_CHECKS)
 
@@ -407,6 +342,7 @@
 	rm -f $(HDR_CHECK_OBJS) $(HDR_CHECK_CS) $(HDR_CHECK_MACROS)
 	rm -f $(OBJ_CHECKS)
 
+.PHONY: realclean_local
 realclean_local:
 	rm -f lib$(RT_LIB_NAME).$A lib$(RT_LIB_NAME).so $(RT_LIB_NAME).init
 	rm -f mercury_conf.h mercury_conf.h.date
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
Index: tools/bootcheck
===================================================================
RCS file: /home/mercury1/repository/mercury/tools/bootcheck,v
retrieving revision 1.112
diff -u -b -r1.112 bootcheck
--- tools/bootcheck	2001/01/29 06:47:32	1.112
+++ tools/bootcheck	2001/01/31 04:26:31
@@ -58,7 +58,8 @@
 		the extras only. This option requires a previous bootstrap
 		check to have left a working stage 2 directory.
 	--no-check-namespace
-		Don't build the check_namespace target in the runtime.
+		Don't build the check_namespace targets in the runtime
+		and trace directories.
 	-t, --no-test-suite
 		By default, bootcheck will also run the test quite.
 		This option prevents that.
@@ -869,6 +870,16 @@
 if $check_namespace
 then
 	cd $root/${stage2_insert}runtime
+	mmake $mmake_opts check_namespace || {
+		echo '** mmake check_namespace failed!'
+		# XXX Currently we just report the errors;
+		#     we don't yet actually return a non-zero status.
+		#     That's why the line below is commented out.
+		#     This is a transition measure until we're sure
+		#     that everything really is namespace-clean.
+		# check_namespace_status=1
+	}
+	cd $root/${stage2_insert}trace
 	mmake $mmake_opts check_namespace || {
 		echo '** mmake check_namespace failed!'
 		# XXX Currently we just report the errors;
cvs diff: Diffing trace
Index: trace/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/Mmakefile,v
retrieving revision 1.19
diff -u -b -r1.19 Mmakefile
--- trace/Mmakefile	2001/02/07 14:37:39	1.19
+++ trace/Mmakefile	2001/02/08 04:36:30
@@ -76,6 +76,11 @@
 OBJS		= $(CFILES:.c=.$O)
 PIC_OBJS	= $(CFILES:.c=.$(EXT_FOR_PIC_OBJECTS))
 
+HDR_CHECK_CS	= $(HDRS:.h=_check.c)
+HDR_CHECK_OBJS	= $(HDRS:.h=_check.$O)
+HDR_CHECK_MACROS = $(HDRS:.h=_check.macros)
+OBJ_CHECKS	= $(OBJS:%=%.obj_check)
+
 LDFLAGS		= -L$(BROWSER_DIR) -L$(LIBRARY_DIR) \
 			-L$(RUNTIME_DIR) -L$(BOEHM_GC_DIR)
 LDLIBS		= -l$(BROWSER_LIB_NAME) -l$(STD_LIB_NAME) -l$(RT_LIB_NAME) \
@@ -146,15 +151,31 @@
 tags: $(CFILES) $(HDRS)
 	ctags $(CFILES) $(HDRS) ../runtime/*.c ../runtime/*.h
 
+#-----------------------------------------------------------------------------#
+#
+# `mmake check_namespace' performs various checks on the header files
+# and object files to make sure that they conform with our coding standards.
+#
+
+HEADER_CLEAN_FILTER = \
+	grep -v -e '^MR_' -e '^GC_' -e '^MERCURY_' | \
+	fgrep -v -x -f ../runtime/RESERVED_MACRO_NAMES
+
+.PHONY: check_headers_self_contained
+check_headers_self_contained: $(HDR_CHECK_OBJS)
+
+.PHONY: check_headers_macros
+check_headers_macros: $(HDR_CHECK_MACROS)
+
 .PHONY: check_headers
-check_headers:
-	for file in $(HDRS); do \
-		echo "$$file"; \
-		echo "#include \"$$file\"" > tmp.c; \
-		$(MGNUC) $(MGNUCFLAGS) -c tmp.c || exit 1; \
-	done
-	rm -f tmp.c
+check_headers: check_headers_self_contained check_headers_macros
+
+.PHONY: check_objs
+check_objs: $(OBJ_CHECKS)
 
+.PHONY: check_namespace
+check_namespace: check_headers check_objs
+
 #-----------------------------------------------------------------------------#
 
 # installation rules
@@ -180,12 +201,18 @@
 
 #-----------------------------------------------------------------------------#
 
-clean_local: clean_o
+clean_local: clean_o clean_check
 
 .PHONY: clean_o
 clean_o:
 	rm -f $(OBJS) $(PIC_OBJS) 
 
+.PHONY: clean_check
+clean_check:
+	rm -f $(HDR_CHECK_OBJS) $(HDR_CHECK_CS) $(HDR_CHECK_MACROS)
+	rm -f $(OBJ_CHECKS)
+
+.PHONY: realclean_local
 realclean_local:
 	rm -f lib$(TRACE_LIB_NAME).$A lib$(TRACE_LIB_NAME).so
 
Index: trace/mercury_trace.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace.h,v
retrieving revision 1.20
diff -u -b -r1.20 mercury_trace.h
--- trace/mercury_trace.h	2001/01/18 01:19:14	1.20
+++ trace/mercury_trace.h	2001/01/22 06:41:50
@@ -21,6 +21,11 @@
 #ifndef MERCURY_TRACE_H
 #define MERCURY_TRACE_H
 
+#include "mercury_memory_zones.h"	/* for MR_MAX_FAKE_REG */
+#include "mercury_types.h"		/* for MR_Unsigned etc */
+#include "mercury_trace_base.h"		/* for MR_Trace_Port   */
+#include "mercury_std.h"		/* for bool            */
+
 /*
 ** MR_Event_Info is used to hold the information for a trace event.  One
 ** of these is built by MR_trace_event and is passed (by reference)
Index: trace/mercury_trace_alias.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_alias.h,v
retrieving revision 1.2
diff -u -b -r1.2 mercury_trace_alias.h
--- trace/mercury_trace_alias.h	2000/09/01 00:50:27	1.2
+++ trace/mercury_trace_alias.h	2001/01/22 06:41:50
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1998,2000 The University of Melbourne.
+** Copyright (C) 1998,2000-2001 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -13,6 +13,7 @@
 #ifndef	MERCURY_TRACE_ALIAS_H
 #define MERCURY_TRACE_ALIAS_H
 
+#include "mercury_std.h"	/* for bool */
 #include <stdio.h>
 
 typedef struct {
Index: trace/mercury_trace_browse.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.h,v
retrieving revision 1.9
diff -u -b -r1.9 mercury_trace_browse.h
--- trace/mercury_trace_browse.h	2000/10/27 08:38:56	1.9
+++ trace/mercury_trace_browse.h	2001/01/22 06:41:50
@@ -16,6 +16,7 @@
 
 #include "mercury_conf.h"	/* for MR_USE_EXTERNAL_DEBUGGER */
 #include "mercury_types.h"	/* for MR_Word, MR_String */
+#include "mercury_std.h"	/* for bool                     */
 
 /*
 ** The following types must correspond with browse_caller_type and
Index: trace/mercury_trace_external.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_external.h,v
retrieving revision 1.8
diff -u -b -r1.8 mercury_trace_external.h
--- trace/mercury_trace_external.h	2000/10/16 01:34:11	1.8
+++ trace/mercury_trace_external.h	2001/01/22 06:41:51
@@ -7,11 +7,10 @@
 #ifndef	MERCURY_TRACE_EXTERNAL_H
 #define	MERCURY_TRACE_EXTERNAL_H
 
+#include "mercury_trace.h"		/* for MR_Trace_Cmd_Info, etc.  */
 #include "mercury_conf.h"		/* for MR_USE_EXTERNAL_DEBUGGER */
 #include "mercury_types.h"		/* for MR_Code */
 #include "mercury_library_types.h"	/* for MercuryFile */
-
-#include "mercury_trace.h"		/* for MR_Trace_Cmd_Info, etc. */
 
 #ifdef	MR_USE_EXTERNAL_DEBUGGER
 
Index: trace/mercury_trace_spy.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_spy.h,v
retrieving revision 1.6
diff -u -b -r1.6 mercury_trace_spy.h
--- trace/mercury_trace_spy.h	2001/01/18 01:19:17	1.6
+++ trace/mercury_trace_spy.h	2001/01/22 06:41:51
@@ -14,6 +14,9 @@
 #ifndef	MERCURY_TRACE_SPY_H
 #define	MERCURY_TRACE_SPY_H
 
+#include "mercury_stack_layout.h"	/* for MR_Proc_Layout etc */
+#include "mercury_trace_base.h"		/* for MR_Trace_Port etc  */
+
 typedef enum {
 	MR_SPY_PRINT, MR_SPY_STOP
 } MR_Spy_Action;
Index: trace/mercury_trace_util.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_util.h,v
retrieving revision 1.4
diff -u -b -r1.4 mercury_trace_util.h
--- trace/mercury_trace_util.h	2000/11/23 02:01:10	1.4
+++ trace/mercury_trace_util.h	2001/01/22 06:41:51
@@ -15,6 +15,10 @@
 #ifndef MERCURY_TRACE_UTIL_H
 #define MERCURY_TRACE_UTIL_H
 
+#include "mercury_std.h"	/* for bool        */
+#include "mercury_types.h"	/* for MR_Word etc */
+#include <stdio.h>		/* for FILE        */
+
 /*
 ** When using the heap pointer, we need to restore it, in case it is
 ** transient.
Index: trace/mercury_trace_vars.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_vars.h,v
retrieving revision 1.11
diff -u -b -r1.11 mercury_trace_vars.h
--- trace/mercury_trace_vars.h	2001/01/18 01:19:17	1.11
+++ trace/mercury_trace_vars.h	2001/01/22 06:41:51
@@ -36,9 +36,11 @@
 #define	MERCURY_TRACE_VARS_H
 
 #include <stdio.h>
-#include "mercury_types.h"
-#include "mercury_stack_layout.h"
-#include "mercury_trace_browse.h"
+#include "mercury_types.h"		/* for MR_Word etc         */
+#include "mercury_stack_layout.h"	/* for MR_Label_Layout etc */
+#include "mercury_type_info.h"		/* for MR_TypeInfo         */
+#include "mercury_trace_base.h"		/* for MR_Trace_Port       */
+#include "mercury_trace_browse.h"	/* for MR_Browser          */
 
 typedef	void	(*MR_Browser)(MR_Word type_info, MR_Word value,
 			MR_Browse_Caller_Type caller, MR_Browse_Format format);
cvs diff: Diffing trial
cvs diff: Diffing util
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list