Files
swift-mirror/include/swift/AST/Substitution.h
Doug Gregor b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00

104 lines
3.6 KiB
C++

//===--- Substitution.h - Swift Generic Substitution ASTs -------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines the Substitution class.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_SUBSTITUTION_H
#define SWIFT_AST_SUBSTITUTION_H
#include "swift/AST/Type.h"
#include "llvm/ADT/ArrayRef.h"
namespace llvm {
class raw_ostream;
}
namespace swift {
class ArchetypeType;
class ProtocolConformance;
/// DenseMap type used internally by Substitution::subst to track conformances
/// applied to archetypes.
using ArchetypeConformanceMap
= llvm::DenseMap<ArchetypeType*, ArrayRef<ProtocolConformance*>>;
/// Substitution - A substitution into a generic specialization.
class Substitution {
ArchetypeType * Archetype = nullptr;
Type Replacement;
ArrayRef<ProtocolConformance *> Conformance;
public:
/// FIXME: An archetype that looks like the archetype or dependent generic
/// parameter type that should be substituted by this substitution, but
/// which is not guaranteed to map to any particular context. All that is
/// guaranteed:
///
/// - Archetype will conform to the same protocols as the substituted
/// type.
/// - Archetype will appear at the same point in the generic parameter
/// hierarchy as the substituted type; that is, if the substituted type
/// is a generic parameter, it will be a primary archetype, or if the
/// substituted type is a dependent member type, it will be a nested
/// archetype with the same name path--if T0.Foo.Bar is being substituted,
/// this will be some archetype X.Foo.Bar.
/// - If the substituted type represents a Self or associated type of a
/// protocol requirement, this Archetype will be that archetype from the
/// protocol context.
///
/// You really shouldn't use the value of this field for anything new.
ArchetypeType *getArchetype() const { return Archetype; }
/// The replacement type.
Type getReplacement() const { return Replacement; }
/// The protocol conformances for the replacement. These appear in the same
/// order as Archetype->getConformsTo() for the substituted archetype.
const ArrayRef<ProtocolConformance *> getConformances() const {
return Conformance;
}
Substitution() {}
Substitution(ArchetypeType *Archetype,
Type Replacement,
ArrayRef<ProtocolConformance*> Conformance);
bool operator!=(const Substitution &other) const { return !(*this == other); }
bool operator==(const Substitution &other) const;
void print(llvm::raw_ostream &os,
const PrintOptions &PO = PrintOptions()) const;
void dump() const;
/// Substitute the replacement and conformance types with the given
/// substitution vector.
Substitution subst(ModuleDecl *module,
GenericParamList *context,
ArrayRef<Substitution> subs) const;
private:
friend class ProtocolConformance;
Substitution subst(ModuleDecl *module,
ArrayRef<Substitution> subs,
TypeSubstitutionMap &subMap,
ArchetypeConformanceMap &conformanceMap) const;
};
void dump(const ArrayRef<Substitution> &subs);
} // end namespace swift
#endif