compiler/libec2: Some classes and methods parsing
[sdk] / compiler / libec2 / src / specifiers.ec
index edb91c4..36a4b37 100644 (file)
@@ -1,26 +1,16 @@
 import "astNode"
+import "classes"
 
 // Specifiers
 public class ASTSpecifier : ASTNode
 {
 public:
-   SpecifierType type;
   /*    struct
       {
          //ExtDecl extDecl;
          //Symbol symbol;
          //OldList * templateArgs;
       };
-      struct
-      {
-         Identifier id;
-         OldList * list;
-         OldList * baseSpecs;
-         OldList * definitions;
-         bool addNameSpace;
-         Context ctx;
-         ExtDecl extDeclStruct;
-      };
       Expression expression;
       NewSpecifier _class;
       TemplateParameter templateParameter;
@@ -42,7 +32,17 @@ public class SpecsList : ASTList<ASTSpecifier>
       while(true)
       {
          peekToken();
-         if(nextToken.type.isSpecifier)
+         if(nextToken.type == STRUCT || nextToken.type == UNION)
+         {
+            ASTSpecifier s = SpecClass::parse();
+            if(s)
+            {
+               if(!specs) specs = { };
+               specs.Add(s);
+            }
+            break;
+         }
+         else if(nextToken.type.isSpecifier)
          {
             readToken();
             if(!specs) specs = { };
@@ -90,6 +90,56 @@ public class SpecName : ASTSpecifier
    }
 }
 
+public class ASTEnumerator : struct
+{
+public:
+   ASTIdentifier id;
+   ASTExpression exp;
+};
+
+public class SpecClass : ASTSpecifier
+{
+   TokenType type;
+   ASTIdentifier id;
+   List<ASTEnumerator> enumerators;
+   SpecsList baseSpecs;
+   ClassDefList definitions;
+   bool addNameSpace;
+   Context ctx;
+   // ExtDecl extDeclStruct;
+
+   SpecClass ::parse()
+   {
+      SpecClass spec { };
+      spec.type = readToken().type;
+      if(peekToken().type == IDENTIFIER)
+         spec.id = ASTIdentifier::parse();
+      if(peekToken().type == '{')
+      {
+         readToken();
+         spec.definitions = ClassDefList::parse();
+         if(peekToken().type == '}')
+            readToken();
+      }
+      return spec;
+   }
+
+   void print()
+   {
+      type.print();
+      Print(" ");
+      if(id) id.print();
+      if(definitions)
+      {
+         PrintLn("\n{");
+         indent++;
+         definitions.print();
+         indent--;
+         Print("\n}");
+      }
+   }
+}
+
 /*
 public class Attribute : struct
 {
@@ -120,14 +170,3 @@ public:
    };
 }
 */
-
-/*
-public class Enumerator : struct
-{
-public:
-   Enumerator prev, next;
-   Location loc;
-   Identifier id;
-   Expression exp;
-};
-*/