This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: coding style, continuing education
- To: Mike Stump <mrs at windriver dot com>
- Subject: Re: coding style, continuing education
- From: sidster <patrick at boxsoft dot com>
- Date: Tue, 16 Jan 2001 00:13:40 -0800
- Cc: gcc at gcc dot gnu dot org
- References: <200101152203.OAA29440@kankakee.wrs.com>
Greetings,
How about this style:
/* --- begin paste --- */
//
//
//
// Pretticized and grouped
//
// Note the "group_xxxxx" comments added. They'll make sense
// after you see the second attachment.
//
if
(
mode1 == VOIDmode
|| GET_CODE (op0) == REG
|| GET_CODE (op0) == SUBREG
|| ( /* group_0 */
modifier != EXPAND_CONST_ADDRESS
&& modifier != EXPAND_INITIALIZER
&& ( /* group_0_0 */
( /* group_0_1_0 */
mode1 != BLKmode
&& !direct_load[(int) mode1]
&& GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
&& GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
)
/* If the field isn't aligned enough to fetch as
a memref, fetch it as a bit field. */
|| ( /* group_0_1_1 */
mode1 != BLKmode
&& SLOW_UNALIGNED_ACCESS (mode1, alignment)
&& (
(
TYPE_ALIGN (TREE_TYPE (tem))
< GET_MODE_ALIGNMENT (mode)
)
|| (
bitpos % GET_MODE_ALIGNMENT (mode) != 0
)
)
)
/* If the type and the field are a constant size
and the size of the type isn't the same size as
the bitfield, we must use bitfield operations. */
|| ( /* group_0_1_2 */
(
bitsize >= 0
&& (
TREE_CODE (TYPE_SIZE (TREE_TYPE (exp)))
== INTEGER_CST
)
&& (
0 != compare_tree_int
(
TYPE_SIZE (TREE_TYPE (exp)),
bitsize
)
)
)
)
)
)
|| ( /* group_1 */
modifier != EXPAND_CONST_ADDRESS
&& modifier != EXPAND_INITIALIZER
&& mode == BLKmode
&& SLOW_UNALIGNED_ACCESS (mode, alignment)
&& (
TYPE_ALIGN (type) > alignment
|| bitpos % TYPE_ALIGN (type) != 0
)
)
)
{
printf( "And yes... we are done!\n" );
}
/* --- end paste --- */
The tabs are replaced with spaces since i never use tabs in my code
(tabs make printouts look like hell). But of course you can replace
every 4 spaces w/a tab character ( in vi :1,$s, ,^I,g ) if it is
a religious thing.
Of course, now you'd want to write "shorthand"ed versions of some of
the grouped code above to even make it more compact and readable (if
possible). [See attachments]
I'm attaching the source files:
one that is just "pretticized.c" and
the other "pretticized-and-broken-down.c"
Hope this helps and that the following was not a rhetorical questions:
> If people _know_ of a good way to split this down, maybe we all just
> need a refresher course on the right way, care to elaborate?
Otherwise, I'll feel like a total idiot spending time on this! >:-)
* Mike Stump (mrs@windriver.com) [20010115 14:04]:
> I know that historically gcc has had thousand line functions, and
> worse, but as time goes on we clean up the various sorts of code and
> make it prettier. It is just like the line formatting rules, see a
> line longer than 80, and one should just split on demand, not stopping
> to think twice about if they should do it or not. I'm tracking down a
> problem on an older compiler, and was traipsing around the code below.
> Icky. I think it would help if people realize that this code is like
> the > 80 character lines, one should just take a moment and split it
> down. I think we should all just agree that conditionals that run on
> past 20 or so lines should be split. Maybe we need a new gcc warning
> when the opening ( and the closing ) are more than 20 lines apart, we
> warn. We could also have a { } checker that will warn when they are
> more than, say 2000 lines apart. Someone want to work on a useful
> warning that will hit often? :-)
>
> If people _know_ of a good way to split this down, maybe we all just
> need a refresher course on the right way, care to elaborate?
>
>
> if (mode1 == VOIDmode
> || GET_CODE (op0) == REG || GET_CODE (op0) == SUBREG
> || (modifier != EXPAND_CONST_ADDRESS
> && modifier != EXPAND_INITIALIZER
> && ((mode1 != BLKmode && ! direct_load[(int) mode1]
> && GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
> && GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT)
> /* If the field isn't aligned enough to fetch as a memref,
> fetch it as a bit field. */
> || (mode1 != BLKmode
> && SLOW_UNALIGNED_ACCESS (mode1, alignment)
> && ((TYPE_ALIGN (TREE_TYPE (tem))
> < GET_MODE_ALIGNMENT (mode))
> || (bitpos % GET_MODE_ALIGNMENT (mode) != 0)))
> /* If the type and the field are a constant size and the
> size of the type isn't the same size as the bitfield,
> we must use bitfield operations. */
> || ((bitsize >= 0
> && (TREE_CODE (TYPE_SIZE (TREE_TYPE (exp)))
> == INTEGER_CST)
> && 0 != compare_tree_int (TYPE_SIZE (TREE_TYPE (exp)),
> bitsize)))))
> || (modifier != EXPAND_CONST_ADDRESS
> && modifier != EXPAND_INITIALIZER
> && mode == BLKmode
> && SLOW_UNALIGNED_ACCESS (mode, alignment)
> && (TYPE_ALIGN (type) > alignment
> || bitpos % TYPE_ALIGN (type) != 0)))
> {
patrick
--
It's a damn poor mind that can only think of one way to spell a word.
-- Andrew Jackson
//
//
//
// Pretticized and grouped
//
void
some_function( void )
{
/* ... */
if
(
mode1 == VOIDmode
|| GET_CODE (op0) == REG
|| GET_CODE (op0) == SUBREG
|| ( /* group_0 */
modifier != EXPAND_CONST_ADDRESS
&& modifier != EXPAND_INITIALIZER
&& ( /* group_0_0 */
( /* group_0_1_0 */
mode1 != BLKmode
&& !direct_load[(int) mode1]
&& GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
&& GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
)
/* If the field isn't aligned enough to fetch as
a memref, fetch it as a bit field. */
|| ( /* group_0_1_1 */
mode1 != BLKmode
&& SLOW_UNALIGNED_ACCESS (mode1, alignment)
&& (
(
TYPE_ALIGN (TREE_TYPE (tem))
< GET_MODE_ALIGNMENT (mode)
)
|| (
bitpos % GET_MODE_ALIGNMENT (mode) != 0
)
)
)
/* If the type and the field are a constant size
and the size of the type isn't the same size as
the bitfield, we must use bitfield operations. */
|| ( /* group_0_1_2 */
(
bitsize >= 0
&& (
TREE_CODE (TYPE_SIZE (TREE_TYPE (exp)))
== INTEGER_CST
)
&& (
0 != compare_tree_int
(
TYPE_SIZE (TREE_TYPE (exp)),
bitsize
)
)
)
)
)
)
|| ( /* group_1 */
modifier != EXPAND_CONST_ADDRESS
&& modifier != EXPAND_INITIALIZER
&& mode == BLKmode
&& SLOW_UNALIGNED_ACCESS (mode, alignment)
&& (
TYPE_ALIGN (type) > alignment
|| bitpos % TYPE_ALIGN (type) != 0
)
)
)
{
printf( "And yes... we are done!\n" );
}
/* ... */
}
//
//
//
// Most simplified
//
//
// Prototypes
//
// Of course one would have more meaningful names for the
// following functions :-)
//
// Also NOTE that here i've assumed all the arguments are of type
// int ... i'm not aware of GCC internals to know the exact arguments.
// Pardon my ignorance in this area. Fixing them shouldn't be any
// problem for any of you GCC gurus.
//
int
group_0
(
int modifier,
int mode1,
int mode,
int alignment,
int tem,
int bitsize,
int exp
);
int
group_1
(
int modifier,
int mode,
int alignment,
int type,
int bitops
);
void
some_function( void )
{
/* ... */
if
(
mode1 == VOIDmode
|| GET_CODE (op0) == REG
|| GET_CODE (op0) == SUBREG
|| group_0( mode1, mode, alignment,
tem, bitsize, exp, bitops )
|| group_1( modifier, mode1, mode,
alignment, tem, bitsize, exp )
)
{
printf( "And yes... we are done!\n" );
}
/* ... */
}
int
group_0_1_0( int mode1, int mode )
{
return
(
mode1 != BLKmode
&& !direct_load[(int) mode1]
&& GET_MODE_CLASS (mode) != MODE_COMPLEX_INT
&& GET_MODE_CLASS (mode) != MODE_COMPLEX_FLOAT
);
}
int
group_0_1_1
(
int mode1,
int mode,
int alignment,
int tem,
int bitops
)
{
return
(
mode1 != BLKmode
&& SLOW_UNALIGNED_ACCESS (mode1, alignment)
&& (
(
TYPE_ALIGN (TREE_TYPE (tem))
< GET_MODE_ALIGNMENT (mode)
)
|| (
bitpos % GET_MODE_ALIGNMENT (mode) != 0
)
)
);
}
int
group_0_1_2( int bitsize, int exp )
{
return
(
bitsize >= 0
&& (
TREE_CODE (TYPE_SIZE (TREE_TYPE (exp)))
== INTEGER_CST
)
&& (
0 != compare_tree_int
(
TYPE_SIZE (TREE_TYPE (exp)),
bitsize
)
)
);
}
int
group_0_0
(
int mode1,
int mode,
int alignment,
int tem,
int bitsize,
int exp,
int bitops
)
{
return
(
group_0_1_0( mode1, mode )
|| group_0_1_1( mode1, mode, alignment, tem, bitops )
|| group_0_1_2( bitsize, exp )
);
}
int
group_0
(
int modifier,
int mode1,
int mode,
int alignment,
int tem,
int bitsize,
int exp
)
{
return
(
modifier != EXPAND_CONST_ADDRESS
&& modifier != EXPAND_INITIALIZER
&& group_0_0 ( mode1, mode, alignment,
tem, bitsize, exp)
)
}
int
group_1
(
int modifier,
int mode,
int alignment,
int type,
int bitops
)
{
return
(
modifier != EXPAND_CONST_ADDRESS
&& modifier != EXPAND_INITIALIZER
&& mode == BLKmode
&& SLOW_UNALIGNED_ACCESS (mode, alignment)
&& (
TYPE_ALIGN (type) > alignment
|| bitpos % TYPE_ALIGN (type) != 0
)
);
}