mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add a basic TypeLoc; start threading it through the parser.
Doug, please double-check that this is going in the right direction... Swift SVN r2146
This commit is contained in:
@@ -156,7 +156,7 @@ bool Parser::checkFullyTyped(Pattern *pattern, Type &funcTy) {
|
||||
/// func-signature-result:
|
||||
/// '->' type
|
||||
bool Parser::parseFunctionSignature(SmallVectorImpl<Pattern*> ¶ms,
|
||||
Type &type) {
|
||||
Type &type, TypeLoc *&loc) {
|
||||
// Parse curried function argument clauses as long as we can.
|
||||
do {
|
||||
NullablePtr<Pattern> pattern = parsePatternTuple();
|
||||
@@ -168,7 +168,7 @@ bool Parser::parseFunctionSignature(SmallVectorImpl<Pattern*> ¶ms,
|
||||
|
||||
// If there's a trailing arrow, parse the rest as the result type.
|
||||
if (consumeIf(tok::arrow)) {
|
||||
if (parseType(type))
|
||||
if (parseType(type, loc))
|
||||
return true;
|
||||
|
||||
checkFullyTyped(type);
|
||||
@@ -176,16 +176,17 @@ bool Parser::parseFunctionSignature(SmallVectorImpl<Pattern*> ¶ms,
|
||||
// Otherwise, we implicitly return ().
|
||||
} else {
|
||||
type = TupleType::getEmpty(Context);
|
||||
loc = nullptr;
|
||||
}
|
||||
|
||||
// Now build up the function type. We require all function
|
||||
// signatures to be fully-typed: that is, all top-down paths to a
|
||||
// leaf pattern must pass through a TypedPattern.
|
||||
return buildFunctionSignature(params, type);
|
||||
return buildFunctionSignature(params, type, loc);
|
||||
}
|
||||
|
||||
bool Parser::buildFunctionSignature(SmallVectorImpl<Pattern*> ¶ms,
|
||||
Type &type) {
|
||||
Type &type, TypeLoc *&loc) {
|
||||
// Now build up the function type. We require all function
|
||||
// signatures to be fully-typed: that is, all top-down paths to a
|
||||
// leaf pattern must pass through a TypedPattern.
|
||||
@@ -215,7 +216,8 @@ NullablePtr<Pattern> Parser::parsePattern() {
|
||||
// Now parse an optional type annotation.
|
||||
if (consumeIf(tok::colon)) {
|
||||
Type type;
|
||||
if (parseTypeAnnotation(type))
|
||||
TypeLoc *loc;
|
||||
if (parseTypeAnnotation(type, loc))
|
||||
return nullptr;
|
||||
|
||||
pattern = new (Context) TypedPattern(pattern.get(), type);
|
||||
|
||||
Reference in New Issue
Block a user