Diff for /parser3/src/main/compile_tools.C between versions 1.2 and 1.65

version 1.2, 2001/02/20 19:21:13 version 1.65, 2009/05/23 05:23:03
Line 1 Line 1
 /*  /** @file
   $Id$          Parser: compiler support helper functions.
   
           Copyright (c) 2001-2009 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"
 #include "pa_exception.h"  #include "pa_exception.h"
   #include "pa_vstring.h"
   #include "pa_vdouble.h"
   
 void *N(void *apool) {  Value* LA2V(ArrayOperation& literal_string_array, int offset, OP::OPCODE code) {
         Pool& pool=*static_cast<Pool *>(apool);          return literal_string_array[offset+0].code==code?literal_string_array[offset+2/*skip opcode&origin*/].value
         return new(pool) Array(pool);                  :0;
 }  }
   
 void A(void **result, enum OPCODE acode) {  void maybe_change_string_literal_to_double_literal(ArrayOperation& literal_array) {
         int code=acode;          assert(literal_array[0].code==OP::OP_VALUE);
         (*static_cast<Array *>(*result))+=reinterpret_cast<Array::Item *>(code);          VString& vstring=*static_cast<VString*>(literal_array[2/*opcode+origin*/].value);
           if(isdigit(vstring.string().first_char()))
                   literal_array.put(2/*opcode+origin*/, &vstring.as_expr_result());
 }  }
   
 void G(void **result, void *param) {  void change_string_literal_value(ArrayOperation& literal_string_array, const String& new_value) {
         (*static_cast<Array *>(*result))+=param;          assert(literal_string_array[0].code==OP::OP_VALUE);
           static_cast<VString*>(literal_string_array[2/*opcode+origin*/].value)->set_string(new_value);
 }  }
   
 void *L(void *astring) {  void changetail_or_append(ArrayOperation& opcodes, 
         String *string=static_cast<String *>(astring);                                                    OP::OPCODE find, bool with_argument, OP::OPCODE replace, OP::OPCODE notfound) {
           int tail=opcodes.count()-(with_argument?2:1);
           if(tail>=0) {
                   Operation& op=opcodes.get_ref(tail);
                   if(op.code==find) {
                           op.code=replace;
                           return;
                   }
           }
   
         // empty ops array          opcodes+=Operation(notfound);
         void *result=N(&string->pool());  }
   
         // append OP_STRING  
         int code=OP_STRING;  
         *(static_cast<Array *>(result))+=reinterpret_cast<Array::Item *>(code);  
   
         // append 'string'  bool maybe_change_first_opcode(ArrayOperation& opcodes, OP::OPCODE find, OP::OPCODE replace, bool strict) {
         *(static_cast<Array *>(result))+=string;          if(opcodes[0].code==find){
                   opcodes.put(0, replace);
                   return true;
           }
           if(strict)
                   assert(opcodes[0].code==find);
   
         return result;          return false;
 }  }
   
 void *LS(void *literal) {  
         return const_cast<void *>(static_cast<Array *>(literal)->get(1));  
 }  
   
 void P(void **result, void *code_array) {  bool maybe_change_first_opcode(ArrayOperation& opcodes, OP::OPCODE find, OP::OPCODE last, OP::OPCODE replace) {
         (*(static_cast<Array *>(*result))).append_array(*static_cast<Array *>(code_array));          if(opcodes[0].code==find && opcodes[opcodes.count()-1].code==last){
                   opcodes.put(0, replace);
                   return true;
           }
           return false;
 }  }
   
   
   void push_LS(Parse_control& pc, lexical_state new_state) { 
 void push_LS(struct parse_control *pc) {          if(pc.ls_sp<MAX_LEXICAL_STATES) {
         if(pc->sp<MAX_LEXICAL_STATES) {                  pc.ls_stack[pc.ls_sp++]=pc.ls;  
                 pc->stack[pc->sp++]=pc->ls;  pc->ls=LS_VAR_NAME_SIMPLE;                  pc.ls=new_state;
         } else          } else
                 (static_cast<Pool *>(pc->pool))->exception().raise(0, 0, 0,                   throw Exception(0, 0, 
                         "push_LS: stack overflow");                          "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
                 (static_cast<Pool *>(pc->pool))->exception().raise(0, 0, 0,                   throw Exception(0, 0, 
                         "push_LS: stack underflow");                          "pop_LS: ls_stack underflow");
 }  
   
 void *string_create(void *apool) {  
         Pool& pool=*static_cast<Pool *>(apool);  
         return new(pool) String(pool);  
 }  
   
 void real_cstring_append(CSTRING_APPEND_PARAMS) {  
         static_cast<String *>(astring)->APPEND(piece, size, file, line);  
 }  }
   
 char *string_cstr(void *astring) {  const String& Parse_control::alias_method(const String& name) {
         return static_cast<String *>(astring)->cstr();          return (main_alias && name==main_method_name)?*main_alias:name;
 }  
   
 /* exception */  
   
 void exception(void *pool,   
                 void *atype, void *acode,  
                 void *aproblem_source,   
                 char *acomment) {  
         static_cast<Pool *>(pool)->exception().raise(  
                 static_cast<class String *>(atype),   
                 static_cast<class String *>(acode),   
                 static_cast<class String *>(aproblem_source),   
                 acomment);  
 }  }

Removed from v.1.2  
changed lines
  Added in v.1.65


E-mail: