remove support for looking up global names with dot syntax. "x.y" != "y(x)" now.

Swift SVN r917
This commit is contained in:
Chris Lattner
2011-12-07 00:59:09 +00:00
parent be5120b180
commit a1b7419a36
6 changed files with 3 additions and 63 deletions

View File

@@ -411,11 +411,6 @@ class UnresolvedDotExpr : public Expr {
SourceLoc DotLoc; SourceLoc DotLoc;
Identifier Name; Identifier Name;
SourceLoc NameLoc; SourceLoc NameLoc;
/// ResolvedDecl - If the name refers to any local or top-level declarations,
/// the name binder fills them in here.
ArrayRef<ValueDecl*> ResolvedDecls;
public: public:
UnresolvedDotExpr(Expr *subexpr, SourceLoc dotloc, Identifier name, UnresolvedDotExpr(Expr *subexpr, SourceLoc dotloc, Identifier name,
SourceLoc nameloc) SourceLoc nameloc)
@@ -441,12 +436,6 @@ public:
Identifier getName() const { return Name; } Identifier getName() const { return Name; }
SourceLoc getNameLoc() const { return NameLoc; } SourceLoc getNameLoc() const { return NameLoc; }
ArrayRef<ValueDecl*> getResolvedDecls() const { return ResolvedDecls; }
void setResolvedDecls(ArrayRef<ValueDecl*> Decls) {
assert(ResolvedDecls.empty());
ResolvedDecls = Decls;
}
// Implement isa/cast/dyncast/etc. // Implement isa/cast/dyncast/etc.
static bool classof(const UnresolvedDotExpr *) { return true; } static bool classof(const UnresolvedDotExpr *) { return true; }
static bool classof(const Expr *E) { static bool classof(const Expr *E) {

View File

@@ -37,8 +37,7 @@ namespace swift {
/// by various query methods. /// by various query methods.
enum class NLKind { enum class NLKind {
UnqualifiedLookup, UnqualifiedLookup,
QualifiedLookup, QualifiedLookup
DotLookup
}; };
/// Module - A unit of modularity. The current translation unit is a /// Module - A unit of modularity. The current translation unit is a

View File

@@ -723,9 +723,6 @@ public:
void visitUnresolvedDotExpr(UnresolvedDotExpr *E) { void visitUnresolvedDotExpr(UnresolvedDotExpr *E) {
OS.indent(Indent) << "(unresolved_dot_expr type='" << E->getType(); OS.indent(Indent) << "(unresolved_dot_expr type='" << E->getType();
OS << "\' field '" << E->getName().str() << "'"; OS << "\' field '" << E->getName().str() << "'";
if (!E->getResolvedDecls().empty())
OS << " decl resolved to " << E->getResolvedDecls().size()
<< " candidate(s)!";
if (E->getBase()) { if (E->getBase()) {
OS << '\n'; OS << '\n';
printRec(E->getBase()); printRec(E->getBase());

View File

@@ -157,13 +157,8 @@ void TUModuleCache::lookupValue(AccessPathTy AccessPath, Identifier Name,
if (I == TopLevelValues.end()) return; if (I == TopLevelValues.end()) return;
Result.reserve(I->second.size()); Result.reserve(I->second.size());
for (ValueDecl *Elt : I->second) { for (ValueDecl *Elt : I->second)
// Dot Lookup ignores values with non-function types.
if (LookupKind == NLKind::DotLookup && !Elt->getType()->is<FunctionType>())
continue;
Result.push_back(Elt); Result.push_back(Elt);
}
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@@ -217,23 +217,10 @@ static Expr *BindNames(Expr *E, WalkOrder Order, NameBinder &Binder) {
if (Order == WalkOrder::PreOrder) if (Order == WalkOrder::PreOrder)
return E; return E;
// A reference to foo.bar may be an application ("bar foo"), so look up bar.
// It may also be a tuple field reference, so don't report an error here if we
// don't find anything juicy.
if (UnresolvedDotExpr *UDE = dyn_cast<UnresolvedDotExpr>(E)) {
SmallVector<ValueDecl*, 4> Decls;
// Perform .-style name lookup.
Binder.TU->lookupGlobalValue(UDE->getName(), NLKind::DotLookup, Decls);
// Copy the overload set into ASTContext memory.
if (!Decls.empty())
UDE->setResolvedDecls(Binder.Context.AllocateCopy(Decls));
return UDE;
}
Identifier Name; Identifier Name;
SourceLoc Loc; SourceLoc Loc;
SmallVector<ValueDecl*, 4> Decls; SmallVector<ValueDecl*, 4> Decls;
// Process UnresolvedDeclRefExpr by doing an unqualified lookup. // Process UnresolvedDeclRefExpr by doing an unqualified lookup.
if (UnresolvedDeclRefExpr *UDRE = dyn_cast<UnresolvedDeclRefExpr>(E)) { if (UnresolvedDeclRefExpr *UDRE = dyn_cast<UnresolvedDeclRefExpr>(E)) {
Name = UDRE->getName(); Name = UDRE->getName();

View File

@@ -439,33 +439,6 @@ Expr *SemaExpressionTree::visitUnresolvedDotExpr(UnresolvedDotExpr *E) {
return Call; return Call;
} }
// Next, check to see if "a.f" is actually being used as sugar for "f a",
// which is a function application of 'a' to 'f'.
if (!E->getResolvedDecls().empty()) {
assert(E->getResolvedDecls()[0]->getType()->is<FunctionType>() &&
"Should have only bound to functions");
Expr *FnRef;
// Apply the base value to the function there is a single candidate in the
// set then this is directly resolved, otherwise it is an overload case.
if (E->getResolvedDecls().size() == 1)
FnRef = new (TC.Context) DeclRefExpr(E->getResolvedDecls()[0],
E->getNameLoc(),
E->getResolvedDecls()[0]->getTypeJudgement());
else {
FnRef = new (TC.Context) OverloadSetRefExpr(E->getResolvedDecls(),
E->getNameLoc());
FnRef->setDependentType(DependentType::get(TC.Context));
}
CallExpr *Call = new (TC.Context) CallExpr(FnRef, Base,
/*DotSyntax=*/true,
TypeJudgement());
if (TC.semaApplyExpr(Call))
return 0;
return Call;
}
// If this is a member access to a oneof with a single element constructor // If this is a member access to a oneof with a single element constructor
// (e.g. a struct), allow direct access to the type underlying the single // (e.g. a struct), allow direct access to the type underlying the single
// element. // element.