2008-03-09 10:55:12 +08:00
|
|
|
//===--- MacroArgs.h - Formal argument info for Macros ----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the MacroArgs interface.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_MACROARGS_H
|
|
|
|
#define LLVM_CLANG_MACROARGS_H
|
|
|
|
|
2011-09-22 10:03:12 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class MacroInfo;
|
|
|
|
class Preprocessor;
|
|
|
|
class Token;
|
2011-07-07 11:40:34 +08:00
|
|
|
class SourceLocation;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// MacroArgs - An instance of this class captures information about
|
|
|
|
/// the formal arguments specified to a function-like macro invocation.
|
|
|
|
class MacroArgs {
|
|
|
|
/// NumUnexpArgTokens - The number of raw, unexpanded tokens for the
|
|
|
|
/// arguments. All of the actual argument tokens are allocated immediately
|
|
|
|
/// after the MacroArgs object in memory. This is all of the arguments
|
|
|
|
/// concatenated together, with 'EOF' markers at the end of each argument.
|
|
|
|
unsigned NumUnexpArgTokens;
|
|
|
|
|
2009-12-15 06:12:52 +08:00
|
|
|
/// VarargsElided - True if this is a C99 style varargs macro invocation and
|
|
|
|
/// there was no argument specified for the "..." argument. If the argument
|
|
|
|
/// was specified (even empty) or this isn't a C99 style varargs function, or
|
|
|
|
/// if in strict mode and the C99 varargs macro had only a ... argument, this
|
|
|
|
/// is false.
|
|
|
|
bool VarargsElided;
|
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// PreExpArgTokens - Pre-expanded tokens for arguments that need them. Empty
|
|
|
|
/// if not yet computed. This includes the EOF marker at the end of the
|
|
|
|
/// stream.
|
|
|
|
std::vector<std::vector<Token> > PreExpArgTokens;
|
|
|
|
|
|
|
|
/// StringifiedArgs - This contains arguments in 'stringified' form. If the
|
|
|
|
/// stringified form of an argument has not yet been computed, this is empty.
|
|
|
|
std::vector<Token> StringifiedArgs;
|
|
|
|
|
2009-12-15 09:51:03 +08:00
|
|
|
/// ArgCache - This is a linked list of MacroArgs objects that the
|
|
|
|
/// Preprocessor owns which we use to avoid thrashing malloc/free.
|
|
|
|
MacroArgs *ArgCache;
|
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
MacroArgs(unsigned NumToks, bool varargsElided)
|
2009-12-15 09:51:03 +08:00
|
|
|
: NumUnexpArgTokens(NumToks), VarargsElided(varargsElided), ArgCache(0) {}
|
2008-03-09 10:55:12 +08:00
|
|
|
~MacroArgs() {}
|
|
|
|
public:
|
|
|
|
/// MacroArgs ctor function - Create a new MacroArgs object with the specified
|
|
|
|
/// macro and argument info.
|
|
|
|
static MacroArgs *create(const MacroInfo *MI,
|
2011-09-22 10:03:12 +08:00
|
|
|
llvm::ArrayRef<Token> UnexpArgTokens,
|
|
|
|
bool VarargsElided, Preprocessor &PP);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// destroy - Destroy and deallocate the memory for this object.
|
|
|
|
///
|
2009-12-15 06:12:52 +08:00
|
|
|
void destroy(Preprocessor &PP);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// ArgNeedsPreexpansion - If we can prove that the argument won't be affected
|
|
|
|
/// by pre-expansion, return false. Otherwise, conservatively return true.
|
|
|
|
bool ArgNeedsPreexpansion(const Token *ArgTok, Preprocessor &PP) const;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// getUnexpArgument - Return a pointer to the first token of the unexpanded
|
|
|
|
/// token list for the specified formal.
|
|
|
|
///
|
|
|
|
const Token *getUnexpArgument(unsigned Arg) const;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// getArgLength - Given a pointer to an expanded or unexpanded argument,
|
|
|
|
/// return the number of tokens, not counting the EOF, that make up the
|
|
|
|
/// argument.
|
|
|
|
static unsigned getArgLength(const Token *ArgPtr);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// getPreExpArgument - Return the pre-expanded form of the specified
|
|
|
|
/// argument.
|
|
|
|
const std::vector<Token> &
|
2009-12-28 14:17:16 +08:00
|
|
|
getPreExpArgument(unsigned Arg, const MacroInfo *MI, Preprocessor &PP);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// getStringifiedArgument - Compute, cache, and return the specified argument
|
|
|
|
/// that has been 'stringified' as required by the # operator.
|
2011-07-07 11:40:34 +08:00
|
|
|
const Token &getStringifiedArgument(unsigned ArgNo, Preprocessor &PP,
|
|
|
|
SourceLocation hashInstLoc);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// getNumArguments - Return the number of arguments passed into this macro
|
|
|
|
/// invocation.
|
|
|
|
unsigned getNumArguments() const { return NumUnexpArgTokens; }
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// isVarargsElidedUse - Return true if this is a C99 style varargs macro
|
|
|
|
/// invocation and there was no argument specified for the "..." argument. If
|
|
|
|
/// the argument was specified (even empty) or this isn't a C99 style varargs
|
|
|
|
/// function, or if in strict mode and the C99 varargs macro had only a ...
|
|
|
|
/// argument, this returns false.
|
|
|
|
bool isVarargsElidedUse() const { return VarargsElided; }
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2008-03-09 10:55:12 +08:00
|
|
|
/// StringifyArgument - Implement C99 6.10.3.2p2, converting a sequence of
|
|
|
|
/// tokens into the literal string token that should be produced by the C #
|
|
|
|
/// preprocessor operator. If Charify is true, then it should be turned into
|
|
|
|
/// a character literal for the Microsoft charize (#@) extension.
|
|
|
|
///
|
|
|
|
static Token StringifyArgument(const Token *ArgToks,
|
2011-07-07 11:40:34 +08:00
|
|
|
Preprocessor &PP, bool Charify,
|
|
|
|
SourceLocation hashInstLoc);
|
2009-12-15 09:51:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// deallocate - This should only be called by the Preprocessor when managing
|
|
|
|
/// its freelist.
|
|
|
|
MacroArgs *deallocate();
|
2008-03-09 10:55:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|