Don't warn for -Wnon-virtual-dtor for dependent classes.
[clang.git] / lib / Lex / MacroInfo.cpp
blobc819011338e899aa6e78d90285e43e93156790fa
1 //===--- MacroInfo.cpp - Information about #defined identifiers -----------===//
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 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;
20 IsC99Varargs = false;
21 IsGNUVarargs = false;
22 IsBuiltinMacro = false;
23 IsFromAST = false;
24 IsDisabled = false;
25 IsUsed = false;
26 IsAllowRedefinitionsWithoutWarning = false;
27 IsWarnIfUnused = false;
29 ArgumentList = 0;
30 NumArguments = 0;
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;
43 IsUsed = MI.IsUsed;
44 IsAllowRedefinitionsWithoutWarning = MI.IsAllowRedefinitionsWithoutWarning;
45 ArgumentList = 0;
46 NumArguments = 0;
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.
53 ///
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())
61 return false;
63 // Check arguments.
64 for (arg_iterator I = arg_begin(), OI = Other.arg_begin(), E = arg_end();
65 I != E; ++I, ++OI)
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())
73 return false;
75 // If this isn't the first first token, check that the whitespace and
76 // start-of-line characteristics match.
77 if (i != 0 &&
78 (A.isAtStartOfLine() != B.isAtStartOfLine() ||
79 A.hasLeadingSpace() != B.hasLeadingSpace()))
80 return false;
82 // If this is an identifier, it is easy.
83 if (A.getIdentifierInfo() || B.getIdentifierInfo()) {
84 if (A.getIdentifierInfo() != B.getIdentifierInfo())
85 return false;
86 continue;
89 // Otherwise, check the spelling.
90 if (PP.getSpelling(A) != PP.getSpelling(B))
91 return false;
94 return true;