--- parser3/src/main/compile.y 2010/09/21 06:01:25 1.259 +++ parser3/src/main/compile.y 2012/05/30 02:25:47 1.263 @@ -2,12 +2,14 @@ /** @file Parser: compiler(lexical parser and grammar). - Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: compile.y,v 1.259 2010/09/21 06:01:25 misha Exp $ + */ +volatile const char * IDENT_COMPILE_Y = "$Id: compile.y,v 1.263 2012/05/30 02:25:47 misha Exp $"; + /** @todo parser4: - cache compiled code from request to request. to do that... @@ -35,7 +37,6 @@ #include "pa_vobject.h" #include "pa_vdouble.h" #include "pa_globals.h" -#include "pa_vvoid.h" #include "pa_vmethod_frame.h" // defines @@ -54,7 +55,7 @@ static int yylex(YYSTYPE* lvalp, void* p static const VBool vfalse(false); static const VBool vtrue(true); -static const VVoid vvoid; +static const VString vempty; // local convinient inplace typecast & var #undef PC @@ -145,7 +146,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, "@"); @@ -155,8 +156,9 @@ control_method: '@' STRING '\n' } if(command==CLASS_NAME) { if(strings_code->count()==1*OPERATIONS_PER_OPVALUE) { + PC.class_add(); // 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; @@ -166,8 +168,9 @@ control_method: '@' STRING '\n' YYERROR; } } else if(command==USE_CONTROL_METHOD_NAME) { + PC.class_add(); for(size_t i=0; icount(); i+=OPERATIONS_PER_OPVALUE) - PC.request.use_file(PC.request.main_class, *LA2S(*strings_code, i), PC.request.get_used_filename(PC.file_no)); + 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,7 +186,7 @@ control_method: '@' STRING '\n' YYERROR; } if(strings_code->count()==1*OPERATIONS_PER_OPVALUE) { - const String& base_name=*LA2S(*strings_code); + 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()) { @@ -208,7 +211,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){ @@ -505,7 +508,7 @@ construct_curly: '{' maybe_codes '}' { }; any_constructor_code_value: - void_value /* optimized $var[] case */ + empty_value /* optimized $var[] case */ | STRING /* optimized $var[STRING] case */ | constructor_code_value /* $var[something complex] */ ; @@ -553,8 +556,9 @@ call_value: '^' { YYSTYPE params_code=$5; if(params_code->count()==3) { // probably [] case. [OP::OP_VALUE+origin+Void] if(Value* value=LA2V(*params_code)) // it is OP_VALUE+origin+value? - if(value->is_void()) // value is VVoid? - params_code=0; // ^zzz[] case. don't append lone empty param. + if(const String * string=value->get_string()) + if(string->is_empty()) // value is empty string? + params_code=0; // ^zzz[] case. don't append lone empty param. } /* stack: context, method_junction */ @@ -629,7 +633,7 @@ store_curly_param_part: maybe_codes { OA(*$$, OP::OP_CURLY_CODE__STORE_PARAM, $1); }; code_param_value: - void_value /* optimized [;...] case */ + empty_value /* optimized [;...] case */ | STRING /* optimized [STRING] case */ | constructor_code_value /* [something complex] */ ; @@ -805,7 +809,7 @@ write_string: STRING { 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); } +empty_value: /* empty */ { $$=VL(/*we know that we will not change it*/const_cast(&vempty), 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); }