cppAttributeList.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file cppAttributeList.h
  10. * @author rdb
  11. * @date 2022-10-23
  12. */
  13. #ifndef CPPATTRIBUTELIST_H
  14. #define CPPATTRIBUTELIST_H
  15. #include "dtoolbase.h"
  16. #include <vector>
  17. class CPPExpression;
  18. class CPPIdentifier;
  19. class CPPScope;
  20. class CPPType;
  21. /**
  22. * A list of square-bracket attributes and/or alignas specifiers.
  23. */
  24. class CPPAttributeList {
  25. public:
  26. bool is_empty() const;
  27. bool has_attribute(const std::string &name) const;
  28. bool operator == (const CPPAttributeList &other) const;
  29. bool operator != (const CPPAttributeList &other) const;
  30. bool operator < (const CPPAttributeList &other) const;
  31. void add_attribute(CPPIdentifier *ident);
  32. void add_attribute(CPPIdentifier *ident, std::string reason);
  33. void add_alignas(int size);
  34. void add_alignas(CPPType *type);
  35. void add_alignas(CPPExpression *expr);
  36. void add_attributes_from(const CPPAttributeList &other);
  37. struct Attribute {
  38. CPPIdentifier *_ident;
  39. std::string _reason;
  40. };
  41. typedef std::vector<Attribute> Attributes;
  42. Attributes _attributes;
  43. CPPExpression *_alignas = nullptr;
  44. void output(std::ostream &out, CPPScope *scope) const;
  45. };
  46. inline std::ostream &
  47. operator << (std::ostream &out, const CPPAttributeList &alist) {
  48. alist.output(out, nullptr);
  49. return out;
  50. }
  51. #endif