--- parser3/src/main/compile.y 2009/08/11 10:19:02 1.251 +++ parser3/src/main/compile.y 2010/10/08 13:16:36 1.260 @@ -5,7 +5,7 @@ Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.251 2009/08/11 10:19:02 misha Exp $ + $Id: compile.y,v 1.260 2010/10/08 13:16:36 misha Exp $ */ /** @@ -145,7 +145,7 @@ method: control_method | code_method; control_method: '@' STRING '\n' maybe_control_strings { - const String& command=*LA2S(*$2); + const String& command=LA2S(*$2)->trim(String::TRIM_END); YYSTYPE strings_code=$4; if(strings_code->count()<1*OPERATIONS_PER_OPVALUE) { strcpy(PC.error, "@"); @@ -156,7 +156,7 @@ control_method: '@' STRING '\n' if(command==CLASS_NAME) { if(strings_code->count()==1*OPERATIONS_PER_OPVALUE) { // new class' name - const String& name=*LA2S(*strings_code); + const String& name=LA2S(*strings_code)->trim(String::TRIM_END); // creating the class VStateless_class* cclass=new VClass; PC.cclass_new=cclass; @@ -167,7 +167,7 @@ control_method: '@' STRING '\n' } } else if(command==USE_CONTROL_METHOD_NAME) { for(size_t i=0; icount(); i+=OPERATIONS_PER_OPVALUE) - PC.request.use_file(PC.request.main_class, *LA2S(*strings_code, i)); + PC.request.use_file(PC.request.main_class, LA2S(*strings_code, i)->trim(String::TRIM_END), PC.request.get_used_filename(PC.file_no)); } else if(command==BASE_NAME) { if(PC.append){ strcpy(PC.error, "can't set base while appending methods to class '"); @@ -183,8 +183,8 @@ control_method: '@' STRING '\n' YYERROR; } if(strings_code->count()==1*OPERATIONS_PER_OPVALUE) { - const String& base_name=*LA2S(*strings_code); - if(Value* base_class_value=PC.request.classes().get(base_name)) { + const String& base_name=LA2S(*strings_code)->trim(String::TRIM_END); + if(Value* base_class_value=PC.request.get_class(base_name)) { // @CLASS == @BASE sanity check if(VStateless_class *base_class=base_class_value->get_class()) { if(PC.cclass==base_class) { @@ -208,7 +208,7 @@ control_method: '@' STRING '\n' } } else if(command==OPTIONS_CONTROL_METHOD_NAME) { for(size_t i=0; icount(); i+=OPERATIONS_PER_OPVALUE) { - const String& option=*LA2S(*strings_code, i); + const String& option=LA2S(*strings_code, i)->trim(String::TRIM_END); if(option==OPTION_ALL_VARS_LOCAL_NAME){ PC.set_all_vars_local(); } else if(option==OPTION_PARTIAL_CLASS){ @@ -221,18 +221,24 @@ control_method: '@' STRING '\n' YYERROR; } } else { - // mark new class as partial. we can add methods to it later. + // marks the new class as partial. we will be able to add methods here later. PC.cclass_new->set_partial(); } } else { strcpy(PC.error, "'"OPTION_PARTIAL_CLASS"' option should be used straight after @"CLASS_NAME); YYERROR; } + } else if(option==method_call_type_static){ + PC.set_methods_call_type(Method::CT_STATIC); + } else if(option==method_call_type_dynamic){ + PC.set_methods_call_type(Method::CT_DYNAMIC); } else { strcpy(PC.error, "'"); strncat(PC.error, option.cstr(), MAX_STRING/2); strcat(PC.error, "' invalid option. valid options are " - "'"OPTION_PARTIAL_CLASS"' and '"OPTION_ALL_VARS_LOCAL_NAME"'"); + "'"OPTION_PARTIAL_CLASS"', '"OPTION_ALL_VARS_LOCAL_NAME"'" + ", '"METHOD_CALL_TYPE_STATIC"' and '"METHOD_CALL_TYPE_DYNAMIC"'" + ); YYERROR; } } @@ -245,7 +251,7 @@ control_method: '@' STRING '\n' } }; maybe_control_strings: empty | control_strings; -control_strings: control_string | control_strings control_string { $$=$1; P(*$$, *$2) }; +control_strings: control_string | control_strings control_string { $$=$1; P(*$$, *$2); }; control_string: maybe_string '\n'; maybe_string: empty | STRING; @@ -281,14 +287,12 @@ code_method: '@' STRING bracketed_maybe_ Method* method=new Method( //name, - Method::CT_ANY, + GetMethodCallType(PC, *$2), 0, 0/*min,max numbered_params_count*/, params_names, locals_names, 0/*to be filled later in next {} */, 0, all_vars_local); *reinterpret_cast(&$$)=method; - - // todo: check [][;result;] } maybe_codes { Method* method=reinterpret_cast($7); // fill in the code @@ -300,9 +304,9 @@ code_method: '@' STRING bracketed_maybe_ }; maybe_bracketed_strings: empty | bracketed_maybe_strings; -bracketed_maybe_strings: '[' maybe_strings ']' {$$=$2}; +bracketed_maybe_strings: '[' maybe_strings ']' {$$=$2;}; maybe_strings: empty | strings; -strings: STRING | strings ';' STRING { $$=$1; P(*$$, *$3) }; +strings: STRING | strings ';' STRING { $$=$1; P(*$$, *$3); }; maybe_comment: empty | STRING; @@ -310,7 +314,7 @@ maybe_comment: empty | STRING; maybe_codes: empty | codes; -codes: code | codes code { $$=$1; P(*$$, *$2) }; +codes: code | codes code { $$=$1; P(*$$, *$2); }; code: write_string | action; action: get | put | call; @@ -357,9 +361,9 @@ get: get_value { P(*$$, *code); }; -get_value: '$' get_name_value { $$=$2 }; +get_value: '$' get_name_value { $$=$2; }; get_name_value: name_without_curly_rdive EON | name_in_curly_rdive; -name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2 }; +name_in_curly_rdive: '{' name_without_curly_rdive '}' { $$=$2; }; name_without_curly_rdive: name_without_curly_rdive_read | name_without_curly_rdive_class; @@ -416,8 +420,8 @@ name_without_curly_rdive_read: name_with #endif /* diving code; stack: current context */ }; -name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P(*$$, *$2) }; -name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P(*$$, *$2) }; +name_without_curly_rdive_class: class_prefix name_without_curly_rdive_code { $$=$1; P(*$$, *$2); }; +name_without_curly_rdive_code: name_advance2 | name_path name_advance2 { $$=$1; P(*$$, *$2); }; /* put */ @@ -468,7 +472,7 @@ name_expr_wdive_write: '.' name_expr_div O(*$$, OP::OP_WITH_WRITE); /* stack: starting context */ P(*$$, *$2); /* diving code; stack: context,name */ }; -name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P(*$$, *$2) }; +name_expr_wdive_class: class_prefix name_expr_dive_code { $$=$1; P(*$$, *$2); }; construct: construct_square @@ -512,7 +516,7 @@ constructor_code_value: constructor_code /* context=pop; stack: context.value() */ }; constructor_code: codes__excluding_sole_str_literal; -codes__excluding_sole_str_literal: action | code codes { $$=$1; P(*$$, *$2) }; +codes__excluding_sole_str_literal: action | code codes { $$=$1; P(*$$, *$2); }; /* call */ @@ -577,7 +581,7 @@ call_value: '^' { call_name: name_without_curly_rdive; -store_params: store_param | store_params store_param { $$=$1; P(*$$, *$2) }; +store_params: store_param | store_params store_param { $$=$1; P(*$$, *$2); }; store_param: store_square_param | store_round_param @@ -588,20 +592,20 @@ store_square_param: '[' { *reinterpret_cast(&$$)=PC.explicit_result; PC.explicit_result=false; } store_code_param_parts { PC.explicit_result=*reinterpret_cast(&$2); -} ']' {$$=$3}; -store_round_param: '(' store_expr_param_parts ')' {$$=$2}; -store_curly_param: '{' store_curly_param_parts '}' {$$=$2}; +} ']' {$$=$3;}; +store_round_param: '(' store_expr_param_parts ')' {$$=$2;}; +store_curly_param: '{' store_curly_param_parts '}' {$$=$2;}; store_code_param_parts: store_code_param_part -| store_code_param_parts ';' store_code_param_part { $$=$1; P(*$$, *$3) } +| store_code_param_parts ';' store_code_param_part { $$=$1; P(*$$, *$3); } ; store_expr_param_parts: store_expr_param_part -| store_expr_param_parts ';' store_expr_param_part { $$=$1; P(*$$, *$3) } +| store_expr_param_parts ';' store_expr_param_part { $$=$1; P(*$$, *$3); } ; store_curly_param_parts: store_curly_param_part -| store_curly_param_parts ';' store_curly_param_part { $$=$1; P(*$$, *$3) } +| store_curly_param_parts ';' store_curly_param_part { $$=$1; P(*$$, *$3); } ; store_code_param_part: code_param_value { $$=$1; @@ -632,9 +636,9 @@ code_param_value: /* name */ -name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P(*$$, *$2) }; +name_expr_dive_code: name_expr_value | name_path name_expr_value { $$=$1; P(*$$, *$2); }; -name_path: name_step | name_path name_step { $$=$1; P(*$$, *$2) }; +name_path: name_step | name_path name_step { $$=$1; P(*$$, *$2); }; name_step: name_advance1 '.'; name_advance1: name_expr_value { // we know that name_advance1 not called from ^xxx context @@ -686,7 +690,7 @@ subvar_ref_name_rdive: STRING { O(*$$, OP::OP_WITH_READ); P(*$$, *$1); }; -subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P(*$$, *$2) }; +subvar_get_writes: subvar__get_write | subvar_get_writes subvar__get_write { $$=$1; P(*$$, *$2); }; subvar__get_write: '$' subvar_ref_name_rdive { $$=$2; O(*$$, OP::OP_GET_ELEMENT__WRITE); @@ -706,12 +710,8 @@ class_static_prefix: STRING ':' { YYERROR; } } -#ifdef OPTIMIZE_BYTECODE_GET_CLASS // optimized OP_VALUE+origin+string+OP_GET_CLASS => OP_VALUE__GET_CLASS+origin+string - maybe_change_first_opcode(*$$, OP::OP_VALUE, OP::OP_VALUE__GET_CLASS) -#else - O(*$$, OP::OP_GET_CLASS); -#endif + maybe_change_first_opcode(*$$, OP::OP_VALUE, OP::OP_VALUE__GET_CLASS); }; class_constructor_prefix: class_static_prefix ':' { $$=$1; @@ -732,46 +732,46 @@ expr: | false_value | get_value | call_value -| '"' string_inside_quotes_value '"' { $$ = $2 } -| '\'' string_inside_quotes_value '\'' { $$ = $2 } +| '"' string_inside_quotes_value '"' { $$ = $2; } +| '\'' string_inside_quotes_value '\'' { $$ = $2; } | '(' expr ')' { $$ = $2; } /* stack: operand // stack: @operand */ -| '-' expr %prec NUNARY { $$=$2; O(*$$, OP::OP_NEG) } -| '+' expr %prec NUNARY { $$=$2 } -| '~' expr { $$=$2; O(*$$, OP::OP_INV) } -| '!' expr { $$=$2; O(*$$, OP::OP_NOT) } -| "def" expr { $$=$2; O(*$$, OP::OP_DEF) } -| "in" expr { $$=$2; O(*$$, OP::OP_IN) } -| "-f" expr { $$=$2; O(*$$, OP::OP_FEXISTS) } -| "-d" expr { $$=$2; O(*$$, OP::OP_DEXISTS) } +| '-' expr %prec NUNARY { $$=$2; O(*$$, OP::OP_NEG); } +| '+' expr %prec NUNARY { $$=$2; } +| '~' expr { $$=$2; O(*$$, OP::OP_INV); } +| '!' expr { $$=$2; O(*$$, OP::OP_NOT); } +| "def" expr { $$=$2; O(*$$, OP::OP_DEF); } +| "in" expr { $$=$2; O(*$$, OP::OP_IN); } +| "-f" expr { $$=$2; O(*$$, OP::OP_FEXISTS); } +| "-d" expr { $$=$2; O(*$$, OP::OP_DEXISTS); } /* stack: a,b // stack: a@b */ -| expr '-' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_SUB) } -| expr '+' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_ADD) } -| expr '*' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_MUL) } -| expr '/' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_DIV) } -| expr '%' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_MOD) } -| expr '\\' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_INTDIV) } -| expr "<<" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_SL) } -| expr ">>" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_SR) } -| expr '&' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_AND) } -| expr '|' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_OR) } -| expr "!|" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_XOR) } -| expr "&&" expr { $$=$1; OA(*$$, OP::OP_NESTED_CODE, $3); O(*$$, OP::OP_LOG_AND) } -| expr "||" expr { $$=$1; OA(*$$, OP::OP_NESTED_CODE, $3); O(*$$, OP::OP_LOG_OR) } -| expr "!||" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_LOG_XOR) } -| expr '<' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_LT) } -| expr '>' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_GT) } -| expr "<=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_LE) } -| expr ">=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_GE) } -| expr "==" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_EQ) } -| expr "!=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_NE) } -| expr "lt" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_LT) } -| expr "gt" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_GT) } -| expr "le" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_LE) } -| expr "ge" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_GE) } -| expr "eq" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_EQ) } -| expr "ne" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_NE) } -| expr "is" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_IS) } +| expr '-' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_SUB); } +| expr '+' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_ADD); } +| expr '*' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_MUL); } +| expr '/' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_DIV); } +| expr '%' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_MOD); } +| expr '\\' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_INTDIV); } +| expr "<<" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_SL); } +| expr ">>" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_SR); } +| expr '&' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_AND); } +| expr '|' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_OR); } +| expr "!|" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_BIN_XOR); } +| expr "&&" expr { $$=$1; OA(*$$, OP::OP_NESTED_CODE, $3); O(*$$, OP::OP_LOG_AND); } +| expr "||" expr { $$=$1; OA(*$$, OP::OP_NESTED_CODE, $3); O(*$$, OP::OP_LOG_OR); } +| expr "!||" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_LOG_XOR); } +| expr '<' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_LT); } +| expr '>' expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_GT); } +| expr "<=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_LE); } +| expr ">=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_GE); } +| expr "==" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_EQ); } +| expr "!=" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_NUM_NE); } +| expr "lt" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_LT); } +| expr "gt" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_GT); } +| expr "le" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_LE); } +| expr "ge" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_GE); } +| expr "eq" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_EQ); } +| expr "ne" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_STR_NE); } +| expr "is" expr { $$=$1; P(*$$, *$3); O(*$$, OP::OP_IS); } ; double_or_STRING: STRING { @@ -802,14 +802,14 @@ string_inside_quotes_value: maybe_codes write_string: STRING { // optimized OP_STRING+OP_WRITE_VALUE => OP_STRING__WRITE - change_string_literal_to_write_string_literal(*($$=$1)) + change_string_literal_to_write_string_literal(*($$=$1)); }; -void_value: /* empty */ { $$=VL(/*we know that we will not change it*/const_cast(&vvoid), 0, 0, 0) } -true_value: "true" { $$ = VL(/*we know that we will not change it*/const_cast(&vtrue), 0, 0, 0) } -false_value: "false" { $$ = VL(/*we know that we will not change it*/const_cast(&vfalse), 0, 0, 0) } +void_value: /* empty */ { $$=VL(/*we know that we will not change it*/const_cast(&vvoid), 0, 0, 0); } +true_value: "true" { $$ = VL(/*we know that we will not change it*/const_cast(&vtrue), 0, 0, 0); } +false_value: "false" { $$ = VL(/*we know that we will not change it*/const_cast(&vfalse), 0, 0, 0); } -empty: /* empty */ { $$=N() }; +empty: /* empty */ { $$=N(); }; %% #endif @@ -1350,7 +1350,7 @@ default: case ']': case '}': case ')': case '"': case '\'': case '<': case '>': // these stand for HTML brackets AND expression binary ops - case '+': case '*': case '/': case '%': + case '+': case '*': case '/': case '\\': case '%': case '&': case '|': case '=': case '!': // common delimiters @@ -1580,12 +1580,9 @@ default: break2: if(end!=begin) { // there is last piece? - if((c=='@' || c==0) && end[-1]=='\n') { // we are before LS_DEF_NAME or EOF? - // strip last \n - end--; - if(end!=begin && end[-1]=='\n') // allow one empty line before LS_DEF_NAME + if(c=='@' || c==0) // we are before LS_DEF_NAME or EOF? + while(end!=begin && end[-1]=='\n') // trim all empty lines before LS_DEF_NAME and EOF end--; - } if(end!=begin && pc.ls!=LS_USER_COMMENT) { // last piece still alive and not comment? if(!pc.string_start) pc.string_start=begin_pos;