aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Lex
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Lex')
-rw-r--r--include/clang/Lex/DirectoryLookup.h40
-rw-r--r--include/clang/Lex/HeaderMap.h14
-rw-r--r--include/clang/Lex/HeaderSearch.h50
-rw-r--r--include/clang/Lex/LexDiagnostic.h2
-rw-r--r--include/clang/Lex/Lexer.h100
-rw-r--r--include/clang/Lex/LiteralSupport.h46
-rw-r--r--include/clang/Lex/MacroInfo.h54
-rw-r--r--include/clang/Lex/MultipleIncludeOpt.h22
-rw-r--r--include/clang/Lex/PPCallbacks.h28
-rw-r--r--include/clang/Lex/PTHLexer.h32
-rw-r--r--include/clang/Lex/PTHManager.h44
-rw-r--r--include/clang/Lex/Pragma.h14
-rw-r--r--include/clang/Lex/Preprocessor.h201
-rw-r--r--include/clang/Lex/PreprocessorLexer.h58
-rw-r--r--include/clang/Lex/ScratchBuffer.h4
-rw-r--r--include/clang/Lex/Token.h70
-rw-r--r--include/clang/Lex/TokenConcatenation.h16
-rw-r--r--include/clang/Lex/TokenLexer.h40
18 files changed, 424 insertions, 411 deletions
diff --git a/include/clang/Lex/DirectoryLookup.h b/include/clang/Lex/DirectoryLookup.h
index 618de39233db..c94a99022415 100644
--- a/include/clang/Lex/DirectoryLookup.h
+++ b/include/clang/Lex/DirectoryLookup.h
@@ -38,20 +38,20 @@ private:
/// Dir - This is the actual directory that we're referring to for a normal
/// directory or a framework.
const DirectoryEntry *Dir;
-
+
/// Map - This is the HeaderMap if this is a headermap lookup.
///
const HeaderMap *Map;
} u;
-
+
/// DirCharacteristic - The type of directory this is: this is an instance of
/// SrcMgr::CharacteristicKind.
unsigned DirCharacteristic : 2;
-
+
/// UserSupplied - True if this is a user-supplied directory.
///
bool UserSupplied : 1;
-
+
/// LookupType - This indicates whether this DirectoryLookup object is a
/// normal directory, a framework, or a headermap.
unsigned LookupType : 2;
@@ -62,25 +62,25 @@ public:
bool isUser, bool isFramework)
: DirCharacteristic(DT), UserSupplied(isUser),
LookupType(isFramework ? LT_Framework : LT_NormalDir) {
- u.Dir = dir;
+ u.Dir = dir;
}
-
+
/// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
/// 'map'.
DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
bool isUser)
: DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap) {
- u.Map = map;
+ u.Map = map;
}
-
+
/// getLookupType - Return the kind of directory lookup that this is: either a
/// normal directory, a framework path, or a HeaderMap.
LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
-
+
/// getName - Return the directory or filename corresponding to this lookup
/// object.
const char *getName() const;
-
+
/// getDir - Return the directory that this entry refers to.
///
const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; }
@@ -90,42 +90,42 @@ public:
const DirectoryEntry *getFrameworkDir() const {
return isFramework() ? u.Dir : 0;
}
-
+
/// getHeaderMap - Return the directory that this entry refers to.
///
const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; }
/// isNormalDir - Return true if this is a normal directory, not a header map.
bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
-
+
/// isFramework - True if this is a framework directory.
///
bool isFramework() const { return getLookupType() == LT_Framework; }
-
+
/// isHeaderMap - Return true if this is a header map, not a normal directory.
bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
-
+
/// DirCharacteristic - The type of directory this is, one of the DirType enum
/// values.
SrcMgr::CharacteristicKind getDirCharacteristic() const {
return (SrcMgr::CharacteristicKind)DirCharacteristic;
}
-
+
/// isUserSupplied - True if this is a user-supplied directory.
///
bool isUserSupplied() const { return UserSupplied; }
-
-
+
+
/// LookupFile - Lookup the specified file in this search path, returning it
/// if it exists or returning null if not.
const FileEntry *LookupFile(const char *FilenameStart,
const char *FilenameEnd, HeaderSearch &HS) const;
-
+
private:
const FileEntry *DoFrameworkLookup(const char *FilenameStart,
- const char *FilenameEnd,
+ const char *FilenameEnd,
HeaderSearch &HS) const;
-
+
};
} // end namespace clang
diff --git a/include/clang/Lex/HeaderMap.h b/include/clang/Lex/HeaderMap.h
index d8033093bd8e..6bb7c25947d7 100644
--- a/include/clang/Lex/HeaderMap.h
+++ b/include/clang/Lex/HeaderMap.h
@@ -30,31 +30,31 @@ namespace clang {
class HeaderMap {
HeaderMap(const HeaderMap&); // DO NOT IMPLEMENT
void operator=(const HeaderMap&); // DO NOT IMPLEMENT
-
+
const llvm::MemoryBuffer *FileBuffer;
bool NeedsBSwap;
-
+
HeaderMap(const llvm::MemoryBuffer *File, bool BSwap)
: FileBuffer(File), NeedsBSwap(BSwap) {
}
public:
~HeaderMap();
-
+
/// HeaderMap::Create - This attempts to load the specified file as a header
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
static const HeaderMap *Create(const FileEntry *FE);
-
+
/// LookupFile - Check to see if the specified relative filename is located in
/// this HeaderMap. If so, open it and return its FileEntry.
const FileEntry *LookupFile(const char *FilenameStart,const char *FilenameEnd,
FileManager &FM) const;
-
+
/// getFileName - Return the filename of the headermap.
const char *getFileName() const;
-
+
/// dump - Print the contents of this headermap to stderr.
void dump() const;
-
+
private:
unsigned getEndianAdjustedWord(unsigned X) const;
const HMapHeader &getHeader() const;
diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h
index f21aab1b4015..7517440983b1 100644
--- a/include/clang/Lex/HeaderSearch.h
+++ b/include/clang/Lex/HeaderSearch.h
@@ -30,17 +30,17 @@ class IdentifierInfo;
struct HeaderFileInfo {
/// isImport - True if this is a #import'd or #pragma once file.
bool isImport : 1;
-
+
/// DirInfo - Keep track of whether this is a system header, and if so,
/// whether it is C++ clean or not. This can be set by the include paths or
/// by #pragma gcc system_header. This is an instance of
/// SrcMgr::CharacteristicKind.
unsigned DirInfo : 2;
-
+
/// NumIncludes - This is the number of times the file has been included
/// already.
unsigned short NumIncludes;
-
+
/// ControllingMacro - If this file has a #ifndef XXX (or equivalent) guard
/// that protects the entire contents of the file, this is the identifier
/// for the macro that controls whether or not it has any effect.
@@ -51,14 +51,14 @@ struct HeaderFileInfo {
/// external storage.
const IdentifierInfo *ControllingMacro;
- /// \brief The ID number of the controlling macro.
+ /// \brief The ID number of the controlling macro.
///
/// This ID number will be non-zero when there is a controlling
/// macro whose IdentifierInfo may not yet have been loaded from
/// external storage.
unsigned ControllingMacroID;
- HeaderFileInfo()
+ HeaderFileInfo()
: isImport(false), DirInfo(SrcMgr::C_User),
NumIncludes(0), ControllingMacro(0), ControllingMacroID(0) {}
@@ -71,7 +71,7 @@ struct HeaderFileInfo {
/// file referenced by a #include or #include_next, (sub-)framework lookup, etc.
class HeaderSearch {
FileManager &FileMgr;
-
+
/// #include search path information. Requests for #include "x" search the
/// directory of the #including file first, then each directory in SearchDirs
/// consequtively. Requests for <x> search the current dir first, then each
@@ -81,7 +81,7 @@ class HeaderSearch {
std::vector<DirectoryLookup> SearchDirs;
unsigned SystemDirIdx;
bool NoCurDirSearch;
-
+
/// FileInfo - This contains all of the preprocessor-specific data about files
/// that are included. The vector is indexed by the FileEntry's UID.
///
@@ -94,13 +94,13 @@ class HeaderSearch {
/// ignored. The second value is the entry in SearchDirs that satisfied the
/// query.
llvm::StringMap<std::pair<unsigned, unsigned> > LookupFileCache;
-
-
+
+
/// FrameworkMap - This is a collection mapping a framework or subframework
/// name like "Carbon" to the Carbon.framework directory.
llvm::StringMap<const DirectoryEntry *> FrameworkMap;
- /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing
+ /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing
/// headermaps. This vector owns the headermap.
std::vector<std::pair<const FileEntry*, const HeaderMap*> > HeaderMaps;
@@ -114,7 +114,7 @@ class HeaderSearch {
unsigned NumFrameworkLookups, NumSubFrameworkLookups;
// HeaderSearch doesn't support default or copy construction.
- explicit HeaderSearch();
+ explicit HeaderSearch();
explicit HeaderSearch(const HeaderSearch&);
void operator=(const HeaderSearch&);
public:
@@ -132,12 +132,12 @@ public:
NoCurDirSearch = noCurDirSearch;
//LookupFileCache.clear();
}
-
+
/// ClearFileInfo - Forget everything we know about headers so far.
void ClearFileInfo() {
FileInfo.clear();
}
-
+
void SetExternalLookup(ExternalIdentifierLookup *EIL) {
ExternalLookup = EIL;
}
@@ -155,7 +155,7 @@ public:
const DirectoryLookup *FromDir,
const DirectoryLookup *&CurDir,
const FileEntry *CurFileEnt);
-
+
/// LookupSubframeworkHeader - Look up a subframework for the specified
/// #include file. For example, if #include'ing <HIToolbox/HIToolbox.h> from
/// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox
@@ -164,7 +164,7 @@ public:
const FileEntry *LookupSubframeworkHeader(const char *FilenameStart,
const char *FilenameEnd,
const FileEntry *RelativeFileEnt);
-
+
/// LookupFrameworkCache - Look up the specified framework name in our
/// framework cache, returning the DirectoryEntry it is in if we know,
/// otherwise, return null.
@@ -172,19 +172,19 @@ public:
const char *FWNameEnd) {
return FrameworkMap.GetOrCreateValue(FWNameStart, FWNameEnd).getValue();
}
-
+
/// ShouldEnterIncludeFile - Mark the specified file as a target of of a
/// #include, #include_next, or #import directive. Return false if #including
/// the file will have no effect or true if we should include it.
bool ShouldEnterIncludeFile(const FileEntry *File, bool isImport);
-
-
+
+
/// getFileDirFlavor - Return whether the specified file is a normal header,
/// a system header, or a C++ friendly system header.
SrcMgr::CharacteristicKind getFileDirFlavor(const FileEntry *File) {
return (SrcMgr::CharacteristicKind)getFileInfo(File).DirInfo;
}
-
+
/// MarkFileIncludeOnce - Mark the specified file as a "once only" file, e.g.
/// due to #pragma once.
void MarkFileIncludeOnce(const FileEntry *File) {
@@ -196,13 +196,13 @@ public:
void MarkFileSystemHeader(const FileEntry *File) {
getFileInfo(File).DirInfo = SrcMgr::C_System;
}
-
+
/// IncrementIncludeCount - Increment the count for the number of times the
/// specified FileEntry has been entered.
void IncrementIncludeCount(const FileEntry *File) {
++getFileInfo(File).NumIncludes;
}
-
+
/// SetFileControllingMacro - Mark the specified file as having a controlling
/// macro. This is used by the multiple-include optimization to eliminate
/// no-op #includes.
@@ -210,11 +210,11 @@ public:
const IdentifierInfo *ControllingMacro) {
getFileInfo(File).ControllingMacro = ControllingMacro;
}
-
+
/// CreateHeaderMap - This method returns a HeaderMap for the specified
/// FileEntry, uniquing them through the the 'HeaderMaps' datastructure.
const HeaderMap *CreateHeaderMap(const FileEntry *FE);
-
+
void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
typedef std::vector<HeaderFileInfo>::iterator header_file_iterator;
@@ -223,10 +223,10 @@ public:
// Used by PCHReader.
void setHeaderFileInfoForUID(HeaderFileInfo HFI, unsigned UID);
-
+
void PrintStats();
private:
-
+
/// getFileInfo - Return the HeaderFileInfo structure for the specified
/// FileEntry.
HeaderFileInfo &getFileInfo(const FileEntry *FE);
diff --git a/include/clang/Lex/LexDiagnostic.h b/include/clang/Lex/LexDiagnostic.h
index 03d9b7b3bbb8..a470aa0924fb 100644
--- a/include/clang/Lex/LexDiagnostic.h
+++ b/include/clang/Lex/LexDiagnostic.h
@@ -13,7 +13,7 @@
#include "clang/Basic/Diagnostic.h"
namespace clang {
- namespace diag {
+ namespace diag {
enum {
#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,SFINAE) ENUM,
#define LEXSTART
diff --git a/include/clang/Lex/Lexer.h b/include/clang/Lex/Lexer.h
index 3a73147152af..c2db4d357c51 100644
--- a/include/clang/Lex/Lexer.h
+++ b/include/clang/Lex/Lexer.h
@@ -39,11 +39,12 @@ class Lexer : public PreprocessorLexer {
SourceLocation FileLoc; // Location for start of file.
LangOptions Features; // Features enabled by this language (cache).
bool Is_PragmaLexer; // True if lexer for _Pragma handling.
+ bool IsEofCodeCompletion; // True if EOF is treated as a code-completion.
//===--------------------------------------------------------------------===//
// Context-specific lexing flags set by the preprocessor.
//
-
+
/// ExtendedTokenMode - The lexer can optionally keep comments and whitespace
/// and return them as tokens. This is used for -C and -CC modes, and
/// whitespace preservation can be useful for some clients that want to lex
@@ -52,7 +53,7 @@ class Lexer : public PreprocessorLexer {
/// When this is set to 2 it returns comments and whitespace. When set to 1
/// it returns comments, when it is set to 0 it returns normal tokens only.
unsigned char ExtendedTokenMode;
-
+
//===--------------------------------------------------------------------===//
// Context that changes as the file is lexed.
// NOTE: any state that mutates when in raw mode must have save/restore code
@@ -65,14 +66,14 @@ class Lexer : public PreprocessorLexer {
// IsAtStartOfLine - True if the next lexed token should get the "start of
// line" flag set on it.
bool IsAtStartOfLine;
-
+
Lexer(const Lexer&); // DO NOT IMPLEMENT
void operator=(const Lexer&); // DO NOT IMPLEMENT
friend class Preprocessor;
-
+
void InitLexer(const char *BufStart, const char *BufPtr, const char *BufEnd);
public:
-
+
/// Lexer constructor - Create a new lexer object for the specified buffer
/// with the specified preprocessor managing the lexing process. This lexer
/// assumes that the associated file buffer and Preprocessor objects will
@@ -84,21 +85,21 @@ public:
/// range will outlive it, so it doesn't take ownership of it.
Lexer(SourceLocation FileLoc, const LangOptions &Features,
const char *BufStart, const char *BufPtr, const char *BufEnd);
-
+
/// Lexer constructor - Create a new raw lexer object. This object is only
/// suitable for calls to 'LexRawToken'. This lexer assumes that the text
/// range will outlive it, so it doesn't take ownership of it.
Lexer(FileID FID, const SourceManager &SM, const LangOptions &Features);
-
+
/// Create_PragmaLexer: Lexer constructor - Create a new lexer object for
/// _Pragma expansion. This has a variety of magic semantics that this method
/// sets up. It returns a new'd Lexer that must be delete'd when done.
- static Lexer *Create_PragmaLexer(SourceLocation SpellingLoc,
+ static Lexer *Create_PragmaLexer(SourceLocation SpellingLoc,
SourceLocation InstantiationLocStart,
SourceLocation InstantiationLocEnd,
unsigned TokLen, Preprocessor &PP);
-
-
+
+
/// getFeatures - Return the language features currently enabled. NOTE: this
/// lexer modifies features as a file is parsed!
const LangOptions &getFeatures() const { return Features; }
@@ -108,7 +109,7 @@ public:
/// 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; }
-
+
/// Lex - Return the next token in the file. If this is the end of file, it
/// return the tok::eof token. Return true if an error occurred and
/// compilation should terminate, false if normal. This implicitly involves
@@ -116,14 +117,14 @@ public:
void Lex(Token &Result) {
// Start a new token.
Result.startToken();
-
- // NOTE, any changes here should also change code after calls to
+
+ // NOTE, any changes here should also change code after calls to
// Preprocessor::HandleDirective
if (IsAtStartOfLine) {
Result.setFlag(Token::StartOfLine);
IsAtStartOfLine = false;
}
-
+
// Get a token. Note that this may delete the current lexer if the end of
// file is reached.
LexTokenInternal(Result);
@@ -131,11 +132,11 @@ public:
/// isPragmaLexer - Returns true if this Lexer is being used to lex a pragma.
bool isPragmaLexer() const { return Is_PragmaLexer; }
-
+
/// IndirectLex - An indirect call to 'Lex' that can be invoked via
/// the PreprocessorLexer interface.
void IndirectLex(Token &Result) { Lex(Result); }
-
+
/// LexFromRawLexer - Lex a token from a designated raw lexer (one with no
/// associated preprocessor object. Return true if the 'next character to
/// read' pointer points at the end of the lexer buffer, false otherwise.
@@ -144,7 +145,7 @@ public:
Lex(Result);
// Note that lexing to the end of the buffer doesn't implicitly delete the
// lexer when in raw mode.
- return BufferPtr == BufferEnd;
+ return BufferPtr == BufferEnd;
}
/// isKeepWhitespaceMode - Return true if the lexer should return tokens for
@@ -168,23 +169,32 @@ public:
bool inKeepCommentMode() const {
return ExtendedTokenMode > 0;
}
-
+
/// SetCommentRetentionMode - Change the comment retention mode of the lexer
/// to the specified mode. This is really only useful when lexing in raw
/// mode, because otherwise the lexer needs to manage this.
- void SetCommentRetentionState(bool Mode) {
+ void SetCommentRetentionState(bool Mode) {
assert(!isKeepWhitespaceMode() &&
"Can't play with comment retention state when retaining whitespace");
ExtendedTokenMode = Mode ? 1 : 0;
}
+
+ /// \brief Specify that end-of-file is to be considered a code-completion
+ /// token.
+ ///
+ /// When in this mode, the end-of-file token will be immediately preceded
+ /// by a code-completion token.
+ void SetEofIsCodeCompletion(bool Val = true) {
+ IsEofCodeCompletion = Val;
+ }
const char *getBufferStart() const { return BufferStart; }
-
+
/// ReadToEndOfLine - Read the rest of the current preprocessor line as an
/// uninterpreted string. This switches the lexer out of directive mode.
std::string ReadToEndOfLine();
-
-
+
+
/// Diag - Forwarding function for diagnostics. This translate a source
/// position in the current buffer into a SourceLocation object for rendering.
DiagnosticBuilder Diag(const char *Loc, unsigned DiagID) const;
@@ -192,20 +202,20 @@ public:
/// getSourceLocation - Return a source location identifier for the specified
/// offset in the current file.
SourceLocation getSourceLocation(const char *Loc, unsigned TokLen = 1) const;
-
+
/// getSourceLocation - Return a source location for the next character in
/// the current file.
SourceLocation getSourceLocation() { return getSourceLocation(BufferPtr); }
-
+
/// Stringify - Convert the specified string into a C string by escaping '\'
/// and " characters. This does not add surrounding ""'s to the string.
/// If Charify is true, this escapes the ' character instead of ".
static std::string Stringify(const std::string &Str, bool Charify = false);
-
+
/// Stringify - Convert the specified string into a C string by escaping '\'
/// and " characters. This does not add surrounding ""'s to the string.
static void Stringify(llvm::SmallVectorImpl<char> &Str);
-
+
/// MeasureTokenLength - Relex the token at the specified location and return
/// its length in bytes in the input file. If the token needs cleaning (e.g.
/// includes a trigraph or an escaped newline) then this count includes bytes
@@ -213,7 +223,7 @@ public:
static unsigned MeasureTokenLength(SourceLocation Loc,
const SourceManager &SM,
const LangOptions &LangOpts);
-
+
//===--------------------------------------------------------------------===//
// Internal implementation interfaces.
private:
@@ -228,7 +238,7 @@ private:
/// takes that range and assigns it to the token as its location and size. In
/// addition, since tokens cannot overlap, this also updates BufferPtr to be
/// TokEnd.
- void FormTokenWithChars(Token &Result, const char *TokEnd,
+ void FormTokenWithChars(Token &Result, const char *TokEnd,
tok::TokenKind Kind) {
unsigned TokLen = TokEnd-BufferPtr;
Result.setLength(TokLen);
@@ -236,7 +246,7 @@ private:
Result.setKind(Kind);
BufferPtr = TokEnd;
}
-
+
/// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
/// tok::l_paren token, 0 if it is something else and 2 if there are no more
/// tokens in the buffer controlled by this lexer.
@@ -245,7 +255,7 @@ private:
//===--------------------------------------------------------------------===//
// Lexer character reading interfaces.
public:
-
+
// This lexer is built on two interfaces for reading characters, both of which
// automatically provide phase 1/2 translation. getAndAdvanceChar is used
// when we know that we will be reading a character from the input buffer and
@@ -260,7 +270,7 @@ public:
// approach allows us to emit diagnostics for characters (e.g. warnings about
// trigraphs), knowing that they only are emitted if the character is
// consumed.
-
+
/// isObviouslySimpleCharacter - Return true if the specified character is
/// obviously the same in translation phase 1 and translation phase 3. This
/// can return false for characters that end up being the same, but it will
@@ -268,7 +278,7 @@ public:
static bool isObviouslySimpleCharacter(char C) {
return C != '?' && C != '\\';
}
-
+
/// getAndAdvanceChar - Read a single 'character' from the specified buffer,
/// advance over it, and return it. This is tricky in several cases. Here we
/// just handle the trivial case and fall-back to the non-inlined
@@ -277,13 +287,13 @@ public:
// If this is not a trigraph and not a UCN or escaped newline, return
// quickly.
if (isObviouslySimpleCharacter(Ptr[0])) return *Ptr++;
-
+
unsigned Size = 0;
char C = getCharAndSizeSlow(Ptr, Size, &Tok);
Ptr += Size;
return C;
}
-
+
private:
/// ConsumeChar - When a character (identified by PeekCharAndSize) is consumed
/// and added to a given token, check to see if there are diagnostics that
@@ -300,7 +310,7 @@ private:
getCharAndSizeSlow(Ptr, Size, &Tok);
return Ptr+Size;
}
-
+
/// getCharAndSize - Peek a single 'character' from the specified buffer,
/// get its size, and return it. This is tricky in several cases. Here we
/// just handle the trivial case and fall-back to the non-inlined
@@ -312,16 +322,16 @@ private:
Size = 1;
return *Ptr;
}
-
+
Size = 0;
return getCharAndSizeSlow(Ptr, Size);
}
-
+
/// getCharAndSizeSlow - Handle the slow/uncommon case of the getCharAndSize
/// method.
char getCharAndSizeSlow(const char *Ptr, unsigned &Size, Token *Tok = 0);
public:
-
+
/// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever
/// emit a warning.
static inline char getCharAndSizeNoWarn(const char *Ptr, unsigned &Size,
@@ -332,30 +342,30 @@ public:
Size = 1;
return *Ptr;
}
-
+
Size = 0;
return getCharAndSizeSlowNoWarn(Ptr, Size, Features);
}
-
+
/// getEscapedNewLineSize - Return the size of the specified escaped newline,
/// or 0 if it is not an escaped newline. P[-1] is known to be a "\" on entry
/// to this function.
static unsigned getEscapedNewLineSize(const char *P);
-
+
/// SkipEscapedNewLines - If P points to an escaped newline (or a series of
/// them), skip over them and return the first non-escaped-newline found,
/// otherwise return P.
static const char *SkipEscapedNewLines(const char *P);
private:
-
+
/// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a
/// diagnostic.
static char getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size,
const LangOptions &Features);
-
+
//===--------------------------------------------------------------------===//
// Other lexer functions.
-
+
// Helper functions to lex the remainder of a token of the specific type.
void LexIdentifier (Token &Result, const char *CurPtr);
void LexNumericConstant (Token &Result, const char *CurPtr);
@@ -363,7 +373,7 @@ private:
void LexAngledStringLiteral(Token &Result, const char *CurPtr);
void LexCharConstant (Token &Result, const char *CurPtr);
bool LexEndOfFile (Token &Result, const char *CurPtr);
-
+
bool SkipWhitespace (Token &Result, const char *CurPtr);
bool SkipBCPLComment (Token &Result, const char *CurPtr);
bool SkipBlockComment (Token &Result, const char *CurPtr);
diff --git a/include/clang/Lex/LiteralSupport.h b/include/clang/Lex/LiteralSupport.h
index 8ee8ecf7359f..97656f7d39d6 100644
--- a/include/clang/Lex/LiteralSupport.h
+++ b/include/clang/Lex/LiteralSupport.h
@@ -17,6 +17,7 @@
#include <string>
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/DataTypes.h"
namespace llvm {
class APInt;
@@ -31,22 +32,22 @@ class Preprocessor;
class Token;
class SourceLocation;
class TargetInfo;
-
+
/// NumericLiteralParser - This performs strict semantic analysis of the content
/// of a ppnumber, classifying it as either integer, floating, or erroneous,
/// determines the radix of the value and can convert it to a useful value.
class NumericLiteralParser {
Preprocessor &PP; // needed for diagnostics
-
+
const char *const ThisTokBegin;
const char *const ThisTokEnd;
const char *DigitsBegin, *SuffixBegin; // markers
const char *s; // cursor
-
+
unsigned radix;
-
+
bool saw_exponent, saw_period;
-
+
public:
NumericLiteralParser(const char *begin, const char *end,
SourceLocation Loc, Preprocessor &PP);
@@ -56,8 +57,9 @@ public:
bool isLongLong;
bool isFloat; // 1.0f
bool isImaginary; // 1.0i
-
- bool isIntegerLiteral() const {
+ bool isMicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
+
+ bool isIntegerLiteral() const {
return !saw_period && !saw_exponent;
}
bool isFloatingLiteral() const {
@@ -66,27 +68,27 @@ public:
bool hasSuffix() const {
return SuffixBegin != ThisTokEnd;
}
-
+
unsigned getRadix() const { return radix; }
-
+
/// GetIntegerValue - Convert this numeric literal value to an APInt that
/// matches Val's input width. If there is an overflow (i.e., if the unsigned
/// value read is larger than the APInt's bits will hold), set Val to the low
/// bits of the result and return true. Otherwise, return false.
bool GetIntegerValue(llvm::APInt &Val);
-
+
/// GetFloatValue - Convert this numeric literal to a floating value, using
/// the specified APFloat fltSemantics (specifying float, double, etc).
/// The optional bool isExact (passed-by-reference) has its value
/// set to true if the returned APFloat can represent the number in the
/// literal exactly, and false otherwise.
- llvm::APFloat GetFloatValue(const llvm::fltSemantics &Format,
+ llvm::APFloat GetFloatValue(const llvm::fltSemantics &Format,
bool* isExact = NULL);
-private:
-
+private:
+
void ParseNumberStartingWithZero(SourceLocation TokLoc);
-
+
/// SkipHexDigits - Read and skip over any hex digits, up to End.
/// Return a pointer to the first non-hex digit or End.
const char *SkipHexDigits(const char *ptr) {
@@ -94,7 +96,7 @@ private:
ptr++;
return ptr;
}
-
+
/// SkipOctalDigits - Read and skip over any octal digits, up to End.
/// Return a pointer to the first non-hex digit or End.
const char *SkipOctalDigits(const char *ptr) {
@@ -102,7 +104,7 @@ private:
ptr++;
return ptr;
}
-
+
/// SkipDigits - Read and skip over any digits, up to End.
/// Return a pointer to the first non-hex digit or End.
const char *SkipDigits(const char *ptr) {
@@ -110,7 +112,7 @@ private:
ptr++;
return ptr;
}
-
+
/// SkipBinaryDigits - Read and skip over any binary digits, up to End.
/// Return a pointer to the first non-binary digit or End.
const char *SkipBinaryDigits(const char *ptr) {
@@ -118,7 +120,7 @@ private:
ptr++;
return ptr;
}
-
+
};
/// CharLiteralParser - Perform interpretation and semantic analysis of a
@@ -143,7 +145,7 @@ public:
/// literals) (C99 5.1.1.2p1).
class StringLiteralParser {
Preprocessor &PP;
-
+
unsigned MaxTokenLength;
unsigned SizeBound;
unsigned wchar_tByteWidth;
@@ -155,7 +157,7 @@ public:
bool hadError;
bool AnyWide;
bool Pascal;
-
+
const char *GetString() { return &ResultBuf[0]; }
unsigned GetStringLength() const { return ResultPtr-&ResultBuf[0]; }
@@ -163,14 +165,14 @@ public:
if (AnyWide)
return GetStringLength() / wchar_tByteWidth;
return GetStringLength();
- }
+ }
/// getOffsetOfStringByte - This function returns the offset of the
/// specified byte of the string data represented by Token. This handles
/// advancing over escape sequences in the string.
static unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo,
Preprocessor &PP);
};
-
+
} // end namespace clang
#endif
diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h
index ccd13c80d354..5887041c46b9 100644
--- a/include/clang/Lex/MacroInfo.h
+++ b/include/clang/Lex/MacroInfo.h
@@ -22,7 +22,7 @@
namespace clang {
class Preprocessor;
-
+
/// MacroInfo - Each identifier that is #define'd has an instance of this class
/// associated with it, used to implement macro expansion.
class MacroInfo {
@@ -39,7 +39,7 @@ class MacroInfo {
/// includes the __VA_ARGS__ identifier on the list.
IdentifierInfo **ArgumentList;
unsigned NumArguments;
-
+
/// ReplacementTokens - This is the list of tokens that the macro is defined
/// to.
llvm::SmallVector<Token, 8> ReplacementTokens;
@@ -47,21 +47,21 @@ class MacroInfo {
/// IsFunctionLike - True if this macro is a function-like macro, false if it
/// is an object-like macro.
bool IsFunctionLike : 1;
-
+
/// IsC99Varargs - True if this macro is of the form "#define X(...)" or
/// "#define X(Y,Z,...)". The __VA_ARGS__ token should be replaced with the
/// contents of "..." in an invocation.
bool IsC99Varargs : 1;
-
+
/// IsGNUVarargs - True if this macro is of the form "#define X(a...)". The
/// "a" identifier in the replacement list will be replaced with all arguments
/// of the macro starting with the specified one.
bool IsGNUVarargs : 1;
-
+
/// IsBuiltinMacro - True if this is a builtin macro, such as __LINE__, and if
/// it has not yet been redefined or undefined.
bool IsBuiltinMacro : 1;
-
+
private:
//===--------------------------------------------------------------------===//
// State that changes as the macro is used.
@@ -70,19 +70,19 @@ private:
/// This disbles recursive expansion, which would be quite bad for things like
/// #define A A.
bool IsDisabled : 1;
-
+
/// IsUsed - True if this macro is either defined in the main file and has
- /// been used, or if it is not defined in the main file. This is used to
+ /// been used, or if it is not defined in the main file. This is used to
/// emit -Wunused-macros diagnostics.
bool IsUsed : 1;
-
+
~MacroInfo() {
assert(ArgumentList == 0 && "Didn't call destroy before dtor!");
}
-
+
public:
MacroInfo(SourceLocation DefLoc);
-
+
/// FreeArgumentList - Free the argument list of the macro, restoring it to a
/// state where it can be reused for other devious purposes.
void FreeArgumentList(llvm::BumpPtrAllocator &PPAllocator) {
@@ -90,13 +90,13 @@ public:
ArgumentList = 0;
NumArguments = 0;
}
-
+
/// Destroy - destroy this MacroInfo object.
void Destroy(llvm::BumpPtrAllocator &PPAllocator) {
FreeArgumentList(PPAllocator);
this->~MacroInfo();
}
-
+
/// getDefinitionLoc - Return the location that the macro was defined at.
///
SourceLocation getDefinitionLoc() const { return Location; }
@@ -112,13 +112,13 @@ public:
/// this macro in spelling, arguments, and whitespace. This is used to emit
/// duplicate definition warnings. This implements the rules in C99 6.10.3.
bool isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const;
-
+
/// setIsBuiltinMacro - Set or clear the isBuiltinMacro flag.
///
void setIsBuiltinMacro(bool Val = true) {
IsBuiltinMacro = Val;
}
-
+
/// setIsUsed - Set the value of the IsUsed flag.
///
void setIsUsed(bool Val) {
@@ -132,13 +132,13 @@ public:
assert(ArgumentList == 0 && NumArguments == 0 &&
"Argument list already set!");
if (NumArgs == 0) return;
-
+
NumArguments = NumArgs;
ArgumentList = PPAllocator.Allocate<IdentifierInfo*>(NumArgs);
for (unsigned i = 0; i != NumArgs; ++i)
ArgumentList[i] = List[i];
}
-
+
/// Arguments - The list of arguments for a function-like macro. This can be
/// empty, for, e.g. "#define X()".
typedef IdentifierInfo* const *arg_iterator;
@@ -146,7 +146,7 @@ public:
arg_iterator arg_begin() const { return ArgumentList; }
arg_iterator arg_end() const { return ArgumentList+NumArguments; }
unsigned getNumArgs() const { return NumArguments; }
-
+
/// getArgumentNum - Return the argument number of the specified identifier,
/// or -1 if the identifier is not a formal argument identifier.
int getArgumentNum(IdentifierInfo *Arg) const {
@@ -154,20 +154,20 @@ public:
if (*I == Arg) return I-arg_begin();
return -1;
}
-
+
/// Function/Object-likeness. Keep track of whether this macro has formal
/// parameters.
void setIsFunctionLike() { IsFunctionLike = true; }
bool isFunctionLike() const { return IsFunctionLike; }
bool isObjectLike() const { return !IsFunctionLike; }
-
+
/// Varargs querying methods. This can only be set for function-like macros.
void setIsC99Varargs() { IsC99Varargs = true; }
void setIsGNUVarargs() { IsGNUVarargs = true; }
bool isC99Varargs() const { return IsC99Varargs; }
bool isGNUVarargs() const { return IsGNUVarargs; }
bool isVariadic() const { return IsC99Varargs | IsGNUVarargs; }
-
+
/// isBuiltinMacro - Return true if this macro is a builtin macro, such as
/// __LINE__, which requires processing before expansion.
bool isBuiltinMacro() const { return IsBuiltinMacro; }
@@ -175,7 +175,7 @@ public:
/// isUsed - Return false if this macro is defined in the main file and has
/// not yet been used.
bool isUsed() const { return IsUsed; }
-
+
/// getNumTokens - Return the number of tokens that this macro expands to.
///
unsigned getNumTokens() const {
@@ -186,22 +186,22 @@ public:
assert(Tok < ReplacementTokens.size() && "Invalid token #");
return ReplacementTokens[Tok];
}
-
+
typedef llvm::SmallVector<Token, 8>::const_iterator tokens_iterator;
tokens_iterator tokens_begin() const { return ReplacementTokens.begin(); }
tokens_iterator tokens_end() const { return ReplacementTokens.end(); }
bool tokens_empty() const { return ReplacementTokens.empty(); }
-
+
/// AddTokenToBody - Add the specified token to the replacement text for the
/// macro.
void AddTokenToBody(const Token &Tok) {
ReplacementTokens.push_back(Tok);
}
-
+
/// isEnabled - Return true if this macro is enabled: in other words, that we
/// are not currently in an expansion of this macro.
bool isEnabled() const { return !IsDisabled; }
-
+
void EnableMacro() {
assert(IsDisabled && "Cannot enable an already-enabled macro!");
IsDisabled = false;
@@ -212,7 +212,7 @@ public:
IsDisabled = true;
}
};
-
+
} // end namespace clang
#endif
diff --git a/include/clang/Lex/MultipleIncludeOpt.h b/include/clang/Lex/MultipleIncludeOpt.h
index 94d4677f9d29..5d5d67329059 100644
--- a/include/clang/Lex/MultipleIncludeOpt.h
+++ b/include/clang/Lex/MultipleIncludeOpt.h
@@ -36,7 +36,7 @@ class MultipleIncludeOpt {
/// to false, that way any tokens before the first #ifdef or after the last
/// #endif can be easily detected.
bool DidMacroExpansion;
-
+
/// TheMacro - The controlling macro for a file, if valid.
///
const IdentifierInfo *TheMacro;
@@ -46,7 +46,7 @@ public:
DidMacroExpansion = false;
TheMacro = 0;
}
-
+
/// Invalidate - Permenantly mark this file as not being suitable for the
/// include-file optimization.
void Invalidate() {
@@ -55,19 +55,19 @@ public:
ReadAnyTokens = true;
TheMacro = 0;
}
-
+
/// getHasReadAnyTokensVal - This is used for the #ifndef hande-shake at the
/// top of the file when reading preprocessor directives. Otherwise, reading
/// the "ifndef x" would count as reading tokens.
bool getHasReadAnyTokensVal() const { return ReadAnyTokens; }
-
+
// If a token is read, remember that we have seen a side-effect in this file.
void ReadToken() { ReadAnyTokens = true; }
-
+
/// ExpandedMacro - When a macro is expanded with this lexer as the current
/// buffer, this method is called to disable the MIOpt if needed.
void ExpandedMacro() { DidMacroExpansion = true; }
-
+
/// EnterTopLevelIFNDEF - When entering a top-level #ifndef directive (or the
/// "#if !defined" equivalent) without any preceding tokens, this method is
/// called.
@@ -80,14 +80,14 @@ public:
// If the macro is already set, this is after the top-level #endif.
if (TheMacro)
return Invalidate();
-
+
// If we have already expanded a macro by the end of the #ifndef line, then
// there is a macro expansion *in* the #ifndef line. This means that the
// condition could evaluate differently when subsequently #included. Reject
// this.
if (DidMacroExpansion)
return Invalidate();
-
+
// Remember that we're in the #if and that we have the macro.
ReadAnyTokens = true;
TheMacro = M;
@@ -100,7 +100,7 @@ public:
/// there is a chunk of the file not guarded by the controlling macro.
Invalidate();
}
-
+
/// ExitTopLevelConditional - This method is called when the lexer exits the
/// top-level conditional.
void ExitTopLevelConditional() {
@@ -108,12 +108,12 @@ public:
// back to "not having read any tokens" so we can detect anything after the
// #endif.
if (!TheMacro) return Invalidate();
-
+
// At this point, we haven't "read any tokens" but we do have a controlling
// macro.
ReadAnyTokens = false;
}
-
+
/// GetControllingMacroAtEndOfFile - Once the entire file has been lexed, if
/// there is a controlling macro, return it.
const IdentifierInfo *GetControllingMacroAtEndOfFile() const {
diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h
index e5cbeebd22aa..dd24fb7d7ba2 100644
--- a/include/clang/Lex/PPCallbacks.h
+++ b/include/clang/Lex/PPCallbacks.h
@@ -23,18 +23,18 @@ namespace clang {
class Token;
class IdentifierInfo;
class MacroInfo;
-
+
/// PPCallbacks - This interface provides a way to observe the actions of the
/// preprocessor as it does its thing. Clients can define their hooks here to
/// implement preprocessor level tools.
class PPCallbacks {
public:
virtual ~PPCallbacks();
-
+
enum FileChangeReason {
EnterFile, ExitFile, SystemHeaderPragma, RenameFile
};
-
+
/// FileChanged - This callback is invoked whenever a source file is
/// entered or exited. The SourceLocation indicates the new location, and
/// EnteringFile indicates whether this is because we are entering a new
@@ -43,25 +43,25 @@ public:
virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType) {
}
-
+
/// Ident - This callback is invoked when a #ident or #sccs directive is read.
///
virtual void Ident(SourceLocation Loc, const std::string &str) {
}
-
+
/// PragmaComment - This callback is invoked when a #pragma comment directive
/// is read.
///
- virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
+ virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
const std::string &Str) {
}
-
+
/// MacroExpands - This is called by
/// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is
/// found.
virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
}
-
+
/// MacroDefined - This hook is called whenever a macro definition is seen.
virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) {
}
@@ -76,7 +76,7 @@ public:
class PPChainedCallbacks : public PPCallbacks {
PPCallbacks *First, *Second;
-public:
+public:
PPChainedCallbacks(PPCallbacks *_First, PPCallbacks *_Second)
: First(_First), Second(_Second) {}
~PPChainedCallbacks() {
@@ -89,23 +89,23 @@ public:
First->FileChanged(Loc, Reason, FileType);
Second->FileChanged(Loc, Reason, FileType);
}
-
+
virtual void Ident(SourceLocation Loc, const std::string &str) {
First->Ident(Loc, str);
Second->Ident(Loc, str);
}
-
- virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
+
+ virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
const std::string &Str) {
First->PragmaComment(Loc, Kind, Str);
Second->PragmaComment(Loc, Kind, Str);
}
-
+
virtual void MacroExpands(const Token &Id, const MacroInfo* MI) {
First->MacroExpands(Id, MI);
Second->MacroExpands(Id, MI);
}
-
+
virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI) {
First->MacroDefined(II, MI);
Second->MacroDefined(II, MI);
diff --git a/include/clang/Lex/PTHLexer.h b/include/clang/Lex/PTHLexer.h
index 369b818a1fc9..e96a8c514e6e 100644
--- a/include/clang/Lex/PTHLexer.h
+++ b/include/clang/Lex/PTHLexer.h
@@ -18,42 +18,42 @@
#include <vector>
namespace clang {
-
+
class PTHManager;
class PTHSpellingSearch;
-
+
class PTHLexer : public PreprocessorLexer {
SourceLocation FileStartLoc;
-
+
/// TokBuf - Buffer from PTH file containing raw token data.
const unsigned char* TokBuf;
-
+
/// CurPtr - Pointer into current offset of the token buffer where
/// the next token will be read.
const unsigned char* CurPtr;
-
+
/// LastHashTokPtr - Pointer into TokBuf of the last processed '#'
/// token that appears at the start of a line.
const unsigned char* LastHashTokPtr;
-
+
/// PPCond - Pointer to a side table in the PTH file that provides a
/// a consise summary of the preproccessor conditional block structure.
/// This is used to perform quick skipping of conditional blocks.
const unsigned char* PPCond;
-
+
/// CurPPCondPtr - Pointer inside PPCond that refers to the next entry
/// to process when doing quick skipping of preprocessor blocks.
const unsigned char* CurPPCondPtr;
PTHLexer(const PTHLexer&); // DO NOT IMPLEMENT
void operator=(const PTHLexer&); // DO NOT IMPLEMENT
-
+
/// ReadToken - Used by PTHLexer to read tokens TokBuf.
void ReadToken(Token& T);
/// PTHMgr - The PTHManager object that created this PTHLexer.
PTHManager& PTHMgr;
-
+
Token EofToken;
protected:
@@ -62,19 +62,19 @@ protected:
/// Create a PTHLexer for the specified token stream.
PTHLexer(Preprocessor& pp, FileID FID, const unsigned char *D,
const unsigned char* ppcond, PTHManager &PM);
-public:
+public:
~PTHLexer() {}
-
+
/// Lex - Return the next token.
void Lex(Token &Tok);
-
+
void getEOF(Token &Tok);
-
+
/// DiscardToEndOfLine - Read the rest of the current preprocessor line as an
/// uninterpreted string. This switches the lexer out of directive mode.
void DiscardToEndOfLine();
-
+
/// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a
/// tok::l_paren token, 0 if it is something else and 2 if there are no more
/// tokens controlled by this lexer.
@@ -85,12 +85,12 @@ public:
// its kind.
tok::TokenKind x = (tok::TokenKind)*CurPtr;
return x == tok::eof ? 2 : x == tok::l_paren;
- }
+ }
/// IndirectLex - An indirect call to 'Lex' that can be invoked via
/// the PreprocessorLexer interface.
void IndirectLex(Token &Result) { Lex(Result); }
-
+
/// getSourceLocation - Return a source location for the token in
/// the current file.
SourceLocation getSourceLocation();
diff --git a/include/clang/Lex/PTHManager.h b/include/clang/Lex/PTHManager.h
index 507576473f60..ff1a17259e8a 100644
--- a/include/clang/Lex/PTHManager.h
+++ b/include/clang/Lex/PTHManager.h
@@ -32,29 +32,29 @@ class FileEntry;
class PTHLexer;
class Diagnostic;
class StatSysCallCache;
-
+
class PTHManager : public IdentifierInfoLookup {
friend class PTHLexer;
-
+
/// The memory mapped PTH file.
const llvm::MemoryBuffer* Buf;
/// Alloc - Allocator used for IdentifierInfo objects.
llvm::BumpPtrAllocator Alloc;
-
+
/// IdMap - A lazily generated cache mapping from persistent identifiers to
/// IdentifierInfo*.
IdentifierInfo** PerIDCache;
-
+
/// FileLookup - Abstract data structure used for mapping between files
/// and token data in the PTH file.
void* FileLookup;
-
+
/// IdDataTable - Array representing the mapping from persistent IDs to the
/// data offset within the PTH file containing the information to
/// reconsitute an IdentifierInfo.
const unsigned char* const IdDataTable;
-
+
/// SortedIdTable - Abstract data structure mapping from strings to
/// persistent IDs. This is used by get().
void* StringIdLookup;
@@ -65,15 +65,15 @@ class PTHManager : public IdentifierInfoLookup {
/// PP - The Preprocessor object that will use this PTHManager to create
/// PTHLexer objects.
Preprocessor* PP;
-
- /// SpellingBase - The base offset within the PTH memory buffer that
+
+ /// SpellingBase - The base offset within the PTH memory buffer that
/// contains the cached spellings for literals.
const unsigned char* const SpellingBase;
-
+
/// OriginalSourceFile - A null-terminated C-string that specifies the name
/// if the file (if any) that was to used to generate the PTH cache.
const char* OriginalSourceFile;
-
+
/// This constructor is intended to only be called by the static 'Create'
/// method.
PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
@@ -84,11 +84,11 @@ class PTHManager : public IdentifierInfoLookup {
// Do not implement.
PTHManager();
void operator=(const PTHManager&);
-
- /// getSpellingAtPTHOffset - Used by PTHLexer classes to get the cached
+
+ /// getSpellingAtPTHOffset - Used by PTHLexer classes to get the cached
/// spelling for a token.
unsigned getSpellingAtPTHOffset(unsigned PTHOffset, const char*& Buffer);
-
+
/// GetIdentifierInfo - Used to reconstruct IdentifierInfo objects from the
/// PTH file.
inline IdentifierInfo* GetIdentifierInfo(unsigned PersistentID) {
@@ -98,44 +98,44 @@ class PTHManager : public IdentifierInfoLookup {
return LazilyCreateIdentifierInfo(PersistentID);
}
IdentifierInfo* LazilyCreateIdentifierInfo(unsigned PersistentID);
-
+
public:
// The current PTH version.
enum { Version = 9 };
~PTHManager();
-
+
/// getOriginalSourceFile - Return the full path to the original header
/// file name that was used to generate the PTH cache.
const char* getOriginalSourceFile() const {
return OriginalSourceFile;
}
-
+
/// get - Return the identifier token info for the specified named identifier.
/// Unlike the version in IdentifierTable, this returns a pointer instead
/// of a reference. If the pointer is NULL then the IdentifierInfo cannot
/// be found.
IdentifierInfo *get(const char *NameStart, const char *NameEnd);
-
+
/// Create - This method creates PTHManager objects. The 'file' argument
/// is the name of the PTH file. This method returns NULL upon failure.
static PTHManager *Create(const std::string& file, Diagnostic* Diags = 0,
Diagnostic::Level failureLevel=Diagnostic::Warning);
- void setPreprocessor(Preprocessor *pp) { PP = pp; }
-
+ void setPreprocessor(Preprocessor *pp) { PP = pp; }
+
/// CreateLexer - Return a PTHLexer that "lexes" the cached tokens for the
/// specified file. This method returns NULL if no cached tokens exist.
/// It is the responsibility of the caller to 'delete' the returned object.
- PTHLexer *CreateLexer(FileID FID);
-
+ PTHLexer *CreateLexer(FileID FID);
+
/// createStatCache - Returns a StatSysCallCache object for use with
/// FileManager objects. These objects use the PTH data to speed up
/// calls to stat by memoizing their results from when the PTH file
/// was generated.
StatSysCallCache *createStatCache();
};
-
+
} // end namespace clang
#endif
diff --git a/include/clang/Lex/Pragma.h b/include/clang/Lex/Pragma.h
index 136dc6fabfb6..ef367feb84db 100644
--- a/include/clang/Lex/Pragma.h
+++ b/include/clang/Lex/Pragma.h
@@ -37,10 +37,10 @@ class PragmaHandler {
public:
PragmaHandler(const IdentifierInfo *name) : Name(name) {}
virtual ~PragmaHandler();
-
+
const IdentifierInfo *getName() const { return Name; }
virtual void HandlePragma(Preprocessor &PP, Token &FirstToken) = 0;
-
+
/// getIfNamespace - If this is a namespace, return it. This is equivalent to
/// using a dynamic_cast, but doesn't require RTTI.
virtual PragmaNamespace *getIfNamespace() { return 0; }
@@ -57,14 +57,14 @@ class PragmaNamespace : public PragmaHandler {
public:
PragmaNamespace(const IdentifierInfo *Name) : PragmaHandler(Name) {}
virtual ~PragmaNamespace();
-
+
/// FindHandler - Check to see if there is already a handler for the
/// specified name. If not, return the handler for the null identifier if it
/// exists, otherwise return null. If IgnoreNull is true (the default) then
/// the null handler isn't returned on failure to match.
PragmaHandler *FindHandler(const IdentifierInfo *Name,
bool IgnoreNull = true) const;
-
+
/// AddPragma - Add a pragma to this namespace.
///
void AddPragma(PragmaHandler *Handler) {
@@ -75,12 +75,12 @@ public:
/// namespace.
void RemovePragmaHandler(PragmaHandler *Handler);
- bool IsEmpty() {
- return Handlers.empty();
+ bool IsEmpty() {
+ return Handlers.empty();
}
virtual void HandlePragma(Preprocessor &PP, Token &FirstToken);
-
+
virtual PragmaNamespace *getIfNamespace() { return this; }
};
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 6d5ed72455b9..0765ac391be3 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -25,11 +25,12 @@
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Allocator.h"
#include <vector>
namespace clang {
-
+
class SourceManager;
class FileManager;
class FileEntry;
@@ -41,7 +42,7 @@ class ScratchBuffer;
class TargetInfo;
class PPCallbacks;
class DirectoryLookup;
-
+
/// Preprocessor - This object engages in a tight little dance with the lexer to
/// efficiently preprocess tokens. Lexers know only about tokens within a
/// single source file, and don't know anything about preprocessor-level issues
@@ -49,21 +50,21 @@ class DirectoryLookup;
///
class Preprocessor {
Diagnostic *Diags;
- const LangOptions &Features;
+ LangOptions Features;
TargetInfo &Target;
FileManager &FileMgr;
SourceManager &SourceMgr;
ScratchBuffer *ScratchBuf;
HeaderSearch &HeaderInfo;
-
+
/// PTH - An optional PTHManager object used for getting tokens from
/// a token cache rather than lexing the original source file.
llvm::OwningPtr<PTHManager> PTH;
-
+
/// BP - A BumpPtrAllocator object used to quickly allocate and release
/// objects internal to the Preprocessor.
llvm::BumpPtrAllocator BP;
-
+
/// Identifiers for builtin macros and other builtins.
IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__
IdentifierInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__
@@ -74,7 +75,7 @@ class Preprocessor {
IdentifierInfo *Ident_Pragma, *Ident__VA_ARGS__; // _Pragma, __VA_ARGS__
IdentifierInfo *Ident__has_feature; // __has_feature
IdentifierInfo *Ident__has_builtin; // __has_builtin
-
+
SourceLocation DATELoc, TIMELoc;
unsigned CounterValue; // Next __COUNTER__ value.
@@ -86,7 +87,7 @@ class Preprocessor {
// State that is set before the preprocessor begins.
bool KeepComments : 1;
bool KeepMacroComments : 1;
-
+
// State that changes while the preprocessor runs:
bool DisableMacroExpansion : 1; // True if macro expansion is disabled.
bool InMacroArgs : 1; // True if parsing fn macro invocation args.
@@ -94,42 +95,42 @@ class Preprocessor {
/// Identifiers - This is mapping/lookup information for all identifiers in
/// the program, including program keywords.
IdentifierTable Identifiers;
-
+
/// Selectors - This table contains all the selectors in the program. Unlike
/// IdentifierTable above, this table *isn't* populated by the preprocessor.
- /// It is declared/instantiated here because it's role/lifetime is
+ /// It is declared/instantiated here because it's role/lifetime is
/// conceptually similar the IdentifierTable. In addition, the current control
- /// flow (in clang::ParseAST()), make it convenient to put here.
+ /// flow (in clang::ParseAST()), make it convenient to put here.
/// FIXME: Make sure the lifetime of Identifiers/Selectors *isn't* tied to
/// the lifetime fo the preprocessor.
SelectorTable Selectors;
/// BuiltinInfo - Information about builtins.
Builtin::Context BuiltinInfo;
-
+
/// PragmaHandlers - This tracks all of the pragmas that the client registered
/// with this preprocessor.
PragmaNamespace *PragmaHandlers;
-
- /// \brief Tracks all of the comment handlers that the client registered
+
+ /// \brief Tracks all of the comment handlers that the client registered
/// with this preprocessor.
std::vector<CommentHandler *> CommentHandlers;
-
+
/// CurLexer - This is the current top of the stack that we're lexing from if
/// not expanding a macro and we are lexing directly from source code.
/// Only one of CurLexer, CurPTHLexer, or CurTokenLexer will be non-null.
llvm::OwningPtr<Lexer> CurLexer;
-
+
/// CurPTHLexer - This is the current top of stack that we're lexing from if
/// not expanding from a macro and we are lexing from a PTH cache.
/// Only one of CurLexer, CurPTHLexer, or CurTokenLexer will be non-null.
llvm::OwningPtr<PTHLexer> CurPTHLexer;
-
+
/// CurPPLexer - This is the current top of the stack what we're lexing from
/// if not expanding a macro. This is an alias for either CurLexer or
/// CurPTHLexer.
PreprocessorLexer* CurPPLexer;
-
+
/// CurLookup - The DirectoryLookup structure used to find the current
/// FileEntry, if CurLexer is non-null and if applicable. This allows us to
/// implement #include_next and find directory-specific properties.
@@ -138,7 +139,7 @@ class Preprocessor {
/// CurTokenLexer - This is the current macro we are expanding, if we are
/// expanding a macro. One of CurLexer and CurTokenLexer must be null.
llvm::OwningPtr<TokenLexer> CurTokenLexer;
-
+
/// IncludeMacroStack - This keeps track of the stack of files currently
/// #included, and macros currently being expanded from, not counting
/// CurLexer/CurTokenLexer.
@@ -146,7 +147,7 @@ class Preprocessor {
Lexer *TheLexer;
PTHLexer *ThePTHLexer;
PreprocessorLexer *ThePPLexer;
- TokenLexer *TheTokenLexer;
+ TokenLexer *TheTokenLexer;
const DirectoryLookup *TheDirLookup;
IncludeStackInfo(Lexer *L, PTHLexer* P, PreprocessorLexer* PPL,
@@ -155,19 +156,19 @@ class Preprocessor {
TheDirLookup(D) {}
};
std::vector<IncludeStackInfo> IncludeMacroStack;
-
+
/// Callbacks - These are actions invoked when some preprocessor activity is
/// encountered (e.g. a file is #included, etc).
PPCallbacks *Callbacks;
-
+
/// Macros - For each IdentifierInfo with 'HasMacro' set, we keep a mapping
/// to the actual definition of the macro.
llvm::DenseMap<IdentifierInfo*, MacroInfo*> Macros;
-
+
/// MICache - A "freelist" of MacroInfo objects that can be reused for quick
/// allocation.
std::vector<MacroInfo*> MICache;
-
+
// Various statistics we track for performance analysis.
unsigned NumDirectives, NumIncluded, NumDefined, NumUndefined, NumPragma;
unsigned NumIf, NumElse, NumEndif;
@@ -175,18 +176,18 @@ class Preprocessor {
unsigned NumMacroExpanded, NumFnMacroExpanded, NumBuiltinMacroExpanded;
unsigned NumFastMacroExpanded, NumTokenPaste, NumFastTokenPaste;
unsigned NumSkipped;
-
+
/// Predefines - This string is the predefined macros that preprocessor
/// should use from the command line etc.
std::string Predefines;
-
+
/// TokenLexerCache - Cache macro expanders to reduce malloc traffic.
enum { TokenLexerCacheSize = 8 };
unsigned NumCachedTokenLexers;
TokenLexer *TokenLexerCache[TokenLexerCacheSize];
private: // Cached tokens state.
- typedef std::vector<Token> CachedTokensTy;
+ typedef llvm::SmallVector<Token, 1> CachedTokensTy;
/// CachedTokens - Cached tokens are stored here when we do backtracking or
/// lookahead. They are "lexed" by the CachingLex() method.
@@ -223,9 +224,9 @@ public:
SelectorTable &getSelectorTable() { return Selectors; }
Builtin::Context &getBuiltinInfo() { return BuiltinInfo; }
llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; }
-
+
void setPTHManager(PTHManager* pm);
-
+
PTHManager *getPTHManager() { return PTH.get(); }
/// SetCommentRetentionState - Control whether or not the preprocessor retains
@@ -234,20 +235,20 @@ public:
this->KeepComments = KeepComments | KeepMacroComments;
this->KeepMacroComments = KeepMacroComments;
}
-
+
bool getCommentRetentionState() const { return KeepComments; }
-
+
/// isCurrentLexer - Return true if we are lexing directly from the specified
/// lexer.
bool isCurrentLexer(const PreprocessorLexer *L) const {
return CurPPLexer == L;
}
-
+
/// getCurrentLexer - Return the current file lexer being lexed from. Note
/// that this ignores any potentially active macro expansions and _Pragma
/// expansions going on at the time.
PreprocessorLexer *getCurrentFileLexer() const;
-
+
/// getPPCallbacks/setPPCallbacks - Accessors for preprocessor callbacks.
/// Note that this class takes ownership of any PPCallbacks object given to
/// it.
@@ -257,32 +258,32 @@ public:
C = new PPChainedCallbacks(C, Callbacks);
Callbacks = C;
}
-
+
/// getMacroInfo - Given an identifier, return the MacroInfo it is #defined to
/// or null if it isn't #define'd.
MacroInfo *getMacroInfo(IdentifierInfo *II) const {
return II->hasMacroDefinition() ? Macros.find(II)->second : 0;
}
-
+
/// setMacroInfo - Specify a macro for this identifier.
///
void setMacroInfo(IdentifierInfo *II, MacroInfo *MI);
-
+
/// macro_iterator/macro_begin/macro_end - This allows you to walk the current
/// state of the macro table. This visits every currently-defined macro.
- typedef llvm::DenseMap<IdentifierInfo*,
+ typedef llvm::DenseMap<IdentifierInfo*,
MacroInfo*>::const_iterator macro_iterator;
macro_iterator macro_begin() const { return Macros.begin(); }
macro_iterator macro_end() const { return Macros.end(); }
-
-
-
+
+
+
const std::string &getPredefines() const { return Predefines; }
/// setPredefines - Set the predefines for this Preprocessor. These
/// predefines are automatically injected when parsing the main file.
void setPredefines(const char *P) { Predefines = P; }
void setPredefines(const std::string &P) { Predefines = P; }
-
+
/// getIdentifierInfo - Return information about the specified preprocessor
/// identifier token. The version of this method that takes two character
/// pointers is preferred unless the identifier is already available as a
@@ -295,7 +296,7 @@ public:
IdentifierInfo *getIdentifierInfo(const char *NameStr) {
return getIdentifierInfo(NameStr, NameStr+strlen(NameStr));
}
-
+
/// AddPragmaHandler - Add the specified pragma handler to the preprocessor.
/// If 'Namespace' is non-null, then it is a token required to exist on the
/// pragma line before the pragma string starts, e.g. "STDC" or "GCC".
@@ -309,16 +310,16 @@ public:
/// \brief Add the specified comment handler to the preprocessor.
void AddCommentHandler(CommentHandler *Handler);
-
+
/// \brief Remove the specified comment handler.
///
/// It is an error to remove a handler that has not been registered.
void RemoveCommentHandler(CommentHandler *Handler);
-
+
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
/// which implicitly adds the builtin defines etc.
- void EnterMainSourceFile();
-
+ void EnterMainSourceFile();
+
/// EnterSourceFile - Add a source file to the top of the include stack and
/// start lexing tokens from it instead of the current buffer. If isMainFile
/// is true, this is the main file for the translation unit.
@@ -331,7 +332,7 @@ public:
/// ILEnd specifies the location of the ')' for a function-like macro or the
/// identifier for an object-like macro.
void EnterMacro(Token &Identifier, SourceLocation ILEnd, MacroArgs *Args);
-
+
/// EnterTokenStream - Add a "macro" context to the top of the include stack,
/// which will cause the lexer to start returning the specified tokens.
///
@@ -346,7 +347,7 @@ public:
///
void EnterTokenStream(const Token *Toks, unsigned NumToks,
bool DisableMacroExpansion, bool OwnsTokens);
-
+
/// RemoveTopOfLexerStack - Pop the current lexer/macro exp off the top of the
/// lexer stack. This should only be used in situations where the current
/// state of the top-of-stack lexer is known.
@@ -371,7 +372,7 @@ public:
void CommitBacktrackedTokens();
/// Backtrack - Make Preprocessor re-lex the tokens that were lexed since
- /// EnableBacktrackAtThisPos() was previously called.
+ /// EnableBacktrackAtThisPos() was previously called.
void Backtrack();
/// isBacktrackEnabled - True if EnableBacktrackAtThisPos() was called and
@@ -390,7 +391,7 @@ public:
else
CachingLex(Result);
}
-
+
/// LexNonComment - Lex a token. If it's a comment, keep lexing until we get
/// something not a comment. This is useful in -E -C mode where comments
/// would foul up preprocessor directive handling.
@@ -408,11 +409,11 @@ public:
DisableMacroExpansion = true;
// Lex the token.
Lex(Result);
-
+
// Reenable it.
DisableMacroExpansion = OldVal;
}
-
+
/// LookAhead - This peeks ahead N tokens and returns that token without
/// consuming any tokens. LookAhead(0) returns the next token that would be
/// returned by Lex(), LookAhead(1) returns the token after it, etc. This
@@ -461,7 +462,7 @@ public:
AnnotatePreviousCachedTokens(Tok);
}
- /// \brief Replace the last token with an annotation token.
+ /// \brief Replace the last token with an annotation token.
///
/// Like AnnotateCachedTokens(), this routine replaces an
/// already-parsed (and resolved) token with an annotation
@@ -481,19 +482,19 @@ public:
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
return Diags->Report(FullSourceLoc(Loc, getSourceManager()), DiagID);
}
-
+
DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) {
return Diags->Report(FullSourceLoc(Tok.getLocation(), getSourceManager()),
DiagID);
}
-
+
/// getSpelling() - Return the 'spelling' of the Tok token. The spelling of a
/// token is the characters used to represent the token in the source file
/// after trigraph expansion and escaped-newline folding. In particular, this
/// wants to get the true, uncanonicalized, spelling of things like digraphs
/// UCNs, etc.
std::string getSpelling(const Token &Tok) const;
-
+
/// getSpelling - This method is used to get the spelling of a token into a
/// preallocated buffer, instead of as an std::string. The caller is required
/// to allocate enough space for the token, which is guaranteed to be at least
@@ -521,7 +522,7 @@ public:
// works.
return *SourceMgr.getCharacterData(Tok.getLocation());
}
-
+
/// CreateString - Plop the specified string into a scratch buffer and set the
/// specified token's location and length to it. If specified, the source
/// location provides a location of the instantiation point of the token.
@@ -539,35 +540,35 @@ public:
/// it points into a macro), this routine returns an invalid
/// source location.
SourceLocation getLocForEndOfToken(SourceLocation Loc);
-
+
/// DumpToken - Print the token to stderr, used for debugging.
///
void DumpToken(const Token &Tok, bool DumpFlags = false) const;
void DumpLocation(SourceLocation Loc) const;
void DumpMacro(const MacroInfo &MI) const;
-
+
/// AdvanceToTokenCharacter - Given a location that specifies the start of a
/// token, return a new location that specifies a character within the token.
SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart,unsigned Char);
-
+
/// IncrementPasteCounter - Increment the counters for the number of token
/// paste operations performed. If fast was specified, this is a 'fast paste'
/// case we handled.
- ///
+ ///
void IncrementPasteCounter(bool isFast) {
if (isFast)
++NumFastTokenPaste;
else
++NumTokenPaste;
}
-
+
void PrintStats();
/// HandleMicrosoftCommentPaste - When the macro expander pastes together a
/// comment (/##/) in microsoft mode, this method handles updating the current
/// state, returning the token on the next source line.
void HandleMicrosoftCommentPaste(Token &Tok);
-
+
//===--------------------------------------------------------------------===//
// Preprocessor callback methods. These are invoked by a lexer as various
// directives and events are found.
@@ -576,26 +577,26 @@ public:
/// identifier information for the token and install it into the token.
IdentifierInfo *LookUpIdentifierInfo(Token &Identifier,
const char *BufPtr = 0);
-
+
/// HandleIdentifier - This callback is invoked when the lexer reads an
/// identifier and has filled in the tokens IdentifierInfo member. This
/// callback potentially macro expands it or turns it into a named token (like
/// 'for').
void HandleIdentifier(Token &Identifier);
-
+
/// HandleEndOfFile - This callback is invoked when the lexer hits the end of
/// the current file. This either returns the EOF token and returns true, or
/// pops a level off the include stack and returns false, at which point the
/// client should call lex again.
bool HandleEndOfFile(Token &Result, bool isEndOfMacro = false);
-
+
/// HandleEndOfTokenLexer - This callback is invoked when the current
/// TokenLexer hits the end of its token stream.
bool HandleEndOfTokenLexer(Token &Result);
-
+
/// HandleDirective - This callback is invoked when the lexer sees a # token
- /// at the start of a line. This consumes the directive, modifies the
+ /// at the start of a line. This consumes the directive, modifies the
/// lexer/preprocessor state, and advances the lexer(s) so that the next token
/// read is the correct one.
void HandleDirective(Token &Result);
@@ -604,11 +605,11 @@ public:
/// not, emit a diagnostic and consume up until the eom. If EnableMacros is
/// true, then we consider macros that expand to zero tokens as being ok.
void CheckEndOfDirective(const char *Directive, bool EnableMacros = false);
-
+
/// DiscardUntilEndOfDirective - Read and discard all tokens remaining on the
/// current line until the tok::eom token is found.
void DiscardUntilEndOfDirective();
-
+
/// SawDateOrTime - This returns true if the preprocessor has seen a use of
/// __DATE__ or __TIME__ in the file so far.
bool SawDateOrTime() const {
@@ -616,13 +617,13 @@ public:
}
unsigned getCounterValue() const { return CounterValue; }
void setCounterValue(unsigned V) { CounterValue = V; }
-
+
/// AllocateMacroInfo - Allocate a new MacroInfo object with the provide
/// SourceLocation.
MacroInfo* AllocateMacroInfo(SourceLocation L);
-
+
private:
-
+
void PushIncludeMacroStack() {
IncludeMacroStack.push_back(IncludeStackInfo(CurLexer.take(),
CurPTHLexer.take(),
@@ -631,7 +632,7 @@ private:
CurDirLookup));
CurPPLexer = 0;
}
-
+
void PopIncludeMacroStack() {
CurLexer.reset(IncludeMacroStack.back().TheLexer);
CurPTHLexer.reset(IncludeMacroStack.back().ThePTHLexer);
@@ -640,11 +641,11 @@ private:
CurDirLookup = IncludeMacroStack.back().TheDirLookup;
IncludeMacroStack.pop_back();
}
-
+
/// ReleaseMacroInfo - Release the specified MacroInfo. This memory will
/// be reused for allocating new MacroInfo objects.
void ReleaseMacroInfo(MacroInfo* MI);
-
+
/// isInPrimaryFile - Return true if we're in the top-level file, not in a
/// #include.
bool isInPrimaryFile() const;
@@ -653,13 +654,13 @@ private:
/// #define or #undef. This emits a diagnostic, sets the token kind to eom,
/// and discards the rest of the macro line if the macro name is invalid.
void ReadMacroName(Token &MacroNameTok, char isDefineUndef = 0);
-
+
/// ReadMacroDefinitionArgList - The ( starting an argument list of a macro
/// definition has just been read. Lex the rest of the arguments and the
/// closing ), updating MI with what we learn. Return true if an error occurs
/// parsing the arg list.
bool ReadMacroDefinitionArgList(MacroInfo *MI);
-
+
/// SkipExcludedConditionalBlock - We just read a #if or related directive and
/// decided that the subsequent tokens are in the #if'd out portion of the
/// file. Lex the rest of the file, until we see an #endif. If
@@ -670,34 +671,34 @@ private:
/// the caller can lex the first valid token.
void SkipExcludedConditionalBlock(SourceLocation IfTokenLoc,
bool FoundNonSkipPortion, bool FoundElse);
-
+
/// PTHSkipExcludedConditionalBlock - A fast PTH version of
/// SkipExcludedConditionalBlock.
void PTHSkipExcludedConditionalBlock();
-
+
/// EvaluateDirectiveExpression - Evaluate an integer constant expression that
/// may occur after a #if or #elif directive and return it as a bool. If the
/// expression is equivalent to "!defined(X)" return X in IfNDefMacro.
bool EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro);
-
+
/// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
/// #pragma GCC poison/system_header/dependency and #pragma once.
void RegisterBuiltinPragmas();
-
+
/// RegisterBuiltinMacros - Register builtin macros, such as __LINE__ with the
/// identifier table.
void RegisterBuiltinMacros();
-
+
/// HandleMacroExpandedIdentifier - If an identifier token is read that is to
/// be expanded as a macro, handle it and return the next token as 'Tok'. If
/// the macro should not be expanded return true, otherwise return false.
bool HandleMacroExpandedIdentifier(Token &Tok, MacroInfo *MI);
-
+
/// isNextPPTokenLParen - Determine whether the next preprocessor token to be
/// lexed is a '('. If so, consume the token and return true, if not, this
/// method should have no observable side-effect on the lexed tokens.
bool isNextPPTokenLParen();
-
+
/// ReadFunctionLikeMacroArgs - After reading "MACRO(", this method is
/// invoked to read all of the formal arguments specified for the macro
/// invocation. This returns null on error.
@@ -707,12 +708,12 @@ private:
/// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
/// as a builtin macro, handle it and return the next token as 'Tok'.
void ExpandBuiltinMacro(Token &Tok);
-
+
/// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then
/// return the first token after the directive. The _Pragma token has just
/// been read into 'Tok'.
void Handle_Pragma(Token &Tok);
-
+
/// EnterSourceFileWithLexer - Add a lexer to the top of the include stack and
/// start lexing tokens from it instead of the current buffer.
void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir);
@@ -720,7 +721,7 @@ private:
/// EnterSourceFileWithPTH - Add a lexer to the top of the include stack and
/// start getting tokens from it using the PTH cache.
void EnterSourceFileWithPTH(PTHLexer *PL, const DirectoryLookup *Dir);
-
+
/// GetIncludeFilenameSpelling - Turn the specified lexer token into a fully
/// checked and spelled filename, e.g. as an operand of #include. This returns
/// true if the input filename was in <>'s or false if it were in ""'s. The
@@ -729,7 +730,7 @@ private:
/// this method decides to use a different buffer.
bool GetIncludeFilenameSpelling(SourceLocation Loc,
const char *&BufStart, const char *&BufEnd);
-
+
/// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
/// return null on failure. isAngled indicates whether the file reference is
/// for system #include's or not (i.e. using <> instead of "").
@@ -737,7 +738,7 @@ private:
bool isAngled, const DirectoryLookup *FromDir,
const DirectoryLookup *&CurDir);
-
+
/// IsFileLexer - Returns true if we are lexing from a file and not a
/// pragma or a macro.
@@ -752,7 +753,7 @@ private:
bool IsFileLexer() const {
return IsFileLexer(CurLexer.get(), CurPPLexer);
}
-
+
//===--------------------------------------------------------------------===//
// Caching stuff.
void CachingLex(Token &Result);
@@ -773,7 +774,7 @@ private:
void HandleDigitDirective(Token &Tok);
void HandleUserDiagnosticDirective(Token &Tok, bool isWarning);
void HandleIdentSCCSDirective(Token &Tok);
-
+
// File inclusion.
void HandleIncludeDirective(Token &Tok,
const DirectoryLookup *LookupFrom = 0,
@@ -781,13 +782,13 @@ private:
void HandleIncludeNextDirective(Token &Tok);
void HandleIncludeMacrosDirective(Token &Tok);
void HandleImportDirective(Token &Tok);
-
+
// Macro handling.
void HandleDefineDirective(Token &Tok);
void HandleUndefDirective(Token &Tok);
// HandleAssertDirective(Token &Tok);
// HandleUnassertDirective(Token &Tok);
-
+
// Conditional Inclusion.
void HandleIfdefDirective(Token &Tok, bool isIfndef,
bool ReadAnyTokensBeforeDirective);
@@ -795,7 +796,7 @@ private:
void HandleEndifDirective(Token &Tok);
void HandleElseDirective(Token &Tok);
void HandleElifDirective(Token &Tok);
-
+
// Pragmas.
void HandlePragmaDirective();
public:
@@ -813,18 +814,18 @@ public:
class PreprocessorFactory {
public:
virtual ~PreprocessorFactory();
- virtual Preprocessor* CreatePreprocessor() = 0;
+ virtual Preprocessor* CreatePreprocessor() = 0;
};
-
-/// \brief Abstract base class that describes a handler that will receive
+
+/// \brief Abstract base class that describes a handler that will receive
/// source ranges for each of the comments encountered in the source file.
class CommentHandler {
public:
virtual ~CommentHandler();
-
+
virtual void HandleComment(Preprocessor &PP, SourceRange Comment) = 0;
};
-
+
} // end namespace clang
#endif
diff --git a/include/clang/Lex/PreprocessorLexer.h b/include/clang/Lex/PreprocessorLexer.h
index f98b5599658f..85c44c5a0b80 100644
--- a/include/clang/Lex/PreprocessorLexer.h
+++ b/include/clang/Lex/PreprocessorLexer.h
@@ -18,7 +18,7 @@
#include "clang/Lex/Token.h"
#include "llvm/ADT/SmallVector.h"
#include <string>
-
+
namespace clang {
class Preprocessor;
@@ -29,19 +29,19 @@ protected:
/// The SourceManager FileID corresponding to the file being lexed.
const FileID FID;
-
+
//===--------------------------------------------------------------------===//
// Context-specific lexing flags set by the preprocessor.
//===--------------------------------------------------------------------===//
-
+
/// ParsingPreprocessorDirective - This is true when parsing #XXX. This turns
/// '\n' into a tok::eom token.
bool ParsingPreprocessorDirective;
-
+
/// ParsingFilename - True after #include: this turns <xx> into a
/// tok::angle_string_literal token.
bool ParsingFilename;
-
+
/// LexingRawMode - True if in raw mode: This flag disables interpretation of
/// tokens and is a far faster mode to lex in than non-raw-mode. This flag:
/// 1. If EOF of the current lexer is found, the include stack isn't popped.
@@ -54,40 +54,40 @@ protected:
///
/// Note that in raw mode that the PP pointer may be null.
bool LexingRawMode;
-
- /// MIOpt - This is a state machine that detects the #ifndef-wrapping a file
+
+ /// MIOpt - This is a state machine that detects the #ifndef-wrapping a file
/// idiom for the multiple-include optimization.
MultipleIncludeOpt MIOpt;
-
+
/// ConditionalStack - Information about the set of #if/#ifdef/#ifndef blocks
/// we are currently in.
llvm::SmallVector<PPConditionalInfo, 4> ConditionalStack;
-
+
PreprocessorLexer(const PreprocessorLexer&); // DO NOT IMPLEMENT
void operator=(const PreprocessorLexer&); // DO NOT IMPLEMENT
friend class Preprocessor;
-
+
PreprocessorLexer(Preprocessor *pp, FileID fid)
: PP(pp), FID(fid), ParsingPreprocessorDirective(false),
ParsingFilename(false), LexingRawMode(false) {}
-
+
PreprocessorLexer()
- : PP(0),
+ : PP(0),
ParsingPreprocessorDirective(false),
ParsingFilename(false),
LexingRawMode(false) {}
-
+
virtual ~PreprocessorLexer() {}
-
+
virtual void IndirectLex(Token& Result) = 0;
-
+
/// getSourceLocation - Return the source location for the next observable
/// location.
virtual SourceLocation getSourceLocation() = 0;
-
+
//===--------------------------------------------------------------------===//
// #if directive handling.
-
+
/// pushConditionalLevel - When we enter a #if directive, this keeps track of
/// what we are currently in for diagnostic emission (e.g. #if with missing
/// #endif).
@@ -102,8 +102,8 @@ protected:
}
void pushConditionalLevel(const PPConditionalInfo &CI) {
ConditionalStack.push_back(CI);
- }
-
+ }
+
/// popConditionalLevel - Remove an entry off the top of the conditional
/// stack, returning information about it. If the conditional stack is empty,
/// this returns true and does not fill in the arguments.
@@ -113,44 +113,44 @@ protected:
ConditionalStack.pop_back();
return false;
}
-
+
/// peekConditionalLevel - Return the top of the conditional stack. This
/// requires that there be a conditional active.
PPConditionalInfo &peekConditionalLevel() {
assert(!ConditionalStack.empty() && "No conditionals active!");
return ConditionalStack.back();
}
-
- unsigned getConditionalStackDepth() const { return ConditionalStack.size(); }
+
+ unsigned getConditionalStackDepth() const { return ConditionalStack.size(); }
public:
-
+
//===--------------------------------------------------------------------===//
// Misc. lexing methods.
-
+
/// LexIncludeFilename - After the preprocessor has parsed a #include, lex and
/// (potentially) macro expand the filename. If the sequence parsed is not
/// lexically legal, emit a diagnostic and return a result EOM token.
void LexIncludeFilename(Token &Result);
-
+
/// setParsingPreprocessorDirective - Inform the lexer whether or not
/// we are currently lexing a preprocessor directive.
void setParsingPreprocessorDirective(bool f) {
ParsingPreprocessorDirective = f;
}
-
+
/// isLexingRawMode - Return true if this lexer is in raw mode or not.
bool isLexingRawMode() const { return LexingRawMode; }
/// getPP - Return the preprocessor object for this lexer.
Preprocessor *getPP() const { return PP; }
-
- FileID getFileID() const {
+
+ FileID getFileID() const {
assert(PP &&
"PreprocessorLexer::getFileID() should only be used with a Preprocessor");
return FID;
}
-
+
/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
/// getFileID(), this only works for lexers with attached preprocessors.
const FileEntry *getFileEntry() const;
diff --git a/include/clang/Lex/ScratchBuffer.h b/include/clang/Lex/ScratchBuffer.h
index 6506f9262947..f03515ffc142 100644
--- a/include/clang/Lex/ScratchBuffer.h
+++ b/include/clang/Lex/ScratchBuffer.h
@@ -29,13 +29,13 @@ class ScratchBuffer {
unsigned BytesUsed;
public:
ScratchBuffer(SourceManager &SM);
-
+
/// getToken - Splat the specified text into a temporary MemoryBuffer and
/// return a SourceLocation that refers to the token. This is just like the
/// previous method, but returns a location that indicates the physloc of the
/// token.
SourceLocation getToken(const char *Buf, unsigned Len, const char *&DestPtr);
-
+
private:
void AllocScratchBuffer(unsigned RequestLen);
};
diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h
index 2c8f2ad3f2b6..8acdb30cc705 100644
--- a/include/clang/Lex/Token.h
+++ b/include/clang/Lex/Token.h
@@ -62,14 +62,14 @@ class Token {
/// Kind - The actual flavor of token this is.
///
- unsigned Kind : 8; // DON'T make Kind a 'tok::TokenKind';
+ unsigned Kind : 8; // DON'T make Kind a 'tok::TokenKind';
// MSVC will treat it as a signed char and
// TokenKinds > 127 won't be handled correctly.
-
+
/// Flags - Bits we track about this token, members of the TokenFlags enum.
unsigned Flags : 8;
public:
-
+
// Various flags set per token:
enum TokenFlags {
StartOfLine = 0x01, // At start of line or only after whitespace.
@@ -80,7 +80,7 @@ public:
tok::TokenKind getKind() const { return (tok::TokenKind)Kind; }
void setKind(tok::TokenKind K) { Kind = K; }
-
+
/// is/isNot - Predicates to check if this token is a specific kind, as in
/// "if (Tok.is(tok::l_brace)) {...}".
bool is(tok::TokenKind K) const { return Kind == (unsigned) K; }
@@ -94,12 +94,12 @@ public:
is(tok::angle_string_literal);
}
- bool isAnnotation() const {
- return is(tok::annot_typename) ||
+ bool isAnnotation() const {
+ return is(tok::annot_typename) ||
is(tok::annot_cxxscope) ||
is(tok::annot_template_id);
}
-
+
/// getLocation - Return a source location identifier for the specified
/// offset in the current file.
SourceLocation getLocation() const { return Loc; }
@@ -132,11 +132,11 @@ public:
setLocation(R.getBegin());
setAnnotationEndLoc(R.getEnd());
}
-
+
const char *getName() const {
return tok::getTokenName( (tok::TokenKind) Kind);
}
-
+
/// startToken - Reset all flags to cleared.
///
void startToken() {
@@ -145,7 +145,7 @@ public:
PtrData = 0;
Loc = SourceLocation();
}
-
+
IdentifierInfo *getIdentifierInfo() const {
assert(!isAnnotation() && "Used IdentInfo on annotation token!");
if (isLiteral()) return 0;
@@ -154,7 +154,7 @@ public:
void setIdentifierInfo(IdentifierInfo *II) {
PtrData = (void*) II;
}
-
+
/// getLiteralData - For a literal token (numeric constant, string, etc), this
/// returns a pointer to the start of it in the text buffer if known, null
/// otherwise.
@@ -166,7 +166,7 @@ public:
assert(isLiteral() && "Cannot set literal data of non-literal");
PtrData = (void*)Ptr;
}
-
+
void *getAnnotationValue() const {
assert(isAnnotation() && "Used AnnotVal on non-annotation token");
return PtrData;
@@ -175,17 +175,17 @@ public:
assert(isAnnotation() && "Used AnnotVal on non-annotation token");
PtrData = val;
}
-
+
/// setFlag - Set the specified flag.
void setFlag(TokenFlags Flag) {
Flags |= Flag;
}
-
+
/// clearFlag - Unset the specified flag.
void clearFlag(TokenFlags Flag) {
Flags &= ~Flag;
}
-
+
/// getFlags - Return the internal represtation of the flags.
/// Only intended for low-level operations such as writing tokens to
// disk.
@@ -195,32 +195,32 @@ public:
/// setFlagValue - Set a flag to either true or false.
void setFlagValue(TokenFlags Flag, bool Val) {
- if (Val)
+ if (Val)
setFlag(Flag);
else
clearFlag(Flag);
}
-
+
/// isAtStartOfLine - Return true if this token is at the start of a line.
///
bool isAtStartOfLine() const { return (Flags & StartOfLine) ? true : false; }
-
+
/// hasLeadingSpace - Return true if this token has whitespace before it.
///
bool hasLeadingSpace() const { return (Flags & LeadingSpace) ? true : false; }
-
+
/// isExpandDisabled - Return true if this identifier token should never
/// be expanded in the future, due to C99 6.10.3.4p2.
bool isExpandDisabled() const {
return (Flags & DisableExpand) ? true : false;
}
-
- /// isObjCAtKeyword - Return true if we have an ObjC keyword identifier.
+
+ /// isObjCAtKeyword - Return true if we have an ObjC keyword identifier.
bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const;
-
+
/// getObjCKeywordID - Return the ObjC keyword kind.
tok::ObjCKeywordKind getObjCKeywordID() const;
-
+
/// needsCleaning - Return true if this token has trigraphs or escaped
/// newlines in it.
///
@@ -233,15 +233,15 @@ struct PPConditionalInfo {
/// IfLoc - Location where the conditional started.
///
SourceLocation IfLoc;
-
+
/// WasSkipping - True if this was contained in a skipping directive, e.g.
/// in a "#if 0" block.
bool WasSkipping;
-
+
/// FoundNonSkip - True if we have emitted tokens already, and now we're in
/// an #else block or something. Only useful in Skipping blocks.
bool FoundNonSkip;
-
+
/// FoundElse - True if we've seen a #else in this block. If so,
/// #elif/#else directives are not allowed.
bool FoundElse;
@@ -263,41 +263,41 @@ struct TemplateIdAnnotation {
/// The declaration of the template corresponding to the
/// template-name. This is an Action::DeclTy*.
- void *Template;
+ void *Template;
/// The kind of template that Template refers to.
TemplateNameKind Kind;
/// The location of the '<' before the template argument
- /// list.
+ /// list.
SourceLocation LAngleLoc;
/// The location of the '>' after the template argument
- /// list.
+ /// list.
SourceLocation RAngleLoc;
/// NumArgs - The number of template arguments.
- unsigned NumArgs;
+ unsigned NumArgs;
/// \brief Retrieves a pointer to the template arguments
void **getTemplateArgs() { return (void **)(this + 1); }
/// \brief Retrieves a pointer to the array of template argument
/// locations.
- SourceLocation *getTemplateArgLocations() {
+ SourceLocation *getTemplateArgLocations() {
return (SourceLocation *)(getTemplateArgs() + NumArgs);
}
/// \brief Retrieves a pointer to the array of flags that states
/// whether the template arguments are types.
- bool *getTemplateArgIsType() {
+ bool *getTemplateArgIsType() {
return (bool *)(getTemplateArgLocations() + NumArgs);
}
static TemplateIdAnnotation* Allocate(unsigned NumArgs) {
- TemplateIdAnnotation *TemplateId
- = (TemplateIdAnnotation *)std::malloc(sizeof(TemplateIdAnnotation) +
- sizeof(void*) * NumArgs +
+ TemplateIdAnnotation *TemplateId
+ = (TemplateIdAnnotation *)std::malloc(sizeof(TemplateIdAnnotation) +
+ sizeof(void*) * NumArgs +
sizeof(SourceLocation) * NumArgs +
sizeof(bool) * NumArgs);
TemplateId->NumArgs = NumArgs;
diff --git a/include/clang/Lex/TokenConcatenation.h b/include/clang/Lex/TokenConcatenation.h
index dfc05f4074e0..d759e47e57fc 100644
--- a/include/clang/Lex/TokenConcatenation.h
+++ b/include/clang/Lex/TokenConcatenation.h
@@ -19,7 +19,7 @@
namespace clang {
class Preprocessor;
class Token;
-
+
/// TokenConcatenation class, which answers the question of
/// "Is it safe to emit two tokens without a whitespace between them, or
/// would that cause implicit concatenation of the tokens?"
@@ -30,40 +30,40 @@ namespace clang {
///
class TokenConcatenation {
Preprocessor &PP;
-
+
enum AvoidConcatInfo {
/// By default, a token never needs to avoid concatenation. Most tokens
/// (e.g. ',', ')', etc) don't cause a problem when concatenated.
aci_never_avoid_concat = 0,
-
+
/// aci_custom_firstchar - AvoidConcat contains custom code to handle this
/// token's requirements, and it needs to know the first character of the
/// token.
aci_custom_firstchar = 1,
-
+
/// aci_custom - AvoidConcat contains custom code to handle this token's
/// requirements, but it doesn't need to know the first character of the
/// token.
aci_custom = 2,
-
+
/// aci_avoid_equal - Many tokens cannot be safely followed by an '='
/// character. For example, "<<" turns into "<<=" when followed by an =.
aci_avoid_equal = 4
};
-
+
/// TokenInfo - This array contains information for each token on what
/// action to take when avoiding concatenation of tokens in the AvoidConcat
/// method.
char TokenInfo[tok::NUM_TOKENS];
public:
TokenConcatenation(Preprocessor &PP);
-
+
bool AvoidConcat(const Token &PrevTok, const Token &Tok) const;
private:
/// StartsWithL - Return true if the spelling of this token starts with 'L'.
bool StartsWithL(const Token &Tok) const;
-
+
/// IsIdentifierL - Return true if the spelling of this token is literally
/// 'L'.
bool IsIdentifierL(const Token &Tok) const;
diff --git a/include/clang/Lex/TokenLexer.h b/include/clang/Lex/TokenLexer.h
index c0a61cf93ee5..3f13e9cc1268 100644
--- a/include/clang/Lex/TokenLexer.h
+++ b/include/clang/Lex/TokenLexer.h
@@ -21,7 +21,7 @@ namespace clang {
class Preprocessor;
class Token;
class MacroArgs;
-
+
/// TokenLexer - This implements a lexer that returns token from a macro body
/// or token stream instead of lexing from a character buffer. This is used for
/// macro expansion and _Pragma handling, for example.
@@ -47,34 +47,34 @@ class TokenLexer {
/// the preprocessor's bump pointer allocator, or some other buffer that we
/// may or may not own (depending on OwnsTokens).
const Token *Tokens;
-
+
/// NumTokens - This is the length of the Tokens array.
///
unsigned NumTokens;
-
+
/// CurToken - This is the next token that Lex will return.
///
unsigned CurToken;
-
+
/// InstantiateLocStart/End - The source location range where this macro was
/// instantiated.
SourceLocation InstantiateLocStart, InstantiateLocEnd;
-
+
/// Lexical information about the expansion point of the macro: the identifier
/// that the macro expanded from had these properties.
bool AtStartOfLine : 1;
bool HasLeadingSpace : 1;
-
+
/// OwnsTokens - This is true if this TokenLexer allocated the Tokens
/// array, and thus needs to free it when destroyed. For simple object-like
/// macros (for example) we just point into the token buffer of the macro
/// definition, we don't make a copy of it.
bool OwnsTokens : 1;
-
+
/// DisableMacroExpansion - This is true when tokens lexed from the TokenLexer
/// should not be subject to further macro expansion.
bool DisableMacroExpansion : 1;
-
+
TokenLexer(const TokenLexer&); // DO NOT IMPLEMENT
void operator=(const TokenLexer&); // DO NOT IMPLEMENT
public:
@@ -87,13 +87,13 @@ public:
: Macro(0), ActualArgs(0), PP(pp), OwnsTokens(false) {
Init(Tok, ILEnd, ActualArgs);
}
-
+
/// Init - Initialize this TokenLexer to expand from the specified macro
/// with the specified argument information. Note that this ctor takes
/// ownership of the ActualArgs pointer. ILEnd specifies the location of the
/// ')' for a function-like macro or the identifier for an object-like macro.
void Init(Token &Tok, SourceLocation ILEnd, MacroArgs *ActualArgs);
-
+
/// Create a TokenLexer for the specified token stream. If 'OwnsTokens' is
/// specified, this takes ownership of the tokens and delete[]'s them when
/// the token lexer is empty.
@@ -102,45 +102,45 @@ public:
: Macro(0), ActualArgs(0), PP(pp), OwnsTokens(false) {
Init(TokArray, NumToks, DisableExpansion, ownsTokens);
}
-
+
/// Init - Initialize this TokenLexer with the specified token stream.
/// This does not take ownership of the specified token vector.
///
- /// DisableExpansion is true when macro expansion of tokens lexed from this
+ /// DisableExpansion is true when macro expansion of tokens lexed from this
/// stream should be disabled.
void Init(const Token *TokArray, unsigned NumToks,
bool DisableMacroExpansion, bool OwnsTokens);
-
+
~TokenLexer() { destroy(); }
-
+
/// isNextTokenLParen - If the next token lexed will pop this macro off the
/// expansion stack, return 2. If the next unexpanded token is a '(', return
/// 1, otherwise return 0.
unsigned isNextTokenLParen() const;
-
+
/// Lex - Lex and return a token from this macro stream.
void Lex(Token &Tok);
-
+
private:
void destroy();
-
+
/// isAtEnd - Return true if the next lex call will pop this macro off the
/// include stack.
bool isAtEnd() const {
return CurToken == NumTokens;
}
-
+
/// PasteTokens - Tok is the LHS of a ## operator, and CurToken is the ##
/// operator. Read the ## and RHS, and paste the LHS/RHS together. If there
/// are is another ## after it, chomp it iteratively. Return the result as
/// Tok. If this returns true, the caller should immediately return the
/// token.
bool PasteTokens(Token &Tok);
-
+
/// Expand the arguments of a function-like macro so that we can quickly
/// return preexpanded tokens from Tokens.
void ExpandFunctionArguments();
-
+
/// HandleMicrosoftCommentPaste - In microsoft compatibility mode, /##/ pastes
/// together to form a comment that comments out everything in the current
/// macro, other active macros, and anything left on the current physical