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

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Fri Feb 29 08:51:56 PST 2008


Author: brysonda
Date: 2008-02-29 11:51:56 -0500 (Fri, 29 Feb 2008)
New Revision: 2401

Modified:
   development/source/script/ASTree.h
   development/source/script/cDumpASTVisitor.cc
   development/source/script/cSemanticASTVisitor.cc
Log:
AS: add conditional block checking.

Modified: development/source/script/ASTree.h
===================================================================
--- development/source/script/ASTree.h	2008-02-29 15:55:08 UTC (rev 2400)
+++ development/source/script/ASTree.h	2008-02-29 16:51:56 UTC (rev 2401)
@@ -474,15 +474,15 @@
 class cASTLiteralArray : public cASTNode
 {
 private:
-  cASTArgumentList* m_value;
+  cASTArgumentList* m_values;
   bool m_is_matrix;
   
 public:
   cASTLiteralArray(const cASFilePosition& fp, cASTArgumentList* v, bool is_mat)
-    : cASTNode(fp), m_value(v), m_is_matrix(is_mat) { ; }
-  ~cASTLiteralArray() { delete m_value; }  
+    : cASTNode(fp), m_values(v), m_is_matrix(is_mat) { ; }
+  ~cASTLiteralArray() { delete m_values; }  
   
-  inline cASTArgumentList* GetValue() { return m_value; }
+  inline cASTArgumentList* GetValues() { return m_values; }
   inline bool IsMatrix() const { return m_is_matrix; }
   
   ASType_t GetType() const { return m_is_matrix ? AS_TYPE_MATRIX : AS_TYPE_ARRAY; }

Modified: development/source/script/cDumpASTVisitor.cc
===================================================================
--- development/source/script/cDumpASTVisitor.cc	2008-02-29 15:55:08 UTC (rev 2400)
+++ development/source/script/cDumpASTVisitor.cc	2008-02-29 16:51:56 UTC (rev 2401)
@@ -337,7 +337,7 @@
   cout << "{" << endl;
   m_depth++;
   
-  node.GetValue()->Accept(*this);
+  node.GetValues()->Accept(*this);
   
   m_depth--;
   indent();

Modified: development/source/script/cSemanticASTVisitor.cc
===================================================================
--- development/source/script/cSemanticASTVisitor.cc	2008-02-29 15:55:08 UTC (rev 2400)
+++ development/source/script/cSemanticASTVisitor.cc	2008-02-29 16:51:56 UTC (rev 2401)
@@ -110,22 +110,65 @@
 
 void cSemanticASTVisitor::visitForeachBlock(cASTForeachBlock& node)
 {
+  // Check values and make sure we can process it as an array
+  node.GetValues()->Accept(*this);
+  checkCast(node.GetValues()->GetType(), TYPE(ARRAY));
+  
+  // @TODO - push scope
+  
+  // Check and define the variable in this scope
+  node.GetVariable()->Accept(*this);
+  
+  // Check the code
+  node.GetCode()->Accept(*this);
+  
+  // @TODO - pop scope
 }
 
 
 void cSemanticASTVisitor::visitIfBlock(cASTIfBlock& node)
 {
+  // Check main condition and code
+  node.GetCondition()->Accept(*this);
+  checkCast(node.GetCondition()->GetType(), TYPE(BOOL));
+  // @TODO - push scope
+  node.GetCode()->Accept(*this);
+  // @TODO - pop scope
+  
+  // Check all elseif blocks
+  tListIterator<cASTIfBlock::cElseIf> it = node.ElseIfIterator();
+  cASTIfBlock::cElseIf* ei = NULL;
+  while ((ei = it.Next())) {
+    ei->GetCondition()->Accept(*this);
+    checkCast(ei->GetCondition()->GetType(), TYPE(BOOL));
+    // @TODO - push scope
+    ei->GetCode()->Accept(*this);
+    // @TODO - pop scope
+  }
+  
+  // Check else block if there is one
+  if (node.GetElseCode()) {
+    // @TODO - push scope
+    node.GetElseCode()->Accept(*this);
+    // @TODO - pop scope
+  }
 }
 
 
 void cSemanticASTVisitor::visitWhileBlock(cASTWhileBlock& node)
 {
+  node.GetCondition()->Accept(*this);
+  checkCast(node.GetCondition()->GetType(), TYPE(BOOL));
+  // @TODO - push scope
+  node.GetCode()->Accept(*this);
+  // @TODO - pop scope
 }
 
 
 
 void cSemanticASTVisitor::visitFunctionDefinition(cASTFunctionDefinition& node)
 {
+  // @TODO - function definition
 }
 
 
@@ -150,8 +193,8 @@
       // If empty, warn...
       if (al->GetSize() == 0) SEMANTIC_WARNING(NO_DIMENSIONS);
       
-      // Arrays can only have one dimension specifier
-      if (node.GetType() == TYPE(ARRAY) && al->GetSize() > 1) {
+      // If dimensions exceed type limits
+      if ((node.GetType() == TYPE(ARRAY) && al->GetSize() > 1) || (node.GetType() == TYPE(MATRIX) && al->GetSize() > 2)) {
         SEMANTIC_ERROR(TOO_MANY_ARGUMENTS);
         SEMANTIC_ERROR(VARIABLE_DIMENSIONS_INVALID, (const char*)node.GetName(), mapType(node.GetType()));
       }
@@ -171,6 +214,8 @@
 
 void cSemanticASTVisitor::visitVariableDefinitionList(cASTVariableDefinitionList& node)
 {
+  // Should never recurse into here.  Variable definition lists are processed by function definitions.
+  SEMANTIC_ERROR(INTERNAL);
 }
 
 
@@ -316,6 +361,7 @@
 
 void cSemanticASTVisitor::visitFunctionCall(cASTFunctionCall& node)
 {
+  // @TODO - function call
 }
 
 
@@ -327,16 +373,26 @@
 
 void cSemanticASTVisitor::visitLiteralArray(cASTLiteralArray& node)
 {
+  cASTArgumentList* al = node.GetValues();
+  if (al) {
+    tListIterator<cASTNode> it = al->Iterator();
+    cASTNode* alnode = NULL;
+    while ((alnode = it.Next())) alnode->Accept(*this);
+  }
+  
+  // Matrix dimension check must be performed at runtime
 }
 
 
 void cSemanticASTVisitor::visitObjectCall(cASTObjectCall& node)
 {
+  // @TODO - object call
 }
 
 
 void cSemanticASTVisitor::visitObjectReference(cASTObjectReference& node)
 {
+  // @TODO - object reference
 }
 
 
@@ -519,12 +575,28 @@
     case AS_SEMANTIC_WARN_LOSS_OF_PRECISION:
       std::cerr << "loss of precision occuring in cast of " << VA_ARG_STR << " to " << VA_ARG_STR << ERR_ENDL;
       break;
+    case AS_SEMANTIC_WARN_NO_DIMENSIONS:
+      std::cerr << "no dimensions specified" << ERR_ENDL;
+      break;
     case AS_SEMANTIC_WARN_UNREACHABLE:
       std::cerr << "unreachable statement(s)" << ERR_ENDL;
       break;
+      
     case AS_SEMANTIC_ERR_CANNOT_CAST:
       std::cerr << "cannot cast " << VA_ARG_STR << " to " << VA_ARG_STR << ERR_ENDL;
       break;
+    case AS_SEMANTIC_ERR_TOO_MANY_ARGUMENTS:
+      std::cerr << "too many arguments" << ERR_ENDL;
+      break;
+    case AS_SEMANTIC_ERR_UNDEFINED_TYPE_OP:
+      std::cerr << "'" << VA_ARG_STR << "' operation undefined for type '" << VA_ARG_STR << "'" << ERR_ENDL;
+      break;
+    case AS_SEMANTIC_ERR_UNPACK_WILD_NONARRAY:
+      std::cerr << "cannot unpack ... items into '" << VA_ARG_STR << "', variable must be an array" << ERR_ENDL;
+      break;
+    case AS_SEMANTIC_ERR_VARIABLE_DIMENSIONS_INVALID:
+      std::cerr << "dimensions of '" << VA_ARG_STR << "' invalid for type " << VA_ARG_STR << ERR_ENDL;
+      break;
     case AS_SEMANTIC_ERR_VARIABLE_UNDEFINED:
       {
         cString varname = VA_ARG_STR;
@@ -534,11 +606,6 @@
         std::cerr << ERR_ENDL;
       }
       break;
-    case AS_SEMANTIC_ERR_UNDEFINED_TYPE_OP:
-      std::cerr << "'" << VA_ARG_STR << "' operation undefined for type '" << VA_ARG_STR << "'" << ERR_ENDL;
-      break;
-    case AS_SEMANTIC_ERR_UNPACK_WILD_NONARRAY:
-      std::cerr << "cannot unpack ... items into '" << VA_ARG_STR << "', variable must be an array" << ERR_ENDL;
     case AS_SEMANTIC_ERR_VARIABLE_REDEFINITION:
       std::cerr << "redefining variable '" << VA_ARG_STR << "'" << ERR_ENDL;
       break;




More information about the Avida-cvs mailing list