resolver.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* C++ modules. Experimental! -*- c++ -*-
  2. Copyright (C) 2017-2022 Free Software Foundation, Inc.
  3. Written by Nathan Sidwell <nathan@acm.org> while at FaceBook
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. GCC is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GXX_RESOLVER_H
  17. #define GXX_RESOLVER_H 1
  18. // Mapper interface for client and server bits
  19. #include "cody.hh"
  20. // C++
  21. #if !IN_GCC
  22. #include <string>
  23. #include <map>
  24. #endif
  25. // This is a GCC class, so GCC coding conventions on new bits.
  26. class module_resolver : public Cody::Resolver
  27. {
  28. public:
  29. using parent = Cody::Resolver;
  30. using module_map = std::map<std::string, std::string>;
  31. private:
  32. std::string repo;
  33. std::string ident;
  34. module_map map;
  35. int fd_repo = -1;
  36. bool default_map = true;
  37. bool default_translate = true;
  38. public:
  39. module_resolver (bool map = true, bool xlate = false);
  40. virtual ~module_resolver () override;
  41. public:
  42. void set_default_map (bool d)
  43. {
  44. default_map = d;
  45. }
  46. void set_default_translate (bool d)
  47. {
  48. default_translate = d;
  49. }
  50. void set_ident (char const *i)
  51. {
  52. ident = i;
  53. }
  54. bool set_repo (std::string &&repo, bool force = false);
  55. bool add_mapping (std::string &&module, std::string &&file,
  56. bool force = false);
  57. // Return +ve line number of error, or -ve errno
  58. int read_tuple_file (int fd, char const *prefix, bool force = false);
  59. int read_tuple_file (int fd, std::string const &prefix,
  60. bool force = false)
  61. {
  62. return read_tuple_file (fd, prefix.empty () ? nullptr : prefix.c_str (),
  63. force);
  64. }
  65. public:
  66. // Virtual overriders, names are controlled by Cody::Resolver
  67. using parent::ConnectRequest;
  68. virtual module_resolver *ConnectRequest (Cody::Server *, unsigned version,
  69. std::string &agent,
  70. std::string &ident)
  71. override;
  72. using parent::ModuleRepoRequest;
  73. virtual int ModuleRepoRequest (Cody::Server *) override;
  74. using parent::ModuleExportRequest;
  75. virtual int ModuleExportRequest (Cody::Server *s, Cody::Flags,
  76. std::string &module)
  77. override;
  78. using parent::ModuleImportRequest;
  79. virtual int ModuleImportRequest (Cody::Server *s, Cody::Flags,
  80. std::string &module)
  81. override;
  82. using parent::IncludeTranslateRequest;
  83. virtual int IncludeTranslateRequest (Cody::Server *s, Cody::Flags,
  84. std::string &include)
  85. override;
  86. using parent::ModuleCompiledRequest;
  87. virtual int ModuleCompiledRequest (Cody::Server *s, Cody::Flags Flags,
  88. std::string &Module) override;
  89. private:
  90. using parent::GetCMISuffix;
  91. virtual char const *GetCMISuffix () override;
  92. private:
  93. int cmi_response (Cody::Server *s, std::string &module);
  94. };
  95. #endif