cppScope.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // Filename: cppScope.h
  2. // Created by: drose (21Oct99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef CPPSCOPE_H
  19. #define CPPSCOPE_H
  20. #include <dtoolbase.h>
  21. #include "cppVisibility.h"
  22. #include "cppTemplateParameterList.h"
  23. #include "cppNameComponent.h"
  24. #include <vector>
  25. #include <map>
  26. #include <set>
  27. #include <string>
  28. using namespace std;
  29. class CPPType;
  30. class CPPDeclaration;
  31. class CPPExtensionType;
  32. class CPPStructType;
  33. class CPPNamespace;
  34. class CPPUsing;
  35. class CPPTypedef;
  36. class CPPInstance;
  37. class CPPFunctionGroup;
  38. class CPPTemplateScope;
  39. class CPPTemplateParameterList;
  40. class CPPPreprocessor;
  41. class CPPNameComponent;
  42. struct cppyyltype;
  43. ///////////////////////////////////////////////////////////////////
  44. // Class : CPPScope
  45. // Description :
  46. ////////////////////////////////////////////////////////////////////
  47. class CPPScope {
  48. public:
  49. CPPScope(CPPScope *parent_scope,
  50. const CPPNameComponent &name, CPPVisibility starting_vis);
  51. virtual ~CPPScope();
  52. void set_current_vis(CPPVisibility current_vis);
  53. CPPVisibility get_current_vis() const;
  54. void set_struct_type(CPPStructType *struct_type);
  55. CPPStructType *get_struct_type() const;
  56. CPPScope *get_parent_scope() const;
  57. virtual void add_declaration(CPPDeclaration *decl, CPPScope *global_scope,
  58. CPPPreprocessor *preprocessor,
  59. const cppyyltype &pos);
  60. virtual void add_enum_value(CPPInstance *inst);
  61. virtual void define_extension_type(CPPExtensionType *type);
  62. virtual void define_namespace(CPPNamespace *scope);
  63. virtual void add_using(CPPUsing *using_decl, CPPScope *global_scope,
  64. CPPPreprocessor *error_sink = NULL);
  65. virtual bool is_fully_specified() const;
  66. CPPScope *
  67. instantiate(const CPPTemplateParameterList *actual_params,
  68. CPPScope *current_scope, CPPScope *global_scope,
  69. CPPPreprocessor *error_sink = NULL) const;
  70. CPPScope *
  71. substitute_decl(CPPDeclaration::SubstDecl &subst,
  72. CPPScope *current_scope,
  73. CPPScope *global_scope) const;
  74. CPPType *find_type(const string &name, bool recurse = true) const;
  75. CPPType *find_type(const string &name,
  76. CPPDeclaration::SubstDecl &subst,
  77. CPPScope *global_scope,
  78. bool recurse = true) const;
  79. CPPScope *find_scope(const string &name, bool recurse = true) const;
  80. CPPScope *find_scope(const string &name,
  81. CPPDeclaration::SubstDecl &subst,
  82. CPPScope *global_scope,
  83. bool recurse = true) const;
  84. CPPDeclaration *find_symbol(const string &name,
  85. bool recurse = true) const;
  86. CPPDeclaration *find_template(const string &name,
  87. bool recurse = true) const;
  88. virtual string get_simple_name() const;
  89. virtual string get_local_name(CPPScope *scope = NULL) const;
  90. virtual string get_fully_scoped_name() const;
  91. virtual void output(ostream &out, CPPScope *scope) const;
  92. void write(ostream &out, int indent, CPPScope *scope) const;
  93. CPPTemplateScope *get_template_scope();
  94. virtual CPPTemplateScope *as_template_scope();
  95. private:
  96. bool
  97. copy_substitute_decl(CPPScope *to_scope, CPPDeclaration::SubstDecl &subst,
  98. CPPScope *global_scope) const;
  99. void handle_declaration(CPPDeclaration *decl, CPPScope *global_scope);
  100. public:
  101. typedef vector<CPPDeclaration *> Declarations;
  102. Declarations _declarations;
  103. typedef map<string, CPPType *> ExtensionTypes;
  104. ExtensionTypes _structs;
  105. ExtensionTypes _classes;
  106. ExtensionTypes _unions;
  107. ExtensionTypes _enums;
  108. typedef map<string, CPPNamespace *> Namespaces;
  109. Namespaces _namespaces;
  110. typedef map<string, CPPTypedef *> Typedefs;
  111. Typedefs _typedefs;
  112. typedef map<string, CPPInstance *> Variables;
  113. Variables _variables;
  114. Variables _enum_values;
  115. typedef map<string, CPPFunctionGroup *> Functions;
  116. Functions _functions;
  117. typedef map<string, CPPDeclaration *> Templates;
  118. Templates _templates;
  119. CPPNameComponent _name;
  120. protected:
  121. CPPScope *_parent_scope;
  122. CPPStructType *_struct_type;
  123. typedef set<CPPScope *> Using;
  124. Using _using;
  125. CPPVisibility _current_vis;
  126. private:
  127. typedef map<const CPPTemplateParameterList *, CPPScope *, CPPTPLCompare> Instantiations;
  128. Instantiations _instantiations;
  129. bool _is_fully_specified;
  130. bool _fully_specified_known;
  131. bool _is_fully_specified_recursive_protect;
  132. bool _subst_decl_recursive_protect;
  133. };
  134. inline ostream &
  135. operator << (ostream &out, const CPPScope &scope) {
  136. scope.output(out, (CPPScope *)NULL);
  137. return out;
  138. }
  139. #endif