Line data Source code
1 : /* C++ modules. Experimental! -*- c++ -*-
2 : Copyright (C) 2017-2026 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 : #if !IN_GCC
28 : #include <string>
29 : #include <map>
30 : #endif
31 :
32 : // This is a GCC class, so GCC coding conventions on new bits.
33 : class module_resolver : public Cody::Resolver
34 : {
35 : public:
36 : using parent = Cody::Resolver;
37 : using module_map = std::map<std::string, std::string>;
38 :
39 : private:
40 : std::string repo;
41 : std::string ident;
42 : module_map map;
43 : int fd_repo = -1;
44 : bool default_map = true;
45 : bool default_translate = true;
46 :
47 : public:
48 : module_resolver (bool map = true, bool xlate = false);
49 : virtual ~module_resolver () override;
50 :
51 : public:
52 : void set_default_map (bool d)
53 : {
54 : default_map = d;
55 : }
56 : void set_default_translate (bool d)
57 : {
58 : default_translate = d;
59 : }
60 : void set_ident (char const *i)
61 : {
62 : ident = i;
63 : }
64 : bool set_repo (std::string &&repo, bool force = false);
65 : bool add_mapping (std::string &&module, std::string &&file,
66 : bool force = false);
67 :
68 : // Return +ve line number of error, or -ve errno
69 : int read_tuple_file (int fd, char const *prefix, bool force = false);
70 24 : int read_tuple_file (int fd, std::string const &prefix,
71 : bool force = false)
72 : {
73 24 : return read_tuple_file (fd, prefix.empty () ? nullptr : prefix.c_str (),
74 : force);
75 : }
76 :
77 : public:
78 : // Virtual overriders, names are controlled by Cody::Resolver
79 : using parent::ConnectRequest;
80 : virtual module_resolver *ConnectRequest (Cody::Server *, unsigned version,
81 : std::string &agent,
82 : std::string &ident)
83 : override;
84 : using parent::ModuleRepoRequest;
85 : virtual int ModuleRepoRequest (Cody::Server *) override;
86 : using parent::ModuleExportRequest;
87 : virtual int ModuleExportRequest (Cody::Server *s, Cody::Flags,
88 : std::string &module)
89 : override;
90 : using parent::ModuleImportRequest;
91 : virtual int ModuleImportRequest (Cody::Server *s, Cody::Flags,
92 : std::string &module)
93 : override;
94 : using parent::IncludeTranslateRequest;
95 : virtual int IncludeTranslateRequest (Cody::Server *s, Cody::Flags,
96 : std::string &include)
97 : override;
98 :
99 : using parent::ModuleCompiledRequest;
100 : virtual int ModuleCompiledRequest (Cody::Server *s, Cody::Flags Flags,
101 : std::string &Module) override;
102 :
103 : private:
104 : using parent::GetCMISuffix;
105 : virtual char const *GetCMISuffix () override;
106 :
107 : private:
108 : int cmi_response (Cody::Server *s, std::string &module);
109 : };
110 :
111 : #endif
|