Mercurial > projects > dil
changeset 640:05645f5613c1
Added an error message.
Improved parseTryStatement().
Fixed getShortClassName().
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 14 Jan 2008 02:36:14 +0100 |
parents | 1b1315ac27a4 |
children | 3569c2fc6124 |
files | trunk/src/cmd/Generate.d trunk/src/dil/Messages.d trunk/src/dil/ast/NodesEnum.d trunk/src/dil/parser/Parser.d |
diffstat | 4 files changed, 32 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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];
--- 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 @{}";
--- 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 ~ "}"
--- 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); }