--- parser3/src/main/compile_tools.h 2008/08/15 15:26:14 1.80 +++ parser3/src/main/compile_tools.h 2009/05/19 13:33:14 1.86 @@ -1,14 +1,14 @@ /** @file Parser: compiler support helper functions decls. - Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ #ifndef COMPILE_TOOLS #define COMPILE_TOOLS -static const char * const IDENT_COMPILE_TOOLS_H="$Date: 2008/08/15 15:26:14 $"; +static const char * const IDENT_COMPILE_TOOLS_H="$Date: 2009/05/19 13:33:14 $"; #include "pa_opcode.h" #include "pa_types.h" @@ -130,27 +130,31 @@ public: } } - bool class_reuse(){ - if(cclass_new){ - if(Value* class_value=request.classes().get(cclass_new->name())){ - if(VStateless_class* existed_class=class_value->get_class()) { - cclass=existed_class; - cclass_new=0; - append=true; - return true; - } else { - return false; - } + VStateless_class* get_existed_class(VStateless_class* aclass){ + if(aclass){ + if(Value* class_value=request.classes().get(aclass->name())){ + return class_value->get_class(); } } - return false; + return 0; + } + + bool reuse_existed_class(VStateless_class* aclass){ + if(aclass->is_partial()){ + cclass=aclass; + cclass_new=0; + append=true; + return true; + } else { + return false; + } } void set_all_vars_local(){ if(cclass_new){ - cclass_new->all_vars_local(); + cclass_new->set_all_vars_local(); } else { - cclass->all_vars_local(); + cclass->set_all_vars_local(); } } @@ -197,6 +201,11 @@ inline void P(ArrayOperation& result, Ar result.append(code_array, offset); } +/// aPpend part of 'code_array', starting from offset, to 'result' +inline void P(ArrayOperation& result, ArrayOperation& code_array, int offset, int limit) { + result.append(code_array, offset, limit); +} + /// append cOde Array inline void OA(ArrayOperation& result, OP::OPCODE code, ArrayOperation* code_array) { result+=Operation(code); // append OP_CODE @@ -222,10 +231,10 @@ inline ArrayOperation* VL(Value* value, } /// Literal Array to(2) Value @return Value from literal Array OP+origin+Value -Value* LA2V(ArrayOperation& literal_string_array, int offset=0); +Value* LA2V(ArrayOperation& literal_string_array, int offset=0, OP::OPCODE code=OP::OP_VALUE); /// Literal Array to(2) String @return String value from literal Array OP+origin+String array -inline const String* LA2S(ArrayOperation& literal_string_array, int offset=0) { - if(Value* value=LA2V(literal_string_array, offset)) +inline const String* LA2S(ArrayOperation& literal_string_array, int offset=0, OP::OPCODE code=OP::OP_VALUE) { + if(Value* value=LA2V(literal_string_array, offset, code)) return value->get_string(); return 0; } @@ -234,6 +243,11 @@ inline void change_string_literal_to_wri literal_string_array.put(0, OP::OP_STRING__WRITE); } +bool maybe_change_first_opcode(ArrayOperation& opcodes, OP::OPCODE find, OP::OPCODE replace, bool strict=false); + +bool maybe_change_first_opcode(ArrayOperation& opcodes, OP::OPCODE find, OP::OPCODE last, OP::OPCODE replace); + +bool append_2ops_opcode(ArrayOperation& opcodes, ArrayOperation& diving_code, OP::OPCODE code, size_t offset); void maybe_change_string_literal_to_double_literal(ArrayOperation& literal_string_array);