13
13
#ifndef SWIFT_AST_FINE_GRAINED_DEPENDENCIES_H
14
14
#define SWIFT_AST_FINE_GRAINED_DEPENDENCIES_H
15
15
16
+ #include " swift/AST/EvaluatorDependencies.h"
16
17
#include " swift/Basic/Debug.h"
17
18
#include " swift/Basic/Fingerprint.h"
18
19
#include " swift/Basic/LLVM.h"
57
58
// ==============================================================================
58
59
59
60
namespace swift {
61
+ class Decl ;
60
62
class DependencyTracker ;
61
63
class DiagnosticEngine ;
62
64
class FrontendOptions ;
63
65
class ModuleDecl ;
64
66
class SourceFile ;
67
+ class NominalTypeDecl ;
68
+ class ValueDecl ;
65
69
66
70
// / Use a new namespace to help keep the experimental code from clashing.
67
71
namespace fine_grained_dependencies {
@@ -417,6 +421,57 @@ class DependencyKey {
417
421
// For import/export
418
422
friend ::llvm::yaml::MappingTraits<DependencyKey>;
419
423
424
+ public:
425
+ class Builder {
426
+ private:
427
+ const NodeKind kind;
428
+ const DeclAspect aspect;
429
+ const NominalTypeDecl *context;
430
+ StringRef name;
431
+
432
+ private:
433
+ // A private copy constructor so our clients are forced to use the
434
+ // move-only builder interface.
435
+ explicit Builder (NodeKind kind, DeclAspect aspect,
436
+ const NominalTypeDecl *context, StringRef name)
437
+ : kind(kind), aspect(aspect), context(context), name(name) {}
438
+
439
+ public:
440
+ // / Creates a DependencyKey::Builder from the given \p kind and \p aspect
441
+ // / with a \c null context and empty name.
442
+ explicit Builder (NodeKind kind, DeclAspect aspect)
443
+ : kind(kind), aspect(aspect), context(nullptr ), name(" " ) {}
444
+
445
+ public:
446
+ // / Consumes this builder and returns a dependency key created from its
447
+ // / data.
448
+ DependencyKey build () &&;
449
+
450
+ public:
451
+ // / Extracts the data from the given \p ref into a this builder.
452
+ Builder fromReference (const evaluator::DependencyCollector::Reference &ref);
453
+
454
+ public:
455
+ // / Extracts the context data from the given declaration, if any.
456
+ Builder withContext (const Decl *D) &&;
457
+ // / Extracts the context data from the given decl-member pair, if any.
458
+ Builder withContext (std::pair<const NominalTypeDecl *, const ValueDecl *>
459
+ holderAndMember) &&;
460
+
461
+ public:
462
+ // / Copies the name data for the given swiftdeps file into this builder.
463
+ Builder withName (StringRef swiftDeps) &&;
464
+ // / Copies the name of the given declaration into this builder, if any.
465
+ Builder withName (const Decl *decl) &&;
466
+ // / Extracts the name from the given decl-member pair, if any.
467
+ Builder withName (std::pair<const NominalTypeDecl *, const ValueDecl *>
468
+ holderAndMember) &&;
469
+
470
+ private:
471
+ static StringRef getTopLevelName (const Decl *decl);
472
+ };
473
+
474
+ private:
420
475
NodeKind kind;
421
476
DeclAspect aspect;
422
477
// / The mangled context type name of the holder for \ref potentialMember, \ref
@@ -485,10 +540,6 @@ class DependencyKey {
485
540
template <NodeKind kind, typename Entity>
486
541
static DependencyKey createForProvidedEntityInterface (Entity);
487
542
488
- // / Given some type of provided entity compute the context field of the key.
489
- template <NodeKind kind, typename Entity>
490
- static std::string computeContextForProvidedEntity (Entity);
491
-
492
543
DependencyKey correspondingImplementation () const {
493
544
return withAspect (DeclAspect::implementation);
494
545
}
@@ -497,10 +548,6 @@ class DependencyKey {
497
548
return DependencyKey (kind, aspect, context, name);
498
549
}
499
550
500
- // / Given some type of provided entity compute the name field of the key.
501
- template <NodeKind kind, typename Entity>
502
- static std::string computeNameForProvidedEntity (Entity);
503
-
504
551
static DependencyKey createKeyForWholeSourceFile (DeclAspect,
505
552
StringRef swiftDeps);
506
553
0 commit comments