Commit Graph

202 Commits

Author SHA1 Message Date
Roman Divacky e637711ae0 Dont cast away const needlessly. Found by gcc48 -Wcast-qual.
llvm-svn: 163325
2012-09-06 15:59:27 +00:00
Eli Friedman 324adad966 Make a bunch of methods on Lexer private.
llvm-svn: 162970
2012-08-31 02:29:37 +00:00
Dmitri Gribenko 4aa05c571e Lexer: remove dead stores. Found by Clang static analyzer!
llvm-svn: 160973
2012-07-30 17:59:40 +00:00
Richard Smith 608c0b65d7 Add warning flag -Winvalid-pp-token for preprocessing-tokens which have
undefined behaviour, and move the diagnostic for '' from an Error into
an ExtWarn in this group. This is important for some users of the preprocessor,
and is necessary for gcc compatibility.

llvm-svn: 159335
2012-06-28 07:51:56 +00:00
James Dennett f442d2455b Documentation cleanup:
* Removed docs for Lexer::makeFileCharRange from Lexer.cpp, as they're in
  the header file;
* Reworked the documentation for SkipBlockComment so that it doesn't confuse
  Doxygen's comment parsing;
* Added another summary with \brief markup.

llvm-svn: 158618
2012-06-17 03:40:43 +00:00
Jordan Rose 127f6eef7e [-E] Emit a rewritten _Pragma on its own line.
1. Teach Lexer that pragma lexers are like macro expansions at EOF.
2. Treat pragmas like #define/#undef when printing.
3. If we just printed a directive, add a newline before any more tokens.
(4. Miscellaneous cleanup in PrintPreprocessedOutput.cpp)

PR10594 and <rdar://problem/11562490> (two separate related problems)

llvm-svn: 158571
2012-06-15 23:33:51 +00:00
James Dennett ff3c995624 Documentation cleanup: escape backslashes in Doxygen comments.
llvm-svn: 158552
2012-06-15 21:36:54 +00:00
Richard Smith e6799ddae8 PR12717: Clang supports hexadecimal floating-point literals in all language
modes. For languages other than C99/C11, this isn't quite a conforming
extension, and for C++11, it breaks some reasonable code containing
user-defined literals.

In languages which don't officially have hexfloats, pare back this extension
to only apply in cases where the token starts 0x and does not contain an
underscore. The extension is still not quite conforming, but it's a lot closer
now.

llvm-svn: 158487
2012-06-15 05:07:49 +00:00
David Blaikie 2af2b3071d Fix PR13065.
This condition (added in r158093) was overly conservative.

llvm-svn: 158483
2012-06-15 00:47:13 +00:00
Dmitri Gribenko 702b732d6f Correct method name in comment: from LexRawToken to LexFromRawLexer, according
to a change done long ago in r57393.

llvm-svn: 158243
2012-06-08 23:19:37 +00:00
Jordan Rose 288c421b3d Insert a space if necessary when suggesting CFBridgingRetain/Release.
This was a problem for people who write 'return(result);'

Also fix ARCMT's corresponding code, though there's no test case for this
because implicit casts like this are rejected by the migrator for being
ambiguous, and explicit casts have no problem.

<rdar://problem/11577346>

llvm-svn: 158130
2012-06-07 01:10:31 +00:00
David Blaikie d5321247c4 Add a -rewrite-includes option, which is similar to -rewrite-macros, but only expands #include directives.
Patch contributed by Lubos Lunak (l.lunax@suse.cz).
Review by Matt Beaumont-Gay (matthewbg@google.com).

llvm-svn: 158093
2012-06-06 18:52:13 +00:00
David Blaikie 987bcf9462 Escape \n and \r in doxycomment.
llvm-svn: 158091
2012-06-06 18:43:20 +00:00
Benjamin Kramer e5fbc6c85d Lexer::ReadToEndOfLine: Only build the string if it's actually used and do so in a less malloc-intensive way.
llvm-svn: 157064
2012-05-18 19:32:16 +00:00
Seth Cantrell e83c731cad Support -Wc++98-compat-pedantic as requested:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120409/056126.html

llvm-svn: 154655
2012-04-13 03:43:23 +00:00
Seth Cantrell 10ac7205ce C++11 no longer requires files to end with a newline
llvm-svn: 154643
2012-04-13 01:00:34 +00:00
Francois Pichet 7ebc4c1910 ext_reserved_user_defined_literal must not default to Error in MicrosoftMode. Hence create ext_ms_reserved_user_defined_literal that doesn't default to Error; otherwise MSVC headers won't parse.
Fixes PR12383.

llvm-svn: 154273
2012-04-07 23:09:23 +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
Richard Smith 0df56f4a90 Implement C++11 [lex.ext]p10 for string and character literals: a ud-suffix not
starting with an underscore is ill-formed.

Since this rule rejects programs that were using <inttypes.h>'s macros, recover
from this error by treating the ud-suffix as a separate preprocessing-token,
with a DefaultError ExtWarn. The approach of treating such cases as two tokens
is under discussion for standardization, but is in any case a conforming
extension and allows existing codebases to keep building while the committee
makes up its mind.

Reword the warning on the definition of literal operators not starting with
underscores (which are, strangely, legal) to more explicitly state that such
operators can't be called by literals. Remove the special-case diagnostic for
hexfloats, since it was both triggering in the wrong cases and incorrect.

llvm-svn: 152287
2012-03-08 02:39:21 +00:00
Richard Smith 3e4a60a2cd Add -Wc++11-compat warning for string and character literals followed by
identifiers, in cases where those identifiers would be treated as
user-defined literal suffixes in C++11.

llvm-svn: 152198
2012-03-07 03:13:00 +00:00
Richard Smith d67aea28f6 User-defined literals: reject string and character UDLs in all places where the
grammar requires a string-literal and not a user-defined-string-literal. The
two constructs are still represented by the same TokenKind, in order to prevent
a combinatorial explosion of different kinds of token. A flag on Token tracks
whether a ud-suffix is present, in order to prevent clients from needing to look
at the token's spelling.

llvm-svn: 152098
2012-03-06 03:21:47 +00:00
Richard Smith e18f0faff2 Lexing support for user-defined literals. Currently these lex as the same token
kinds as the underlying string literals, and we silently drop the ud-suffix;
those issues will be fixed by subsequent patches.

llvm-svn: 152012
2012-03-05 04:02:15 +00:00
Argyrios Kyrtzidis 0d9e24b1db Change Lexer::makeFileCharRange() to have it accept a CharSourceRange
instead of a SourceRange, and handle the case where the range is
a char (not token) range.

llvm-svn: 149677
2012-02-03 05:58:29 +00:00
Argyrios Kyrtzidis abff5f1271 Improve Lexer::getImmediateMacroName to take into account inner macros
of macro arguments.

For "MAC1( MAC2(foo) )" and location of 'foo' token it would return
"MAC1" instead of "MAC2".

llvm-svn: 148704
2012-01-23 16:58:33 +00:00
Argyrios Kyrtzidis 85e7671b71 Enhance Lexer::makeFileCharRange to check for ranges inside a macro argument
expansion, in which case it returns a file range in the location where the
argument was spelled.

llvm-svn: 148551
2012-01-20 16:52:43 +00:00
Argyrios Kyrtzidis 7838a2bffb Introduce Lexer::getSourceText() that returns a string for the source
that the given source range encompasses.

llvm-svn: 148481
2012-01-19 15:59:19 +00:00
Argyrios Kyrtzidis a99e02d019 Introduce Lexer::makeFileCharRange() that accepts a token source range
and returns a character range with file locations.

llvm-svn: 148480
2012-01-19 15:59:14 +00:00
Argyrios Kyrtzidis 1b07c344b4 For Lexer's isAt[Start/End]OfMacroExpansion add an out parameter for the macro
start/end location.

It is commonly needed after calling the function; with this way we avoid
recalculating it.

llvm-svn: 148479
2012-01-19 15:59:08 +00:00
Anna Zaks 1bea4bf590 Refactor: Pull getImmediateMacroName() out of DiagnosticRenderer and
into Lexer and Preprocessor; making it widely available.

llvm-svn: 148410
2012-01-18 20:17:16 +00:00
Chandler Carruth 5b15a9be6a Two variables had been added for an assert, but their values were
re-computed rather than the variables be re-used just after the assert.
Just use the variables since we have them already. Fixes an unused
variable warning.

Also fix an 80-column violation.

llvm-svn: 148212
2012-01-15 09:03:45 +00:00
Argyrios Kyrtzidis 8a26c4de64 In Lexer::getCharAndSizeSlow[NoWarn] if we come up against
\<newline><newline>

don't consume the second newline.

Thanks to David Blaikie for pointing out the crash!

llvm-svn: 147138
2011-12-22 04:38:07 +00:00
Argyrios Kyrtzidis e5cdd080ba In Lexer::getCharAndSizeSlow[NoWarn] make sure we don't go over the end of the buffer
when the end of the buffer is immediately after an escaped newline.

Fixes http://llvm.org/PR10153.

llvm-svn: 147091
2011-12-21 20:19:55 +00:00
David Blaikie 68e081d606 Unweaken vtables as per http://llvm.org/docs/CodingStandards.html#ll_virtual_anch
llvm-svn: 146959
2011-12-20 02:48:34 +00:00
Benjamin Kramer 900f1defdd Remove assert from hot code path and add a clarifying comment.
The assert wasn't adding much value but slowed down Release+Asserts builds.

llvm-svn: 145082
2011-11-22 20:39:31 +00:00
Benjamin Kramer 3885737a1b Lexer: Don't throw away the hard work SSE did to find a slash.
We can reuse the information and avoid looping over all the bytes again.

llvm-svn: 145070
2011-11-22 18:56:46 +00:00
Ted Kremenek a08713ce86 Move about 20 random diagnostics under -W flags. Patch by Ahmed Charles!
llvm-svn: 142284
2011-10-17 21:47:53 +00:00
Richard Smith acd4d3d52a -Wc++98-compat warnings for the lexer.
This also adds a -Wc++98-compat-pedantic for warning on constructs which would
be diagnosed by -std=c++98 -pedantic (that is, it warns even on C++11 features
which we enable by default, with no warning, in C++98 mode).

llvm-svn: 142034
2011-10-15 01:18:56 +00:00
Douglas Gregor 227c352bae We do parse hexfloats in C++11; make it actually work.
llvm-svn: 141798
2011-10-12 18:51:02 +00:00
Richard Smith a9e33d44a6 Handle Perforce-style conflict markers like normal conflict markers. Perforce
swaps over the <<<< and >>>> markers, and uses shorter markers than traditional
tools.

llvm-svn: 141751
2011-10-12 00:37:51 +00:00
Abramo Bagnara e398e60611 Fixed exapnsion range for # and ##.
llvm-svn: 141012
2011-10-03 18:39:03 +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
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
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 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
Argyrios Kyrtzidis f6a3b0ca4b In Lexer::isAtEndOfMacroExpansion use SourceManager::isInFileID and avoid
the extra SourceManager::getFileID call.

llvm-svn: 138376
2011-08-23 21:02:30 +00:00
Argyrios Kyrtzidis 161868db4c Make Lexer::GetBeginningOfToken able to handle macro arg expansion locations.
llvm-svn: 137795
2011-08-17 00:31:23 +00:00