[SILParser] fix a few issues to enable parsing of sil from swift array

Add PrintForSIL in PrintOptions
1> for NameAliasType, we print getSinglyDesugaredType()
I attempted another option: set FullyQualifiedTypes of PrintOptions, but that
will print xxx.Type.xxx and Parser can’t handle it.
2> for Self, we print @sil_self

We also work around parsing:
sil_witness_table _CocoaArrayType: _CocoaArrayType

sil_vtable uses internal classes in stdlib, so we use lookupTopDecl instead
of lookupValue when parsing sil_vtable, to find internal classes.

Fix rdar://17261925 rdar://17295316 rdar://17046276 rdar://17579890


Swift SVN r20070
This commit is contained in:
Manman Ren
2014-07-17 04:43:24 +00:00
parent 61df8d7f1f
commit 1bd9d81971
13 changed files with 73 additions and 38 deletions

View File

@@ -3101,15 +3101,15 @@ bool Parser::parseSILVTable() {
return true;
// Find the class decl.
SmallVector<ValueDecl*, 4> CurModuleResults;
SF.getParentModule()->lookupValue(Module::AccessPathTy(), Name,
NLKind::UnqualifiedLookup,
CurModuleResults);
if (CurModuleResults.size() != 1) {
llvm::PointerUnion<ValueDecl*, Module *> Res = lookupTopDecl(*this, Name);
assert(Res.is<ValueDecl*>() && "Class look-up should return a Decl");
ValueDecl *VD = Res.get<ValueDecl*>();
if (!VD) {
diagnose(Loc, diag::sil_vtable_class_not_found, Name);
return true;
}
ClassDecl *theClass = dyn_cast<ClassDecl>(CurModuleResults[0]);
ClassDecl *theClass = dyn_cast<ClassDecl>(VD);
if (!theClass) {
diagnose(Loc, diag::sil_vtable_class_not_found, Name);
return true;
@@ -3203,6 +3203,11 @@ static NormalProtocolConformance *parseNormalProtocolConformance(Parser &P,
return nullptr;
}
// FIXME: we currently emit _CocoaArrayType: _CocoaArrayType.
if (ConformingTy->is<ProtocolType>() &&
ConformingTy->getAs<ProtocolType>()->getDecl() == proto)
return nullptr;
// Calling lookupConformance on a BoundGenericType will return a specialized
// conformance. We use UnboundGenericType to find the normal conformance.
Type lookupTy = ConformingTy;
@@ -3211,10 +3216,16 @@ static NormalProtocolConformance *parseNormalProtocolConformance(Parser &P,
P.Context);
auto lookup = P.SF.getParentModule()->lookupConformance(
lookupTy, proto, nullptr);
if (!lookup.getPointer()) {
P.diagnose(KeywordLoc, diag::sil_witness_protocol_conformance_not_found);
return nullptr;
}
NormalProtocolConformance *theConformance =
dyn_cast<NormalProtocolConformance>(lookup.getPointer());
if (!theConformance)
if (!theConformance) {
P.diagnose(KeywordLoc, diag::sil_witness_protocol_conformance_not_found);
return nullptr;
}
return theConformance;
}
@@ -3411,24 +3422,27 @@ bool Parser::parseSILWitnessTable() {
ArchetypeBuilder builder(*SF.getParentModule(), Diags);
auto conf = WitnessState.parseProtocolConformance(proto, dummy, builder,
false/*localScope*/);
if (!conf) {
diagnose(Tok, diag::sil_witness_protocol_conformance_not_found);
return true;
}
NormalProtocolConformance *theConformance =
dyn_cast<NormalProtocolConformance>(conf);
NormalProtocolConformance *theConformance = conf ?
dyn_cast<NormalProtocolConformance>(conf) : nullptr;
// If we don't have an lbrace, then this witness table is a declaration.
if (Tok.getKind() != tok::l_brace) {
// Default to public external linkage.
if (!Linkage)
Linkage = SILLinkage::PublicExternal;
SILWitnessTable::create(*SIL->M, *Linkage, theConformance);
// We ignore empty witness table without normal protocol conformance.
if (theConformance)
SILWitnessTable::create(*SIL->M, *Linkage, theConformance);
BodyScope.reset();
return false;
}
if (!theConformance) {
diagnose(Tok, diag::sil_witness_protocol_conformance_not_found);
return true;
}
SourceLoc LBraceLoc = Tok.getLoc();
consumeToken(tok::l_brace);