Name.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (c) 2008 Roberto Raggi <[email protected]>
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. #include "Literals.h"
  21. #include "Matcher.h"
  22. #include "Name.h"
  23. #include "Names.h"
  24. #include "NameVisitor.h"
  25. #include <cstring>
  26. using namespace CPlusPlus;
  27. Name::Name()
  28. { }
  29. Name::~Name()
  30. { }
  31. bool Name::isNameId() const
  32. { return asNameId() != 0; }
  33. bool Name::isAnonymousNameId() const
  34. { return asAnonymousNameId() != 0; }
  35. bool Name::isTemplateNameId() const
  36. { return asTemplateNameId() != 0; }
  37. bool Name::isDestructorNameId() const
  38. { return asDestructorNameId() != 0; }
  39. bool Name::isOperatorNameId() const
  40. { return asOperatorNameId() != 0; }
  41. bool Name::isConversionNameId() const
  42. { return asConversionNameId() != 0; }
  43. bool Name::isQualifiedNameId() const
  44. { return asQualifiedNameId() != 0; }
  45. bool Name::isSelectorNameId() const
  46. { return asSelectorNameId() != 0; }
  47. void Name::accept(NameVisitor *visitor) const
  48. {
  49. if (visitor->preVisit(this))
  50. accept0(visitor);
  51. visitor->postVisit(this);
  52. }
  53. void Name::accept(const Name *name, NameVisitor *visitor)
  54. {
  55. if (! name)
  56. return;
  57. name->accept(visitor);
  58. }
  59. bool Name::match(const Name *other, Matcher *matcher) const
  60. {
  61. return Matcher::match(this, other, matcher);
  62. }
  63. bool Name::Compare::operator()(const Name *name, const Name *other) const
  64. {
  65. if (name == 0)
  66. return other != 0;
  67. if (other == 0)
  68. return false;
  69. if (name == other)
  70. return false;
  71. const Identifier *id = name->identifier();
  72. const Identifier *otherId = other->identifier();
  73. if (id == 0)
  74. return otherId != 0;
  75. if (otherId == 0)
  76. return false;
  77. return std::strcmp(id->chars(), otherId->chars()) < 0;
  78. }