[cfe-commits] r62309 - in /cfe/trunk: Driver/PrintPreprocessedOutput.cpp include/clang/Basic/SourceLocation.h include/clang/Basic/SourceManager.h include/clang/Lex/Preprocessor.h lib/AST/StmtDumper.cpp lib/Analysis/LiveVariables.cpp lib/Basic/Diagnostic.cpp lib/Basic/SourceLocation.cpp lib/Basic/SourceManager.cpp lib/Lex/Lexer.cpp lib/Lex/PTHLexer.cpp lib/Lex/Preprocessor.cpp lib/Lex/PreprocessorLexer.cpp test/Preprocessor/dumptokens_phyloc.c
Chris Lattner
sabre at nondot.org
Thu Jan 15 23:00:02 PST 2009
Author: lattner
Date: Fri Jan 16 01:00:02 2009
New Revision: 62309
URL: http://llvm.org/viewvc/llvm-project?rev=62309&view=rev
Log:
Change some terminology in SourceLocation: instead of referring to
the "physical" location of tokens, refer to the "spelling" location.
This is more concrete and useful, tokens aren't really physical objects!
Modified:
cfe/trunk/Driver/PrintPreprocessedOutput.cpp
cfe/trunk/include/clang/Basic/SourceLocation.h
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/AST/StmtDumper.cpp
cfe/trunk/lib/Analysis/LiveVariables.cpp
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Basic/SourceLocation.cpp
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Lex/PTHLexer.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Lex/PreprocessorLexer.cpp
cfe/trunk/test/Preprocessor/dumptokens_phyloc.c
Modified: cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/Driver/PrintPreprocessedOutput.cpp Fri Jan 16 01:00:02 2009
@@ -124,7 +124,7 @@
if (LineNo-CurLine == 1)
OS << '\n';
else if (LineNo == CurLine)
- return false; // Phys line moved, but logical line didn't.
+ return false; // Spelling line moved, but logical line didn't.
else {
const char *NewLines = "\n\n\n\n\n\n\n\n";
OS.write(NewLines, LineNo-CurLine);
@@ -200,7 +200,7 @@
/// is called for the first token on each new line. If this really is the start
/// of a new logical line, handle it and return true, otherwise return false.
/// This may not be the start of a logical line because the "start of line"
-/// marker is set for physical lines, not logical ones.
+/// marker is set for spelling lines, not logical ones.
bool PrintPPOutputPPCallbacks::HandleFirstTokOnLine(Token &Tok) {
// Figure out what line we went to and insert the appropriate number of
// newline characters.
@@ -319,7 +319,7 @@
static bool StartsWithL(const Token &Tok, Preprocessor &PP) {
if (!Tok.needsCleaning()) {
SourceManager &SrcMgr = PP.getSourceManager();
- return *SrcMgr.getCharacterData(SrcMgr.getPhysicalLoc(Tok.getLocation()))
+ return *SrcMgr.getCharacterData(SrcMgr.getSpellingLoc(Tok.getLocation()))
== 'L';
}
@@ -339,7 +339,7 @@
if (Tok.getLength() != 1)
return false;
SourceManager &SrcMgr = PP.getSourceManager();
- return *SrcMgr.getCharacterData(SrcMgr.getPhysicalLoc(Tok.getLocation()))
+ return *SrcMgr.getCharacterData(SrcMgr.getSpellingLoc(Tok.getLocation()))
== 'L';
}
@@ -403,7 +403,7 @@
} else if (!Tok.needsCleaning()) {
SourceManager &SrcMgr = PP.getSourceManager();
FirstChar =
- *SrcMgr.getCharacterData(SrcMgr.getPhysicalLoc(Tok.getLocation()));
+ *SrcMgr.getCharacterData(SrcMgr.getSpellingLoc(Tok.getLocation()));
} else if (Tok.getLength() < 256) {
const char *TokPtr = Buffer;
PP.getSpelling(Tok, TokPtr);
Modified: cfe/trunk/include/clang/Basic/SourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Fri Jan 16 01:00:02 2009
@@ -47,8 +47,8 @@
// bits 28...9 -> MacroID number.
MacroIDBits = 20,
- // bits 8...0 -> Macro Physical offset
- MacroPhysOffsBits = 9,
+ // bits 8...0 -> Macro spelling offset
+ MacroSpellingOffsBits = 9,
// Useful constants.
@@ -84,23 +84,23 @@
return L;
}
- static bool isValidMacroPhysOffs(int Val) {
+ static bool isValidMacroSpellingOffs(int Val) {
if (Val >= 0)
- return Val < (1 << (MacroPhysOffsBits-1));
- return -Val <= (1 << (MacroPhysOffsBits-1));
+ return Val < (1 << (MacroSpellingOffsBits-1));
+ return -Val <= (1 << (MacroSpellingOffsBits-1));
}
- static SourceLocation getMacroLoc(unsigned MacroID, int PhysOffs){
+ static SourceLocation getMacroLoc(unsigned MacroID, int SpellingOffs) {
assert(MacroID < (1 << MacroIDBits) && "Too many macros!");
- assert(isValidMacroPhysOffs(PhysOffs) && "Physoffs too large!");
+ assert(isValidMacroSpellingOffs(SpellingOffs) &&"spelling offs too large!");
// Mask off sign bits.
- PhysOffs &= (1 << MacroPhysOffsBits)-1;
+ SpellingOffs &= (1 << MacroSpellingOffsBits)-1;
SourceLocation L;
L.ID = (1 << 31) |
- (MacroID << MacroPhysOffsBits) |
- PhysOffs;
+ (MacroID << MacroSpellingOffsBits) |
+ SpellingOffs;
return L;
}
@@ -125,14 +125,14 @@
unsigned getMacroID() const {
assert(isMacroID() && "Is not a macro id!");
- return (ID >> MacroPhysOffsBits) & ((1 << MacroIDBits)-1);
+ return (ID >> MacroSpellingOffsBits) & ((1 << MacroIDBits)-1);
}
- int getMacroPhysOffs() const {
+ int getMacroSpellingOffs() const {
assert(isMacroID() && "Is not a macro id!");
- int Val = ID & ((1 << MacroPhysOffsBits)-1);
+ int Val = ID & ((1 << MacroSpellingOffsBits)-1);
// Sign extend it properly.
- unsigned ShAmt = sizeof(int)*8 - MacroPhysOffsBits;
+ unsigned ShAmt = sizeof(int)*8 - MacroSpellingOffsBits;
return (Val << ShAmt) >> ShAmt;
}
@@ -237,7 +237,7 @@
}
FullSourceLoc getLogicalLoc() const;
- FullSourceLoc getPhysicalLoc() const;
+ FullSourceLoc getSpellingLoc() const;
FullSourceLoc getIncludeLoc() const;
unsigned getLineNumber() const;
@@ -246,8 +246,8 @@
unsigned getLogicalLineNumber() const;
unsigned getLogicalColumnNumber() const;
- unsigned getPhysicalLineNumber() const;
- unsigned getPhysicalColumnNumber() const;
+ unsigned getSpellingLineNumber() const;
+ unsigned getSpellingColumnNumber() const;
const char *getCharacterData() const;
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Fri Jan 16 01:00:02 2009
@@ -121,7 +121,7 @@
/// is a byte offset from the start of this.
///
/// FileID's are used to compute the location of a character in memory as well
- /// as the logical source location, which can be differ from the physical
+ /// as the logical source location, which can be differ from the spelling
/// location. It is different when #line's are active or when macros have
/// been expanded.
///
@@ -183,23 +183,23 @@
/// MacroIDInfo - Macro SourceLocations refer to these records by their ID.
/// Each MacroIDInfo encodes the Instantiation location - where the macro was
- /// instantiated, and the PhysicalLoc - where the actual character data for
+ /// instantiated, and the SpellingLoc - where the actual character data for
/// the token came from. An actual macro SourceLocation stores deltas from
/// these positions.
class MacroIDInfo {
- SourceLocation VirtualLoc, PhysicalLoc;
+ SourceLocation VirtualLoc, SpellingLoc;
public:
SourceLocation getVirtualLoc() const { return VirtualLoc; }
- SourceLocation getPhysicalLoc() const { return PhysicalLoc; }
+ SourceLocation getSpellingLoc() const { return SpellingLoc; }
/// get - Return a MacroID for a macro expansion. VL specifies
- /// the instantiation location (where the macro is expanded), and PL
- /// specifies the physical location (where the characters from the token
+ /// the instantiation location (where the macro is expanded), and SL
+ /// specifies the spelling location (where the characters from the token
/// come from). Both VL and PL refer to normal File SLocs.
- static MacroIDInfo get(SourceLocation VL, SourceLocation PL) {
+ static MacroIDInfo get(SourceLocation VL, SourceLocation SL) {
MacroIDInfo X;
X.VirtualLoc = VL;
- X.PhysicalLoc = PL;
+ X.SpellingLoc = SL;
return X;
}
@@ -228,10 +228,10 @@
/// files and assigns unique FileID's for each unique #include chain.
///
/// The SourceManager can be queried for information about SourceLocation
-/// objects, turning them into either physical or logical locations. Physical
+/// objects, turning them into either spelling or logical locations. Spelling
/// locations represent where the bytes corresponding to a token came from and
/// logical locations represent where the location is in the user's view. In
-/// the case of a macro expansion, for example, the physical location indicates
+/// the case of a macro expansion, for example, the spelling location indicates
/// where the expanded token came from and the logical location specifies where
/// it was expanded. Logical locations are also influenced by #line directives,
/// etc.
@@ -348,19 +348,19 @@
/// getColumnNumber - Return the column # for the specified file position.
/// This is significantly cheaper to compute than the line number. This
/// returns zero if the column number isn't known. This may only be called on
- /// a file sloc, so you must choose a physical or logical location before
+ /// a file sloc, so you must choose a spelling or logical location before
/// calling this method.
unsigned getColumnNumber(SourceLocation Loc) const;
- unsigned getPhysicalColumnNumber(SourceLocation Loc) const {
- return getColumnNumber(getPhysicalLoc(Loc));
+ unsigned getSpellingColumnNumber(SourceLocation Loc) const {
+ return getColumnNumber(getSpellingLoc(Loc));
}
unsigned getLogicalColumnNumber(SourceLocation Loc) const {
return getColumnNumber(getLogicalLoc(Loc));
}
- /// getLineNumber - Given a SourceLocation, return the physical line number
+ /// getLineNumber - Given a SourceLocation, return the spelling line number
/// for the position indicated. This requires building and caching a table of
/// line offsets for the MemoryBuffer, so this is not cheap: use only when
/// about to emit a diagnostic.
@@ -369,8 +369,8 @@
unsigned getLogicalLineNumber(SourceLocation Loc) const {
return getLineNumber(getLogicalLoc(Loc));
}
- unsigned getPhysicalLineNumber(SourceLocation Loc) const {
- return getLineNumber(getPhysicalLoc(Loc));
+ unsigned getSpellingLineNumber(SourceLocation Loc) const {
+ return getLineNumber(getSpellingLoc(Loc));
}
/// getSourceName - This method returns the name of the file or buffer that
@@ -381,33 +381,35 @@
/// Given a SourceLocation object, return the logical location referenced by
/// the ID. This logical location is subject to #line directives, etc.
SourceLocation getLogicalLoc(SourceLocation Loc) const {
- // File locations are both physical and logical.
+ // File locations work.
if (Loc.isFileID()) return Loc;
-
+
return MacroIDs[Loc.getMacroID()].getVirtualLoc();
}
- /// getPhysicalLoc - Given a SourceLocation object, return the physical
- /// location referenced by the ID.
- SourceLocation getPhysicalLoc(SourceLocation Loc) const {
- // File locations are both physical and logical.
+ /// getSpellingLoc - Given a SourceLocation object, return the spelling
+ /// location referenced by the ID. This is the place where the characters
+ /// that make up the lexed token can be found.
+ SourceLocation getSpellingLoc(SourceLocation Loc) const {
+ // File locations work!
if (Loc.isFileID()) return Loc;
- SourceLocation PLoc = MacroIDs[Loc.getMacroID()].getPhysicalLoc();
- return PLoc.getFileLocWithOffset(Loc.getMacroPhysOffs());
+ // Look up the macro token's spelling location.
+ SourceLocation PLoc = MacroIDs[Loc.getMacroID()].getSpellingLoc();
+ return PLoc.getFileLocWithOffset(Loc.getMacroSpellingOffs());
}
- /// getContentCacheForLoc - Return the ContentCache for the physloc of the
- /// specified SourceLocation, if one exists.
+ /// getContentCacheForLoc - Return the ContentCache for the spelling loc of
+ /// the specified SourceLocation, if one exists.
const SrcMgr::ContentCache* getContentCacheForLoc(SourceLocation Loc) const {
- Loc = getPhysicalLoc(Loc);
+ Loc = getSpellingLoc(Loc);
unsigned FileID = Loc.getFileID();
assert(FileID-1 < FileIDs.size() && "Invalid FileID!");
return FileIDs[FileID-1].getContentCache();
}
- /// getFileEntryForLoc - Return the FileEntry record for the physloc of the
- /// specified SourceLocation, if one exists.
+ /// getFileEntryForLoc - Return the FileEntry record for the spelling loc of
+ /// the specified SourceLocation, if one exists.
const FileEntry* getFileEntryForLoc(SourceLocation Loc) const {
return getContentCacheForLoc(Loc)->Entry;
}
@@ -422,8 +424,8 @@
/// into multiple chunks. This method returns the unique FileID without
/// chunk information for a given SourceLocation. Use this method when
/// you want to compare FileIDs across SourceLocations.
- unsigned getCanonicalFileID(SourceLocation PhysLoc) const {
- return getDecomposedFileLoc(PhysLoc).first;
+ unsigned getCanonicalFileID(SourceLocation SpellingLoc) const {
+ return getDecomposedFileLoc(SpellingLoc).first;
}
/// getDecomposedFileLoc - Decompose the specified file location into a raw
@@ -447,11 +449,11 @@
}
/// getFullFilePos - This (efficient) method returns the offset from the start
- /// of the file that the specified physical SourceLocation represents. This
- /// returns the location of the physical character data, not the logical file
+ /// of the file that the specified spelling SourceLocation represents. This
+ /// returns the location of the actual character data, not the logical file
/// position.
- unsigned getFullFilePos(SourceLocation PhysLoc) const {
- return getDecomposedFileLoc(PhysLoc).second;
+ unsigned getFullFilePos(SourceLocation SpellingLoc) const {
+ return getDecomposedFileLoc(SpellingLoc).second;
}
/// isFromSameFile - Returns true if both SourceLocations correspond to
@@ -471,7 +473,7 @@
return getFileCharacteristic(Loc) != SrcMgr::C_User;
}
SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const {
- return getFIDInfo(getPhysicalLoc(Loc).getFileID())->getFileCharacteristic();
+ return getFIDInfo(getSpellingLoc(Loc).getFileID())->getFileCharacteristic();
}
SrcMgr::CharacteristicKind getFileCharacteristic(unsigned FileID) const {
return getFIDInfo(FileID)->getFileCharacteristic();
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Jan 16 01:00:02 2009
@@ -455,7 +455,7 @@
/// location in the appropriate MemoryBuffer.
char getPhysicalCharacterAt(SourceLocation SL) const {
if (PTH) {
- SL = SourceMgr.getPhysicalLoc(SL);
+ SL = SourceMgr.getSpellingLoc(SL);
unsigned fid = SourceMgr.getCanonicalFileID(SL);
unsigned fpos = SourceMgr.getFullFilePos(SL);
const char* data;
Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Fri Jan 16 01:00:02 2009
@@ -152,21 +152,22 @@
//===----------------------------------------------------------------------===//
void StmtDumper::DumpLocation(SourceLocation Loc) {
- SourceLocation PhysLoc = SM->getPhysicalLoc(Loc);
+ SourceLocation SpellingLoc = SM->getSpellingLoc(Loc);
// The general format we print out is filename:line:col, but we drop pieces
// that haven't changed since the last loc printed.
- const char *Filename = SM->getSourceName(PhysLoc);
- unsigned LineNo = SM->getLineNumber(PhysLoc);
+ const char *Filename = SM->getSourceName(SpellingLoc);
+ unsigned LineNo = SM->getLineNumber(SpellingLoc);
+ unsigned ColNo = SM->getColumnNumber(SpellingLoc);
if (strcmp(Filename, LastLocFilename) != 0) {
- fprintf(stderr, "%s:%u:%u", Filename, LineNo, SM->getColumnNumber(PhysLoc));
+ fprintf(stderr, "%s:%u:%u", Filename, LineNo, ColNo);
LastLocFilename = Filename;
LastLocLine = LineNo;
} else if (LineNo != LastLocLine) {
- fprintf(stderr, "line:%u:%u", LineNo, SM->getColumnNumber(PhysLoc));
+ fprintf(stderr, "line:%u:%u", LineNo, ColNo);
LastLocLine = LineNo;
} else {
- fprintf(stderr, "col:%u", SM->getColumnNumber(PhysLoc));
+ fprintf(stderr, "col:%u", ColNo);
}
}
Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Fri Jan 16 01:00:02 2009
@@ -358,13 +358,13 @@
for (AnalysisDataTy::decl_iterator I = AD.begin_decl(),
E = AD.end_decl(); I!=E; ++I)
if (V.getDeclBit(I->second)) {
- SourceLocation PhysLoc = SM.getPhysicalLoc(I->first->getLocation());
+ SourceLocation SpellingLoc = SM.getSpellingLoc(I->first->getLocation());
fprintf(stderr, " %s <%s:%u:%u>\n",
I->first->getIdentifier()->getName(),
- SM.getSourceName(PhysLoc),
- SM.getLineNumber(PhysLoc),
- SM.getColumnNumber(PhysLoc));
+ SM.getSourceName(SpellingLoc),
+ SM.getLineNumber(SpellingLoc),
+ SM.getColumnNumber(SpellingLoc));
}
}
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Fri Jan 16 01:00:02 2009
@@ -244,7 +244,7 @@
Info.getID() < diag::NUM_BUILTIN_DIAGNOSTICS &&
getBuiltinDiagClass(Info.getID()) != ERROR &&
Info.getLocation().isValid() &&
- Info.getLocation().getPhysicalLoc().isInSystemHeader())
+ Info.getLocation().getSpellingLoc().isInSystemHeader())
return;
if (DiagLevel >= Diagnostic::Error) {
Modified: cfe/trunk/lib/Basic/SourceLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceLocation.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceLocation.cpp (original)
+++ cfe/trunk/lib/Basic/SourceLocation.cpp Fri Jan 16 01:00:02 2009
@@ -42,9 +42,9 @@
return FullSourceLoc(SrcMgr->getLogicalLoc(Loc), *SrcMgr);
}
-FullSourceLoc FullSourceLoc::getPhysicalLoc() const {
- assert (isValid());
- return FullSourceLoc(SrcMgr->getPhysicalLoc(Loc), *SrcMgr);
+FullSourceLoc FullSourceLoc::getSpellingLoc() const {
+ assert(isValid());
+ return FullSourceLoc(SrcMgr->getSpellingLoc(Loc), *SrcMgr);
}
FullSourceLoc FullSourceLoc::getIncludeLoc() const {
@@ -73,14 +73,14 @@
return SrcMgr->getLogicalColumnNumber(Loc);
}
-unsigned FullSourceLoc::getPhysicalLineNumber() const {
+unsigned FullSourceLoc::getSpellingLineNumber() const {
assert (isValid());
- return SrcMgr->getPhysicalLineNumber(Loc);
+ return SrcMgr->getSpellingLineNumber(Loc);
}
-unsigned FullSourceLoc::getPhysicalColumnNumber() const {
+unsigned FullSourceLoc::getSpellingColumnNumber() const {
assert (isValid());
- return SrcMgr->getPhysicalColumnNumber(Loc);
+ return SrcMgr->getSpellingColumnNumber(Loc);
}
const char* FullSourceLoc::getSourceName() const {
@@ -120,13 +120,13 @@
}
if (isFileID()) {
- // The logical and physical pos is identical for file locs.
+ // The logical and spelling pos is identical for file locs.
fprintf(stderr, "File Loc from '%s': %d: %d\n",
getSourceName(), getLogicalLineNumber(),
getLogicalColumnNumber());
} else {
- fprintf(stderr, "Macro Loc (\n Physical: ");
- getPhysicalLoc().dump();
+ fprintf(stderr, "Macro Loc (\n Spelling: ");
+ getSpellingLoc().dump();
fprintf(stderr, " Logical: ");
getLogicalLoc().dump();
fprintf(stderr, ")\n");
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Fri Jan 16 01:00:02 2009
@@ -146,14 +146,14 @@
}
/// getInstantiationLoc - Return a new SourceLocation that encodes the fact
-/// that a token from physloc PhysLoc should actually be referenced from
+/// that a token from SpellingLoc should actually be referenced from
/// InstantiationLoc.
-SourceLocation SourceManager::getInstantiationLoc(SourceLocation PhysLoc,
+SourceLocation SourceManager::getInstantiationLoc(SourceLocation SpellingLoc,
SourceLocation InstantLoc) {
// The specified source location may be a mapped location, due to a macro
// instantiation or #line directive. Strip off this information to find out
// where the characters are actually located.
- PhysLoc = getPhysicalLoc(PhysLoc);
+ SpellingLoc = getSpellingLoc(SpellingLoc);
// Resolve InstantLoc down to a real logical location.
InstantLoc = getLogicalLoc(InstantLoc);
@@ -164,21 +164,21 @@
for (int i = MacroIDs.size()-1, e = MacroIDs.size()-6; i >= 0 && i != e; --i){
MacroIDInfo &LastOne = MacroIDs[i];
- // The instanitation point and source physloc have to exactly match to reuse
- // (for now). We could allow "nearby" instantiations in the future.
+ // The instanitation point and source SpellingLoc have to exactly match to
+ // reuse (for now). We could allow "nearby" instantiations in the future.
if (LastOne.getVirtualLoc() != InstantLoc ||
- LastOne.getPhysicalLoc().getFileID() != PhysLoc.getFileID())
+ LastOne.getSpellingLoc().getFileID() != SpellingLoc.getFileID())
continue;
- // Check to see if the physloc of the token came from near enough to reuse.
- int PhysDelta = PhysLoc.getRawFilePos() -
- LastOne.getPhysicalLoc().getRawFilePos();
- if (SourceLocation::isValidMacroPhysOffs(PhysDelta))
- return SourceLocation::getMacroLoc(i, PhysDelta);
+ // Check to see if the spellloc of the token came from near enough to reuse.
+ int SpellDelta = SpellingLoc.getRawFilePos() -
+ LastOne.getSpellingLoc().getRawFilePos();
+ if (SourceLocation::isValidMacroSpellingOffs(SpellDelta))
+ return SourceLocation::getMacroLoc(i, SpellDelta);
}
- MacroIDs.push_back(MacroIDInfo::get(InstantLoc, PhysLoc));
+ MacroIDs.push_back(MacroIDInfo::get(InstantLoc, SpellingLoc));
return SourceLocation::getMacroLoc(MacroIDs.size()-1, 0);
}
@@ -196,7 +196,7 @@
const char *SourceManager::getCharacterData(SourceLocation SL) const {
// Note that this is a hot function in the getSpelling() path, which is
// heavily used by -E mode.
- SL = getPhysicalLoc(SL);
+ SL = getSpellingLoc(SL);
// Note that calling 'getBuffer()' may lazily page in a source file.
return getContentCache(SL.getFileID())->getBuffer()->getBufferStart() +
@@ -279,7 +279,7 @@
std::copy(LineOffsets.begin(), LineOffsets.end(), FI->SourceLineCache);
}
-/// getLineNumber - Given a SourceLocation, return the physical line number
+/// getLineNumber - Given a SourceLocation, return the spelling line number
/// for the position indicated. This requires building and caching a table of
/// line offsets for the MemoryBuffer, so this is not cheap: use only when
/// about to emit a diagnostic.
@@ -481,13 +481,13 @@
void MacroIDInfo::Emit(llvm::Serializer& S) const {
S.Emit(VirtualLoc);
- S.Emit(PhysicalLoc);
+ S.Emit(SpellingLoc);
}
MacroIDInfo MacroIDInfo::ReadVal(llvm::Deserializer& D) {
MacroIDInfo I;
I.VirtualLoc = SourceLocation::ReadVal(D);
- I.PhysicalLoc = SourceLocation::ReadVal(D);
+ I.SpellingLoc = SourceLocation::ReadVal(D);
return I;
}
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Jan 16 01:00:02 2009
@@ -68,7 +68,7 @@
Features(pp.getLangOptions()) {
SourceManager &SourceMgr = PP->getSourceManager();
- unsigned InputFileID = SourceMgr.getPhysicalLoc(FileLoc).getFileID();
+ unsigned InputFileID = SourceMgr.getSpellingLoc(FileLoc).getFileID();
const llvm::MemoryBuffer *InputFile = SourceMgr.getBuffer(InputFileID);
Is_PragmaLexer = false;
@@ -281,15 +281,15 @@
unsigned CharNo) {
// Otherwise, we're lexing "mapped tokens". This is used for things like
// _Pragma handling. Combine the instantiation location of FileLoc with the
- // physical location.
+ // spelling location.
SourceManager &SourceMgr = PP.getSourceManager();
// Create a new SLoc which is expanded from logical(FileLoc) but whose
- // characters come from phys(FileLoc)+Offset.
+ // characters come from spelling(FileLoc)+Offset.
SourceLocation VirtLoc = SourceMgr.getLogicalLoc(FileLoc);
- SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(FileLoc);
- PhysLoc = SourceLocation::getFileLoc(PhysLoc.getFileID(), CharNo);
- return SourceMgr.getInstantiationLoc(PhysLoc, VirtLoc);
+ SourceLocation SpellingLoc = SourceMgr.getSpellingLoc(FileLoc);
+ SpellingLoc = SourceLocation::getFileLoc(SpellingLoc.getFileID(), CharNo);
+ return SourceMgr.getInstantiationLoc(SpellingLoc, VirtLoc);
}
/// getSourceLocation - Return a source location identifier for the specified
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Fri Jan 16 01:00:02 2009
@@ -422,7 +422,7 @@
unsigned PTHLexer::getSpelling(SourceLocation sloc, const char *&Buffer) {
SourceManager& SM = PP->getSourceManager();
- sloc = SM.getPhysicalLoc(sloc);
+ sloc = SM.getSpellingLoc(sloc);
unsigned fid = SM.getCanonicalFileID(sloc);
unsigned fpos = SM.getFullFilePos(sloc);
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Jan 16 01:00:02 2009
@@ -145,10 +145,10 @@
<< SourceMgr.getLineNumber(LogLoc) << ':'
<< SourceMgr.getColumnNumber(LogLoc);
- SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(Loc);
- if (PhysLoc != LogLoc) {
- llvm::cerr << " <PhysLoc=";
- DumpLocation(PhysLoc);
+ SourceLocation SpellingLoc = SourceMgr.getSpellingLoc(Loc);
+ if (SpellingLoc != LogLoc) {
+ llvm::cerr << " <SpellingLoc=";
+ DumpLocation(SpellingLoc);
llvm::cerr << ">";
}
}
@@ -199,12 +199,12 @@
const char* TokStart;
if (PTH) {
- SourceLocation sloc = SourceMgr.getPhysicalLoc(Tok.getLocation());
- unsigned fid = SourceMgr.getCanonicalFileID(sloc);
- unsigned fpos = SourceMgr.getFullFilePos(sloc);
- if (unsigned len = PTH->getSpelling(fid, fpos, TokStart)) {
+ SourceLocation SLoc = SourceMgr.getSpellingLoc(Tok.getLocation());
+ unsigned fid = SourceMgr.getCanonicalFileID(SLoc);
+ unsigned fpos = SourceMgr.getFullFilePos(SLoc);
+ if (unsigned Len = PTH->getSpelling(fid, fpos, TokStart)) {
assert(!Tok.needsCleaning());
- return std::string(TokStart, TokStart+len);
+ return std::string(TokStart, TokStart+Len);
}
}
@@ -251,7 +251,7 @@
// If using PTH, try and get the spelling from the PTH file.
if (PTH) {
- unsigned len;
+ unsigned Len;
if (CurPTHLexer) {
// We perform the const_cast<> here because we will only have a PTHLexer
@@ -260,22 +260,22 @@
// getting token spellings in the order of tokens, and thus can update
// its internal state so that it can quickly fetch spellings from the PTH
// file.
- len =
+ Len =
const_cast<PTHLexer*>(CurPTHLexer.get())->getSpelling(Tok.getLocation(),
Buffer);
}
else {
- SourceLocation sloc = SourceMgr.getPhysicalLoc(Tok.getLocation());
+ SourceLocation sloc = SourceMgr.getSpellingLoc(Tok.getLocation());
unsigned fid = SourceMgr.getCanonicalFileID(sloc);
unsigned fpos = SourceMgr.getFullFilePos(sloc);
- len = PTH->getSpelling(fid, fpos, Buffer);
+ Len = PTH->getSpelling(fid, fpos, Buffer);
}
// Did we find a spelling? If so return its length. Otherwise fall
// back to the default behavior for getting the spelling by looking at
// at the source code.
- if (len)
- return len;
+ if (Len)
+ return Len;
}
// Otherwise, compute the start of the token in the input lexer buffer.
Modified: cfe/trunk/lib/Lex/PreprocessorLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessorLexer.cpp?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessorLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessorLexer.cpp Fri Jan 16 01:00:02 2009
@@ -18,7 +18,7 @@
using namespace clang;
PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L)
- : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()),
+ : PP(pp), FileID(pp->getSourceManager().getSpellingLoc(L).getFileID()),
ParsingPreprocessorDirective(false),
ParsingFilename(false),
LexingRawMode(false) {}
Modified: cfe/trunk/test/Preprocessor/dumptokens_phyloc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/dumptokens_phyloc.c?rev=62309&r1=62308&r2=62309&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/dumptokens_phyloc.c (original)
+++ cfe/trunk/test/Preprocessor/dumptokens_phyloc.c Fri Jan 16 01:00:02 2009
@@ -1,4 +1,4 @@
-// RUN: clang -dump-tokens %s 2>&1 | grep "PhysLoc=.*dumptokens_phyloc.c:3:20"
+// RUN: clang -dump-tokens %s 2>&1 | grep "SpellingLoc=.*dumptokens_phyloc.c:3:20"
#define TESTPHYLOC 10
More information about the cfe-commits
mailing list