1 //===--- MacroInfo.cpp - Information about #defined identifiers -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the MacroInfo interface.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Lex/MacroInfo.h"
15 #include "clang/Lex/Preprocessor.h"
16 using namespace clang
;
18 MacroInfo::MacroInfo(SourceLocation DefLoc
) : Location(DefLoc
) {
19 IsFunctionLike
= false;
22 IsBuiltinMacro
= false;
26 IsAllowRedefinitionsWithoutWarning
= false;
27 IsWarnIfUnused
= false;
33 MacroInfo::MacroInfo(const MacroInfo
&MI
, llvm::BumpPtrAllocator
&PPAllocator
) {
34 Location
= MI
.Location
;
35 EndLocation
= MI
.EndLocation
;
36 ReplacementTokens
= MI
.ReplacementTokens
;
37 IsFunctionLike
= MI
.IsFunctionLike
;
38 IsC99Varargs
= MI
.IsC99Varargs
;
39 IsGNUVarargs
= MI
.IsGNUVarargs
;
40 IsBuiltinMacro
= MI
.IsBuiltinMacro
;
41 IsFromAST
= MI
.IsFromAST
;
42 IsDisabled
= MI
.IsDisabled
;
44 IsAllowRedefinitionsWithoutWarning
= MI
.IsAllowRedefinitionsWithoutWarning
;
47 setArgumentList(MI
.ArgumentList
, MI
.NumArguments
, PPAllocator
);
50 /// isIdenticalTo - Return true if the specified macro definition is equal to
51 /// this macro in spelling, arguments, and whitespace. This is used to emit
52 /// duplicate definition warnings. This implements the rules in C99 6.10.3.
54 bool MacroInfo::isIdenticalTo(const MacroInfo
&Other
, Preprocessor
&PP
) const {
55 // Check # tokens in replacement, number of args, and various flags all match.
56 if (ReplacementTokens
.size() != Other
.ReplacementTokens
.size() ||
57 getNumArgs() != Other
.getNumArgs() ||
58 isFunctionLike() != Other
.isFunctionLike() ||
59 isC99Varargs() != Other
.isC99Varargs() ||
60 isGNUVarargs() != Other
.isGNUVarargs())
64 for (arg_iterator I
= arg_begin(), OI
= Other
.arg_begin(), E
= arg_end();
66 if (*I
!= *OI
) return false;
68 // Check all the tokens.
69 for (unsigned i
= 0, e
= ReplacementTokens
.size(); i
!= e
; ++i
) {
70 const Token
&A
= ReplacementTokens
[i
];
71 const Token
&B
= Other
.ReplacementTokens
[i
];
72 if (A
.getKind() != B
.getKind())
75 // If this isn't the first first token, check that the whitespace and
76 // start-of-line characteristics match.
78 (A
.isAtStartOfLine() != B
.isAtStartOfLine() ||
79 A
.hasLeadingSpace() != B
.hasLeadingSpace()))
82 // If this is an identifier, it is easy.
83 if (A
.getIdentifierInfo() || B
.getIdentifierInfo()) {
84 if (A
.getIdentifierInfo() != B
.getIdentifierInfo())
89 // Otherwise, check the spelling.
90 if (PP
.getSpelling(A
) != PP
.getSpelling(B
))