Commit Graph

227 Commits

Author SHA1 Message Date
Axel Naumann 2eb1d90fd8 From Vassil Vassilev:
Enable incremental parsing by the Preprocessor,
where more code can be provided after an EOF.
It mainly prevents the tearing down of the topmost lexer.
To be used like this:
PP.enableIncrementalProcessing();
while (getMoreSource()) {
  while (Parser.ParseTopLevelDecl(ADecl)) {...}
}
PP.enableIncrementalProcessing(false);

llvm-svn: 152914
2012-03-16 10:40:17 +00:00
David Blaikie bbafb8a745 Unify naming of LangOptions variable/get function across the Clang stack (Lex to AST).
The member variable is always "LangOpts" and the member function is always "getLangOpts".

Reviewed by Chris Lattner

llvm-svn: 152536
2012-03-11 07:00:24 +00:00
Argyrios Kyrtzidis 647dcd80f0 [preprocessor] Enhance PreprocessingRecord to keep track of locations of conditional directives.
Introduce PreprocessingRecord::rangeIntersectsConditionalDirective() which returns
true if a given range intersects with a conditional directive block.

llvm-svn: 152018
2012-03-05 05:48:17 +00:00
Ted Kremenek c1e4dd0e8e Change @import to @__experimental_modules_import. We are not ready to commit to a particular syntax for modules,
and don't have time to push it forward in the near future.

llvm-svn: 151841
2012-03-01 22:07:04 +00:00
Argyrios Kyrtzidis 335c5a42e9 Don't record nested macro expansions in the preprocessing record,
it can only bring pain when dealing with preprocessor abuse (see: boost).

rdar://10898986

llvm-svn: 151427
2012-02-25 02:41:16 +00:00
Benjamin Kramer 7ec12c928a Revert my patches which removed Diagnostic.h includes by moving some operator overloads out of line.
This seems to negatively affect compile time onsome ObjC tests
(which use a lot of partial diagnostics I assume). I have to come
up with a way to keep them inline without including Diagnostic.h
everywhere. Now adding a new diagnostic requires a full rebuild
of e.g. the static analyzer which doesn't even use those diagnostics.

This reverts commit 6496bd10dc3a6d5e3266348f08b6e35f8184bc99.
This reverts commit 7af19b817ba964ac560b50c1ed6183235f699789.
This reverts commit fdd15602a42bbe26185978ef1e17019f6d969aa7.
This reverts commit 00bd44d5677783527d7517c1ffe45e4d75a0f56f.
This reverts commit ef9b60ffed980864a8db26ad30344be429e58ff5.

llvm-svn: 150006
2012-02-07 22:29:24 +00:00
Dylan Noblesmith 2c1dd2716a Basic: import SmallString<> into clang namespace
(I was going to fix the TODO about DenseMap too, but
that would break self-host right now. See PR11922.)

llvm-svn: 149799
2012-02-05 02:13:05 +00:00
Benjamin Kramer 4903802fbf Move a method from IdentifierTable.h out of line and remove the SmallString include.
Fix all the transitive include users.

llvm-svn: 149783
2012-02-04 13:45:25 +00:00
Benjamin Kramer 02c746de10 Remove Diagnostic.h include from Preprocessor.h.
- Move the offending methods out of line and fix transitive includers.
- This required changing an enum in the PPCallback API into an unsigned.

llvm-svn: 149782
2012-02-04 13:02:15 +00:00
Douglas Gregor 8992928274 Thread a TargetInfo through to the module map; we'll need it for
target-specific module requirements.

llvm-svn: 149224
2012-01-30 06:01:29 +00:00
Douglas Gregor 279a6c3747 Rework HeaderSearch's interface for getting a module from a name and
for getting the name of the module file, unifying the code for
searching for a module with a given name (into lookupModule()) and
separating out the mapping to a module file (into
getModuleFileName()). No functionality change.

llvm-svn: 149197
2012-01-29 17:08:11 +00:00
Argyrios Kyrtzidis 9afd449e8f When loading an AST file, set SourceManager::MainFileID to the main file of the AST file,
as suggested by Tom Honermann.

llvm-svn: 147612
2012-01-05 21:36:25 +00:00
Douglas Gregor 8d76cca3a2 Don't treat 'import' as a contextual keyword when we're in a caching lexer, or when modules are disabled.
llvm-svn: 147524
2012-01-04 06:20:15 +00:00
Douglas Gregor da82e703d1 Eliminate the uglified keyword __import_module__ for importing
modules. This leaves us without an explicit syntax for importing
modules in C/C++, because such a syntax needs to be discussed
first. In Objective-C/Objective-C++, the @import syntax is used to
import modules.

Note that, under -fmodules, C/C++ programs can import modules via the
#include mechanism when a module map is in place for that header. This
allows us to work with modules in C/C++ without committing to a syntax.

llvm-svn: 147467
2012-01-03 19:32:59 +00:00
Douglas Gregor 22d0974b40 Introduce a non-uglified syntax for module imports in Objective-C:
@import identifier [. identifier]* ;

llvm-svn: 147452
2012-01-03 18:04:46 +00:00
Douglas Gregor ad01b31b94 Add a "Modules" language option, which subsumes the previous
"AutoModuleImport" preprocessor option and is tied to -fmodules.

llvm-svn: 147448
2012-01-03 17:07:34 +00:00
Abramo Bagnara 123bec89ab Added -Wdisabled-macro-expansion warning.
llvm-svn: 147418
2012-01-01 22:01:04 +00:00
Douglas Gregor bcfc7d0229 When we treat an #include or #import as a module import, create an
implicit ImportDecl in the translation unit to record the presence of
the import.

llvm-svn: 145727
2011-12-02 23:42:12 +00:00
Douglas Gregor 2b82c2a59e Implementing parsing and resolution of module export declarations
within module maps, which will (eventually) be used to re-export a
module from another module. There are still some pieces missing,
however.

llvm-svn: 145665
2011-12-02 01:47:07 +00:00
Douglas Gregor ff2be53f8f Introduce the notion of name visibility into modules. For a given
(sub)module, all of the names may be hidden, just the macro names may
be exposed (for example, after the preprocessor has seen the import of
the module but the parser has not), or all of the names may be
exposed. Importing a module makes its names, and the names in any of
its non-explicit submodules, visible to name lookup (transitively).

This commit only introduces the notion of name visible and marks
modules and submodules as visible when they are imported. The actual
name-hiding logic in the AST reader will follow (along with test cases).

llvm-svn: 145586
2011-12-01 17:11:21 +00:00
Douglas Gregor 1805b8a42f Teach the preprocessor how to handle module import declarations that
involve submodules (e.g., importing std.vector), rather than always
importing the top-level module.

llvm-svn: 145478
2011-11-30 04:26:53 +00:00
Douglas Gregor 71944203de Switch the module-loading interfaces and parser from a simple
top-level module name to a module path (e.g., std.vector). We're still
missing a number of pieces for this actually to do something.

llvm-svn: 145462
2011-11-30 00:36:36 +00:00
Argyrios Kyrtzidis e4d082827d Remove an assertion that is not valid if we cancel parsing.
llvm-svn: 145108
2011-11-23 20:27:29 +00:00
Douglas Gregor 935bc7a214 Make the loading of information attached to an IdentifierInfo from an
AST file more lazy, so that we don't eagerly load that information for
all known identifiers each time a new AST file is loaded. The eager
reloading made some sense in the context of precompiled headers, since
very few identifiers were defined before PCH load time. With modules,
however, a huge amount of code can get parsed before we see an
@import, so laziness becomes important here.

The approach taken to make this information lazy is fairly simple:
when we load a new AST file, we mark all of the existing identifiers
as being out-of-date. Whenever we want to access information that may
come from an AST (e.g., whether the identifier has a macro definition,
or what top-level declarations have that name), we check the
out-of-date bit and, if it's set, ask the AST reader to update the
IdentifierInfo from the AST files. The update is a merge, and we now
take care to merge declarations before/after imports with declarations
from multiple imports.

The results of this optimization are fairly dramatic. On a small
application that brings in 14 non-trivial modules, this takes modules
from being > 3x slower than a "perfect" PCH file down to 30% slower
for a full rebuild. A partial rebuild (where the PCH file or modules
can be re-used) is down to 7% slower. Making the PCH file just a
little imperfect (e.g., adding two smallish modules used by a bunch of
.m files that aren't in the PCH file) tips the scales in favor of the
modules approach, with 24% faster partial rebuilds.

This is just a first step; the lazy scheme could possibly be improved
by adding versioning, so we don't search into modules we already
searched. Moreover, we'll need similar lazy schemes for all of the
other lookup data structures, such as DeclContexts.

llvm-svn: 143100
2011-10-27 09:33:13 +00:00
Richard Smith 4dd85d6fa1 Add a -Wc++0x-compat warning for C++11 keywords used as identifiers when in
C++98 mode. Only the first occurrence of each keyword will produce a warning.

llvm-svn: 141700
2011-10-11 19:57:52 +00:00
Abramo Bagnara e398e60611 Fixed exapnsion range for # and ##.
llvm-svn: 141012
2011-10-03 18:39:03 +00:00
Zhongxing Xu 2d17ff466e Properly initialize Preprocessor::CurLexerKind to avoid use of uninitialized variable.
llvm-svn: 140514
2011-09-26 03:37:43 +00:00
David Blaikie 9c902b5502 Rename Diagnostic to DiagnosticsEngine as per issue 5397
llvm-svn: 140478
2011-09-25 23:23:43 +00:00
Argyrios Kyrtzidis 64f6381097 Introduce PreprocessingRecord::getPreprocessedEntitiesInRange()
which will do a binary search and return a pair of iterators
for preprocessed entities in the given source range.

Source ranges of preprocessed entities are stored twice currently in
the PCH/Module file but this will be fixed in a subsequent commit.

llvm-svn: 140058
2011-09-19 20:40:25 +00:00
Douglas Gregor 97eec24b0b Add an experimental flag -fauto-module-import that automatically turns
#include or #import direcctives of framework headers into module
imports of the corresponding framework module.

llvm-svn: 139860
2011-09-15 22:00:41 +00:00
Douglas Gregor af5c48490e Optimize the preprocessor's handling of the __import_module__
keyword. We now handle this keyword in HandleIdentifier, making a note
for ourselves when we've seen the __import_module__ keyword so that
the next lexed token can trigger a module import (if needed). This
greatly simplifies Preprocessor::Lex(), and completely erases the 5.5%
-Eonly slowdown Argiris noted when I originally implemented
__import_module__. Big thanks to Argiris for noting that horrible
regression!

llvm-svn: 139265
2011-09-07 23:11:54 +00:00
Benjamin Kramer 60053cf547 Use const_cast to avoid warnings.
llvm-svn: 139104
2011-09-04 20:26:28 +00:00
Argyrios Kyrtzidis 5cec2aea3f Support code-completion for C++ inline methods and ObjC buffering methods.
Previously we would cut off the source file buffer at the code-completion
point; this impeded code-completion inside C++ inline methods and,
recently, with buffering ObjC methods.

Have the code-completion inserted into the source buffer so that it can
be buffered along with a method body. When we actually hit the code-completion
point the cut-off lexing or parsing.

Fixes rdar://10056932&8319466

llvm-svn: 139086
2011-09-04 03:32:15 +00:00
Douglas Gregor 83297dfc7e Allow the preprocessor to be constructed without performing target-
and language-specific initialization. Use this to allow ASTUnit to
create a preprocessor object *before* loading the AST file. No actual
functionality change.

llvm-svn: 138983
2011-09-01 23:39:15 +00:00
Douglas Gregor 7018d5bcfb Teach ASTContext and Preprocessor to hold on to references to the same
LangOptions, rather than making distinct copies of
LangOptions. Granted, LangOptions doesn't actually get modified, but
this will eventually make it easier to construct ASTContext and
Preprocessor before we know all of the LangOptions.

llvm-svn: 138959
2011-09-01 20:23:19 +00:00
Eli Friedman 874844123f Make sure to initialize field. Hopefully this will fix some test failures on Windows.
llvm-svn: 138880
2011-08-31 18:45:31 +00:00
Douglas Gregor ca97589f7d Switch __import__ over to __import_module__, so we don't conflict with
existing practice with Python extension modules. Not that Python
extension modules should be using a double-underscored identifier
anyway, but...

llvm-svn: 138870
2011-08-31 18:19:09 +00:00
Douglas Gregor d90c3c92d5 Take an entirely different approach to handling the "parsing" of
__import__ within the preprocessor, since the prior one foolishly
assumed that Preprocessor::Lex() was re-entrant. We now handle
__import__ at the top level (only), after macro expansion. This should
fix the buildbot failures.

llvm-svn: 138704
2011-08-27 06:37:51 +00:00
Douglas Gregor 081425343b Introduce support for a simple module import declaration, which
loads the named module. The syntax itself is intentionally hideous and
will be replaced at some later point with something more
palatable. For now, we're focusing on the semantics:
  - Module imports are handled first by the preprocessor (to get macro
  definitions) and then the same tokens are also handled by the parser
  (to get declarations). If both happen (as in normal compilation),
  the second one is redundant, because we currently have no way to
  hide macros or declarations when loading a module. Chris gets credit
  for this mad-but-workable scheme.
  - The Preprocessor now holds on to a reference to a module loader,
  which is responsible for loading named modules. CompilerInstance is
  the only important module loader: it now knows how to create and
  wire up an AST reader on demand to actually perform the module load.
  - We search for modules in the include path, using the module name
  with the suffix ".pcm" (precompiled module) for the file name. This
  is a temporary hack; we hope to improve the situation in the
  future.

llvm-svn: 138679
2011-08-26 23:56:07 +00:00
Ted Kremenek 8b77fe75af Change Preprocessor::getTotalMemory() to use llvm::capacity_in_bytes().
llvm-svn: 136239
2011-07-27 18:41:23 +00:00
Ted Kremenek 182543aba2 Report more memory using in Preprocessor::getTotalMemory() and PreprocessingRecord::getTotalMemory().
Most of the memory was already reported; but now we report more memory from side data structures.

Fixes <rdar://problem/9379717>.

llvm-svn: 136150
2011-07-26 21:17:24 +00:00
Chandler Carruth 115b077f30 Rename create(MacroArg)InstantiationLoc to create(MacroArg)ExpansionLoc.
llvm-svn: 136054
2011-07-26 03:03:05 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +00:00
Chandler Carruth a88a221855 Move the rest of the preprocessor terminology from 'instantiate' and
variants to 'expand'. This changed a couple of public APIs, including
one public type "MacroInstantiation" which is now "MacroExpansion". The
rest of the codebase was updated to reflect this, especially the
libclang code. Two of the C++ (and thus easily changed) libclang APIs
were updated as well because they pertained directly to the old
MacroInstantiation class.

No functionality changed.

llvm-svn: 135139
2011-07-14 08:20:46 +00:00
Argyrios Kyrtzidis 8cc0459907 Introduce a caching mechanism for macro expanded tokens.
Previously macro expanded tokens were added to Preprocessor's bump allocator and never released,
even after the TokenLexer that were lexing them was finished, thus they were wasting memory.
A very "useful" boost library was causing clang to eat 1 GB just for the expanded macro tokens.

Introduce a special cache that works like a stack; a TokenLexer can add the macro expanded tokens
in the cache, and when it finishes, the tokens are removed from the end of the cache.

Now consumed memory by expanded tokens for that library is ~ 1.5 MB.

Part of rdar://9327049.

llvm-svn: 134105
2011-06-29 22:20:11 +00:00
Argyrios Kyrtzidis e379ee31c0 Introduce Preprocessor::getTotalMemory() and use it in CIndex.cpp, no functionality change.
llvm-svn: 134103
2011-06-29 22:20:04 +00:00
Douglas Gregor 998caead70 Introduce a new libclang parsing flag,
CXTranslationUnit_NestedMacroInstantiations, which indicates whether
we want to see "nested" macro instantiations (e.g., those that occur
inside other macro instantiations) within the detailed preprocessing
record. Many clients (e.g., those that only care about visible tokens)
don't care about this information, and in code that uses preprocessor
metaprogramming, this information can have a very high cost.

Addresses <rdar://problem/9389320>.

llvm-svn: 130990
2011-05-06 16:33:08 +00:00
John Wiegley 1c0675e155 Parsing/AST support for Structured Exception Handling
Patch authored by Sohail Somani.

Provide parsing and AST support for Windows structured exception handling.

llvm-svn: 130366
2011-04-28 01:08:34 +00:00
John McCall 462c055d85 Fix my earlier commit to work with escaped newlines and leave breadcrumbs
in case we want to make a world where we can check intermediate instantiations
for this kind of breadcrumb.

llvm-svn: 127221
2011-03-08 07:59:04 +00:00
John McCall cff9bcfbd3 Add an API call to retrieve the spelling data of a token from its SourceLocation.
llvm-svn: 127216
2011-03-08 04:06:57 +00:00