|
|
| version 1.18, 2001/03/08 09:31:47 | version 1.54.2.5.2.5, 2003/03/27 10:53:01 |
|---|---|
| Line 1 | Line 1 |
| /* | /** @file |
| $Id$ | Parser: compiler support helper functions. |
| Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) | |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | |
| */ | */ |
| static const char* 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 9 | 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+1].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[1].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[1].value)->set_string(new_value); |
| Array *result=N(value->pool()); | } |
| // append 'value' to 'result' | |
| PV(result, value); | |
| return result; | |
| } | } |
| Array *CL(VClass *vclass) { | |
| // empty ops array | |
| Array *result=N(vclass->pool()); | |
| // append OP_CLASS | void changetail_or_append(ArrayOperation& opcodes, |
| Operation op; op.code=OP_CLASS; | OPCODE find, bool with_argument, OPCODE replace, OPCODE notfound) { |
| *result+=op.cast; | int tail=opcodes.count()-(with_argument?2:1); |
| if(tail>=0) { | |
| // append 'vclass' | Operation& op=opcodes.unchecked_get_ref(tail); |
| *result+=vclass; | if(op.code==find) { |
| op.code=replace; | |
| return result; | return; |
| } | } |
| } | |
| String *SLA2S(Array *literal_string_array, int offset) { | |
| Operation op; | |
| op.cast=literal_string_array->get(offset+0); | |
| if(op.code!=OP_VALUE) | |
| return 0; | |
| return static_cast<VString *>(literal_string_array->get(offset+1))->get_string(); | |
| } | |
| void change_string_literal_to_double_literal(Array *literal_string_array) { | opcodes+=Operation(notfound); |
| VString *vstring=static_cast<VString *>(literal_string_array->get(1)); | |
| Pool& pool=vstring->pool(); | |
| VDouble *vdouble=new(pool) VDouble(pool, vstring->get_double()); | |
| literal_string_array->put(1, vdouble); | |
| } | } |
| 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"); | |
| } | } |