diff parser/Parser.d @ 136:2be29b296081

Lots of changes: - Parsing classes and interfaces - Fixed some seg faults in sema - Supporting "private" to some extend - And a lot of other small fixes
author johnsen@johnsen-laptop
date Fri, 11 Jul 2008 21:47:57 +0200
parents c3b24e7e8cf8
children 927ae00bd9d2
line wrap: on
line diff
--- a/parser/Parser.d	Wed Jul 09 13:38:11 2008 +0200
+++ b/parser/Parser.d	Fri Jul 11 21:47:57 2008 +0200
@@ -154,7 +154,7 @@
                     return action.actOnDeclarator(type, iden, exp, att);
                 }
                 else if (next.type == Tok.OpenParentheses)
-                    return parseFunc(type, iden);
+                    return parseFunc(type, iden, att);
                 else
                     messages.report(UnexpectedTok, next.location).arg(next.getType);
                 return null;
@@ -176,6 +176,20 @@
             
             return parseStruct(type, iden, att);
         }
+        else if (t.type == Tok.Class)
+        {
+            Id type = Id(lexer.next);
+            Id iden = Id(require(Tok.Identifier));
+            
+            return parseClass(type, iden, att);
+        }
+        else if (t.type == Tok.Interface)
+        {
+            Id type = Id(lexer.next);
+            Id iden = Id(require(Tok.Identifier));
+            
+            return parseClass(type, iden, att);
+        }
         messages.report(UnexpectedTok, t.location)
             .arg(t.getType)
             .arg(Tok.Identifier)
@@ -263,6 +277,100 @@
     }
 
     /**
+      Parse interface
+     */
+    Decl parseInterface(Id type, Id iden, Attribute att)
+    {
+        auto decl = action.actOnDeclarator(type, iden, null, att);
+
+        if (lexer.peek.type == Tok.Colon)
+            // SuperInterfaces
+        {
+            lexer.next; // Remove colon.
+
+            Token identifier;
+
+            // The identifier
+            identifier = require(Tok.Identifier);
+
+            // FIXME: Register Interface here
+
+            // We should now have an optional list of items, each starting ','
+            while (lexer.peek.type == Tok.Comma)
+            {
+                lexer.next; // Remove comma
+
+                // The identifier
+                identifier = require(Tok.Identifier);
+
+                // FIXME: Register Interface here
+            }
+        }
+
+        require(Tok.OpenBrace);
+
+        Attribute a;
+        while(lexer.peek.isBasicType || lexer.peek.isIdentifier || lexer.peek.isAttribute)
+        {
+            auto m_decl = parseDecl(&a);
+            action.actOnStructMember(decl, m_decl); 
+        }
+
+        require(Tok.CloseBrace);
+        
+        return decl;
+    }
+
+    /**
+      Parse class
+     */
+    Decl parseClass(Id type, Id iden, Attribute att)
+    {
+        auto decl = action.actOnDeclarator(type, iden, null, att);
+
+        if (lexer.peek.type == Tok.Colon)
+            // BaseClassList - Super class and interfaces(in that order)
+        {
+            lexer.next; // Remove colon.
+
+            Token protection, identifier;
+
+            // First we expect an optional protection level.
+            if (lexer.peek.isBaseClassProtection)
+                protection = lexer.next;
+            // Then the identifier
+            identifier = require(Tok.Identifier);
+
+            // FIXME: Register Interface here
+
+            // We should now have an optional list of items, each starting ','
+            while (lexer.peek.type == Tok.Comma)
+            {
+                lexer.next; // Remove comma
+
+                // First we expect an optional protection level.
+                if (lexer.peek.isBaseClassProtection)
+                    protection = lexer.next;
+                // Then the identifier
+                identifier = require(Tok.Identifier);
+            }
+        }
+
+        require(Tok.OpenBrace);
+
+        Attribute a;
+        while(lexer.peek.isBasicType || lexer.peek.isIdentifier || lexer.peek.isAttribute)
+        {
+            auto m_decl = parseDecl(&a);
+            action.actOnStructMember(decl, m_decl); // FIXME: Should call actOnClassMember
+        }
+
+        require(Tok.CloseBrace);
+        
+        return decl;
+    }
+
+    /**
       Parse struct
      */
     Decl parseStruct(Id type, Id iden, Attribute att)
@@ -417,9 +525,9 @@
     /**
       Parses a function/method given the already parsed return type and name
      */
-    Decl parseFunc(ref Id type, ref Id name)
+    Decl parseFunc(ref Id type, ref Id name, Attribute att)
     {
-        Decl func = action.actOnStartOfFunctionDef(type, name);
+        Decl func = action.actOnStartOfFunctionDef(type, name, att);
         parseFuncArgs(func);
 
         if(lexer.peek.type == Tok.Seperator)
@@ -543,7 +651,10 @@
             {
                 lexer.next;
                 if(lexer.peek.type == Tok.Integer)
-                    currentType = ArrayId(currentType, action.actOnNumericConstant(require(Tok.Integer)));
+                    currentType = StaticArrayId(
+                            currentType, 
+                            action.actOnNumericConstant(
+                                require(Tok.Integer)));
                 require(Tok.CloseBracket);
                 
             }