Annotation of parser3/src/main/pa_request.C, revision 1.3
1.1 paf 1: /*
1.3 ! paf 2: $Id: core.C,v 1.49 2001/03/10 11:18:15 paf Exp $
1.1 paf 3: */
4:
5: #include "pa_request.h"
1.3 ! paf 6: #include "pa_wwrapper.h"
! 7: #include "pa_common.h"
! 8: #include "pa_vclass.h"
! 9: #include "classes/_root.h"
! 10: #include "classes/_env.h"
! 11:
! 12: #include <stdio.h>
! 13:
! 14: Request::Request(Pool& apool) : Pooled(apool),
! 15: stack(apool),
! 16: root_class(apool),
! 17: env_class(apool),
! 18: fclasses(apool),
! 19: fclasses_array(apool),
! 20: lang(String::Untaint_lang::HTML_TYPO)
! 21: {
! 22: // root class
! 23: initialize_root_class(pool(), root_class);
! 24: // adding root superclass,
! 25: // parent of all classes,
! 26: // operators holder
! 27: String ROOT(pool()); ROOT.APPEND_CONST(ROOT_NAME);
! 28: classes().put(ROOT, &root_class);
! 29:
! 30: // env class
! 31: initialize_env_class(pool(), env_class);
! 32: String ENV(pool()); ENV.APPEND_CONST(ENV_NAME);
! 33: classes().put(ENV, &env_class);
! 34: }
1.1 paf 35:
36: void Request::core() {
1.3 ! paf 37: TRY {
! 38: char *file="Y:\\parser3\\src\\test.p";
! 39: String RUN(pool()); RUN.APPEND_CONST(RUN_NAME);
! 40: use(file, &RUN);
! 41:
! 42: char *result=execute_MAIN();
! 43: printf("result-----------------\n%sEOF----------------\n", result);
! 44: }
! 45: CATCH(e) {
! 46: printf("\nERROR: ");
! 47: const String *problem_source=e.problem_source();
! 48: if(problem_source) {
! 49: const Origin& origin=problem_source->origin();
! 50: if(origin.file)
! 51: printf("%s(%d): ",
! 52: origin.file, 1+origin.line);
! 53: printf("'%s' ",
! 54: problem_source->cstr());
! 55: }
! 56: printf("%s", e.comment());
1.1 paf 57: const String *type=e.type();
58: if(type) {
59: printf(" type: %s", type->cstr());
60: const String *code=e.code();
61: if(code)
62: printf(", code: %s", code->cstr());
63: }
1.3 ! paf 64: printf("\n");
1.1 paf 65: }
1.3 ! paf 66: END_CATCH
1.1 paf 67: }
68:
1.3 ! paf 69: void Request::use(char *file, String *name) {
! 70: // TODO: обнаружить|решить cyclic dependences
1.1 paf 71: char *source=file_read(pool(), file);
1.3 ! paf 72: if(!source)
! 73: THROW(0,0,
! 74: 0,
! 75: "use: can not read '%s' file", file);
! 76:
! 77: COMPILE(source, name, file);
! 78: // TODO: запустить @STATIC[], если есть
1.1 paf 79:
1.3 ! paf 80: // if(alias)
! 81: //classes().put(*alias, &vclass);
1.1 paf 82: }
83:
1.3 ! paf 84: char *Request::execute_MAIN() {
! 85: // locate class with @main & it's code
! 86: String name_main(pool());
1.1 paf 87: name_main.APPEND_CONST(MAIN_METHOD_NAME);
88:
1.3 ! paf 89: // looking for latest known @main
! 90: for(int i=classes_array().size(); --i>=0;) {
! 91: VClass *vclass=static_cast<VClass *>(classes_array().get(i));
! 92: Value *main=vclass->get_element(name_main);
! 93: if(main) { // found some 'main' element
! 94: Junction *junction=main->get_junction();
! 95: if(junction) {// it even has junction!
! 96: const Method *method=junction->method;
! 97: if(method) { // and junction is method-junction! call it
! 98: // initialize contexts
! 99: root=rcontext=self=vclass;
! 100: wcontext=NEW WWrapper(pool(), vclass, false /* not constructing */);
! 101:
! 102: // execute!
! 103: execute(*method->parser_code);
! 104:
! 105: // return chars
! 106: return wcontext->get_string()->cstr();
! 107: }
! 108: }
! 109: }
! 110: }
! 111:
! 112: THROW(0,0,
! 113: 0,
! 114: "'"MAIN_METHOD_NAME"' method not found");
! 115: return 0;
1.1 paf 116: }
E-mail: