--- parser3/src/main/Attic/core.C 2001/02/12 11:34:12 1.2 +++ parser3/src/main/Attic/core.C 2001/03/12 13:13:21 1.61 @@ -1,122 +1,79 @@ -void process(Pool& pool, - Value& self, - RContext& rcontext, WContext& wcontext, - StringIterator& code, char char_to_stop_before) { - - // $ on code? - process_dollar(pool, rcontext, wcontext, code, char_to_stop_before); - - // ^ on code? - process_bird(pool, rcontext, wcontext, code, char_to_stop_before); -} - -void process_dollar(Pool& pool, - Value& THIS, - RContext& rcontext, WContext& wcontext, - StringIterator& iter, char char_to_stop_before) { - - // $name.field.subfield -- read - // $name.field.subfield(constructor code) -- construct - // $name.field.subfield[usage code & if none existed autoconstructed as VHash] -- use OR auto-VHash construct - - Array/**/ names(pool); // what.they.refer.to left-to-right list - char names_ended_before; // the char after long name - get_names( - iter, " ([", - &names, &names_ended_before); // must return count()>0 - - bool read_mode=name_ended_before==' '; - Value *context=read_mode?rcontext:wcontext; - - if(read_mode) { - for(int i=0; iget_element(static_cast(names.get[i])); - if(!context) // no such object field, nothing bad, just ignore that - return; - } - wcontext.write(context); - } else { // write mode - iter++; // skip '(' '[' - - bool construct_mode=names_ended_before=='('; - - int steps=names.count(); - if(construct_mode) - steps--; - for(int i=0; i(names.get[i]); - Value *next_current=context->get_element(name); - if(next_current) - next_current=context->put_element(name, new(pool) VHash(pool)); - context=new_current; - } - - if(construct_mode) { - // pure side effect, no wcontext.write here - String& name=static_cast(names.get[steps]); - WContext local_wcontext(pool /* empty */); - process(pool, rcontext, local_wcontext, iter, ')'); - context->put_element(name, local_wcontext.value()); - } else { // =='[' - WContext local_context(pool, context); - process(pool, local_context, local_context, iter, ']'); - wcontext.write(local_context); - } - - iter++; // skip ')' ']' - } +/* + Parser + Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: core.C,v 1.61 2001/03/12 13:13:21 paf Exp $ +*/ + +#include "core.h" +#include "_string.h" +#include "_double.h" +#include "_int.h" +#include "_table.h" +#include "pa_request.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() { + Pool pool; + + // names + GLOBAL_STRING(unnamed_name, "unnamed"); + empty_string=new(pool) String(pool); + + 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); + 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(String::Untaint_lang::AS_IS)); + LOCAL_STRING(table, "table"); + untaint_lang_name2enum->put(table, + static_cast(String::Untaint_lang::TABLE)); + LOCAL_STRING(sql, "sql"); + untaint_lang_name2enum->put(sql, + static_cast(String::Untaint_lang::SQL)); + LOCAL_STRING(js, "js"); + untaint_lang_name2enum->put(js, + static_cast(String::Untaint_lang::JS)); + LOCAL_STRING(html, "html"); + untaint_lang_name2enum->put(html, + static_cast(String::Untaint_lang::HTML)); + LOCAL_STRING(html_typo, "html-typo"); + untaint_lang_name2enum->put(html_typo, + static_cast(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(); } -void process_bird(Pool& pool, - Value& self, - RContext& rcontext, WContext& wcontext, - StringIterator& iter, char char_to_stop_before) { - - // ^name.field.subfield.method[..] -- plain call - // ^name.field.subfield.method_ref[..] -- method ref call, when .get_method()!=0 - - Array/**/ names(pool); // what.they.refer.to left-to-right list - char names_ended_before; // the char after long name - get_names( - iter, "[", - &names, &names_ended_before); // must return count()>0 - - Value *context=rcontext; - iter++; // skip '[' - - Value *local_self=context; - int steps=names.count()-1; - for(int i=0; i(names.get[i]); - context=(local_self=context)->get_element(name); - if(!context) // no such object field, sad story: can't call method of void - pool.exception().raise(name, "call: to void.method"); - } - - String& name=static_cast(names.get[steps]); - // first we're trying to locate method with that 'name' - Method *method=context.get_method(name); - if(!method) { // no such method: try to locate method ref field - Value *value=context.get_element(name); - if(!value) // failed: no element of that 'name' - pool.exception().raise(name, "call: no method field found"); - method=value->get_method(); - if(!method) // failed: that field wasn't method_ref - pool.exception().raise(name, "call: this field is not a method reference"); - local_self=value->get_self(); - } - - - Array/**/ param_values(pool); - get_params( - iter, "]", - ¶m_values); - iter++; // skip ']' - - Method_self_n_params local_rcontext(pool, - local_self, - method->param_names, param_values); - WContext local_wcontext(pool /* empty */); - process(pool, local_rcontext, local_wcontext, iter, ']'); - wcontext.write(local_wcontext); -} \ No newline at end of file