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

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Tue Jul 17 09:16:36 PDT 2007


Author: brysonda
Date: 2007-07-17 12:16:36 -0400 (Tue, 17 Jul 2007)
New Revision: 1812

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: ReturnStatement and VariableReference nodes.

Modified: development/source/script/ASTree.cc
===================================================================
--- development/source/script/ASTree.cc	2007-07-17 13:13:30 UTC (rev 1811)
+++ development/source/script/ASTree.cc	2007-07-17 16:16:36 UTC (rev 1812)
@@ -29,6 +29,7 @@
 
 void cASTAssignment::Accept(cASTVisitor& visitor) { visitor.visitAssignment(*this); }
 
+void cASTReturnStatement::Accept(cASTVisitor& visitor) { visitor.visitReturnStatement(*this); }
 void cASTStatementList::Accept(cASTVisitor& visitor) { visitor.visitStatementList(*this); }
 
 void cASTForeachBlock::Accept(cASTVisitor& visitor) { visitor.visitForeachBlock(*this); }

Modified: development/source/script/ASTree.h
===================================================================
--- development/source/script/ASTree.h	2007-07-17 13:13:30 UTC (rev 1811)
+++ development/source/script/ASTree.h	2007-07-17 16:16:36 UTC (rev 1812)
@@ -92,6 +92,21 @@
 
 // --------  Block Nodes  --------
 
+class cASTReturnStatement : public cASTNode
+{
+private:
+  cASTNode* m_expr;
+  
+public:
+  cASTReturnStatement(cASTNode* expr) : m_expr(expr) { ; }
+  ~cASTReturnStatement() { delete m_expr; }
+
+  inline cASTNode* GetExpression() { return m_expr; }
+  
+  void Accept(cASTVisitor& visitor);
+};
+
+
 class cASTStatementList : public cASTNode
 {
 private:
@@ -274,10 +289,13 @@
 class cASTVariableReference : public cASTNode
 {
 private:
+  cString m_name;
   
 public:
-  cASTVariableReference() { ; }
+  cASTVariableReference(const char* name) : m_name(name) { ; }
   
+  inline const cString& GetName() { return m_name; }
+  
   void Accept(cASTVisitor& visitor);
 };
 

Modified: development/source/script/cASTDumpVisitor.cc
===================================================================
--- development/source/script/cASTDumpVisitor.cc	2007-07-17 13:13:30 UTC (rev 1811)
+++ development/source/script/cASTDumpVisitor.cc	2007-07-17 16:16:36 UTC (rev 1812)
@@ -94,6 +94,18 @@
   m_depth--;
 }
 
+
+void cASTDumpVisitor::visitReturnStatement(cASTReturnStatement& node)
+{
+  indent();
+  cout << "return:" << endl;
+  
+  m_depth++;
+  node.GetExpression()->Accept(*this);
+  m_depth--;  
+}
+
+
 void cASTDumpVisitor::visitStatementList(cASTStatementList& node)
 {
   tListIterator<cASTNode> it(node.Iterator());
@@ -205,5 +217,6 @@
 
 void cASTDumpVisitor::visitVariableReference(cASTVariableReference& node)
 {
-  
+  indent();
+  cout << node.GetName() << endl;
 }

Modified: development/source/script/cASTDumpVisitor.h
===================================================================
--- development/source/script/cASTDumpVisitor.h	2007-07-17 13:13:30 UTC (rev 1811)
+++ development/source/script/cASTDumpVisitor.h	2007-07-17 16:16:36 UTC (rev 1812)
@@ -40,6 +40,7 @@
   
   void visitAssignment(cASTAssignment&);
   
+  void visitReturnStatement(cASTReturnStatement&);
   void visitStatementList(cASTStatementList&);
   
   void visitForeachBlock(cASTForeachBlock&);

Modified: development/source/script/cASTVisitor.h
===================================================================
--- development/source/script/cASTVisitor.h	2007-07-17 13:13:30 UTC (rev 1811)
+++ development/source/script/cASTVisitor.h	2007-07-17 16:16:36 UTC (rev 1812)
@@ -39,6 +39,7 @@
   
   virtual void visitAssignment(cASTAssignment&) = 0;
   
+  virtual void visitReturnStatement(cASTReturnStatement&) = 0;
   virtual void visitStatementList(cASTStatementList&) = 0;
   
   virtual void visitForeachBlock(cASTForeachBlock&) = 0;

Modified: development/source/script/cParser.cc
===================================================================
--- development/source/script/cParser.cc	2007-07-17 13:13:30 UTC (rev 1811)
+++ development/source/script/cParser.cc	2007-07-17 16:16:36 UTC (rev 1812)
@@ -590,7 +590,7 @@
         }
         expr = new cASTFunctionCall(); // @todo
       } else {
-        expr = new cASTVariableReference(); // @todo
+        expr = new cASTVariableReference(currentText());
       }
       break;
     case TOKEN(PREC_OPEN):
@@ -889,10 +889,9 @@
 cASTNode* cParser::parseReturnStatement()
 {
   PARSE_TRACE("parseReturnStatement");
-  cASTNode* rs = NULL;
   
   nextToken();
-  parseExpression();
+  cASTNode* rs = new cASTReturnStatement(parseExpression());
   
   return rs;
 }




More information about the Avida-cvs mailing list