cppScope.h 5.0 KB

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