Push operator lookup into SourceFile, and simplify the interface.

The operator lookup cache already lived in SourceFile, but we need to be
able to look up operators on a per-SourceFile basis. Different files can
have different imports. The interface previously distinguished between
"no operator found" and "error", but none of the call sites were making
use of this distinction, and indeed some were misusing the return value
(Optional<SomeOperatorDecl *>). Now the lookup functions just return
operator decl pointers, which may be null.

Swift SVN r9668
This commit is contained in:
Jordan Rose
2013-10-25 17:30:33 +00:00
parent 918d66d6e7
commit cf31df96c5
5 changed files with 137 additions and 141 deletions

View File

@@ -186,28 +186,18 @@ public:
LazyResolver *typeResolver,
SmallVectorImpl<ValueDecl *> &decls);
/// Look up an InfixOperatorDecl for the given operator
/// name in this module (which must be NameBound) and return it, or return
/// null if there is no operator decl. Returns Nothing if there was an error
/// resolving the operator name (such as if there were conflicting importing
/// operator declarations).
Optional<InfixOperatorDecl *> lookupInfixOperator(Identifier name,
SourceLoc diagLoc = SourceLoc());
/// Look up an PrefixOperatorDecl for the given operator
/// name in this module (which must be NameBound) and return it, or return
/// null if there is no operator decl. Returns Nothing if there was an error
/// resolving the operator name (such as if there were conflicting importing
/// operator declarations).
Optional<PrefixOperatorDecl *> lookupPrefixOperator(Identifier name,
SourceLoc diagLoc = SourceLoc());
/// Look up an PostfixOperatorDecl for the given operator
/// name in this module (which must be NameBound) and return it, or return
/// null if there is no operator decl. Returns Nothing if there was an error
/// resolving the operator name (such as if there were conflicting importing
/// operator declarations).
Optional<PostfixOperatorDecl *> lookupPostfixOperator(Identifier name,
SourceLoc diagLoc = SourceLoc());
/// @{
/// Look up the given operator in this module.
///
/// If the operator is not found, or if there is an ambiguity, returns null.
InfixOperatorDecl *lookupInfixOperator(Identifier name,
SourceLoc diagLoc = {});
PrefixOperatorDecl *lookupPrefixOperator(Identifier name,
SourceLoc diagLoc = {});
PostfixOperatorDecl *lookupPostfixOperator(Identifier name,
SourceLoc diagLoc = {});
/// @}
/// Finds all class members defined in this module.
///
@@ -435,6 +425,20 @@ public:
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;
const SmallVectorImpl<ValueDecl *> &getCachedVisibleDecls() const;
/// @{
/// Look up the given operator in this file.
///
/// The file must be name-bound already. If the operator is not found, or if
/// there is an ambiguity, returns null.
InfixOperatorDecl *lookupInfixOperator(Identifier name,
SourceLoc diagLoc = {});
PrefixOperatorDecl *lookupPrefixOperator(Identifier name,
SourceLoc diagLoc = {});
PostfixOperatorDecl *lookupPostfixOperator(Identifier name,
SourceLoc diagLoc = {});
/// @}
/// \brief The buffer ID for the file that was imported as this TU, or Nothing
/// if this is not an imported TU.
Optional<unsigned> getImportBufferID() const {