summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/Lexer.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Initial implementation of a code-completion interface in Clang. InDouglas Gregor2009-09-171-1/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | essence, code completion is triggered by a magic "code completion" token produced by the lexer [*], which the parser recognizes at certain points in the grammar. The parser then calls into the Action object with the appropriate CodeCompletionXXX action. Sema implements the CodeCompletionXXX callbacks by performing minimal translation, then forwarding them to a CodeCompletionConsumer subclass, which uses the results of semantic analysis to provide code-completion results. At present, only a single, "printing" code completion consumer is available, for regression testing and debugging. However, the design is meant to permit other code-completion consumers. This initial commit contains two code-completion actions: one for member access, e.g., "x." or "p->", and one for nested-name-specifiers, e.g., "std::". More code-completion actions will follow, along with improved gathering of code-completion results for the various contexts. [*] In the current -code-completion-dump testing/debugging mode, the file is truncated at the completion point and EOF is translated into "code completion". llvm-svn: 82166
* Remove tabs, and whitespace cleanups.Mike Stump2009-09-091-148/+148
| | | | llvm-svn: 81346
* Convert the CharInfo table to be statically initialized, instead of ↵Chris Lattner2009-07-071-15/+86
| | | | | | dynamically initialized. Patch by Ryan Flynn! llvm-svn: 74919
* fix an out-of-date comment.Chris Lattner2009-07-071-5/+3
| | | | llvm-svn: 74894
* Add support for retrieving the Doxygen comment associated with a givenDouglas Gregor2009-07-021-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | declaration in the AST. The new ASTContext::getCommentForDecl function searches for a comment that is attached to the given declaration, and returns that comment, which may be composed of several comment blocks. Comments are always available in an AST. However, to avoid harming performance, we don't actually parse the comments. Rather, we keep the source ranges of all of the comments within a large, sorted vector, then lazily extract comments via a binary search in that vector only when needed (which never occurs in a "normal" compile). Comments are written to a precompiled header/AST file as a blob of source ranges. That blob is only lazily loaded when one requests a comment for a declaration (this never occurs in a "normal" compile). The indexer testbed now supports comment extraction. When the -point-at location points to a declaration with a Doxygen-style comment, the indexer testbed prints the associated comment block(s). See test/Index/comments.c for an example. Some notes: - We don't actually attempt to parse the comment blocks themselves, beyond identifying them as Doxygen comment blocks to associate them with a declaration. - We won't find comment blocks that aren't adjacent to the declaration, because we start our search based on the location of the declaration. - We don't go through the necessary hops to find, for example, whether some redeclaration of a declaration has comments when our current declaration does not. Similarly, we don't attempt to associate a \param Foo marker in a function body comment with the parameter named Foo (although that is certainly possible). - Verification of my "no performance impact" claims is still "to be done". llvm-svn: 74704
* Fix our check for "random whitespace between a \ and newline" to workChris Lattner2009-06-231-2/+3
| | | | | | | | | | | | | | | with dos style newlines. I have a trivial test for this: // RUN: clang-cc %s -verify #define test(x, y) \ x ## y but I don't know how to get svn to not change newlines and testrunner doesn't work with dos style newlines either, so "not worth it". :) rdar://6994000 llvm-svn: 73945
* Fix rdar://6880630 - # in _Pragma does not start a preprocessor directive.Chris Lattner2009-05-131-2/+2
| | | | llvm-svn: 71643
* Get rid of some useless uses of NoExtensions. The philosophy here is Eli Friedman2009-04-281-2/+1
| | | | | | | | | | | | that if we're going to print an extension warning anyway, there's no point to changing behavior based on NoExtensions: it will only make error recovery worse. Note that this doesn't cause any behavior change because NoExtensions isn't used by the current front-end. I'm still considering what to do about the remaining use of NoExtensions in IdentifierTable.cpp. llvm-svn: 70273
* fix rdar://6816766 - Crash with function-like macro test at end of directive.Chris Lattner2009-04-241-0/+2
| | | | llvm-svn: 69964
* add a new Lexer::SkipEscapedNewLines method.Chris Lattner2009-04-181-0/+23
| | | | llvm-svn: 69483
* factor escape newline measuring out into its own helper function.Chris Lattner2009-04-181-40/+45
| | | | llvm-svn: 69482
* remove unneeded scopes.Chris Lattner2009-04-181-45/+41
| | | | llvm-svn: 69481
* Fix two problems from PR3916, and one problem I noticed while hackingChris Lattner2009-04-171-5/+5
| | | | | | on the code. llvm-svn: 69404
* Change Lexer::MeasureTokenLength to take a LangOptions reference.Chris Lattner2009-04-141-6/+2
| | | | | | | | | | | | | | | | | | This allows it to accurately measure tokens, so that we get: t.cpp:8:13: error: unknown type name 'X' static foo::X P; ~~~~~^ instead of the woefully inferior: t.cpp:8:13: error: unknown type name 'X' static foo::X P; ~~~~ ^ Most of this is just plumbing to push the reference around. llvm-svn: 69099
* fix rdar://6757323, where an escaped newline in a // commentChris Lattner2009-04-051-0/+8
| | | | | | was causing the char after the newline to get eaten. llvm-svn: 68430
* A code modification hint for files that don't end in a newline.Mike Stump2009-04-021-1/+3
| | | | | | | Eventually, would be nice to be able to run these modifications even when we don't want the warning or errors for the actual diagnostic. llvm-svn: 68272
* silence some errors that should not apply to .S files on code like:Chris Lattner2009-03-181-4/+4
| | | | | | | | '' ' ' llvm-svn: 67237
* properly form a full token for # before calling HandleDirective.Chris Lattner2009-03-181-6/+7
| | | | llvm-svn: 67235
* simplify some logic by making ScratchBuffer handle the application of trailingChris Lattner2009-03-081-0/+1
| | | | | | | \0's to created tokens instead of making all clients do it. No functionality change. llvm-svn: 66373
* fix PR3609, emit:Chris Lattner2009-02-191-1/+1
| | | | | | | | | | | | | | t.c:1:10: error: missing terminating '>' character #include <stdio.h ^ instead of: t.c:1:10: error: missing terminating " character #include <stdio.h ^ llvm-svn: 65052
* track "just a little more" location information for macro instantiations.Chris Lattner2009-02-151-5/+15
| | | | | | | | | | | | 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
* move library-specific diagnostic headers into library private dirs. ReduceChris Lattner2009-01-291-1/+1
| | | | | | redundant #includes. Patch by Anders Johnsen! llvm-svn: 63271
* Split the single monolithic DiagnosticKinds.def file into oneChris Lattner2009-01-271-1/+1
| | | | | | | | | .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
* Fix a bug I introduced in my changes, which caused MeasureTokenLengthChris Lattner2009-01-261-1/+2
| | | | | | | to crash when given an instantiation location. Thanks to Fariborz for the testcase. llvm-svn: 63057
* allow _Pragmas formed from #defines to keep their full instantiationChris Lattner2009-01-261-2/+1
| | | | | | history llvm-svn: 63035
* This change refactors some of the low-level lexer interfaces a bit.Chris Lattner2009-01-261-3/+10
| | | | | | | | | | | | | Token now has a class of kinds for "literals", which include numeric constants, strings, etc. These tokens can optionally have a pointer to the start of the token in the lexer buffer. This makes it faster to get spelling and do other gymnastics, because we don't have to go through source locations. This change is performance neutral, but will make other changes more feasible down the road. llvm-svn: 63028
* Check in the long promised SourceLocation rewrite. This lays theChris Lattner2009-01-261-12/+13
| | | | | | | | | | ground work for implementing #line, and fixes the "out of macro ID's" problem. There is nothing particularly tricky about the code, other than the very performance sensitive SourceManager::getFileID() method. llvm-svn: 62978
* This is a follow-up to r62675:Chris Lattner2009-01-231-0/+4
| | | | | | | | | | Refactor how the preprocessor changes a token from being an tok::identifier to a keyword (e.g. tok::kw_for). Instead of doing this in HandleIdentifier, hoist this common case out into the caller, so that every keyword doesn't have to go through HandleIdentifier. This drops time in HandleIdentifier from 1.25ms to .62ms, and speeds up clang -Eonly with PTH by about 1%. llvm-svn: 62855
* a trivial micro optimization to save a load.Chris Lattner2009-01-211-2/+2
| | | | llvm-svn: 62676
* Add a bit to IdentifierInfo that acts as a simple predicate whichChris Lattner2009-01-211-1/+3
| | | | | | | | | tells us whether Preprocessor::HandleIdentifier needs to be called. Because this method is only rarely needed, this saves a call and a bunch of random checks. This drops the time in HandleIdentifier from 3.52ms to .98ms on cocoa.h on my machine. llvm-svn: 62675
* Rename SourceManager::getCanonicalFileID -> getFileID. There isChris Lattner2009-01-191-1/+1
| | | | | | no longer such thing as a non-canonical FileID. llvm-svn: 62499
* Make SourceLocation::getFileLoc private to reduce the API exposure of Chris Lattner2009-01-191-7/+9
| | | | | | | SourceLocation. This requires making some cleanups to token pasting and _Pragma expansion. llvm-svn: 62490
* Rename SourceLocation::getFileID to getChunkID, because it returnsChris Lattner2009-01-171-2/+2
| | | | | | | | the chunk ID not the file ID. This exposes problems in TextDiagnosticPrinter where it should have been using the canonical file ID but wasn't. Fix these along the way. llvm-svn: 62427
* simplify some lookups.Chris Lattner2009-01-171-4/+4
| | | | llvm-svn: 62426
* Change the Lexer ctor used to lex _Pragma directives into a static factoryChris Lattner2009-01-171-21/+44
| | | | | | | | | | | method. This lets us clean up the interface and make it more obvious that this method is *really really* _Pragma specific. Note that _Pragma handling uglifies the Lexer in the critical path. It would be very interesting to consider making _Pragma remapping be a new special lexer class of its own. llvm-svn: 62425
* Change the Lexer ctor used in the non _Pragma case to take a FileID insteadChris Lattner2009-01-171-11/+6
| | | | | | of a SourceLocation. This should speed it up and definitely simplifies it. llvm-svn: 62422
* More simplifications to the lexer ctors.Chris Lattner2009-01-171-10/+24
| | | | llvm-svn: 62419
* make the verbose raw-lexer ctor fully explicit instead of havingChris Lattner2009-01-171-9/+3
| | | | | | embedded magic. llvm-svn: 62417
* add a simplified lexer ctor that sets up the lexer to raw-lex anChris Lattner2009-01-171-1/+14
| | | | | | entire file. llvm-svn: 62414
* refactor some common initialization code out of the two lexer ctors.Chris Lattner2009-01-171-52/+45
| | | | llvm-svn: 62411
* this massive patch introduces a simple new abstraction: it makesChris Lattner2009-01-171-10/+14
| | | | | | | | | | | | | | | "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
* Instead of iterating over FileID's, have PTH generation iterate over theChris Lattner2009-01-171-2/+1
| | | | | | | content cache directly. Content cache has a 1-1 mapping with fileentries, whereas multiple FileIDs can be the same FileEntry. llvm-svn: 62401
* Fix PR2477 - clang misparses "//*" in C89 modeChris Lattner2009-01-161-9/+24
| | | | llvm-svn: 62368
* more SourceLocation lexicon change: instead of referring to theChris Lattner2009-01-161-4/+4
| | | | | | "logical" location, refer to the "instantiation" location. llvm-svn: 62316
* Change some terminology in SourceLocation: instead of referring to Chris Lattner2009-01-161-6/+6
| | | | | | | the "physical" location of tokens, refer to the "spelling" location. This is more concrete and useful, tokens aren't really physical objects! llvm-svn: 62309
* rdar://6060752 - don't warn about trigraphs in bcpl-style commentsChris Lattner2008-12-121-1/+6
| | | | llvm-svn: 60942
* fix thought-oChris Lattner2008-12-121-1/+1
| | | | llvm-svn: 60937
* Objective-C keywords are not always identifiers. Some are also C++ keywordsDouglas Gregor2008-12-011-2/+3
| | | | llvm-svn: 60373
* Comment fix.Daniel Dunbar2008-11-251-1/+1
| | | | llvm-svn: 59997
* Fix a weird inconsistency with hex floats. Previously the lexer Chris Lattner2008-11-221-2/+2
| | | | | | | | | would not eat the "-1" in "0x0p-1", but LiteralSupport would accept it when extensions are on. This caused strangeness and failures when hexfloats were properly treated as an extension (not error) in LiteralSupport. llvm-svn: 59865
OpenPOWER on IntegriCloud