Ted Kremenek | 7cd6245 | 2008-11-12 21:37:15 +0000 | [diff] [blame] | 1 | //===--- PTHLexer.cpp - Lex from a token stream ---------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the PTHLexer interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 14 | #include "clang/Basic/TokenKinds.h" |
| 15 | #include "clang/Basic/FileManager.h" |
| 16 | #include "clang/Basic/IdentifierTable.h" |
Douglas Gregor | 52289d3 | 2009-04-20 07:08:21 +0000 | [diff] [blame] | 17 | #include "clang/Basic/OnDiskHashTable.h" |
Ted Kremenek | 7cd6245 | 2008-11-12 21:37:15 +0000 | [diff] [blame] | 18 | #include "clang/Lex/PTHLexer.h" |
| 19 | #include "clang/Lex/Preprocessor.h" |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 20 | #include "clang/Lex/PTHManager.h" |
| 21 | #include "clang/Lex/Token.h" |
| 22 | #include "clang/Lex/Preprocessor.h" |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/OwningPtr.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringExtras.h" |
| 25 | #include "llvm/ADT/StringMap.h" |
Chris Lattner | 34eab39 | 2009-01-22 23:50:07 +0000 | [diff] [blame] | 26 | #include "llvm/Support/MemoryBuffer.h" |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 27 | #include <sys/stat.h> |
Ted Kremenek | 7cd6245 | 2008-11-12 21:37:15 +0000 | [diff] [blame] | 28 | using namespace clang; |
Douglas Gregor | 52289d3 | 2009-04-20 07:08:21 +0000 | [diff] [blame] | 29 | using namespace clang::io; |
Ted Kremenek | 7cd6245 | 2008-11-12 21:37:15 +0000 | [diff] [blame] | 30 | |
Ted Kremenek | 8433f0b | 2009-01-19 23:13:15 +0000 | [diff] [blame] | 31 | #define DISK_TOKEN_SIZE (1+1+2+4+4) |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 32 | |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 34 | // PTHLexer methods. |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 37 | PTHLexer::PTHLexer(Preprocessor &PP, FileID FID, const unsigned char *D, |
Ted Kremenek | 8d178f4 | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 38 | const unsigned char *ppcond, PTHManager &PM) |
Chris Lattner | d32480d | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 39 | : PreprocessorLexer(&PP, FID), TokBuf(D), CurPtr(D), LastHashTokPtr(0), |
Ted Kremenek | 8d178f4 | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 40 | PPCond(ppcond), CurPPCondPtr(ppcond), PTHMgr(PM) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 41 | |
Chris Lattner | d32480d | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 42 | FileStartLoc = PP.getSourceManager().getLocForStartOfFile(FID); |
Ted Kremenek | 47b8cf6 | 2009-01-09 22:05:30 +0000 | [diff] [blame] | 43 | } |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 44 | |
| 45 | void PTHLexer::Lex(Token& Tok) { |
| 46 | LexNextToken: |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 47 | |
Ted Kremenek | 66076a9 | 2008-12-23 02:30:15 +0000 | [diff] [blame] | 48 | //===--------------------------------------==// |
| 49 | // Read the raw token data. |
| 50 | //===--------------------------------------==// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 51 | |
Ted Kremenek | 66076a9 | 2008-12-23 02:30:15 +0000 | [diff] [blame] | 52 | // Shadow CurPtr into an automatic variable. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | const unsigned char *CurPtrShadow = CurPtr; |
Ted Kremenek | 66076a9 | 2008-12-23 02:30:15 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 137d649 | 2009-01-18 02:10:31 +0000 | [diff] [blame] | 55 | // Read in the data for the token. |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 56 | unsigned Word0 = ReadLE32(CurPtrShadow); |
| 57 | uint32_t IdentifierID = ReadLE32(CurPtrShadow); |
| 58 | uint32_t FileOffset = ReadLE32(CurPtrShadow); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 59 | |
Ted Kremenek | 8433f0b | 2009-01-19 23:13:15 +0000 | [diff] [blame] | 60 | tok::TokenKind TKind = (tok::TokenKind) (Word0 & 0xFF); |
| 61 | Token::TokenFlags TFlags = (Token::TokenFlags) ((Word0 >> 8) & 0xFF); |
Chris Lattner | 47def97 | 2009-01-21 07:21:56 +0000 | [diff] [blame] | 62 | uint32_t Len = Word0 >> 16; |
Ted Kremenek | 8433f0b | 2009-01-19 23:13:15 +0000 | [diff] [blame] | 63 | |
Chris Lattner | 47def97 | 2009-01-21 07:21:56 +0000 | [diff] [blame] | 64 | CurPtr = CurPtrShadow; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 65 | |
Ted Kremenek | 66076a9 | 2008-12-23 02:30:15 +0000 | [diff] [blame] | 66 | //===--------------------------------------==// |
| 67 | // Construct the token itself. |
| 68 | //===--------------------------------------==// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 69 | |
Ted Kremenek | 66076a9 | 2008-12-23 02:30:15 +0000 | [diff] [blame] | 70 | Tok.startToken(); |
Chris Lattner | 18fc6ce | 2009-01-18 02:34:01 +0000 | [diff] [blame] | 71 | Tok.setKind(TKind); |
| 72 | Tok.setFlag(TFlags); |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 73 | assert(!LexingRawMode); |
Chris Lattner | d32480d | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 74 | Tok.setLocation(FileStartLoc.getFileLocWithOffset(FileOffset)); |
Ted Kremenek | 66076a9 | 2008-12-23 02:30:15 +0000 | [diff] [blame] | 75 | Tok.setLength(Len); |
| 76 | |
Chris Lattner | 3029b35 | 2009-01-21 07:50:06 +0000 | [diff] [blame] | 77 | // Handle identifiers. |
Ted Kremenek | 8d178f4 | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 78 | if (Tok.isLiteral()) { |
| 79 | Tok.setLiteralData((const char*) (PTHMgr.SpellingBase + IdentifierID)); |
| 80 | } |
| 81 | else if (IdentifierID) { |
Chris Lattner | 3029b35 | 2009-01-21 07:50:06 +0000 | [diff] [blame] | 82 | MIOpt.ReadToken(); |
| 83 | IdentifierInfo *II = PTHMgr.GetIdentifierInfo(IdentifierID-1); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 3029b35 | 2009-01-21 07:50:06 +0000 | [diff] [blame] | 85 | Tok.setIdentifierInfo(II); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 1f6c7fe | 2009-01-23 18:35:48 +0000 | [diff] [blame] | 87 | // Change the kind of this identifier to the appropriate token kind, e.g. |
| 88 | // turning "for" into a keyword. |
| 89 | Tok.setKind(II->getTokenID()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
Chris Lattner | 3029b35 | 2009-01-21 07:50:06 +0000 | [diff] [blame] | 91 | if (II->isHandleIdentifierCase()) |
| 92 | PP->HandleIdentifier(Tok); |
| 93 | return; |
| 94 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 95 | |
Ted Kremenek | 66076a9 | 2008-12-23 02:30:15 +0000 | [diff] [blame] | 96 | //===--------------------------------------==// |
| 97 | // Process the token. |
| 98 | //===--------------------------------------==// |
Chris Lattner | 18fc6ce | 2009-01-18 02:34:01 +0000 | [diff] [blame] | 99 | if (TKind == tok::eof) { |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 100 | // Save the end-of-file token. |
| 101 | EofToken = Tok; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 103 | Preprocessor *PPCache = PP; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 104 | |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 105 | assert(!ParsingPreprocessorDirective); |
| 106 | assert(!LexingRawMode); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 108 | // FIXME: Issue diagnostics similar to Lexer. |
| 109 | if (PP->HandleEndOfFile(Tok, false)) |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 110 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 112 | assert(PPCache && "Raw buffer::LexEndOfFile should return a token"); |
| 113 | return PPCache->Lex(Tok); |
| 114 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | |
Chris Lattner | 18fc6ce | 2009-01-18 02:34:01 +0000 | [diff] [blame] | 116 | if (TKind == tok::hash && Tok.isAtStartOfLine()) { |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 117 | LastHashTokPtr = CurPtr - DISK_TOKEN_SIZE; |
| 118 | assert(!LexingRawMode); |
| 119 | PP->HandleDirective(Tok); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 120 | |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 121 | if (PP->isCurrentLexer(this)) |
| 122 | goto LexNextToken; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 124 | return PP->Lex(Tok); |
| 125 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 126 | |
Chris Lattner | 18fc6ce | 2009-01-18 02:34:01 +0000 | [diff] [blame] | 127 | if (TKind == tok::eom) { |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 128 | assert(ParsingPreprocessorDirective); |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 129 | ParsingPreprocessorDirective = false; |
| 130 | return; |
| 131 | } |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 132 | |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 133 | MIOpt.ReadToken(); |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | // FIXME: We can just grab the last token instead of storing a copy |
| 137 | // into EofToken. |
Ted Kremenek | 78cc247 | 2008-12-23 19:24:24 +0000 | [diff] [blame] | 138 | void PTHLexer::getEOF(Token& Tok) { |
Ted Kremenek | 8ae0662 | 2009-01-09 00:36:11 +0000 | [diff] [blame] | 139 | assert(EofToken.is(tok::eof)); |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 140 | Tok = EofToken; |
| 141 | } |
| 142 | |
| 143 | void PTHLexer::DiscardToEndOfLine() { |
| 144 | assert(ParsingPreprocessorDirective && ParsingFilename == false && |
| 145 | "Must be in a preprocessing directive!"); |
| 146 | |
| 147 | // We assume that if the preprocessor wishes to discard to the end of |
| 148 | // the line that it also means to end the current preprocessor directive. |
| 149 | ParsingPreprocessorDirective = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 151 | // Skip tokens by only peeking at their token kind and the flags. |
| 152 | // We don't need to actually reconstruct full tokens from the token buffer. |
| 153 | // This saves some copies and it also reduces IdentifierInfo* lookup. |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 154 | const unsigned char* p = CurPtr; |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 155 | while (1) { |
| 156 | // Read the token kind. Are we at the end of the file? |
| 157 | tok::TokenKind x = (tok::TokenKind) (uint8_t) *p; |
| 158 | if (x == tok::eof) break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 159 | |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 160 | // Read the token flags. Are we at the start of the next line? |
| 161 | Token::TokenFlags y = (Token::TokenFlags) (uint8_t) p[1]; |
| 162 | if (y & Token::StartOfLine) break; |
| 163 | |
| 164 | // Skip to the next token. |
| 165 | p += DISK_TOKEN_SIZE; |
| 166 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 168 | CurPtr = p; |
| 169 | } |
| 170 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 171 | /// SkipBlock - Used by Preprocessor to skip the current conditional block. |
| 172 | bool PTHLexer::SkipBlock() { |
| 173 | assert(CurPPCondPtr && "No cached PP conditional information."); |
| 174 | assert(LastHashTokPtr && "No known '#' token."); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 176 | const unsigned char* HashEntryI = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | uint32_t Offset; |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 178 | uint32_t TableIdx; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 179 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 180 | do { |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 181 | // Read the token offset from the side-table. |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 182 | Offset = ReadLE32(CurPPCondPtr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
| 184 | // Read the target table index from the side-table. |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 185 | TableIdx = ReadLE32(CurPPCondPtr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 186 | |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 187 | // Compute the actual memory address of the '#' token data for this entry. |
| 188 | HashEntryI = TokBuf + Offset; |
| 189 | |
| 190 | // Optmization: "Sibling jumping". #if...#else...#endif blocks can |
| 191 | // contain nested blocks. In the side-table we can jump over these |
| 192 | // nested blocks instead of doing a linear search if the next "sibling" |
| 193 | // entry is not at a location greater than LastHashTokPtr. |
| 194 | if (HashEntryI < LastHashTokPtr && TableIdx) { |
| 195 | // In the side-table we are still at an entry for a '#' token that |
| 196 | // is earlier than the last one we saw. Check if the location we would |
| 197 | // stride gets us closer. |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 198 | const unsigned char* NextPPCondPtr = |
| 199 | PPCond + TableIdx*(sizeof(uint32_t)*2); |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 200 | assert(NextPPCondPtr >= CurPPCondPtr); |
| 201 | // Read where we should jump to. |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 202 | uint32_t TmpOffset = ReadLE32(NextPPCondPtr); |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 203 | const unsigned char* HashEntryJ = TokBuf + TmpOffset; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 204 | |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 205 | if (HashEntryJ <= LastHashTokPtr) { |
| 206 | // Jump directly to the next entry in the side table. |
| 207 | HashEntryI = HashEntryJ; |
| 208 | Offset = TmpOffset; |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 209 | TableIdx = ReadLE32(NextPPCondPtr); |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 210 | CurPPCondPtr = NextPPCondPtr; |
| 211 | } |
| 212 | } |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 213 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 214 | while (HashEntryI < LastHashTokPtr); |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 215 | assert(HashEntryI == LastHashTokPtr && "No PP-cond entry found for '#'"); |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 216 | assert(TableIdx && "No jumping from #endifs."); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 217 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 218 | // Update our side-table iterator. |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 219 | const unsigned char* NextPPCondPtr = PPCond + TableIdx*(sizeof(uint32_t)*2); |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 220 | assert(NextPPCondPtr >= CurPPCondPtr); |
| 221 | CurPPCondPtr = NextPPCondPtr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 222 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 223 | // Read where we should jump to. |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 224 | HashEntryI = TokBuf + ReadLE32(NextPPCondPtr); |
| 225 | uint32_t NextIdx = ReadLE32(NextPPCondPtr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 226 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 227 | // By construction NextIdx will be zero if this is a #endif. This is useful |
| 228 | // to know to obviate lexing another token. |
| 229 | bool isEndif = NextIdx == 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 230 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 231 | // This case can occur when we see something like this: |
| 232 | // |
| 233 | // #if ... |
| 234 | // /* a comment or nothing */ |
| 235 | // #elif |
| 236 | // |
| 237 | // If we are skipping the first #if block it will be the case that CurPtr |
| 238 | // already points 'elif'. Just return. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 239 | |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 240 | if (CurPtr > HashEntryI) { |
| 241 | assert(CurPtr == HashEntryI + DISK_TOKEN_SIZE); |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 242 | // Did we reach a #endif? If so, go ahead and consume that token as well. |
| 243 | if (isEndif) |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 244 | CurPtr += DISK_TOKEN_SIZE*2; |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 245 | else |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 246 | LastHashTokPtr = HashEntryI; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 247 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 248 | return isEndif; |
| 249 | } |
| 250 | |
| 251 | // Otherwise, we need to advance. Update CurPtr to point to the '#' token. |
Ted Kremenek | 877556f | 2008-12-12 22:05:38 +0000 | [diff] [blame] | 252 | CurPtr = HashEntryI; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 253 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 254 | // Update the location of the last observed '#'. This is useful if we |
| 255 | // are skipping multiple blocks. |
| 256 | LastHashTokPtr = CurPtr; |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 257 | |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 258 | // Skip the '#' token. |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 259 | assert(((tok::TokenKind)*CurPtr) == tok::hash); |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 260 | CurPtr += DISK_TOKEN_SIZE; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 262 | // Did we reach a #endif? If so, go ahead and consume that token as well. |
Ted Kremenek | 1b18ad2 | 2008-12-23 01:30:52 +0000 | [diff] [blame] | 263 | if (isEndif) { CurPtr += DISK_TOKEN_SIZE*2; } |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 264 | |
| 265 | return isEndif; |
| 266 | } |
| 267 | |
Ted Kremenek | 63ff81c | 2008-12-17 23:36:32 +0000 | [diff] [blame] | 268 | SourceLocation PTHLexer::getSourceLocation() { |
Chris Lattner | 137d649 | 2009-01-18 02:10:31 +0000 | [diff] [blame] | 269 | // getSourceLocation is not on the hot path. It is used to get the location |
| 270 | // of the next token when transitioning back to this lexer when done |
Ted Kremenek | 63ff81c | 2008-12-17 23:36:32 +0000 | [diff] [blame] | 271 | // handling a #included file. Just read the necessary data from the token |
| 272 | // data buffer to construct the SourceLocation object. |
| 273 | // NOTE: This is a virtual function; hence it is defined out-of-line. |
Ted Kremenek | ae54f2f | 2009-01-21 22:41:38 +0000 | [diff] [blame] | 274 | const unsigned char *OffsetPtr = CurPtr + (DISK_TOKEN_SIZE - 4); |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 275 | uint32_t Offset = ReadLE32(OffsetPtr); |
Chris Lattner | 137d649 | 2009-01-18 02:10:31 +0000 | [diff] [blame] | 276 | return FileStartLoc.getFileLocWithOffset(Offset); |
Ted Kremenek | 63ff81c | 2008-12-17 23:36:32 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Ted Kremenek | 47b8cf6 | 2009-01-09 22:05:30 +0000 | [diff] [blame] | 279 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 280 | // PTH file lookup: map from strings to file data. |
| 281 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 282 | |
| 283 | /// PTHFileLookup - This internal data structure is used by the PTHManager |
| 284 | /// to map from FileEntry objects managed by FileManager to offsets within |
| 285 | /// the PTH file. |
| 286 | namespace { |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 287 | class VISIBILITY_HIDDEN PTHFileData { |
| 288 | const uint32_t TokenOff; |
| 289 | const uint32_t PPCondOff; |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 290 | public: |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 291 | PTHFileData(uint32_t tokenOff, uint32_t ppCondOff) |
| 292 | : TokenOff(tokenOff), PPCondOff(ppCondOff) {} |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | |
| 294 | uint32_t getTokenOffset() const { return TokenOff; } |
| 295 | uint32_t getPPCondOffset() const { return PPCondOff; } |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 296 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 297 | |
| 298 | |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 299 | class VISIBILITY_HIDDEN PTHFileLookupCommonTrait { |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 300 | public: |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 301 | typedef std::pair<unsigned char, const char*> internal_key_type; |
| 302 | |
| 303 | static unsigned ComputeHash(internal_key_type x) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 304 | return llvm::HashString(x.second); |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 305 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 306 | |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 307 | static std::pair<unsigned, unsigned> |
| 308 | ReadKeyDataLength(const unsigned char*& d) { |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 309 | unsigned keyLen = (unsigned) ReadUnalignedLE16(d); |
| 310 | unsigned dataLen = (unsigned) *(d++); |
| 311 | return std::make_pair(keyLen, dataLen); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 312 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 313 | |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 314 | static internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 315 | unsigned char k = *(d++); // Read the entry kind. |
| 316 | return std::make_pair(k, (const char*) d); |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 317 | } |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 318 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 320 | class VISIBILITY_HIDDEN PTHFileLookupTrait : public PTHFileLookupCommonTrait { |
| 321 | public: |
| 322 | typedef const FileEntry* external_key_type; |
| 323 | typedef PTHFileData data_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 324 | |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 325 | static internal_key_type GetInternalKey(const FileEntry* FE) { |
| 326 | return std::make_pair((unsigned char) 0x1, FE->getName()); |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 327 | } |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 328 | |
| 329 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 330 | return a.first == b.first && strcmp(a.second, b.second) == 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | static PTHFileData ReadData(const internal_key_type& k, |
| 334 | const unsigned char* d, unsigned) { |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 335 | assert(k.first == 0x1 && "Only file lookups can match!"); |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 336 | uint32_t x = ::ReadUnalignedLE32(d); |
| 337 | uint32_t y = ::ReadUnalignedLE32(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 338 | return PTHFileData(x, y); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 339 | } |
| 340 | }; |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 341 | |
| 342 | class VISIBILITY_HIDDEN PTHStringLookupTrait { |
| 343 | public: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | typedef uint32_t |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 345 | data_type; |
| 346 | |
| 347 | typedef const std::pair<const char*, unsigned> |
| 348 | external_key_type; |
| 349 | |
| 350 | typedef external_key_type internal_key_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 351 | |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 352 | static bool EqualKey(const internal_key_type& a, |
| 353 | const internal_key_type& b) { |
| 354 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 355 | : false; |
| 356 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 358 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 359 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 360 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 362 | // This hopefully will just get inlined and removed by the optimizer. |
| 363 | static const internal_key_type& |
| 364 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 366 | static std::pair<unsigned, unsigned> |
| 367 | ReadKeyDataLength(const unsigned char*& d) { |
| 368 | return std::make_pair((unsigned) ReadUnalignedLE16(d), sizeof(uint32_t)); |
| 369 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 371 | static std::pair<const char*, unsigned> |
| 372 | ReadKey(const unsigned char* d, unsigned n) { |
| 373 | assert(n >= 2 && d[n-1] == '\0'); |
| 374 | return std::make_pair((const char*) d, n-1); |
| 375 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 376 | |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 377 | static uint32_t ReadData(const internal_key_type& k, const unsigned char* d, |
| 378 | unsigned) { |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 379 | return ::ReadUnalignedLE32(d); |
| 380 | } |
| 381 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
| 383 | } // end anonymous namespace |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 384 | |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 385 | typedef OnDiskChainedHashTable<PTHFileLookupTrait> PTHFileLookup; |
| 386 | typedef OnDiskChainedHashTable<PTHStringLookupTrait> PTHStringIdLookup; |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 387 | |
| 388 | //===----------------------------------------------------------------------===// |
| 389 | // PTHManager methods. |
| 390 | //===----------------------------------------------------------------------===// |
| 391 | |
| 392 | PTHManager::PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 393 | const unsigned char* idDataTable, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 394 | IdentifierInfo** perIDCache, |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 395 | void* stringIdLookup, unsigned numIds, |
Ted Kremenek | f9ccd5c | 2009-03-19 22:19:30 +0000 | [diff] [blame] | 396 | const unsigned char* spellingBase, |
| 397 | const char* originalSourceFile) |
Ted Kremenek | 73a4d28 | 2008-12-03 01:16:39 +0000 | [diff] [blame] | 398 | : Buf(buf), PerIDCache(perIDCache), FileLookup(fileLookup), |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 399 | IdDataTable(idDataTable), StringIdLookup(stringIdLookup), |
Ted Kremenek | f9ccd5c | 2009-03-19 22:19:30 +0000 | [diff] [blame] | 400 | NumIds(numIds), PP(0), SpellingBase(spellingBase), |
| 401 | OriginalSourceFile(originalSourceFile) {} |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 402 | |
| 403 | PTHManager::~PTHManager() { |
| 404 | delete Buf; |
| 405 | delete (PTHFileLookup*) FileLookup; |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 406 | delete (PTHStringIdLookup*) StringIdLookup; |
Ted Kremenek | 1aed3dd | 2008-12-04 22:47:11 +0000 | [diff] [blame] | 407 | free(PerIDCache); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 410 | static void InvalidPTH(Diagnostic *Diags, Diagnostic::Level level, |
| 411 | const char* Msg = 0) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 412 | if (!Diags) return; |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 413 | if (!Msg) Msg = "Invalid or corrupted PTH file"; |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 414 | unsigned DiagID = Diags->getCustomDiagID(level, Msg); |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 415 | Diags->Report(FullSourceLoc(), DiagID); |
| 416 | } |
| 417 | |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 418 | PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags, |
| 419 | Diagnostic::Level level) { |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 420 | // Memory map the PTH file. |
| 421 | llvm::OwningPtr<llvm::MemoryBuffer> |
| 422 | File(llvm::MemoryBuffer::getFile(file.c_str())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | |
Ted Kremenek | 3b0589e | 2009-01-28 20:49:33 +0000 | [diff] [blame] | 424 | if (!File) { |
| 425 | if (Diags) { |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 426 | unsigned DiagID = Diags->getCustomDiagID(level, |
Ted Kremenek | 3b0589e | 2009-01-28 20:49:33 +0000 | [diff] [blame] | 427 | "PTH file %0 could not be read"); |
| 428 | Diags->Report(FullSourceLoc(), DiagID) << file; |
| 429 | } |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 430 | |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 431 | return 0; |
Ted Kremenek | 3b0589e | 2009-01-28 20:49:33 +0000 | [diff] [blame] | 432 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 434 | // Get the buffer ranges and check if there are at least three 32-bit |
| 435 | // words at the end of the file. |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 436 | const unsigned char* BufBeg = (unsigned char*)File->getBufferStart(); |
| 437 | const unsigned char* BufEnd = (unsigned char*)File->getBufferEnd(); |
Ted Kremenek | eb8c8fb | 2009-01-26 21:43:14 +0000 | [diff] [blame] | 438 | |
| 439 | // Check the prologue of the file. |
Ted Kremenek | 327d00c | 2009-01-26 22:16:12 +0000 | [diff] [blame] | 440 | if ((BufEnd - BufBeg) < (signed) (sizeof("cfe-pth") + 3 + 4) || |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 441 | memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0) { |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 442 | InvalidPTH(Diags, level); |
Ted Kremenek | eb8c8fb | 2009-01-26 21:43:14 +0000 | [diff] [blame] | 443 | return 0; |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 444 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 445 | |
Ted Kremenek | 978b5be | 2009-01-26 21:50:21 +0000 | [diff] [blame] | 446 | // Read the PTH version. |
Ted Kremenek | eb8c8fb | 2009-01-26 21:43:14 +0000 | [diff] [blame] | 447 | const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1); |
Ted Kremenek | 978b5be | 2009-01-26 21:50:21 +0000 | [diff] [blame] | 448 | unsigned Version = ReadLE32(p); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 450 | if (Version != PTHManager::Version) { |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 451 | InvalidPTH(Diags, level, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 452 | Version < PTHManager::Version |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 453 | ? "PTH file uses an older PTH format that is no longer supported" |
| 454 | : "PTH file uses a newer PTH format that cannot be read"); |
Ted Kremenek | 978b5be | 2009-01-26 21:50:21 +0000 | [diff] [blame] | 455 | return 0; |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 456 | } |
Ted Kremenek | 978b5be | 2009-01-26 21:50:21 +0000 | [diff] [blame] | 457 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 458 | // Compute the address of the index table at the end of the PTH file. |
Ted Kremenek | 4c1d41f | 2009-02-11 23:34:32 +0000 | [diff] [blame] | 459 | const unsigned char *PrologueOffset = p; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | |
Ted Kremenek | 4c1d41f | 2009-02-11 23:34:32 +0000 | [diff] [blame] | 461 | if (PrologueOffset >= BufEnd) { |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 462 | InvalidPTH(Diags, level); |
Ted Kremenek | eb8c8fb | 2009-01-26 21:43:14 +0000 | [diff] [blame] | 463 | return 0; |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 464 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 465 | |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 466 | // Construct the file lookup table. This will be used for mapping from |
| 467 | // FileEntry*'s to cached tokens. |
Ted Kremenek | 4c1d41f | 2009-02-11 23:34:32 +0000 | [diff] [blame] | 468 | const unsigned char* FileTableOffset = PrologueOffset + sizeof(uint32_t)*2; |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 469 | const unsigned char* FileTable = BufBeg + ReadLE32(FileTableOffset); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 470 | |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 471 | if (!(FileTable > BufBeg && FileTable < BufEnd)) { |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 472 | InvalidPTH(Diags, level); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 473 | return 0; // FIXME: Proper error diagnostic? |
| 474 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 476 | llvm::OwningPtr<PTHFileLookup> FL(PTHFileLookup::Create(FileTable, BufBeg)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 477 | |
Ted Kremenek | 80e239a | 2009-03-20 17:54:25 +0000 | [diff] [blame] | 478 | // Warn if the PTH file is empty. We still want to create a PTHManager |
| 479 | // as the PTH could be used with -include-pth. |
| 480 | if (FL->isEmpty()) |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 481 | InvalidPTH(Diags, level, "PTH file contains no cached source data"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 482 | |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 483 | // Get the location of the table mapping from persistent ids to the |
| 484 | // data needed to reconstruct identifiers. |
Ted Kremenek | 4c1d41f | 2009-02-11 23:34:32 +0000 | [diff] [blame] | 485 | const unsigned char* IDTableOffset = PrologueOffset + sizeof(uint32_t)*0; |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 486 | const unsigned char* IData = BufBeg + ReadLE32(IDTableOffset); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 487 | |
Ted Kremenek | 8d6c828 | 2009-01-21 07:34:28 +0000 | [diff] [blame] | 488 | if (!(IData >= BufBeg && IData < BufEnd)) { |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 489 | InvalidPTH(Diags, level); |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 490 | return 0; |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 491 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 493 | // Get the location of the hashtable mapping between strings and |
| 494 | // persistent IDs. |
Ted Kremenek | 4c1d41f | 2009-02-11 23:34:32 +0000 | [diff] [blame] | 495 | const unsigned char* StringIdTableOffset = PrologueOffset + sizeof(uint32_t)*1; |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 496 | const unsigned char* StringIdTable = BufBeg + ReadLE32(StringIdTableOffset); |
| 497 | if (!(StringIdTable >= BufBeg && StringIdTable < BufEnd)) { |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 498 | InvalidPTH(Diags, level); |
Ted Kremenek | 62224c1 | 2009-01-28 21:02:43 +0000 | [diff] [blame] | 499 | return 0; |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 500 | } |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 501 | |
| 502 | llvm::OwningPtr<PTHStringIdLookup> SL(PTHStringIdLookup::Create(StringIdTable, |
| 503 | BufBeg)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Ted Kremenek | 8d178f4 | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 505 | // Get the location of the spelling cache. |
Ted Kremenek | 4c1d41f | 2009-02-11 23:34:32 +0000 | [diff] [blame] | 506 | const unsigned char* spellingBaseOffset = PrologueOffset + sizeof(uint32_t)*3; |
Ted Kremenek | 8d178f4 | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 507 | const unsigned char* spellingBase = BufBeg + ReadLE32(spellingBaseOffset); |
| 508 | if (!(spellingBase >= BufBeg && spellingBase < BufEnd)) { |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 509 | InvalidPTH(Diags, level); |
Ted Kremenek | 8d178f4 | 2009-01-27 00:01:05 +0000 | [diff] [blame] | 510 | return 0; |
| 511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Ted Kremenek | 73a4d28 | 2008-12-03 01:16:39 +0000 | [diff] [blame] | 513 | // Get the number of IdentifierInfos and pre-allocate the identifier cache. |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 514 | uint32_t NumIds = ReadLE32(IData); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | |
Ted Kremenek | 73a4d28 | 2008-12-03 01:16:39 +0000 | [diff] [blame] | 516 | // Pre-allocate the peristent ID -> IdentifierInfo* cache. We use calloc() |
| 517 | // so that we in the best case only zero out memory once when the OS returns |
| 518 | // us new pages. |
Ted Kremenek | 8d6c828 | 2009-01-21 07:34:28 +0000 | [diff] [blame] | 519 | IdentifierInfo** PerIDCache = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | |
Ted Kremenek | 8d6c828 | 2009-01-21 07:34:28 +0000 | [diff] [blame] | 521 | if (NumIds) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 522 | PerIDCache = (IdentifierInfo**)calloc(NumIds, sizeof(*PerIDCache)); |
Ted Kremenek | 8d6c828 | 2009-01-21 07:34:28 +0000 | [diff] [blame] | 523 | if (!PerIDCache) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 524 | InvalidPTH(Diags, level, |
Ted Kremenek | dc637a0 | 2009-03-22 06:42:39 +0000 | [diff] [blame] | 525 | "Could not allocate memory for processing PTH file"); |
Ted Kremenek | 8d6c828 | 2009-01-21 07:34:28 +0000 | [diff] [blame] | 526 | return 0; |
| 527 | } |
Ted Kremenek | 73a4d28 | 2008-12-03 01:16:39 +0000 | [diff] [blame] | 528 | } |
Ted Kremenek | 8d6c828 | 2009-01-21 07:34:28 +0000 | [diff] [blame] | 529 | |
Ted Kremenek | f9ccd5c | 2009-03-19 22:19:30 +0000 | [diff] [blame] | 530 | // Compute the address of the original source file. |
| 531 | const unsigned char* originalSourceBase = PrologueOffset + sizeof(uint32_t)*4; |
| 532 | unsigned len = ReadUnalignedLE16(originalSourceBase); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | if (!len) originalSourceBase = 0; |
| 534 | |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 535 | // Create the new PTHManager. |
| 536 | return new PTHManager(File.take(), FL.take(), IData, PerIDCache, |
Ted Kremenek | f9ccd5c | 2009-03-19 22:19:30 +0000 | [diff] [blame] | 537 | SL.take(), NumIds, spellingBase, |
| 538 | (const char*) originalSourceBase); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 539 | } |
Ted Kremenek | f9ccd5c | 2009-03-19 22:19:30 +0000 | [diff] [blame] | 540 | |
Chris Lattner | 144aacd | 2009-01-18 02:57:21 +0000 | [diff] [blame] | 541 | IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) { |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 542 | // Look in the PTH file for the string data for the IdentifierInfo object. |
Chris Lattner | 144aacd | 2009-01-18 02:57:21 +0000 | [diff] [blame] | 543 | const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*PersistentID; |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 544 | const unsigned char* IDData = |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 545 | (const unsigned char*)Buf->getBufferStart() + ReadLE32(TableEntry); |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 546 | assert(IDData < (const unsigned char*)Buf->getBufferEnd()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 547 | |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 548 | // Allocate the object. |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 549 | std::pair<IdentifierInfo,const unsigned char*> *Mem = |
| 550 | Alloc.Allocate<std::pair<IdentifierInfo,const unsigned char*> >(); |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 551 | |
| 552 | Mem->second = IDData; |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 553 | assert(IDData[0] != '\0'); |
Ted Kremenek | 52f73ca | 2009-01-20 23:28:34 +0000 | [diff] [blame] | 554 | IdentifierInfo *II = new ((void*) Mem) IdentifierInfo(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 555 | |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 556 | // Store the new IdentifierInfo in the cache. |
Chris Lattner | 144aacd | 2009-01-18 02:57:21 +0000 | [diff] [blame] | 557 | PerIDCache[PersistentID] = II; |
Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame^] | 558 | assert(II->getNameStart() && II->getNameStart()[0] != '\0'); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 559 | return II; |
| 560 | } |
| 561 | |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 562 | IdentifierInfo* PTHManager::get(const char *NameStart, const char *NameEnd) { |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 563 | PTHStringIdLookup& SL = *((PTHStringIdLookup*)StringIdLookup); |
| 564 | // Double check our assumption that the last character isn't '\0'. |
Daniel Dunbar | ad027c7 | 2009-02-12 19:31:53 +0000 | [diff] [blame] | 565 | assert(NameEnd==NameStart || NameStart[NameEnd-NameStart-1] != '\0'); |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 566 | PTHStringIdLookup::iterator I = SL.find(std::make_pair(NameStart, |
| 567 | NameEnd - NameStart)); |
| 568 | if (I == SL.end()) // No identifier found? |
| 569 | return 0; |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 570 | |
Ted Kremenek | e5554de | 2009-02-11 21:29:16 +0000 | [diff] [blame] | 571 | // Match found. Return the identifier! |
| 572 | assert(*I > 0); |
| 573 | return GetIdentifierInfo(*I-1); |
| 574 | } |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 575 | |
Chris Lattner | ab1d4b8 | 2009-01-17 08:06:50 +0000 | [diff] [blame] | 576 | PTHLexer *PTHManager::CreateLexer(FileID FID) { |
| 577 | const FileEntry *FE = PP->getSourceManager().getFileEntryForID(FID); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 578 | if (!FE) |
| 579 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 580 | |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 581 | // Lookup the FileEntry object in our file lookup data structure. It will |
| 582 | // return a variant that indicates whether or not there is an offset within |
| 583 | // the PTH file that contains cached tokens. |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 584 | PTHFileLookup& PFL = *((PTHFileLookup*)FileLookup); |
| 585 | PTHFileLookup::iterator I = PFL.find(FE); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 586 | |
Ted Kremenek | 86423a9 | 2009-02-10 22:16:22 +0000 | [diff] [blame] | 587 | if (I == PFL.end()) // No tokens available? |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 588 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 589 | |
| 590 | const PTHFileData& FileData = *I; |
| 591 | |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 592 | const unsigned char *BufStart = (const unsigned char *)Buf->getBufferStart(); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 593 | // Compute the offset of the token data within the buffer. |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 594 | const unsigned char* data = BufStart + FileData.getTokenOffset(); |
Ted Kremenek | 56572ab | 2008-12-12 18:34:08 +0000 | [diff] [blame] | 595 | |
| 596 | // Get the location of pp-conditional table. |
Chris Lattner | eb09754 | 2009-01-18 01:57:14 +0000 | [diff] [blame] | 597 | const unsigned char* ppcond = BufStart + FileData.getPPCondOffset(); |
Chris Lattner | fec5470 | 2009-01-22 19:48:26 +0000 | [diff] [blame] | 598 | uint32_t Len = ReadLE32(ppcond); |
Chris Lattner | 137d649 | 2009-01-18 02:10:31 +0000 | [diff] [blame] | 599 | if (Len == 0) ppcond = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 600 | |
Ted Kremenek | a705b04 | 2009-01-15 18:47:46 +0000 | [diff] [blame] | 601 | assert(PP && "No preprocessor set yet!"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 602 | return new PTHLexer(*PP, FID, data, ppcond, *this); |
Ted Kremenek | 33eeabd | 2008-12-03 00:38:03 +0000 | [diff] [blame] | 603 | } |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 604 | |
| 605 | //===----------------------------------------------------------------------===// |
| 606 | // 'stat' caching. |
| 607 | //===----------------------------------------------------------------------===// |
| 608 | |
| 609 | namespace { |
| 610 | class VISIBILITY_HIDDEN PTHStatData { |
| 611 | public: |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 612 | const bool hasStat; |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 613 | const ino_t ino; |
| 614 | const dev_t dev; |
| 615 | const mode_t mode; |
| 616 | const time_t mtime; |
| 617 | const off_t size; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 619 | PTHStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 620 | : hasStat(true), ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
| 621 | |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 622 | PTHStatData() |
| 623 | : hasStat(false), ino(0), dev(0), mode(0), mtime(0), size(0) {} |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 624 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 626 | class VISIBILITY_HIDDEN PTHStatLookupTrait : public PTHFileLookupCommonTrait { |
| 627 | public: |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 628 | typedef const char* external_key_type; // const char* |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 629 | typedef PTHStatData data_type; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 630 | |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 631 | static internal_key_type GetInternalKey(const char *path) { |
| 632 | // The key 'kind' doesn't matter here because it is ignored in EqualKey. |
| 633 | return std::make_pair((unsigned char) 0x0, path); |
| 634 | } |
| 635 | |
| 636 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 637 | // When doing 'stat' lookups we don't care about the kind of 'a' and 'b', |
| 638 | // just the paths. |
| 639 | return strcmp(a.second, b.second) == 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 642 | static data_type ReadData(const internal_key_type& k, const unsigned char* d, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | unsigned) { |
| 644 | |
Ted Kremenek | 2fd18ec | 2009-02-13 22:07:44 +0000 | [diff] [blame] | 645 | if (k.first /* File or Directory */) { |
| 646 | if (k.first == 0x1 /* File */) d += 4 * 2; // Skip the first 2 words. |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 647 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 648 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 649 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 650 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 651 | return data_type(ino, dev, mode, mtime, (off_t) ReadUnalignedLE64(d)); |
| 652 | } |
Ted Kremenek | 2fd18ec | 2009-02-13 22:07:44 +0000 | [diff] [blame] | 653 | |
| 654 | // Negative stat. Don't read anything. |
Ted Kremenek | 29942a3 | 2009-02-13 19:13:46 +0000 | [diff] [blame] | 655 | return data_type(); |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 656 | } |
| 657 | }; |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 658 | |
| 659 | class VISIBILITY_HIDDEN PTHStatCache : public StatSysCallCache { |
| 660 | typedef OnDiskChainedHashTable<PTHStatLookupTrait> CacheTy; |
| 661 | CacheTy Cache; |
| 662 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | public: |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 664 | PTHStatCache(PTHFileLookup &FL) : |
| 665 | Cache(FL.getNumBuckets(), FL.getNumEntries(), FL.getBuckets(), |
| 666 | FL.getBase()) {} |
| 667 | |
| 668 | ~PTHStatCache() {} |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 669 | |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 670 | int stat(const char *path, struct stat *buf) { |
| 671 | // Do the lookup for the file's data in the PTH file. |
| 672 | CacheTy::iterator I = Cache.find(path); |
| 673 | |
| 674 | // If we don't get a hit in the PTH file just forward to 'stat'. |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 675 | if (I == Cache.end()) |
| 676 | return StatSysCallCache::stat(path, buf); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 677 | |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 678 | const PTHStatData& Data = *I; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | |
Ted Kremenek | 2fd18ec | 2009-02-13 22:07:44 +0000 | [diff] [blame] | 680 | if (!Data.hasStat) |
| 681 | return 1; |
| 682 | |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 683 | buf->st_ino = Data.ino; |
| 684 | buf->st_dev = Data.dev; |
| 685 | buf->st_mtime = Data.mtime; |
| 686 | buf->st_mode = Data.mode; |
| 687 | buf->st_size = Data.size; |
| 688 | return 0; |
| 689 | } |
| 690 | }; |
Ted Kremenek | 29b8697 | 2009-02-23 23:27:54 +0000 | [diff] [blame] | 691 | } // end anonymous namespace |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 692 | |
| 693 | StatSysCallCache *PTHManager::createStatCache() { |
Ted Kremenek | b4c85cc | 2009-02-12 03:45:39 +0000 | [diff] [blame] | 694 | return new PTHStatCache(*((PTHFileLookup*) FileLookup)); |
Ted Kremenek | a5c2c27 | 2009-02-12 03:26:59 +0000 | [diff] [blame] | 695 | } |