cppManifest.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 cppManifest.h
  10. * @author drose
  11. * @date 1999-10-22
  12. */
  13. #ifndef CPPMANIFEST_H
  14. #define CPPMANIFEST_H
  15. #include "dtoolbase.h"
  16. #include "cppFile.h"
  17. #include "cppVisibility.h"
  18. #include "cppBisonDefs.h"
  19. #include "vector_string.h"
  20. #include <unordered_set>
  21. class CPPExpression;
  22. class CPPType;
  23. /**
  24. *
  25. */
  26. class CPPManifest {
  27. public:
  28. typedef std::unordered_set<const CPPManifest *> Ignores;
  29. CPPManifest(const CPPPreprocessor &parser, const std::string &args, const cppyyltype &loc);
  30. CPPManifest(const CPPPreprocessor &parser, const std::string &macro, const std::string &definition);
  31. ~CPPManifest();
  32. static std::string stringify(const std::string &source);
  33. void extract_args(vector_string &args, const std::string &expr, size_t &p) const;
  34. std::string expand(const vector_string &args = vector_string(),
  35. bool expand_undefined = false,
  36. const Ignores &ignores = Ignores()) const;
  37. CPPType *determine_type() const;
  38. bool is_equal(const CPPManifest *other) const;
  39. void output(std::ostream &out) const;
  40. const CPPPreprocessor &_parser;
  41. std::string _name;
  42. bool _has_parameters;
  43. size_t _num_parameters;
  44. int _variadic_param;
  45. cppyyltype _loc;
  46. CPPExpression *_expr;
  47. // Manifests don't have a visibility in the normal sense. Normally this
  48. // will be V_public. But a manifest that is defined between __begin_publish
  49. // and __end_publish will have a visibility of V_published.
  50. CPPVisibility _vis;
  51. private:
  52. class ExpansionNode {
  53. public:
  54. ExpansionNode(int parm_number, bool stringify, bool paste);
  55. ExpansionNode(const std::string &str, bool paste = false);
  56. ExpansionNode(std::vector<ExpansionNode> nested, bool stringify = false, bool paste = false, bool optional = false);
  57. bool operator ==(const ExpansionNode &other) const;
  58. int _parm_number;
  59. bool _expand;
  60. bool _stringify;
  61. bool _paste;
  62. bool _optional;
  63. std::string _str;
  64. std::vector<ExpansionNode> _nested;
  65. };
  66. typedef std::vector<ExpansionNode> Expansion;
  67. void parse_parameters(const std::string &args, size_t &p,
  68. vector_string &parameter_names);
  69. void save_expansion(Expansion &expansion, const std::string &exp,
  70. const vector_string &parameter_names);
  71. std::string r_expand(const Expansion &expansion, const vector_string &args,
  72. bool expand_undefined, const Ignores &ignores) const;
  73. Expansion _expansion;
  74. };
  75. inline std::ostream &operator << (std::ostream &out, const CPPManifest &manifest) {
  76. manifest.output(out);
  77. return out;
  78. }
  79. #endif