C Code Beautifier and Parsing 
Author Message
 C Code Beautifier and Parsing

Hallo,

I'm looking for a C code beautifier, that do more than indent lines and
formating the code.
This beautifier should also calculate terms like ((0x0345)<<7)+34 and
replace them with the result.

Thanx,

Ciao
Steffen
--



Sat, 25 Jan 2003 03:00:00 GMT  
 C Code Beautifier and Parsing

Quote:

> This beautifier should also calculate terms like ((0x0345)<<7)+34 and
> replace them with the result.

Would you like it to erase your files and security-wipe the spot where they
were, too? That's probably safer...

--
 Phlip
======= http://users.deltanet.com/~tegan/home.html =======
--



Sat, 25 Jan 2003 03:00:00 GMT  
 C Code Beautifier and Parsing
The DMS Reengineering Toolkit can be used to automate
custom analyses and modifications to large software systems.
It uses generalized compiler technology to parse, transform,
and prettyprint ("beautify") changed (or unchanged!) sources.
DMS operates with many languages, including C and C++
with preprocessor directives.

"Simplify" is a special case of "transform".   As an example,
we have used DMS to simplify preprocessor conditionals.
This is accomplished by artifically treating certain #DEFINEs as false
(e.g., #DEFINE MSDOS 0), simplifiying the boolean
expressions in preprocessor conditionals, and eliminating
those conditionals (and associated code blocks)
whose formula evaluates to false.   The rest of the source
is prettyprinted (or fidelity-printed if you like).

See http://www.semdesigns.com/Products/DMS/DMSToolkit.html.

--

Semantic Designs, Inc., www.semdesigns.com FAX 512-250-1191
12636 Research Blvd #C214, Austin, Texas 78759


Quote:
> Hallo,

> I'm looking for a C code beautifier, that do more than indent lines and
> formating the code.
> This beautifier should also calculate terms like ((0x0345)<<7)+34 and
> replace them with the result.

> Thanx,

> Ciao
> Steffen
> --


--



Sat, 25 Jan 2003 03:00:00 GMT  
 C Code Beautifier and Parsing

Quote:

> I'm looking for a C code beautifier, that do more than indent lines and
> formating the code.
> This beautifier should also calculate terms like ((0x0345)<<7)+34 and
> replace them with the result.

Slightly off topic, but I don't think this makes the code more
beautiful.

For example, this code:

        percent_hours = total_hours / (365 * 24);

If I were reading the code, I'd rather see the equation, where the
values make some sense, than the result, which becomes a meaningless
number.

--

--



Sun, 26 Jan 2003 03:00:00 GMT  
 C Code Beautifier and Parsing

Quote:

> For example, this code:

>    percent_hours = total_hours / (365 * 24);

> If I were reading the code, I'd rather see the equation, where the
> values make some sense, than the result, which becomes a meaningless
> number.

If I were reading this code, I'd probably change it to
        percent_hours = total_hours / (365. * 24) * 100.;
and verify that percent_hours has a floating-point type (and
total_hours should probably be one too).  Alternatively, I might
rename percent_hours to fraction_hours.
--



Sun, 26 Jan 2003 03:00:00 GMT  
 C Code Beautifier and Parsing


Quote:
>Hallo,

>I'm looking for a C code beautifier, that do more than indent lines and
>formating the code.
>This beautifier should also calculate terms like ((0x0345)<<7)+34 and
>replace them with the result.

Then I expect you to be out of luck. Such a program would be hiding
information rather than displaying it in some consistent manner.

Francis Glassborow      Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
--



Sun, 26 Jan 2003 03:00:00 GMT  
 C Code Beautifier and Parsing

Quote:
> Hallo,
> I'm looking for a C code beautifier, that do more than indent lines and
> formating the code.
> This beautifier should also calculate terms like ((0x0345)<<7)+34 and
> replace them with the result.

That'd not be a beautifier, by any definition of 'beauty' in source
code I've seen. I'd rather call such a beast an obfuscator.

It would gain you nothing (assuming decent compilers), and create code
that is far less maintainable than the original. Esp. if the numbers
in that expression were proper #define'd macros, rather than 'magic
cookies'. IOW, I personally would immediately throw away any
'beautifier' that turns

        months = seconds / SECONDSPERDAY / DAY{*filter*}ONTH;

into

        months = seconds / 2629800;

In these days of freely available, highly optimizing compilers for
just about every existing platform, there's hardly any point in trying
to do this kind of micro-optimizations yourself. There are
overwhelming arguments *against* it, indeed.
--

Even if all the snow were burnt, ashes would remain.
--



Tue, 28 Jan 2003 03:00:00 GMT  
 C Code Beautifier and Parsing
Has anyone ever come across a C code beautifier that know what to do
with embedded SQL? Specifically, Oracle Pro*C source files?

My news server has a {*filter*} habit of losing articles. Please respond
with email and followup posts. Thanks.

On 08 Aug 2000 13:48:07 GMT, Steffan Guertler

Quote:

>Hallo,

>I'm looking for a C code beautifier, that do more than indent lines and
>formating the code.
>This beautifier should also calculate terms like ((0x0345)<<7)+34 and
>replace them with the result.

>Thanx,

>Ciao
>Steffen

--



Fri, 31 Jan 2003 03:00:00 GMT  
 C Code Beautifier and Parsing

Quote:

> Hallo,

> I'm looking for a C code beautifier, that do more than indent lines and
> formating the code.

> This beautifier should also calculate terms like ((0x0345)<<7)+34 and
> replace them with the result.

Presumably, this means that you have found a beautifier like GNU
"indent"[1] which translates badly formatted code into something that
doesn't create "beautiful new impediments to understanding"[2].

As to the second requirement, this is _a very bad idea_. Earlier
respondents have indicated, correctly, that this is the case, but
haven't explained why. So, allow me to offer MHO:

1) The use of "magic numbers" in software (in _any_ language) is a bad
idea and is _never_ justified. As indicated by earlier respondents,
DAYS_IN_MONTH tells you _exactly_ what the number means and helps to
inform you about the code whereas, say, 31 tells you nothing. Equally,
#define-d symbolic constants are easy to change - changing them in one
place effects the change everywhere, rather than having to hunt through
your source code for all occurences of, say 7, and having to decide,
every time you find one, whether it's the 7 that means "number of apples
in a bag" or the 7 which means "number of days in a week".

2) Replacing operations on manifest constants or literals _buys
nothing_. I admit that I am open to correction on this, but I would
imagine that the vast majority, if not all, C compilers perform
"constant folding"[3,p.595], one of the simplest and most easily
understood optimisations that could be asked of a compiler. Essentially,
this operation evaluates operations involving constants at compile-time
and uses this value in subsequent stages of compilation.

In synopsis, there is exactly zero run-time efficiency gain if you
"calculate terms" as you propose. The compile-time gain of a few
billionths of a second required to perform constant-folding by the
compiler is offset, by several orders of magnitude by:
    1) the time taken to run this code obfuscator, and
    2) the time it will cost in greatly diminished code readability
        (for development, maintenance, porting, upgrading, ...)

Basically, if you wrote code like the output of this "beautifier", as a
teacher I would give you a fail grade, and as an employer I would fire
you.

Hope this helps,

Emmet

References:
[1] GNU Indent: http://www.gnu.org/software/indent/
[2] "The Ten Commandments for C Programmers", Henry Spencer:
    http://www.plethora.net/~seebs/c/10com.html
[3] "Compilers (Principles, Techniques, and Tools)", 1st ed., 1986;
Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman; Addison-Wesley,
Reading Massachussetts;
--



Fri, 07 Feb 2003 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. C Code Beautifier and Parsing

2. Newbie: separate big .cs file into small .cs files

3. HELP: C code beautifier

4. Need C code formatter/beautifier

5. C Source code beautifier

6. ANN: C/C++ source code beautifier

7. C code beautifier

8. cb (C Beautifier) source code

9. C code beautifiers

10. ANN: New Source Code Beautifier

11. Pretty Printer / Code beautifier addon for VC?

12. C code beautifier, please

 

 
Powered by phpBB® Forum Software