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