Commit Graph

241 Commits

Author SHA1 Message Date
Douglas Gregor 9bd6db5834 Eliminate clang_getInstantiationLocationOffset(), and instead add an
offset parameter to clang_getInstantiationLocation(). 

llvm-svn: 94573
2010-01-26 19:19:08 +00:00
Douglas Gregor 6165611986 Implement clang_annotateTokens(), which associates cursors with each
of the tokens within a raw token stream. This does not even attempt to
handle macros yet.

llvm-svn: 94561
2010-01-26 18:31:56 +00:00
Douglas Gregor 27b4fa994d Introduce a CIndex API for lexing the raw tokens within a given source
range. The token-annotation function does nothing, yet.

llvm-svn: 94551
2010-01-26 17:06:03 +00:00
Douglas Gregor 47751d6c21 Introduce clang_getInstantiationLocationOffset(), which decomposes a
source location in file + offset.

llvm-svn: 94497
2010-01-26 03:07:15 +00:00
Daniel Dunbar d01592617f Update comment.
llvm-svn: 94393
2010-01-25 00:43:14 +00:00
Daniel Dunbar b9999fdc67 Tweak clang_visitChildren comment.
llvm-svn: 94360
2010-01-24 04:10:31 +00:00
Daniel Dunbar 62ebf25f44 Index.h: Tweak comments, delete trailing whitespace, fix a few typos, etc.
llvm-svn: 94351
2010-01-24 02:54:26 +00:00
Ted Kremenek 3e315a28b1 Add doxygen comment to clang_getClangVersion().
llvm-svn: 94311
2010-01-23 17:51:23 +00:00
Douglas Gregor aa98ed9a07 Extend clang_createTranslationUnitFromSourceFile() to support creating
translation units that include unsaved files.

llvm-svn: 94258
2010-01-23 00:14:00 +00:00
Ted Kremenek c0f3f72fa4 Add 'clang_getClangVersion()' function to CIndex. This exposes the full Clang version string through the CIndex API.
llvm-svn: 94242
2010-01-22 22:44:15 +00:00
Douglas Gregor 6007cf2e9e Improve content and structure of the Doxygen documentation for the
CIndex API. No functionality change.

llvm-svn: 94234
2010-01-22 22:29:16 +00:00
Douglas Gregor 816fd36316 Yet more CIndex API cleanup:
- Added more routines to manipulate/compare source locations and ranges
  - Switched clang_getCursor() over to take a CXSourceLocation rather
  than file/line/column.

llvm-svn: 94226
2010-01-22 21:44:22 +00:00
Douglas Gregor 93f899509d Introduce type references into the C API, capturing references to
typedefs only (for now).

llvm-svn: 94078
2010-01-21 16:28:34 +00:00
Douglas Gregor fed36b1aa1 Stash a CXXUnit pointer into each cursor. This allows us to simplify
the interface to clang_visitChildren() by eliminating the
CXTranslationUnit pointer.

llvm-svn: 94051
2010-01-20 23:57:43 +00:00
Douglas Gregor c8e390c215 Yet more Doxygen-comment tweaking in the CIndex library.
llvm-svn: 94044
2010-01-20 22:45:41 +00:00
Douglas Gregor 802f12f719 Improve Doxygen documentation for the CIndex library, somewhat.
llvm-svn: 94042
2010-01-20 22:28:27 +00:00
Douglas Gregor 721e82edbc Kill CXEntity and CXDecl. The first has never been used, while the
second has been wholly replaced by cursors.

llvm-svn: 94039
2010-01-20 22:14:22 +00:00
Douglas Gregor dd969c897e Kill some CXDecl-related APIs that have been superceded by
CXCursor-based APIs.

llvm-svn: 94037
2010-01-20 21:45:58 +00:00
Douglas Gregor 2582af00d4 Kill CXStmt. It isn't being used anywhere, and has no future.
llvm-svn: 94036
2010-01-20 21:38:07 +00:00
Douglas Gregor 990b576ec8 Kill clang_loadDeclaration() and clang_loadTranslationUnit().
llvm-svn: 94034
2010-01-20 21:37:00 +00:00
Douglas Gregor 71f3d94391 Introduce a new, cursor-based traversal function that visits the
children of a given cursor, regardless of what kind of cursor it
is. This is a generalization of clang_loadDeclaration and
clang_loadTranslationUnit that will also extent to statements,
expressions, etc.

As proof-of-concept, switched clang_loadDeclaration() from its own
visitor over to an instance of this traversal function internally.

llvm-svn: 94022
2010-01-20 20:59:29 +00:00
Douglas Gregor 52606ff2ca Attempt to improve CIndex Doxygen organization, although I can't actually test this locally
llvm-svn: 93961
2010-01-20 01:10:47 +00:00
Douglas Gregor 9074c3fe97 Kill off clang_getDeclColumn, clang_getDeclExtent, clang_getDeclLine,
clang_getDeclSource, and clang_getDeclSourceFile; the cursor
equivalents are the way of the future.

llvm-svn: 93955
2010-01-20 00:26:57 +00:00
Douglas Gregor d2fc7277be Introduce a special cursor kind for the translation unit, to serve as
the root of the conceptual cursor hierarchy (just like we do with
declarations). This will be used when we get to unify
clang_loadTranslationUnit() and clang_loadDeclaration() into something
more generally useful.

llvm-svn: 93954
2010-01-20 00:23:15 +00:00
Douglas Gregor c0943d089f CXCursor_UnexposedDecl to the first declaration kind
llvm-svn: 93952
2010-01-20 00:07:45 +00:00
Douglas Gregor 084236fafd Kill CXCursor_ObjCSelectorRef, CXCursor_VarRef, CXCursor_FunctionRef,
and CXCursor_EnumConstantRef; they've been subsumed by expression
references, which do a much nicer job.

llvm-svn: 93947
2010-01-19 23:25:01 +00:00
Douglas Gregor 8f40bbee78 Extend the CIndex API with direct support for expressions and
statements, moving some of the more unnatural kinds of references
(VarRef, EnumConstantRef, etc.) over to the expressions. We can now
poke at arbitrary expressions and statements with, e.g.,
clang_getCursor() and get back useful information (e.g., source
ranges).

llvm-svn: 93946
2010-01-19 23:20:36 +00:00
Douglas Gregor 7d1efeb43d Kill the unused and unnecessary CXCursor_MemberRef, twin to the
now-dead CXCursor_ObjCIvarRef.

llvm-svn: 93928
2010-01-19 22:15:34 +00:00
Douglas Gregor 015026e358 Kill CXCursor_ObjCIvarRef. Such cursors could never be created, and
have been marked for death for a while.

llvm-svn: 93927
2010-01-19 22:11:32 +00:00
Douglas Gregor accb183371 Introduce the notion of an "unexposed" declaration into the CIndex
API. This is a catch-all for any declaration known to Clang but not
specifically part of the CIndex API. We'll use the same approach with
expressions, statements, references, etc., as needed.

llvm-svn: 93924
2010-01-19 22:07:56 +00:00
Douglas Gregor 4f46e789b3 Rework the CXSourceLocation and CXSourceRange APIs. They are now
opaque data structures accessed through the new functions
clang_getInstantiationLocation(), clang_getRangeStart(), and
clang_getRangeEnd(). The new API permits later extensions to introduce
new functions to allow CIndex clients to walk macro instantiations, if
we ever care.

llvm-svn: 93915
2010-01-19 21:36:55 +00:00
Douglas Gregor 6b8232ff82 Eliminate cursor kinds used to express definitions. Instead, provide
CIndex functions that (1) map from a reference or declaration to the
corresponding definition, if available, and (2) determine whether a
given declaration cursor is also a definition. This eliminates a lot
of duplication in the cursor kinds, and maps more closely to the Clang
ASTs.

This is another API + ABI breaker with no deprecation. Yay, progress.

llvm-svn: 93893
2010-01-19 19:34:47 +00:00
Douglas Gregor ad27e8b777 Introduce clang_getCursorReferenced, to get a cursor pointing at the
entity that a particular cursor references.

llvm-svn: 93830
2010-01-19 01:20:04 +00:00
Douglas Gregor 33c34ac19a Implement clang_getCursorExtent, which provides a source range for the
cursor itself. In particular, for references this returns the source
range of the reference rather than the source range of the thing it
refers to.

Switch c-index-test from clang_getDeclExtent (which will eventually be
deprecated and removed) over to clang_getCursorExtent. The source
ranges we print for references now make sense; fix up the tests
appropriately.

llvm-svn: 93823
2010-01-19 00:34:46 +00:00
Douglas Gregor 3338c1f5d2 Now that a reasonable deprecation cycle has passed, kill
clang_getCursorLine(), clang_getCursorColumn(),
clang_getCursorSource(), and clang_getCursorSourceFile() outright.

llvm-svn: 93801
2010-01-18 22:48:04 +00:00
Douglas Gregor 66a58819d1 Introduce clang_getCursorLocation(), which supercedes
clang_getCursorLine(), clang_getCursorColumn(),
clang_getCursorSource(), and clang_getCursorSourceFile(). Mark those 4
functions as deprecated and stop using them ourselves.

llvm-svn: 93800
2010-01-18 22:46:11 +00:00
Douglas Gregor 49c4baf430 Clean up the CIndex API slightly.
Renamed CXSourceFileLine to CXSourceLocation and added a CXFile, to
better match Clang's SourceLocation. Teach clang_getDeclExtent to fill
in the CXFile properly.

Renamed CXSourceExtent to CXSourceRange, to better match Clang's
SourceLocation.

llvm-svn: 93783
2010-01-18 22:13:09 +00:00
Ted Kremenek 473c7a72f1 Replace clang_getDeclUSR() with clang_getCursorUSR(). Also remove printing 'contexts' from c-index-test output; it wasn't helpful and was extremely brittle.
llvm-svn: 93760
2010-01-18 20:23:29 +00:00
Ted Kremenek 4ba5263441 Remove 'default' case in switch statement in clang_getCursorKindSpelling(). This identified a missing case (warned by the compiler) and identified that CXCursor_FirstDecl didn't actually correspond to the first decl.
llvm-svn: 93622
2010-01-16 02:02:09 +00:00
Douglas Gregor c58d05bcf9 Make CXCursor's data opaque.
llvm-svn: 93561
2010-01-15 21:56:13 +00:00
Ted Kremenek e14e372b67 Add 'referringDecl' field to CXCursor to prepare the way to better model declaration references from other delcarations.
llvm-svn: 93343
2010-01-13 19:59:20 +00:00
Ted Kremenek cb674f9492 Rename clang_getUSR() -> clang_getDeclUSR(). For now we take a CXDecl instead of a CXEntity.
Enhance USR generation a bit with support for records.

llvm-svn: 93267
2010-01-12 23:33:42 +00:00
Ted Kremenek 87be3617e3 Change clang_getUSR() to return a CXString instead of a 'const char *'.
llvm-svn: 93213
2010-01-12 00:38:53 +00:00
Ted Kremenek e5f86be138 CIndex:
- Remove unused (and unimplemented) clang_getDeclarationName().
- Remove unused (and unimplemented) clang_getEntity().
- Add clang_getEntityFromDecl(): maps from a CXDecl to a CXEntity)
- Add clang_getDeclaration(): maps from a (CXEntity, CXTranslationUnit) to a CXDecl).

llvm-svn: 93209
2010-01-11 23:56:39 +00:00
Douglas Gregor 504a6ae83e Improve code completion by introducing patterns for the various C and
C++ grammatical constructs that show up in top-level (namespace-level)
declarations, member declarations, template declarations, statements,
expressions, conditions, etc. For example, we now provide a pattern
for

  static_cast<type>(expr)

when we can have an expression, or

  using namespace identifier;

when we can have a using directive.

Also, improves the results of code completion at the beginning of a
top-level declaration. Previously, we would see value names (function
names, global variables, etc.); now we see types, namespace names,
etc., but no values.

llvm-svn: 93134
2010-01-10 23:08:15 +00:00
Ted Kremenek ea903067e1 For now, add back clang_getDeclSource().
llvm-svn: 93003
2010-01-08 17:11:32 +00:00
Ted Kremenek 2a43fd58ee Change clang_getDeclExtent() to have the endpoint point to the last character in the last token.
llvm-svn: 92869
2010-01-06 23:43:31 +00:00
Daniel Dunbar 143a5b9f3c Add missing CINDEX_LINKAGE.
llvm-svn: 92827
2010-01-06 06:51:48 +00:00
Ted Kremenek bde648030b Remove deprecated function 'clang_getDeclSource()'. Use 'clang_getDeclFile()' instead.
llvm-svn: 92803
2010-01-05 23:21:30 +00:00
Ted Kremenek a44d99c934 Add C API hook 'clang_getDeclExtent()', which returns the source extent of a declaration. This implements <rdar://problem/7280072>.
llvm-svn: 92802
2010-01-05 23:18:49 +00:00
Ted Kremenek 9cd9f6d861 Split (mostly nonexistent) USR code out from the main CIndex logic.
llvm-svn: 92789
2010-01-05 22:06:45 +00:00
Douglas Gregor b3fa919c2d Extend code-completion results with the type of each result
llvm-svn: 91702
2009-12-18 18:53:37 +00:00
Douglas Gregor f72b6ac87f Change clang_codeComplete API to return the results in a structure on
the heap, so that clients are not forced to copy the results during
the initial iteration. A separate clang_disposeCodeCompleteResults
function frees the returned results.

llvm-svn: 91690
2009-12-18 16:20:58 +00:00
Chandler Carruth aacafe54af Include <time.h> in order to use 'time_t'.
llvm-svn: 91597
2009-12-17 09:27:29 +00:00
Daniel Dunbar 1108966959 Switch clang_createTranslationUnitFromSourceFile to use ASTUnit::LoadFromCommandLine.
- This is much faster, as it avoids the overhead of dumping an AST file to disk and reloading it.
 - For debugging purposes, there is a clang_setUseExternalASTGeneration hook which can be used to disable this.

On the Sketch Cocoa app, the speedup is pretty nice, especially when using a PCH file while scanning the source:

Wall time to c-index-test all files (no PCH):
Old: 23.4221
New: 12.3884

Wall time to c-index-test all files (with a PCH, and "local" mode):
Old: 10.9233
New:  1.9038

llvm-svn: 90385
2009-12-03 01:54:28 +00:00
Douglas Gregor 9485bf9538 Extend the CIndex code-completion API to perform code completion
involving unsaved files, using the -remap-file= functionality recently
added to clang-cc.

llvm-svn: 90314
2009-12-02 09:21:34 +00:00
Ted Kremenek e05d7806ff Add clang_getNullCursor() and clang_equalCursors() (the latter for comparing cursors).
llvm-svn: 89131
2009-11-17 19:28:59 +00:00
Ted Kremenek 123344e5dd Allow "source_filename" to be an optional argument (the client can provide NULL). This allows the client to put the source_filename in the command_line_args without fear of the file being named twice.
llvm-svn: 89118
2009-11-17 18:18:02 +00:00
Steve Naroff 8675d5c754 Introduce CXString type and associated functions clang_getCString() and clang_disposeString().
This abstraction will help us manage string memory for complex names that cross the C++/C boundary (e.g. ObjC methods, selectors). This patch also uses it in clang_getTranslationUnitSpelling (which I'm not sure is necessary). Will investigate later...since the extra malloc() can't hurt (for now).

Patch by John Thompson.

llvm-svn: 86562
2009-11-09 17:45:52 +00:00
Douglas Gregor 9eb7701dff Various improvements to Clang's code-completion infrastructure:
- Introduce more code-completion string "chunk" kinds that describe
  symbols, the actual text that the user is expected to type, etc.
  - Make the generation of macro results optional, since it can be
  slow
  - Make code-completion accessible through the C API, marshalling the
  code-completion results through a temporary file (ick) to maintain
  process separation.

The last doesn't have tests yet.

llvm-svn: 86306
2009-11-07 00:00:49 +00:00
Douglas Gregor 249c121883 Add two missing CINDEX_LINKAGE uses, in libCIndex, from Kovarththanan
Rajaratnam!

llvm-svn: 85665
2009-10-31 15:48:08 +00:00
Steve Naroff 58bd62d190 Remove _clang_initCXLookupHint() and _clang_getCursorWithHint(). Related to <rdar://problem/7310688>.
Localize the optimization to ResolveLocationInAST(). The last valid AST location is now stored with ASTUnit. There still isn't optimal, however it's an improvement (with a much cleaner API). Having the client manage an "hint" is error prone and complex.

I wanted to land the major changes before finishing up the optimizations. 

llvm-svn: 85425
2009-10-28 20:44:47 +00:00
Steve Naroff 6231f18793 Add support for 'CXFile' (<rdar://problem/7303360>).
- 4 new functions (clang_getCursorSourceFile, clang_getDeclSourceFile, clang_getFileName, clang_getFileTime).

- Should remove clang_getDeclSource() and clang_getCursorSource(). For now, just put 'deprecate' comment in header. 

- Also changed CXX style comment to C style (to eliminate warning).

llvm-svn: 85238
2009-10-27 14:35:18 +00:00
John Thompson de258b5ab9 Changes for building as a Windows DLL
llvm-svn: 85234
2009-10-27 13:42:56 +00:00
Ted Kremenek a96b72a4ca Split clang_getCursor() into clang_getCursor() and clang_getCursorWithHint().
llvm-svn: 84873
2009-10-22 17:22:53 +00:00
Ted Kremenek 649bf5c04b Enhance 'clang_createTranslationUnitFromSourceFile()' in two ways:
(1) Allow the source file to be specified in the actual command line arguments by allowing the
    caller to set 'source_filename' to NULL.

(2) Automatically strip off the arguments '-emit-ast', '-fsyntax-only', and '-c'.

llvm-svn: 84802
2009-10-22 00:03:57 +00:00
Steve Naroff 20bad0b7c6 Extend clang_getCursor() to take a 'relativeDecl' argument (so speed up searching). Without a 'relativeDecl', the algorithm is n-squared. For example, running the following command on 'Large.m' takes hours without a 'relatvieDecl'.
snaroff% time ../../Debug/bin/c-index-test Large.ast all > Large.out
snaroff% cat Large.m
#import <Cocoa/Cocoa.h>
#import <QuickTime/QuickTime.h>
#import <OpenGL/OpenGL.h>

With a 'relativeDecl', it takes <30 seconds:-)

llvm-svn: 84760
2009-10-21 13:56:23 +00:00
Steve Naroff bb4568a37d Add an example to help claify the process/assumptions...
llvm-svn: 84642
2009-10-20 16:36:34 +00:00
Steve Naroff 531e284064 - Extend clang_createIndex() to support PCH and diagnostic 'filtering'. This seems cleaner to me without sacrificing much flexibility.
- Remove clang_wantOnlyLocalDeclarations().

- Remove 'displayDiagnostics' arguments to clang_createTranslationUnitFromSourceFile() and clang_createTranslationUnit().

- Have clang_createTranslationUnitFromSourceFile() strip the '-o <outfile>' command line arguments if they exist. Document this semantic in the header. Also verify we have a valid ASTUnit before telling it to 'unlinkTemporaryFile()'.

llvm-svn: 84634
2009-10-20 14:46:24 +00:00
Ted Kremenek 02b319ce18 Really fix <rdar://problem/7312058> by adding a 'displayDiagnostics' option to
clang_createTranslationUnit() and clang_createTranslationUnitFromSourceFile(). The user can now
specify if the diagnostics from Clang are printed to stderr or are silenced completely. We can
obviously evolve this API to be more general in the future.

Note: Added a FIXME since I wasn't certain what was the best way to redirect to something analogous
to '/dev/null' on Windows.

llvm-svn: 84548
2009-10-19 22:15:09 +00:00
Douglas Gregor 16bef857d9 Keep track of whether declararions were loaded from a precompiled
header or not via a new "PCHLevel" field in Decl. We currently use
this information to help CIndex filter out declarations that came from
a precompiled header (rather than from an AST file). Further down the
road, it can be used to help implement multi-level precompiled
headers.

llvm-svn: 84267
2009-10-16 20:01:17 +00:00
Steve Naroff 7781daa4e0 Implement <rdar://problem/7303432> [Clang/Index] In-memory-style AST generation API (initial API implementation).
Added clang_createTranslationUnitFromSourceFile().
Changed clang_createIndex() to lookup the location of clang (using dladdr).

llvm-svn: 84198
2009-10-15 20:04:39 +00:00
Steve Naroff 2676089407 Add clang_getDeclSource().
llvm-svn: 82807
2009-09-25 21:45:39 +00:00
Steve Naroff 63f475a212 Add clang_getDeclLine and clang_getDeclColumn
Fix clang_getCursorDecl to do the right thing for expr refs
Fixup test file to accommodate new output (which includes the line/column for the referenced decl)

llvm-svn: 82798
2009-09-25 21:32:34 +00:00
Steve Naroff 76b8f13fcb More work to enable more exhaustive testing of the indexing API.
Next step: Add actual some test cases:-)

llvm-svn: 82636
2009-09-23 17:52:52 +00:00
Steve Naroff 66af1aecdb - Implement support for various types of "refs" (initially to help test clang_getCursor()).
- Add missing prototypes for dispose functions.

llvm-svn: 82564
2009-09-22 19:25:29 +00:00
Chris Lattner dd890b2b2e fit in 80 cols
llvm-svn: 82073
2009-09-16 20:18:54 +00:00
Steve Naroff 54f22fb1de - clang_getCursor(): Replace asserts with error codes (CXCursor_InvalidFile, CXCursor_NoDeclFound).
- Add predicate clang_isInvalid().
- Implement clang_getCursorFromDecl().

llvm-svn: 81908
2009-09-15 20:25:34 +00:00
Steve Naroff 38c1a7ba12 - Add back some harmless code that part of a reverted commit (r80859). I'll investigate the lifetime snafu (with ASTUnit) separately.
- Traverse category methods, add a "class ref" and make the little test harness a bit more flexible.

llvm-svn: 80921
2009-09-03 15:49:00 +00:00
Daniel Dunbar 3a0637b06b Revert "Visit function/method bodies and issue callback for parameters and local
variables.", this is breaking x86_64-apple-darwin10 and Linux tests.

llvm-svn: 80896
2009-09-03 05:59:50 +00:00
Steve Naroff ef3cf2a576 Visit function/method bodies and issue callback for parameters and local variables.
Add clang_getTranslationUnitSpelling().

llvm-svn: 80859
2009-09-03 00:32:06 +00:00
Steve Naroff 80a766bf50 Start issuing callback for references (add some predicates, refactor some code).
llvm-svn: 80810
2009-09-02 18:26:48 +00:00
Steve Naroff 3645f5a99b Flesh out CXCursorKind...
- More declaration types (distinguish between struct/union/class, instance/class methods).
- Add definition types (class, category, function, instance/class method, etc.).

Add client data to clang_loadDeclaration() and implement.

llvm-svn: 80787
2009-09-02 13:28:54 +00:00
Steve Naroff 95908b373a Tweak comment based on Daniel's recently added '-emit-ast' option.
llvm-svn: 80684
2009-09-01 17:13:31 +00:00
Steve Naroff 69b10fd2c5 Add explicit "blind" client data to callback function (since we aren't using blocks).
llvm-svn: 80673
2009-09-01 15:55:40 +00:00
Steve Naroff 772c1a4574 Implement source/line/column hooks.
llvm-svn: 80585
2009-08-31 14:26:51 +00:00
Steve Naroff 1054e60334 More fleshing out the C-based indexing API (under construction).
llvm-svn: 80529
2009-08-31 00:59:03 +00:00
Steve Naroff a1c728438c Lot's of little changes to get the C-based indexing API going...
Work in progress.

llvm-svn: 80367
2009-08-28 15:28:48 +00:00
Steve Naroff 8721959642 Add CX prefix to Cursor and move a comment.
llvm-svn: 80359
2009-08-28 12:07:44 +00:00
Steve Naroff d5e8e862bb Fill in Index.h header file and add stubs to implementation file.
llvm-svn: 80279
2009-08-27 19:51:58 +00:00
Ted Kremenek b60d87c517 Add initial boilerplate for CIndex, a shared library that will vend high-level
source symbol information (harvested by Clang) through a C API.

llvm-svn: 80166
2009-08-26 22:36:44 +00:00