# HG changeset patch # User Aziz K?ksal # Date 1200274574 -3600 # Node ID 05645f5613c13de267bb22e08d8de66c6e7d3e15 # Parent 1b1315ac27a406ad587a6adfa6a577a6a0f7a921 Added an error message. Improved parseTryStatement(). Fixed getShortClassName(). diff -r 1b1315ac27a4 -r 05645f5613c1 trunk/src/cmd/Generate.d --- a/trunk/src/cmd/Generate.d Mon Jan 14 01:45:44 2008 +0100 +++ b/trunk/src/cmd/Generate.d Mon Jan 14 02:36:14 2008 +0100 @@ -102,18 +102,36 @@ suffixLength = "Declaration".length; break; case NC.Statement: - if (node.kind == NodeKind.Statements) + switch (node.kind) + { + case NodeKind.Statements, + NodeKind.CatchBody, + NodeKind.FinallyBody, + NodeKind.AsmInstruction, + NodeKind.IllegalAsmInstruction: break; - suffixLength = "Statement".length; + default: + suffixLength = "Statement".length; + } break; case NC.Expression: - suffixLength = "Expression".length; + switch (node.kind) + { + case NodeKind.VoidInitializer, + NodeKind.ArrayInitializer, + NodeKind.StructInitializer: + break; + default: + suffixLength = "Expression".length; + } break; case NC.Type: suffixLength = "Type".length; break; case NC.Other: + break; default: + assert(0); } // Remove common suffix. name = name[0 .. $ - suffixLength]; diff -r 1b1315ac27a4 -r 05645f5613c1 trunk/src/dil/Messages.d --- a/trunk/src/dil/Messages.d Mon Jan 14 01:45:44 2008 +0100 +++ b/trunk/src/dil/Messages.d Mon Jan 14 02:36:14 2008 +0100 @@ -135,6 +135,7 @@ auto ExpectedAliasTemplateParam = "expected name for alias template parameter, not '{}'"; auto ExpectedNameForThisTempParam = "expected name for 'this' template parameter, not '{}'"; auto ExpectedIdentOrInt = "expected an identifier or an integer, not '{}'"; + auto MissingCatchOrFinally = "try statement is missing a catch or finally body."; // Semantic analysis: auto DeclConflictsWithDecl = "declaration '{}' conflicts with declaration @{}"; auto VariableConflictsWithDecl = "variable '{}' conflicts with declaration @{}"; diff -r 1b1315ac27a4 -r 05645f5613c1 trunk/src/dil/ast/NodesEnum.d --- a/trunk/src/dil/ast/NodesEnum.d Mon Jan 14 01:45:44 2008 +0100 +++ b/trunk/src/dil/ast/NodesEnum.d Mon Jan 14 02:36:14 2008 +0100 @@ -4,7 +4,7 @@ +/ module dil.ast.NodesEnum; -enum NodeCategory +enum NodeCategory : ushort { Declaration, Statement, @@ -60,7 +60,6 @@ "ExpressionStatement", "DeclarationStatement", "IfStatement", -// "ConditionalStatement", "WhileStatement", "DoWhileStatement", "ForStatement", @@ -225,7 +224,7 @@ // enum NodeKind; mixin( - "enum NodeKind" + "enum NodeKind : ushort" "{" ~ generateNodeKindMembers ~ "}" diff -r 1b1315ac27a4 -r 05645f5613c1 trunk/src/dil/parser/Parser.d --- a/trunk/src/dil/parser/Parser.d Mon Jan 14 01:45:44 2008 +0100 +++ b/trunk/src/dil/parser/Parser.d Mon Jan 14 02:36:14 2008 +0100 @@ -2096,6 +2096,7 @@ Statement parseTryStatement() { assert(token.type == T.Try); + auto begin = token; nT(); auto tryBody = parseScopeStatement(); @@ -2107,30 +2108,24 @@ Parameter param; if (skipped(T.LParen)) { - auto begin = token; + auto begin2 = token; Identifier* ident; auto type = parseDeclarator(ident, true); param = new Parameter(StorageClass.None, type, ident, null); - set(param, begin); + set(param, begin2); require(T.RParen); } - catchBodies ~= new CatchBody(param, parseNoScopeStatement()); + catchBodies ~= set(new CatchBody(param, parseNoScopeStatement()), begin); if (param is null) break; // This is a LastCatch + begin = token; } - if (token.type == T.Finally) - { - auto begin = token; - nT(); - finBody = new FinallyBody(parseNoScopeStatement()); - set(finBody, begin); - } + if (skipped(T.Finally)) + finBody = set(new FinallyBody(parseNoScopeStatement()), prevToken); if (catchBodies.length == 0 && finBody is null) - { - // TODO: issue error msg. - } + assert(begin.type == T.Try), error(begin, MSG.MissingCatchOrFinally); return new TryStatement(tryBody, catchBodies, finBody); }