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