e021fe2008-04-14Henrik Grubbström (Grubba) /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */ #ifndef PIKE_COMPILER_H #define PIKE_COMPILER_H #include "lex.h" #include "program.h"
dd40072017-02-02Henrik Grubbström (Grubba) extern struct program *compilation_env_program; extern struct program *compilation_program; extern struct object *compilation_environment; typedef int supporter_callback (void *, int); struct Supporter { #ifdef PIKE_DEBUG int magic; #endif struct Supporter *previous; /* Makes up a linked list of supporters with the first one in * current_supporter. Supporters are linked onto this list during * the (recursive) compilation of each compilation unit (i.e. * compiled string). Thus nested programs and programs built from C * don't have supporters. */ struct Supporter *depends_on; /* The supporter furthest in on the current_supporter linked list * that this one depends on. When it gets unlinked from that list, * this becomes a back pointer for the dependants linked list * below. */ struct Supporter *dependants, *next_dependant; /* dependants points to a linked list of supporters that depends on * this one, and next_dependant makes up the links between those * supporters. A supporter is linked onto this list when it is * unlinked from the current_supporter list. */ struct object *self; supporter_callback *fun; void *data; struct program *prog; /* The top level program in the compilation unit. */ };
e021fe2008-04-14Henrik Grubbström (Grubba) struct compilation { struct Supporter supporter; struct pike_string *prog; /* String to compile. */ struct object *handler; /* error_handler */ struct object *compat_handler; /* compat_handler */
e048d52008-04-25Henrik Grubbström (Grubba)  int major, minor; /* Base compat version */
e021fe2008-04-14Henrik Grubbström (Grubba)  struct program *target; /* Program being compiled. */ struct object *placeholder;
41c9152008-04-18Henrik Grubbström (Grubba)  int flags;
13670c2015-05-25Martin Nilsson 
e021fe2008-04-14Henrik Grubbström (Grubba)  struct program *p; /* Compiled program or NULL. */ struct lex lex; int compilation_inherit; /* Inherit in supporter->self containing * compilation_program. */
5b84a52008-04-26Henrik Grubbström (Grubba) 
8853882008-04-26Henrik Grubbström (Grubba)  struct svalue default_module; /* predef:: */
2d10fb2016-12-29Arne Goedeke  struct byte_buffer used_modules; /* Stack of svalues with imported
5b84a52008-04-26Henrik Grubbström (Grubba)  * modules. */ INT32 num_used_modules; /* Number of entries on the stack. */
8853882008-04-26Henrik Grubbström (Grubba)  int compilation_depth; /* Current class nesting depth. */
9d80342013-08-14Marcus Comstedt #ifdef PIKE_THREADS
8b5b3a2014-04-28Henrik Grubbström (Grubba)  int saved_lock_depth;
9d80342013-08-14Marcus Comstedt #endif
518b042011-11-20Henrik Grubbström (Grubba)  struct mapping *resolve_cache;
e021fe2008-04-14Henrik Grubbström (Grubba) }; #ifdef PIKE_DEBUG #define CHECK_COMPILER() do { \ if (!Pike_fp || !compilation_program || \ Pike_fp->context->prog != compilation_program) { \ Pike_fatal("Invalid compilation context!\n"); \ } \ } while(0) #else #define CHECK_COMPILER() #endif #define THIS_COMPILATION ((struct compilation *)(Pike_fp->current_storage)) #define MAYBE_THIS_COMPILATION ((Pike_fp && compilation_program && (Pike_fp->context->prog == compilation_program))?THIS_COMPILATION:NULL)
41c9152008-04-18Henrik Grubbström (Grubba) /* Flags. */ #define COMPILER_BUSY 1 /* The compiler is busy compiling. */
ec994b2008-08-13Martin Stjernholm #define COMPILER_DONE 2 /* The compiler is finished compiling. */
41c9152008-04-18Henrik Grubbström (Grubba)  /* CompilerEnvironment function numbers. */
17799f2008-04-24Henrik Grubbström (Grubba) #define CE_REPORT_FUN_NUM 0 #define CE_COMPILE_FUN_NUM 1 #define CE_RESOLV_FUN_NUM 2 #define CE_PIKE_COMPILER_FUN_NUM 3 #define CE_GET_COMPILATION_HANDLER_FUN_NUM 4 #define CE_GET_DEFAULT_MODULE_FUN_NUM 5
1f91c02008-05-02Henrik Grubbström (Grubba) #define CE_HANDLE_INHERIT_FUN_NUM 6
41c9152008-04-18Henrik Grubbström (Grubba)  /* PikeCompiler function numbers. */
1f91c02008-05-02Henrik Grubbström (Grubba) #define PC_HANDLE_INHERIT_FUN_NUM 7
08e8662008-05-03Henrik Grubbström (Grubba) #define PC_POP_TYPE_ATTRIBUTE_FUN_NUM 8 #define PC_PUSH_TYPE_ATTRIBUTE_FUN_NUM 9
b0b9392008-05-04Henrik Grubbström (Grubba) #define PC_APPLY_TYPE_ATTRIBUTE_FUN_NUM 10
ec53782008-05-18Henrik Grubbström (Grubba) #define PC_APPLY_ATTRIBUTE_CONSTANT_FUN_NUM 11
e021fe2008-04-14Henrik Grubbström (Grubba) 
1420732017-02-08Henrik Grubbström (Grubba) extern struct program *null_program; extern struct program *placeholder_program; extern struct object *placeholder_object;
dd40072017-02-02Henrik Grubbström (Grubba) /* Prototypes begin here */ PMOD_EXPORT void lock_pike_compiler(void); PMOD_EXPORT void unlock_pike_compiler(void); void verify_supporters(void); void init_supporter(struct Supporter *s, supporter_callback *fun, void *data); int unlink_current_supporter(struct Supporter *c); int call_dependants(struct Supporter *s, int finish); int report_compiler_dependency(struct program *p); struct compilation; void run_pass2(struct compilation *c); PMOD_EXPORT void enter_compiler(struct pike_string *filename, INT_TYPE linenumber); PMOD_EXPORT void exit_compiler(void); struct program *compile(struct pike_string *aprog, struct object *ahandler, int amajor, int aminor, struct program *atarget, struct object *aplaceholder);
2f07ac2017-02-04Henrik Grubbström (Grubba) void push_compiler_frame(int lexical_scope); node *low_pop_local_variables(int level, node *block); node *pop_local_variables(int level, node *block); void pop_compiler_frame(void); PMOD_EXPORT void change_compiler_compatibility(int major, int minor);
dd40072017-02-02Henrik Grubbström (Grubba) void init_pike_compiler(void); void cleanup_pike_compiler(void); /* Prototypes end here */
e021fe2008-04-14Henrik Grubbström (Grubba) #endif /* !PIKE_COMPILER_H */