|
| 1 | +//===----- AbstractSourceFileDepGraphFactory.h ----------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef SWIFT_AST_SOURCE_FILE_DEP_GRAPH_CONSTRUCTOR_H |
| 14 | +#define SWIFT_AST_SOURCE_FILE_DEP_GRAPH_CONSTRUCTOR_H |
| 15 | + |
| 16 | +#include "swift/AST/DeclContext.h" |
| 17 | +#include "swift/AST/FineGrainedDependencies.h" |
| 18 | + |
| 19 | +namespace swift { |
| 20 | +class DiagnosticEngine; |
| 21 | +namespace fine_grained_dependencies { |
| 22 | + |
| 23 | +/// Abstract class for building a \c SourceFileDepGraph from either a real |
| 24 | +/// \c SourceFile or a unit test |
| 25 | +class AbstractSourceFileDepGraphFactory { |
| 26 | +protected: |
| 27 | + /// To match the existing system, set this to false. |
| 28 | + /// To include even private entities and get intra-file info, set to true. |
| 29 | + const bool includePrivateDeps; |
| 30 | + |
| 31 | + /// If there was an error, cannot get accurate info. |
| 32 | + const bool hadCompilationError; |
| 33 | + |
| 34 | + /// The name of the swiftDeps file. |
| 35 | + const std::string swiftDeps; |
| 36 | + |
| 37 | + /// The fingerprint of the whole file |
| 38 | + const std::string fileFingerprint; |
| 39 | + |
| 40 | + /// For debugging |
| 41 | + const bool emitDotFileAfterConstruction; |
| 42 | + |
| 43 | + DiagnosticEngine &diags; |
| 44 | + |
| 45 | + /// Graph under construction |
| 46 | + SourceFileDepGraph g; |
| 47 | + |
| 48 | +public: |
| 49 | + /// Expose this layer to enable faking up a constructor for testing. |
| 50 | + /// See the instance variable comments for explanation. |
| 51 | + AbstractSourceFileDepGraphFactory(bool includePrivateDeps, |
| 52 | + bool hadCompilationError, |
| 53 | + StringRef swiftDeps, |
| 54 | + StringRef fileFingerprint, |
| 55 | + bool emitDotFileAfterConstruction, |
| 56 | + DiagnosticEngine &diags); |
| 57 | + |
| 58 | + virtual ~AbstractSourceFileDepGraphFactory() = default; |
| 59 | + |
| 60 | + /// Create a SourceFileDepGraph. |
| 61 | + SourceFileDepGraph construct(); |
| 62 | + |
| 63 | +private: |
| 64 | + void addSourceFileNodesToGraph(); |
| 65 | + |
| 66 | + /// Add the "provides" nodes when mocking up a graph |
| 67 | + virtual void addAllDefinedDecls() = 0; |
| 68 | + |
| 69 | + /// Add the "depends" nodes and arcs when mocking a graph |
| 70 | + virtual void addAllUsedDecls() = 0; |
| 71 | + |
| 72 | +protected: |
| 73 | + /// Add an pair of interface, implementation nodes to the graph, which |
| 74 | + /// represent some \c Decl defined in this source file. \param key the |
| 75 | + /// interface key of the pair |
| 76 | + void addADefinedDecl(const DependencyKey &key, |
| 77 | + Optional<StringRef> fingerprint); |
| 78 | + |
| 79 | + void addAUsedDecl(const DependencyKey &def, const DependencyKey &use); |
| 80 | +}; |
| 81 | + |
| 82 | +} // namespace fine_grained_dependencies |
| 83 | +} // namespace swift |
| 84 | + |
| 85 | +#endif // SWIFT_AST_SOURCE_FILE_DEP_GRAPH_CONSTRUCTOR_H |
0 commit comments