|
|
| version 1.26, 2001/03/11 08:16:34 | version 1.56, 2003/11/20 16:34:26 |
|---|---|
| Line 1 | Line 1 |
| /* | /** @file |
| Parser | Parser: compiler support helper functions. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | |
| $Id$ | Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | |
| */ | */ |
| static const char * const IDENT_COMPILE_TOOLS_C="$Date$"; | |
| #include "compile_tools.h" | #include "compile_tools.h" |
| #include "pa_string.h" | #include "pa_string.h" |
| #include "pa_array.h" | #include "pa_array.h" |
| Line 13 | Line 14 |
| #include "pa_vstring.h" | #include "pa_vstring.h" |
| #include "pa_vdouble.h" | #include "pa_vdouble.h" |
| void PV(Array/*<op>*/ *result, Value *value) { | Value* LA2V(ArrayOperation& literal_string_array, int offset) { |
| // append OP_VALUE | return literal_string_array[offset+0].code==OP_VALUE?literal_string_array[offset+2/*skip opcode&origin*/].value |
| Operation op; op.code=OP_VALUE; | :0; |
| *result+=op.cast; | |
| // append 'value' | |
| *result+=value; | |
| } | } |
| void PCA(Array/*<op>*/ *result, Array/*<op>*/ *code_array) { | void change_string_literal_to_double_literal(ArrayOperation& literal_string_array) { |
| // append OP_CODE | if(literal_string_array[0].code==OP_VALUE) { |
| Operation op; op.code=OP_CODE__STORE_PARAM; | Value& value=literal_string_array[2/*opcode+origin*/].value->as_expr_result(); |
| *result+=op.cast; | literal_string_array.put(1, &value); |
| } | |
| // append 'vstring' | |
| *result+=code_array; | |
| } | } |
| void change_string_literal_value(ArrayOperation& literal_string_array, const String& new_value) { | |
| Array *VL(Value *value) { | if(literal_string_array[0].code==OP_VALUE) { // extra safety |
| // empty ops array | static_cast<VString*>(literal_string_array[2/*opcode+origin*/].value)->set_string(new_value); |
| Array *result=N(value->pool()); | } |
| // append 'value' to 'result' | |
| PV(result, value); | |
| return result; | |
| } | } |
| const String *SLA2S(Array *literal_string_array, int offset) { | void changetail_or_append(ArrayOperation& opcodes, |
| Operation op; | OPCODE find, bool with_argument, OPCODE replace, OPCODE notfound) { |
| op.cast=literal_string_array->get(offset+0); | int tail=opcodes.count()-(with_argument?2:1); |
| if(op.code!=OP_VALUE) | if(tail>=0) { |
| return 0; | Operation& op=opcodes.get_ref(tail); |
| if(op.code==find) { | |
| op.code=replace; | |
| return; | |
| } | |
| } | |
| return static_cast<VString *>(literal_string_array->get(offset+1))->get_string(); | opcodes+=Operation(notfound); |
| } | } |
| void change_string_literal_to_double_literal(Array *literal_string_array) { | |
| VString *vstring=static_cast<VString *>(literal_string_array->get(1)); | |
| Value *value=vstring->get_expr_result(); | |
| literal_string_array->put(1, value); | |
| } | |
| void change_string_literal_to_write_string_literal(Array *literal_string_array) { | |
| Operation op; op.code=OP_STRING__WRITE; | |
| literal_string_array->put(0, op.cast); | |
| } | |
| void push_LS(struct parse_control *pc, lexical_state new_state) { | void push_LS(Parse_control& pc, lexical_state new_state) { |
| if(pc->sp<MAX_LEXICAL_STATES) { | if(pc.ls_sp<MAX_LEXICAL_STATES) { |
| pc->stack[pc->sp++]=pc->ls; pc->ls=new_state; | pc.ls_stack[pc.ls_sp++]=pc.ls; |
| pc.ls=new_state; | |
| } else | } else |
| pc->pool->THROW(0, 0, 0, "push_LS: stack overflow"); | throw Exception(0, 0, |
| "push_LS: ls_stack overflow"); | |
| } | } |
| void pop_LS(struct parse_control *pc) { | void pop_LS(Parse_control& pc) { |
| if(--pc->sp>=0) | if(--pc.ls_sp>=0) |
| pc->ls=pc->stack[pc->sp]; | pc.ls=pc.ls_stack[pc.ls_sp]; |
| else | else |
| pc->pool->THROW(0, 0, 0, "push_LS: stack underflow"); | throw Exception(0, 0, |
| "pop_LS: ls_stack underflow"); | |
| } | |
| const String& Parse_control::alias_method(const String& name) { | |
| return (main_alias && name==main_method_name)?*main_alias:name; | |
| } | } |