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

version 1.37, 2001/02/25 08:50:13 version 1.68, 2001/03/13 20:02:10
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)
 #include "pa_request.h"  
 #include "pa_wwrapper.h"  
 #include "pa_common.h"  
 #include "pa_vclass.h"  
   
 #include <stdio.h>  
   
 void core() {  
         Pool pool;  
         Request request(pool);  
         request.core();  
 }  
   
 void Request::core() {          $Id$
         TRY {  */
                 char *file="Y:\\parser3\\src\\test.p";  
                 String RUN(pool()); RUN.APPEND_CONST(NAME_RUN);  
                 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) {  
         char *source=file_read(pool(), file);  
         if(!source)  
                 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() {  #include "core.h"
         // locate class with @main & it's code  #include "_string.h"
         String name_main(pool());  #include "_double.h"
         name_main.APPEND_CONST(MAIN_METHOD_NAME);  #include "_int.h"
   #include "_table.h"
         // looking for latest known @main  #include "_form.h"
         for(int i=classes_array().size(); --i>=0;) {  #include "_env.h"
                 VClass *vclass=static_cast<VClass *>(classes_array().get(i));  
                 Value *main=vclass->get_element(name_main);  String *exception_method_name;
                 if(main) { // found some 'main' element  
                         Junction *junction=main->get_junction();  String *unnamed_name;
                         if(junction) {// it even has junction!  String *empty_string;
                                 const Method *method=junction->method;  
                                 if(method) { // and junction is method-junction! call it  String *auto_method_name;
                                         // initialize contexts  String *main_method_name;
                                         self=root=rcontext=vclass;  
                                         wcontext=NEW WWrapper(pool(), vclass);  String *root_class_name;
                                           String *main_class_name;
                                         // execute!       String *env_class_name;
                                         execute(method->code);  String *table_class_name;
                                           String *form_class_name;
                                         // return chars  
                                         return wcontext->get_string()->cstr();  Hash *untaint_lang_name2enum;
                                 }  
                         }  
                 }  void core(Pool& pool) {
         }          #define NEW_STRING(name, value)  name=new(pool) String(pool); name->APPEND_CONST(value)
                   #define LOCAL_STRING(name, value)  String name(pool); name.APPEND_CONST(value)
         THROW(0,0,  
                 0,           // names
                 "'"MAIN_METHOD_NAME"' method not found");          NEW_STRING(exception_method_name, EXCEPTION_METHOD_NAME);
         return 0;  
           NEW_STRING(unnamed_name, UNNAMED_NAME);
           empty_string=new(pool) String(pool); 
   
           NEW_STRING(auto_method_name, AUTO_METHOD_NAME);
           NEW_STRING(main_method_name, MAIN_METHOD_NAME);
   
           NEW_STRING(root_class_name, ROOT_CLASS_NAME);
           NEW_STRING(main_class_name, MAIN_CLASS_NAME);
           NEW_STRING(table_class_name, TABLE_CLASS_NAME);
           NEW_STRING(env_class_name, ENV_CLASS_NAME);     
           NEW_STRING(form_class_name, FORM_CLASS_NAME);   
   
           // hashes
           untaint_lang_name2enum=new(pool) Hash(pool);
           LOCAL_STRING(as_is, "as-is");  
           untaint_lang_name2enum->put(as_is, (int)String::Untaint_lang::AS_IS);
           LOCAL_STRING(table, "table");
           untaint_lang_name2enum->put(table, (int)String::Untaint_lang::TABLE);
           LOCAL_STRING(sql, "sql");
           untaint_lang_name2enum->put(sql, (int)String::Untaint_lang::SQL);
           LOCAL_STRING(js, "js");
           untaint_lang_name2enum->put(js, (int)String::Untaint_lang::JS);
           LOCAL_STRING(html, "html");
           untaint_lang_name2enum->put(html, (int)String::Untaint_lang::HTML);
           LOCAL_STRING(html_typo, "html-typo");
           untaint_lang_name2enum->put(html_typo, (int)String::Untaint_lang::HTML_TYPO);
   
           // read-only stateless classes
           initialize_string_class(pool, *(string_class=new(pool) VStateless_class(pool)));  string_class->freeze();
           initialize_double_class(pool, *(double_class=new(pool) VStateless_class(pool)));  double_class->freeze();
           initialize_int_class(pool, *(int_class=new(pool) VStateless_class(pool)));  int_class->freeze();
           initialize_table_class(pool, *(table_class=new(pool) VStateless_class(pool)));  table_class->freeze();
   
           // read-only stateless base classes
           initialize_env_base_class(pool, *(env_base_class=new(pool) VStateless_class(pool)));  env_base_class->set_name(*env_class_name);  env_base_class->freeze();
           initialize_form_base_class(pool, *(form_base_class=new(pool) VStateless_class(pool)));  form_base_class->set_name(*form_class_name);  form_base_class->freeze();
 }  }

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


E-mail: