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
25 /// MacroArgs - An instance of this class captures information about
26 /// the formal arguments specified to a function-like macro invocation.
28 /// NumUnexpArgTokens - The number of raw, unexpanded tokens for the
29 /// arguments. All of the actual argument tokens are allocated immediately
30 /// after the MacroArgs object in memory. This is all of the arguments
31 /// concatenated together, with 'EOF' markers at the end of each argument.
32 unsigned NumUnexpArgTokens;
34 /// VarargsElided - True if this is a C99 style varargs macro invocation and
35 /// there was no argument specified for the "..." argument. If the argument
36 /// was specified (even empty) or this isn't a C99 style varargs function, or
37 /// if in strict mode and the C99 varargs macro had only a ... argument, this
41 /// PreExpArgTokens - Pre-expanded tokens for arguments that need them. Empty
42 /// if not yet computed. This includes the EOF marker at the end of the
44 std::vector<std::vector<Token> > PreExpArgTokens;
46 /// StringifiedArgs - This contains arguments in 'stringified' form. If the
47 /// stringified form of an argument has not yet been computed, this is empty.
48 std::vector<Token> StringifiedArgs;
50 /// ArgCache - This is a linked list of MacroArgs objects that the
51 /// Preprocessor owns which we use to avoid thrashing malloc/free.
54 MacroArgs(unsigned NumToks, bool varargsElided)
55 : NumUnexpArgTokens(NumToks), VarargsElided(varargsElided), ArgCache(0) {}
58 /// MacroArgs ctor function - Create a new MacroArgs object with the specified
59 /// macro and argument info.
60 static MacroArgs *create(const MacroInfo *MI,
61 const Token *UnexpArgTokens,
62 unsigned NumArgTokens, bool VarargsElided,
65 /// destroy - Destroy and deallocate the memory for this object.
67 void destroy(Preprocessor &PP);
69 /// ArgNeedsPreexpansion - If we can prove that the argument won't be affected
70 /// by pre-expansion, return false. Otherwise, conservatively return true.
71 bool ArgNeedsPreexpansion(const Token *ArgTok, Preprocessor &PP) const;
73 /// getUnexpArgument - Return a pointer to the first token of the unexpanded
74 /// token list for the specified formal.
76 const Token *getUnexpArgument(unsigned Arg) const;
78 /// getArgLength - Given a pointer to an expanded or unexpanded argument,
79 /// return the number of tokens, not counting the EOF, that make up the
81 static unsigned getArgLength(const Token *ArgPtr);
83 /// getPreExpArgument - Return the pre-expanded form of the specified
85 const std::vector<Token> &
86 getPreExpArgument(unsigned Arg, const MacroInfo *MI, Preprocessor &PP);
88 /// getStringifiedArgument - Compute, cache, and return the specified argument
89 /// that has been 'stringified' as required by the # operator.
90 const Token &getStringifiedArgument(unsigned ArgNo, Preprocessor &PP,
91 SourceLocation hashInstLoc);
93 /// getNumArguments - Return the number of arguments passed into this macro
95 unsigned getNumArguments() const { return NumUnexpArgTokens; }
98 /// isVarargsElidedUse - Return true if this is a C99 style varargs macro
99 /// invocation and there was no argument specified for the "..." argument. If
100 /// the argument was specified (even empty) or this isn't a C99 style varargs
101 /// function, or if in strict mode and the C99 varargs macro had only a ...
102 /// argument, this returns false.
103 bool isVarargsElidedUse() const { return VarargsElided; }
105 /// StringifyArgument - Implement C99 6.10.3.2p2, converting a sequence of
106 /// tokens into the literal string token that should be produced by the C #
107 /// preprocessor operator. If Charify is true, then it should be turned into
108 /// a character literal for the Microsoft charize (#@) extension.
110 static Token StringifyArgument(const Token *ArgToks,
111 Preprocessor &PP, bool Charify,
112 SourceLocation hashInstLoc);
115 /// deallocate - This should only be called by the Preprocessor when managing
117 MacroArgs *deallocate();
120 } // end namespace clang