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

1.32      paf         1: /** @file
1.33      paf         2:        Parser: compiler support helper functions decls.
                      3: 
1.26      paf         4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.51      paf         5:        Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.26      paf         6: 
1.54    ! paf         7:        $Id: compile_tools.h,v 1.53 2002/01/24 17:18:48 paf Exp $
1.1       paf         8: */
                      9: 
                     10: #ifndef COMPILE_TOOLS
                     11: #define COMPILE_TOOLS
                     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.34      paf        20:        LS_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,
                     29:        LS_VAR_NAME_SIMPLE_WITH_COLON, LS_VAR_NAME_SIMPLE_WITHOUT_COLON,
1.1       paf        30:        LS_VAR_NAME_CURLY,
1.22      paf        31:        LS_VAR_ROUND,
1.18      paf        32:        LS_VAR_SQUARE,
1.1       paf        33:        LS_VAR_CURLY,
                     34:        LS_METHOD_NAME,
1.18      paf        35:        LS_METHOD_SQUARE,
1.1       paf        36:        LS_METHOD_CURLY,
1.22      paf        37:        LS_METHOD_ROUND,
1.1       paf        38:        LS_METHOD_AFTER
                     39: };
1.38      paf        40: /// compiler status
1.1       paf        41: struct parse_control {
1.38      paf        42:        //@{
                     43:        /// @name input
1.3       paf        44:        Pool *pool;
1.14      paf        45:        Request *request;
1.30      paf        46:        VStateless_class *cclass;
1.1       paf        47: #ifndef NO_CSTRING_ORIGIN
1.29      paf        48:        const char *source;
                     49:        const char *file;
1.44      parser     50: #endif
1.4       paf        51:        int line, col;
1.38      paf        52:        //@}
                     53:        //@{
                     54:        /// @name state; initially
1.45      parser     55:        bool trim_bof;
1.38      paf        56:        int pending_state; ///< i=0
                     57:        String *string; ///< =new(pool) String(pool)
1.1       paf        58:        
                     59: #define MAX_LEXICAL_STATES 100
1.38      paf        60:        enum lexical_state ls; ///< =LS_USER;
1.54    ! paf        61:        int ls_sp; ///< =0
        !            62:        enum lexical_state ls_stack[MAX_LEXICAL_STATES];
1.38      paf        63:        int brackets_nestages[MAX_LEXICAL_STATES]; ///< brackets nestage on each state
1.46      parser     64: 
1.47      parser     65:        bool object_constructor_allowed;
1.54    ! paf        66:        
        !            67: #define MAX_OPERATOR_STATES 100
        !            68:        bool operator_call_allowed; ///< =false
        !            69:        int oca_sp; ///< =0
        !            70:        bool oca_stack[MAX_OPERATOR_STATES];
1.38      paf        71:        //@}
1.1       paf        72:        
1.36      paf        73:        /// output: filled input 'methods' and 'error' if any
1.5       paf        74:        char error[MAX_STRING];
1.1       paf        75: };
                     76: 
1.36      paf        77: /// New array // return empty array
1.28      paf        78: inline Array/*<Operation>*/ *N(Pool& pool) {
                     79:        return new(pool) Array/*<Operation>*/(pool);
1.3       paf        80: }
                     81: 
1.36      paf        82: /// Assembler instruction // append ordinary instruction to ops
1.28      paf        83: inline void O(Array/*<Operation>*/ *result, enum OPCODE code) {
1.3       paf        84:        Operation op; op.code=code;
                     85:        *result+=op.cast;
                     86: }
                     87: 
1.36      paf        88: /// aPpend 'code_array' to 'result'
1.28      paf        89: inline void P(Array/*<Operation>*/ *result, Array *code_array) {
1.3       paf        90:        result->append_array(*code_array);
1.11      paf        91: }
1.36      paf        92: /// aPpend part of 'code_array', starting from offset, to 'result'
1.28      paf        93: inline void P(Array/*<Operation>*/ *result, Array *code_array, int offset) {
1.11      paf        94:        result->append_array(*code_array, offset);
1.3       paf        95: }
1.53      paf        96: 
1.36      paf        97: /// aPpend 'vstring' to 'result'
1.28      paf        98: void PV(Array/*<Operation>*/ *result, VString *vstring);
1.43      parser     99: /// Parameter 'simple Code_Array'
1.28      paf       100: void PCA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array);
1.43      parser    101: /// Parameter 'Expression code_Array'
1.31      paf       102: void PEA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array);
1.43      parser    103: /// Construct 'simple Code_Array'
                    104: void CCA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array);
1.53      paf       105: /// aPpend Nested Code
                    106: void PNC(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array);
1.1       paf       107: 
1.36      paf       108: /**
                    109:        Value Literal // returns array with 
                    110:        - first: OP_VALUE instruction
                    111:        - second op: string itself
                    112: */
1.21      paf       113: Array *VL(Value *value);
1.36      paf       114: /// Literal Array to(2) Value @return Value from literal Array OP+Value
                    115: Value *LA2V(Array *literal_string_array, int offset=0);
                    116: /// Literal Array to(2) String  @return String value from literal Array OP+String array
                    117: inline const String *LA2S(Array *literal_string_array, int offset=0) {
1.37      paf       118:        if(Value *value=LA2V(literal_string_array, offset))
                    119:                return value->get_string();
                    120:        return 0;
1.36      paf       121: }
1.19      paf       122: void change_string_literal_to_double_literal(Array *literal_string_array);
1.25      paf       123: void change_string_literal_to_write_string_literal(Array *literal_string_array);
1.1       paf       124: 
1.35      paf       125: void push_LS(parse_control& pc, lexical_state new_state);
                    126: void pop_LS(parse_control& pc);
1.54    ! paf       127: 
        !           128: void push_OCA(parse_control& pc, bool operator_call_allowed);
        !           129: void pop_OCA(parse_control& pc);
1.1       paf       130: 
                    131: #endif

E-mail: