diff options
Diffstat (limited to 'include/clang/Lex')
-rw-r--r-- | include/clang/Lex/CodeCompletionHandler.h | 6 | ||||
-rw-r--r-- | include/clang/Lex/DirectoryLookup.h | 10 | ||||
-rw-r--r-- | include/clang/Lex/HeaderMap.h | 2 | ||||
-rw-r--r-- | include/clang/Lex/HeaderSearch.h | 138 | ||||
-rw-r--r-- | include/clang/Lex/Lexer.h | 35 | ||||
-rw-r--r-- | include/clang/Lex/LiteralSupport.h | 1 | ||||
-rw-r--r-- | include/clang/Lex/MacroInfo.h | 15 | ||||
-rw-r--r-- | include/clang/Lex/ModuleMap.h | 6 | ||||
-rw-r--r-- | include/clang/Lex/MultipleIncludeOpt.h | 43 | ||||
-rw-r--r-- | include/clang/Lex/PPCallbacks.h | 123 | ||||
-rw-r--r-- | include/clang/Lex/Pragma.h | 10 | ||||
-rw-r--r-- | include/clang/Lex/PreprocessingRecord.h | 18 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 134 | ||||
-rw-r--r-- | include/clang/Lex/PreprocessorLexer.h | 55 | ||||
-rw-r--r-- | include/clang/Lex/Token.h | 53 |
15 files changed, 357 insertions, 292 deletions
diff --git a/include/clang/Lex/CodeCompletionHandler.h b/include/clang/Lex/CodeCompletionHandler.h index d876776..91c3b78 100644 --- a/include/clang/Lex/CodeCompletionHandler.h +++ b/include/clang/Lex/CodeCompletionHandler.h @@ -43,11 +43,11 @@ public: /// where the name of a macro is expected. /// /// \param IsDefinition Whether this is the definition of a macro, e.g., - /// in a #define. + /// in a \#define. virtual void CodeCompleteMacroName(bool IsDefinition) { } /// \brief Callback invoked when performing code completion in a preprocessor - /// expression, such as the condition of an #if or #elif directive. + /// expression, such as the condition of an \#if or \#elif directive. virtual void CodeCompletePreprocessorExpression() { } /// \brief Callback invoked when performing code completion inside a @@ -62,7 +62,7 @@ public: /// \brief Callback invoked when performing code completion in a part of the /// file where we expect natural language, e.g., a comment, string, or - /// #error directive. + /// \#error directive. virtual void CodeCompleteNaturalLanguage() { } }; diff --git a/include/clang/Lex/DirectoryLookup.h b/include/clang/Lex/DirectoryLookup.h index 95f0d27..d773fc6 100644 --- a/include/clang/Lex/DirectoryLookup.h +++ b/include/clang/Lex/DirectoryLookup.h @@ -25,7 +25,7 @@ class HeaderSearch; class Module; /// DirectoryLookup - This class represents one entry in the search list that -/// specifies the search order for directories in #include directives. It +/// specifies the search order for directories in \#include directives. It /// represents either a directory, a framework, or a headermap. /// class DirectoryLookup { @@ -146,14 +146,14 @@ public: /// part of a known module, this will be set to the module that should /// be imported instead of preprocessing/parsing the file found. /// - /// \param InUserSpecifiedSystemHeader [out] If the file is found, set to true - /// if the file is located in a framework that has been user-specified to be - /// treated as a system framework. + /// \param [out] InUserSpecifiedSystemFramework If the file is found, + /// set to true if the file is located in a framework that has been + /// user-specified to be treated as a system framework. const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module **SuggestedModule, - bool &InUserSpecifiedSystemHeader) const; + bool &InUserSpecifiedSystemFramework) const; private: const FileEntry *DoFrameworkLookup( diff --git a/include/clang/Lex/HeaderMap.h b/include/clang/Lex/HeaderMap.h index 08bc5b6..107408d 100644 --- a/include/clang/Lex/HeaderMap.h +++ b/include/clang/Lex/HeaderMap.h @@ -26,7 +26,7 @@ namespace clang { struct HMapHeader; /// This class represents an Apple concept known as a 'header map'. To the -/// #include file resolution process, it basically acts like a directory of +/// \#include file resolution process, it basically acts like a directory of /// symlinks to files. Its advantages are that it is dense and more efficient /// to create and process than a directory of symlinks. class HeaderMap { diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h index 5128ce6..8e9491f 100644 --- a/include/clang/Lex/HeaderSearch.h +++ b/include/clang/Lex/HeaderSearch.h @@ -16,6 +16,7 @@ #include "clang/Lex/DirectoryLookup.h" #include "clang/Lex/ModuleMap.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Allocator.h" @@ -30,18 +31,18 @@ class FileEntry; class FileManager; class IdentifierInfo; -/// HeaderFileInfo - The preprocessor keeps track of this information for each -/// file that is #included. +/// \brief The preprocessor keeps track of this information for each +/// file that is \#included. struct HeaderFileInfo { - /// isImport - True if this is a #import'd or #pragma once file. + /// \brief True if this is a \#import'd or \#pragma once file. unsigned isImport : 1; - /// isPragmaOnce - True if this is #pragma once file. + /// \brief True if this is a \#pragma once file. unsigned isPragmaOnce : 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 + /// by \#pragma gcc system_header. This is an instance of /// SrcMgr::CharacteristicKind. unsigned DirInfo : 2; @@ -61,8 +62,7 @@ struct HeaderFileInfo { /// those framework headers. unsigned IndexHeaderMapHeader : 1; - /// NumIncludes - This is the number of times the file has been included - /// already. + /// \brief The number of times the file has been included already. unsigned short NumIncludes; /// \brief The ID number of the controlling macro. @@ -72,8 +72,8 @@ struct HeaderFileInfo { /// external storage. unsigned ControllingMacroID; - /// ControllingMacro - If this file has a #ifndef XXX (or equivalent) guard - /// that protects the entire contents of the file, this is the identifier + /// 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. /// /// Note: Most clients should use getControllingMacro() to access @@ -117,8 +117,8 @@ public: virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) = 0; }; -/// HeaderSearch - This class encapsulates the information needed to find the -/// file referenced by a #include or #include_next, (sub-)framework lookup, etc. +/// \brief Encapsulates the information needed to find the file referenced +/// by a \#include or \#include_next, (sub-)framework lookup, etc. class HeaderSearch { /// This structure is used to record entries in our framework cache. struct FrameworkCacheEntry { @@ -133,8 +133,8 @@ class HeaderSearch { FileManager &FileMgr; DiagnosticsEngine &Diags; - /// #include search path information. Requests for #include "x" search the - /// directory of the #including file first, then each directory in SearchDirs + /// \#include search path information. Requests for \#include "x" search the + /// directory of the \#including file first, then each directory in SearchDirs /// consecutively. Requests for <x> search the current dir first, then each /// directory in SearchDirs, starting at AngledDirIdx, consecutively. If /// NoCurDirSearch is true, then the check for the file in the current @@ -144,24 +144,32 @@ class HeaderSearch { unsigned SystemDirIdx; bool NoCurDirSearch; + /// \brief \#include prefixes for which the 'system header' property is + /// overridden. + /// + /// For a \#include "x" or \#include \<x> directive, the last string in this + /// list which is a prefix of 'x' determines whether the file is treated as + /// a system header. + std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes; + /// \brief The path to the module cache. std::string ModuleCachePath; - /// FileInfo - This contains all of the preprocessor-specific data about files - /// that are included. The vector is indexed by the FileEntry's UID. - /// + /// \brief All of the preprocessor-specific data about files that are + /// included, indexed by the FileEntry's UID. std::vector<HeaderFileInfo> FileInfo; - /// LookupFileCache - This is keeps track of each lookup performed by - /// LookupFile. The first part of the value is the starting index in - /// SearchDirs that the cached search was performed from. If there is a hit - /// and this value doesn't match the current query, the cache has to be - /// ignored. The second value is the entry in SearchDirs that satisfied the - /// query. + /// \brief Keeps track of each lookup performed by LookupFile. + /// + /// The first part of the value is the starting index in SearchDirs + /// that the cached search was performed from. If there is a hit and + /// this value doesn't match the current query, the cache has to be + /// ignored. The second value is the entry in SearchDirs that satisfied + /// the query. llvm::StringMap<std::pair<unsigned, unsigned>, llvm::BumpPtrAllocator> LookupFileCache; - /// FrameworkMap - This is a collection mapping a framework or subframework + /// \brief Collection mapping a framework or subframework /// name like "Carbon" to the Carbon.framework directory. llvm::StringMap<FrameworkCacheEntry, llvm::BumpPtrAllocator> FrameworkMap; @@ -212,8 +220,7 @@ public: FileManager &getFileMgr() const { return FileMgr; } - /// SetSearchPaths - Interface for setting the file search paths. - /// + /// \brief Interface for setting the file search paths. void SetSearchPaths(const std::vector<DirectoryLookup> &dirs, unsigned angledDirIdx, unsigned systemDirIdx, bool noCurDirSearch) { @@ -226,7 +233,7 @@ public: //LookupFileCache.clear(); } - /// AddSearchPath - Add an additional search path. + /// \brief Add an additional search path. void AddSearchPath(const DirectoryLookup &dir, bool isAngled) { unsigned idx = isAngled ? SystemDirIdx : AngledDirIdx; SearchDirs.insert(SearchDirs.begin() + idx, dir); @@ -235,12 +242,18 @@ public: SystemDirIdx++; } - /// HasIncludeAliasMap - Checks whether the map exists or not + /// \brief Set the list of system header prefixes. + void SetSystemHeaderPrefixes(ArrayRef<std::pair<std::string, bool> > P) { + SystemHeaderPrefixes.assign(P.begin(), P.end()); + } + + /// \brief Checks whether the map exists or not. bool HasIncludeAliasMap() const { return IncludeAliases; } - /// AddIncludeAlias - Map the source include name to the dest include name. + /// \brief Map the source include name to the dest include name. + /// /// The Source should include the angle brackets or quotes, the dest /// should not. This allows for distinction between <> and "" headers. void AddIncludeAlias(StringRef Source, StringRef Dest) { @@ -271,7 +284,7 @@ public: /// \brief Retrieve the path to the module cache. StringRef getModuleCachePath() const { return ModuleCachePath; } - /// ClearFileInfo - Forget everything we know about headers so far. + /// \brief Forget everything we know about headers so far. void ClearFileInfo() { FileInfo.clear(); } @@ -293,7 +306,7 @@ public: /// already known. void setTarget(const TargetInfo &Target); - /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file, + /// \brief Given a "foo" or \<foo> reference, look up the indicated file, /// return null on failure. /// /// \returns If successful, this returns 'UsedDir', the DirectoryLookup member @@ -302,9 +315,9 @@ public: /// \param isAngled indicates whether the file reference is a <> reference. /// /// \param CurDir If non-null, the file was found in the specified directory - /// search location. This is used to implement #include_next. + /// search location. This is used to implement \#include_next. /// - /// \param CurFileEnt If non-null, indicates where the #including file is, in + /// \param CurFileEnt If non-null, indicates where the \#including file is, in /// case a relative search is needed. /// /// \param SearchPath If non-null, will be set to the search path relative @@ -327,73 +340,76 @@ public: Module **SuggestedModule, bool SkipCache = false); - /// 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 - /// is a subframework within Carbon.framework. If so, return the FileEntry - /// for the designated file, otherwise return null. + /// \brief 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 is a subframework within Carbon.framework. If so, return + /// the FileEntry for the designated file, otherwise return null. const FileEntry *LookupSubframeworkHeader( StringRef Filename, const FileEntry *RelativeFileEnt, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath); - /// LookupFrameworkCache - Look up the specified framework name in our - /// framework cache, returning the DirectoryEntry it is in if we know, - /// otherwise, return null. + /// \brief Look up the specified framework name in our framework cache. + /// \returns The DirectoryEntry it is in if we know, null otherwise. FrameworkCacheEntry &LookupFrameworkCache(StringRef FWName) { return FrameworkMap.GetOrCreateValue(FWName).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. + /// \brief 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, + /// \brief 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. + /// \brief Mark the specified file as a "once only" file, e.g. due to + /// \#pragma once. void MarkFileIncludeOnce(const FileEntry *File) { HeaderFileInfo &FI = getFileInfo(File); FI.isImport = true; FI.isPragmaOnce = true; } - /// MarkFileSystemHeader - Mark the specified file as a system header, e.g. - /// due to #pragma GCC system_header. + /// \brief Mark the specified file as a system header, e.g. due to + /// \#pragma GCC system_header. 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. + /// \brief 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. + /// \brief Mark the specified file as having a controlling macro. + /// + /// This is used by the multiple-include optimization to eliminate + /// no-op \#includes. void SetFileControllingMacro(const FileEntry *File, const IdentifierInfo *ControllingMacro) { getFileInfo(File).ControllingMacro = ControllingMacro; } /// \brief Determine whether this file is intended to be safe from - /// multiple inclusions, e.g., it has #pragma once or a controlling + /// multiple inclusions, e.g., it has \#pragma once or a controlling /// macro. /// - /// This routine does not consider the effect of #import + /// This routine does not consider the effect of \#import bool isFileMultipleIncludeGuarded(const FileEntry *File); /// CreateHeaderMap - This method returns a HeaderMap for the specified - /// FileEntry, uniquing them through the the 'HeaderMaps' datastructure. + /// FileEntry, uniquing them through the 'HeaderMaps' datastructure. const HeaderMap *CreateHeaderMap(const FileEntry *FE); /// \brief Retrieve the name of the module file that should be used to @@ -408,7 +424,7 @@ public: /// \brief Retrieve the name of the module file that should be used to /// load a module with the given name. /// - /// \param Module The module whose module file name will be returned. + /// \param ModuleName The module whose module file name will be returned. /// /// \returns The name of the module file that corresponds to this module, /// or an empty string if this module does not correspond to any module file. @@ -445,8 +461,6 @@ public: /// /// \param File The module map file. /// - /// \param OnlyModule If non-NULL, this will receive the - /// /// \returns true if an error occurred, false otherwise. bool loadModuleMapFile(const FileEntry *File); @@ -480,8 +494,7 @@ public: // Used by ASTReader. void setHeaderFileInfoForUID(HeaderFileInfo HFI, unsigned UID); - /// getFileInfo - Return the HeaderFileInfo structure for the specified - /// FileEntry. + /// \brief Return the HeaderFileInfo structure for the specified FileEntry. const HeaderFileInfo &getFileInfo(const FileEntry *FE) const { return const_cast<HeaderSearch*>(this)->getFileInfo(FE); } @@ -552,8 +565,7 @@ private: /// named directory. LoadModuleMapResult loadModuleMapFile(const DirectoryEntry *Dir); - /// getFileInfo - Return the HeaderFileInfo structure for the specified - /// FileEntry. + /// \brief Return the HeaderFileInfo structure for the specified FileEntry. HeaderFileInfo &getFileInfo(const FileEntry *FE); }; diff --git a/include/clang/Lex/Lexer.h b/include/clang/Lex/Lexer.h index 04bcead..ca233de 100644 --- a/include/clang/Lex/Lexer.h +++ b/include/clang/Lex/Lexer.h @@ -97,14 +97,14 @@ public: Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, Preprocessor &PP); /// 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. + /// suitable for calls to 'LexFromRawLexer'. This lexer assumes that the + /// text range will outlive it, so it doesn't take ownership of it. Lexer(SourceLocation FileLoc, const LangOptions &LangOpts, 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. + /// suitable for calls to 'LexFromRawLexer'. This lexer assumes that the + /// text range will outlive it, so it doesn't take ownership of it. Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, const SourceManager &SM, const LangOptions &LangOpts); @@ -200,7 +200,7 @@ public: /// ReadToEndOfLine - Read the rest of the current preprocessor line as an /// uninterpreted string. This switches the lexer out of directive mode. - std::string ReadToEndOfLine(); + void ReadToEndOfLine(SmallVectorImpl<char> *Result = 0); /// Diag - Forwarding function for diagnostics. This translate a source @@ -335,6 +335,28 @@ public: /// /// Returns a null range if a part of the range resides inside a macro /// expansion or the range does not reside on the same FileID. + /// + /// This function is trying to deal with macros and return a range based on + /// file locations. The cases where it can successfully handle macros are: + /// + /// -begin or end range lies at the start or end of a macro expansion, in + /// which case the location will be set to the expansion point, e.g: + /// \#define M 1 2 + /// a M + /// If you have a range [a, 2] (where 2 came from the macro), the function + /// will return a range for "a M" + /// if you have range [a, 1], the function will fail because the range + /// overlaps with only a part of the macro + /// + /// -The macro is a function macro and the range can be mapped to the macro + /// arguments, e.g: + /// \#define M 1 2 + /// \#define FM(x) x + /// FM(a b M) + /// if you have range [b, 2], the function will return the file range "b M" + /// inside the macro arguments. + /// if you have range [a, 2], the function will return the file range + /// "FM(a b M)" since the range includes all of the macro expansion. static CharSourceRange makeFileCharRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts); @@ -519,6 +541,9 @@ public: const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine); + /// \brief Returns true if the given character could appear in an identifier. + static bool isIdentifierBodyChar(char c, const LangOptions &LangOpts); + private: /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a diff --git a/include/clang/Lex/LiteralSupport.h b/include/clang/Lex/LiteralSupport.h index 7e7f82f..bbce62d 100644 --- a/include/clang/Lex/LiteralSupport.h +++ b/include/clang/Lex/LiteralSupport.h @@ -232,6 +232,7 @@ private: void init(const Token *StringToks, unsigned NumStringToks); bool CopyStringFragment(StringRef Fragment); bool DiagnoseBadString(const Token& Tok); + void DiagnoseLexingError(SourceLocation Loc); }; } // end namespace clang diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h index 8775d39..cbd201f 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 +/// MacroInfo - Each identifier that is \#define'd has an instance of this class /// associated with it, used to implement macro expansion. class MacroInfo { //===--------------------------------------------------------------------===// @@ -35,7 +35,7 @@ class MacroInfo { /// Arguments - The list of arguments for a function-like macro. This can be /// empty, for, e.g. "#define X()". In a C99-style variadic macro, this - /// includes the __VA_ARGS__ identifier on the list. + /// includes the \c __VA_ARGS__ identifier on the list. IdentifierInfo **ArgumentList; unsigned NumArguments; @@ -45,15 +45,14 @@ class MacroInfo { /// If invalid, this macro has not been explicitly given any visibility. SourceLocation VisibilityLocation; - /// ReplacementTokens - This is the list of tokens that the macro is defined - /// to. + /// \brief This is the list of tokens that the macro is defined to. SmallVector<Token, 8> ReplacementTokens; /// \brief Length in characters of the macro definition. mutable unsigned DefinitionLength; mutable bool IsDefinitionLengthCached : 1; - /// IsFunctionLike - True if this macro is a function-like macro, false if it + /// \brief True if this macro is a function-like macro, false if it /// is an object-like macro. bool IsFunctionLike : 1; @@ -71,7 +70,7 @@ class MacroInfo { /// it has not yet been redefined or undefined. bool IsBuiltinMacro : 1; - /// IsFromAST - True if this macro was loaded from an AST file. + /// \brief True if this macro was loaded from an AST file. bool IsFromAST : 1; /// \brief Whether this macro changed after it was loaded from an AST file. @@ -82,8 +81,8 @@ private: // State that changes as the macro is used. /// IsDisabled - True if we have started an expansion of this macro already. - /// This disbles recursive expansion, which would be quite bad for things like - /// #define A A. + /// This disables 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 diff --git a/include/clang/Lex/ModuleMap.h b/include/clang/Lex/ModuleMap.h index 4ebb1d4..fe5abdf 100644 --- a/include/clang/Lex/ModuleMap.h +++ b/include/clang/Lex/ModuleMap.h @@ -126,7 +126,7 @@ public: /// \brief Retrieve a module with the given name. /// - /// \param The name of the module to look up. + /// \param Name The name of the module to look up. /// /// \returns The named module, if known; otherwise, returns null. Module *findModule(StringRef Name); @@ -134,7 +134,7 @@ public: /// \brief Retrieve a module with the given name using lexical name lookup, /// starting at the given context. /// - /// \param The name of the module to look up. + /// \param Name The name of the module to look up. /// /// \param Context The module context, from which we will perform lexical /// name lookup. @@ -145,7 +145,7 @@ public: /// \brief Retrieve a module with the given name within the given context, /// using direct (qualified) name lookup. /// - /// \param The name of the module to look up. + /// \param Name The name of the module to look up. /// /// \param Context The module for which we will look for a submodule. If /// null, we will look for a top-level module. diff --git a/include/clang/Lex/MultipleIncludeOpt.h b/include/clang/Lex/MultipleIncludeOpt.h index 95b00df..a2a5a77 100644 --- a/include/clang/Lex/MultipleIncludeOpt.h +++ b/include/clang/Lex/MultipleIncludeOpt.h @@ -6,8 +6,9 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This file defines the MultipleIncludeOpt interface. +/// +/// \file +/// \brief Defines the MultipleIncludeOpt interface. // //===----------------------------------------------------------------------===// @@ -17,17 +18,18 @@ namespace clang { class IdentifierInfo; -/// MultipleIncludeOpt - This class implements the simple state machine that the -/// Lexer class uses to detect files subject to the 'multiple-include' -/// optimization. The public methods in this class are triggered by various +/// \brief Implements the simple state machine that the Lexer class uses to +/// detect files subject to the 'multiple-include' optimization. +/// +/// The public methods in this class are triggered by various /// events that occur when a file is lexed, and after the entire file is lexed, /// information about which macro (if any) controls the header is returned. class MultipleIncludeOpt { /// ReadAnyTokens - This is set to false when a file is first opened and true /// any time a token is returned to the client or a (non-multiple-include) - /// directive is parsed. When the final #endif is parsed this is reset back - /// to false, that way any tokens before the first #ifdef or after the last - /// #endif can be easily detected. + /// directive is parsed. When the final \#endif is parsed this is reset back + /// to false, that way any tokens before the first \#ifdef or after the last + /// \#endif can be easily detected. bool ReadAnyTokens; /// ReadAnyTokens - This is set to false when a file is first opened and true @@ -56,7 +58,7 @@ public: TheMacro = 0; } - /// getHasReadAnyTokensVal - This is used for the #ifndef hande-shake at the + /// 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; } @@ -68,14 +70,13 @@ public: /// 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. + /// \brief Called when entering a top-level \#ifndef directive (or the + /// "\#if !defined" equivalent) without any preceding tokens. /// /// Note, we don't care about the input value of 'ReadAnyTokens'. The caller /// ensures that this is only called if there are no tokens read before the - /// #ifndef. The caller is required to do this, because reading the #if line - /// obviously reads in in tokens. + /// \#ifndef. The caller is required to do this, because reading the \#if + /// line obviously reads in in tokens. void EnterTopLevelIFNDEF(const IdentifierInfo *M) { // If the macro is already set, this is after the top-level #endif. if (TheMacro) @@ -93,16 +94,14 @@ public: TheMacro = M; } - /// EnterTopLevelConditional - This is invoked when a top level conditional - /// (except #ifndef) is found. + /// \brief Invoked when a top level conditional (except \#ifndef) is found. void EnterTopLevelConditional() { - /// If a conditional directive (except #ifndef) is found at the top level, - /// there is a chunk of the file not guarded by the controlling macro. + // If a conditional directive (except #ifndef) is found at the top level, + // 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. + /// \brief Called when the lexer exits the top-level conditional. void ExitTopLevelConditional() { // If we have a macro, that means the top of the file was ok. Set our state // back to "not having read any tokens" so we can detect anything after the @@ -114,8 +113,8 @@ public: ReadAnyTokens = false; } - /// GetControllingMacroAtEndOfFile - Once the entire file has been lexed, if - /// there is a controlling macro, return it. + /// \brief Once the entire file has been lexed, if there is a controlling + /// macro, return it. const IdentifierInfo *GetControllingMacroAtEndOfFile() const { // If we haven't read any tokens after the #endif, return the controlling // macro if it's valid (if it isn't, it will be null). diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index 33558c8..962b4df 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -6,9 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This file defines the PPCallbacks interface. -// +/// +/// \file +/// \brief Defines the PPCallbacks interface. +/// //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_LEX_PPCALLBACKS_H @@ -26,9 +27,10 @@ namespace clang { 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. +/// \brief 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(); @@ -37,29 +39,29 @@ public: 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 - /// #include'd file (when true) or whether we're exiting one because we ran - /// off the end (when false). + /// \brief Callback invoked whenever a source file is entered or exited. /// - /// \param PrevFID the file that was exited if \arg Reason is ExitFile. + /// \param Loc Indicates the new location. + /// \param PrevFID the file that was exited if \p Reason is ExitFile. virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, SrcMgr::CharacteristicKind FileType, FileID PrevFID = FileID()) { } - /// FileSkipped - This callback is invoked whenever a source file is - /// skipped as the result of header guard optimization. ParentFile - /// is the file that #includes the skipped file. FilenameTok is the - /// token in ParentFile that indicates the skipped file. + /// \brief Callback invoked whenever a source file is skipped as the result + /// of header guard optimization. + /// + /// \param ParentFile The file that \#included the skipped file. + /// + /// \param FilenameTok The token in ParentFile that indicates the + /// skipped file. virtual void FileSkipped(const FileEntry &ParentFile, const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) { } - /// FileNotFound - This callback is invoked whenever an inclusion directive - /// results in a file-not-found error. + /// \brief Callback invoked whenever an inclusion directive results in a + /// file-not-found error. /// /// \param FileName The name of the file being included, as written in the /// source code. @@ -75,8 +77,8 @@ public: return false; } - /// \brief This callback is invoked whenever an inclusion directive of - /// any kind (\c #include, \c #import, etc.) has been processed, regardless + /// \brief Callback invoked whenever an inclusion directive of + /// any kind (\c \#include, \c \#import, etc.) has been processed, regardless /// of whether the inclusion will actually result in an inclusion. /// /// \param HashLoc The location of the '#' that starts the inclusion @@ -118,119 +120,116 @@ public: StringRef RelativePath) { } - /// EndOfMainFile - This callback is invoked when the end of the main file is - /// reach, no subsequent callbacks will be made. + /// \brief Callback invoked when the end of the main file is reached. + /// + /// No subsequent callbacks will be made. virtual void EndOfMainFile() { } - /// Ident - This callback is invoked when a #ident or #sccs directive is read. + /// \brief Callback invoked when a \#ident or \#sccs directive is read. /// \param Loc The location of the directive. /// \param str The text of the directive. /// virtual void Ident(SourceLocation Loc, const std::string &str) { } - /// PragmaComment - This callback is invoked when a #pragma comment directive - /// is read. - /// + /// \brief Callback invoked when a \#pragma comment directive is read. virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, const std::string &Str) { } - /// PragmaMessage - This callback is invoked when a #pragma message directive - /// is read. + /// \brief Callback invoked when a \#pragma message directive is read. /// \param Loc The location of the message directive. - /// \param str The text of the message directive. - /// + /// \param Str The text of the message directive. virtual void PragmaMessage(SourceLocation Loc, StringRef Str) { } - /// PragmaDiagnosticPush - This callback is invoked when a - /// #pragma gcc dianostic push directive is read. + /// \brief Callback invoked when a \#pragma gcc dianostic push directive + /// is read. virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) { } - /// PragmaDiagnosticPop - This callback is invoked when a - /// #pragma gcc dianostic pop directive is read. + /// \brief Callback invoked when a \#pragma gcc dianostic pop directive + /// is read. virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) { } - /// PragmaDiagnostic - This callback is invoked when a - /// #pragma gcc dianostic directive is read. + /// \brief Callback invoked when a \#pragma gcc dianostic directive is read. virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Mapping mapping, StringRef Str) { } - /// MacroExpands - This is called by - /// Preprocessor::HandleMacroExpandedIdentifier when a macro invocation is - /// found. + /// \brief Called by Preprocessor::HandleMacroExpandedIdentifier when a + /// macro invocation is found. virtual void MacroExpands(const Token &MacroNameTok, const MacroInfo* MI, SourceRange Range) { } - /// MacroDefined - This hook is called whenever a macro definition is seen. + /// \brief Hook called whenever a macro definition is seen. virtual void MacroDefined(const Token &MacroNameTok, const MacroInfo *MI) { } - /// MacroUndefined - This hook is called whenever a macro #undef is seen. + /// \brief Hook called whenever a macro \#undef is seen. + /// /// MI is released immediately following this callback. virtual void MacroUndefined(const Token &MacroNameTok, const MacroInfo *MI) { } - /// Defined - This hook is called whenever the 'defined' operator is seen. + /// \brief Hook called whenever the 'defined' operator is seen. virtual void Defined(const Token &MacroNameTok) { } - /// SourceRangeSkipped - This hook is called when a source range is skipped. + /// \brief Hook called when a source range is skipped. /// \param Range The SourceRange that was skipped. The range begins at the - /// #if/#else directive and ends after the #endif/#else directive. + /// \#if/\#else directive and ends after the \#endif/\#else directive. virtual void SourceRangeSkipped(SourceRange Range) { } - /// If -- This hook is called whenever an #if is seen. + /// \brief Hook called whenever an \#if is seen. /// \param Loc the source location of the directive. /// \param ConditionRange The SourceRange of the expression being tested. + /// // FIXME: better to pass in a list (or tree!) of Tokens. virtual void If(SourceLocation Loc, SourceRange ConditionRange) { } - /// Elif -- This hook is called whenever an #elif is seen. + /// \brief Hook called whenever an \#elif is seen. /// \param Loc the source location of the directive. /// \param ConditionRange The SourceRange of the expression being tested. - /// \param IfLoc the source location of the #if/#ifdef/#ifndef directive. + /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. // FIXME: better to pass in a list (or tree!) of Tokens. virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc) { } - /// Ifdef -- This hook is called whenever an #ifdef is seen. + /// \brief Hook called whenever an \#ifdef is seen. /// \param Loc the source location of the directive. - /// \param II Information on the token being tested. + /// \param MacroNameTok Information on the token being tested. virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok) { } - /// Ifndef -- This hook is called whenever an #ifndef is seen. + /// \brief Hook called whenever an \#ifndef is seen. /// \param Loc the source location of the directive. - /// \param II Information on the token being tested. + /// \param MacroNameTok Information on the token being tested. virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok) { } - /// Else -- This hook is called whenever an #else is seen. + /// \brief Hook called whenever an \#else is seen. /// \param Loc the source location of the directive. - /// \param IfLoc the source location of the #if/#ifdef/#ifndef directive. + /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. virtual void Else(SourceLocation Loc, SourceLocation IfLoc) { } - /// Endif -- This hook is called whenever an #endif is seen. + /// \brief Hook called whenever an \#endif is seen. /// \param Loc the source location of the directive. - /// \param IfLoc the source location of the #if/#ifdef/#ifndef directive. + /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) { } }; -/// PPChainedCallbacks - Simple wrapper class for chaining callbacks. +/// \brief Simple wrapper class for chaining callbacks. class PPChainedCallbacks : public PPCallbacks { virtual void anchor(); PPCallbacks *First, *Second; @@ -342,38 +341,38 @@ public: Second->SourceRangeSkipped(Range); } - /// If -- This hook is called whenever an #if is seen. + /// \brief Hook called whenever an \#if is seen. virtual void If(SourceLocation Loc, SourceRange ConditionRange) { First->If(Loc, ConditionRange); Second->If(Loc, ConditionRange); } - /// Elif -- This hook is called whenever an #if is seen. + /// \brief Hook called whenever an \#if is seen. virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, SourceLocation IfLoc) { First->Elif(Loc, ConditionRange, IfLoc); Second->Elif(Loc, ConditionRange, IfLoc); } - /// Ifdef -- This hook is called whenever an #ifdef is seen. + /// \brief Hook called whenever an \#ifdef is seen. virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok) { First->Ifdef(Loc, MacroNameTok); Second->Ifdef(Loc, MacroNameTok); } - /// Ifndef -- This hook is called whenever an #ifndef is seen. + /// \brief Hook called whenever an \#ifndef is seen. virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok) { First->Ifndef(Loc, MacroNameTok); Second->Ifndef(Loc, MacroNameTok); } - /// Else -- This hook is called whenever an #else is seen. + /// \brief Hook called whenever an \#else is seen. virtual void Else(SourceLocation Loc, SourceLocation IfLoc) { First->Else(Loc, IfLoc); Second->Else(Loc, IfLoc); } - /// Endif -- This hook is called whenever an #endif is seen. + /// \brief Hook called whenever an \#endif is seen. virtual void Endif(SourceLocation Loc, SourceLocation IfLoc) { First->Endif(Loc, IfLoc); Second->Endif(Loc, IfLoc); diff --git a/include/clang/Lex/Pragma.h b/include/clang/Lex/Pragma.h index 4868811..087448f 100644 --- a/include/clang/Lex/Pragma.h +++ b/include/clang/Lex/Pragma.h @@ -26,12 +26,12 @@ namespace clang { class PragmaNamespace; /** - * \brief Describes how the pragma was introduced, e.g., with #pragma, + * \brief Describes how the pragma was introduced, e.g., with \#pragma, * _Pragma, or __pragma. */ enum PragmaIntroducerKind { /** - * \brief The pragma was introduced via #pragma. + * \brief The pragma was introduced via \#pragma. */ PIK_HashPragma, @@ -54,7 +54,7 @@ namespace clang { /// pragmas the handler with a null identifier is invoked, if it exists. /// /// Note that the PragmaNamespace class can be used to subdivide pragmas, e.g. -/// we treat "#pragma STDC" and "#pragma GCC" as namespaces that contain other +/// we treat "\#pragma STDC" and "\#pragma GCC" as namespaces that contain other /// pragmas. class PragmaHandler { std::string Name; @@ -84,8 +84,8 @@ public: /// PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas, /// allowing hierarchical pragmas to be defined. Common examples of namespaces -/// are "#pragma GCC", "#pragma STDC", and "#pragma omp", but any namespaces may -/// be (potentially recursively) defined. +/// are "\#pragma GCC", "\#pragma STDC", and "\#pragma omp", but any namespaces +/// may be (potentially recursively) defined. class PragmaNamespace : public PragmaHandler { /// Handlers - This is a map of the handlers in this namespace with their name /// as key. diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index 45e3a5d..fb3e081 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -59,8 +59,8 @@ namespace clang { /// \brief A macro definition. MacroDefinitionKind, - /// \brief An inclusion directive, such as \c #include, \c - /// #import, or \c #include_next. + /// \brief An inclusion directive, such as \c \#include, \c + /// \#import, or \c \#include_next. InclusionDirectiveKind, /// @} @@ -197,19 +197,19 @@ namespace clang { }; /// \brief Record the location of an inclusion directive, such as an - /// \c #include or \c #import statement. + /// \c \#include or \c \#import statement. class InclusionDirective : public PreprocessingDirective { public: /// \brief The kind of inclusion directives known to the /// preprocessor. enum InclusionKind { - /// \brief An \c #include directive. + /// \brief An \c \#include directive. Include, - /// \brief An Objective-C \c #import directive. + /// \brief An Objective-C \c \#import directive. Import, - /// \brief A GNU \c #include_next directive. + /// \brief A GNU \c \#include_next directive. IncludeNext, - /// \brief A Clang \c #__include_macros directive. + /// \brief A Clang \c \#__include_macros directive. IncludeMacros }; @@ -551,7 +551,7 @@ namespace clang { /// /// Can be used to avoid implicit deserializations of preallocated /// preprocessed entities if we only care about entities of a specific file - /// and not from files #included in the range given at + /// and not from files \#included in the range given at /// \see getPreprocessedEntitiesInRange. bool isEntityInFileID(iterator PPEI, FileID FID); @@ -565,7 +565,7 @@ namespace clang { } /// \brief Returns true if the given range intersects with a conditional - /// directive. if a #if/#endif block is fully contained within the range, + /// directive. if a \#if/\#endif block is fully contained within the range, /// this function will return false. bool rangeIntersectsConditionalDirective(SourceRange Range) const; diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 055008f..02e3f1e 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -58,7 +58,7 @@ class ModuleLoader; /// 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 -/// like the #include stack, token expansion, etc. +/// like the \#include stack, token expansion, etc. /// class Preprocessor : public RefCountedBase<Preprocessor> { DiagnosticsEngine *Diags; @@ -103,7 +103,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> { unsigned CounterValue; // Next __COUNTER__ value. enum { - /// MaxIncludeStackDepth - Maximum depth of #includes. + /// MaxIncludeStackDepth - Maximum depth of \#includes. MaxAllowedIncludeStackDepth = 200 }; @@ -121,9 +121,19 @@ class Preprocessor : public RefCountedBase<Preprocessor> { /// DisableMacroExpansion - True if macro expansion is disabled. bool DisableMacroExpansion : 1; + /// MacroExpansionInDirectivesOverride - Temporarily disables + /// DisableMacroExpansion (i.e. enables expansion) when parsing preprocessor + /// directives. + bool MacroExpansionInDirectivesOverride : 1; + + class ResetMacroExpansionHelper; + /// \brief Whether we have already loaded macros from the external source. mutable bool ReadMacrosFromExternalSource : 1; + /// \brief True if pragmas are enabled. + bool PragmasEnabled : 1; + /// \brief True if we are pre-expanding macro arguments. bool InMacroArgPreExpansion; @@ -165,11 +175,12 @@ class Preprocessor : public RefCountedBase<Preprocessor> { unsigned CodeCompletionOffset; /// \brief The location for the code-completion point. This gets instantiated - /// when the CodeCompletionFile gets #include'ed for preprocessing. + /// when the CodeCompletionFile gets \#include'ed for preprocessing. SourceLocation CodeCompletionLoc; /// \brief The start location for the file of the code-completion point. - /// This gets instantiated when the CodeCompletionFile gets #include'ed + /// + /// This gets instantiated when the CodeCompletionFile gets \#include'ed /// for preprocessing. SourceLocation CodeCompletionFileLoc; @@ -215,7 +226,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> { /// 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. + /// implement \#include_next and find directory-specific properties. const DirectoryLookup *CurDirLookup; /// CurTokenLexer - This is the current macro we are expanding, if we are @@ -232,7 +243,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> { } CurLexerKind; /// IncludeMacroStack - This keeps track of the stack of files currently - /// #included, and macros currently being expanded from, not counting + /// \#included, and macros currently being expanded from, not counting /// CurLexer/CurTokenLexer. struct IncludeStackInfo { enum CurLexerKind CurLexerKind; @@ -251,9 +262,18 @@ class Preprocessor : public RefCountedBase<Preprocessor> { std::vector<IncludeStackInfo> IncludeMacroStack; /// Callbacks - These are actions invoked when some preprocessor activity is - /// encountered (e.g. a file is #included, etc). + /// encountered (e.g. a file is \#included, etc). PPCallbacks *Callbacks; + struct MacroExpandsInfo { + Token Tok; + MacroInfo *MI; + SourceRange Range; + MacroExpandsInfo(Token Tok, MacroInfo *MI, SourceRange Range) + : Tok(Tok), MI(MI), Range(Range) { } + }; + SmallVector<MacroExpandsInfo, 2> DelayedMacroExpandsCallbacks; + /// Macros - For each IdentifierInfo with 'HasMacro' set, we keep a mapping /// to the actual definition of the macro. llvm::DenseMap<IdentifierInfo*, MacroInfo*> Macros; @@ -400,6 +420,9 @@ public: bool getCommentRetentionState() const { return KeepComments; } + void setPragmasEnabled(bool Enabled) { PragmasEnabled = Enabled; } + bool getPragmasEnabled() const { return PragmasEnabled; } + void SetSuppressIncludeNotFoundError(bool Suppress) { SuppressIncludeNotFoundError = Suppress; } @@ -434,8 +457,8 @@ public: Callbacks = C; } - /// getMacroInfo - Given an identifier, return the MacroInfo it is #defined to - /// or null if it isn't #define'd. + /// \brief Given an identifier, return the MacroInfo it is \#defined to + /// or null if it isn't \#define'd. MacroInfo *getMacroInfo(IdentifierInfo *II) const { if (!II->hasMacroDefinition()) return 0; @@ -443,8 +466,7 @@ public: return getInfoForMacro(II); } - /// setMacroInfo - Specify a macro for this identifier. - /// + /// \brief Specify a macro for this identifier. void setMacroInfo(IdentifierInfo *II, MacroInfo *MI, bool LoadedFromAST = false); @@ -488,12 +510,12 @@ public: } /// \brief Add the specified comment handler to the preprocessor. - void AddCommentHandler(CommentHandler *Handler); + 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); + void removeCommentHandler(CommentHandler *Handler); /// \brief Set the code completion handler to the given object. void setCodeCompletionHandler(CodeCompletionHandler &Handler) { @@ -634,6 +656,12 @@ public: while (Result.getKind() == tok::comment); } + /// Disables macro expansion everywhere except for preprocessor directives. + void SetMacroExpansionOnlyInDirectives() { + DisableMacroExpansion = true; + MacroExpansionInDirectivesOverride = true; + } + /// 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 @@ -752,25 +780,24 @@ public: getDiagnostics().setSuppressAllDiagnostics(true); } - /// \brief The location of the currently-active #pragma clang + /// \brief The location of the currently-active \#pragma clang /// arc_cf_code_audited begin. Returns an invalid location if there /// is no such pragma active. SourceLocation getPragmaARCCFCodeAuditedLoc() const { return PragmaARCCFCodeAuditedLoc; } - /// \brief Set the location of the currently-active #pragma clang + /// \brief Set the location of the currently-active \#pragma clang /// arc_cf_code_audited begin. An invalid location ends the pragma. void setPragmaARCCFCodeAuditedLoc(SourceLocation Loc) { PragmaARCCFCodeAuditedLoc = Loc; } - /// \brief Instruct the preprocessor to skip part of the main - /// the main source file. + /// \brief Instruct the preprocessor to skip part of the main source file. /// - /// \brief Bytes The number of bytes in the preamble to skip. + /// \param Bytes The number of bytes in the preamble to skip. /// - /// \brief StartOfLine Whether skipping these bytes puts the lexer at the + /// \param StartOfLine Whether skipping these bytes puts the lexer at the /// start of a line. void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine) { SkipMainFilePreamble.first = Bytes; @@ -1035,24 +1062,27 @@ public: /// \brief Retrieves the module that we're currently building, if any. Module *getCurrentModule(); - /// AllocateMacroInfo - Allocate a new MacroInfo object with the provide - /// SourceLocation. + /// \brief Allocate a new MacroInfo object with the provided SourceLocation. MacroInfo *AllocateMacroInfo(SourceLocation L); - /// CloneMacroInfo - Allocate a new MacroInfo object which is clone of MI. + /// \brief Allocate a new MacroInfo object which is clone of \p MI. MacroInfo *CloneMacroInfo(const MacroInfo &MI); - /// 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 - /// caller is expected to provide a buffer that is large enough to hold the - /// spelling of the filename, but is also expected to handle the case when - /// this method decides to use a different buffer. + /// \brief Turn the specified lexer token into a fully checked and spelled + /// filename, e.g. as an operand of \#include. + /// + /// The caller is expected to provide a buffer that is large enough to hold + /// the spelling of the filename, but is also expected to handle the case + /// when this method decides to use a different buffer. + /// + /// \returns true if the input filename was in <>'s or false if it was + /// in ""'s. bool GetIncludeFilenameSpelling(SourceLocation Loc,StringRef &Filename); - /// 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 ""). + /// \brief Given a "foo" or \<foo> reference, look up the indicated file. + /// + /// Returns null on failure. \p isAngled indicates whether the file + /// reference is for system \#include's or not (i.e. using <> instead of ""). const FileEntry *LookupFile(StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, @@ -1063,18 +1093,19 @@ public: /// GetCurLookup - 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. + /// implement \#include_next and find directory-specific properties. const DirectoryLookup *GetCurDirLookup() { return CurDirLookup; } - /// isInPrimaryFile - Return true if we're in the top-level file, not in a - /// #include. + /// \brief Return true if we're in the top-level file, not in a \#include. bool isInPrimaryFile() const; - /// ConcatenateIncludeName - Handle cases where the #include name is expanded + /// ConcatenateIncludeName - Handle cases where the \#include name is expanded /// from a macro as multiple tokens, which need to be glued together. This /// occurs for code like: - /// #define FOO <a/b.h> - /// #include FOO + /// \code + /// \#define FOO <a/b.h> + /// \#include FOO + /// \endcode /// because in this case, "<a/b.h>" is returned as 7 tokens, not one. /// /// This code concatenates and consumes tokens up to the '>' token. It @@ -1109,15 +1140,16 @@ private: IncludeMacroStack.pop_back(); } - /// AllocateMacroInfo - Allocate a new MacroInfo object. + /// \brief Allocate a new MacroInfo object. MacroInfo *AllocateMacroInfo(); - /// ReleaseMacroInfo - Release the specified MacroInfo. This memory will - /// be reused for allocating new MacroInfo objects. + /// \brief Release the specified MacroInfo for re-use. + /// + /// This memory will be reused for allocating new MacroInfo objects. void ReleaseMacroInfo(MacroInfo* MI); /// ReadMacroName - Lex and validate a macro name, which occurs after a - /// #define or #undef. This emits a diagnostic, sets the token kind to eod, + /// \#define or \#undef. This emits a diagnostic, sets the token kind to eod, /// and discards the rest of the macro line if the macro name is invalid. void ReadMacroName(Token &MacroNameTok, char isDefineUndef = 0); @@ -1128,20 +1160,19 @@ private: /// Return true if an error occurs parsing the arg list. bool ReadMacroDefinitionArgList(MacroInfo *MI, Token& LastTok); - /// 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 + /// 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 \p /// FoundNonSkipPortion is true, then we have already emitted code for part of - /// this #if directive, so #else/#elif blocks should never be entered. If - /// FoundElse is false, then #else directives are ok, if not, then we have - /// already seen one so a #else directive is a duplicate. When this returns, + /// this \#if directive, so \#else/\#elif blocks should never be entered. If + /// \p FoundElse is false, then \#else directives are ok, if not, then we have + /// already seen one so a \#else directive is a duplicate. When this returns, /// the caller can lex the first valid token. void SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, bool FoundNonSkipPortion, bool FoundElse, SourceLocation ElseLoc = SourceLocation()); - /// PTHSkipExcludedConditionalBlock - A fast PTH version of - /// SkipExcludedConditionalBlock. + /// \brief A fast PTH version of SkipExcludedConditionalBlock. void PTHSkipExcludedConditionalBlock(); /// EvaluateDirectiveExpression - Evaluate an integer constant expression that @@ -1150,11 +1181,10 @@ private: bool EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro); /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas: - /// #pragma GCC poison/system_header/dependency and #pragma once. + /// \#pragma GCC poison/system_header/dependency and \#pragma once. void RegisterBuiltinPragmas(); - /// RegisterBuiltinMacros - Register builtin macros, such as __LINE__ with the - /// identifier table. + /// \brief Register builtin macros such as __LINE__ with the identifier table. void RegisterBuiltinMacros(); /// HandleMacroExpandedIdentifier - If an identifier token is read that is to diff --git a/include/clang/Lex/PreprocessorLexer.h b/include/clang/Lex/PreprocessorLexer.h index b551cd4..8a0b3cf 100644 --- a/include/clang/Lex/PreprocessorLexer.h +++ b/include/clang/Lex/PreprocessorLexer.h @@ -6,9 +6,10 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This file defines the PreprocessorLexer interface. -// +/// +/// \file +/// \brief Defines the PreprocessorLexer interface. +/// //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_PreprocessorLexer_H @@ -38,16 +39,17 @@ protected: // Context-specific lexing flags set by the preprocessor. //===--------------------------------------------------------------------===// - /// ParsingPreprocessorDirective - This is true when parsing #XXX. This turns - /// '\n' into a tok::eod token. + /// \brief True when parsing \#XXX; turns '\\n' into a tok::eod token. bool ParsingPreprocessorDirective; - /// ParsingFilename - True after #include: this turns <xx> into a - /// tok::angle_string_literal token. + /// \brief True after \#include; 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: + /// \brief True if in raw mode. + /// + /// Raw mode 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. /// 2. Identifier information is not looked up for identifier tokens. As an /// effect of this, implicit macro expansion is naturally disabled. @@ -59,11 +61,11 @@ 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 + /// \brief 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 + /// \brief Information about the set of \#if/\#ifdef/\#ifndef blocks /// we are currently in. SmallVector<PPConditionalInfo, 4> ConditionalStack; @@ -83,16 +85,15 @@ protected: virtual void IndirectLex(Token& Result) = 0; - /// getSourceLocation - Return the source location for the next observable - /// location. + /// \brief 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). + /// 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). void pushConditionalLevel(SourceLocation DirectiveStart, bool WasSkipping, bool FoundNonSkip, bool FoundElse) { PPConditionalInfo CI; @@ -116,8 +117,8 @@ protected: return false; } - /// peekConditionalLevel - Return the top of the conditional stack. This - /// requires that there be a conditional active. + /// \brief Return the top of the conditional stack. + /// \pre This requires that there be a conditional active. PPConditionalInfo &peekConditionalLevel() { assert(!ConditionalStack.empty() && "No conditionals active!"); return ConditionalStack.back(); @@ -130,21 +131,23 @@ 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 EOD token. + /// \brief 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 EOD token. void LexIncludeFilename(Token &Result); - /// setParsingPreprocessorDirective - Inform the lexer whether or not - /// we are currently lexing a preprocessor directive. + /// \brief 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. + /// \brief Return true if this lexer is in raw mode or not. bool isLexingRawMode() const { return LexingRawMode; } - /// getPP - Return the preprocessor object for this lexer. + /// \brief Return the preprocessor object for this lexer. Preprocessor *getPP() const { return PP; } FileID getFileID() const { @@ -163,7 +166,7 @@ public: const FileEntry *getFileEntry() const; /// \brief Iterator that traverses the current stack of preprocessor - /// conditional directives (#if/#ifdef/#ifndef). + /// conditional directives (\#if/\#ifdef/\#ifndef). typedef SmallVectorImpl<PPConditionalInfo>::const_iterator conditional_iterator; diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h index a88f607..9c5a023 100644 --- a/include/clang/Lex/Token.h +++ b/include/clang/Lex/Token.h @@ -87,7 +87,7 @@ public: bool is(tok::TokenKind K) const { return Kind == (unsigned) K; } bool isNot(tok::TokenKind K) const { return Kind != (unsigned) K; } - /// isAnyIdentifier - Return true if this is a raw identifier (when lexing + /// \brief Return true if this is a raw identifier (when lexing /// in raw mode) or a non-keyword identifier (when lexing in non-raw mode). bool isAnyIdentifier() const { return is(tok::identifier) || is(tok::raw_identifier); @@ -112,7 +112,7 @@ public: return false; } - /// getLocation - Return a source location identifier for the specified + /// \brief Return a source location identifier for the specified /// offset in the current file. SourceLocation getLocation() const { return Loc; } unsigned getLength() const { @@ -139,8 +139,8 @@ public: return isAnnotation() ? getAnnotationEndLoc() : getLocation(); } - /// getAnnotationRange - SourceRange of the group of tokens that this - /// annotation token represents. + /// \brief SourceRange of the group of tokens that this annotation token + /// represents. SourceRange getAnnotationRange() const { return SourceRange(getLocation(), getAnnotationEndLoc()); } @@ -153,8 +153,7 @@ public: return tok::getTokenName( (tok::TokenKind) Kind); } - /// startToken - Reset all flags to cleared. - /// + /// \brief Reset all flags to cleared. void startToken() { Kind = tok::unknown; Flags = 0; @@ -208,24 +207,25 @@ public: PtrData = val; } - /// setFlag - Set the specified flag. + /// \brief Set the specified flag. void setFlag(TokenFlags Flag) { Flags |= Flag; } - /// clearFlag - Unset the specified flag. + /// \brief 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. + /// \brief Return the internal represtation of the flags. + /// + /// This is only intended for low-level operations such as writing tokens to + /// disk. unsigned getFlags() const { return Flags; } - /// setFlagValue - Set a flag to either true or false. + /// \brief Set a flag to either true or false. void setFlagValue(TokenFlags Flag, bool Val) { if (Val) setFlag(Flag); @@ -237,25 +237,23 @@ public: /// bool isAtStartOfLine() const { return (Flags & StartOfLine) ? true : false; } - /// hasLeadingSpace - Return true if this token has whitespace before it. + /// \brief 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 + /// \brief 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. + /// \brief Return true if we have an ObjC keyword identifier. bool isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const; - /// getObjCKeywordID - Return the ObjC keyword kind. + /// \brief Return the ObjC keyword kind. tok::ObjCKeywordKind getObjCKeywordID() const; - /// needsCleaning - Return true if this token has trigraphs or escaped - /// newlines in it. - /// + /// \brief Return true if this token has trigraphs or escaped newlines in it. bool needsCleaning() const { return (Flags & NeedsCleaning) ? true : false; } /// \brief Return true if this token has an empty macro before it. @@ -269,23 +267,22 @@ public: bool hasUDSuffix() const { return (Flags & HasUDSuffix) ? true : false; } }; -/// PPConditionalInfo - Information about the conditional stack (#if directives) +/// \brief Information about the conditional stack (\#if directives) /// currently active. struct PPConditionalInfo { - /// IfLoc - Location where the conditional started. - /// + /// \brief Location where the conditional started. SourceLocation IfLoc; - /// WasSkipping - True if this was contained in a skipping directive, e.g. - /// in a "#if 0" block. + /// \brief 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. + /// \brief 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. + /// \brief True if we've seen a \#else in this block. If so, + /// \#elif/\#else directives are not allowed. bool FoundElse; }; |