cppInstance.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 cppInstance.h
  10. * @author drose
  11. * @date 1999-10-19
  12. */
  13. #ifndef CPPINSTANCE_H
  14. #define CPPINSTANCE_H
  15. #include "dtoolbase.h"
  16. #include "cppDeclaration.h"
  17. #include "cppType.h"
  18. #include "cppTemplateParameterList.h"
  19. class CPPInstanceIdentifier;
  20. class CPPIdentifier;
  21. class CPPParameterList;
  22. class CPPScope;
  23. class CPPExpression;
  24. /**
  25. *
  26. */
  27. class CPPInstance : public CPPDeclaration {
  28. public:
  29. // Some of these flags clearly only make sense in certain contexts, e.g.
  30. // for a function or method.
  31. enum StorageClass {
  32. SC_static = 0x0001,
  33. SC_extern = 0x0002,
  34. SC_c_binding = 0x0004,
  35. SC_virtual = 0x0008,
  36. SC_inline = 0x0010,
  37. SC_explicit = 0x0020,
  38. SC_register = 0x0040,
  39. SC_pure_virtual = 0x0080,
  40. SC_volatile = 0x0100,
  41. SC_mutable = 0x0200,
  42. SC_constexpr = 0x0400,
  43. // This bit is only set by CPPStructType::check_virtual().
  44. SC_inherited_virtual = 0x0800,
  45. // This is a special "storage class" for methods tagged with the BLOCKING
  46. // macro (i.e. the special __blocking keyword). These are methods that
  47. // might block and therefore need to release Python threads for their
  48. // duration.
  49. SC_blocking = 0x1000,
  50. // And this is for methods tagged with __extension, which declares
  51. // extension methods defined separately from the source code.
  52. SC_extension = 0x2000,
  53. // These are for =default and =delete functions.
  54. SC_defaulted = 0x4000,
  55. SC_deleted = 0x8000,
  56. SC_thread_local = 0x10000,
  57. // This isn't really a storage class. It's only used temporarily by the
  58. // parser, to make parsing specifier sequences a bit easier.
  59. SC_const = 0x20000,
  60. // Used to indicate that this is a parameter pack.
  61. SC_parameter_pack = 0x40000,
  62. };
  63. CPPInstance(CPPType *type, const string &name, int storage_class = 0);
  64. CPPInstance(CPPType *type, CPPIdentifier *ident, int storage_class = 0);
  65. CPPInstance(CPPType *type, CPPInstanceIdentifier *ii,
  66. int storage_class, const CPPFile &file);
  67. CPPInstance(const CPPInstance &copy);
  68. ~CPPInstance();
  69. static CPPInstance *
  70. make_typecast_function(CPPInstance *inst, CPPIdentifier *ident,
  71. CPPParameterList *parameters, int function_flags);
  72. bool operator == (const CPPInstance &other) const;
  73. bool operator != (const CPPInstance &other) const;
  74. bool operator < (const CPPInstance &other) const;
  75. void set_initializer(CPPExpression *initializer);
  76. void set_alignment(int align);
  77. void set_alignment(CPPExpression *const_expr);
  78. bool is_scoped() const;
  79. CPPScope *get_scope(CPPScope *current_scope, CPPScope *global_scope,
  80. CPPPreprocessor *error_sink = NULL) const;
  81. string get_simple_name() const;
  82. string get_local_name(CPPScope *scope = NULL) const;
  83. string get_fully_scoped_name() const;
  84. void check_for_constructor(CPPScope *current_scope, CPPScope *global_scope);
  85. virtual CPPDeclaration *
  86. instantiate(const CPPTemplateParameterList *actual_params,
  87. CPPScope *current_scope, CPPScope *global_scope,
  88. CPPPreprocessor *error_sink = NULL) const;
  89. virtual bool is_fully_specified() const;
  90. virtual CPPDeclaration *substitute_decl(SubstDecl &subst,
  91. CPPScope *current_scope,
  92. CPPScope *global_scope);
  93. virtual void output(ostream &out, int indent_level, CPPScope *scope,
  94. bool complete) const;
  95. void output(ostream &out, int indent_level, CPPScope *scope,
  96. bool complete, int num_default_parameters) const;
  97. virtual SubType get_subtype() const;
  98. virtual CPPInstance *as_instance();
  99. CPPType *_type;
  100. CPPIdentifier *_ident;
  101. CPPExpression *_initializer;
  102. int _storage_class;
  103. CPPExpression *_alignment;
  104. int _bit_width;
  105. private:
  106. typedef map<const CPPTemplateParameterList *, CPPInstance *, CPPTPLCompare> Instantiations;
  107. Instantiations _instantiations;
  108. };
  109. #endif