<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
</style>
</head>
<body class='hmmessage'>
<div>Ok, I've found a solution for now (is not neateful, but works for me :-) ).</div><div>Thank you all for the tips!</div><div><br></div><div><div>void RewriteFunctiont(FunctionDecl *FD) </div><div><span class="Apple-tab-span" style="white-space: pre; ">       </span>{</div><div><span class="Apple-tab-span" style="white-space: pre; ">         </span>//Get the start location of the function name</div><div><span class="Apple-tab-span" style="white-space: pre; ">             </span>SourceLocation loc = FD->getLocStart();</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">               </span>// Decompose the location into a FID/Offset pair.</div><div><span class="Apple-tab-span" style="white-space: pre; ">         </span>std::pair<FileID, unsigned> LocInfo = Context->getSourceManager().getDecomposedLoc(loc);</div><div><span class="Apple-tab-span" style="white-space: pre; ">         </span>FileID FID = LocInfo.first;</div><div><span class="Apple-tab-span" style="white-space: pre; ">               </span>unsigned FileOffset = LocInfo.second, offset = 0;</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>// Get information about the buffer it points into.</div><div><span class="Apple-tab-span" style="white-space: pre; ">               </span>std::pair<const char*, const char*> BufferInfo = Context->getSourceManager().getBufferData(FID);</div><div><span class="Apple-tab-span" style="white-space: pre; ">         </span>const char *BufStart = BufferInfo.first;</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">         </span>// Pointer to the buffer</div><div><span class="Apple-tab-span" style="white-space: pre; ">          </span>const char *TokPtr = BufStart+FileOffset;</div><div><span class="Apple-tab-span" style="white-space: pre; ">                         </span></div><div><span class="Apple-tab-span" style="white-space: pre; ">          </span>//Advance to the parameter list</div><div><span class="Apple-tab-span" style="white-space: pre; ">           </span>while(*TokPtr != '(' && *TokPtr != NULL) </div><div><span class="Apple-tab-span" style="white-space: pre; ">            </span>{</div><div><span class="Apple-tab-span" style="white-space: pre; ">                 </span>TokPtr++;</div><div><span class="Apple-tab-span" style="white-space: pre; ">                 </span>offset++;</div><div><span class="Apple-tab-span" style="white-space: pre; ">         </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>//Insert as first parameters (listDeclaration contains the list of declarations to insert)</div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">               </span>int i = 0;</div><div><span class="Apple-tab-span" style="white-space: pre; ">                </span>for(std::list<std::string>::iterator it = listDeclaration.begin(); it != listDeclaration.end(); it++)</div><div><span class="Apple-tab-span" style="white-space: pre; ">          </span>{<span class="Apple-tab-span" style="white-space: pre; ">        </span></div><div><span class="Apple-tab-span" style="white-space: pre; ">                  </span>if(i > 0) Rewrite.InsertTextAfter(loc.getFileLocWithOffset(offset+1), ", ", 2);<br></div><div><br></div><div><span class="Apple-tab-span" style="white-space: pre; ">                   </span>Rewrite.InsertTextAfter(loc.getFileLocWithOffset(offset+1), (*it).c_str(), (*it).length());</div><div><span class="Apple-tab-span" style="white-space: pre; ">                     </span>i++;</div><div><span class="Apple-tab-span" style="white-space: pre; ">              </span>}</div><div><span class="Apple-tab-span" style="white-space: pre; ">         </span></div><div><span class="Apple-tab-span" style="white-space: pre; ">          </span>if(i && FD->param_size() > 0)</div><div><span class="Apple-tab-span" style="white-space: pre; ">               </span>{</div><div><span class="Apple-tab-span" style="white-space: pre; ">                 </span>Rewrite.InsertTextAfter(loc.getFileLocWithOffset(offset+1), ", ", 2);</div><div><span class="Apple-tab-span" style="white-space: pre; ">           </span>}</div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>}</div></div><br><br>> Date: Tue, 11 Aug 2009 09:45:15 -0700<br>> From: rjmccall@apple.com<br>> To: cfe-dev@cs.uiuc.edu<br>> Subject: Re: [cfe-dev] Function Rewriting<br>> <br>> Cédric Venet wrote:<br>> > I didn't respond earlier because I do not remember exactly the function <br>> > to use. I do not think this is a bug, but a design decision. it is <br>> > always only the start which is in the AST (for single token construct at <br>> > least), to get the end of the token, use a Lex function lextoken or <br>> > something like this. However, this is just my understanding. you can <br>> > check how the caret diagnostic are generated, it will show you the good <br>> > way to do what you want.<br>> > <br>> <br>> No, it's a bug. I'm not sure how that function works well enough to <br>> tell you if it works after the parse phase, but regardless, in C/C++, <br>> knowing the endpoint of the identifier token does not actually tell you <br>> where the end of the parameter declaration is.<br>> <br>> void apply(int count, int /*unused */, int array[], int <br>> (*function)(void ()) = &standard_callback);<br>> <br>> John.<br>> _______________________________________________<br>> cfe-dev mailing list<br>> cfe-dev@cs.uiuc.edu<br>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br><br /><hr />Instale o novo Internet Explorer 8 versão especial para o MSN.  <a href='http://ie8.msn.com/microsoft/internet-explorer-8/pt-br/ie8.aspx' target='_new'>Download aqui</a></body>
</html>