<div dir="ltr">Hello, Argyrios.<div><br></div><div>I'm android developer and unfortunately i am not skilled enough to develop compiler using c/cpp.</div><div>So AFAIK there is no such possibility now?</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">2014/1/10 Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Anton,<br>
<div class="im"><br>
On Jan 9, 2014, at 4:21 AM, Anton Smirnov <<a href="mailto:dev@antonsmirnov.name">dev@antonsmirnov.name</a>> wrote:<br>
<br>
> I'm working on code complete and i'd like to let the user see function parameters when he types function name or even already typed first parameters:<br>
><br>
> source code:<br>
><br>
>     void func(int a, int b) {<br>
>     }<br>
><br>
> user types:<br>
><br>
>     func(/*cursor here*/<br>
><br>
> or he forgots the second argument type:<br>
><br>
>     func(1, /*cursor here*/<br>
> and presses "show arguments"<br>
><br>
><br>
> is it possible to find according function(s) using Clang?<br>
><br>
> I've tried to find cursor and show info, but cursor kind is `CompoundStmt` and i can't find any function cursor for it.<br>
<br>
</div>This would be a really cool feature! If you are interested on working on it I’d suggest that the way to go is by enhancing our code completion machinery.<br>
Basically, we should have Sema completion also report the function call context (which function is getting called, which is the index of the parameter we are completing in, etc.), add it to the code-completion data and expose it through libclang.<br>

<br>
What do you think ?<br>
<div><div class="h5"><br>
><br>
> source code:<br>
><br>
>     CXIndex index2 = clang_createIndex(false, true);<br>
><br>
>         // unsaved file tu<br>
>         fprintf(stderr, "\nunsaved file =============\n");<br>
>         CXUnsavedFile *unsavedFile = new CXUnsavedFile;<br>
>         unsavedFile->Filename = "./temp.cpp";<br>
>         unsavedFile->Contents = "struct s { void func(int a) { return 1; }; }; void main() {s var; var.func(); }";<br>
><br>
>         unsavedFile->Length = strlen((char*)unsavedFile->Contents);<br>
><br>
>         CXTranslationUnit in_memory_tu = clang_parseTranslationUnit(index2, unsavedFile->Filename, 0, 0, unsavedFile, 1,<br>
>           CXTranslationUnit_None | CXTranslationUnit_Incomplete);<br>
>         int offset = atoi(argv[1]);<br>
>         showArguments(in_memory_tu, (char *)unsavedFile->Filename, offset); //line=1, column=74<br>
><br>
>         clang_disposeTranslationUnit(in_memory_tu);<br>
>         clang_disposeIndex(index2);<br>
><br>
>     // show arguments<br>
>     void showArguments(CXTranslationUnit TU, char *src_filename, int offset)<br>
>     {<br>
>         fprintf(stderr, "TU=%p, file=%s offset==%i\n", &TU, src_filename, offset);<br>
>         printSourceFileName("check TU filename", TU);<br>
><br>
>         CXFile file = clang_getFile(TU, src_filename);<br>
>         CXSourceLocation sourceLocation = clang_getLocationForOffset(TU, file, offset);<br>
>         CXCursor cursor = clang_getCursor(TU, sourceLocation);<br>
><br>
>         if (cursor.kind == CXCursor_InvalidCode || cursor.kind == CXCursor_InvalidFile) {<br>
>           fprintf(stderr, "NULL sursor found at %i\n", offset);<br>
>         } else {<br>
>           CXCursorKind kind = clang_getCursorKind(cursor);<br>
>           CXString kindSpelling = clang_getCursorKindSpelling(kind);<br>
>           CXString spelling = clang_getCursorSpelling(cursor);<br>
>           CXString name = clang_getCursorDisplayName(cursor);<br>
><br>
>           fprintf(stderr, "cursor found: kind=%i (%s) spelling=%s, name=%s\n",<br>
>             kind, clang_getCString(kindSpelling), clang_getCString(spelling), clang_getCString(name));<br>
><br>
>           clang_disposeString(kindSpelling);<br>
>           clang_disposeString(name);<br>
>           clang_disposeString(spelling);<br>
>         }<br>
>     }<br>
><br>
> output:<br>
><br>
> > MBA-Anton:build asmirnov$ ./clang_complete_function 76 Starting ----<br>
> ><br>
> > unsaved file ============= ./temp.cpp:1:31: error: void function<br>
> > 'func' should not return a value [-Wreturn-type] ./temp.cpp:1:47:<br>
> > error: 'main' must return 'int' ./temp.cpp:1:76: error: too few<br>
> > arguments to function call, single argument 'a' was not specified<br>
> > ./temp.cpp:1:12: note: 'func' declared here TU=0x7fff5dc11b58,<br>
> > file=./temp.cpp offset==76 check TU filename: [./temp.cpp] cursor<br>
> > found: kind=202 (CompoundStmt) spelling=, name=<br>
><br>
> Regards, Anton.<br>
</div></div>> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br>
</blockquote></div><br></div>