changeset 209:42e663451371

Renamed some of the actions. Declarations now have it's own action.
author Anders Johnsen <skabet@gmail.com>
date Tue, 12 Aug 2008 19:05:17 +0200
parents 41ccd50e7cbc
children f4149d4f6896
files docs/candydoc/modules.ddoc src/ast/Expr.d src/basic/Message.d src/parser/Action.d src/parser/Parser.d
diffstat 5 files changed, 89 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/docs/candydoc/modules.ddoc	Tue Aug 12 18:21:06 2008 +0200
+++ b/docs/candydoc/modules.ddoc	Tue Aug 12 19:05:17 2008 +0200
@@ -1,14 +1,1 @@
 MODULES =
-	$(MODULE_FULL parser.Action)
-	$(MODULE_FULL parser.Parser)
-	$(MODULE_FULL ast.Decl)
-	$(MODULE_FULL ast.Stmt)
-	$(MODULE_FULL ast.Expr)
-	$(MODULE_FULL lexer.Keyword)
-	$(MODULE_FULL lexer.Lexer)
-	$(MODULE_FULL lexer.Token)
-	$(MODULE_FULL basic.SmallArray)
-	$(MODULE_FULL basic.Message)
-	$(MODULE_FULL basic.SourceLocation)
-	$(MODULE_FULL basic.Messages)
-	$(MODULE_FULL basic.SourceManager)
--- a/src/ast/Expr.d	Tue Aug 12 18:21:06 2008 +0200
+++ b/src/ast/Expr.d	Tue Aug 12 19:05:17 2008 +0200
@@ -30,23 +30,23 @@
     ArrayLiteral asArrayLiteral() { return null; }
     bool isArrayLiteral() { return false; }
 
-    Assign asAssign() { return null; }
-    bool isAssign() { return false; }
+    AssignExp asAssignExp() { return null; }
+    bool isAssignExp() { return false; }
 
-    Binary asBinary() { return null; }
-    bool isBinary() { return false; }
+    BinaryExp asBinaryExp() { return null; }
+    bool isBinaryExp() { return false; }
 
-    Negate asNegate() { return null; }
-    bool isNegate() { return false; }
+    NegateExp asNegateExp() { return null; }
+    bool isNegateExp() { return false; }
 
-    Deref asDeref() { return null; }
-    bool isDeref() { return false; }
+    DerefExp asDerefExp() { return null; }
+    bool isDerefExp() { return false; }
 
-    AddressOf asAddressOf() { return null; }
-    bool isAddressOf() { return false; }
+    AddressOfExp asAddressOfExp() { return null; }
+    bool isAddressOfExp() { return false; }
 
-    Index asIndex() { return null; }
-    bool isIndex() { return false; }
+    IndexExp asIndexExp() { return null; }
+    bool isIndexExp() { return false; }
 
     Identifier asIdentifier() { return null; }
     bool isIdentifier() { return false; }
@@ -116,71 +116,71 @@
 }
 
 /**
-  The Assign expression contains two expression, a left and a right side, 
+  The AssignExp expression contains two expression, a left and a right side, 
   left being a lvalue, right being a rvalue. 
 
   If the right side ain't the same type as the left type, the right side will
   try to be promoted through an implicit cast. If this failes, an error must
   be given.
   */
-class Assign : Expr
+class AssignExp : Expr
 {
-    override Assign asAssign() { return this; }
-    override bool isAssign() { return true; }
+    override AssignExp asAssignExp() { return this; }
+    override bool isAssignExp() { return true; }
 
 private:
     Expr left, right;
 }
 
 /**
-  Binary
+  BinaryExp
   */
-class Binary : Expr
+class BinaryExp : Expr
 {
-    override Binary asBinary() { return this; }
-    override bool isBinary() { return true; }
+    override BinaryExp asBinaryExp() { return this; }
+    override bool isBinaryExp() { return true; }
 
 private:
     Expr left, right;
 }
 
 /**
-  Negate
+  NegateExp
   */
-class Negate : Expr
+class NegateExp : Expr
 {
-    override Negate asNegate() { return this; }
-    override bool isNegate() { return true; }
+    override NegateExp asNegateExp() { return this; }
+    override bool isNegateExp() { return true; }
 
 private:
     Expr expr;
 }
 
 /**
-  Deref
+  DerefExp
   */
-class Deref : Expr
+class DerefExp : Expr
 {
-    override Deref asDeref() { return this; }
-    override bool isDeref() { return true; }
+    override DerefExp asDerefExp() { return this; }
+    override bool isDerefExp() { return true; }
 }
 
 /**
-  AddressOf
+  AddressOfExp
   */
-class AddressOf : Expr
+class AddressOfExp : Expr
 {
-    override AddressOf asAddressOf() { return this; }
-    override bool isAddressOf() { return true; }
+    override AddressOfExp asAddressOfExp() { return this; }
+    override bool isAddressOfExp() { return true; }
 }
 
 /**
-  Index
+  IndexExp
   */
-class Index : Expr
+class IndexExp : Expr
 {
-    override Index asIndex() { return this; }
-    override bool isIndex() { return true; }
+    override IndexExp asIndexExp() { return this; }
+    override bool isIndexExp() { return true; }
 }
 
 /**
--- a/src/basic/Message.d	Tue Aug 12 18:21:06 2008 +0200
+++ b/src/basic/Message.d	Tue Aug 12 19:05:17 2008 +0200
@@ -10,8 +10,7 @@
 import llvm.type;
 
 import lexer.Token,
-       lexer.Lexer,
-       sema.DType;
+       lexer.Lexer;
 
 import basic.SourceLocation,
        basic.SourceManager;
@@ -195,14 +194,6 @@
         return arg([c]);
     }
 
-    Message arg(DType[] types)
-    {
-        char[][] res;
-        foreach (type; types)
-            res ~= type.name();
-        return arg(res);
-    }
-
     Message fatal(ExitLevel exitlevel = ExitLevel.Normal)
     {
         msg_handler.checkErrors(exitlevel);
--- a/src/parser/Action.d	Tue Aug 12 18:21:06 2008 +0200
+++ b/src/parser/Action.d	Tue Aug 12 19:05:17 2008 +0200
@@ -163,14 +163,42 @@
     }
 
     /**
-      Either we should have one case that handles a lot of things, or we should
-      have a lot of separate cases.
-      As an example, this method could handle the params in `int f(int, int)`
-      as well as handling `int x` at both top-level, in classes and in methods.
-      
-      The other solution is an addParamToFunc or similar.
+      Called when an simple variable had been parsed.
+     */
+    DeclT actOnVarDecl(ref Id type, ref Id name, 
+            ExprT initializer, Attribute att)
+    {
+        return null;
+    }
+
+    /**
+      Called when a struct has been parsed. 
+
+      actOnStructMember will be called for all members
      */
-    DeclT actOnDeclarator(ref Id type, ref Id name, ExprT init, Attribute att)
+    DeclT actOnStructDecl(ref Id name, Attribute att)
+    {
+        return null;
+    }
+
+    /**
+      Called when a class has been parsed. 
+
+      actOnClassMember will be called for all members
+      actOnClassBaseClass will be called for all base classes
+     */
+    DeclT actOnClassDecl(ref Id name, Attribute att)
+    {
+        return null;
+    }
+
+    /**
+      Called when a interface has been parsed. 
+
+      actOnInterfaceMember will be called for all members
+      actOnInterfaceBaseClass will be called for all base classes
+     */
+    DeclT actOnInterfaceDecl(ref Id name, Attribute att)
     {
         return null;
     }
@@ -366,14 +394,6 @@
     }
 
     /**
-      This is called when strings are used in expression
-     */
-    ExprT actOnStringExp(Token t)
-    {
-        return null;
-    }
-
-    /**
       Unary operator.
      */
     ExprT actOnUnaryOp(Token op, ExprT operand)
--- a/src/parser/Parser.d	Tue Aug 12 18:21:06 2008 +0200
+++ b/src/parser/Parser.d	Tue Aug 12 19:05:17 2008 +0200
@@ -77,19 +77,19 @@
         switch(peek.type)
         {
             case Tok.Struct:
-                Id type = Id(next());
+                next();
                 Id iden = Id(require(Tok.Identifier));            
-                return parseStruct(type, iden, att);
+                return parseStruct(iden, att);
 
             case Tok.Class:
-                Id type = Id(next());
+                next();
                 Id iden = Id(require(Tok.Identifier));            
-                return parseClass(type, iden, att);
+                return parseClass(iden, att);
 
             case Tok.Interface:
-                Id type = Id(next());
+                next();
                 Id iden = Id(require(Tok.Identifier));
-                return parseInterface(type, iden, att);
+                return parseInterface(iden, att);
 
             case Tok.Alias:
                 next();
@@ -104,13 +104,13 @@
                 {
                     case Tok.Seperator:
                         Token sep = next();
-                        return action.actOnDeclarator(type, iden, null, att);
+                        return action.actOnVarDecl(type, iden, null, att);
 
                     case Tok.Assign:
                         Token assign = next();
                         Exp exp = parseExpression();
                         require(Tok.Seperator);
-                        return action.actOnDeclarator(type, iden, exp, att);
+                        return action.actOnVarDecl(type, iden, exp, att);
 
                     case Tok.OpenParentheses:
                         return parseFunc(type, iden, att);
@@ -119,7 +119,7 @@
                         auto n1 = next();
                         isEOF(type.tok);
                         messages.report(UnexpectedTok, n1.location).arg(n1.get(sm));
-                        return action.actOnDeclarator(type, iden, null, att);
+                        return action.actOnVarDecl(type, iden, null, att);
                 }
                 messages.report(InvalidDeclType, peek.location)
                     .arg(sm.getText(peek.asRange));
@@ -263,9 +263,9 @@
     /**
       Parse interface
      */
-    Decl parseInterface(Id type, Id iden, Attribute att)
+    Decl parseInterface(Id iden, Attribute att)
     {
-        auto decl = action.actOnDeclarator(type, iden, null, att);
+        auto decl = action.actOnInterfaceDecl(iden, att);
 
         if (peek.type == Tok.Colon)
             // SuperInterfaces
@@ -313,9 +313,9 @@
     /**
       Parse class
      */
-    Decl parseClass(Id type, Id iden, Attribute att)
+    Decl parseClass(Id iden, Attribute att)
     {
-        auto decl = action.actOnDeclarator(type, iden, null, att);
+        auto decl = action.actOnClassDecl(iden, att);
 
         if (peek.type == Tok.Colon)
             // BaseClassList - Super class and interfaces(in that order)
@@ -380,9 +380,9 @@
     /**
       Parse struct
      */
-    Decl parseStruct(Id type, Id iden, Attribute att)
+    Decl parseStruct(Id iden, Attribute att)
     {
-        auto decl = action.actOnDeclarator(type, iden, null, att);
+        auto decl = action.actOnStructDecl(iden, att);
 
         require(Tok.OpenBrace);
 
@@ -716,7 +716,7 @@
             init = parseExpression();
         require(Tok.Seperator);
         Attribute att;
-        Decl d = action.actOnDeclarator(type, id, init, att);
+        Decl d = action.actOnVarDecl(type, id, init, att);
         return d;
     }
 
@@ -870,7 +870,7 @@
                             i = parseIdentifier();
 
                         // Act on function type param
-                        decls ~= action.actOnDeclarator(t, i, null, Attribute());
+                        decls ~= action.actOnVarDecl(t, i, null, Attribute());
 
                         if(peek.type == Tok.Comma)
                             next();