Deleted Added
full compact
MacroArgs.cpp (198092) MacroArgs.cpp (200583)
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,
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) {
23 unsigned NumToks, bool VarargsElided,
24 Preprocessor &PP) {
24 assert(MI->isFunctionLike() &&
25 "Can't have args for an object-like macro!");
26
27 // Allocate memory for the MacroArgs object with the lexer tokens at the end.
28 MacroArgs *Result = (MacroArgs*)malloc(sizeof(MacroArgs) +
29 NumToks*sizeof(Token));
30 // Construct the macroargs object.
31 new (Result) MacroArgs(NumToks, VarargsElided);
32
33 // Copy the actual unexpanded tokens to immediately after the result ptr.
34 if (NumToks)
35 memcpy(const_cast<Token*>(Result->getUnexpArgument(0)),
36 UnexpArgTokens, NumToks*sizeof(Token));
37
38 return Result;
39}
40
41/// destroy - Destroy and deallocate the memory for this object.
42///
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///
43void MacroArgs::destroy() {
44void MacroArgs::destroy(Preprocessor &PP) {
44 // Run the dtor to deallocate the vectors.
45 this->~MacroArgs();
46 // Release the memory for the object.
47 free(this);
48}
49
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}
50
63
64
51/// getArgLength - Given a pointer to an expanded or unexpanded argument,
52/// return the number of tokens, not counting the EOF, that make up the
53/// argument.
54unsigned MacroArgs::getArgLength(const Token *ArgPtr) {
55 unsigned NumArgTokens = 0;
56 for (; ArgPtr->isNot(tok::eof); ++ArgPtr)
57 ++NumArgTokens;
58 return NumArgTokens;

--- 182 unchanged lines hidden ---
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 ---