<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 7, 2015 at 11:02 PM, Mattias Holm <span dir="ltr"><<a href="mailto:lorrden@openorbit.org" target="_blank">lorrden@openorbit.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have been using libclang (3.5 on Linux) for extracting information in headers. When parsing the following C99 code:<br>
<br>
---<br>
#include <stdbool.h><br>
bool foo(int a, int b);<br>
_Bool bar(int a, int b);<br>
---<br>
<br>
I manage to visit only the second function's arguments. When running my test app, I get the following output (code is below):<br>
<br>
visiting function: foo<br>
        type: int (int, int)<br>
        rettype: int<br>
visiting function: bar<br>
        type: _Bool (int, int)<br>
        rettype: _Bool<br>
        arg: a type: int<br>
        arg: b type: int<br>
<br>
As can be seen, firstly the type of foo is wrong, secondly, the argument visitor is never invoked<br>
<br>
I find this rather strange and I am wondering if there is something obviously wrong with my libclang based setup (i.e the main function), or if this is a known issue in libclang.</blockquote><div><br></div><div>What's probably happening is:</div><div><br></div><div>1) You turned off displaying of diagnostics and didn't specify anything else to do with them, so they're silently discarded, and</div><div>2) <stdbool.h> is not found.</div><div><br></div><div>The return type of 'int' is invented because lookup of 'bool' failed, and we don't bother to build the parameters for the invalid declaration of 'foo'.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I tried to search bugzilla, but found nothing similar.<br>
<br>
<br>
Cheers,<br>
Mattias<br>
<br>
<br>
My code...<br>
---<br>
#include "clang-c/Index.h"<br>
<br>
#include <stdio.h><br>
#include <stdlib.h><br>
<br>
enum CXChildVisitResult<br>
visitFuncParam(CXCursor Cursor, CXCursor Parent, CXClientData ClientData)<br>
{<br>
  CXType ArgTyp = clang_getCursorType(Cursor);<br>
  const char *ArgName = clang_getCString(clang_<u></u>getCursorSpelling(Cursor));<br>
  printf("\targ: %s type: %s\n",<br>
         ArgName, clang_getCString(clang_<u></u>getTypeSpelling(ArgTyp)));<br>
<br>
  return CXChildVisit_Continue;<br>
}<br>
<br>
<br>
enum CXChildVisitResult<br>
visitFuncDecl(CXCursor Cursor, CXCursor Parent, CXClientData ClientData)<br>
{<br>
  CXType FuncTyp = clang_getCursorType(Cursor);<br>
  const char *FuncName = clang_getCString(clang_<u></u>getCursorSpelling(Cursor));<br>
  CXType FuncRetTyp = clang_getResultType(FuncTyp);<br>
<br>
  printf("visiting function: %s\n", FuncName);<br>
  printf("\ttype: %s\n", clang_getCString(clang_<u></u>getTypeSpelling(FuncTyp)));<br>
  printf("\trettype: %s\n", clang_getCString(clang_<u></u>getTypeSpelling(FuncRetTyp)));<br>
<br>
  clang_visitChildren(Cursor, visitFuncParam, NULL);<br>
<br>
  return CXChildVisit_Continue;<br>
}<br>
<br>
enum CXChildVisitResult<br>
visitDecls(CXCursor Cursor, CXCursor Parent, CXClientData ClientData)<br>
{<br>
  CXSourceLocation SL = clang_getCursorLocation(<u></u>Cursor);<br>
<br>
  if (clang_Location_<u></u>isFromMainFile(SL)) {<br>
    if (clang_getCursorKind(Cursor) == CXCursor_FunctionDecl) {<br>
      visitFuncDecl(Cursor, Parent, NULL);<br>
    }<br>
  }<br>
  return CXChildVisit_Continue;<br>
}<br>
<br>
int<br>
main(int argc, const char *argv[argc])<br>
{<br>
  CXIndex Index = clang_createIndex(0, 0);<br></blockquote><div><br></div><div>Try setting the second parameter (displayDiagnostics) to 1 here to see the problem.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  CXTranslationUnit TU =<br>
    clang_parseTranslationUnit(<u></u>Index, 0, argv, argc, 0, 0,<br>
                               0);//CXTranslationUnit_<u></u>SkipFunctionBodies);<br>
<br>
  CXCursor C = clang_<u></u>getTranslationUnitCursor(TU);<br>
  clang_visitChildren(C, visitDecls, NULL);<br>
<br>
  clang_disposeTranslationUnit(<u></u>TU);<br>
  clang_disposeIndex(Index);<br>
<br>
  return 0;<br>
}<br>
---<br>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">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/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>