Commit Graph

67 Commits

Author SHA1 Message Date
Douglas Gregor a95387786d Don't mark include guard macros as implicitly private. This isn't
actually a terribly good heuristic, and the world is too horrible for
it to work.

llvm-svn: 146393
2011-12-12 18:47:39 +00:00
John McCall 43d4dd49bf Argyrios says this change is required for safety under PTH.
Me, I believe him.

llvm-svn: 142327
2011-10-18 01:36:41 +00:00
John McCall 95ff270ee9 Fix several bugs with #pragma clang arc_cf_code_audited and macros.
llvm-svn: 142324
2011-10-18 00:44:04 +00:00
Douglas Gregor ebf0049901 For modules, all macros that aren't include guards are implicitly
public. Add a __private_macro__ directive to hide a macro, similar to
the __module_private__ declaration specifier.

llvm-svn: 142188
2011-10-17 15:32:29 +00:00
Argyrios Kyrtzidis 7a70d2f11b For the FileChanged Preprocessor callback, when exiting a file, pass its FileID.
llvm-svn: 141681
2011-10-11 17:29:44 +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 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
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
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 61ef3db222 Boost the efficiency of SourceManager::getMacroArgExpandedLocation.
Currently getMacroArgExpandedLocation is very inefficient and for the case
of a location pointing at the main file it will end up checking almost all of
the SLocEntries. Make it faster:

-Use a map of macro argument chunks to their expanded source location. The map
 is for a single source file, it's stored in the file's ContentCache and lazily
 computed, like the source lines cache.
-In SLocEntry's FileInfo add an 'unsigned NumCreatedFIDs' field that keeps track
 of the number of FileIDs (files and macros) that were created during preprocessing
 of that particular file SLocEntry. This is useful when computing the macro argument
 map in skipping included files while scanning for macro arg FileIDs that lexed from
 a specific source file. Due to padding, the new field does not increase the size
 of SLocEntry.

llvm-svn: 138225
2011-08-21 23:33:04 +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
Peter Collingbourne 2f1e36bfd0 Rename tok::eom to tok::eod.
The previous name was inaccurate as this token in fact appears at
the end of every preprocessing directive, not just macro definitions.
No functionality change, except for a diagnostic tweak.

llvm-svn: 126631
2011-02-28 02:37:51 +00:00
Argyrios Kyrtzidis 1cb0de1d4c Fix diagnostic pragmas.
Diagnostic pragmas are broken because we don't keep track of the diagnostic state changes and we only check the current/latest state.
Problems manifest if a diagnostic is emitted for a source line that has different diagnostic state than the current state; this can affect
a lot of places, like C++ inline methods, template instantiations, the lexer, etc.

Fix the issue by having the Diagnostic object keep track of the source location of the pragmas so that it is able to know what is the diagnostic state at any given source location.

Fixes rdar://8365684.

llvm-svn: 121873
2010-12-15 18:44:22 +00:00
Chris Lattner fb24a3a4ec push some source location information down through the compiler,
into ContentCache::getBuffer.  This allows it to produce 
diagnostics on the broken #include line instead of without a 
location.

llvm-svn: 101939
2010-04-20 20:35:58 +00:00
Daniel Dunbar cb9eaf59fb PPCallbacks: Add hook for reaching the end of the main file, and fix DependencyFile to not do work in its destructor.
llvm-svn: 99257
2010-03-23 05:09:10 +00:00
Douglas Gregor 4fb7fbef3b Audit all getBuffer() callers (for both the FullSourceLoc and
SourceManager versions), updating those callers that need to recover
gracefully from failure.

llvm-svn: 98665
2010-03-16 20:01:30 +00:00
Douglas Gregor 874cc62876 Use SourceManager's Diagnostic object for all file-reading errors,
simplifying the SourceManager interfaces somewhat.

llvm-svn: 98598
2010-03-16 00:35:39 +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
Douglas Gregor 9882a5aac6 Teach Preprocessor::macro_begin/macro_end to lazily load all macro
definitions from a precompiled header. This ensures that
code-completion with macro names behaves the same with or without
precompiled headers.

llvm-svn: 92497
2010-01-04 19:18:44 +00:00
Daniel Dunbar 58ecb2ab51 Unbreak and add test case for r90276, a situation in which getBuffer is expected to fail.
Also, update SourceManager.h doxyments for getBuffer() to reflect reality.

llvm-svn: 90701
2009-12-06 09:19:25 +00:00
Daniel Dunbar 1776679e71 Change Preprocessor::EnterSourceFile to make ErrorStr non-optional, clients should be forced to deal with error conditions.
llvm-svn: 90700
2009-12-06 09:19:12 +00:00
Chris Lattner ed3b360290 pass the reason for failure up from MemoryBuffer and report it
in diagnostics when we fail to open a file.  This allows us to
report things like:

$ clang test.c -I.
test.c:2:10: fatal error: error opening file './foo.h': Permission denied
#include "foo.h"
         ^

llvm-svn: 90276
2009-12-01 22:52:33 +00:00
Chris Lattner 710bb87147 Fix PR5633 by making the preprocessor handle the case where we can
stat a file but where mmaping it fails.  In this case, we emit an
error like:
t.c:1:10: fatal error: error opening file '../../foo.h'

instead of "cannot find file".

llvm-svn: 90110
2009-11-30 04:18:44 +00:00
Nuno Lopes 0e5d13e025 remove stall comment
llvm-svn: 90080
2009-11-29 17:07:16 +00:00
Mike Stump 11289f4280 Remove tabs, and whitespace cleanups.
llvm-svn: 81346
2009-09-09 15:08:12 +00:00
Steve Naroff 3fa455a1aa Add PCH support for #import.
llvm-svn: 69987
2009-04-24 20:03:17 +00:00
Chris Lattner 2d17ab783b when preprocessing a .S file, unknown directives should just be passed through,
and the token after the # should be expanded if it is not a valid directive.
This allows us to transform things like:

#define FOO BAR
# FOO

into # BAR, even though FOO is not normally expanded for directives.

This should fix PR3833

llvm-svn: 67236
2009-03-18 21:00:25 +00:00
Chris Lattner 80c21df8ea use accessor instead of poking ivar directly
llvm-svn: 66954
2009-03-13 21:17:23 +00:00
Chris Lattner 9dc9c206d3 track "just a little more" location information for macro instantiations.
Now instead of just tracking the expansion history, also track the full
range of the macro that got replaced.  For object-like macros, this doesn't
change anything.  For _Pragma and function-like macros, this means we track
the locations of the ')'.

This is required for PR3579 because apparently GCC uses the line of the ')'
of a function-like macro as the location to expand __LINE__ to.

llvm-svn: 64601
2009-02-15 20:52:18 +00:00
Chris Lattner 190f64e9b8 add an assertion from Alexei Svitkine!
llvm-svn: 64503
2009-02-13 23:06:48 +00:00
Chris Lattner 5c7cd6043e add interface for walking macro table.
llvm-svn: 63925
2009-02-06 06:26:42 +00:00
Chris Lattner 60f36223a9 move library-specific diagnostic headers into library private dirs. Reduce
redundant #includes.  Patch by Anders Johnsen!

llvm-svn: 63271
2009-01-29 05:15:15 +00:00
Chris Lattner 7368d581c1 Split the single monolithic DiagnosticKinds.def file into one
.def file for each library.  This means that adding a diagnostic
to sema doesn't require all the other libraries to be rebuilt.

Patch by Anders Johnsen!

llvm-svn: 63111
2009-01-27 18:30:58 +00:00
Chris Lattner 4fd8b958be do not use SourceManager::getFileCharacteristic(FileID), it is not
safe because a #line can change the file characteristic on a per-loc
basis.

llvm-svn: 62502
2009-01-19 08:01:53 +00:00
Chris Lattner ab1d4b8abd simplify PTHManager::CreateLexer
llvm-svn: 62424
2009-01-17 08:06:50 +00:00
Chris Lattner c809089b26 Change the Lexer ctor used in the non _Pragma case to take a FileID instead
of a SourceLocation.  This should speed it up and definitely simplifies it.

llvm-svn: 62422
2009-01-17 08:03:42 +00:00
Chris Lattner d32480d3db this massive patch introduces a simple new abstraction: it makes
"FileID" a concept that is now enforced by the compiler's type checker
instead of yet-another-random-unsigned floating around.

This is an important distinction from the "FileID" currently tracked by
SourceLocation.  *That* FileID may refer to the start of a file or to a
chunk within it.  The new FileID *only* refers to the file (and its 
#include stack and eventually #line data), it cannot refer to a chunk.

FileID is a completely opaque datatype to all clients, only SourceManager
is allowed to poke and prod it.

llvm-svn: 62407
2009-01-17 06:22:33 +00:00
Ted Kremenek b0051a9955 Remove old PTH token-generation test harness.
llvm-svn: 61382
2008-12-23 19:25:33 +00:00
Ted Kremenek 78cc24730e PTH: Remove some methods and simplify some conditions in PTHLexer::Lex(). No big functionality change.
llvm-svn: 61381
2008-12-23 19:24:24 +00:00
Ted Kremenek 8e1f05fc26 PreprocessorLexer (and subclasses):
- Added virtual method 'getSourceLocation()' (no arguments) that gets the location of the next "observable" location (e.g., next character, next token).
PPLexerChange.cpp:
- Implemented FIXME by using PreprocessorLexer::getSourceLocation() to get the location in the file we are returning to after lexing a #included file.  This appears to be slightly faster than having the branch (i.e., 'if(CurLexer)').  It's also not a really hot part of the Preprocessor.

llvm-svn: 60860
2008-12-10 23:20:59 +00:00
Ted Kremenek af058b5696 Preprocessor:
- Added method "setPTHManager" that will be called by the driver to install
  a PTHManager for the Preprocessor.
- Fixed some comments.
- Added EnterSourceFileWithPTH to mirror EnterSourceFileWithLexer.

llvm-svn: 60437
2008-12-02 19:46:31 +00:00
Ted Kremenek 1f50dc899f PTHLexer now owns the Token vector.
llvm-svn: 60136
2008-11-27 00:38:24 +00:00
Ted Kremenek 1ad05ce600 Reenable the default lexer.
llvm-svn: 59843
2008-11-21 20:51:59 +00:00
Ted Kremenek b6209858cb When creating the raw tokens for PTHLexer, make sure the token representing the file to include is checked for being an identifier.
llvm-svn: 59842
2008-11-21 20:51:15 +00:00
Ted Kremenek 72d9912b08 When creating raw tokens for the PTHLexer specially handle angled strings for #include directives.
llvm-svn: 59840
2008-11-21 19:41:29 +00:00
Ted Kremenek 6bc5f3ec90 Rename IsNonPragmaNonMacroLexer to IsFileLexer.
llvm-svn: 59731
2008-11-20 16:19:53 +00:00
Ted Kremenek 85b48c6e3a Add ugly "test harness" for PTHLexer that is not enabled by default. The
(temporary hack) to test the PTHLexer is that whenever we would create a Lexer
object we instead raw lex a memory buffer first and then use the PTHLexer. This
logic exists only to driver the PTHLexer and will be removed/changed in the
future. Note that the regular path using normal Lexer objects is what is used by
default.

llvm-svn: 59723
2008-11-20 07:56:33 +00:00
Ted Kremenek 2af3cee287 Make FIXME a hard assertion.
llvm-svn: 59695
2008-11-20 01:52:55 +00:00
Ted Kremenek b33ce32bda Preprocessor::getCurrentFileLexer() now returns a PreprocessorLexer* instead of
a Lexer*. This means it will either return the current (normal) file Lexer or a
PTHLexer.

llvm-svn: 59694
2008-11-20 01:49:44 +00:00
Ted Kremenek a2c3c8d71c Move more cases of using 'CurLexer' to 'CurPPLexer'.
Use PTHLexer::isNextPPTokenLParen() when using the PTHLexer.

llvm-svn: 59671
2008-11-19 22:43:49 +00:00