]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Lex/MacroArgs.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r305575, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Lex / MacroArgs.h
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_LEX_MACROARGS_H
15 #define LLVM_CLANG_LEX_MACROARGS_H
16
17 #include "clang/Basic/LLVM.h"
18 #include "clang/Lex/Token.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include <vector>
21
22 namespace clang {
23   class MacroInfo;
24   class Preprocessor;
25   class SourceLocation;
26
27 /// MacroArgs - An instance of this class captures information about
28 /// the formal arguments specified to a function-like macro invocation.
29 class MacroArgs {
30   /// NumUnexpArgTokens - The number of raw, unexpanded tokens for the
31   /// arguments.  All of the actual argument tokens are allocated immediately
32   /// after the MacroArgs object in memory.  This is all of the arguments
33   /// concatenated together, with 'EOF' markers at the end of each argument.
34   unsigned NumUnexpArgTokens;
35
36   /// VarargsElided - True if this is a C99 style varargs macro invocation and
37   /// there was no argument specified for the "..." argument.  If the argument
38   /// was specified (even empty) or this isn't a C99 style varargs function, or
39   /// if in strict mode and the C99 varargs macro had only a ... argument, this
40   /// is false.
41   bool VarargsElided;
42   
43   /// PreExpArgTokens - Pre-expanded tokens for arguments that need them.  Empty
44   /// if not yet computed.  This includes the EOF marker at the end of the
45   /// stream.
46   std::vector<std::vector<Token> > PreExpArgTokens;
47
48   /// StringifiedArgs - This contains arguments in 'stringified' form.  If the
49   /// stringified form of an argument has not yet been computed, this is empty.
50   std::vector<Token> StringifiedArgs;
51
52   /// ArgCache - This is a linked list of MacroArgs objects that the
53   /// Preprocessor owns which we use to avoid thrashing malloc/free.
54   MacroArgs *ArgCache;
55
56   /// MacroArgs - The number of arguments the invoked macro expects.
57   unsigned NumMacroArgs;
58
59   MacroArgs(unsigned NumToks, bool varargsElided, unsigned MacroArgs)
60       : NumUnexpArgTokens(NumToks), VarargsElided(varargsElided),
61         ArgCache(nullptr), NumMacroArgs(MacroArgs) {}
62   ~MacroArgs() = default;
63
64 public:
65   /// MacroArgs ctor function - Create a new MacroArgs object with the specified
66   /// macro and argument info.
67   static MacroArgs *create(const MacroInfo *MI,
68                            ArrayRef<Token> UnexpArgTokens,
69                            bool VarargsElided, Preprocessor &PP);
70
71   /// destroy - Destroy and deallocate the memory for this object.
72   ///
73   void destroy(Preprocessor &PP);
74
75   /// ArgNeedsPreexpansion - If we can prove that the argument won't be affected
76   /// by pre-expansion, return false.  Otherwise, conservatively return true.
77   bool ArgNeedsPreexpansion(const Token *ArgTok, Preprocessor &PP) const;
78
79   /// getUnexpArgument - Return a pointer to the first token of the unexpanded
80   /// token list for the specified formal.
81   ///
82   const Token *getUnexpArgument(unsigned Arg) const;
83
84   /// getArgLength - Given a pointer to an expanded or unexpanded argument,
85   /// return the number of tokens, not counting the EOF, that make up the
86   /// argument.
87   static unsigned getArgLength(const Token *ArgPtr);
88
89   /// getPreExpArgument - Return the pre-expanded form of the specified
90   /// argument.
91   const std::vector<Token> &
92     getPreExpArgument(unsigned Arg, const MacroInfo *MI, Preprocessor &PP);
93
94   /// getStringifiedArgument - Compute, cache, and return the specified argument
95   /// that has been 'stringified' as required by the # operator.
96   const Token &getStringifiedArgument(unsigned ArgNo, Preprocessor &PP,
97                                       SourceLocation ExpansionLocStart,
98                                       SourceLocation ExpansionLocEnd);
99
100   /// getNumMacroArguments - Return the number of arguments the invoked macro
101   /// expects.
102   unsigned getNumMacroArguments() const { return NumMacroArgs; }
103
104   /// isVarargsElidedUse - Return true if this is a C99 style varargs macro
105   /// invocation and there was no argument specified for the "..." argument.  If
106   /// the argument was specified (even empty) or this isn't a C99 style varargs
107   /// function, or if in strict mode and the C99 varargs macro had only a ...
108   /// argument, this returns false.
109   bool isVarargsElidedUse() const { return VarargsElided; }
110
111   /// StringifyArgument - Implement C99 6.10.3.2p2, converting a sequence of
112   /// tokens into the literal string token that should be produced by the C #
113   /// preprocessor operator.  If Charify is true, then it should be turned into
114   /// a character literal for the Microsoft charize (#@) extension.
115   ///
116   static Token StringifyArgument(const Token *ArgToks,
117                                  Preprocessor &PP, bool Charify,
118                                  SourceLocation ExpansionLocStart,
119                                  SourceLocation ExpansionLocEnd);
120   
121   
122   /// deallocate - This should only be called by the Preprocessor when managing
123   /// its freelist.
124   MacroArgs *deallocate();
125 };
126
127 }  // end namespace clang
128
129 #endif