This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: preprocessing infrastructure



This patch adds the build infrastructure to generate Java source files
from preprocessed source (.jpp) files.

The C preprocessor is used for preprocessing.  Comments are preserved
in the output, and a new program (fixlines) adjusts the output so the
.java file lines match up with the .jpp file lines.

This infrastructure is required in order to generate different runtime
profiles (specifically, smaller runtimes similar to the various
J2ME profiles).

Comments?

AG


2001-06-30  Anthony Green  <green@redhat.com>

	* Makefile.in: Rebuilt.
	* Makefile.am: Add infrastructure for preprocessed source files.
	Make Class.java a preprocessed source files.
	(SUFFIXES): Add .jpp.
	(.jpp.java): Describe how to build .java files from .jpp files.
	(fixlines*): Describe how and when to build the new program
	`fixlines'.
	* java/lang/Class.java: Renamed to Class.jpp.
	* fixlines.c: New file.

Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.153
diff -u -p -r1.153 Makefile.am
--- Makefile.am	2001/06/08 19:09:04	1.153
+++ Makefile.am	2001/07/01 04:08:16
@@ -211,14 +211,14 @@ libgcj.jar: $(java_source_files) $(x_jav
 	  sed -e '/\/\./d' -e '/\/xlib/d' | \
 	  $(ZIP) cfM0E@ $@
 
-MOSTLYCLEANFILES = $(javao_files) $(nat_files) $(nat_headers) $(c_files) $(x_javao_files) $(x_nat_files) $(x_nat_headers)
+MOSTLYCLEANFILES = $(javao_files) $(nat_files) $(nat_headers) $(c_files) $(x_javao_files) $(x_nat_files) $(x_nat_headers) $(preprocessed_java_source_files)
 CLEANFILES = tmp-list libgcj.jar
 
 clean-local:
 ## We just remove every .class file that was created.
 	find . -name '*.class' -print | xargs rm -f
 
-SUFFIXES = .class .java .h
+SUFFIXES = .class .java .jpp .h
 
 .class.lo:
 	$(GCJCOMPILE) -o $@ $<
@@ -226,6 +226,9 @@ SUFFIXES = .class .java .h
 .java.lo:
 	$(GCJCOMPILE) -o $@ $<
 
+.jpp.java:
+	cat $< | $(CXXCPP) -C - | $(top_builddir)/fixlines > $@
+
 ## This is GNU make specific.  For the .o files in subdirs, use a
 ## special rule.  The standard automake rule can't be overridden (this
 ## is a bug in automake), and it also won't put the .o files into
@@ -402,19 +405,34 @@ header-check: libgcj.jar $(nat_headers)
 ## ################################################################
 
 ##
+## The `fixlines' program
+##
+
+## fixlines reads preprocessor output from stdin, and write output to
+## stdout.  The output has all #line directives replaced with an
+## appropriate amount of padding so the input and output sources lines
+## match up properly.  The whole point of this excercise is to make
+## debugging easier.
+fixlines_SOURCES = fixlines.c
+
+## ################################################################
+
+##
 ## The `jv-convert' program and code to rebuild the converter header
 ## files.
 ##
 
+CONVERT_DIR = gnu/gcj/convert
+
 ## it only makes sense to try to rebuild the JIS .h files on native
 ## systems.
 if NATIVE
 if MAINTAINER_MODE
-noinst_PROGRAMS = gen-from-JIS
+maintainer_programs = gen-from-JIS
 endif
 endif 
 
-CONVERT_DIR = gnu/gcj/convert
+noinst_PROGRAMS = fixlines $(maintainer_programs)
 
 jv_convert_SOURCES =
 EXTRA_jv_convert_SOURCES = $(convert_source_files)
@@ -482,7 +500,6 @@ $(srcdir)/$(CONVERT_DIR)/JIS0212.h:  # $
 	>> tmp-0212; \
 	mv tmp-0212 $(srcdir)/$(CONVERT_DIR)/JIS0212.h
 
-
 gen_from_JIS_SOURCES =
 EXTRA_gen_from_JIS_SOURCES = $(srcdir)/$(CONVERT_DIR)/gen-from-JIS.c \
 		$(srcdir)/$(CONVERT_DIR)/make-trie.c \
@@ -548,7 +565,7 @@ gnu/gcj/convert/UnicodeToBytes.java
 
 ## List of all .java files for which the .h file is maintained by
 ## hand.
-special_java_source_files = java/lang/Class.java java/lang/Object.java
+special_java_source_files = java/lang/Object.java
 
 awt_java_source_files =	\
 gnu/awt/LightweightRedirector.java \
@@ -788,8 +805,25 @@ java/beans/Visibility.java
 
 ## Java files which are created by configure and thus are in the build
 ## directory.
-built_java_source_files = java/lang/ConcreteProcess.java \
-                          gnu/classpath/Configuration.java
+ordinary_built_java_source_files = java/lang/ConcreteProcess.java \
+	gnu/classpath/Configuration.java
+
+## Java files which are created at make time through preprocessing and
+## have a header file in the source directory.
+special_preprocessed_java_source_files = java/lang/Class.java
+
+## Java files which are created at make time through preprocessing and
+## need to have a header file generated.
+ordinary_preprocessed_java_source_files =
+
+## All preprocessed java source files.
+preprocessed_java_source_files = $(special_preprocessed_java_source_files) \
+	$(ordinary_preprocessed_java_source_files)
+
+$(preprocessed_java_source_files): fixlines
+
+built_java_source_files = $(preprocessed_java_source_files) \
+	$(ordinary_built_java_source_files) 
 
 ## Java files in the core packages java.lang, java.io, and java.util.
 ## These are built before the other source files, in order to reduce 





And here's the new file.....

---- cut here -------------------------------------------------------------
/* fixlines.c - make .java source lines match up with .jpp source lines
   Copyright (C) 2001
   Free Software Foundation, Inc.

This file is part of GNU CC.

GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main ()
{
  char buf[BUFSIZ];
  int line = 1, fline = 0;

  while (fgets (buf, BUFSIZ, stdin))
    {
      if (buf[0] == '#' && buf[1] == ' ')
	{
	  sscanf (&buf[2], "%d", &fline); 
	  while (line < fline)
	    {
	      line++;
	      puts ("// This line has been preprocessed out.");
	    }
	}
      else
	{
	  line++;
	  fwrite (buf, 1, strlen (buf), stdout);
	}
    }

  exit (EXIT_SUCCESS);
}

---- cut here -------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]