# HG changeset patch # User Aziz K?ksal # Date 1197668624 -3600 # Node ID 433d51c18524a7b835fbb7e4f1b0564658499f21 # Parent 7cb97346bc6fd1c7921744906506af733454a0c8 Renamed template Cast to TryCast. diff -r 7cb97346bc6f -r 433d51c18524 trunk/src/dil/Module.d --- a/trunk/src/dil/Module.d Fri Dec 14 20:12:13 2007 +0100 +++ b/trunk/src/dil/Module.d Fri Dec 14 22:43:44 2007 +0100 @@ -49,7 +49,7 @@ if (root.children.length) { // moduleDecl will be null if first node can't be cast to ModuleDeclaration. - this.moduleDecl = Cast!(ModuleDeclaration)(root.children[0]); + this.moduleDecl = TryCast!(ModuleDeclaration)(root.children[0]); if (moduleDecl) { this.setFQN(moduleDecl.getFQN()); diff -r 7cb97346bc6f -r 433d51c18524 trunk/src/dil/SettingsLoader.d --- a/trunk/src/dil/SettingsLoader.d Fri Dec 14 20:12:13 2007 +0100 +++ b/trunk/src/dil/SettingsLoader.d Fri Dec 14 22:43:44 2007 +0100 @@ -25,7 +25,7 @@ foreach (decl; modul.root.children) { - auto v = Cast!(VariableDeclaration)(decl); + auto v = TryCast!(VariableDeclaration)(decl); if (v is null) continue; @@ -37,29 +37,29 @@ switch (variableName) { case "langfile": - if (auto val = Cast!(StringExpression)(e)) + if (auto val = TryCast!(StringExpression)(e)) GlobalSettings.langFile = val.getString(); break; case "import_paths": - if (auto array = Cast!(ArrayInitializer)(e)) + if (auto array = TryCast!(ArrayInitializer)(e)) { foreach (value; array.values) - if (auto str = Cast!(StringExpression)(value)) + if (auto str = TryCast!(StringExpression)(value)) GlobalSettings.importPaths ~= str.getString(); } else throw new Exception("import_paths variable is set to "~e.classinfo.name~" instead of an ArrayInitializer."); break; case "lexer_error": - if (auto val = Cast!(StringExpression)(e)) + if (auto val = TryCast!(StringExpression)(e)) GlobalSettings.lexerErrorFormat = val.getString(); break; case "parser_error": - if (auto val = Cast!(StringExpression)(e)) + if (auto val = TryCast!(StringExpression)(e)) GlobalSettings.parserErrorFormat = val.getString(); break; case "semantic_error": - if (auto val = Cast!(StringExpression)(e)) + if (auto val = TryCast!(StringExpression)(e)) GlobalSettings.semanticErrorFormat = val.getString(); break; default: @@ -77,7 +77,7 @@ char[][] messages; foreach (decl; modul.root.children) { - auto v = Cast!(VariableDeclaration)(decl); + auto v = TryCast!(VariableDeclaration)(decl); if (v is null) continue; @@ -89,11 +89,11 @@ switch (variableName) { case "messages": - if (auto array = Cast!(ArrayInitializer)(e)) + if (auto array = TryCast!(ArrayInitializer)(e)) { foreach (value; array.values) { - if (auto str = Cast!(StringExpression)(value)) + if (auto str = TryCast!(StringExpression)(value)) messages ~= str.getString(); } } @@ -101,7 +101,7 @@ throw new Exception("messages variable is set to "~e.classinfo.name~" instead of an ArrayInitializer."); break; case "lang_code": - if (auto str = Cast!(StringExpression)(e)) + if (auto str = TryCast!(StringExpression)(e)) GlobalSettings.langCode = str.getString(); break; default: diff -r 7cb97346bc6f -r 433d51c18524 trunk/src/dil/SyntaxTree.d --- a/trunk/src/dil/SyntaxTree.d Fri Dec 14 20:12:13 2007 +0100 +++ b/trunk/src/dil/SyntaxTree.d Fri Dec 14 22:43:44 2007 +0100 @@ -220,7 +220,7 @@ /// This string is mixed into the constructor of a class that inherits from Node. const string set_kind = `this.kind = mixin("NodeKind." ~ typeof(this).stringof);`; -Class Cast(Class)(Node n) +Class TryCast(Class)(Node n) { assert(n !is null); if (n.kind == mixin("NodeKind." ~ typeof(Class).stringof))