Deleted Added
sdiff udiff text old ( 198092 ) new ( 200583 )
full compact
1//===--- TokenLexer.cpp - Lex from a token stream -------------------------===//
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//===----------------------------------------------------------------------===//

--- 6 unchanged lines hidden (view full) ---

15#include "clang/Lex/MacroInfo.h"
16#include "clang/Lex/Preprocessor.h"
17#include "clang/Lex/LexDiagnostic.h"
18using namespace clang;
19
20/// MacroArgs ctor function - This destroys the vector passed in.
21MacroArgs *MacroArgs::create(const MacroInfo *MI,
22 const Token *UnexpArgTokens,
23 unsigned NumToks, bool VarargsElided,
24 Preprocessor &PP) {
25 assert(MI->isFunctionLike() &&
26 "Can't have args for an object-like macro!");
27
28 // Allocate memory for the MacroArgs object with the lexer tokens at the end.
29 MacroArgs *Result = (MacroArgs*)malloc(sizeof(MacroArgs) +
30 NumToks*sizeof(Token));
31 // Construct the macroargs object.
32 new (Result) MacroArgs(NumToks, VarargsElided);
33
34 // Copy the actual unexpanded tokens to immediately after the result ptr.
35 if (NumToks)
36 memcpy(const_cast<Token*>(Result->getUnexpArgument(0)),
37 UnexpArgTokens, NumToks*sizeof(Token));
38
39 return Result;
40}
41
42/// destroy - Destroy and deallocate the memory for this object.
43///
44void MacroArgs::destroy(Preprocessor &PP) {
45 // Run the dtor to deallocate the vectors.
46 this->~MacroArgs();
47 // Release the memory for the object.
48 free(this);
49}
50
51/// deallocate - This should only be called by the Preprocessor when managing
52/// its freelist.
53MacroArgs *MacroArgs::deallocate() {
54 MacroArgs *Next = ArgCache;
55
56 // Run the dtor to deallocate the vectors.
57 this->~MacroArgs();
58 // Release the memory for the object.
59 free(this);
60
61 return Next;
62}
63
64
65/// getArgLength - Given a pointer to an expanded or unexpanded argument,
66/// return the number of tokens, not counting the EOF, that make up the
67/// argument.
68unsigned MacroArgs::getArgLength(const Token *ArgPtr) {
69 unsigned NumArgTokens = 0;
70 for (; ArgPtr->isNot(tok::eof); ++ArgPtr)
71 ++NumArgTokens;
72 return NumArgTokens;

--- 182 unchanged lines hidden ---