<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>+cfe-dev</p>
<p>The people familiar with clang-format are more likely active
there :)<br>
</p>
<br>
<div class="moz-cite-prefix">Am 17.04.2018 um 09:40 schrieb Daniel
via cfe-users:<br>
</div>
<blockquote type="cite"
cite="mid:fc4818c5-a7c1-64a0-dad1-a00c3f915bff@fagerlie.org">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<p>Hello, </p>
<p>For the senior project in my undergraduate studies, my team and
I are developing a tool that will evaluate the format and code
conventions of a c++ program, outputting a score and displaying
useful messages, very much like pylint for python. <br>
</p>
<p>The idea is kind of like clang-format except no alterations to
the code should be made. The tool would be used as a teaching
aid and automatic grader. To handle the beautiful diversity of
c++, it shouldn't constrain the author to any particular style
(although it should be able to do that too). For example: open
curly braces on same line as function declaration compared to
having them on a new line. In this case, the tool could check
for consistency only. As long as the entire file has the same
format, you will get a perfect score. If, however, there are 10
places of braces on same line and 9 on newline, there will be a
penalty to the score, larger than if 18 on same line and 1 on
newline. The idea is to enforce consistency without getting in
the way of authors preferred style. This should give professors
a robust tool to teach c++.</p>
<p>I was hoping the clang community could help me understand the
inner workings of clang a little bit better. Right now, my
hangup is trying to get format data to work in conjunction with
clangs AST. What I'm trying to do is get back the whitespace,
comment, and bracket information that is loss during AST
buildup. Suppose I want to check that all operators have
consistent spacing format, something like "(2 * 2)" verses
"(2*2)" verses "(2* 2)". The AST will be used to get the
semantics of that particular operator so as to not get it
confused with the array pointer operator, but I need to count
the operator whitespace prefix and postfix. The same concept
will be applied to statement whitespace circumfixs. If done
right, I should be able to refer to all operators the same way
no matter the complexity of the expression. Something like "(x -
4) / 3 * (2 +1)" would show an inconsistency in the end part "(2
+1)" because of a missing space. <br>
</p>
<p>My first thought was to use the SourceManager locational
information to point back to the source code, then process and
identify the whitespace from there; However, this seems wildly
inefficient and inelegant. My second thought was to somehow get
clang to keep the whitespace information and add it to the AST,
but I believe there are inherent difficulties with that.</p>
<p>My biggest problem is lack of expertise within clangs source
code. Does anybody have any ideas on how I can get clang to give
me the information I need to support the above functionality?</p>
<p>Thanks for any interest. I hope this is an appropriate mailing
list to post my question.</p>
<p>Daniel.<br>
</p>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cfe-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-users@lists.llvm.org">cfe-users@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a>
</pre>
</blockquote>
<br>
</body>
</html>