cppScope.h 5.1 KB

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