convert parseType to take a DiagID.

Swift SVN r762
This commit is contained in:
Chris Lattner
2011-10-20 19:53:00 +00:00
parent f149ab5527
commit 96f732b6a2
5 changed files with 22 additions and 10 deletions

View File

@@ -86,6 +86,8 @@ ERROR(decl_expected_module_name,decl_parsing,none,
"expected module name in import declaration", ()) "expected module name in import declaration", ())
// TypeAlias // TypeAlias
ERROR(expected_type_in_typealias,decl_parsing,none,
"expected type in var declaration", ())
// Func // Func
ERROR(func_decl_without_paren,decl_parsing,none, ERROR(func_decl_without_paren,decl_parsing,none,
@@ -102,12 +104,24 @@ ERROR(struct_not_tuple,decl_parsing,none,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Type parsing diagnostics // Type parsing diagnostics
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
ERROR(expected_type,type_parsing,none,
"expected type", ())
ERROR(expected_type_function_result,type_parsing,none,
"expected type for function result", ())
// oneof Types
ERROR(duplicate_oneof_element,type_parsing,none, ERROR(duplicate_oneof_element,type_parsing,none,
"duplicate definition of element '%0'", (StringRef)) "duplicate definition of element '%0'", (StringRef))
ERROR(expected_type_oneof_element,type_parsing,none,
"expected type while parsing oneof element", ())
// Array Types
ERROR(non_constant_array,type_parsing,none, ERROR(non_constant_array,type_parsing,none,
"array has non-constant size", ()) "array has non-constant size", ())
ERROR(zero_length_array,type_parsing,none, ERROR(zero_length_array,type_parsing,none,
"array has length zero", ()) "array has length zero", ())
ERROR(expected_protocol_member,type_parsing,none, ERROR(expected_protocol_member,type_parsing,none,
"expected a function or variable declaration in protocol", ()) "expected a function or variable declaration in protocol", ())
ERROR(type_redefinition,type_parsing,none, ERROR(type_redefinition,type_parsing,none,

View File

@@ -262,7 +262,7 @@ TypeAliasDecl *Parser::parseDeclTypeAlias() {
Type Ty; Type Ty;
if (parseIdentifier(Id, diags::expected_identifier_in_decl, "typealias") || if (parseIdentifier(Id, diags::expected_identifier_in_decl, "typealias") ||
parseToken(tok::colon, "expected ':' in typealias declaration") || parseToken(tok::colon, "expected ':' in typealias declaration") ||
parseType(Ty, "expected type in var declaration")) parseType(Ty, diags::expected_type_in_typealias))
return 0; return 0;
return ScopeInfo.addTypeAliasToScope(TypeAliasLoc, Id, Ty); return ScopeInfo.addTypeAliasToScope(TypeAliasLoc, Id, Ty);

View File

@@ -21,7 +21,7 @@
using namespace swift; using namespace swift;
bool Parser::parseType(Type &Result) { bool Parser::parseType(Type &Result) {
return parseType(Result, "expected type"); return parseType(Result, diags::expected_type);
} }
/// parseType /// parseType
@@ -43,7 +43,7 @@ bool Parser::parseType(Type &Result) {
/// identifier /// identifier
/// scope-qualifier identifier /// scope-qualifier identifier
/// ///
bool Parser::parseType(Type &Result, const Twine &Message) { bool Parser::parseType(Type &Result, Diag<> MessageID) {
// Parse type-simple first. // Parse type-simple first.
switch (Tok.getKind()) { switch (Tok.getKind()) {
case tok::identifier: { case tok::identifier: {
@@ -87,7 +87,7 @@ bool Parser::parseType(Type &Result, const Twine &Message) {
return true; return true;
break; break;
default: default:
error(Tok.getLoc(), Message); diagnose(Tok.getLoc(), MessageID);
return true; return true;
} }
@@ -96,7 +96,7 @@ bool Parser::parseType(Type &Result, const Twine &Message) {
SourceLoc TokLoc = Tok.getLoc(); SourceLoc TokLoc = Tok.getLoc();
if (consumeIf(tok::arrow)) { if (consumeIf(tok::arrow)) {
Type SecondHalf; Type SecondHalf;
if (parseType(SecondHalf, "expected type in result of function type")) if (parseType(SecondHalf, diags::expected_type_function_result))
return true; return true;
Result = FunctionType::get(Result, SecondHalf, Context); Result = FunctionType::get(Result, SecondHalf, Context);
continue; continue;
@@ -221,9 +221,7 @@ bool Parser::parseTypeOneOfBody(SourceLoc OneOfLoc, const DeclAttributes &Attrs,
// See if we have a type specifier for this oneof element. If so, parse it. // See if we have a type specifier for this oneof element. If so, parse it.
if (consumeIf(tok::colon) && if (consumeIf(tok::colon) &&
parseType(ElementInfo.EltType, parseType(ElementInfo.EltType, diags::expected_type_oneof_element)) {
"expected type while parsing oneof element '" +
ElementInfo.Name + "'")) {
skipUntil(tok::r_brace); skipUntil(tok::r_brace);
return true; return true;
} }

View File

@@ -133,7 +133,7 @@ bool Parser::parseValueSpecifier(Type &Ty, NullablePtr<Expr> &Init,
// Parse the type if present. // Parse the type if present.
if (consumeIf(tok::colon) && if (consumeIf(tok::colon) &&
parseType(Ty, "expected type in var declaration")) parseType(Ty, diags::expected_type))
return true; return true;
// Parse the initializer, if present. // Parse the initializer, if present.

View File

@@ -189,7 +189,7 @@ public:
// Type Parsing // Type Parsing
bool parseType(Type &Result); bool parseType(Type &Result);
bool parseType(Type &Result, const Twine &Message); bool parseType(Type &Result, Diag<> ID);
bool parseTypeTupleBody(SourceLoc LPLoc, Type &Result); bool parseTypeTupleBody(SourceLoc LPLoc, Type &Result);
bool parseTypeOneOf(Type &Result); bool parseTypeOneOf(Type &Result);