MacroInfo.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //===--- 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. #include "clang/Lex/MacroInfo.h"
  14. #include "clang/Lex/Preprocessor.h"
  15. using namespace clang;
  16. MacroInfo::MacroInfo(SourceLocation DefLoc) : Location(DefLoc) {
  17. IsFunctionLike = false;
  18. IsC99Varargs = false;
  19. IsGNUVarargs = false;
  20. IsBuiltinMacro = false;
  21. IsTargetSpecific = false;
  22. IsDisabled = false;
  23. IsUsed = true;
  24. }
  25. /// isIdenticalTo - Return true if the specified macro definition is equal to
  26. /// this macro in spelling, arguments, and whitespace. This is used to emit
  27. /// duplicate definition warnings. This implements the rules in C99 6.10.3.
  28. ///
  29. /// Note that this intentionally does not check isTargetSpecific for matching.
  30. ///
  31. bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const {
  32. // Check # tokens in replacement, number of args, and various flags all match.
  33. if (ReplacementTokens.size() != Other.ReplacementTokens.size() ||
  34. Arguments.size() != Other.Arguments.size() ||
  35. isFunctionLike() != Other.isFunctionLike() ||
  36. isC99Varargs() != Other.isC99Varargs() ||
  37. isGNUVarargs() != Other.isGNUVarargs())
  38. return false;
  39. // Check arguments.
  40. for (arg_iterator I = arg_begin(), OI = Other.arg_begin(), E = arg_end();
  41. I != E; ++I, ++OI)
  42. if (*I != *OI) return false;
  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. // If this is an identifier, it is easy.
  52. if (A.getIdentifierInfo() || B.getIdentifierInfo()) {
  53. if (A.getIdentifierInfo() != B.getIdentifierInfo())
  54. return false;
  55. continue;
  56. }
  57. // Otherwise, check the spelling.
  58. if (PP.getSpelling(A) != PP.getSpelling(B))
  59. return false;
  60. }
  61. return true;
  62. }