1 /**
2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved.
3 License: MPL-2
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 
6 This Source Code Form is subject to the terms of the Mozilla Public License,
7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain
8 one at http://mozilla.org/MPL/2.0/.
9 */
10 module dextool.plugin.cpptestdouble.backend.interface_;
11 
12 import dsrcgen.cpp : CppModule, CppHModule;
13 
14 import cpptooling.testdouble.header_filter : LocationType;
15 import cpptooling.type : MainName, StubPrefix, CustomHeader, MainNs, MainInterface;
16 
17 import dextool.type : AbsolutePath, DextoolVersion, Path;
18 import dextool.io : WriteStrategy;
19 
20 /** Control various aspectes of the analyze and generation like what nodes to
21  * process.
22  */
23 @safe interface Controller {
24     /// Query the controller with the filename of the AST node for a decision
25     /// if it shall be processed.
26     bool doFile(in string filename, in string info);
27 
28     /** A list of includes for the test double header.
29      *
30      * Part of the controller because they are dynamic, may change depending on
31      * for example calls to doFile.
32      */
33     Path[] getIncludes();
34 
35     // TODO Move the doXXX to Parameters
36 
37     /// If any google mocks are generated.
38     bool doGoogleMock();
39 
40     /// If pretty print functions for google test are generated.
41     bool doGoogleTestPODPrettyPrint();
42 
43     /// Generate a pre_include header file from internal template?
44     bool doPreIncludes();
45 
46     /// Generate a #include of the pre include header
47     bool doIncludeOfPreIncludes();
48 
49     /// Generate a post_include header file from internal template?
50     bool doPostIncludes();
51 
52     /// Generate a #include of the post include header
53     bool doIncludeOfPostIncludes();
54 
55     /// Generate test doubles of free functions
56     bool doFreeFunction();
57 }
58 
59 /** Parameters used during generation.
60  *
61  * Important aspact that they do NOT change, therefore it is pure.
62  */
63 @safe pure interface Parameters {
64     /// Source files used to generate the stub.
65     Path[] getIncludes();
66 
67     /// Name affecting interface, namespace and output file.
68     MainName getMainName();
69 
70     /** Namespace for the generated test double.
71      *
72      * Contains the adapter, C++ interface, gmock etc.
73      */
74     MainNs getMainNs();
75 
76     /** Name of the interface of the test double.
77      *
78      * Used in Adapter.
79      */
80     MainInterface getMainInterface();
81 
82     /// Prefix used for test artifacts.
83     StubPrefix getArtifactPrefix();
84 
85     /// Dextool Tool version.
86     DextoolVersion getToolVersion();
87 
88     /// Custom header to prepend generated files with.
89     CustomHeader getCustomHeader();
90 }
91 
92 /// Data produced by the generator like files.
93 @safe interface Products {
94     /** Data pushed from the generator to be written to files.
95      *
96      * The put value is the code generation tree. It allows the caller of
97      * Generator to inject more data in the tree before writing. For example a
98      * custom header.
99      *
100      * Params:
101      *   fname = file the content is intended to be written to.
102      *   hdr_data = data to write to the file.
103      */
104     void putFile(AbsolutePath fname, CppHModule hdr_data);
105 
106     /// ditto.
107     void putFile(AbsolutePath fname, CppHModule impl_data, WriteStrategy strategy);
108 
109     /// ditto.
110     void putFile(AbsolutePath fname, CppModule impl_data);
111 
112     /** During the translation phase the location of symbols that aren't
113      * filtered out are pushed to the variant.
114      *
115      * It is intended that the variant control the #include directive strategy.
116      * Just the files that was input?
117      * Deduplicated list of files where the symbols was found?
118      */
119     void putLocation(Path loc, LocationType type);
120 }
121 
122 /** Transformations that are governed by user input or other factors the
123  * backend is unaware of.
124  */
125 @safe interface Transform {
126     /// Returns: the transformed name to a filename suitable for a header.
127     AbsolutePath createHeaderFile(string name);
128 
129     /// Returns: the transformed name to a filename suitable for an implementation.
130     AbsolutePath createImplFile(string name);
131 
132     /// Returns: path to a xml file.
133     AbsolutePath createXmlFile(string name);
134 }