[Avida-SVN] r2018 - development/source/script

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Aug 27 13:27:34 PDT 2007


Author: brysonda
Date: 2007-08-27 16:27:34 -0400 (Mon, 27 Aug 2007)
New Revision: 2018

Modified:
   development/source/script/ASTree.cc
   development/source/script/ASTree.h
   development/source/script/cASTDumpVisitor.cc
   development/source/script/cASTDumpVisitor.h
   development/source/script/cASTVisitor.h
   development/source/script/cParser.cc
Log:
AS: Array unpack construction (not printing yet).

Modified: development/source/script/ASTree.cc
===================================================================
--- development/source/script/ASTree.cc	2007-08-27 19:45:47 UTC (rev 2017)
+++ development/source/script/ASTree.cc	2007-08-27 20:27:34 UTC (rev 2018)
@@ -48,6 +48,7 @@
 void cASTLiteral::Accept(cASTVisitor& visitor) { visitor.visitLiteral(*this); }
 void cASTLiteralArray::Accept(cASTVisitor& visitor) { visitor.visitLiteralArray(*this); }
 void cASTVariableReference::Accept(cASTVisitor& visitor) { visitor.visitVariableReference(*this); }
+void cASTUnpackTarget::Accept(cASTVisitor& visitor) { visitor.visitUnpackTarget(*this); }
 
 
 cASTStatementList::~cASTStatementList()

Modified: development/source/script/ASTree.h
===================================================================
--- development/source/script/ASTree.h	2007-08-27 19:45:47 UTC (rev 2017)
+++ development/source/script/ASTree.h	2007-08-27 20:27:34 UTC (rev 2018)
@@ -37,6 +37,9 @@
 #ifndef tList_h
 #include "tList.h"
 #endif
+#ifndef tManagedPointerArray_h
+#include "tManagedPointerArray.h"
+#endif
 
 
 class cASTVisitor;
@@ -88,6 +91,7 @@
 class cASTLiteral;
 class cASTLiteralArray;
 class cASTVariableReference;
+class cASTUnpackTarget;
 
 
 
@@ -436,4 +440,27 @@
 };
 
 
+class cASTUnpackTarget : public cASTNode
+{
+private:
+  tManagedPointerArray<cString> m_nodes;
+  bool m_last_wild;
+  bool m_last_named;
+  
+public:
+  cASTUnpackTarget() : m_last_wild(false), m_last_named(false) { ; }
+  ~cASTUnpackTarget() { ; }
+  
+  inline void AddVar(const cString& name) { m_nodes.Push(name); }
+  inline int GetSize() const { return m_nodes.GetSize(); }
+  inline const cString& GetVar(int idx) const { return m_nodes[idx]; }
+  
+  inline void SetLastNamed() { m_last_wild = true; m_last_named = true; }
+  inline void SetLastWild() { m_last_wild = true; m_last_named = false; }
+  
+  
+  void Accept(cASTVisitor& visitor);
+};
+
+
 #endif

Modified: development/source/script/cASTDumpVisitor.cc
===================================================================
--- development/source/script/cASTDumpVisitor.cc	2007-08-27 19:45:47 UTC (rev 2017)
+++ development/source/script/cASTDumpVisitor.cc	2007-08-27 20:27:34 UTC (rev 2018)
@@ -384,3 +384,9 @@
   indent();
   cout << node.GetName() << endl;
 }
+
+
+void cASTDumpVisitor::visitUnpackTarget(cASTUnpackTarget& node)
+{
+  // @todo
+}

Modified: development/source/script/cASTDumpVisitor.h
===================================================================
--- development/source/script/cASTDumpVisitor.h	2007-08-27 19:45:47 UTC (rev 2017)
+++ development/source/script/cASTDumpVisitor.h	2007-08-27 20:27:34 UTC (rev 2018)
@@ -59,6 +59,7 @@
   void visitLiteral(cASTLiteral&);
   void visitLiteralArray(cASTLiteralArray&);
   void visitVariableReference(cASTVariableReference&);
+  void visitUnpackTarget(cASTUnpackTarget&);
 
 private:
   inline void indent();

Modified: development/source/script/cASTVisitor.h
===================================================================
--- development/source/script/cASTVisitor.h	2007-08-27 19:45:47 UTC (rev 2017)
+++ development/source/script/cASTVisitor.h	2007-08-27 20:27:34 UTC (rev 2018)
@@ -58,6 +58,7 @@
   virtual void visitLiteral(cASTLiteral&) = 0;
   virtual void visitLiteralArray(cASTLiteralArray&) = 0;
   virtual void visitVariableReference(cASTVariableReference&) = 0;
+  virtual void visitUnpackTarget(cASTUnpackTarget&) = 0;
 };
 
 #endif

Modified: development/source/script/cParser.cc
===================================================================
--- development/source/script/cParser.cc	2007-08-27 19:45:47 UTC (rev 2017)
+++ development/source/script/cParser.cc	2007-08-27 20:27:34 UTC (rev 2018)
@@ -265,31 +265,34 @@
 cASTNode* cParser::parseArrayUnpack()
 {
   PARSE_TRACE("parseArrayUnpack");
-  cASTNode* au = NULL;
   
-  // @todo - array unpack
-  
   if (nextToken() != TOKEN(ID)) PARSE_UNEXPECT();
+
+  tAutoRelease<cASTUnpackTarget> ut(new cASTUnpackTarget());
+  (*ut).AddVar(currentText());
   
   while (nextToken()) {
     if (currentToken() == TOKEN(COMMA)) {
       nextToken();
       if (currentToken() == TOKEN(ID)) {
+        (*ut).AddVar(currentText());
         continue;
       } else if (currentToken() == TOKEN(ARR_WILD)) {
+        (*ut).SetLastWild();
         break;
       } else {
         PARSE_ERROR(UNEXPECTED_TOKEN);
         break;
       }
     } else if (currentToken() == TOKEN(ARR_WILD)) {
+      (*ut).SetLastNamed();
       break;
     } else {
       PARSE_UNEXPECT();
     }
   }
 
-  return au;
+  return ut.Release();
 }
 
 cASTArgumentList* cParser::parseArgumentList()




More information about the Avida-cvs mailing list