SafeMatcher.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Digia. For licensing terms and
  13. ** conditions see http://www.qt.io/licensing. For further information
  14. ** use the contact form at http://www.qt.io/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 or version 3 as published by the Free
  19. ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
  20. ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
  21. ** following information to ensure the GNU Lesser General Public License
  22. ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
  23. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  24. **
  25. ** In addition, as a special exception, Digia gives you certain additional
  26. ** rights. These rights are described in the Digia Qt LGPL Exception
  27. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  28. **
  29. ****************************************************************************/
  30. #include "CoreTypes.h"
  31. #include "Names.h"
  32. #include "SafeMatcher.h"
  33. using namespace std;
  34. using namespace CPlusPlus;
  35. namespace {
  36. template<typename T>
  37. class Blocker
  38. {
  39. vector<const T *> &v;
  40. public:
  41. Blocker(vector<const T *> &v, const T *el1, const T *el2)
  42. : v(v)
  43. { v.push_back(el1); v.push_back(el2); }
  44. ~Blocker() { v.pop_back(); v.pop_back(); }
  45. };
  46. template<typename T, typename U>
  47. bool isBlocked(const vector<const T *> &v, const U *t1, const U *t2)
  48. {
  49. for (size_t i = v.size(); i > 0; ) {
  50. const T *t = v[--i];
  51. if (t == t1 || t == t2)
  52. return true;
  53. }
  54. return false;
  55. }
  56. } // anonymous namespace
  57. SafeMatcher::SafeMatcher()
  58. {
  59. _blockedTypes.reserve(8);
  60. _blockedNames.reserve(8);
  61. }
  62. SafeMatcher::~SafeMatcher()
  63. {}
  64. bool SafeMatcher::match(const PointerToMemberType *type, const PointerToMemberType *otherType)
  65. {
  66. if (isBlocked(_blockedTypes, type, otherType))
  67. return true;
  68. Blocker<Type> b(_blockedTypes, type, otherType);
  69. return Matcher::match(type, otherType);
  70. }
  71. bool SafeMatcher::match(const PointerType *type, const PointerType *otherType)
  72. {
  73. if (isBlocked(_blockedTypes, type, otherType))
  74. return true;
  75. Blocker<Type> b(_blockedTypes, type, otherType);
  76. return Matcher::match(type, otherType);
  77. }
  78. bool SafeMatcher::match(const ReferenceType *type, const ReferenceType *otherType)
  79. {
  80. if (isBlocked(_blockedTypes, type, otherType))
  81. return true;
  82. Blocker<Type> b(_blockedTypes, type, otherType);
  83. return Matcher::match(type, otherType);
  84. }
  85. bool SafeMatcher::match(const ArrayType *type, const ArrayType *otherType)
  86. {
  87. if (isBlocked(_blockedTypes, type, otherType))
  88. return true;
  89. Blocker<Type> b(_blockedTypes, type, otherType);
  90. return Matcher::match(type, otherType);
  91. }
  92. bool SafeMatcher::match(const NamedType *type, const NamedType *otherType)
  93. {
  94. if (isBlocked(_blockedTypes, type, otherType))
  95. return true;
  96. Blocker<Type> b(_blockedTypes, type, otherType);
  97. return Matcher::match(type, otherType);
  98. }
  99. bool SafeMatcher::match(const TemplateNameId *name, const TemplateNameId *otherName)
  100. {
  101. if (isBlocked(_blockedNames, name, otherName))
  102. return true;
  103. Blocker<Name> b(_blockedNames, name, otherName);
  104. return Matcher::match(name, otherName);
  105. }
  106. bool SafeMatcher::match(const DestructorNameId *name, const DestructorNameId *otherName)
  107. {
  108. if (isBlocked(_blockedNames, name, otherName))
  109. return true;
  110. Blocker<Name> b(_blockedNames, name, otherName);
  111. return Matcher::match(name, otherName);
  112. }
  113. bool SafeMatcher::match(const ConversionNameId *name, const ConversionNameId *otherName)
  114. {
  115. if (isBlocked(_blockedNames, name, otherName))
  116. return true;
  117. Blocker<Name> b(_blockedNames, name, otherName);
  118. return Matcher::match(name, otherName);
  119. }
  120. bool SafeMatcher::match(const QualifiedNameId *name, const QualifiedNameId *otherName)
  121. {
  122. if (isBlocked(_blockedNames, name, otherName))
  123. return true;
  124. Blocker<Name> b(_blockedNames, name, otherName);
  125. return Matcher::match(name, otherName);
  126. }
  127. bool SafeMatcher::match(const SelectorNameId *name, const SelectorNameId *otherName)
  128. {
  129. if (isBlocked(_blockedNames, name, otherName))
  130. return true;
  131. Blocker<Name> b(_blockedNames, name, otherName);
  132. return Matcher::match(name, otherName);
  133. }