cppInstance.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Filename: cppInstance.h
  2. // Created by: drose (19Oct99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef CPPINSTANCE_H
  15. #define CPPINSTANCE_H
  16. #include "dtoolbase.h"
  17. #include "cppDeclaration.h"
  18. #include "cppType.h"
  19. #include "cppTemplateParameterList.h"
  20. class CPPInstanceIdentifier;
  21. class CPPIdentifier;
  22. class CPPParameterList;
  23. class CPPScope;
  24. class CPPExpression;
  25. ///////////////////////////////////////////////////////////////////
  26. // Class : CPPInstance
  27. // Description :
  28. ////////////////////////////////////////////////////////////////////
  29. class CPPInstance : public CPPDeclaration {
  30. public:
  31. // Some of these flags clearly only make sense in certain contexts,
  32. // e.g. for a function or method.
  33. enum StorageClass {
  34. SC_static = 0x0001,
  35. SC_extern = 0x0002,
  36. SC_c_binding = 0x0004,
  37. SC_virtual = 0x0008,
  38. SC_inline = 0x0010,
  39. SC_explicit = 0x0020,
  40. SC_register = 0x0040,
  41. SC_pure_virtual = 0x0080,
  42. SC_volatile = 0x0100,
  43. SC_mutable = 0x0200,
  44. SC_constexpr = 0x0400,
  45. // This bit is only set by CPPStructType::check_virtual().
  46. SC_inherited_virtual = 0x0800,
  47. // This is a special "storage class" for methods tagged with the
  48. // BLOCKING macro (i.e. the special __blocking keyword). These
  49. // are methods that might block and therefore need to release
  50. // Python threads for their duration.
  51. SC_blocking = 0x1000,
  52. // And this is for methods tagged with __extension, which declares
  53. // extension methods defined separately from the source code.
  54. SC_extension = 0x2000,
  55. };
  56. CPPInstance(CPPType *type, const string &name, int storage_class = 0);
  57. CPPInstance(CPPType *type, CPPIdentifier *ident, int storage_class = 0);
  58. CPPInstance(CPPType *type, CPPInstanceIdentifier *ii,
  59. int storage_class, const CPPFile &file);
  60. CPPInstance(const CPPInstance &copy);
  61. ~CPPInstance();
  62. static CPPInstance *
  63. make_typecast_function(CPPInstance *inst, CPPIdentifier *ident,
  64. CPPParameterList *parameters, int function_flags);
  65. bool operator == (const CPPInstance &other) const;
  66. bool operator != (const CPPInstance &other) const;
  67. bool operator < (const CPPInstance &other) const;
  68. void set_initializer(CPPExpression *initializer);
  69. void set_alignment(int align);
  70. void set_alignment(CPPExpression *const_expr);
  71. bool is_scoped() const;
  72. CPPScope *get_scope(CPPScope *current_scope, CPPScope *global_scope,
  73. CPPPreprocessor *error_sink = NULL) const;
  74. string get_simple_name() const;
  75. string get_local_name(CPPScope *scope = NULL) const;
  76. string get_fully_scoped_name() const;
  77. void check_for_constructor(CPPScope *current_scope, CPPScope *global_scope);
  78. virtual CPPDeclaration *
  79. instantiate(const CPPTemplateParameterList *actual_params,
  80. CPPScope *current_scope, CPPScope *global_scope,
  81. CPPPreprocessor *error_sink = NULL) const;
  82. virtual bool is_fully_specified() const;
  83. virtual CPPDeclaration *substitute_decl(SubstDecl &subst,
  84. CPPScope *current_scope,
  85. CPPScope *global_scope);
  86. virtual void output(ostream &out, int indent_level, CPPScope *scope,
  87. bool complete) const;
  88. void output(ostream &out, int indent_level, CPPScope *scope,
  89. bool complete, int num_default_parameters) const;
  90. virtual SubType get_subtype() const;
  91. virtual CPPInstance *as_instance();
  92. CPPType *_type;
  93. CPPIdentifier *_ident;
  94. CPPExpression *_initializer;
  95. int _storage_class;
  96. CPPExpression *_alignment;
  97. private:
  98. typedef map<const CPPTemplateParameterList *, CPPInstance *, CPPTPLCompare> Instantiations;
  99. Instantiations _instantiations;
  100. };
  101. #endif