1 //===--- MacroArgs.h - Formal argument info for Macros ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the MacroArgs interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_MACROARGS_H
15 #define LLVM_CLANG_MACROARGS_H
24 /// MacroArgs - An instance of this class captures information about
25 /// the formal arguments specified to a function-like macro invocation.
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;
33 /// VarargsElided - True if this is a C99 style varargs macro invocation and
34 /// there was no argument specified for the "..." argument. If the argument
35 /// was specified (even empty) or this isn't a C99 style varargs function, or
36 /// if in strict mode and the C99 varargs macro had only a ... argument, this
40 /// PreExpArgTokens - Pre-expanded tokens for arguments that need them. Empty
41 /// if not yet computed. This includes the EOF marker at the end of the
43 std::vector<std::vector<Token> > PreExpArgTokens;
45 /// StringifiedArgs - This contains arguments in 'stringified' form. If the
46 /// stringified form of an argument has not yet been computed, this is empty.
47 std::vector<Token> StringifiedArgs;
49 /// ArgCache - This is a linked list of MacroArgs objects that the
50 /// Preprocessor owns which we use to avoid thrashing malloc/free.
53 MacroArgs(unsigned NumToks, bool varargsElided)
54 : NumUnexpArgTokens(NumToks), VarargsElided(varargsElided), ArgCache(0) {}
57 /// MacroArgs ctor function - Create a new MacroArgs object with the specified
58 /// macro and argument info.
59 static MacroArgs *create(const MacroInfo *MI,
60 const Token *UnexpArgTokens,
61 unsigned NumArgTokens, bool VarargsElided,
64 /// destroy - Destroy and deallocate the memory for this object.
66 void destroy(Preprocessor &PP);
68 /// ArgNeedsPreexpansion - If we can prove that the argument won't be affected
69 /// by pre-expansion, return false. Otherwise, conservatively return true.
70 bool ArgNeedsPreexpansion(const Token *ArgTok, Preprocessor &PP) const;
72 /// getUnexpArgument - Return a pointer to the first token of the unexpanded
73 /// token list for the specified formal.
75 const Token *getUnexpArgument(unsigned Arg) const;
77 /// getArgLength - Given a pointer to an expanded or unexpanded argument,
78 /// return the number of tokens, not counting the EOF, that make up the
80 static unsigned getArgLength(const Token *ArgPtr);
82 /// getPreExpArgument - Return the pre-expanded form of the specified
84 const std::vector<Token> &
85 getPreExpArgument(unsigned Arg, const MacroInfo *MI, Preprocessor &PP);
87 /// getStringifiedArgument - Compute, cache, and return the specified argument
88 /// that has been 'stringified' as required by the # operator.
89 const Token &getStringifiedArgument(unsigned ArgNo, Preprocessor &PP);
91 /// getNumArguments - Return the number of arguments passed into this macro
93 unsigned getNumArguments() const { return NumUnexpArgTokens; }
96 /// isVarargsElidedUse - Return true if this is a C99 style varargs macro
97 /// invocation and there was no argument specified for the "..." argument. If
98 /// the argument was specified (even empty) or this isn't a C99 style varargs
99 /// function, or if in strict mode and the C99 varargs macro had only a ...
100 /// argument, this returns false.
101 bool isVarargsElidedUse() const { return VarargsElided; }
103 /// StringifyArgument - Implement C99 6.10.3.2p2, converting a sequence of
104 /// tokens into the literal string token that should be produced by the C #
105 /// preprocessor operator. If Charify is true, then it should be turned into
106 /// a character literal for the Microsoft charize (#@) extension.
108 static Token StringifyArgument(const Token *ArgToks,
109 Preprocessor &PP, bool Charify = false);
112 /// deallocate - This should only be called by the Preprocessor when managing
114 MacroArgs *deallocate();
117 } // end namespace clang