Commit Graph

370 Commits

Author SHA1 Message Date
Douglas Gregor 6481ef1f9c Once we've built (or reused) a precompiled preamble, create the
appropriately-padded main file buffer (that has spaces in the extra
"reserved" space) and thread that buffer through to the parsing
function. This still does nothing.

llvm-svn: 109299
2010-07-24 00:38:13 +00:00
Douglas Gregor 4dde74988e Once we've built a precompiled preamble, keep track of the details of
that preamble (the preamble text, preamble file, reserved main file
size). Check these details when we try to rebuild the precompiled
preamble, and when nothing has changed, re-use the precompiled
preamble.

This code is still very much a WIP, and can't even properly be tested
because we have no way to use the precompiled preamble yet. "Trust me"

llvm-svn: 109294
2010-07-23 23:58:40 +00:00
Zhongxing Xu 318e40360d Fix build on Ubuntu 10.04.
llvm-svn: 109208
2010-07-23 02:15:08 +00:00
Douglas Gregor be2d8c6096 Basic plumbing for generating a precompiled preamble for an
ASTUnit/CXTranslationUnit. We can't actually use this preamble yet,
however.

llvm-svn: 109202
2010-07-23 00:33:23 +00:00
Douglas Gregor aa21cc401b Introduce a new libclang API, clang_reparseTranslationUnit(), which
reparses an already-parsed translation unit. At the moment it's just a
convenience function, but we hope to use it for performance
optimizations.

llvm-svn: 108756
2010-07-19 21:46:24 +00:00
Daniel Dunbar e38764c66c Driver: Change the driver to take the path to the main executable, instead of
taking it in pieces.
 - Fixes a problem where the Clang executable path was not initialized properly
   on Win32, because sys::Path::getBasename() doesn't do what I always think it
   does. Imagine that, a sys::Path interface that is confusing!

llvm-svn: 108667
2010-07-19 00:44:04 +00:00
Sebastian Redl 8b41f30064 There is another implementation of PCHReaderListener around. Update it to the new interface.
llvm-svn: 108377
2010-07-14 23:29:55 +00:00
Charles Davis 95a546ee4d Add an option to specify the target C++ ABI to the frontend. Use it to
select either the default Itanium ABI or the new, experimental Microsoft ABI.

llvm-svn: 105804
2010-06-11 01:06:47 +00:00
Daniel Dunbar 9507f9cc05 Frontend: Add FrontendAction support for handling LLVM IR inputs.
- These inputs follow an abbreviated execution path, but are still worth handling by FrontendAction so they reuse all the other clang -cc1 features.

llvm-svn: 105582
2010-06-07 23:26:47 +00:00
Daniel Dunbar aed46fcbe9 Frontend: Move some initialization from CompilerInstance to FrontendAction, to parallel what is done for AST inputs.
llvm-svn: 105579
2010-06-07 23:23:50 +00:00
Daniel Dunbar 8654638b23 Frontend: Change FrontendAction::BeginSourceFile to take the input kind instead of an IsAST bool.
llvm-svn: 105578
2010-06-07 23:23:06 +00:00
Daniel Dunbar 9b491e79fc Frontend: Lift InputKind enumeration to top level.
llvm-svn: 105577
2010-06-07 23:22:09 +00:00
Ted Kremenek acc59c3ec9 Workaround: Don't add ObjCMethodDecls to the vector of TopLevelDecls since they don't go in
the DeclContext for the translation unit.  This is to workaround a fundamental issue in how
ObjC decls (within an @implementation) are parsed before the ObjCContainerDecl is available.

llvm-svn: 102944
2010-05-03 20:16:35 +00:00
Dan Gohman 145f3f1e83 Fix -Wcast-qual warnings.
llvm-svn: 101786
2010-04-19 16:39:44 +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
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
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 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 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 81dfb30e4c Don't "take" the file manager and source manager when
ASTUnit::LoadFromCompilerInvocation() fails to create target
information.

llvm-svn: 98697
2010-03-17 00:32:06 +00:00
Douglas Gregor a2f4945099 Make sure we actually override ReadHeaderFileInfo when we meant to
llvm-svn: 98655
2010-03-16 19:09:18 +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 7829362620 The Windows build is just too weird; there's no real cost to doing the concurrency checks for ASTUnit in all builds
llvm-svn: 97840
2010-03-05 22:19:41 +00:00
Douglas Gregor 1e1973c0eb Switch from NDEBUG to _DEBUG, since our Windows build is funny
llvm-svn: 97835
2010-03-05 21:48:53 +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 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
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 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
Daniel Dunbar 1951192213 ASTUnit: Constant fold UseBumpAllocator to true, we don't care to support this as an argument.
llvm-svn: 96316
2010-02-16 01:55:04 +00:00
Daniel Dunbar 7f21a7f7ce ASTUnit::LoadFromCompilerInvocation - Take ownership of the provided invocation.
llvm-svn: 96315
2010-02-16 01:54:54 +00:00
Daniel Dunbar 6b03ecef0d ASTUnit: Ensure the CompilerInvocation object used in LoadFromCommandLine is
live as long as the ASTUnit. This is useful for clients which want to maintain
pointers to the LangOptions object which ultimately lives in the
CompilerInvocation, although it would be nice to make all of this ownership
stuff more explicit and obvious.

llvm-svn: 94924
2010-01-30 21:47:16 +00:00
Benjamin Kramer 2ecf8eb2dc PCHReader doesn't implement classof so dyn_casting it will do really weird stuff. Use a static_cast instead.
I don't know if this hack is the right fix. Doug, please take a look.

llvm-svn: 94895
2010-01-30 16:23:25 +00:00
Daniel Dunbar fcf2d428e4 ASTUnit: Don't check that input files exist when parsing ASTs from the command
line -- they may be remapped (fake) files. This is useful for testing parsing
entirely from memory.

llvm-svn: 94395
2010-01-25 00:44:02 +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
Daniel Dunbar a5a166d01a Add -resource-dir to clang -cc1, this allows the base directory for compiler
resources (e.g., /usr/lib/clang/1.1) to be passed on the command line instead of
computed.

llvm-svn: 91370
2009-12-15 00:06:45 +00:00
Daniel Dunbar 8d4a202aad Lift builtin-include-path logic out of ASTUnit::LoadFromCommandLine and fix CIndex to pass in the right directory (previously it was using the path to the main executable, which generally is wrong).
llvm-svn: 91238
2009-12-13 03:46:13 +00:00
Daniel Dunbar d613677ec9 CompilerInvocation: Move builtin-include-path logic out of CompilerInvocation::CreateFromArgs.
llvm-svn: 91237
2009-12-13 03:45:58 +00:00
Jeffrey Yasskin 567ae47b4a Remove several .c_str() to be forward-compatible with StringRef.
llvm-svn: 90822
2009-12-08 01:46:24 +00:00
Daniel Dunbar 644dca07b9 ASTUnit/CIndex: Explicitly track the top-level decls when using an ASTUnit made
from a source file.
 - This allows CIndex to avoid iterating over all the top-level decls when using
   a PCH, which means we deserialize far fewer decls.

llvm-svn: 90559
2009-12-04 08:17:33 +00:00
Daniel Dunbar 59203007ac Fix ASTUnit to allows require a (persistent) Diagnostic object be provided; propogate and simplify.
llvm-svn: 90379
2009-12-03 01:45:44 +00:00
Daniel Dunbar a18f9580e4 ASTUnit: Explicitly track whether the ASTUnit came from an actual AST or not.
llvm-svn: 90349
2009-12-02 21:47:43 +00:00
Daniel Dunbar 4897349a79 ASTUnit: Fix initialization of OnlyLocalDecls variable, and honor UseBumpAllocator.
llvm-svn: 90348
2009-12-02 21:47:32 +00:00
Daniel Dunbar a8a509376c Fix ASTUnit::getOriginalSourceFileName() when using ASTUnit's derived from
source files.

llvm-svn: 90311
2009-12-02 08:44:16 +00:00
Daniel Dunbar 7afbb8c08c ASTUnit: Don't create an LLVMContext, it shouldn't be needed.
llvm-svn: 90310
2009-12-02 08:43:56 +00:00
Daniel Dunbar 55a17b66cd Add ASTUnit::LoadFromCommandLine, which creates an ASTUnit out of a list of
(clang/driver) command line arguments (including the source file).
 - The arguments are expected to include the source file.

 - The idea is that even though this is a somewhat odd API, its the form which
   many tools can most easily use (for example, by interposing with the compiler).

Also, switch index-test's -ast-from-source to use this entry point, and provide
a -arg command line argument which can be used to test that the command line
arguments are handled correctly.

llvm-svn: 90288
2009-12-02 03:23:45 +00:00
Daniel Dunbar d2f8be3629 ASTUnit: Make sure to preserve the TargetInfo for later use.
llvm-svn: 90263
2009-12-01 21:57:33 +00:00
Daniel Dunbar 764c082027 Add ASTUnit::LoadFromCompilerInvocation, which does what it says.
Also, add an -ast-from-source option to index-test which allows index-test to
run on source files directly.

llvm-svn: 90223
2009-12-01 09:51:01 +00:00
Benjamin Kramer 16634c2c5a Remove VISIBILITY_HIDDEN from anonymous namespaces in libFrontend.
llvm-svn: 90033
2009-11-28 10:07:24 +00:00
Daniel Dunbar b9bbd54fdb Add TargetOptions and use it when constructing targets.
- This ended up being hard to factor, sorry for the large diff.

 - Some post-commit cleanup to come.

llvm-svn: 88833
2009-11-15 06:48:46 +00:00
Daniel Dunbar 000c4ffd16 Redo how PCH handles its implicit include. Instead of treating this specially in
the front-end (as far as the preprocessor goes), follow the usual logic of
inserting the (original include path) name into the predefines buffer. This
pushes the responsibility for handling this to PCH instead of the front-end.  In
PCH this requires being a little more clever when we diff the predefines
buffers.

Neither of these solutions are particularly great, I think what we eventually
should do is something like gcc where we insert a special marker to indicate the
PCH file, but then run the preprocessor as usual. This would be clearer and
would allow us to drop the overly clever predefines handling.

llvm-svn: 86806
2009-11-11 05:29:04 +00:00
Daniel Dunbar 20a682de6b StringRefify some PCH interfaces.
llvm-svn: 86775
2009-11-11 00:52:11 +00:00
Ted Kremenek 428c637ada The constructor for ASTUnit now takes a DiagnosticClient*, allowing uses of ASTUnit to specify
alternate DiagnosticClients. To match this API, ASTUnit::LoadFromPCHFile() now takes a corresponding
DiagnosticClient* argument as well. The DiagnosticClient object is destroyed when the ASTUnit object
is destroyed.

The CIndex library now uses this API to create a 'IgnoreDiagnosticsClient' that simply silences
diagnostics when using the clang_createTranslationUnitFromSourceFile() function. This fixes
<rdar://problem/7312058>. This API can change in the future as we add more flexibility for clients.

llvm-svn: 84539
2009-10-19 21:44:57 +00:00
Steve Naroff 505fb84ed9 Move Diagnostic/DiagClient/FileManager from Indexer => ASTUnit.
Removing this shared data should enable clang_createTranslationUnit/clang_createTranslationUnitFromSourceFile to be run from multiple threads (related to <rdar://problem/7303432>).

llvm-svn: 84499
2009-10-19 14:34:22 +00:00
Benjamin Kramer 6c839f827c Use sys::Path::eraseFromDisk instead of unlink as suggested by Chris.
llvm-svn: 84415
2009-10-18 11:34:14 +00:00
Ted Kremenek 8bcb1c6883 Add 'UseBumpPtrAllocator' flag to ASTUnit::LoadFromPCHFile() to cause the created ASTContext to use
its own BumpPtrAllocator to allocate ASTs.

Change clang_createTranslationUnit (CIndex) to pass 'UseBumpPtrAllocator = true' to
ASTUnit::LoadFromPCHFile().

llvm-svn: 84296
2009-10-17 00:34:24 +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 44cd60eebe Make sure temporary files get unlinked.
llvm-svn: 84208
2009-10-15 22:23:48 +00:00
Daniel Dunbar b7bbfdd9e6 Change ASTUnit to only initialize the predefines buffer to the suggested predefines.
- It isn't really clear what to do with the preprocessor here, but this is more sensible.

llvm-svn: 82431
2009-09-21 03:03:47 +00:00
Daniel Dunbar 7cd285f0fe Change ASTUnit to take the Diagnostic as an argument, the client should have control of this.
llvm-svn: 82430
2009-09-21 03:03:39 +00:00
Mike Stump 11289f4280 Remove tabs, and whitespace cleanups.
llvm-svn: 81346
2009-09-09 15:08:12 +00:00
Steve Naroff ef9618b75f Implement accessors clang_getCursorKind(), clang_getCursorDecl().
Implement clang_getCursor() - wired up to Argiris's work.
Implement callbacks for CXCursor_ObjCProtocolRef.

llvm-svn: 81004
2009-09-04 15:44:05 +00:00
Steve Naroff c0683b909a Add ASTUnit::getOriginalSourceFileName() and use in clang_getTranslationUnitSpelling().
llvm-svn: 80932
2009-09-03 18:19:54 +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
Daniel Dunbar 2d9c740cc5 Revert "Remove redundant local variable (use newly created instance data).", the
previous commit this depends on is breaking x86_64-apple-darwin10 and Linux tests.

llvm-svn: 80895
2009-09-03 05:59:35 +00:00
Steve Naroff 517ea46e2e Remove redundant local variable (use newly created instance data).
llvm-svn: 80861
2009-09-03 00:43:52 +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
Argyrios Kyrtzidis 55c34113e4 Handle PCHReader::IgnorePCH, it gets returned for when the file does not exist.
llvm-svn: 74196
2009-06-25 18:22:30 +00:00
Argyrios Kyrtzidis 3a08ec1662 Add the license part to the new source files.
llvm-svn: 73825
2009-06-20 08:27:14 +00:00
Argyrios Kyrtzidis ce3797527e Introduce the ASTUnit class.
ASTUnit is a helper class to allow easy loading of an ASTContext from a PCH file. No users for now.

llvm-svn: 73819
2009-06-20 08:08:23 +00:00