Closed Bug 1093191 Opened 10 years ago Closed 10 years ago

Make .cpp files in editor/libeditor include their own .h file first

Categories

(Core :: DOM: Editor, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla37

People

(Reporter: dholbert, Assigned: dholbert)

Details

Attachments

(3 files)

We have a general best-practice that Foo.cpp's first #include should be for Foo.h (if Foo.h exists).

This lets us verify that Foo.h correctly forward-declares all the types that it uses.  (If it doesn't, then Foo.cpp will fail to compile.

Filing this bug on fixing up .cpp files in editor/libeditor to conform to this.
First: when bumping #includes up for this bug, I noticed that several of these files start with...
> #include <stdio.h>                      // for printf
...and yet don't use printf at all.

So, this patch drops those includes.
Assignee: nobody → dholbert
Status: NEW → ASSIGNED
Attachment #8516072 - Flags: review?(ehsan.akhgari)
Unsurprisingly, the "main" patch here (which I'll post next) caused build failures, because it caught some missing forward-decls / includes in the .h files.

This patch adds those missing forward-decls / includes, so that we can continue compiling.

(Note: I built with "ac_add_options --disable-unified-compilation" to catch these, since otherwise, unified compilation lets us cheat & have the things we need already declared/defined by previous .cpp files.)
Attachment #8516074 - Flags: review?(ehsan.akhgari)
Comment on attachment 8516074 [details] [diff] [review]
part 2: add missing forward-decls / #includes

>+++ b/editor/libeditor/nsHTMLEditUtils.h
> #ifndef nsHTMLEditUtils_h__
> #define nsHTMLEditUtils_h__
> 
>+#include "mozilla/Types.h"
> 

(In case it's not clear, this ^ include is to give us "int32_t", which this header uses in some function-signatures lower down.)
...and here's the main patch here -- making each .cpp file #include its own .h file first.
Attachment #8516075 - Flags: review?(ehsan.akhgari)
(FWIW, I looked for candidate .cpp files to fix here with the following shell command...

for cppfile in *cpp; do hfile=`echo $cppfile | sed "s/.cpp/.h/"`; echo; echo "***$cppfile***"; grep -B4 $hfile $cppfile; done

...and I skimmed the output for chunks with other #includes in grep's before-context from "-B4".)
(Try run is green.)
Attachment #8516072 - Flags: review?(ehsan.akhgari) → review+
Attachment #8516074 - Flags: review?(ehsan.akhgari) → review+
(In reply to Daniel Holbert [:dholbert] from comment #3)
> Comment on attachment 8516074 [details] [diff] [review]
> part 2: add missing forward-decls / #includes
> 
> >+++ b/editor/libeditor/nsHTMLEditUtils.h
> > #ifndef nsHTMLEditUtils_h__
> > #define nsHTMLEditUtils_h__
> > 
> >+#include "mozilla/Types.h"
> > 
> 
> (In case it's not clear, this ^ include is to give us "int32_t", which this
> header uses in some function-signatures lower down.)

You could just include <stdint.h> for that, right?
Attachment #8516075 - Flags: review?(ehsan.akhgari) → review+
(In reply to :Ehsan Akhgari (not reading bugmail, needinfo? me!) from comment #8)
> You could just include <stdint.h> for that, right?

Hmm, looks like it. Not sure why I'd thought I needed mfbt's Types.h for that. I'll sanity-check that w/ Try, and then land if all is well. Thanks for the review!
Flags: needinfo?(dholbert)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: