summaryrefslogtreecommitdiffstats
path: root/clang/tools/CIndex/CIndex.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Rename 'CIndex' to 'libclang', since it has basically become our stable publicDaniel Dunbar2010-04-301-2598/+0
| | | | | | (C) API, and will likely grow further in this direction in the future. llvm-svn: 102779
* Teach clang_getLocation() to cope with a NULL file argument.Douglas Gregor2010-04-301-2/+2
| | | | llvm-svn: 102748
* Completely reimplement __builtin_offsetof, based on a patch by RobertoDouglas Gregor2010-04-281-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Amadini. This change introduces a new expression node type, OffsetOfExpr, that describes __builtin_offsetof. Previously, __builtin_offsetof was implemented using a unary operator whose subexpression involved various synthesized array-subscript and member-reference expressions, which was ugly and made it very hard to instantiate as a template. OffsetOfExpr represents the AST more faithfully, with proper type source information and a more compact representation. OffsetOfExpr also has support for dependent __builtin_offsetof expressions; it can be value-dependent, but will never be type-dependent (like sizeof or alignof). This commit introduces template instantiation for __builtin_offsetof as well. There are two major caveats to this patch: 1) CodeGen cannot handle the case where __builtin_offsetof is not a constant expression, so it produces an error. So, to avoid regressing in C, we retain the old UnaryOperator-based __builtin_offsetof implementation in C while using the shiny new OffsetOfExpr implementation in C++. The old implementation can go away once we have proper CodeGen support for this case, which we expect won't cause much trouble in C++. 2) __builtin_offsetof doesn't work well with non-POD class types, particularly when the designated field is found within a base class. I will address this in a subsequent patch. Fixes PR5880 and a bunch of assertions when building Boost.Python tests. llvm-svn: 102542
* Make TemplateDecl and ObjCContainerDecl abstractDouglas Gregor2010-04-221-4/+0
| | | | llvm-svn: 102145
* Overhaul the AST representation of Objective-C message sendDouglas Gregor2010-04-211-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | expressions, to improve source-location information, clarify the actual receiver of the message, and pave the way for proper C++ support. The ObjCMessageExpr node represents four different kinds of message sends in a single AST node: 1) Send to a object instance described by an expression (e.g., [x method:5]) 2) Send to a class described by the class name (e.g., [NSString method:5]) 3) Send to a superclass class (e.g, [super method:5] in class method) 4) Send to a superclass instance (e.g., [super method:5] in instance method) Previously these four cases where tangled together. Now, they have more distinct representations. Specific changes: 1) Unchanged; the object instance is represented by an Expr*. 2) Previously stored the ObjCInterfaceDecl* referring to the class receiving the message. Now stores a TypeSourceInfo* so that we know how the class was spelled. This both maintains typedef information and opens the door for more complicated C++ types (e.g., dependent types). There was an alternative, unused representation of these sends by naming the class via an IdentifierInfo *. In practice, we either had an ObjCInterfaceDecl *, from which we would get the IdentifierInfo *, or we fell into the case below... 3) Previously represented by a class message whose IdentifierInfo * referred to "super". Sema and CodeGen would use isStr("super") to determine if they had a send to super. Now represented as a "class super" send, where we have both the location of the "super" keyword and the ObjCInterfaceDecl* of the superclass we're targetting (statically). 4) Previously represented by an instance message whose receiver is a an ObjCSuperExpr, which Sema and CodeGen would check for via isa<ObjCSuperExpr>(). Now represented as an "instance super" send, where we have both the location of the "super" keyword and the ObjCInterfaceDecl* of the superclass we're targetting (statically). Note that ObjCSuperExpr only has one remaining use in the AST, which is for "super.prop" references. The new representation of ObjCMessageExpr is 2 pointers smaller than the old one, since it combines more storage. It also eliminates a leak when we loaded message-send expressions from a precompiled header. The representation also feels much cleaner to me; comments welcome! This patch attempts to maintain the same semantics we previously had with Objective-C message sends. In several places, there are massive changes that boil down to simply replacing a nested-if structure such as: if (message has a receiver expression) { // instance message if (isa<ObjCSuperExpr>(...)) { // send to super } else { // send to an object } } else { // class message if (name->isStr("super")) { // class send to super } else { // send to class } } with a switch switch (E->getReceiverKind()) { case ObjCMessageExpr::SuperInstance: ... case ObjCMessageExpr::Instance: ... case ObjCMessageExpr::SuperClass: ... case ObjCMessageExpr::Class:... } There are quite a few places (particularly in the checkers) where send-to-super is effectively ignored. I've placed FIXMEs in most of them, and attempted to address send-to-super in a reasonable way. This could use some review. llvm-svn: 101972
* Keep proper source location information for the type in an Objective-CDouglas Gregor2010-04-201-0/+6
| | | | | | @encode expression. llvm-svn: 101907
* Add cursor kind for C++ methods.Ted Kremenek2010-04-131-0/+2
| | | | llvm-svn: 101193
* Add 'clang_getCursorLanguage' to return the "language" of the AST element ↵Ted Kremenek2010-04-121-0/+63
| | | | | | (e.g., distinguish between C and Objective-C language features). Currently this only returns results for declarations. llvm-svn: 101070
* Prune includes.Benjamin Kramer2010-04-121-1/+4
| | | | llvm-svn: 101059
* Add CIndex support for blocks.Ted Kremenek2010-04-111-2/+19
| | | | llvm-svn: 100989
* Fix CIndex crash on invalid code reported in <rdar://problem/7833619>.Ted Kremenek2010-04-071-2/+3
| | | | llvm-svn: 100589
* Make Diagnostic reference-counted, which is simpler than jugglingDouglas Gregor2010-04-051-3/+4
| | | | | | maybe-ownership vs. ownership. llvm-svn: 100498
* Match MemoryBuffer API changes.Chris Lattner2010-04-051-3/+2
| | | | llvm-svn: 100484
* Clarify the ownership semantics of the Diagnostic object used byDouglas Gregor2010-04-051-9/+5
| | | | | | | | | ASTUnit. Previously, we would end up with use-after-free errors because the Diagnostic object would be creating in one place (say, CIndex) and its ownership would not be transferred into the ASTUnit. Fixes <rdar://problem/7818608>. llvm-svn: 100464
* Minor ASTUnit cleanups:Douglas Gregor2010-04-051-3/+3
| | | | | | | | - Rename "Diagnostics" and related to "StoredDiagnostics", to better capture what we're actually storing. - Move SourceManager and FileManager to the heap. llvm-svn: 100441
* Code completion results that refer to macros now get the cursor kindDouglas Gregor2010-04-051-1/+1
| | | | | | | of macro definitions when passed to CIndex. Add test for code completion of macros via CIndex. llvm-svn: 100431
* Return translation units from clang_createTranslationUnitFromSource()Ted Kremenek2010-03-261-2/+1
| | | | | | if even they contain errors. llvm-svn: 99594
* Use the cursor's ASTContext rather than the ASTContext computed from aDouglas Gregor2010-03-221-2/+2
| | | | | | | declaration, just in case invalid code makes the latter incorrect. This may be the cause behind <rdar://problem/7777070>. llvm-svn: 99179
* Fix unused variable warning.Daniel Dunbar2010-03-201-2/+1
| | | | llvm-svn: 99021
* Optimize region-of-interest based cursor walks through theDouglas Gregor2010-03-201-6/+49
| | | | | | | | preprocessed entities by grouping preprocessed entities by file ID. This drastically improves performance of repeated clang_getCursor() calls local tests, although it is a bit ugly. llvm-svn: 99015
* Implement serialization and lazy deserialization of the preprocessingDouglas Gregor2010-03-191-24/+9
| | | | | | | | | | | | | | | | | | | | | | | | record (which includes all macro instantiations and definitions). As with all lay deserialization, this introduces a new external source (here, an external preprocessing record source) that loads all of the preprocessed entities prior to iterating over the entities. The preprocessing record is an optional part of the precompiled header that is disabled by default (enabled with -detailed-preprocessing-record). When the preprocessor given to the PCH writer has a preprocessing record, that record is written into the PCH file. When the PCH reader is given a PCH file that contains a preprocessing record, it will be lazily loaded (which, effectively, implicitly adds -detailed-preprocessing-record). This is the first case where we have sections of the precompiled header that are added/removed based on a compilation flag, which is unfortunate. However, this data consumes ~550k in the PCH file for Cocoa.h (out of ~9.9MB), and there is a non-trivial cost to gathering this detailed preprocessing information, so it's too expensive to turn on by default. In the future, we should investigate a better encoding of this information. llvm-svn: 99002
* Teach clang_getCursorKindSpelling() about CXCursor_InvalidCode.Ted Kremenek2010-03-191-0/+2
| | | | llvm-svn: 98982
* Make the CIndex API more resilient to being used on invalid code.Ted Kremenek2010-03-191-3/+4
| | | | llvm-svn: 98981
* Optionally store a PreprocessingRecord in the preprocessor itself, andDouglas Gregor2010-03-191-6/+9
| | | | | | tie its creation to a CC1 flag -detailed-preprocessing-record. llvm-svn: 98963
* Visit preprocessing elements (macro instantiations and macroDouglas Gregor2010-03-191-106/+48
| | | | | | | | definitions) as part of the translation unit, so that normal visitation, token-annotation, and cursor-at retrieval all see preprocessing elements. llvm-svn: 98935
* Revert 98907 since it is breaking buildbots.Bob Wilson2010-03-191-45/+106
| | | | | | | | --- Reverse-merging r98907 into '.': D test/Index/c-index-getCursor-pp.c U tools/CIndex/CIndex.cpp llvm-svn: 98929
* Visit preprocessing elements (macro instantiations and macroDouglas Gregor2010-03-191-106/+45
| | | | | | | | definitions) as part of the translation unit, so that normal visitation, token-annotation, and cursor-at retrieval all see preprocessing elements. llvm-svn: 98907
* Try to appease MSVC's standard libraryDouglas Gregor2010-03-181-0/+14
| | | | llvm-svn: 98878
* Try to appease MSVCDouglas Gregor2010-03-181-4/+4
| | | | llvm-svn: 98875
* Explicitly link macro instantiations to macro definitions in theDouglas Gregor2010-03-181-0/+8
| | | | | | | | preprocessing record. Use that link with clang_getCursorReferenced() and clang_getCursorDefinition() to match instantiations of a macro to the definition of the macro. llvm-svn: 98842
* Expose macro definitions as CIndex cursors. These can still only beDouglas Gregor2010-03-181-1/+25
| | | | | | generated by clang_annotateTokens(). llvm-svn: 98837
* Introduce the notion of a "preprocessing record", which keeps track ofDouglas Gregor2010-03-181-83/+55
| | | | | | | | | | | | | | | | | | | | | | | | the macro definitions and macro instantiations that are found during preprocessing. Preprocessing records are *not* generated by default; rather, we provide a PPCallbacks subclass that hooks into the existing callback mechanism to record this activity. The only client of preprocessing records is CIndex, which keeps track of macro definitions and instantations so that they can be exposed via cursors. At present, only token annotation uses these facilities, and only for macro instantiations; both will change in the near future. However, with this change, token annotation properly annotates macro instantiations that do not produce any tokens and instantiations of macros that are later undef'd, improving our consistency. Preprocessing directives that are not macro definitions are still handled by clang_annotateTokens() via re-lexing, so that we don't have to track every preprocessing directive in the preprocessing record. Performance impact of preprocessing records is still TBD, although it is limited to CIndex and therefore out of the path of the main compiler. llvm-svn: 98836
* More token-annotation experimentation, preprocessing the annotatedDouglas Gregor2010-03-181-11/+89
| | | | | | | token sequence to detect macro instantiations (that produce at least token). WIP. llvm-svn: 98826
* Experimental stab at using relexing to identify preprocessorDouglas Gregor2010-03-181-8/+116
| | | | | | | | directives while annotating tokens in CIndex. This functionality should probably be factored out of this routine, but we're not there yet. llvm-svn: 98786
* Audit all callers of SourceManager::getBufferData(); fix the one thatDouglas Gregor2010-03-161-0/+2
| | | | | | needs better error recovery. llvm-svn: 98667
* Let SourceManager::getBufferData return StringRef instead of a pair of two ↵Benjamin Kramer2010-03-161-8/+7
| | | | | | const char*. llvm-svn: 98630
* Give SourceManager a Diagnostic object with which to report errors,Douglas Gregor2010-03-161-11/+10
| | | | | | and start simplifying the interfaces in SourceManager that can fail. llvm-svn: 98594
* Introduce a new BufferResult class to act as the return type ofDouglas Gregor2010-03-151-6/+17
| | | | | | | | | | | | | | SourceManager's getBuffer() (and similar) operations. This abstract can be used to force callers to cope with errors in getBuffer(), such as missing files and changed files. Fix a bunch of callers to use the new interface. Add some very basic checks for file consistency (file size, modification time) into ContentCache::getBuffer(), although these checks don't help much until we've updated the main callers (e.g., SourceManager::getSpelling()). llvm-svn: 98585
* Revert 98439. There is a bad race condition in sys::Path::makeUnique on win32.Benjamin Kramer2010-03-131-4/+9
| | | | llvm-svn: 98452
* Make getTemporaryPath a static member of CIndexer and use it to replace ↵Benjamin Kramer2010-03-131-9/+4
| | | | | | | | tmpnam calls. This fixes linker warnings on linux. llvm-svn: 98439
* Implement clang_isUnexposed(), a predicate function to simplify filtering outTed Kremenek2010-03-081-0/+12
| | | | | | unexposed AST elements. llvm-svn: 97985
* Extend ObjCMessageExpr for class method sends with the source locationDouglas Gregor2010-03-081-0/+9
| | | | | | of the class name. llvm-svn: 97943
* Keep track of type source information in the return type of anDouglas Gregor2010-03-081-3/+4
| | | | | | | | | | Objective-C method declaration, e.g., for - (Foo *)myMethod; we now have TypeSourceInfo for the Foo*. llvm-svn: 97942
* Check if 'Unit' is NULL before trying to iterate over the diagnostics.Ted Kremenek2010-03-051-1/+2
| | | | | | | This obviates a null dereference that can occur when 'NumErrors' is not zero. llvm-svn: 97849
* Add clang version to crashtracer string.Ted Kremenek2010-03-051-1/+2
| | | | llvm-svn: 97848
* A little hack to identify unwanted concurrency in CIndexDouglas Gregor2010-03-051-0/+6
| | | | llvm-svn: 97831
* Add clang_getCursorLinkage(), which returns theTed Kremenek2010-03-031-0/+19
| | | | | | | underlying linkage for the entity referred to by a CXCursor. llvm-svn: 97646
* When given unsaved files in clang_createTranslationUnitFromSourceFile,Douglas Gregor2010-02-271-1/+1
| | | | | | | | | | copy the source buffers provided rather than referencing them directly, so that the caller can free those buffers immediately after calling clang_createTranslationUnitFromSourceFile(). Otherwise, we risk hitting those buffers later (when building source ranges, forming diagnostics, etc.). llvm-svn: 97296
* Fix bogus diagnostic format string.Daniel Dunbar2010-02-231-1/+1
| | | | llvm-svn: 96978
* Rework the CIndex API for displaying diagnostics. Instead of printingDouglas Gregor2010-02-221-4/+21
| | | | | | | the diagnostics to a FILE*, return a CXString containing the formatted diagnostic. llvm-svn: 96823
OpenPOWER on IntegriCloud