changeset 673:64fec49651cf

Renamed VariableDeclaration to VariablesDeclaration. Removed TryCast and CastTo template functions. Renamed Node.iS() to Node.Is().
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 18 Jan 2008 16:44:20 +0100
parents d422e5f2f3ea
children 6a934ff01b68
files trunk/src/dil/SettingsLoader.d trunk/src/dil/ast/Declarations.d trunk/src/dil/ast/DefaultVisitor.d trunk/src/dil/ast/Node.d trunk/src/dil/ast/NodesEnum.d trunk/src/dil/parser/ImportParser.d trunk/src/dil/parser/Parser.d trunk/src/dil/semantic/Analysis.d trunk/src/dil/semantic/Module.d trunk/src/dil/semantic/Pass1.d trunk/src/dil/translator/German.d
diffstat 11 files changed, 27 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/src/dil/SettingsLoader.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/SettingsLoader.d	Fri Jan 18 16:44:20 2008 +0100
@@ -26,7 +26,7 @@
 
   foreach (decl; modul.root.children)
   {
-    auto v = TryCast!(VariableDeclaration)(decl);
+    auto v = decl.Is!(VariablesDeclaration);
     if (v is null)
       continue;
 
@@ -38,29 +38,29 @@
     switch (variableName)
     {
     case "langfile":
-      if (auto val = TryCast!(StringExpression)(e))
+      if (auto val = e.Is!(StringExpression))
         GlobalSettings.langFile = val.getString();
       break;
     case "import_paths":
-      if (auto array = TryCast!(ArrayInitializer)(e))
+      if (auto array = e.Is!(ArrayInitializer))
       {
         foreach (value; array.values)
-          if (auto str = TryCast!(StringExpression)(value))
+          if (auto str = value.Is!(StringExpression))
             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 = TryCast!(StringExpression)(e))
+      if (auto val = e.Is!(StringExpression))
         GlobalSettings.lexerErrorFormat = val.getString();
       break;
     case "parser_error":
-      if (auto val = TryCast!(StringExpression)(e))
+      if (auto val = e.Is!(StringExpression))
         GlobalSettings.parserErrorFormat = val.getString();
       break;
     case "semantic_error":
-      if (auto val = TryCast!(StringExpression)(e))
+      if (auto val = e.Is!(StringExpression))
         GlobalSettings.semanticErrorFormat = val.getString();
       break;
     default:
@@ -78,7 +78,7 @@
   char[][] messages;
   foreach (decl; modul.root.children)
   {
-    auto v = TryCast!(VariableDeclaration)(decl);
+    auto v = decl.Is!(VariablesDeclaration);
     if (v is null)
       continue;
 
@@ -90,11 +90,11 @@
     switch (variableName)
     {
     case "messages":
-      if (auto array = TryCast!(ArrayInitializer)(e))
+      if (auto array = e.Is!(ArrayInitializer))
       {
         foreach (value; array.values)
         {
-          if (auto str = TryCast!(StringExpression)(value))
+          if (auto str = value.Is!(StringExpression))
             messages ~= str.getString();
         }
       }
@@ -102,7 +102,7 @@
         throw new Exception("messages variable is set to "~e.classinfo.name~" instead of an ArrayInitializer.");
       break;
     case "lang_code":
-      if (auto str = TryCast!(StringExpression)(e))
+      if (auto str = e.Is!(StringExpression))
           GlobalSettings.langCode = str.getString();
       break;
     default:
--- a/trunk/src/dil/ast/Declarations.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/ast/Declarations.d	Fri Jan 18 16:44:20 2008 +0100
@@ -357,7 +357,8 @@
   }
 }
 
-class VariableDeclaration : Declaration
+/// VariablesDeclaration := Type? Identifier ("=" Init)? ("," Identifier ("=" Init)?)* ";"
+class VariablesDeclaration : Declaration
 {
   TypeNode typeNode;
   Identifier*[] idents;
--- a/trunk/src/dil/ast/DefaultVisitor.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/ast/DefaultVisitor.d	Fri Jan 18 16:44:20 2008 +0100
@@ -69,7 +69,7 @@
       d.tparams && visitN(d.tparams),
       visitN(d.params),
       visitS(d.funcBody);
-    static if (is(D == VariableDeclaration))
+    static if (is(D == VariablesDeclaration))
     {
       d.typeNode && visitT(d.typeNode);
       foreach(value; d.values)
--- a/trunk/src/dil/ast/Node.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/ast/Node.d	Fri Jan 18 16:44:20 2008 +0100
@@ -12,20 +12,6 @@
 /// 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 TryCast(Class)(Node n)
-{
-  assert(n !is null);
-  if (n.kind == mixin("NodeKind." ~ typeof(Class).stringof))
-    return cast(Class)cast(void*)n;
-  return null;
-}
-
-Class CastTo(Class)(Node n)
-{
-  assert(n !is null && n.kind == mixin("NodeKind." ~ typeof(Class).stringof));
-  return cast(Class)cast(void*)n;
-}
-
 class Node
 {
   NodeCategory category;
@@ -79,7 +65,7 @@
     children is null || addChildren(children);
   }
 
-  Class iS(Class)()
+  Class Is(Class)()
   {
     if (kind == mixin("NodeKind." ~ typeof(Class).stringof))
       return cast(Class)cast(void*)this;
--- a/trunk/src/dil/ast/NodesEnum.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/ast/NodesEnum.d	Fri Jan 18 16:44:20 2008 +0100
@@ -35,7 +35,7 @@
   "DestructorDeclaration",
   "StaticDestructorDeclaration",
   "FunctionDeclaration",
-  "VariableDeclaration",
+  "VariablesDeclaration",
   "InvariantDeclaration",
   "UnittestDeclaration",
   "DebugDeclaration",
--- a/trunk/src/dil/parser/ImportParser.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/parser/ImportParser.d	Fri Jan 18 16:44:20 2008 +0100
@@ -197,7 +197,7 @@
     case_Import:
       auto decl = parseImportDeclaration();
       decl.setProtection(prot); // Set the protection attribute.
-      imports ~= CastTo!(ImportDeclaration)(decl);
+      imports ~= decl.to!(ImportDeclaration);
       break;
     case T.Enum:
       nT();
--- a/trunk/src/dil/parser/Parser.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/parser/Parser.d	Fri Jan 18 16:44:20 2008 +0100
@@ -298,7 +298,7 @@
     case T.Import:
     case_Import:
       decl = parseImportDeclaration();
-      imports ~= CastTo!(ImportDeclaration)(decl);
+      imports ~= decl.to!(ImportDeclaration);
       // Handle specially. StorageClass mustn't be set.
       decl.setProtection(this.protection);
       return set(decl, begin);
@@ -538,7 +538,7 @@
         values ~= null;
     }
     require(T.Semicolon);
-    auto d = new VariableDeclaration(type, idents, values);
+    auto d = new VariablesDeclaration(type, idents, values);
     d.setStorageClass(stc);
     d.setLinkageType(linkType);
     d.setProtection(protection);
@@ -1817,7 +1817,7 @@
       ident = requireIdentifier(MSG.ExpectedVariableName);
       require(T.Assign);
       auto init = parseExpression();
-      auto v = new VariableDeclaration(null, [ident], [init]);
+      auto v = new VariablesDeclaration(null, [ident], [init]);
       set(v, begin.nextNWS);
       auto d = new StorageClassDeclaration(StorageClass.Auto, v);
       set(d, begin);
@@ -1838,7 +1838,7 @@
       if (success)
       {
         auto init = parseExpression();
-        auto v = new VariableDeclaration(type, [ident], [init]);
+        auto v = new VariablesDeclaration(type, [ident], [init]);
         set(v, begin);
         variable = new DeclarationStatement(v);
         set(variable, begin);
--- a/trunk/src/dil/semantic/Analysis.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/semantic/Analysis.d	Fri Jan 18 16:44:20 2008 +0100
@@ -36,7 +36,7 @@
     {
       // scop.error(e.begin, "expression is not evaluatable at compile time");
     }
-    else if (auto stringExpr = TryCast!(StringExpression)(e))
+    else if (auto stringExpr = e.Is!(StringExpression))
       // Print string to standard output.
       Stdout(stringExpr.getString());
     else
@@ -59,7 +59,7 @@
   {
     // scop.error(e.begin, "expression is not evaluatable at compile time");
   }
-  else if (auto stringExpr = TryCast!(StringExpression)(e))
+  else if (auto stringExpr = e.Is!(StringExpression))
   {
     // TODO: collect library paths in Module?
     // scop.modul.addLibrary(stringExpr.getString());
--- a/trunk/src/dil/semantic/Module.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/semantic/Module.d	Fri Jan 18 16:44:20 2008 +0100
@@ -63,8 +63,8 @@
 
     if (root.children.length)
     {
-      // moduleDecl will be null if first node can't be cast to ModuleDeclaration.
-      this.moduleDecl = TryCast!(ModuleDeclaration)(root.children[0]);
+      // moduleDecl will be null if first node isn't a ModuleDeclaration.
+      this.moduleDecl = root.children[0].Is!(ModuleDeclaration);
       if (moduleDecl)
       {
         this.setFQN(moduleDecl.getFQN());
--- a/trunk/src/dil/semantic/Pass1.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/semantic/Pass1.d	Fri Jan 18 16:44:20 2008 +0100
@@ -223,7 +223,7 @@
   Declaration visit(FunctionDeclaration)
   { return null; }
 
-  Declaration visit(VariableDeclaration vd)
+  Declaration visit(VariablesDeclaration vd)
   {
     Type type = Types.Undefined;
 
--- a/trunk/src/dil/translator/German.d	Fri Jan 18 00:30:14 2008 +0100
+++ b/trunk/src/dil/translator/German.d	Fri Jan 18 16:44:20 2008 +0100
@@ -161,7 +161,7 @@
     return n;
   }
 
-  D visit(VariableDeclaration n)
+  D visit(VariablesDeclaration n)
   {
     printLoc(n);
     char[] was;