Quantcast

Header files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Header files

Rik-4
4/26/16

jwe,

Looks like we were working independently on cleaning up the header files.
See my cset here http://hg.savannah.gnu.org/hgweb/octave/rev/3f1bf237908b.

Is anyone on Octave-Maintainers aware of a tool that would help with the
drudge work of determining which header files are needed?

--Rik

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Header files

Mike Miller-4
On Wed, Apr 26, 2017 at 10:20:57 -0700, Rik wrote:
> Is anyone on Octave-Maintainers aware of a tool that would help with the
> drudge work of determining which header files are needed?

The llvm project has a tool called include-what-you-use (apt-get install
iwyu). I have only heard about it, haven't tried it yet.

  https://include-what-you-use.org/

--
mike

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Header files

Andreas Weber-6
In reply to this post by Rik-4
Am 26.04.2017 um 19:20 schrieb Rik:
> Is anyone on Octave-Maintainers aware of a tool that would help with the
> drudge work of determining which header files are needed?

I've used googles cppclean (https://github.com/myint/cppclean) for my
own projects but I don't know how easy it would be to run it on the
Octave source tree.

I tried
$ cppclean src libinterp liboctave | grep "does not need"
which runs since 30min now and the only output is

libinterp/corefcn/base-text-renderer.h:35: 'text-renderer.h' does not
need to be #included; use a forward declaration instead
libinterp/corefcn/call-stack.h:35: 'input.h' does not need to be #included
libinterp/corefcn/defun-dld.h:32: 'defun-int.h' does not need to be
#included
libinterp/corefcn/defun-int.h:32: 'symtab.h' does not need to be #included
libinterp/corefcn/defun.h:32: 'defun-int.h' does not need to be #included

-- Andy

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Header files

John W. Eaton
Administrator
In reply to this post by Rik-4
On 04/26/2017 01:20 PM, Rik wrote:

> Looks like we were working independently on cleaning up the header files.
> See my cset here http://hg.savannah.gnu.org/hgweb/octave/rev/3f1bf237908b.

Minimizing the #include statements so that we only include what is
needed is a good goal.

I was just trying to get all the header files to compile individually.
To do that, I was iterating over

   PATH=/tmp/install/dir/bin:$PATH
   rm -rf /tmp/install/dir
   make all && make install  ## with prefix=/tmp/install/dir

and then in a temporary directory, doing

   for ff in /tmp/install/dir/include/octave-4.3.0+/octave/*.h ; do
     f=$(basename $ff)
     echo $f
     echo "#include <$f>" > foo.cc
     mkoctfile -c foo.cc >& $f-log && rm -f $f-log
     rm -f foo.cc foo.o
   done

and adding forward declarations or additional #include lines until
almost all the header files compiled when included individually.  I
tried to use forward declarations where possible.

The only two that don't work properly for me now are mexproto.h and
ov-intx.h.

I'm not sure how to deal with mxArray in mexproto.h.  It is declared as
a class when mexproto.h is included in the Octave sources, or as void
for including in external code (the type is supposed to be opaque and
users aren't supposed to access it except through function calls).

For ov-intx.h, a number of macros are supposed to be defined before it
is included.  It's  not really supposed to be included separately.  That
the ov-{u,}int{8,16,23,64}.h files work is good enough.

Maybe it would be worth including some variation of these commands in a
Makefile rule, at least as a maintainer mode option.

jwe


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Header files

Mike Miller-4
On Wed, Apr 26, 2017 at 14:10:08 -0400, John W. Eaton wrote:

> The only two that don't work properly for me now are mexproto.h and
> ov-intx.h.
>
> I'm not sure how to deal with mxArray in mexproto.h.  It is declared as a
> class when mexproto.h is included in the Octave sources, or as void for
> including in external code (the type is supposed to be opaque and users
> aren't supposed to access it except through function calls).
>
> For ov-intx.h, a number of macros are supposed to be defined before it is
> included.  It's  not really supposed to be included separately.  That the
> ov-{u,}int{8,16,23,64}.h files work is good enough.

If you want more elegant error messages for these two particular cases,
we could add tests for the include guards from the other files that must
be included first, or for the number of macros in the ov-inx.h case,
with specific error messages.

For example if I write a program and try to include <bits/stdio.h>, I
get the error message

    Never include <bits/stdio.h> directly; use <stdio.h> instead.

--
mike

Loading...