[cfe-dev] New to clang, and first observations

Andy Somerville andy.somerville at gmail.com
Wed Nov 4 22:48:32 PST 2009


Hi Clang community,

I just recently decided to dive into clang to get familiar. The
potential uses for such an awesome project are just too enticing not
to : ) There seem to be a lot of very cool features and I'm very excited to
see what I can do with it. I currently have my mind set on using it
for creating some simple code refactoring tools.

I was putting together an absolute barebones example to parse a simple
c file into an AST to get myself familiar when I noticed some changes
I could make that would make the code clearer for new comers(as well
as less coupled) and was thinking that I would make the changes while
I was digging and then offer them back when I had finished.

However, in watching the change logs in some of the very code I was
digging through I noticed that many of the function signatures were
being changed in the opposite direction of where I was thinking of
going. I thought perhaps then, maybe my changes might be unwanted/ not
agreed with.

A trivial example of what I might want to change would be from clang-cc.cpp:~886

current:
     InitializeSourceManager(Preprocessor &PP, const std::string &InFile)
to
proposed:
     InitializeSourceManager(SrcMgr &srcMgr, FileMgr &fileMgr, const
std::string &InFile)

The former takes in the Preprocessor, but doesn't need it per se. It
is only used to carry in references to the SourceManager and the
FileManager. While passing in the Preprocessor reduces the number of
arguments by one, doing so also makes implicit the input requirements,
which, for some unfamiliar person attempting to read the code, could
be better explicit. Furthermore, and perhaps more importantly it
unnecessarily couples the function to the Preprocessor class.

This is one trivial example outside of the library, but there are many
less trivial ones inside which may tend to move the code toward
unwanted coupling, and complicate its reuse for other projects.

So I'm wondering if my observations seem warranted to any of you, or
if I seem off-base.

Hopefully I'm not being to bold/forward in my first post to the list.


     Regards,
     Andy



More information about the cfe-dev mailing list