Annotation of parser3/src/main/compile_tools.h, revision 1.67.2.8.2.2
1.32 paf 1: /** @file
1.33 paf 2: Parser: compiler support helper functions decls.
3:
1.67.2.6 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.8.2.2! paf 11: static const char* IDENT_COMPILE_TOOLS_H="$Date: 2003/03/18 15:14:18 $";
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:
1.67.2.8.2.2! paf 18: extern "C" {
! 19: #include "cord.h"
! 20: }
! 21:
1.1 paf 22: enum lexical_state {
1.48 parser 23: LS_USER, LS_NAME_SQUARE_PART,
1.65 paf 24: LS_USER_COMMENT,
1.7 paf 25: LS_DEF_NAME,
26: LS_DEF_PARAMS,
27: LS_DEF_LOCALS,
28: LS_DEF_COMMENT,
1.18 paf 29: LS_DEF_SPECIAL_BODY,
1.42 parser 30: LS_EXPRESSION_STRING_QUOTED,
31: LS_EXPRESSION_STRING_APOSTROFED,
1.48 parser 32: LS_EXPRESSION_VAR_NAME_WITH_COLON, LS_EXPRESSION_VAR_NAME_WITHOUT_COLON,
1.65 paf 33: LS_EXPRESSION_COMMENT,
1.48 parser 34: LS_VAR_NAME_SIMPLE_WITH_COLON, LS_VAR_NAME_SIMPLE_WITHOUT_COLON,
1.1 paf 35: LS_VAR_NAME_CURLY,
1.22 paf 36: LS_VAR_ROUND,
1.18 paf 37: LS_VAR_SQUARE,
1.1 paf 38: LS_VAR_CURLY,
39: LS_METHOD_NAME,
1.18 paf 40: LS_METHOD_SQUARE,
1.1 paf 41: LS_METHOD_CURLY,
1.22 paf 42: LS_METHOD_ROUND,
1.1 paf 43: LS_METHOD_AFTER
44: };
1.38 paf 45: /// compiler status
1.1 paf 46: struct parse_control {
1.38 paf 47: //@{
48: /// @name input
1.67.2.8.2.2! paf 49: Request& request;
1.67.2.7 paf 50: VStateless_class* cclass;
1.67.2.6 paf 51: const char* source;
52: const char* file;
1.4 paf 53: int line, col;
1.38 paf 54: //@}
55: //@{
56: /// @name state; initially
1.45 parser 57: bool trim_bof;
1.38 paf 58: int pending_state; ///< i=0
1.67.2.8.2.2! paf 59: StringBody string; ///< lexical string accumulator
1.1 paf 60:
61: #define MAX_LEXICAL_STATES 100
1.38 paf 62: enum lexical_state ls; ///< =LS_USER;
1.54 paf 63: int ls_sp; ///< =0
64: enum lexical_state ls_stack[MAX_LEXICAL_STATES];
1.38 paf 65: int brackets_nestages[MAX_LEXICAL_STATES]; ///< brackets nestage on each state
1.46 parser 66:
1.56 paf 67: bool in_call_value;
1.38 paf 68: //@}
1.1 paf 69:
1.36 paf 70: /// output: filled input 'methods' and 'error' if any
1.5 paf 71: char error[MAX_STRING];
1.67.2.8.2.2! paf 72:
! 73: parse_control(Request& arequest,
! 74: VStateless_class* aclass,
! 75: const char* asource,
! 76: const char* afile):
! 77: request(arequest), // input
! 78:
! 79: // we were told the class to compile to?
! 80: cclass(aclass), // until changed with @CLASS would consider operators loading
! 81:
! 82: source(asource),
! 83:
! 84: file(afile),
! 85: line(0), col(0),
! 86:
! 87: // initialise state
! 88: trim_bof(true),
! 89: pending_state(0),
! 90: ls(LS_USER),
! 91: ls_sp(0),
! 92: in_call_value(false) {
! 93: }
1.1 paf 94: };
95:
1.36 paf 96: /// New array // return empty array
1.67.2.8.2.2! paf 97: inline ArrayOperation* N() {
! 98: return new ArrayOperation;
1.3 paf 99: }
100:
1.36 paf 101: /// Assembler instruction // append ordinary instruction to ops
1.67.2.3 paf 102: inline void O(ArrayOperation& result, OPCODE code) {
103: result+=Operation(code);
1.3 paf 104: }
105:
1.36 paf 106: /// aPpend 'code_array' to 'result'
1.67.2.4 paf 107: inline void P(ArrayOperation& result, ArrayOperation& code_array) {
108: result.append(code_array);
1.11 paf 109: }
1.36 paf 110: /// aPpend part of 'code_array', starting from offset, to 'result'
1.67.2.4 paf 111: inline void P(ArrayOperation& result, ArrayOperation& code_array, int offset) {
112: result.append(code_array, offset);
1.3 paf 113: }
1.53 paf 114:
1.36 paf 115: /// aPpend 'vstring' to 'result'
1.67.2.8.2.2! paf 116: inline void PV(ArrayOperation& result, Value* value) {
1.67.2.3 paf 117: result+=Operation(OP_VALUE); // append OP_VALUE
118: result+=Operation(value); // append 'value'
1.67.2.2 paf 119: }
1.61 paf 120:
1.67.2.2 paf 121: /// append cOde Array
1.67.2.8.2.2! paf 122: inline void OA(ArrayOperation& result, OPCODE code, ArrayOperation* code_array) {
1.67.2.3 paf 123: result+=Operation(code); // append OP_CODE
124: result+=Operation(code_array); // append 'code_array'
1.61 paf 125: }
1.1 paf 126:
1.36 paf 127: /**
128: Value Literal // returns array with
129: - first: OP_VALUE instruction
130: - second op: string itself
131: */
1.67.2.8.2.2! paf 132: inline ArrayOperation* VL(Value* value) {
1.61 paf 133: // empty ops array
1.67.2.8.2.2! paf 134: ArrayOperation* result=N();
1.61 paf 135:
136: // append 'value' to 'result'
1.67.2.3 paf 137: PV(*result, value);
1.61 paf 138:
139: return result;
140: }
141:
1.36 paf 142: /// Literal Array to(2) Value @return Value from literal Array OP+Value
1.67.2.8.2.2! paf 143: Value* LA2V(ArrayOperation& literal_string_array, int offset=0);
1.36 paf 144: /// Literal Array to(2) String @return String value from literal Array OP+String array
1.67.2.8.2.2! paf 145: inline const String* LA2S(ArrayOperation& literal_string_array, int offset=0) {
! 146: if(Value* value=LA2V(literal_string_array, offset))
! 147: return value->get_string();
1.67.2.8.2.1 paf 148: return 0;
1.36 paf 149: }
1.61 paf 150:
1.67.2.3 paf 151: inline void change_string_literal_to_write_string_literal(ArrayOperation& literal_string_array) {
152: literal_string_array[0].code=OP_STRING__WRITE;
1.61 paf 153: }
154:
155:
1.67.2.3 paf 156: void change_string_literal_to_double_literal(ArrayOperation& literal_string_array);
157:
1.67.2.8.2.1 paf 158: void change_string_literal_value(ArrayOperation& literal_string_array, const String& new_value);
1.67.2.3 paf 159:
160: void changetail_or_append(ArrayOperation& opcodes,
161: OPCODE find, bool with_argument, OPCODE replace, OPCODE notfound);
1.64 paf 162:
1.1 paf 163:
1.35 paf 164: void push_LS(parse_control& pc, lexical_state new_state);
165: void pop_LS(parse_control& pc);
1.1 paf 166:
167: #endif
E-mail: