diff options
author | Faisal Vali <faisalv@yahoo.com> | 2017-07-17 01:27:53 +0000 |
---|---|---|
committer | Faisal Vali <faisalv@yahoo.com> | 2017-07-17 01:27:53 +0000 |
commit | fc60afa41c22bbd3cde2075d5ade4f8698e99243 (patch) | |
tree | d313291c5fb4eb3cf458bff6887e01ebe48c5b70 /include | |
parent | 80beb506ac01d2360fffdb66f1195720c267cb8a (diff) |
[NFC] Refactor the Preprocessor function that handles Macro definitions and rename Arguments to Parameters in Macro Definitions.
- Extracted the reading of the tokens out into a separate function.
- Replace 'Argument' with 'Parameter' when referring to the identifiers of the macro definition (as opposed to the supplied arguments - MacroArgs - during the macro invocation).
This is in preparation for submitting patches for review to implement __VA_OPT__ which will otherwise just keep lengthening the HandleDefineDirective function and making it less comprehensible.
Thanks!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@308157 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/Lex/MacroInfo.h | 50 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 19 |
2 files changed, 41 insertions, 28 deletions
diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h index 7da1e7b41a..d25431b55f 100644 --- a/include/clang/Lex/MacroInfo.h +++ b/include/clang/Lex/MacroInfo.h @@ -42,14 +42,14 @@ class MacroInfo { /// \brief The list of arguments for a function-like macro. /// - /// ArgumentList points to the first of NumArguments pointers. + /// ParameterList points to the first of NumParameters pointers. /// /// This can be empty, for, e.g. "#define X()". In a C99-style variadic /// macro, this includes the \c __VA_ARGS__ identifier on the list. - IdentifierInfo **ArgumentList; + IdentifierInfo **ParameterList; - /// \see ArgumentList - unsigned NumArguments; + /// \see ParameterList + unsigned NumParameters; /// \brief This is the list of tokens that the macro is defined to. SmallVector<Token, 8> ReplacementTokens; @@ -153,37 +153,37 @@ public: /// \brief Set the value of the IsWarnIfUnused flag. void setIsWarnIfUnused(bool val) { IsWarnIfUnused = val; } - /// \brief Set the specified list of identifiers as the argument list for + /// \brief Set the specified list of identifiers as the parameter list for /// this macro. - void setArgumentList(ArrayRef<IdentifierInfo *> List, + void setParameterList(ArrayRef<IdentifierInfo *> List, llvm::BumpPtrAllocator &PPAllocator) { - assert(ArgumentList == nullptr && NumArguments == 0 && - "Argument list already set!"); + assert(ParameterList == nullptr && NumParameters == 0 && + "Parameter list already set!"); if (List.empty()) return; - NumArguments = List.size(); - ArgumentList = PPAllocator.Allocate<IdentifierInfo *>(List.size()); - std::copy(List.begin(), List.end(), ArgumentList); + NumParameters = List.size(); + ParameterList = PPAllocator.Allocate<IdentifierInfo *>(List.size()); + std::copy(List.begin(), List.end(), ParameterList); } - /// Arguments - The list of arguments for a function-like macro. This can be - /// empty, for, e.g. "#define X()". - typedef IdentifierInfo *const *arg_iterator; - bool arg_empty() const { return NumArguments == 0; } - arg_iterator arg_begin() const { return ArgumentList; } - arg_iterator arg_end() const { return ArgumentList + NumArguments; } - unsigned getNumArgs() const { return NumArguments; } - ArrayRef<const IdentifierInfo *> args() const { - return ArrayRef<const IdentifierInfo *>(ArgumentList, NumArguments); + /// Parameters - The list of parameters for a function-like macro. This can + /// be empty, for, e.g. "#define X()". + typedef IdentifierInfo *const *param_iterator; + bool param_empty() const { return NumParameters == 0; } + param_iterator param_begin() const { return ParameterList; } + param_iterator param_end() const { return ParameterList + NumParameters; } + unsigned getNumParams() const { return NumParameters; } + ArrayRef<const IdentifierInfo *> params() const { + return ArrayRef<const IdentifierInfo *>(ParameterList, NumParameters); } - /// \brief Return the argument number of the specified identifier, - /// or -1 if the identifier is not a formal argument identifier. - int getArgumentNum(const IdentifierInfo *Arg) const { - for (arg_iterator I = arg_begin(), E = arg_end(); I != E; ++I) + /// \brief Return the parameter number of the specified identifier, + /// or -1 if the identifier is not a formal parameter identifier. + int getParameterNum(const IdentifierInfo *Arg) const { + for (param_iterator I = param_begin(), E = param_end(); I != E; ++I) if (*I == Arg) - return I - arg_begin(); + return I - param_begin(); return -1; } diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 62090d6496..a058fbfbb4 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -1813,11 +1813,24 @@ private: void ReadMacroName(Token &MacroNameTok, MacroUse IsDefineUndef = MU_Other, bool *ShadowFlag = nullptr); + /// ReadOptionalMacroParameterListAndBody - This consumes all (i.e. the + /// entire line) of the macro's tokens and adds them to MacroInfo, and while + /// doing so performs certain validity checks including (but not limited to): + /// - # (stringization) is followed by a macro parameter + /// \param MacroNameTok - Token that represents the macro name + /// \param ImmediatelyAfterHeaderGuard - Macro follows an #ifdef header guard + /// + /// Either returns a pointer to a MacroInfo object OR emits a diagnostic and + /// returns a nullptr if an invalid sequence of tokens is encountered. + + MacroInfo *ReadOptionalMacroParameterListAndBody( + const Token &MacroNameTok, bool ImmediatelyAfterHeaderGuard); + /// The ( starting an argument list of a macro definition has just been read. - /// Lex the rest of the arguments and the closing ), updating \p MI with + /// Lex the rest of the parameters and the closing ), updating \p MI with /// what we learn and saving in \p LastTok the last token read. /// Return true if an error occurs parsing the arg list. - bool ReadMacroDefinitionArgList(MacroInfo *MI, Token& LastTok); + bool ReadMacroParameterList(MacroInfo *MI, Token& LastTok); /// We just read a \#if or related directive and decided that the /// subsequent tokens are in the \#if'd out portion of the @@ -1878,7 +1891,7 @@ private: /// After reading "MACRO(", this method is invoked to read all of the formal /// arguments specified for the macro invocation. Returns null on error. - MacroArgs *ReadFunctionLikeMacroArgs(Token &MacroName, MacroInfo *MI, + MacroArgs *ReadMacroCallArgumentList(Token &MacroName, MacroInfo *MI, SourceLocation &ExpansionEnd); /// \brief If an identifier token is read that is to be expanded |