blob: f41b37e212278dfa01f502dcbd30b295b1019b0d [file] [log] [blame]
Chris Lattner22eb9722006-06-18 05:43:12 +00001//===--- MacroInfo.cpp - Information about #defined identifiers -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the MacroInfo interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Lex/MacroInfo.h"
Chris Lattner21284df2006-07-08 07:16:08 +000015#include "clang/Lex/Preprocessor.h"
Chris Lattner22eb9722006-06-18 05:43:12 +000016#include <iostream>
17using namespace llvm;
18using namespace clang;
Chris Lattnere8eef322006-07-08 07:01:00 +000019
Chris Lattnercefc7682006-07-08 08:28:12 +000020MacroInfo::MacroInfo(SourceLocation DefLoc) : Location(DefLoc) {
21 IsFunctionLike = false;
22 IsC99Varargs = false;
23 IsGNUVarargs = false;
24 IsBuiltinMacro = false;
25 IsDisabled = false;
26 IsUsed = true;
27}
28
29
Chris Lattner21284df2006-07-08 07:16:08 +000030/// isIdenticalTo - Return true if the specified macro definition is equal to
31/// this macro in spelling, arguments, and whitespace. This is used to emit
32/// duplicate definition warnings. This implements the rules in C99 6.10.3.
33bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const {
Chris Lattnercefc7682006-07-08 08:28:12 +000034 // TODO: Check param count.
Chris Lattner21284df2006-07-08 07:16:08 +000035
36 // Check # tokens in replacement match.
Chris Lattnercefc7682006-07-08 08:28:12 +000037 if (ReplacementTokens.size() != Other.ReplacementTokens.size() ||
38 isFunctionLike() != Other.isFunctionLike() ||
39 isC99Varargs() != Other.isC99Varargs() ||
40 isGNUVarargs() != Other.isGNUVarargs())
Chris Lattner21284df2006-07-08 07:16:08 +000041 return false;
42
43 // Check all the tokens.
44 for (unsigned i = 0, e = ReplacementTokens.size(); i != e; ++i) {
45 const LexerToken &A = ReplacementTokens[i];
46 const LexerToken &B = Other.ReplacementTokens[i];
47 if (A.getKind() != B.getKind() ||
48 A.isAtStartOfLine() != B.isAtStartOfLine() ||
49 A.hasLeadingSpace() != B.hasLeadingSpace())
50 return false;
51
52 // If this is an identifier, it is easy.
53 if (A.getIdentifierInfo() || B.getIdentifierInfo()) {
54 if (A.getIdentifierInfo() != B.getIdentifierInfo())
55 return false;
56 continue;
57 }
58
59 // Otherwise, check the spelling.
60 if (PP.getSpelling(A) != PP.getSpelling(B))
61 return false;
62 }
63
Chris Lattnere8eef322006-07-08 07:01:00 +000064 return true;
65}