This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Feature idea for c/c++: `#use' and `--recursive'


Hi,

After doing some projects in java, c, and c++, I imagined
two new features for the c and c++ languages.
They would be implemented as a new preprocessor directive, `#use',
and a new command line switch, `--recursive'.

I would like to get some feedback on my idea.
If I get mostly positive feedback, I will then go ahead
and implement it as a semester project at my school.
Maybe it can be merged into the main gcc tree later on.

The following is a description of my idea:

--------------------------------------------------------------------

New features `#use' and `--recursive':

The aim is to reduce c/c++ development time in the following ways:
- No need to create and maintain inter-project header files.
  They are created automatically from the source files.
- No need to search for library headers and shared libraries.
  Shared libraries are found the same way ld finds them,
  and the necessary header files are created automatically.
- Less need for makefiles: dependencies are found automatically.


Syntax for `#use':

#use "header.h" // same effect as #include "header.h"
#use "source.c" // same effect as #include "source.h" after
                //  creating an appropriate source.h for source.c
#use <library>  // same effect as #include "libheader.h"


Implementation of `#use':

Whenever cpp hits a #use directive, it looks what kind of file is
referenced:
- If it is a header file, it is directly included.
- If it is a source file, cpp starts the program `c2h', which creates a
   corresponding appropriate header file, which cpp then includes.
- If it is an object file, cpp starts the program `o2h', which creates a
   header file for that object file, which cpp then includes.
- If it is neither of the three, the preprocessor aborts with an error.

A header file foo.h created by c2h for an input file foo.c contains:
- some comments about the file having been created automatically
   (c2h only overwrites file containing this comment)
- #ifndef C2H_FOO_H, #define C2H_FOO_H, #endif //def C2H_FOO_H
- an `#include' directive for every `#include' and `#use' directive in foo.c
- a verbatim copy of every typedef, struct, class definition,
   and `#define' directive
- a function declaration for every function definition in foo.c,
   except for those that already have such a declaration (eg. methods)
- an `external' variable declaration for every global variable in foo.c

c2h doesn't have to recreate the header file at every recompilation.
If the source file's modification date is older than the header file's,
or if the interface didn't change, no recreation is necessary.
c2h indicates with its exit status wether it recreated the header file.
If the build directory isn't equal to the source directory,
c2h creates the header files in the build directory.

o2h does basically the same thing as c2h, except that it reads
the symbol tables of ELF files instead of c/c++ source files.


Implementation of `--recursive':

If gcc is invoked with the command line switch `--recursive' (or `-r'),
then all dependencies of the current source file on other source files
are looked at recursively, and any source file that doesn't have an
up-to-date object file is re-compiled. A file which has a dependency
on another file whose interface changed is treated as not up-to-date.

A dependency is found if a source file contains a `#use' directive
referencing another source file. For a `#use' directive referencing
another kind of file, the developer assumes the responsibility that
the referenced object is up-to-date. If it is in the same project,
the corresponding source file has to be referenced by the makefile.

If the compiler hits an `#include' directive with recursion activated,
it warns that the coresponding object files might not be up-to-date.
This is necessary so people trying to compile "old" projects with
`--recursive' are warned.

The linker then links all files that the recursion looked at,
including libraries referenced with `#use'.


Notes:

For simple projects with no configuration needs, the use of `#use'
and `--recursive' eliminates the need for header files and makefiles.
To recompile after changing something in a source file,
one only has to type: `gcc main.c -o foobar --recursive -Wall'.

`#use' has similar aims as the pragmas `interface' and `implementation'
in g++. However, there are two advantages of `#use':
- It works for c as well as for c++,
- The concerned functions don't have to be inlined.

c2h could be extended to accept an option to automatically create
documentation for a project, similar to javadoc. Such "header" files
would be stored in something like /usr/doc instead of /usr/include 

What needs to be developed for the features to work is:
- the utilities c2h and o2h
- a patch to the preprocessor cpp
- a patch to gcc/g++ to accept `-r' and treat cpp and ld accordingly
- documentation for the above

--------------------------------------------------------------------

Martin Schaffner
student at EPFL, Switzerland


-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!


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