[cfe-commits] r59690 - in /cfe/trunk: include/clang/Lex/PTHLexer.h include/clang/Lex/PreprocessorLexer.h lib/Lex/PTHLexer.cpp lib/Lex/PreprocessorLexer.cpp
Ted Kremenek
kremenek at apple.com
Wed Nov 19 17:29:45 PST 2008
Author: kremenek
Date: Wed Nov 19 19:29:45 2008
New Revision: 59690
URL: http://llvm.org/viewvc/llvm-project?rev=59690&view=rev
Log:
- Default initialize ParsingPreprocessorDirective, ParsingFilename, and
LexingRawMode in the ctor of PreprocessorLexer.
- PTHLexer: Use "LastToken" instead of "NumToken"
Modified:
cfe/trunk/include/clang/Lex/PTHLexer.h
cfe/trunk/include/clang/Lex/PreprocessorLexer.h
cfe/trunk/lib/Lex/PTHLexer.cpp
cfe/trunk/lib/Lex/PreprocessorLexer.cpp
Modified: cfe/trunk/include/clang/Lex/PTHLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHLexer.h?rev=59690&r1=59689&r2=59690&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PTHLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PTHLexer.h Wed Nov 19 19:29:45 2008
@@ -11,29 +11,24 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_PTHLexer_H
-#define LLVM_CLANG_PTHLexer_H
+#ifndef LLVM_CLANG_PTHLEXER_H
+#define LLVM_CLANG_PTHLEXER_H
#include "clang/Lex/PreprocessorLexer.h"
namespace clang {
class PTHLexer : public PreprocessorLexer {
- /// FileLoc - Location for the start of the file.
- ///
- SourceLocation FileLoc;
-
/// Tokens - This is the pointer to an array of tokens that the macro is
/// defined to, with arguments expanded for function-like macros. If this is
/// a token stream, these are the tokens we are returning.
const Token *Tokens;
- /// NumTokens - This is the length of the Tokens array.
- ///
- unsigned NumTokens;
+ /// LastTokenIdx - The index of the last token in Tokens. This token
+ /// will be an eof token.
+ unsigned LastToken;
- /// CurToken - This is the next token that Lex will return.
- ///
+ /// CurToken - This is the index of the next token that Lex will return.
unsigned CurToken;
PTHLexer(const PTHLexer&); // DO NOT IMPLEMENT
@@ -51,12 +46,6 @@
void setEOF(Token &Tok);
- /// getFileLoc - Return the File Location for the file we are lexing out of.
- /// The physical location encodes the location where the characters come from,
- /// the virtual location encodes where we should *claim* the characters came
- /// from. Currently this is only used by _Pragma handling.
- SourceLocation getFileLoc() const { return FileLoc; }
-
/// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
/// uninterpreted string. This switches the lexer out of directive mode.
void DiscardToEndOfLine();
Modified: cfe/trunk/include/clang/Lex/PreprocessorLexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessorLexer.h?rev=59690&r1=59689&r2=59690&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessorLexer.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessorLexer.h Wed Nov 19 19:29:45 2008
@@ -68,7 +68,12 @@
friend class Preprocessor;
PreprocessorLexer(Preprocessor* pp, SourceLocation L);
- PreprocessorLexer() : PP(0), FileID(0) {}
+
+ PreprocessorLexer()
+ : PP(0), FileID(0),
+ ParsingPreprocessorDirective(false),
+ ParsingFilename(false),
+ LexingRawMode(false) {}
virtual ~PreprocessorLexer();
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=59690&r1=59689&r2=59690&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Wed Nov 19 19:29:45 2008
@@ -17,21 +17,19 @@
using namespace clang;
PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc,
- const Token *TokArray, unsigned NumToks)
- : PreprocessorLexer(&pp, fileloc), FileLoc(fileloc),
- Tokens(TokArray), NumTokens(NumToks), CurToken(0) {
+ const Token *TokArray, unsigned NumTokens)
+ : PreprocessorLexer(&pp, fileloc),
+ Tokens(TokArray),
+ LastToken(NumTokens - 1),
+ CurToken(0) {
- assert (Tokens[NumTokens-1].is(tok::eof));
- --NumTokens;
-
- LexingRawMode = false;
- ParsingPreprocessorDirective = false;
- ParsingFilename = false;
+ assert (NumTokens >= 1);
+ assert (Tokens[LastToken].is(tok::eof));
}
void PTHLexer::Lex(Token& Tok) {
- if (CurToken == NumTokens) {
+ if (CurToken == LastToken) {
// If we hit the end of the file while parsing a preprocessor directive,
// end the preprocessor directive first. The next token returned will
// then be the end of file.
@@ -73,8 +71,7 @@
}
void PTHLexer::setEOF(Token& Tok) {
- Tok = Tokens[NumTokens]; // NumTokens is already adjusted, so this isn't
- // an overflow.
+ Tok = Tokens[LastToken];
}
void PTHLexer::DiscardToEndOfLine() {
@@ -82,17 +79,17 @@
"Must be in a preprocessing directive!");
// Already at end-of-file?
- if (CurToken == NumTokens)
+ if (CurToken == LastToken)
return;
// Find the first token that is not the start of the *current* line.
- for ( ++CurToken; CurToken != NumTokens ; ++CurToken )
+ for ( ++CurToken; CurToken != LastToken ; ++CurToken )
if (Tokens[CurToken].isAtStartOfLine())
return;
}
unsigned PTHLexer::isNextPPTokenLParen() {
- if (CurToken == NumTokens)
+ if (CurToken == LastToken)
return 2;
return Tokens[CurToken].is(tok::l_paren);
Modified: cfe/trunk/lib/Lex/PreprocessorLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessorLexer.cpp?rev=59690&r1=59689&r2=59690&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessorLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessorLexer.cpp Wed Nov 19 19:29:45 2008
@@ -19,7 +19,10 @@
using namespace clang;
PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L)
- : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()) {}
+ : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()),
+ ParsingPreprocessorDirective(false),
+ ParsingFilename(false),
+ LexingRawMode(false) {}
PreprocessorLexer::~PreprocessorLexer() {}
More information about the cfe-commits
mailing list