<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Apr 12, 2013, at 8:23 AM, "Siedlarek, Mikołaj" <<a href="mailto:m.siedlarek@nctz.net">m.siedlarek@nctz.net</a>> wrote:<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Fri, Apr 12, 2013 at 4:59 PM, Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>> wrote:<br><blockquote type="cite">On Apr 11, 2013, at 11:43 PM, "Siedlarek, Mikołaj" <<a href="mailto:m.siedlarek@nctz.net">m.siedlarek@nctz.net</a>> wrote:<br><br><blockquote type="cite">On Thu, Apr 11, 2013 at 7:22 PM, Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>> wrote:<br><blockquote type="cite">On Apr 5, 2013, at 4:20 AM, "Siedlarek, Mikołaj" <<a href="mailto:m.siedlarek@nctz.net">m.siedlarek@nctz.net</a>><br>wrote:<br><br>On Fri, Apr 5, 2013 at 12:37 PM, Siedlarek, Mikołaj<br><<a href="mailto:m.siedlarek@nctz.net">m.siedlarek@nctz.net</a>> wrote:<br><br>On Fri, Apr 5, 2013 at 12:22 AM, Argyrios Kyrtzidis <<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>><br>wrote:<br><br><br>On Apr 2, 2013, at 1:33 AM, Mikołaj Siedlarek <<a href="mailto:m.siedlarek@nctz.net">m.siedlarek@nctz.net</a>> wrote:<br><br>Hi,<br><br>I'm writing a simple code dependency analysis tool using libclang and I'm<br>missing some way of distinguishing system headers from user headers. I see<br>clang::DirectoryLookup::getDirCharacteristic() provides such interface, but<br>is there any way I could obtain this information using just libclang? My<br>tool is rather simple and I'd like to keep it that way - libclang seems to<br>be sufficient for the rest of my needs.<br><br><br>There is no way currently, but it should relatively easy, are you interested<br>in providing such a patch ?<br>The clang function you may need to look into using is<br>"SourceManager::isInSystemHeader(SourceLocation Loc)"<br>The libclang function would accept a CXTranslationUnit and a<br>CXSourceLocation.<br><br><br><br>How about this? That's the best and most elastic approach I could think of.<br><br><br>There was unnecessary CINDEX_LINKAGE in the first version of my patch.<br>Here's corrected one.<br><br><br>+  /**<br>+   * \brief System code which is implicitly 'extern "C"' in C++ mode<br>+   */<br>+  CXCharacteristicKind_ExternCSystem<br><br>This is very "legacy-hacky-compiler-specific"; I can't think of a reason<br>that a libclang client would need to know this.<br><br>I suggest just adding a<br>int clang_SourceLocation_isInSystemHeader(CXSourceLocation location)<br>function.<br></blockquote><br>I agree ExternCSystem may not be useful - I added it to mimic<br>underlaying library interface. Nevertheless, I don't think boolean<br>isInSystemHeader is enough. For example - in my program I need to know<br>whether given source location is in user code. !isInSystemHeader<br>wouldn't be enough, because there are also invalid locations like<br>built-in compiler declarations or anything really that has no<br>corresponding location in the source.<br></blockquote><br>To check for invalid locations you can do:<br>if (clang_equalLocations(Location, clang_getNullLocation()) {<br> // invalid<br>}<br></blockquote><br>I don't really think that's user/client-friendly approach to have a<br>combination of<br>different interface functions providing same information type, but I guess it's<br>your choice.</div></blockquote><div><br></div><div>From my viewpoint this is what your enum returning version did, it provided an additional way to determine if a source location was invalid, while there was already a standard one.</div><div>In general there are libclang functions to determine if an object is null/invalid and more functions to query information from the object. If all clang_is* functions were changed to return an enum to also cover the null/invalid case, this would be rather user unfriendly.</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Here's simple isInSystemHeader.<br></div></blockquote><div><br></div><div>Committed a modified patch in r179384, thanks!</div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br>--<span class="Apple-converted-space"> </span><br>Mikołaj Siedlarek<br><a href="mailto:m.siedlarek@nctz.net">m.siedlarek@nctz.net</a><br><span><file-characteristics-v3.diff></span></div></blockquote></div><br></body></html>