pike.git / src / program.c

version» Context lines:

pike.git/src/program.c:1312:    */      /*! @endclass    */      struct program *first_program = 0;   static int current_program_id = PROG_DYNAMIC_ID_START;      struct program *null_program=0;    + static struct program *reporter_program = NULL;   struct program *compilation_program = 0;   struct program *compilation_env_program = 0;   struct object *compilation_environment = NULL;      struct program *gc_internal_program = 0;   static struct program *gc_mark_program_pos = 0;      #ifdef PIKE_DEBUG   #define CHECK_FILE_ENTRY(PROG, POS, LEN, SHIFT) \    do { \
pike.git/src/program.c:7800:    verify_supporters();    ret++; /* dependency registred */    }    }    }    }    verify_supporters();    return ret;   }    - /*! @module DefaultCompilerEnvironment + /*! @class Reporter    *! -  *! The @[CompilerEnvironment] object that is used -  *! for loading C-modules and by @[predef::compile()]. -  *! -  *! @note -  *! @[predef::compile()] is essentially an alias for the -  *! @[CompilerEnvironment()->compile()] in this object. -  *! -  *! @seealso -  *! @[CompilerEnvironment], @[predef::compile()] +  *! API for reporting parse errors and similar.    */    - /*! @endmodule -  */ -  - /*! @class CompilerEnvironment -  *! -  *! The compiler environment. -  *! -  *! By inheriting this class and overloading the functions, -  *! it is possible to make a custom Pike compiler. -  *! -  *! @note -  *! Prior to Pike 7.8 this sort of customization has to be done -  *! either via custom master objects, or via @[CompilationHandler]s. -  *! -  *! @seealso -  *! @[CompilationHandler], @[MasterObject], @[master()], @[replace_master()] -  */ -  +    /*! @decl enum SeverityLevel    *! Message severity level.    *! { NOTICE, WARNING, ERROR, FATAL }    *!    *! @constant NOTICE    *! @constant WARNING    *! @constant ERROR    *! @constant FATAL    *!    *! @seealso
pike.git/src/program.c:7895:    *!    *! If there's no master object yet, the diagnostic is output to    *! @[Stdio.stderr].    *!    *! @note    *! In Pike 7.8 and earlier @[MasterObject()->report()] was not called.    *!    *! @seealso    *! @[PikeCompiler()->report()]    */ - static void f_compilation_env_report(INT32 args) + /* NOTE: This function MUST NOT use any storage in the Reporter program! */ + static void f_reporter_report(INT32 args)   {    int level;    struct pike_string *filename;    INT_TYPE linenumber;    struct pike_string *subsystem;    struct pike_string *message;    struct object *master_ob;       if ((master_ob = get_master()) && master_ob->prog) {    int fun = find_identifier("report", master_ob->prog);
pike.git/src/program.c:7949:    fprintf(stderr, "%s:%ld: Warning: %s\n",    filename->str, linenumber, message->str);    }    fflush(stderr);    }    }    pop_n_elems(args);    push_int(0);   }    + /*! @endclass +  */ +  + /*! @module DefaultCompilerEnvironment +  *! +  *! The @[CompilerEnvironment] object that is used +  *! for loading C-modules and by @[predef::compile()]. +  *! +  *! @note +  *! @[predef::compile()] is essentially an alias for the +  *! @[CompilerEnvironment()->compile()] in this object. +  *! +  *! @seealso +  *! @[CompilerEnvironment], @[predef::compile()] +  */ +  + /*! @endmodule +  */ +  + /*! @class CompilerEnvironment +  *! +  *! The compiler environment. +  *! +  *! By inheriting this class and overloading the functions, +  *! it is possible to make a custom Pike compiler. +  *! +  *! @note +  *! Prior to Pike 7.8 this sort of customization has to be done +  *! either via custom master objects, or via @[CompilationHandler]s. +  *! +  *! @seealso +  *! @[CompilationHandler], @[MasterObject], @[master()], @[replace_master()] +  */ +  + /*! @decl inherit Reporter +  *! +  *! Implements the @[Reporter] API. +  *! +  *! @seealso +  *! @[Reporter()->report()], @[Reporter()->SeverityLevel] +  */ +    /*! @decl program compile(string source, CompilationHandler|void handler, @    *! int|void major, int|void minor,@    *! program|void target, object|void placeholder)    *!    *! Compile a string to a program.    *!    *! This function takes a piece of Pike code as a string and    *! compiles it into a clonable program.    *!    *! The optional argument @[handler] is used to specify an alternative
pike.git/src/program.c:9662:    p2->flags |= PROGRAM_PASS_1_DONE;    co = parent_clone_object(p2, compilation_environment,    CE_PIKE_COMPILER_FUN_NUM, 0);    p2->flags &= ~PROGRAM_PASS_1_DONE;       low_enter_compiler(co, 0);       low_start_new_program(p, 1, NULL, 0, NULL);    free_program(p); /* Remove the extra ref we just got... */    -  ADD_FUNCTION("report", f_compilation_env_report, +  /* NOTE: The order of these identifiers is hard-coded in +  * the CE_*_FUN_NUM definitions in "pike_compiler.h". +  */ +  +  /* NB: Overloaded properly by inherit of Reporter later on. */ +  ADD_FUNCTION("report", f_reporter_report,    tFuncV(tName("SeverityLevel", tInt03) tStr tIntPos    tStr tStr, tMix, tVoid),0);       ADD_FUNCTION("compile", f_compilation_env_compile,    tFunc(tOr(tStr, tVoid) tOr(tObj, tVoid)    tOr(tInt, tVoid) tOr(tInt, tVoid)    tOr(tPrg(tObj), tVoid) tOr(tObj, tVoid),    tPrg(tObj)), 0);       ADD_FUNCTION("resolv", f_compilation_env_resolv,
pike.git/src/program.c:9790:    f_compilation_env_get_compilation_handler,    tFunc(tInt tInt, tObj), 0);       ADD_FUNCTION("get_default_module",    f_compilation_env_get_default_module,    tFunc(tNone, tOr(tMap(tStr, tMix), tObj)), 0);       ADD_FUNCTION("handle_inherit", f_compilation_env_handle_inherit,    tFunc(tStr tStr tOr(tObj, tVoid), tPrg(tObj)), 0);    +  /* Reporter */ +  start_new_program();    {    struct svalue type_value;    -  +  ADD_FUNCTION("report", f_reporter_report, +  tFuncV(tName("SeverityLevel", tInt03) tStr tIntPos +  tStr tStr, tMix, tVoid),0); +     /* enum SeverityLevel { NOTICE, WARNING, ERROR, FATAL } */    SET_SVAL(type_value, PIKE_T_TYPE, 0, type,    CONSTTYPE(tName("SeverityLevel", tInt03)));    simple_add_constant("SeverityLevel", &type_value, 0);    free_svalue(&type_value);       add_integer_constant("NOTICE", REPORT_NOTICE, 0);    add_integer_constant("WARNING", REPORT_WARNING, 0);    add_integer_constant("ERROR", REPORT_ERROR, 0);    add_integer_constant("FATAL", REPORT_FATAL, 0); -  +  +  reporter_program = end_program();    } -  +  add_global_program("Reporter", reporter_program);    -  +  low_inherit(reporter_program, NULL, -1, 0, 0, 0); +     compilation_env_program = end_program();       add_global_program("CompilerEnvironment", compilation_env_program);       exit_compiler();       ref_push_object(compilation_environment);    low_add_constant("DefaultCompilerEnvironment", Pike_sp-1);    pop_stack();   }
pike.git/src/program.c:10313:    compilation_program = 0;    }    if (compilation_environment) {    free_object(compilation_environment);    compilation_environment = 0;    }    if (compilation_env_program) {    free_program(compilation_env_program);    compilation_env_program = 0;    } +  if (reporter_program) { +  free_program(reporter_program); +  reporter_program = 0;    } -  + }         PMOD_EXPORT void visit_program (struct program *p, int action)   {    switch (action) {   #ifdef PIKE_DEBUG    default:    Pike_fatal ("Unknown visit action %d.\n", action);    case VISIT_NORMAL:    case VISIT_COMPLEX_ONLY: