Files
swift-mirror/include/swift/AST/SynthesizedFileUnit.h
Dan Zheng f7a9eed4de [AutoDiff] Add generated implicit declarations to SynthesizedFileUnit.
Add implicit declarations generated by the differentiation transform to a
`SynthesizedFileUnit` instead of an ad-hoc pre-existing `SourceFile`.

Resolves TF-1232: type reconstruction for AutoDiff-generated declarations.

Previously, type reconstruction failed because retroactively adding declarations
to a `SourceFile` did not update name lookup caches.
2020-04-07 18:29:34 -07:00

64 lines
2.0 KiB
C++

//===--- SynthesizedFileUnit.h - A synthesized file unit --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_AST_SYNTHESIZEDFILEUNIT_H
#define SWIFT_AST_SYNTHESIZEDFILEUNIT_H
#include "swift/AST/FileUnit.h"
#include "swift/Basic/Debug.h"
namespace swift {
/// A container for synthesized module-level declarations.
class SynthesizedFileUnit final : public FileUnit {
/// Synthesized top level declarations.
TinyPtrVector<ValueDecl *> TopLevelDecls;
/// A unique identifier representing this file; used to mark private decls
/// within the file to keep them from conflicting with other files in the
/// same module.
mutable Identifier PrivateDiscriminator;
public:
SynthesizedFileUnit(ModuleDecl &M);
~SynthesizedFileUnit() = default;
/// Add a synthesized top-level declaration.
void addTopLevelDecl(ValueDecl *D) { TopLevelDecls.push_back(D); }
virtual void lookupValue(DeclName name, NLKind lookupKind,
SmallVectorImpl<ValueDecl *> &result) const override;
void lookupObjCMethods(
ObjCSelector selector,
SmallVectorImpl<AbstractFunctionDecl *> &results) const override;
Identifier getDiscriminatorForPrivateValue(const ValueDecl *D) const override;
void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;
ArrayRef<ValueDecl *> getTopLevelDecls() const {
return TopLevelDecls;
};
static bool classof(const FileUnit *file) {
return file->getKind() == FileUnitKind::Synthesized;
}
static bool classof(const DeclContext *DC) {
return isa<FileUnit>(DC) && classof(cast<FileUnit>(DC));
}
};
} // namespace swift
#endif // SWIFT_AST_SYNTHESIZEDFILEUNIT_H