zcov: / lib/Lex/MacroArgs.h


Files: 1 Branches Taken: 0.0% 0 / 0
Generated: 2010-02-10 01:31 Branches Executed: 0.0% 0 / 0
Line Coverage: 100.0% 5 / 5


Programs: 4 Runs 6036


       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                 :   /// 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
      37                 :   /// is false.
      38                 :   bool VarargsElided;
      39                 :   
      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
      42                 :   /// stream.
      43                 :   std::vector<std::vector<Token> > PreExpArgTokens;
      44                 : 
      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;
      48                 : 
      49                 :   /// ArgCache - This is a linked list of MacroArgs objects that the
      50                 :   /// Preprocessor owns which we use to avoid thrashing malloc/free.
      51                 :   MacroArgs *ArgCache;
      52                 :   
      53              630:   MacroArgs(unsigned NumToks, bool varargsElided)
      54              630:     : NumUnexpArgTokens(NumToks), VarargsElided(varargsElided), ArgCache(0) {}
      55              630:   ~MacroArgs() {}
      56                 : public:
      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,
      62                 :                            Preprocessor &PP);
      63                 : 
      64                 :   /// destroy - Destroy and deallocate the memory for this object.
      65                 :   ///
      66                 :   void destroy(Preprocessor &PP);
      67                 : 
      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;
      71                 : 
      72                 :   /// getUnexpArgument - Return a pointer to the first token of the unexpanded
      73                 :   /// token list for the specified formal.
      74                 :   ///
      75                 :   const Token *getUnexpArgument(unsigned Arg) const;
      76                 : 
      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
      79                 :   /// argument.
      80                 :   static unsigned getArgLength(const Token *ArgPtr);
      81                 : 
      82                 :   /// getPreExpArgument - Return the pre-expanded form of the specified
      83                 :   /// argument.
      84                 :   const std::vector<Token> &
      85                 :     getPreExpArgument(unsigned Arg, const MacroInfo *MI, Preprocessor &PP);
      86                 : 
      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);
      90                 : 
      91                 :   /// getNumArguments - Return the number of arguments passed into this macro
      92                 :   /// invocation.
      93              454:   unsigned getNumArguments() const { return NumUnexpArgTokens; }
      94                 : 
      95                 : 
      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               40:   bool isVarargsElidedUse() const { return VarargsElided; }
     102                 : 
     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.
     107                 :   ///
     108                 :   static Token StringifyArgument(const Token *ArgToks,
     109                 :                                  Preprocessor &PP, bool Charify = false);
     110                 :   
     111                 :   
     112                 :   /// deallocate - This should only be called by the Preprocessor when managing
     113                 :   /// its freelist.
     114                 :   MacroArgs *deallocate();
     115                 : };
     116                 : 
     117                 : }  // end namespace clang
     118                 : 
     119                 : #endif

Generated: 2010-02-10 01:31 by zcov