Name.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifndef CPLUSPLUS_NAME_H
  21. #define CPLUSPLUS_NAME_H
  22. #include "CPlusPlusForwardDeclarations.h"
  23. #include "Matcher.h"
  24. #include <functional>
  25. namespace CPlusPlus {
  26. class CPLUSPLUS_EXPORT Name
  27. {
  28. public:
  29. Name();
  30. virtual ~Name();
  31. virtual const Identifier *identifier() const = 0;
  32. bool isNameId() const;
  33. bool isAnonymousNameId() const;
  34. bool isTemplateNameId() const;
  35. bool isDestructorNameId() const;
  36. bool isOperatorNameId() const;
  37. bool isConversionNameId() const;
  38. bool isQualifiedNameId() const;
  39. bool isSelectorNameId() const;
  40. virtual const Identifier *asNameId() const { return 0; }
  41. virtual const AnonymousNameId *asAnonymousNameId() const { return 0; }
  42. virtual const TemplateNameId *asTemplateNameId() const { return 0; }
  43. virtual const DestructorNameId *asDestructorNameId() const { return 0; }
  44. virtual const OperatorNameId *asOperatorNameId() const { return 0; }
  45. virtual const ConversionNameId *asConversionNameId() const { return 0; }
  46. virtual const QualifiedNameId *asQualifiedNameId() const { return 0; }
  47. virtual const SelectorNameId *asSelectorNameId() const { return 0; }
  48. void accept(NameVisitor *visitor) const;
  49. static void accept(const Name *name, NameVisitor *visitor);
  50. bool match(const Name *other, Matcher *matcher = 0) const;
  51. public:
  52. struct Compare: std::binary_function<const Name *, const Name *, bool> {
  53. bool operator()(const Name *name, const Name *other) const;
  54. };
  55. protected:
  56. virtual void accept0(NameVisitor *visitor) const = 0;
  57. protected: // for Matcher
  58. friend class Matcher;
  59. virtual bool match0(const Name *otherName, Matcher *matcher) const = 0;
  60. };
  61. } // namespace CPlusPlus
  62. #endif // CPLUSPLUS_NAME_H