--- parser3/src/main/Attic/core.C 2001/02/24 15:35:28 1.36 +++ parser3/src/main/Attic/core.C 2001/03/11 12:10:43 1.59 @@ -1,95 +1,72 @@ /* -$Id: core.C,v 1.36 2001/02/24 15:35:28 paf Exp $ + Parser + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: core.C,v 1.59 2001/03/11 12:10:43 paf Exp $ */ +#include "core.h" +#include "_string.h" +#include "_double.h" +#include "_int.h" #include "pa_request.h" -#include "pa_wwrapper.h" -#include "pa_common.h" -#include "pa_vclass.h" -#include +#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; + +Hash *untaint_lang_name_to_enum; + void core() { Pool pool; - Request request(pool); - request.core(); -} + + // names + GLOBAL_STRING(unnamed_name, "unnamed"); + empty_string=new(pool) String(pool); -void Request::core() { - 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 -} + GLOBAL_STRING(auto_method_name, AUTO_METHOD_NAME); + GLOBAL_STRING(main_method_name, MAIN_METHOD_NAME); + + GLOBAL_STRING(main_class_name, MAIN_CLASS_NAME); + GLOBAL_STRING(root_class_name, ROOT_CLASS_NAME); + GLOBAL_STRING(env_class_name, ENV_CLASS_NAME); + + // hashes + untaint_lang_name_to_enum=new(pool) Hash(pool); + LOCAL_STRING(as_is, "as-is"); + untaint_lang_name_to_enum->put(as_is, + static_cast(String::Untaint_lang::AS_IS)); + LOCAL_STRING(sql, "sql"); + untaint_lang_name_to_enum->put(sql, + static_cast(String::Untaint_lang::SQL)); + LOCAL_STRING(js, "js"); + untaint_lang_name_to_enum->put(js, + static_cast(String::Untaint_lang::JS)); + LOCAL_STRING(html, "html"); + untaint_lang_name_to_enum->put(html, + static_cast(String::Untaint_lang::HTML)); + LOCAL_STRING(html_typo, "html-typo"); + untaint_lang_name_to_enum->put(html_typo, + static_cast(String::Untaint_lang::HTML_TYPO)); + + // classes + 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))); -void Request::use(char *file, String *name) { - char *source=file_read(pool(), 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); + // request + Request request(pool); + request.core(); } -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(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; -}