Diff for /parser3/src/main/Attic/core.C between versions 1.37 and 1.61

version 1.37, 2001/02/25 08:50:13 version 1.61, 2001/03/12 13:13:21
Line 1 Line 1
 /*  /*
 $Id$          Parser
           Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
           Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
   
           $Id$
 */  */
   
   #include "core.h"
   #include "_string.h"
   #include "_double.h"
   #include "_int.h"
   #include "_table.h"
 #include "pa_request.h"  #include "pa_request.h"
 #include "pa_wwrapper.h"  
 #include "pa_common.h"  
 #include "pa_vclass.h"  
   
 #include <stdio.h>  #define GLOBAL_STRING(name, value)  name=new(pool) String(pool); name->APPEND_CONST(value)
   #define LOCAL_STRING(name, value)  String name(pool); name.APPEND_CONST(value)
   
   String *unnamed_name;
   String *empty_string;
   
   String *auto_method_name;
   String *main_method_name;
   
   String *main_class_name;
   String *root_class_name;
   String *env_class_name;
   String *table_class_name;
   
   Hash *untaint_lang_name2enum;
   
   
 void core() {  void core() {
         Pool pool;          Pool pool;
         Request request(pool);          
         request.core();          // names
 }          GLOBAL_STRING(unnamed_name, "unnamed");
           empty_string=new(pool) String(pool); 
   
 void Request::core() {          GLOBAL_STRING(auto_method_name, AUTO_METHOD_NAME);
         TRY {          GLOBAL_STRING(main_method_name, MAIN_METHOD_NAME);
                 char *file="Y:\\parser3\\src\\test.p";          
                 String RUN(pool()); RUN.APPEND_CONST(NAME_RUN);          GLOBAL_STRING(main_class_name, MAIN_CLASS_NAME);
                 use(file, &RUN);          GLOBAL_STRING(root_class_name, ROOT_CLASS_NAME);
           GLOBAL_STRING(env_class_name, ENV_CLASS_NAME);  
                 char *result=execute_MAIN();          GLOBAL_STRING(table_class_name, TABLE_CLASS_NAME);
                 printf("result-----------------\n%sEOF----------------\n", result);  
         }           // hashes
         CATCH(e) {          untaint_lang_name2enum=new(pool) Hash(pool);
                 printf("\nERROR: ");          LOCAL_STRING(as_is, "as-is");  
                 const String *problem_source=e.problem_source();          untaint_lang_name2enum->put(as_is, 
                 if(problem_source) {                  static_cast<int>(String::Untaint_lang::AS_IS));
                         const Origin& origin=problem_source->origin();          LOCAL_STRING(table, "table");
                         if(origin.file)          untaint_lang_name2enum->put(table, 
                                 printf("%s(%d): ",                  static_cast<int>(String::Untaint_lang::TABLE));
                                 origin.file, 1+origin.line);          LOCAL_STRING(sql, "sql");
                         printf("'%s' ",           untaint_lang_name2enum->put(sql, 
                                 problem_source->cstr());                  static_cast<int>(String::Untaint_lang::SQL));
                 }          LOCAL_STRING(js, "js");
                 printf("%s", e.comment());          untaint_lang_name2enum->put(js, 
                 const String *type=e.type();                  static_cast<int>(String::Untaint_lang::JS));
                 if(type) {          LOCAL_STRING(html, "html");
                         printf("  type: %s", type->cstr());          untaint_lang_name2enum->put(html, 
                         const String *code=e.code();                  static_cast<int>(String::Untaint_lang::HTML));
                         if(code)          LOCAL_STRING(html_typo, "html-typo");
                                 printf(", code: %s", code->cstr());          untaint_lang_name2enum->put(html_typo, 
                 }                  static_cast<int>(String::Untaint_lang::HTML_TYPO));
                 printf("\n");  
         }          // read-only classes
         END_CATCH          initialize_string_class(pool, *(string_class=new(pool) VClass(pool)));  string_class->freeze();
 }          initialize_double_class(pool, *(double_class=new(pool) VClass(pool)));  double_class->freeze();
           initialize_int_class(pool, *(int_class=new(pool) VClass(pool)));  int_class->freeze();
           initialize_table_class(pool, *(table_class=new(pool) VClass(pool)));  table_class->freeze();
   
 void Request::use(char *file, String *name) {          // request
         char *source=file_read(pool(), file);          Request request(pool);
         if(!source)          request.core();
                 THROW(0,0,  
                         0,  
                         "use: can not read '%s' file", file);  
   
         VClass& vclass=COMPILE(source, file);  
         if(name) // they forced some name?  
                 vclass.set_name(*name);  
         name=vclass.name();  
         if(!name)  
                 return; //TODO: add operators   
         classes_array()+=&vclass;  
         classes().put(*name, &vclass);  
 }  }
   
 char *Request::execute_MAIN() {  
         // locate class with @main & it's code  
         String name_main(pool());  
         name_main.APPEND_CONST(MAIN_METHOD_NAME);  
   
         // looking for latest known @main  
         for(int i=classes_array().size(); --i>=0;) {  
                 VClass *vclass=static_cast<VClass *>(classes_array().get(i));  
                 Value *main=vclass->get_element(name_main);  
                 if(main) { // found some 'main' element  
                         Junction *junction=main->get_junction();  
                         if(junction) {// it even has junction!  
                                 const Method *method=junction->method;  
                                 if(method) { // and junction is method-junction! call it  
                                         // initialize contexts  
                                         self=root=rcontext=vclass;  
                                         wcontext=NEW WWrapper(pool(), vclass);  
                                           
                                         // execute!       
                                         execute(method->code);  
                                           
                                         // return chars  
                                         return wcontext->get_string()->cstr();  
                                 }  
                         }  
                 }  
         }  
           
         THROW(0,0,  
                 0,   
                 "'"MAIN_METHOD_NAME"' method not found");  
         return 0;  
 }  

Removed from v.1.37  
changed lines
  Added in v.1.61


E-mail: