[Avida-SVN] r2409 - in development/source: script targets/avida-s

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Sun Mar 2 10:07:44 PST 2008


Author: brysonda
Date: 2008-03-02 13:07:44 -0500 (Sun, 02 Mar 2008)
New Revision: 2409

Modified:
   development/source/script/AvidaScript.h
   development/source/script/cParser.cc
   development/source/script/cSemanticASTVisitor.cc
   development/source/script/cSemanticASTVisitor.h
   development/source/targets/avida-s/main.cc
Log:
AS: Standardize exit codes and handle semantic check successful state.

Modified: development/source/script/AvidaScript.h
===================================================================
--- development/source/script/AvidaScript.h	2008-03-02 17:47:19 UTC (rev 2408)
+++ development/source/script/AvidaScript.h	2008-03-02 18:07:44 UTC (rev 2409)
@@ -140,6 +140,15 @@
 } ASSemanticError_t;
 
 
+enum eASExitCodes {
+  AS_EXIT_OK = 0,
+  AS_EXIT_FILE_NOT_FOUND = 100,
+  AS_EXIT_FAIL_PARSE,
+  AS_EXIT_FAIL_SEMANTIC,
+
+  AS_EXIT_UNKNOWN
+};
+
 typedef enum eASTypes {
   AS_TYPE_ARRAY = 0,
   AS_TYPE_BOOL,

Modified: development/source/script/cParser.cc
===================================================================
--- development/source/script/cParser.cc	2008-03-02 17:47:19 UTC (rev 2408)
+++ development/source/script/cParser.cc	2008-03-02 18:07:44 UTC (rev 2409)
@@ -188,8 +188,8 @@
  */
 
 
-#define PARSE_DEBUG(x) { std::cerr << x << std::endl; }
-#define PARSE_TRACE(x) { std::cerr << "trace: " << x << std::endl; }
+#define PARSE_DEBUG(x) /*{ std::cerr << x << std::endl; }*/
+#define PARSE_TRACE(x) /*{ std::cerr << "trace: " << x << std::endl; }*/
 
 #define PARSE_ERROR(x) reportError(AS_PARSE_ERR_ ## x, __LINE__)
 #define PARSE_UNEXPECT() { if (currentToken()) { PARSE_ERROR(UNEXPECTED_TOKEN); } else { PARSE_ERROR(EOF); } return NULL; }

Modified: development/source/script/cSemanticASTVisitor.cc
===================================================================
--- development/source/script/cSemanticASTVisitor.cc	2008-03-02 17:47:19 UTC (rev 2408)
+++ development/source/script/cSemanticASTVisitor.cc	2008-03-02 18:07:44 UTC (rev 2409)
@@ -68,6 +68,7 @@
 
 cSemanticASTVisitor::cSemanticASTVisitor(cASLibrary* lib, cSymbolTable* global_symtbl)
   : m_library(lib), m_global_symtbl(global_symtbl), m_parent_scope(global_symtbl), m_fun_id(0), m_cur_symtbl(global_symtbl)
+  , m_success(true), m_fun_def(false)
 {
   // Add internal definition of the global function
   int fun_id = -1;

Modified: development/source/script/cSemanticASTVisitor.h
===================================================================
--- development/source/script/cSemanticASTVisitor.h	2008-03-02 17:47:19 UTC (rev 2408)
+++ development/source/script/cSemanticASTVisitor.h	2008-03-02 18:07:44 UTC (rev 2409)
@@ -68,6 +68,9 @@
 public:
   cSemanticASTVisitor(cASLibrary* lib, cSymbolTable* global_symtbl);
   
+  inline bool WasSuccessful() { return m_success; }
+  
+  
   void visitAssignment(cASTAssignment&);
   
   void visitReturnStatement(cASTReturnStatement&);

Modified: development/source/targets/avida-s/main.cc
===================================================================
--- development/source/targets/avida-s/main.cc	2008-03-02 17:47:19 UTC (rev 2408)
+++ development/source/targets/avida-s/main.cc	2008-03-02 18:07:44 UTC (rev 2409)
@@ -45,26 +45,29 @@
   cFile file;
   if (file.Open("main.asl")) {
     if (parser->Parse(file)) {
-      std::cout << "Parse Successful\n" << std::endl;
-      
       cASTNode* tree = parser->ExtractTree();
 
+      cDumpASTVisitor dump;
+      tree->Accept(dump);
+      std::cout << std::endl;
+      
       cSymbolTable global_symtbl;
       cSemanticASTVisitor semantic_check(lib, &global_symtbl);
       tree->Accept(semantic_check);
+      if (!semantic_check.WasSuccessful()) {
+        std::cerr << "error: semantics check failed" << std::endl;
+        Avida::Exit(AS_EXIT_FAIL_SEMANTIC);
+      }
       
-      cDumpASTVisitor dump;
-      tree->Accept(dump);
-      
-      std::cout << std::endl;
-      Avida::Exit(0);
+      Avida::Exit(AS_EXIT_OK);
     } else {
-      std::cout << "Parse Failed" << std::endl;
-      Avida::Exit(-1);
+      std::cerr << "error: parse failed" << std::endl;
+      Avida::Exit(AS_EXIT_FAIL_PARSE);
     }
   } else {
     std::cerr << "error: unable to open script" << std::endl;
+    Avida::Exit(AS_EXIT_FILE_NOT_FOUND);
   }
   
-  return -1;
+  return AS_EXIT_UNKNOWN;
 }




More information about the Avida-cvs mailing list