cppScope.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Filename: cppScope.h
  2. // Created by: drose (21Oct99)
  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 CPPSCOPE_H
  15. #define CPPSCOPE_H
  16. #include "dtoolbase.h"
  17. #include "cppVisibility.h"
  18. #include "cppTemplateParameterList.h"
  19. #include "cppNameComponent.h"
  20. #include <vector>
  21. #include <map>
  22. #include <set>
  23. #include <string>
  24. using namespace std;
  25. class CPPType;
  26. class CPPDeclaration;
  27. class CPPExtensionType;
  28. class CPPStructType;
  29. class CPPNamespace;
  30. class CPPUsing;
  31. class CPPTypedef;
  32. class CPPInstance;
  33. class CPPFunctionGroup;
  34. class CPPTemplateScope;
  35. class CPPTemplateParameterList;
  36. class CPPPreprocessor;
  37. class CPPNameComponent;
  38. struct cppyyltype;
  39. ///////////////////////////////////////////////////////////////////
  40. // Class : CPPScope
  41. // Description :
  42. ////////////////////////////////////////////////////////////////////
  43. class CPPScope {
  44. public:
  45. CPPScope(CPPScope *parent_scope,
  46. const CPPNameComponent &name, CPPVisibility starting_vis);
  47. virtual ~CPPScope();
  48. void set_current_vis(CPPVisibility current_vis);
  49. CPPVisibility get_current_vis() const;
  50. void set_struct_type(CPPStructType *struct_type);
  51. CPPStructType *get_struct_type() const;
  52. CPPScope *get_parent_scope() const;
  53. virtual void add_declaration(CPPDeclaration *decl, CPPScope *global_scope,
  54. CPPPreprocessor *preprocessor,
  55. const cppyyltype &pos);
  56. virtual void add_enum_value(CPPInstance *inst);
  57. virtual void define_extension_type(CPPExtensionType *type);
  58. virtual void define_namespace(CPPNamespace *scope);
  59. virtual void add_using(CPPUsing *using_decl, CPPScope *global_scope,
  60. CPPPreprocessor *error_sink = NULL);
  61. virtual bool is_fully_specified() const;
  62. CPPScope *
  63. instantiate(const CPPTemplateParameterList *actual_params,
  64. CPPScope *current_scope, CPPScope *global_scope,
  65. CPPPreprocessor *error_sink = NULL) const;
  66. CPPScope *
  67. substitute_decl(CPPDeclaration::SubstDecl &subst,
  68. CPPScope *current_scope,
  69. CPPScope *global_scope) const;
  70. CPPType *find_type(const string &name, bool recurse = true) const;
  71. CPPType *find_type(const string &name,
  72. CPPDeclaration::SubstDecl &subst,
  73. CPPScope *global_scope,
  74. bool recurse = true) const;
  75. CPPScope *find_scope(const string &name, bool recurse = true) const;
  76. CPPScope *find_scope(const string &name,
  77. CPPDeclaration::SubstDecl &subst,
  78. CPPScope *global_scope,
  79. bool recurse = true) const;
  80. CPPDeclaration *find_symbol(const string &name,
  81. bool recurse = true) const;
  82. CPPDeclaration *find_template(const string &name,
  83. bool recurse = true) const;
  84. virtual string get_simple_name() const;
  85. virtual string get_local_name(CPPScope *scope = NULL) const;
  86. virtual string get_fully_scoped_name() const;
  87. virtual void output(ostream &out, CPPScope *scope) const;
  88. void write(ostream &out, int indent, CPPScope *scope) const;
  89. CPPTemplateScope *get_template_scope();
  90. virtual CPPTemplateScope *as_template_scope();
  91. private:
  92. bool
  93. copy_substitute_decl(CPPScope *to_scope, CPPDeclaration::SubstDecl &subst,
  94. CPPScope *global_scope) const;
  95. void handle_declaration(CPPDeclaration *decl, CPPScope *global_scope);
  96. public:
  97. typedef vector<CPPDeclaration *> Declarations;
  98. Declarations _declarations;
  99. typedef map<string, CPPType *> ExtensionTypes;
  100. ExtensionTypes _structs;
  101. ExtensionTypes _classes;
  102. ExtensionTypes _unions;
  103. ExtensionTypes _enums;
  104. typedef map<string, CPPNamespace *> Namespaces;
  105. Namespaces _namespaces;
  106. typedef map<string, CPPTypedef *> Typedefs;
  107. Typedefs _typedefs;
  108. typedef map<string, CPPInstance *> Variables;
  109. Variables _variables;
  110. Variables _enum_values;
  111. typedef map<string, CPPFunctionGroup *> Functions;
  112. Functions _functions;
  113. typedef map<string, CPPDeclaration *> Templates;
  114. Templates _templates;
  115. CPPNameComponent _name;
  116. protected:
  117. CPPScope *_parent_scope;
  118. CPPStructType *_struct_type;
  119. typedef set<CPPScope *> Using;
  120. Using _using;
  121. CPPVisibility _current_vis;
  122. private:
  123. typedef map<const CPPTemplateParameterList *, CPPScope *, CPPTPLCompare> Instantiations;
  124. Instantiations _instantiations;
  125. bool _is_fully_specified;
  126. bool _fully_specified_known;
  127. bool _is_fully_specified_recursive_protect;
  128. bool _subst_decl_recursive_protect;
  129. };
  130. inline ostream &
  131. operator << (ostream &out, const CPPScope &scope) {
  132. scope.output(out, (CPPScope *)NULL);
  133. return out;
  134. }
  135. #endif