summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/SourceManager.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Rename SourceManager (and InstantiationInfo) isMacroArgInstantiation APIChandler Carruth2011-07-261-2/+2
| | | | | | to isMacroArgExpansion. llvm-svn: 136053
* Rename getInstantiationLineNumber to getExpansionLineNumber in bothChandler Carruth2011-07-251-2/+2
| | | | | | SourceManager and FullSourceLoc. llvm-svn: 135969
* Rename getInstantiationColumnNumber to getExpansionColumnNumber in bothChandler Carruth2011-07-251-2/+2
| | | | | | SourceManager and FullSourceLoc. llvm-svn: 135965
* Rename getDecomposedInstantiationLoc to getDecomposedExpansionLoc.Chandler Carruth2011-07-251-7/+7
| | | | llvm-svn: 135962
* getInstantiationLocSlowCase -> getExpansionLocSlowCaseChandler Carruth2011-07-251-2/+2
| | | | llvm-svn: 135961
* Rename SourceManager::getImmediateInstantiationRange toChandler Carruth2011-07-251-5/+5
| | | | | | getImmediateExpansionRange. llvm-svn: 135960
* Rename SourceManager::getInstantiationRange to getExpansionRange.Chandler Carruth2011-07-251-3/+3
| | | | llvm-svn: 135915
* remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner2011-07-231-7/+7
| | | | | | | | LLVM.h imports them into the clang namespace. llvm-svn: 135852
* Revamp the SourceManager to separate the representation of parsedDouglas Gregor2011-07-191-170/+214
| | | | | | | | | | | | | | | | | | | | | | | | | | | source locations from source locations loaded from an AST/PCH file. Previously, loading an AST/PCH file involved carefully pre-allocating space at the beginning of the source manager for the source locations and FileIDs that correspond to the prefix, and then appending the source locations/FileIDs used for parsing the remaining translation unit. This design forced us into loading PCH files early, as a prefix, whic has become a rather significant limitation. This patch splits the SourceManager space into two parts: for source location "addresses", the lower values (growing upward) are used to describe parsed code, while upper values (growing downward) are used for source locations loaded from AST/PCH files. Similarly, positive FileIDs are used to describe parsed code while negative FileIDs are used to file/macro locations loaded from AST/PCH files. As a result, we can load PCH/AST files even during parsing, making various improvemnts in the future possible, e.g., teaching #include <foo.h> to look for and load <foo.h.gch> if it happens to be already available. This patch was originally written by Sebastian Redl, then brought forward to the modern age by Jonathan Turner, and finally polished/finished by me to be committed. llvm-svn: 135484
* Keep track of which source locations are part of a macro argumentChandler Carruth2011-07-071-4/+27
| | | | | | | | | | | | | | | | | | | | instantiation and improve diagnostics which are stem from macro arguments to trace the argument itself back through the layers of macro expansion. This requires some tricky handling of the source locations, as the argument appears to be expanded in the opposite direction from the surrounding macro. This patch provides helper routines that encapsulate the logic and explain the reasoning behind how we step through macros during diagnostic printing. This fixes the rest of the test cases originially in PR9279, and later split out into PR10214 and PR10215. There is still some more work we can do here to improve the macro backtrace, but those will follow as separate patches. llvm-svn: 134660
* Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the ↵Argyrios Kyrtzidis2011-07-071-55/+0
| | | | | | Lexer, since they depend on it now. llvm-svn: 134644
* Make the Preprocessor more memory efficient and improve macro instantiation ↵Argyrios Kyrtzidis2011-07-071-52/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | diagnostics. When a macro instantiation occurs, reserve a SLocEntry chunk with length the full length of the macro definition source. Set the spelling location of this chunk to point to the start of the macro definition and any tokens that are lexed directly from the macro definition will get a location from this chunk with the appropriate offset. For any tokens that come from argument expansion, '##' paste operator, etc. have their instantiation location point at the appropriate place in the instantiated macro definition (the argument identifier and the '##' token respectively). This improves macro instantiation diagnostics: Before: t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int') int y = M(/); ^~~~ t.c:5:11: note: instantiated from: int y = M(/); ^ After: t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int') int y = M(/); ^~~~ t.c:3:20: note: instantiated from: \#define M(op) (foo op 3); ~~~ ^ ~ t.c:5:11: note: instantiated from: int y = M(/); ^ The memory savings for a candidate boost library that abuses the preprocessor are: - 32% less SLocEntries (37M -> 25M) - 30% reduction in PCH file size (900M -> 635M) - 50% reduction in memory usage for the SLocEntry table (1.6G -> 800M) llvm-svn: 134587
* Fix bug in SourceManager::getDecomposedInstantiationLocSlowCase.Argyrios Kyrtzidis2011-07-071-3/+4
| | | | | | | | | | | | | It would add up relative (decomposed) offsets like in getDecomposedSpellingLocSlowCase, but while it makes sense to preserve the offset among lexed spelling locations, it doesn't make sense to add anything to the offset of the instantiation location. The instantiation location will be the same regardless of the relative offset in the tokens that were instantiated. This bug didn't actually affect anything because, currently, in practice we never create macro locations with relative offset greater than 0. llvm-svn: 134586
* For -print-stats, add the number of bytes that SLocEntryTable consumes.Argyrios Kyrtzidis2011-07-071-1/+3
| | | | llvm-svn: 134585
* SmallVectorize a critical vector.Benjamin Kramer2011-07-061-1/+1
| | | | | | | The small number of elements was determined by taking the median file length in clang+llvm and /usr/include on OS X with xcode installed. llvm-svn: 134496
* SourceManager::isAtStartOfMacroInstantiation should check not only if the ↵Argyrios Kyrtzidis2011-06-241-1/+5
| | | | | | | | location is at the first token but that the location's offset is not inside the token as well. llvm-svn: 133800
* Make more use of llvm::StringRef in various APIs. In particular, don'tJay Foad2011-06-211-4/+4
| | | | | | use the deprecated forms of llvm::StringMap::GetOrCreateValue(). llvm-svn: 133515
* Add a couple of helper methods in the SourceManager API, ↵Argyrios Kyrtzidis2011-05-281-0/+67
| | | | | | | | isAtStartOfMacroInstantiation/isAtEndOfMacroInstantiation useful only for source locations that point at a macro token. llvm-svn: 132247
* Do some safety checks.Argyrios Kyrtzidis2011-05-171-0/+6
| | | | llvm-svn: 131491
* Enhance clang_getCXTUResourceUsage() to report how much memory is used by ↵Ted Kremenek2011-04-281-0/+34
| | | | | | SourceManager's memory buffers. llvm-svn: 130433
* Teach SourceManager::getSLocEntry() that it can fail due to problemsDouglas Gregor2011-04-201-22/+91
| | | | | | | | during deserialization from a precompiled header, and update all of its callers to note when this problem occurs and recover (more) gracefully. Fixes <rdar://problem/9119249>. llvm-svn: 129839
* fix a bunch of comment typos found by codespell. Patch byChris Lattner2011-04-151-2/+2
| | | | | | Luis Felipe Strano Moraes! llvm-svn: 129559
* Eat the UTF-8 BOM at the beginning of a file since it's ignored anyhow.Eric Christopher2011-04-091-6/+5
| | | | | | | | Nom Nom Nom. Patch by Anton Korobeynikov! llvm-svn: 129174
* Add 'OverridenFilesKeepOriginalName' field in SourceManager which if true ↵Argyrios Kyrtzidis2011-03-081-2/+4
| | | | | | | | | | | the SourceManager should report the original file name for contents of files that were overriden by other files, otherwise it should report the name of the new file. Default is true. Also add similar field in PreprocessorOptions and pass similar parameter in ASTUnit::LoadFromCommandLine. llvm-svn: 127289
* Currently we can only remap a file by creating a MemoryBuffer and replacing ↵Argyrios Kyrtzidis2011-03-051-18/+38
| | | | | | | | | the file contents with it. Allow remapping a file by specifying another filename whose contents should be loaded if the original file gets loaded. This allows to override files without having to create & load buffers in advance. llvm-svn: 127052
* Switch the VerifyDiagnosticsClient to use PresumedLocs now that theyChandler Carruth2011-02-231-3/+14
| | | | | | | exist. Cheat and do this by adding some wrappers around the PresumedLoc machinery that directly return the line and column number. llvm-svn: 126281
* Fix a thinko with llvm::Optional, which is clearly the most dangerous class ↵Douglas Gregor2011-02-161-4/+8
| | | | | | template in the universe llvm-svn: 125679
* Don't compare llvm::Optional<> objects directly; compare theirDouglas Gregor2011-02-111-8/+14
| | | | | | contents when it's safe. I just *love* C++ some days. llvm-svn: 125378
* Teach SourceManager::getLocation() how to cope with a source fileDouglas Gregor2011-02-031-18/+84
| | | | | | | | | | | | | | | | whose inode has changed since the file was first created and that is being seen through a different path name (e.g., due to symlinks or relative path elements), such that its FileEntry pointer doesn't match a known FileEntry pointer. Since this requires a system call (to stat()), we only perform this deeper checking if we can't find the file by comparing FileEntry pointers. Also, add a micro-optimization where we don't bother to compute line numbers when given the location (1, 1). This improves the efficiency of clang_getLocationForOffset(). llvm-svn: 124800
* Harden Lexer::GetBeginningOfToken() against bogus source locations andDouglas Gregor2011-01-311-2/+11
| | | | | | the disappearance/alteration of files. llvm-svn: 124616
* Handle locations coming from macro instantiations properly in ↵Argyrios Kyrtzidis2010-12-241-0/+7
| | | | | | | | SourceManager::isBeforeInTranslationUnit(). Fixes rdar://8790245 and http://llvm.org/PR8821. llvm-svn: 122536
* Merge System into Support.Michael J. Spencer2010-11-291-1/+1
| | | | llvm-svn: 120297
* reduce indentation and use early outs, to make it easier to readChris Lattner2010-11-231-72/+79
| | | | | | this code. no functionality change. llvm-svn: 120011
* now the FileManager has a FileSystemOpts ivar, stop threadingChris Lattner2010-11-231-6/+3
| | | | | | | | | FileSystemOpts through a ton of apis, simplifying a lot of code. This also fixes a latent bug in ASTUnit where it would invoke methods on FileManager without creating one in some code paths in cindextext. llvm-svn: 120010
* Partially revert Doug's PCH validation patch (r98585).Chris Lattner2010-11-231-14/+4
| | | | | | | | | | | | | | | | | | | | | | This patch completely defeated the "passing in a prestat'd size to MemoryBuffer" optimization, leading to an extra fstat call for every buffer opened, in order to find out if the datestamp and size of the file on disk matches what is in the stat cache. I fully admit that I don't completely understand what is going on here: why punish code when a stat cache isn't in use? what is the point of a stat cache if you have to turn around and stat stuff to validate it? To resolve both these issues, just drop the modtime check and check the file size, which is the important thing anyway. This should also resolve PR6812, because presumably windows is stable when it comes to file sizes. If the modtime is actually important, we should get it and keep it on the first stat. This eliminates 833 fstat syscalls when processing Cocoa.h, speeding up system time on -Eonly Cocoa.h from 0.041 to 0.038s. llvm-svn: 120001
* Refactoring of Diagnostic class.Argyrios Kyrtzidis2010-11-181-3/+12
| | | | | | | | | | | -Move the stuff of Diagnostic related to creating/querying diagnostic IDs into a new DiagnosticIDs class. -DiagnosticIDs can be shared among multiple Diagnostics for multiple translation units. -The rest of the state in Diagnostic object is considered related and tied to one translation unit. -Have Diagnostic point to the SourceManager that is related with. Diagnostic can now accept just a SourceLocation instead of a FullSourceLoc. -Reflect the changes to various interfaces. llvm-svn: 119730
* Fix a typo in the UTF-8 BOM (PR8645). Use a StringSwitch while at it.Benjamin Kramer2010-11-181-24/+15
| | | | llvm-svn: 119698
* Implement -working-directory.Argyrios Kyrtzidis2010-11-031-3/+4
| | | | | | | | | | | | | | | | | | | When -working-directory is passed in command line, file paths are resolved relative to the specified directory. This helps both when using libclang (where we can't require the user to actually change the working directory) and to help reproduce test cases when the reproduction work comes along. --FileSystemOptions is introduced which controls how file system operations are performed (currently it just contains the working directory value if set). --FileSystemOptions are passed around to various interfaces that perform file operations. --Opening & reading the content of files should be done only through FileManager. This is useful in general since file operations will be abstracted in the future for the reproduction mechanism. FileSystemOptions is independent of FileManager so that we can have multiple translation units sharing the same FileManager but with different FileSystemOptions. Addresses rdar://8583824. llvm-svn: 118203
* Teach SourceManager::getPresumedLoc() how to fail gracefully if ↵Douglas Gregor2010-11-021-2/+8
| | | | | | getLineNumber/getColumnNumber fail llvm-svn: 117990
* getOrCreateContentCache never returns null, so overrideFileContentsDan Gohman2010-10-261-4/+2
| | | | | | doesn't need its return value. llvm-svn: 117393
* Update remaining attribute macros to new style.Chandler Carruth2010-10-231-1/+1
| | | | llvm-svn: 117204
* Fix handling of the 'Invalid' argument in SourceManager's methods (patch by ↵Zhanyong Wan2010-10-051-5/+14
| | | | | | Dean Sturtevant, reviewed by chandlerc and Sebastian Redl). llvm-svn: 115638
* Fix a typo.Dan Gohman2010-08-261-1/+1
| | | | llvm-svn: 112219
* More PCH -> AST renaming.Sebastian Redl2010-08-181-1/+1
| | | | llvm-svn: 111472
* Add a test case for tentative definitions in chained PCH. Fix a bug that ↵Sebastian Redl2010-07-281-1/+4
| | | | | | completely messed up source locations and thus caused a crash whenever a diagnostic was emitted in chained PCH files. llvm-svn: 109660
* Introduce basic support for loading a precompiled preamble whileDouglas Gregor2010-07-261-11/+14
| | | | | | | | | | | | | | | | | | | | | | | reparsing an ASTUnit. When saving a preamble, create a buffer larger than the actual file we're working with but fill everything from the end of the preamble to the end of the file with spaces (so the lexer will quickly skip them). When we load the file, create a buffer of the same size, filling it with the file and then spaces. Then, instruct the lexer to start lexing after the preamble, therefore continuing the parse from the spot where the preamble left off. It's now possible to perform a simple preamble build + parse (+ reparse) with ASTUnit. However, one has to disable a bunch of checking in the PCH reader to do so. That part isn't committed; it will likely be handled with some other kind of flag (e.g., -fno-validate-pch). As part of this, fix some issues with null termination of the memory buffers created for the preamble; we were trying to explicitly NULL-terminate them, even though they were also getting implicitly NULL terminated, leading to excess warnings about NULL characters in source files. llvm-svn: 109445
* clean up isBeforeInTranslationUnit by factoring out some commonChris Lattner2010-05-071-24/+34
| | | | | | | code into a MoveUpIncludeHierarchy helper, and use the helper to fix a case involving macros which regressed from my recent patch. llvm-svn: 103288
* reimplement the guts of SourceManager::isBeforeInTranslationUnitChris Lattner2010-05-071-53/+56
| | | | | | | | | | | to be algorithmically faster and avoid an std::map. This routine basically boils down to finding the nearest common ancestor in a tree, and we (implicitly) have information about nesting depth, use it! This wraps up rdar://7948633 - SourceManager::isBeforeInTranslationUnit has poor performance llvm-svn: 103239
* start using the caching now that it appears to work!Chris Lattner2010-05-071-16/+4
| | | | llvm-svn: 103236
* reimplement the caching in the SourceManager::isBeforeInTranslationUnit()Chris Lattner2010-05-071-20/+31
| | | | | | | | method to be correct. Right now it correctly computes the cache, then goes ahead and computes the result the hard way, then asserts that they match. Next I'll actually turn it on. llvm-svn: 103231
OpenPOWER on IntegriCloud