summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/SourceManager.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Break SourceManager::translateFileLineCol into translateFile, no ↵Argyrios Kyrtzidis2011-09-271-5/+16
| | | | | | functionality change. llvm-svn: 140610
* Associate the macro arguments location map with a FileID insteadArgyrios Kyrtzidis2011-09-261-17/+17
| | | | | | | of a ContentCache, since multiple FileIDs can have the same ContentCache but the expanded macro arguments locations will be different. llvm-svn: 140521
* Rename Diagnostic to DiagnosticsEngine as per issue 5397David Blaikie2011-09-251-4/+4
| | | | llvm-svn: 140478
* In SourceManager::translateLineCol, handle the case where we are pointingArgyrios Kyrtzidis2011-09-201-4/+9
| | | | | | directly at the end of the source file. llvm-svn: 140192
* [libclang] When getting a source location from a file:line:col tripletArgyrios Kyrtzidis2011-09-191-4/+8
| | | | | | | check whether the requested location points inside the precompiled preamble, in which case the returned source location will be a "loaded" one. llvm-svn: 140060
* Break SourceManager::translateFileLineCol into translateLineCol that returns theArgyrios Kyrtzidis2011-09-191-7/+22
| | | | | | source location of line:col of a specific FileID. llvm-svn: 140059
* Rename SourceLocation::getFileLocWithOffset -> getLocWithOffset.Argyrios Kyrtzidis2011-09-191-8/+8
| | | | | | It already works (and is useful with) macro locs as well. llvm-svn: 140057
* For SourceManager::isBeforeInTranslationUnit, a location pointingArgyrios Kyrtzidis2011-09-191-1/+1
| | | | | | | inside a macro argument should be regarded as coming before the location of the expanded tokens. llvm-svn: 140053
* Remove one SourceManager::isInFileID overload and use isOffsetInFileID for ↵Argyrios Kyrtzidis2011-08-231-24/+0
| | | | | | the other. llvm-svn: 138381
* Amend r138129 (reduction of SLocEntries) which introduced performance ↵Argyrios Kyrtzidis2011-08-231-1/+2
| | | | | | | | | | | | | | | | | | | | | | regression due to increased calls to SourceManager::getFileID. (rdar://9992664) Use a slightly different approach that is more efficient both in terms of speed (no extra getFileID calls) and in SLocEntries reduction. Comparing pre-r138129 and this patch we get: For compiling SemaExpr.cpp reduction of SLocEntries by 26%. For the boost enum library: -SLocEntries -34% (note that this was -5% for r138129) -Memory consumption -50% -PCH size -31% Reduced SLocEntries also benefit the hot function SourceManager::getFileID, evident by the reduced "FileID scans". llvm-svn: 138380
* Move a couple of SourceManager functions out-of-line; no functionality change.Argyrios Kyrtzidis2011-08-231-0/+43
| | | | llvm-svn: 138375
* Boost the efficiency of SourceManager::getMacroArgExpandedLocation.Argyrios Kyrtzidis2011-08-211-39/+101
| | | | | | | | | | | | | | | | | | 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
* Refactor common functionality into SourceManager::getFileIDSize, no ↵Argyrios Kyrtzidis2011-08-191-14/+1
| | | | | | functionality change. llvm-svn: 138127
* Introduce SourceManager::getMacroArgExpandedLocation function.Argyrios Kyrtzidis2011-08-171-6/+75
| | | | | | | | | | | | | | | | If we pass it a source location that points inside a function macro argument, the returned location will be the macro location in which the argument was expanded. If a macro argument is used multiple times, the expanded location will be at the first expansion of the argument. e.g. MY_MACRO(foo); ^ Passing a file location pointing at 'foo', will yield a macro location where 'foo' was expanded into. Make SourceManager::getLocation call getMacroArgExpandedLocation as well. llvm-svn: 137794
* Make SourceManager::isBeforeInTranslationUnit handle macro locations correctly.Argyrios Kyrtzidis2011-08-171-7/+3
| | | | llvm-svn: 137793
* Change SourceManager::getDataStructureSizes() to use llvm::capacity_in_bytes().Ted Kremenek2011-07-271-7/+8
| | | | llvm-svn: 136236
* clang_getCXTUResourceUsage: Report memory used by data structures in ↵Ted Kremenek2011-07-261-0/+8
| | | | | | SourceManager. llvm-svn: 136189
* Clean up as many of the comments in Basic I can find to talk in terms ofChandler Carruth2011-07-261-28/+25
| | | | | | 'expansion' rather than 'instantiation' for macro source locations. llvm-svn: 136058
* Migrate 'Instantiation' data and API bits of SLocEntry to 'Expansion'Chandler Carruth2011-07-261-17/+15
| | | | | | | | etc. With this I think essentially all of the SourceManager APIs are converted. Comments and random other bits of cleanup should be all thats left. llvm-svn: 136057
* Convert InstantiationInfo and much of the related code to ExpansionInfoChandler Carruth2011-07-261-17/+17
| | | | | | | | | and various other 'expansion' based terms. I've tried to reformat where appropriate and catch as many references in comments but I'm going to do several more passes. Also I've tried to expand parameter names to be more clear where appropriate. llvm-svn: 136056
* Rename create(MacroArg)InstantiationLoc to create(MacroArg)ExpansionLoc.Chandler Carruth2011-07-261-18/+20
| | | | llvm-svn: 136054
* 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
OpenPOWER on IntegriCloud