Chris Lattner | 568ec6b | 2008-03-09 02:55:12 +0000 | [diff] [blame] | 1 | //===--- MacroArgs.h - Formal argument info for Macros ----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the MacroArgs interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_MACROARGS_H |
| 15 | #define LLVM_CLANG_MACROARGS_H |
| 16 | |
| 17 | #include <vector> |
| 18 | |
| 19 | namespace clang { |
| 20 | class MacroInfo; |
| 21 | class Preprocessor; |
| 22 | class Token; |
| 23 | |
| 24 | /// MacroArgs - An instance of this class captures information about |
| 25 | /// the formal arguments specified to a function-like macro invocation. |
| 26 | class MacroArgs { |
| 27 | /// NumUnexpArgTokens - The number of raw, unexpanded tokens for the |
| 28 | /// arguments. All of the actual argument tokens are allocated immediately |
| 29 | /// after the MacroArgs object in memory. This is all of the arguments |
| 30 | /// concatenated together, with 'EOF' markers at the end of each argument. |
| 31 | unsigned NumUnexpArgTokens; |
| 32 | |
| 33 | /// PreExpArgTokens - Pre-expanded tokens for arguments that need them. Empty |
| 34 | /// if not yet computed. This includes the EOF marker at the end of the |
| 35 | /// stream. |
| 36 | std::vector<std::vector<Token> > PreExpArgTokens; |
| 37 | |
| 38 | /// StringifiedArgs - This contains arguments in 'stringified' form. If the |
| 39 | /// stringified form of an argument has not yet been computed, this is empty. |
| 40 | std::vector<Token> StringifiedArgs; |
| 41 | |
| 42 | /// VarargsElided - True if this is a C99 style varargs macro invocation and |
| 43 | /// there was no argument specified for the "..." argument. If the argument |
| 44 | /// was specified (even empty) or this isn't a C99 style varargs function, or |
| 45 | /// if in strict mode and the C99 varargs macro had only a ... argument, this |
| 46 | /// is false. |
| 47 | bool VarargsElided; |
| 48 | |
| 49 | MacroArgs(unsigned NumToks, bool varargsElided) |
| 50 | : NumUnexpArgTokens(NumToks), VarargsElided(varargsElided) {} |
| 51 | ~MacroArgs() {} |
| 52 | public: |
| 53 | /// MacroArgs ctor function - Create a new MacroArgs object with the specified |
| 54 | /// macro and argument info. |
| 55 | static MacroArgs *create(const MacroInfo *MI, |
| 56 | const Token *UnexpArgTokens, |
| 57 | unsigned NumArgTokens, bool VarargsElided); |
| 58 | |
| 59 | /// destroy - Destroy and deallocate the memory for this object. |
| 60 | /// |
| 61 | void destroy(); |
| 62 | |
| 63 | /// ArgNeedsPreexpansion - If we can prove that the argument won't be affected |
| 64 | /// by pre-expansion, return false. Otherwise, conservatively return true. |
| 65 | bool ArgNeedsPreexpansion(const Token *ArgTok, Preprocessor &PP) const; |
| 66 | |
| 67 | /// getUnexpArgument - Return a pointer to the first token of the unexpanded |
| 68 | /// token list for the specified formal. |
| 69 | /// |
| 70 | const Token *getUnexpArgument(unsigned Arg) const; |
| 71 | |
| 72 | /// getArgLength - Given a pointer to an expanded or unexpanded argument, |
| 73 | /// return the number of tokens, not counting the EOF, that make up the |
| 74 | /// argument. |
| 75 | static unsigned getArgLength(const Token *ArgPtr); |
| 76 | |
| 77 | /// getPreExpArgument - Return the pre-expanded form of the specified |
| 78 | /// argument. |
| 79 | const std::vector<Token> & |
| 80 | getPreExpArgument(unsigned Arg, Preprocessor &PP); |
| 81 | |
| 82 | /// getStringifiedArgument - Compute, cache, and return the specified argument |
| 83 | /// that has been 'stringified' as required by the # operator. |
| 84 | const Token &getStringifiedArgument(unsigned ArgNo, Preprocessor &PP); |
| 85 | |
| 86 | /// getNumArguments - Return the number of arguments passed into this macro |
| 87 | /// invocation. |
| 88 | unsigned getNumArguments() const { return NumUnexpArgTokens; } |
| 89 | |
| 90 | |
| 91 | /// isVarargsElidedUse - Return true if this is a C99 style varargs macro |
| 92 | /// invocation and there was no argument specified for the "..." argument. If |
| 93 | /// the argument was specified (even empty) or this isn't a C99 style varargs |
| 94 | /// function, or if in strict mode and the C99 varargs macro had only a ... |
| 95 | /// argument, this returns false. |
| 96 | bool isVarargsElidedUse() const { return VarargsElided; } |
| 97 | |
| 98 | /// StringifyArgument - Implement C99 6.10.3.2p2, converting a sequence of |
| 99 | /// tokens into the literal string token that should be produced by the C # |
| 100 | /// preprocessor operator. If Charify is true, then it should be turned into |
| 101 | /// a character literal for the Microsoft charize (#@) extension. |
| 102 | /// |
| 103 | static Token StringifyArgument(const Token *ArgToks, |
| 104 | Preprocessor &PP, bool Charify = false); |
| 105 | }; |
| 106 | |
| 107 | } // end namespace clang |
| 108 | |
| 109 | #endif |