Fixed bugreport:6032 r15982's variable assignment should be fully functional now. Fixed the bug which prevented stuff such as "for (.@i = 0; .@i < 20; .@i++)" from working.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@16555 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
shennetsind 2012-08-02 02:04:05 +00:00
parent cee98d69ba
commit 41ea3a29c3

View File

@ -1052,8 +1052,7 @@ static void parse_nextline(bool first, const char* p)
/// Parse a variable assignment using the direct equals operator /// Parse a variable assignment using the direct equals operator
/// @param p script position where the function should run from /// @param p script position where the function should run from
/// @return NULL if not a variable assignment, the new position otherwise /// @return NULL if not a variable assignment, the new position otherwise
const char* parse_variable(const char* p) const char* parse_variable(const char* p) {
{
int i, j, word; int i, j, word;
c_op type = C_NOP; c_op type = C_NOP;
const char *p2 = NULL; const char *p2 = NULL;
@ -1063,21 +1062,17 @@ const char* parse_variable(const char* p)
p = skip_word(p); p = skip_word(p);
p = skip_space(p); p = skip_space(p);
if( p == NULL ) if( p == NULL ) {// end of the line or invalid buffer
{// end of the line or invalid buffer
return NULL; return NULL;
} }
if( *p == '[' ) if( *p == '[' ) {// array variable so process the array as appropriate
{// array variable so process the array as appropriate for( p2 = p, i = 0, j = 1; p; ++ i ) {
for( p2 = p, i = 0, j = 1; p; ++ i )
{
if( *p ++ == ']' && --(j) == 0 ) break; if( *p ++ == ']' && --(j) == 0 ) break;
if( *p == '[' ) ++ j; if( *p == '[' ) ++ j;
} }
if( !(p = skip_space(p)) ) if( !(p = skip_space(p)) ) {// end of line or invalid characters remaining
{// end of line or invalid characters remaining
disp_error_message("Missing right expression or closing bracket for variable.", p); disp_error_message("Missing right expression or closing bracket for variable.", p);
} }
} }
@ -1102,29 +1097,24 @@ const char* parse_variable(const char* p)
return NULL; return NULL;
} }
switch( type ) switch( type ) {
{ case C_EQ: {// incremental modifier
case C_EQ:
{// incremental modifier
p = skip_space( &p[1] ); p = skip_space( &p[1] );
} }
break; break;
case C_L_SHIFT: case C_L_SHIFT:
case C_R_SHIFT: case C_R_SHIFT: {// left or right shift modifier
{// left or right shift modifier
p = skip_space( &p[3] ); p = skip_space( &p[3] );
} }
break; break;
default: default: {// normal incremental command
{// normal incremental command
p = skip_space( &p[2] ); p = skip_space( &p[2] );
} }
} }
if( p == NULL ) if( p == NULL ) {// end of line or invalid buffer
{// end of line or invalid buffer
return NULL; return NULL;
} }
@ -1148,8 +1138,7 @@ const char* parse_variable(const char* p)
disp_error_message("Cannot modify a variable which has the same name as a function or label.", p); disp_error_message("Cannot modify a variable which has the same name as a function or label.", p);
} }
if( p2 ) if( p2 ) {// process the variable index
{// process the variable index
const char* p3 = NULL; const char* p3 = NULL;
// push the getelementofarray method into the stack // push the getelementofarray method into the stack
@ -1161,29 +1150,22 @@ const char* parse_variable(const char* p)
p3 = parse_subexpr(p2 + 1, 1); p3 = parse_subexpr(p2 + 1, 1);
p3 = skip_space(p3); p3 = skip_space(p3);
if( *p3 != ']' ) if( *p3 != ']' ) {// closing parenthesis is required for this script
{// closing parenthesis is required for this script
disp_error_message("Missing closing ']' parenthesis for the variable assignment.", p3); disp_error_message("Missing closing ']' parenthesis for the variable assignment.", p3);
} }
// push the closing function stack operator onto the stack // push the closing function stack operator onto the stack
add_scriptc(C_FUNC); add_scriptc(C_FUNC);
p3 ++; p3 ++;
} } else {// simply push the variable or value onto the stack
else
{// simply push the variable or value onto the stack
add_scriptl(word); add_scriptl(word);
} }
add_scriptc(C_REF); if( type == C_ADD_PP || type == C_SUB_PP ) {// incremental operator for the method
add_scriptc(C_REF);
if( type == C_ADD_PP || type == C_SUB_PP )
{// incremental operator for the method
add_scripti(1); add_scripti(1);
add_scriptc(type == C_ADD_PP ? C_ADD : C_SUB); add_scriptc(type == C_ADD_PP ? C_ADD : C_SUB);
} } else {// process the value as an expression
else
{// process the value as an expression
p = parse_subexpr(p, -1); p = parse_subexpr(p, -1);
if( type != C_EQ ) if( type != C_EQ )
@ -3220,10 +3202,10 @@ void op_2(struct script_state *st, int op)
left = script_getdatatop(st, -2); left = script_getdatatop(st, -2);
right = script_getdatatop(st, -1); right = script_getdatatop(st, -1);
if (st->op2ref) if (st->op2ref) {
{ if (data_isreference(left)) {
if (data_isreference(left))
leftref = *left; leftref = *left;
}
st->op2ref = 0; st->op2ref = 0;
} }
@ -3392,7 +3374,7 @@ static void script_check_buildin_argtype(struct script_state* st, int func)
case 'l': case 'l':
if( !data_islabel(data) && !data_isfunclabel(data) ) if( !data_islabel(data) && !data_isfunclabel(data) )
{// label {// label
ShowWarning("Unexpected type for argument %d. Expected label.\n", idx-1); ShowWarning("Unexpected type for argument %d. Expected label, got %s\n", idx-1,script_op2name(data->type));
script_reportdata(data); script_reportdata(data);
invalid++; invalid++;
} }