Annotation of parser3/src/main/compile_tools.h, revision 1.67.2.1

1.32      paf         1: /** @file
1.33      paf         2:        Parser: compiler support helper functions decls.
                      3: 
1.67      paf         4:        Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.58      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef COMPILE_TOOLS
                      9: #define COMPILE_TOOLS
1.62      paf        10: 
1.67.2.1! paf        11: static const char* IDENT_COMPILE_TOOLS_H="$Date: 2003/01/21 15:51:13 $";
1.1       paf        12: 
1.39      paf        13: #include "pa_opcode.h"
1.1       paf        14: #include "pa_types.h"
1.10      paf        15: #include "pa_vstring.h"
1.14      paf        16: #include "pa_request.h"
1.1       paf        17: 
                     18: enum lexical_state {
1.48      parser     19:        LS_USER, LS_NAME_SQUARE_PART,
1.65      paf        20:        LS_USER_COMMENT,
1.7       paf        21:        LS_DEF_NAME,
                     22:        LS_DEF_PARAMS,
                     23:        LS_DEF_LOCALS,
                     24:        LS_DEF_COMMENT,
1.18      paf        25:        LS_DEF_SPECIAL_BODY,
1.42      parser     26:        LS_EXPRESSION_STRING_QUOTED,
                     27:        LS_EXPRESSION_STRING_APOSTROFED,
1.48      parser     28:        LS_EXPRESSION_VAR_NAME_WITH_COLON, LS_EXPRESSION_VAR_NAME_WITHOUT_COLON,
1.65      paf        29:        LS_EXPRESSION_COMMENT,
1.48      parser     30:        LS_VAR_NAME_SIMPLE_WITH_COLON, LS_VAR_NAME_SIMPLE_WITHOUT_COLON,
1.1       paf        31:        LS_VAR_NAME_CURLY,
1.22      paf        32:        LS_VAR_ROUND,
1.18      paf        33:        LS_VAR_SQUARE,
1.1       paf        34:        LS_VAR_CURLY,
                     35:        LS_METHOD_NAME,
1.18      paf        36:        LS_METHOD_SQUARE,
1.1       paf        37:        LS_METHOD_CURLY,
1.22      paf        38:        LS_METHOD_ROUND,
1.1       paf        39:        LS_METHOD_AFTER
                     40: };
1.38      paf        41: /// compiler status
1.1       paf        42: struct parse_control {
1.38      paf        43:        //@{
                     44:        /// @name input
1.3       paf        45:        Pool *pool;
1.14      paf        46:        Request *request;
1.30      paf        47:        VStateless_class *cclass;
1.66      paf        48: #ifndef NO_STRING_ORIGIN
1.29      paf        49:        const char *source;
                     50:        const char *file;
1.44      parser     51: #endif
1.4       paf        52:        int line, col;
1.38      paf        53:        //@}
                     54:        //@{
                     55:        /// @name state; initially
1.45      parser     56:        bool trim_bof;
1.38      paf        57:        int pending_state; ///< i=0
1.67.2.1! paf        58:        StringPtr string; ///< lexical string accumulator
1.1       paf        59:        
                     60: #define MAX_LEXICAL_STATES 100
1.38      paf        61:        enum lexical_state ls; ///< =LS_USER;
1.54      paf        62:        int ls_sp; ///< =0
                     63:        enum lexical_state ls_stack[MAX_LEXICAL_STATES];
1.38      paf        64:        int brackets_nestages[MAX_LEXICAL_STATES]; ///< brackets nestage on each state
1.46      parser     65: 
1.56      paf        66:        bool in_call_value;
1.38      paf        67:        //@}
1.1       paf        68:        
1.36      paf        69:        /// output: filled input 'methods' and 'error' if any
1.5       paf        70:        char error[MAX_STRING];
1.1       paf        71: };
                     72: 
1.36      paf        73: /// New array // return empty array
1.67.2.1! paf        74: inline ArrayCodePtr N() {
        !            75:        return new ArrayCode;
1.3       paf        76: }
                     77: 
1.36      paf        78: /// Assembler instruction // append ordinary instruction to ops
1.28      paf        79: inline void O(Array/*<Operation>*/ *result, enum OPCODE code) {
1.3       paf        80:        Operation op; op.code=code;
                     81:        *result+=op.cast;
                     82: }
                     83: 
1.36      paf        84: /// aPpend 'code_array' to 'result'
1.28      paf        85: inline void P(Array/*<Operation>*/ *result, Array *code_array) {
1.3       paf        86:        result->append_array(*code_array);
1.11      paf        87: }
1.36      paf        88: /// aPpend part of 'code_array', starting from offset, to 'result'
1.28      paf        89: inline void P(Array/*<Operation>*/ *result, Array *code_array, int offset) {
1.11      paf        90:        result->append_array(*code_array, offset);
1.3       paf        91: }
1.53      paf        92: 
1.36      paf        93: /// aPpend 'vstring' to 'result'
1.61      paf        94: void PV(Array/*<Operation>*/ *result, Value *value);
                     95: 
                     96: inline void OA(Array/*<Operation>*/ *result, OPCODE opcode, Array/*<Operation>*/ *code_array) {
                     97:        // append OP_CODE
                     98:        Operation op; op.code=opcode;
                     99:        *result+=op.cast;
                    100: 
                    101:        // append 'vstring'
                    102:        *result+=code_array;
                    103: }
1.1       paf       104: 
1.36      paf       105: /**
                    106:        Value Literal // returns array with 
                    107:        - first: OP_VALUE instruction
                    108:        - second op: string itself
                    109: */
1.61      paf       110: inline Array *VL(Value *value) {
                    111:        // empty ops array
                    112:        Array *result=N(value->pool());
                    113: 
                    114:        // append 'value' to 'result'
                    115:        PV(result, value);
                    116: 
                    117:        return result;
                    118: }
                    119: 
1.36      paf       120: /// Literal Array to(2) Value @return Value from literal Array OP+Value
                    121: Value *LA2V(Array *literal_string_array, int offset=0);
                    122: /// Literal Array to(2) String  @return String value from literal Array OP+String array
                    123: inline const String *LA2S(Array *literal_string_array, int offset=0) {
1.37      paf       124:        if(Value *value=LA2V(literal_string_array, offset))
                    125:                return value->get_string();
                    126:        return 0;
1.36      paf       127: }
1.61      paf       128: 
                    129: inline void change_string_literal_to_write_string_literal(Array *literal_string_array) {
                    130:        Operation op; op.code=OP_STRING__WRITE;
                    131:        literal_string_array->put(0, op.cast);
                    132: }
                    133: 
                    134: void changetail_or_append(Array *opcodes, 
                    135:                                                  OPCODE find, bool with_argument, OPCODE replace, OPCODE notfound);
                    136: 
1.19      paf       137: void change_string_literal_to_double_literal(Array *literal_string_array);
1.64      paf       138: 
                    139: void change_string_literal_value(Array *literal_string_array, const String& new_value);
1.1       paf       140: 
1.35      paf       141: void push_LS(parse_control& pc, lexical_state new_state);
                    142: void pop_LS(parse_control& pc);
1.1       paf       143: 
                    144: #endif

E-mail: