<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Nov 10, 2011, at 11:21 AM, Argyrios Kyrtzidis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Nov 10, 2011, at 10:49 AM, Ted Kremenek wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Nov 10, 2011, at 10:32 AM, Argyrios Kyrtzidis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div>+void CXLoadedDiagnostic::decodeLocation(CXSourceLocation location,<br>+ CXFile *file,<br>+ unsigned int *line,<br>+ unsigned int *column,<br>+ unsigned int *offset) {<br>+ <br>+ <br>+ // CXSourceLocation consists of the following fields:<br>+ //<br>+ // void *ptr_data[2];<br>+ // unsigned int_data;<br>+ //<br>+ // The lowest bit of ptr_data[0] is always set to 1 to indicate this<br>+ // is a persistent diagnostic.<br>+ //<br>+ // For now, do the unoptimized approach and store the data in a side<br>+ // data structure. We can optimize this case later.<br>+ <br>+ uintptr_t V = (uintptr_t) location.ptr_data[0];<br>+ assert((V & 0x1) == 1);<br>+ V &= ~(uintptr_t)1;<br>+ <br>+ const Location &Loc = *((Location*)V);<br>+ <br>+ if (file)<br>+ *file = Loc.file; <br>+ if (line)<br>+ *line = Loc.line;<br>+ if (column)<br>+ *column = Loc.column;<br>+ if (offset)<br>+ *offset = Loc.offset;<br>+}<br></div></blockquote><div><br></div><div>Is this modification to CXSourceLocation so that the diagnostic location becomes independent of a SourceManager ?</div></div></div></span></blockquote><div><br></div><div>Yes. The idea is that deserialized diagnostics don't have a source location. They don't actually need one since all this locations are raw physical locations anyway.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><br></div><div>Why not introduce a new kind of location (like CXFileLocation or something) instead ?</div></div></div></span></blockquote><div><br></div><div>I couldn't disagree with you more. Requiring clients to use a different set of mostly duplicate APIs for source locations which are just different under the hood seems like extremely poor API design to me. It makes the API verbose for no reason at all. Why should the client be concerned at all about how the CXSourceLocation is implemented under the hood as long as it provides the same functionality?</div></div></div></blockquote><div><br></div><div>I'm fine with abstracting under hood if the abstraction does not "leak"; if the plan is to make all the APIs that accept a CXSourceLocation work with this new kind that'd be great, otherwise it does not "provide the same functionality".</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><br></div><div>Keep in mind this would also require duplicating a bunch of the CXDiagnostics API to distinguish between diagnostics that have CXFileLocations and those that have CXSourceLocations.</div></div></div></blockquote><div><br></div><div>No, you make the CXDiagnostics API use just CXFileLocations. Otherwise you get in a situation where to know whether you can or cannot do stuff with CXSourceLocations you need to know where they came from.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div> If you remove the SourceManager you "disable" the functionality of CXSourceLocation anyway, e.g. while previously you could go through the expansion stack, get presumed location, etc., you can't do that with this new kind of location.</div></div></div></span></blockquote><div><br></div><div>Sorry, but I think that statement is not true. The prime use of CXSourceLocations is to query file, line, and column information. That is still supported.</div></div></div></blockquote><div><br></div><div>CXSourceLocation can do a lot more than that</div><div><br></div><div>We have</div><div><br></div><div>clang_getExpansionLocation(CXSourceLocation)</div><div>clang_getPresumedLocation(CXSourceLocation)</div><div>clang_getSpellingLocation(CXSourceLocation)</div><div><br></div><div>these are all different. There is also SourceManager::getFileLocation, which is currently not exposed by libclang but which could in the future, which is slightly different again (returns location of expansion or spelling depending on if the location is in a macro argument or not).</div><div><br></div><div>Also clang_getCursor(CXTranslationUnit, CXSourceLocation) does not work with the new kind.</div><div><br></div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div><br></div><div>We aren't disabling any functionality. Yes, we are losing the macro expansion trace and the inclusion stack, but the locations are actual locations. They are just the spelling locations. In the absence of macro expansions, these are the same exact locations that a client would see in the non-deserialized diagnostics case. One way to think of it is that the locations have been "pre-lowered" for consumption by a client that just wants to issue warnings at actual lines/columns in code. We can still include all the macro expansion goop, but pre-lower those as parts of the diagnostic instead of encoding them into the CXSourceLocations.</div></div></div></blockquote><div><br></div><div>So how do you see providing the macro expansion goop. Previously the client could use the clang_get*Location functions with a CXSourceLocation to get everything she is interested in.</div><div>If you are going to "pre-lower those as parts of the diagnostic", which means providing new API, what is the practical advantage of giving a CXSourceLocation for a diagnostic.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div> Seems better to be clear in the API.</div></div></div></blockquote><br></div><div>I think duplicating most (all) of the same CXSourceLocation APIs just to expose a detail that clients should not be thinking about anyway adds no clarity to the API.</div></div></blockquote><br></div><div>Currently the new kind only provides file, line, and column information; if there is no plan to support the other stuff you only need one new function for that.</div><br></div></blockquote></div><br><div>If the goal is to pre-lower for consumption, and not abstract everything about CXSourceLocation, the semantics of CXFileLocation could be that it is a "lowered" form and the client can get a CXSourceLocation out of CXTranslationUnit + CXFileLocation, so you really do not need to duplicate any other API.</div></body></html>