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

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.33      paf         5: 
1.27      paf         6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.26      paf         7: 
1.38    ! paf         8:        $Id: compile_tools.h,v 1.37 2001/04/19 18:30:40 paf Exp $
1.1       paf         9: */
                     10: 
                     11: #ifndef COMPILE_TOOLS
                     12: #define COMPILE_TOOLS
                     13: 
                     14: #include "code.h"
                     15: #include "pa_types.h"
1.10      paf        16: #include "pa_vstring.h"
1.14      paf        17: #include "pa_request.h"
1.1       paf        18: 
                     19: enum lexical_state {
                     20:        LS_USER,
1.34      paf        21:        LS_COMMENT,
1.7       paf        22:        LS_DEF_NAME,
                     23:        LS_DEF_PARAMS,
                     24:        LS_DEF_LOCALS,
                     25:        LS_DEF_COMMENT,
1.18      paf        26:        LS_DEF_SPECIAL_BODY,
                     27:        LS_EXPRESSION_STRING,
1.22      paf        28:        LS_EXPRESSION_VAR_NAME,
1.1       paf        29:        LS_VAR_NAME_SIMPLE,
                     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.4       paf        50:        int line, col;
1.1       paf        51: #endif
1.38    ! paf        52:        //@}
        !            53:        //@{
        !            54:        /// @name state; initially
        !            55:        int pending_state; ///< i=0
        !            56:        String *string; ///< =new(pool) String(pool)
1.1       paf        57:        
                     58: #define MAX_LEXICAL_STATES 100
1.38    ! paf        59:        enum lexical_state ls; ///< =LS_USER;
        !            60:        int sp; ///< =0
1.1       paf        61:        enum lexical_state stack[MAX_LEXICAL_STATES];
1.38    ! paf        62:        int brackets_nestages[MAX_LEXICAL_STATES]; ///< brackets nestage on each state
        !            63:        //@}
1.1       paf        64:        
1.36      paf        65:        /// output: filled input 'methods' and 'error' if any
1.5       paf        66:        char error[MAX_STRING];
1.1       paf        67: };
                     68: 
1.36      paf        69: /// New array // return empty array
1.28      paf        70: inline Array/*<Operation>*/ *N(Pool& pool) {
                     71:        return new(pool) Array/*<Operation>*/(pool);
1.3       paf        72: }
                     73: 
1.36      paf        74: /// Assembler instruction // append ordinary instruction to ops
1.28      paf        75: inline void O(Array/*<Operation>*/ *result, enum OPCODE code) {
1.3       paf        76:        Operation op; op.code=code;
                     77:        *result+=op.cast;
                     78: }
                     79: 
1.36      paf        80: /// Argument Eval_expression // append eval_expression to ops
1.28      paf        81: inline void AE(Array/*<Operation>*/ *result, char *eval_expression) {
1.3       paf        82:        *result+=eval_expression;
                     83: }
                     84: 
1.36      paf        85: /// aPpend 'code_array' to 'result'
1.28      paf        86: inline void P(Array/*<Operation>*/ *result, Array *code_array) {
1.3       paf        87:        result->append_array(*code_array);
1.11      paf        88: }
1.36      paf        89: /// aPpend part of 'code_array', starting from offset, to 'result'
1.28      paf        90: inline void P(Array/*<Operation>*/ *result, Array *code_array, int offset) {
1.11      paf        91:        result->append_array(*code_array, offset);
1.3       paf        92: }
1.36      paf        93: /// aPpend 'vstring' to 'result'
1.28      paf        94: void PV(Array/*<Operation>*/ *result, VString *vstring);
1.36      paf        95: /// aPpend 'simple Code_Array' to result
1.28      paf        96: void PCA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array);
1.36      paf        97: /// aPpend 'expression Code_Array' to result
1.31      paf        98: void PEA(Array/*<Operation>*/ *result, Array/*<Operation>*/ *code_array);
1.1       paf        99: 
1.36      paf       100: /**
                    101:        Value Literal // returns array with 
                    102:        - first: OP_VALUE instruction
                    103:        - second op: string itself
                    104: */
1.21      paf       105: Array *VL(Value *value);
1.36      paf       106: /// Literal Array to(2) Value @return Value from literal Array OP+Value
                    107: Value *LA2V(Array *literal_string_array, int offset=0);
                    108: /// Literal Array to(2) String  @return String value from literal Array OP+String array
                    109: inline const String *LA2S(Array *literal_string_array, int offset=0) {
1.37      paf       110:        if(Value *value=LA2V(literal_string_array, offset))
                    111:                return value->get_string();
                    112:        return 0;
1.36      paf       113: }
1.19      paf       114: void change_string_literal_to_double_literal(Array *literal_string_array);
1.25      paf       115: void change_string_literal_to_write_string_literal(Array *literal_string_array);
1.1       paf       116: 
1.35      paf       117: void push_LS(parse_control& pc, lexical_state new_state);
                    118: void pop_LS(parse_control& pc);
1.1       paf       119: 
                    120: #endif

E-mail: