Diff for /parser3/src/main/Attic/core.C between versions 1.49 and 1.62

version 1.49, 2001/03/10 11:18:15 version 1.62, 2001/03/12 18:13:49
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>  
 #include "classes/_root.h"  
 #include "classes/_env.h"  
 #include "classes/_string.h"  
 #include "classes/_double.h"  
 #include "classes/_int.h"  
   
 void core() {  #define GLOBAL_STRING(name, value)  name=new(pool) String(pool); name->APPEND_CONST(value)
         Pool pool;  #define LOCAL_STRING(name, value)  String name(pool); name.APPEND_CONST(value)
         initialize_string_class(pool, *(string_class=new(pool) VClass(pool)));  
         initialize_double_class(pool, *(double_class=new(pool) VClass(pool)));  
         initialize_int_class(pool, *(int_class=new(pool) VClass(pool)));  
         Request request(pool);  
         request.core();  
 }  
   
 Request::Request(Pool& apool) : Pooled(apool),  String *unnamed_name;
         stack(apool),  String *empty_string;
         root_class(apool),  
         env_class(apool),  
         fclasses(apool),  
         fclasses_array(apool),  
         lang(String::Untaint_lang::HTML_TYPO)  
 {  
         // root class  
         initialize_root_class(pool(), root_class);  
         // adding root superclass,   
         //   parent of all classes,   
         //   operators holder  
         String ROOT(pool()); ROOT.APPEND_CONST(ROOT_NAME);  
         classes().put(ROOT, &root_class);  
   
         // env class  
         initialize_env_class(pool(), env_class);  
         String ENV(pool()); ENV.APPEND_CONST(ENV_NAME);  
         classes().put(ENV, &env_class);  
 }  
   
 void Request::core() {  String *auto_method_name;
         TRY {  String *main_method_name;
                 char *file="Y:\\parser3\\src\\test.p";  
                 String RUN(pool()); RUN.APPEND_CONST(RUN_NAME);  
                 use(file, &RUN);  
   
                 char *result=execute_MAIN();  
                 printf("result-----------------\n%sEOF----------------\n", result);  
         }   
         CATCH(e) {  
                 printf("\nERROR: ");  
                 const String *problem_source=e.problem_source();  
                 if(problem_source) {  
                         const Origin& origin=problem_source->origin();  
                         if(origin.file)  
                                 printf("%s(%d): ",  
                                 origin.file, 1+origin.line);  
                         printf("'%s' ",   
                                 problem_source->cstr());  
                 }  
                 printf("%s", e.comment());  
                 const String *type=e.type();  
                 if(type) {  
                         printf("  type: %s", type->cstr());  
                         const String *code=e.code();  
                         if(code)  
                                 printf(", code: %s", code->cstr());  
                 }  
                 printf("\n");  
         }  
         END_CATCH  
 }  
   
 void Request::use(char *file, String *name) {  String *main_class_name;
         // TODO: обнаружить|решить cyclic dependences  String *root_class_name;
         char *source=file_read(pool(), file);  String *env_class_name;
         if(!source)  String *table_class_name;
                 THROW(0,0,  
                         0,  
                         "use: can not read '%s' file", file);  
   
         COMPILE(source, name, file);  Hash *untaint_lang_name2enum;
         // TODO: запустить @STATIC[], если есть  
   
 //      if(alias)  
                 //classes().put(*alias, &vclass);  
 }  
   
 char *Request::execute_MAIN() {  void core() {
         // locate class with @main & it's code          Pool pool;
         String name_main(pool());          
         name_main.APPEND_CONST(MAIN_METHOD_NAME);          // names
           GLOBAL_STRING(unnamed_name, UNNAMED_NAME);
         // looking for latest known @main          empty_string=new(pool) String(pool); 
         for(int i=classes_array().size(); --i>=0;) {  
                 VClass *vclass=static_cast<VClass *>(classes_array().get(i));          GLOBAL_STRING(auto_method_name, AUTO_METHOD_NAME);
                 Value *main=vclass->get_element(name_main);          GLOBAL_STRING(main_method_name, MAIN_METHOD_NAME);
                 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  
                                         root=rcontext=self=vclass;  
                                         wcontext=NEW WWrapper(pool(), vclass, false /* not constructing */);  
                                           
                                         // execute!       
                                         execute(*method->parser_code);  
                                           
                                         // return chars  
                                         return wcontext->get_string()->cstr();  
                                 }  
                         }  
                 }  
         }  
                   
         THROW(0,0,          GLOBAL_STRING(main_class_name, MAIN_CLASS_NAME);
                 0,           GLOBAL_STRING(root_class_name, ROOT_CLASS_NAME);
                 "'"MAIN_METHOD_NAME"' method not found");          GLOBAL_STRING(env_class_name, ENV_CLASS_NAME);  
         return 0;          GLOBAL_STRING(table_class_name, TABLE_CLASS_NAME);
   
           // hashes
           untaint_lang_name2enum=new(pool) Hash(pool);
           LOCAL_STRING(as_is, "as-is");  
           untaint_lang_name2enum->put(as_is, 
                   static_cast<int>(String::Untaint_lang::AS_IS));
           LOCAL_STRING(table, "table");
           untaint_lang_name2enum->put(table, 
                   static_cast<int>(String::Untaint_lang::TABLE));
           LOCAL_STRING(sql, "sql");
           untaint_lang_name2enum->put(sql, 
                   static_cast<int>(String::Untaint_lang::SQL));
           LOCAL_STRING(js, "js");
           untaint_lang_name2enum->put(js, 
                   static_cast<int>(String::Untaint_lang::JS));
           LOCAL_STRING(html, "html");
           untaint_lang_name2enum->put(html, 
                   static_cast<int>(String::Untaint_lang::HTML));
           LOCAL_STRING(html_typo, "html-typo");
           untaint_lang_name2enum->put(html_typo, 
                   static_cast<int>(String::Untaint_lang::HTML_TYPO));
   
           // read-only classes
           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();
   
           // request
           Request request(pool);
           request.core();
 }  }
   

Removed from v.1.49  
changed lines
  Added in v.1.62


E-mail: