Commit Graph

896 Commits

Author SHA1 Message Date
Abramo Bagnara e398e60611 Fixed exapnsion range for # and ##.
llvm-svn: 141012
2011-10-03 18:39:03 +00:00
John McCall 32f5fe1467 Add explicit attributes to mark functions as having had their
CoreFoundation object-transfer properties audited, and add a #pragma
to cause them to be automatically applied to functions in a particular
span of code.  This has to be implemented largely in the preprocessor
because of the requirement that the region be entirely contained in
a single file;  that's hard to impose from the parser without registering
for a ton of callbacks.

llvm-svn: 140846
2011-09-30 05:12:12 +00:00
Argyrios Kyrtzidis 18bcfd5595 Introduce a callback to PPCallbacks for lines skipped by the preprocessor.
Patch by Jason Haslam!

llvm-svn: 140612
2011-09-27 17:32:05 +00:00
Douglas Gregor 4d68366b2f When parsing a character literal, extract the characters from the
buffer as an 'unsigned char', so that integer promotion doesn't
sign-extend character values > 127 into oblivion. Fixes
<rdar://problem/10188919>.

llvm-svn: 140608
2011-09-27 17:00:18 +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
David Blaikie 76bd3c80d4 Fix missing includes for llvm_unreachable
llvm-svn: 140368
2011-09-23 05:35:21 +00:00
David Blaikie 83d382b1ca Switch assert(0/false) llvm_unreachable.
llvm-svn: 140367
2011-09-23 05:06:16 +00:00
Argyrios Kyrtzidis e523e389b2 Do manual binary search for preprocessing entities because their end locations
may be unordered and MSVC's debug-mode doesn't like it.

llvm-svn: 140337
2011-09-22 21:17:02 +00:00
David Blaikie 319b738e17 ArrayRef-ifying MacroArgs::create's arguments argument.
llvm-svn: 140288
2011-09-22 02:03:12 +00:00
David Blaikie 441417a954 Simplify the last character check.
llvm-svn: 140287
2011-09-22 01:35:49 +00:00
Benjamin Kramer 2e9d9cfc39 More MSVC9 unbreaking.
llvm-svn: 140256
2011-09-21 16:58:20 +00:00
Argyrios Kyrtzidis 45e8cf5732 [libclang] When pointing at a macro expansion inside a macro argument,
return a cursor for the inner macro.

llvm-svn: 140207
2011-09-20 23:27:33 +00:00
Argyrios Kyrtzidis 0d48fb89c0 The location of the name in MacroDefinition is the beginning of its range,
don't store an extra location for it.

llvm-svn: 140190
2011-09-20 22:14:48 +00:00
Argyrios Kyrtzidis a35c4441b3 Fix gcc build.
llvm-svn: 140073
2011-09-19 22:02:08 +00:00
Argyrios Kyrtzidis 7f44836998 Introduce local_begin()/local_end() methods in PreprocessingRecord which
return iterators for local, non-loaded, preprocessed entities.

llvm-svn: 140062
2011-09-19 20:40:42 +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
Argyrios Kyrtzidis e6e67deeed Rename SourceLocation::getFileLocWithOffset -> getLocWithOffset.
It already works (and is useful with) macro locs as well.

llvm-svn: 140057
2011-09-19 20:40:19 +00:00
Francois Pichet 0706d203cf Rename LangOptions::Microsoft to LangOptions::MicrosoftExt to make it clear that this flag must be used only for Microsoft extensions and not emulation; to avoid confusion with the new LangOptions::MicrosoftMode flag.
Many of the code now under LangOptions::MicrosoftExt will eventually be moved under the LangOptions::MicrosoftMode flag.

llvm-svn: 139987
2011-09-17 17:15:52 +00:00
Douglas Gregor 5d1bee253c When we load header file information from the external source (i.e.,
the AST reader), merge that header file information with whatever
header file information we already have. Otherwise, we might forget
something we already knew (e.g., that the header was #import'd already).

llvm-svn: 139979
2011-09-17 05:35:18 +00:00
Douglas Gregor 88b4ddfa91 Tweak the module auto-import heuristics a bit
llvm-svn: 139887
2011-09-16 00:22:46 +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
Argyrios Kyrtzidis 03c40c5182 [PCH] Overhaul how preprocessed entities are [de]serialized.
-Use an array of offsets for all preprocessed entities
-Get rid of the separate array of offsets for just macro definitions;
 for references to macro definitions use an index inside the preprocessed
 entities array.
-Deserialize each preprocessed entity lazily, at first request; not in bulk.

Paves the way for binary searching of preprocessed entities that will offer
efficiency and will simplify things on the libclang side a lot.

llvm-svn: 139809
2011-09-15 18:02:56 +00:00
Douglas Gregor 1735f4e752 For modules, use a hash of the compiler version, language options, and
target triple to separate modules built under different
conditions. The hash is used to create a subdirectory in the module
cache path where other invocations of the compiler (with the same
version, language options, etc.) can find the precompiled modules.

llvm-svn: 139662
2011-09-13 23:15:45 +00:00
Douglas Gregor faeb1d4658 When an import statement fails to find a module in the module cache,
but there is a corresponding umbrella header in a framework, build the
module on-the-fly so it can be immediately loaded at the import
statement. This is very much proof-of-concept code, with details to be
fleshed out over time.

llvm-svn: 139558
2011-09-12 23:31:24 +00:00
Douglas Gregor 1e44e02292 Introduce a cc1-level option to provide the path to the module cache,
where the compiler will look for module files. Eliminates the
egregious hack where we looked into the header search paths for
modules.

llvm-svn: 139538
2011-09-12 20:41:59 +00:00
Argyrios Kyrtzidis 80f78b961a [libclang] Fix annotation and getting a "macro expansion" cursor
for a builtin macro expansion.

llvm-svn: 139298
2011-09-08 17:18:41 +00:00
Douglas Gregor 8b7d403684 Allow C++0x enumerations with a fixed underlying type in
Objective-C. The @encode'ing of such an enumeration type is the same
as its underlying type. <rdar://problem/5276348>.

llvm-svn: 139297
2011-09-08 17:18:35 +00:00
Douglas Gregor bab8a96f2f Implement the Objective-C 'instancetype' type, which is an alias of
'id' that can be used (only!) via a contextual keyword as the result
type of an Objective-C message send. 'instancetype' then gives the
method a related result type, which we have already been inferring for
a variety of methods (new, alloc, init, self, retain). Addresses
<rdar://problem/9267640>.

llvm-svn: 139275
2011-09-08 01:46:34 +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
Richard Smith a8a5c402bb Advertise support for cxx_range_for as an extension in C++98 mode. Patch by Jean-Daniel Dupas!
Also provide a modicum of test coverage for ranged for in C++98.

llvm-svn: 139149
2011-09-06 18:03:41 +00:00
Benjamin Kramer 17ff23c708 Speed up BCPL comment lexing by looking aggressively for newlines and then scannig backwards to see if the newline is escaped.
3% speedup in preprocessing all of clang with -Eonly. Also includes a small testcase for coverage.

llvm-svn: 139116
2011-09-05 07:19:39 +00:00
Benjamin Kramer dbfb18a0a9 Use the Lexer's definition of whitespace here.
llvm-svn: 139115
2011-09-05 07:19:35 +00:00
Benjamin Kramer 60053cf547 Use const_cast to avoid warnings.
llvm-svn: 139104
2011-09-04 20:26:28 +00:00
Sebastian Redl e9c4e84f8e Add test case for defaulted copy and move structure validation.
Fix bug this uncovered.
Address minor comments from Doug.
Enable cxx_implicit_moves feature.

llvm-svn: 139101
2011-09-04 18:14:28 +00:00
Argyrios Kyrtzidis b914e3bc5c Handle a code-completion token being passed to the macro stringify operator.
Fixes http://llvm.org/PR10826.

llvm-svn: 139087
2011-09-04 03:32:19 +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
Argyrios Kyrtzidis a3deaeeb52 Fix Lexer::ComputePreamble when MaxLines parameter is non-zero.
The function was only counting lines that included tokens and not empty lines,
but MaxLines (mainly initiated to the line where the code-completion point resides)
is a count of overall lines (even empty ones).

llvm-svn: 139085
2011-09-04 03:32:04 +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
Argyrios Kyrtzidis 43ea78b48d Don't try keeping a 'LeadingEmptyMacroLoc' in NullStmt. This fails
in the face of buffering C++/ObjC method bodies.

llvm-svn: 138972
2011-09-01 21:53:45 +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
Douglas Gregor 4a69c2e6c5 Modules hide macro definitions by default, so that silly things like
include guards don't show up as macro definitions in every translation
unit that imports a module. Macro definitions can, however, be
exported with the intentionally-ugly #__export_macro__
directive. Implement this feature by not even bothering to serialize
non-exported macros to a module, because clients of that module need
not (should not) know that these macros even exist.

llvm-svn: 138943
2011-09-01 17:04:32 +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
Eli Friedman 3781a36238 Change err_pp_file_not_found back to an Error; when it's a Warning, we suppress it in system headers. And it is not a good idea to suppress it in system headers. (This was originally changed in r134996 to implement -MG.)
Fixes <rdar://10041960>.  And also brings down the number of warnings without a flag by one :)

llvm-svn: 138842
2011-08-30 23:07:51 +00:00
Douglas Gregor 86325ad2b5 Allow C99 hexfloats in C++0x mode. This change resolves the standards
collision between C99 hexfloats and C++0x user-defined literals by
giving C99 hexfloats precedence. Also, warning about user-defined
literals that conflict with hexfloats and those that have names that
are reserved by the implementation. Fixes <rdar://problem/9940194>.

llvm-svn: 138839
2011-08-30 22:40:35 +00:00
Douglas Gregor 26858b7e10 Add and document __has_feature values for the remaining C++0x
features, so clients can check for the availability of these features
even before we get around to implementing them.

llvm-svn: 138741
2011-08-29 17:28:38 +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
Argyrios Kyrtzidis 7aecbc7661 Make Lexer::ComputePreamble accept a LangOptions parameter, otherwise it may be
out-of-sync how a file is compiled. Patch by Matthias Kleine!

llvm-svn: 138580
2011-08-25 20:39:19 +00:00