Commit Graph

1279 Commits

Author SHA1 Message Date
Ted Kremenek 84d2bd759f Remove clang_isDeclarationADefinition() since its functionality is already provided by clang_isCursorDefinition().
llvm-svn: 104138
2010-05-19 18:36:55 +00:00
Ted Kremenek 26bde774df Add clang support for IBOutletCollection.
llvm-svn: 104135
2010-05-19 17:38:06 +00:00
Ted Kremenek a10f12829f Add function 'clang_isTagDeclDefinition()' to allow clients of libclang to distinguish between
forward declarations and definitions of structs/classes/enums.

llvm-svn: 104075
2010-05-18 22:32:15 +00:00
Ted Kremenek 49be9e0819 Teach CursorVisitor about duplicate ObjCPropertyDecls that can arise because of a current
design limitation in how we handle Objective-C class extensions.  This was causing the CursorVisitor
to essentially visit an @property twice (once in the @interface, the other in the class extension).
Fixes <rdar://problem/7410145>.

llvm-svn: 104055
2010-05-18 21:09:07 +00:00
Ted Kremenek 0ed7549343 Fix missing '}'.
llvm-svn: 103966
2010-05-17 20:12:45 +00:00
Ted Kremenek 9cfe9e6a4a Add libclang function 'clang_CXXMethod_isStatic' to query of a C++ method
is declared static.

llvm-svn: 103963
2010-05-17 20:06:56 +00:00
John McCall 8b07ec253d Substantially alter the design of the Objective C type AST by introducing
ObjCObjectType, which is basically just a pair of
  one of {primitive-id, primitive-Class, user-defined @class}
with
  a list of protocols.
An ObjCObjectPointerType is therefore just a pointer which always points to
one of these types (possibly sugared).  ObjCInterfaceType is now just a kind
of ObjCObjectType which happens to not carry any protocols.

Alter a rather large number of use sites to use ObjCObjectType instead of
ObjCInterfaceType.  Store an ObjCInterfaceType as a pointer on the decl rather
than hashing them in a FoldingSet.  Remove some number of methods that are no
longer used, at least after this patch.

By simplifying ObjCObjectPointerType, we are now able to easily remove and apply
pointers to Objective-C types, which is crucial for a certain kind of ObjC++
metaprogramming common in WebKit.

llvm-svn: 103870
2010-05-15 11:32:37 +00:00
Ted Kremenek be4556f550 Change install_name for libclang.dylib to '@rpath/libclang.dylib'. Fixes <rdar://problem/7987039>.
llvm-svn: 103837
2010-05-14 23:50:33 +00:00
Ted Kremenek 6bca984b54 Add CXType and an initial set of supporting functions to libclang. This exposes details of
Clang's representation of the C type system to clients.  It is nowhere near complete, and will
be expanded on demand.

llvm-svn: 103809
2010-05-14 21:29:26 +00:00
Ted Kremenek d321413e3d Fold assertion into condition, as it does not hold all the time.
llvm-svn: 103716
2010-05-13 15:38:38 +00:00
Ted Kremenek 00da2b1546 Remove stale comment.
llvm-svn: 103696
2010-05-13 03:40:51 +00:00
Ted Kremenek 12e0f2937e Specially handle CaseStmts in CursorVisitor because they can be nested and walking them
can blow out the stack.

llvm-svn: 103687
2010-05-13 00:25:00 +00:00
Ted Kremenek 8278a32802 Re-apply r103581 with updated tests. It turns out we were computing bogus locations for
many things.

llvm-svn: 103583
2010-05-12 06:16:13 +00:00
Ted Kremenek a53bead8db Temporarily revert r103581 so I can fix the failing tests.
llvm-svn: 103582
2010-05-12 06:03:33 +00:00
Ted Kremenek 847941b1f4 Correctly check if a cursor is a declaration before returning its location/range in clang_getCursorLocation()/clang_getCursorExtent(). This fixes a horrible bug reported in
<rdar://problem/7961995> and <rdar://problem/7967123> where declarations with attributes
would get grossly annotated with the wrong tokens because the attribute would be interpreted
as if it was a Decl*.

llvm-svn: 103581
2010-05-12 06:00:25 +00:00
Ted Kremenek 7b2fcc3697 Remove debugging aids I did not intend to commit.
llvm-svn: 103578
2010-05-12 05:30:50 +00:00
Ted Kremenek 5d61614eab Adjust clang_annotateTokens() to correctly account for the TypeSourceInfo for DeclaratorDecls
when annotating tokens.  Fixes <rdar://problem/7971430>.

llvm-svn: 103577
2010-05-12 05:29:33 +00:00
Abramo Bagnara 6150c884df Merged Elaborated and QualifiedName types.
llvm-svn: 103517
2010-05-11 21:36:43 +00:00
Ted Kremenek 37c220c8ed Extend C++ usrs to include type mangling for tag decl arguments, indicating whether a method
is static, and mangling in the qualifers of the method.

llvm-svn: 103289
2010-05-07 20:39:40 +00:00
Ted Kremenek dacfc2eee6 Switch USR generation over from NamedDecl::getNameAsString() to NamedDecl::printName().
llvm-svn: 103285
2010-05-07 20:07:23 +00:00
Douglas Gregor 542ad31597 Add a stub frontend action for BoostCon, for next week's workshop.
llvm-svn: 103258
2010-05-07 15:41:56 +00:00
Ted Kremenek 586ff60cfc Add initial USR support for mangling in the types of C++ functions and methods.
llvm-svn: 103225
2010-05-07 01:04:32 +00:00
Ted Kremenek b80cba5d7d Add CXCursor support for LinkageSpecDecl (e.g., 'extern "C"').
llvm-svn: 103224
2010-05-07 01:04:29 +00:00
Ted Kremenek 0b4b46e3e1 Add USR support for C++ namespaces, and unify mangling of location information in USRs
for anonymous symbols.

llvm-svn: 103212
2010-05-06 23:38:28 +00:00
Ted Kremenek bd67fb208d Add CXCursor support for C++ namespaces.
llvm-svn: 103211
2010-05-06 23:38:21 +00:00
Ted Kremenek 680fe51e2c Rework clang_annotateTokens() to annotate tokens with information that more closely matches
clang_getCursor().  Tokens are now annotated with the cursor (for the matching AST element)
that most closely encompasses that token.

llvm-svn: 103064
2010-05-05 00:55:23 +00:00
Ted Kremenek 15cbc3a8a5 Map Objective-C keywords to CXToken_Keyword.
llvm-svn: 103063
2010-05-05 00:55:20 +00:00
Ted Kremenek 458c2f190a Move post-processing of token annotations to method in AnnotateTokensWorker.
llvm-svn: 103062
2010-05-05 00:55:17 +00:00
Ted Kremenek 63ac5999f1 Refactor visitor logic for clang_annotateTokens() into a worker class. No functionality change yet.
llvm-svn: 103061
2010-05-05 00:55:15 +00:00
Daniel Dunbar 832fc4a098 Fix NON_ANSI_COMPILE_FLAGS setting, for MSVC.
llvm-svn: 102811
2010-05-01 00:06:42 +00:00
Daniel Dunbar d5a2a073a0 Rename 'CIndex' to 'libclang', since it has basically become our stable public
(C) API, and will likely grow further in this direction in the future.

llvm-svn: 102779
2010-04-30 21:51:10 +00:00
Douglas Gregor 0925fbc3fd Teach clang_getLocation() to cope with a NULL file argument.
llvm-svn: 102748
2010-04-30 19:45:53 +00:00
Daniel Dunbar 9f84c7b600 Move include installation steps to better location, inside each include dir instead of at the top-level.
Also, don't set NO_INSTALL=1 for c-index-test.

llvm-svn: 102724
2010-04-30 17:59:38 +00:00
Ted Kremenek 3b9ad93a35 Add USR support for 'static inline' functions (which can be declared in header files).
Add USR support for 'static' functions and local variables, which can be handy for resolving named variables within a translation unit.

llvm-svn: 102641
2010-04-29 17:43:29 +00:00
Ted Kremenek 9825536eea Remove USRGenerator::VisitBlockDecl(). We don't need to generate USRs for blocks, since
they have no linkage and by definition are anonymous.

llvm-svn: 102640
2010-04-29 17:43:26 +00:00
Douglas Gregor 882211c1da Completely reimplement __builtin_offsetof, based on a patch by Roberto
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
2010-04-28 22:16:22 +00:00
Douglas Gregor a9f7c3263e CMake: Fix DESTDIR-related installation problem on Windows, from the
mysterious Elrood on IRC.

llvm-svn: 102435
2010-04-27 16:14:06 +00:00
Douglas Gregor ff1915208d Make TemplateDecl and ObjCContainerDecl abstract
llvm-svn: 102145
2010-04-22 23:35:25 +00:00
Zhongxing Xu 105dfb5a72 CXXNamedCastExpr is actually an abstract expression.
llvm-svn: 101994
2010-04-21 06:32:25 +00:00
Douglas Gregor 9a12919421 Overhaul the AST representation of Objective-C message send
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
2010-04-21 00:45:42 +00:00
Ted Kremenek 6d159c1060 Fix USRs for 'extern' variables declaration in functions/method bodies.
Fix USRs for @synthesize.
Add more USR tests.

llvm-svn: 101954
2010-04-20 23:15:40 +00:00
Douglas Gregor abd9e9689a Keep proper source location information for the type in an Objective-C
@encode expression. 

llvm-svn: 101907
2010-04-20 15:39:42 +00:00
Dan Gohman 145f3f1e83 Fix -Wcast-qual warnings.
llvm-svn: 101786
2010-04-19 16:39:44 +00:00
Benjamin Kramer b11416d061 Add raw_ostream operators to NamedDecl for convenience. Switch over all users of getNameAsString on a stream.
The next step is to print the name directly into the stream, avoiding a temporary std::string copy.

llvm-svn: 101632
2010-04-17 09:33:03 +00:00
Ted Kremenek cab334cc90 Send code completion data in json format.
llvm-svn: 101586
2010-04-17 00:21:42 +00:00
Ted Kremenek 551c178efc Remove unneeded assertion and don't return a null CXString.
llvm-svn: 101585
2010-04-17 00:21:38 +00:00
Ted Kremenek 7afa85b8fa Rework USR generation for symbols with no linkage. Many of the USRs are now shortened,
and we now include the file name that declares the symbol with no linkage in the USR.
USRs for such symbols are generated only in restructed cases, e.g., anonymous enum declarations,
typedefs, etc.

llvm-svn: 101542
2010-04-16 21:31:52 +00:00
Dan Gohman 314ca58a91 Convert libCIndex to use the new native EXPORTED_SYMBOL_FILE mechanism.
libCIndex also has a CMakeLists.txt file which has its own code for using
the exports file. To preserve existing functionality, create a separate
darwin-specific exports file for use by this CMakeLists.txt code.

llvm-svn: 101440
2010-04-16 04:45:02 +00:00
Ted Kremenek a96a8eebbb Better support USRs for anonymous enums, structs, by including the location where
the tag was declared.  WIP.

llvm-svn: 101403
2010-04-15 21:51:13 +00:00
Ted Kremenek 9833d399ce Do not generate USRs for declarations with 'no linkage' except for enums, structs, typedefs.
Those still need work to disambiguate them across translation units.

llvm-svn: 101401
2010-04-15 21:04:25 +00:00
Daniel Dunbar 76fa840d09 Driver/Frontend: Add support for -mllvm, which forwards options to the LLVM option parser.
- Note that this is a behavior change, previously -mllvm at the driver level forwarded to clang -cc1. The driver does a little magic to make sure that '-mllvm -disable-llvm-optzns' works correctly, but other users will need to be updated to use -Xclang.

llvm-svn: 101354
2010-04-15 06:09:03 +00:00
Ted Kremenek 9e0cf0978c Add optional timing logging for code completion results. This causes a UDP packet
containing the time taken for the code completion to be sent to a designated server
(which is specified using a compile-time -D flag).

llvm-svn: 101326
2010-04-15 01:02:28 +00:00
Ted Kremenek 225b8e39f1 Add cursor kind for C++ methods.
llvm-svn: 101193
2010-04-13 23:39:06 +00:00
Ted Kremenek 4ed2925b91 Add 'clang_getCursorLanguage' to return the "language" of the AST element (e.g., distinguish between C and Objective-C language features). Currently this only returns results for declarations.
llvm-svn: 101070
2010-04-12 21:22:16 +00:00
Ted Kremenek 601f6d5b59 Sort exports file.
llvm-svn: 101069
2010-04-12 21:22:10 +00:00
Benjamin Kramer 0644145373 Prune includes.
llvm-svn: 101059
2010-04-12 19:45:50 +00:00
Ted Kremenek 2908a20d86 Add initial USR support for macro definitions.
llvm-svn: 100997
2010-04-11 22:20:34 +00:00
Ted Kremenek 74c4389ea6 Augment clang_getCursorUSR() to not always expect that clang_getCursorDecl() does the right
thing if the cursor is not a decl (such as in the case of macros).

llvm-svn: 100996
2010-04-11 22:20:26 +00:00
Ted Kremenek 33b9a42f41 Add CIndex support for blocks.
llvm-svn: 100989
2010-04-11 21:47:37 +00:00
Benjamin Kramer 31160e8469 CIndex: move extractUSRSuffix out of extern "C" and simplify it.
llvm-svn: 100773
2010-04-08 15:54:07 +00:00
Daniel Dunbar 8ee6760971 Fronted: Kill overly specialized RecordLayoutDumper, just make -dump-record-layouts a bit that Sema honors.
llvm-svn: 100747
2010-04-08 02:59:56 +00:00
Chris Lattner 1f054ecca2 update for api change.
llvm-svn: 100718
2010-04-07 23:12:35 +00:00
Ted Kremenek 6ca136a77f Fix CIndex crash on invalid code reported in <rdar://problem/7833619>.
llvm-svn: 100589
2010-04-07 00:27:13 +00:00
Ted Kremenek 7deb7050d5 Fix ccc-analyzer's handling of quoted arguments in the build command. Fixes PR 6791.[B
llvm-svn: 100551
2010-04-06 19:41:24 +00:00
Chris Lattner 6d67213ebb reduce indentation, tidy.
llvm-svn: 100537
2010-04-06 17:52:14 +00:00
Douglas Gregor 7f95d26e53 Make Diagnostic reference-counted, which is simpler than juggling
maybe-ownership vs. ownership.

llvm-svn: 100498
2010-04-05 23:52:57 +00:00
Chris Lattner 61955ab200 inline in MC assembly parsers. clang -integrated-as now
works with inline asm!

llvm-svn: 100493
2010-04-05 23:33:20 +00:00
Chris Lattner 58c79341ab Match MemoryBuffer API changes.
llvm-svn: 100484
2010-04-05 22:42:27 +00:00
Douglas Gregor d03e823fb4 Clarify the ownership semantics of the Diagnostic object used by
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
2010-04-05 21:10:19 +00:00
Douglas Gregor a2433154c8 Minor ASTUnit cleanups:
- Rename "Diagnostics" and related to "StoredDiagnostics", to better
  capture what we're actually storing.
  - Move SourceManager and FileManager to the heap.

llvm-svn: 100441
2010-04-05 18:10:21 +00:00
Douglas Gregor f3df985ba7 Code completion results that refer to macros now get the cursor kind
of macro definitions when passed to CIndex. Add test for code
completion of macros via CIndex.

llvm-svn: 100431
2010-04-05 16:10:30 +00:00
Daniel Dunbar e43887bd2b Driver: Add support for a CLANGXX_IS_PRODUCTION build variable, which enable
Clang++ support, even in "Production" mode (for testing purposes).

llvm-svn: 100119
2010-04-01 18:21:41 +00:00
Douglas Gregor a771f46c82 Reinstate my CodeModificationHint -> FixItHint renaming patch, without
the C-only "optimization".

llvm-svn: 100022
2010-03-31 17:46:05 +00:00
Douglas Gregor 30e631862f Revert r100008, which inexplicably breaks the clang-i686-darwin10 builder
llvm-svn: 100018
2010-03-31 17:25:35 +00:00
Douglas Gregor 3baad0d4f7 Rename CodeModificationHint to FixItHint, since we've been using the
term "fix-it" everywhere and even *I* get tired of long names
sometimes. No functionality change.

llvm-svn: 100008
2010-03-31 15:31:50 +00:00
Douglas Gregor 171b780c91 Teach Clang's -cc1 option -print-stats to print LLVM statistics.
llvm-svn: 99894
2010-03-30 17:33:59 +00:00
Chris Lattner 09f8cc8c70 make -ftime-report work even in -disable-free mode. Woo, finally.
rdar://7781603

llvm-svn: 99878
2010-03-30 05:39:52 +00:00
Ted Kremenek d76197a271 scan-build: set environment variable LDPLUSPLUS to 'c++-analyzer' to correctly link projects
with c++ code.

llvm-svn: 99684
2010-03-27 00:20:01 +00:00
Ted Kremenek 014e70b797 Return translation units from clang_createTranslationUnitFromSource()
if even they contain errors.

llvm-svn: 99594
2010-03-26 01:34:51 +00:00
Ted Kremenek 599d73aa72 Add c-index-test support for printing USRs.
llvm-svn: 99476
2010-03-25 02:00:39 +00:00
Ted Kremenek f64a38907d Require that all Clang-based USRs start with the prefix 'c:' for the "USR space".
llvm-svn: 99475
2010-03-25 02:00:36 +00:00
Douglas Gregor 023da0d43a Make sure that we have File IDs for all of the unsaved files before we
deserialize diagnostics.

llvm-svn: 99426
2010-03-24 21:04:06 +00:00
Daniel Dunbar 30b24e95fa Frontend: Don't free the CompilerInstance or FrontendActions when running under
-disable-free. Among other things, this fixes freeing of the LLVM module on
exit.
 - Note that this means we are disable-free'ing of a lot more stuff than we used to -- this should flush out bugs in anything left that is trying to do real work in its destructor. I did a mini-audit but '::~' is not totally uncommon.

llvm-svn: 99258
2010-03-23 05:09:16 +00:00
Douglas Gregor 7bf6b8a416 Use the cursor's ASTContext rather than the ASTContext computed from a
declaration, just in case invalid code makes the latter
incorrect. This may be the cause behind <rdar://problem/7777070>.

llvm-svn: 99179
2010-03-22 15:53:50 +00:00
Kovarththanan Rajaratnam a0170209af Use DEFINE_SYMBOL property to control dllexport/dllimport
llvm-svn: 99176
2010-03-22 15:44:38 +00:00
Daniel Dunbar 6a8efa8a79 Driver: Support CC_PRINT_OPTIONS, used for logging the compile commands (in -v style) to a file.
llvm-svn: 99054
2010-03-20 08:01:59 +00:00
Daniel Dunbar aef1db1d71 Fix unused variable warning.
llvm-svn: 99021
2010-03-20 01:11:56 +00:00
Douglas Gregor 3dc10b530e Optimize region-of-interest based cursor walks through the
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
2010-03-20 00:41:21 +00:00
Douglas Gregor aae9224e49 Implement serialization and lazy deserialization of the preprocessing
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
2010-03-19 21:51:54 +00:00
Ted Kremenek 00da3b9a80 Teach clang_getCursorKindSpelling() about CXCursor_InvalidCode.
llvm-svn: 98982
2010-03-19 20:39:05 +00:00
Ted Kremenek e184ac5a66 Make the CIndex API more resilient to being used on invalid code.
llvm-svn: 98981
2010-03-19 20:39:03 +00:00
Daniel Dunbar 1c201fbf73 clang -cc1: Kill off -empty-input only, and replace with -init-only which is an
actual action.
 - This is easier to use, and more reliable for timing the thing this was
   actually meant to be useful for.

llvm-svn: 98978
2010-03-19 19:44:04 +00:00
Douglas Gregor 7f6d60dcc2 Optionally store a PreprocessingRecord in the preprocessor itself, and
tie its creation to a CC1 flag -detailed-preprocessing-record.

llvm-svn: 98963
2010-03-19 16:15:56 +00:00
Douglas Gregor 5272e80ce5 Visit preprocessing elements (macro instantiations and macro
definitions) as part of the translation unit, so that normal
visitation, token-annotation, and cursor-at retrieval all see
preprocessing elements.

llvm-svn: 98935
2010-03-19 05:22:59 +00:00
Bob Wilson 4f559a3042 Revert 98907 since it is breaking buildbots.
--- Reverse-merging r98907 into '.':
D    test/Index/c-index-getCursor-pp.c
U    tools/CIndex/CIndex.cpp

llvm-svn: 98929
2010-03-19 03:57:57 +00:00
Douglas Gregor 20004ee7d2 Visit preprocessing elements (macro instantiations and macro
definitions) as part of the translation unit, so that normal
visitation, token-annotation, and cursor-at retrieval all see
preprocessing elements.

llvm-svn: 98907
2010-03-19 00:18:31 +00:00
Douglas Gregor e56c353eb1 Try to appease MSVC's standard library
llvm-svn: 98878
2010-03-18 21:28:30 +00:00
Douglas Gregor 5810ead358 Try to appease MSVC
llvm-svn: 98875
2010-03-18 21:25:12 +00:00
Douglas Gregor 78ae2481b6 Explicitly link macro instantiations to macro definitions in the
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
2010-03-18 18:23:03 +00:00
Douglas Gregor 06d6d32762 Expose macro definitions as CIndex cursors. These can still only be
generated by clang_annotateTokens().

llvm-svn: 98837
2010-03-18 18:04:21 +00:00
Douglas Gregor 065f8d11ca Introduce the notion of a "preprocessing record", which keeps track of
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
2010-03-18 17:52:52 +00:00
Douglas Gregor 02ded2a56c More token-annotation experimentation, preprocessing the annotated
token sequence to detect macro instantiations (that produce at least
token). WIP.

llvm-svn: 98826
2010-03-18 15:23:44 +00:00
Douglas Gregor 92a524fd47 Experimental stab at using relexing to identify preprocessor
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
2010-03-18 00:42:48 +00:00
Douglas Gregor 554e0b1ec2 Audit all callers of SourceManager::getBufferData(); fix the one that
needs better error recovery.

llvm-svn: 98667
2010-03-16 20:26:15 +00:00
Benjamin Kramer eb92dc0b09 Let SourceManager::getBufferData return StringRef instead of a pair of two const char*.
llvm-svn: 98630
2010-03-16 14:14:31 +00:00
Douglas Gregor e0fbb83b8b Give SourceManager a Diagnostic object with which to report errors,
and start simplifying the interfaces in SourceManager that can fail.

llvm-svn: 98594
2010-03-16 00:06:06 +00:00
Douglas Gregor 802b77601e Introduce a new BufferResult class to act as the return type of
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
2010-03-15 22:54:52 +00:00
Ted Kremenek bc1a67bee3 Rename clang_constructUSR_ObjCategory to clang_constructUSR_ObjCCategory.
(there was a missing 'C').

llvm-svn: 98554
2010-03-15 17:38:58 +00:00
Anton Korobeynikov 762c6b7346 Fix thinko and enable clang build on mingw again (hopefully)
llvm-svn: 98492
2010-03-14 12:55:35 +00:00
Benjamin Kramer f156b9d55d Revert 98439. There is a bad race condition in sys::Path::makeUnique on win32.
llvm-svn: 98452
2010-03-13 21:22:49 +00:00
Benjamin Kramer 84c37f9903 Make getTemporaryPath a static member of CIndexer and use it to replace tmpnam calls.
This fixes linker warnings on linux.

llvm-svn: 98439
2010-03-13 13:05:20 +00:00
Ted Kremenek d071c6019a Implement several CIndex functions for constructing USRs from C-strings instead of AST elements.
llvm-svn: 98421
2010-03-13 02:50:34 +00:00
Jeffrey Yasskin f6442f80cb Allow users to set CPPFLAGS and CXXFLAGS on the make command line.
Tested: make CPPFLAGS=-m64 CXXFLAGS=-m64 -j8 && (cd tools/clang;make test)
llvm-svn: 98399
2010-03-12 22:55:16 +00:00
Ted Kremenek ff9021b675 Implement clang_isUnexposed(), a predicate function to simplify filtering out
unexposed AST elements.

llvm-svn: 97985
2010-03-08 21:17:29 +00:00
Ted Kremenek adccbca23f Don't enable static analysis support for C++ by default. Users are
accidentally using it without realizing that it is nowhere close
to being generally usable and are reporting crashes that we
already know about.

llvm-svn: 97960
2010-03-08 19:06:44 +00:00
Kovarththanan Rajaratnam 4bc61181f9 Mark variable as const
llvm-svn: 97951
2010-03-08 18:33:04 +00:00
Douglas Gregor de4827dd34 Extend ObjCMessageExpr for class method sends with the source location
of the class name.

llvm-svn: 97943
2010-03-08 16:40:19 +00:00
Douglas Gregor 12852d9521 Keep track of type source information in the return type of an
Objective-C method declaration, e.g., for 

  - (Foo *)myMethod;

we now have TypeSourceInfo for the Foo*.

llvm-svn: 97942
2010-03-08 14:59:44 +00:00
Chris Lattner 03b3eba151 disable these dirs which rely on dynamic linking on mingw/cygwin
llvm-svn: 97892
2010-03-07 00:17:28 +00:00
Ted Kremenek a6d3ab394c Check if 'Unit' is NULL before trying to iterate over the diagnostics.
This obviates a null dereference that can occur when 'NumErrors'
is not zero.

llvm-svn: 97849
2010-03-05 22:43:29 +00:00
Ted Kremenek b39084072f Add clang version to crashtracer string.
llvm-svn: 97848
2010-03-05 22:43:25 +00:00
Douglas Gregor 0c7c2f8b4d A little hack to identify unwanted concurrency in CIndex
llvm-svn: 97831
2010-03-05 21:16:25 +00:00
Douglas Gregor 0b46650b66 c-index-test's printing of linkage was completely broken, as was the
test of this functionality. The API worked great, though! :)

llvm-svn: 97736
2010-03-04 19:36:27 +00:00
Ted Kremenek 83b28a2433 Add '-test-print-linkage-source' option to c-index-test
to test clang_getCursorLinkage()

llvm-svn: 97648
2010-03-03 06:37:58 +00:00
Ted Kremenek 547f4172b7 Export clang_getCursorLinkage().
llvm-svn: 97647
2010-03-03 06:37:30 +00:00
Ted Kremenek fb4961dfd0 Add clang_getCursorLinkage(), which returns the
underlying linkage for the entity referred to by a
CXCursor.

llvm-svn: 97646
2010-03-03 06:36:57 +00:00
Charles Davis dde71b93da Pass -m32 and -m64 to the static analyzer when using scan-build. Now we can
use scan-build with Wine, for example.

Ted, I hope this is OK.

llvm-svn: 97566
2010-03-02 15:26:41 +00:00
Douglas Gregor 89a56c561f When given unsaved files in clang_createTranslationUnitFromSourceFile,
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
2010-02-27 01:32:48 +00:00
Daniel Dunbar cea0c70f12 Frontend: Pull CodeGenAction out more, and eliminate CreateBackendConsumer.
This is the way I would like to move the frontend function towards -- distinct
pieces of functionality should be exposed only via FrontendAction
implementations which have clean and relatively-stable APIs.

This also isolates the surface area in clang which depends on LLVM CodeGen.

llvm-svn: 97110
2010-02-25 04:37:45 +00:00
Daniel Dunbar 12ee380a61 Driver: Use TextDiagnosticPrinter instead of a custom one.
llvm-svn: 97102
2010-02-25 03:23:43 +00:00
Daniel Dunbar 253dbad1c9 Fix bogus diagnostic format string.
llvm-svn: 96978
2010-02-23 20:23:45 +00:00
Douglas Gregor d770f73fac Rework the CIndex API for displaying diagnostics. Instead of printing
the diagnostics to a FILE*, return a CXString containing the formatted
diagnostic.

llvm-svn: 96823
2010-02-22 23:17:23 +00:00
Daniel Dunbar 43b464cfe5 Remove unused includes.
llvm-svn: 96760
2010-02-21 21:47:19 +00:00
Douglas Gregor e61e24a5e3 Attempt to fix the MSVC9 failure with c-indext-test, where the CIndex DLL
and the c-index-test executable end up getting different copies	of
stderr, causing	non-deterministic ordering of output. Fixed by
flushing the file after printing a diagnostic (only on Windows).

llvm-svn: 96754
2010-02-21 20:15:42 +00:00
Douglas Gregor 836ec94c8e Simplify the CIndex fix-it API, now that we have half-open CXSourceRanges.
llvm-svn: 96685
2010-02-19 18:16:06 +00:00
Douglas Gregor 6cb5ba4c4f Teach ASTUnit to keep track of temporary files, then delete them when
the ASTUnit itself is destroyed. Fixes <rdar://problem/7649385>.

llvm-svn: 96628
2010-02-18 23:35:40 +00:00
Douglas Gregor 1e21cc7d19 Re-apply my diagnostics-capture patch for CIndex, with some tweaks to
try to address the msvc failures.

llvm-svn: 96624
2010-02-18 23:07:20 +00:00
Ted Kremenek e21102523a Revert "Sort visitor methods so we can easily tell what's implemented."
This reverts commit 4383e04c75731f8695b8355783f9966ac56b0926.

llvm-svn: 96622
2010-02-18 22:36:18 +00:00
Ted Kremenek aaaf2bfffb Revert "Tidy up order of switch statement. No functionality change."
This reverts commit 95575005fc6409df98e6e079caf324308f62171b.

llvm-svn: 96620
2010-02-18 22:32:43 +00:00
Douglas Gregor 9773e3d077 Revert my CIndex diagnostic changes (r96603, 96606, 96607), which were
breaking the msvc9 builder for unknown reasons.

llvm-svn: 96618
2010-02-18 22:27:07 +00:00
Douglas Gregor 81d53769b5 Introduce debugging/testing hook clang_enableStackTraces() into
CIndex, so that c-index-test to use it to call
lvm::sys::PrintStackTraceOnErrorSignal().

llvm-svn: 96607
2010-02-18 20:22:25 +00:00
Douglas Gregor 707cf72cb8 Resurrect the displayDiagnostics parameter to clang_createIndex(), and
display captured diagnostics when we can't return an invalid
CXTranslationUnit.

llvm-svn: 96606
2010-02-18 20:11:31 +00:00
Douglas Gregor 06dcf0375b Introduce CIndex API functions for displaying a diagnostic, with some
knobs to control formatting. Eventually, I'd like to merge the
implementation of this code with the TextDiagnosticPrinter, so that
it's easy for CIndex clients to produce beautiful diagnostics like the
clang compiler does.

Use this new function to display diagnostics within c-index-test.

llvm-svn: 96603
2010-02-18 19:08:21 +00:00
Ted Kremenek fcb3db7d68 Tidy up order of switch statement. No functionality change.
llvm-svn: 96602
2010-02-18 18:52:18 +00:00
Ted Kremenek 7dff4163aa Sort visitor methods so we can easily tell what's implemented.
llvm-svn: 96600
2010-02-18 18:47:08 +00:00
Ted Kremenek 0e2930979d Change cursor behavior for attributes to have them visited as part of recursing
to the children of a Decl.

llvm-svn: 96599
2010-02-18 18:47:01 +00:00
Douglas Gregor 33cdd81064 Rework how CIndex handles diagnostics. Rather than using a callback,
we attach diagnostics to translation units and code-completion
results, so they can be queried at any time.

To facilitate this, the new StoredDiagnostic class stores a diagnostic
in a serializable/deserializable form, and ASTUnit knows how to
capture diagnostics in this stored form. CIndex's CXDiagnostic is a
thin wrapper around StoredDiagnostic, providing a C interface to
stored or de-serialized diagnostics.

I've XFAIL'd one test case temporarily, because currently we end up
storing diagnostics in an ASTUnit that's never returned to the user
(because it contains errors). I'll introduce a temporary fix for this
soon; the real fix will be to allow us to return and query invalid ASTs.

llvm-svn: 96592
2010-02-18 18:08:43 +00:00
Ted Kremenek 6ab9aa02e3 Add basic cursor traversal for attributes. We currently don't have source
ranges for Attr objects, so lookup by cursor location currently doesn't work.

llvm-svn: 96571
2010-02-18 05:46:33 +00:00
Douglas Gregor 4db30233a8 Teach CMake to put the CIndex header into the Xcode/MSVC project
llvm-svn: 96566
2010-02-18 04:01:41 +00:00
Ted Kremenek bff31437ef Start adding cursor kinds for attributes, with first exposing
IBActionAttr and IBOutletAttr respectively.

llvm-svn: 96563
2010-02-18 03:09:07 +00:00