diff options
author | unknown <bell@sanja.is.com.ua> | 2004-03-18 18:27:03 +0200 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2004-03-18 18:27:03 +0200 |
commit | 647498e9657b7d68faf0cb24bac43a940238920c (patch) | |
tree | 3a985f7a301b3fb3561e467c887e3b33a4a9124d | |
parent | 85dddd908a70bcbcd992b2f24525ff3f96476569 (diff) | |
download | mariadb-git-647498e9657b7d68faf0cb24bac43a940238920c.tar.gz |
fixed signed numeric literal parsing
sql/item.h:
added negation methods for numeric Items
sql/sql_yacc.yy:
fixed numeric literal
-rw-r--r-- | sql/item.h | 26 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 11 |
2 files changed, 27 insertions, 10 deletions
diff --git a/sql/item.h b/sql/item.h index 7f50495d23b..6917a5ffef7 100644 --- a/sql/item.h +++ b/sql/item.h @@ -242,6 +242,13 @@ public: }; +class Item_num: public Item +{ +public: + virtual void neg()= 0; +}; + + class st_select_lex; class Item_ident :public Item { @@ -398,10 +405,10 @@ public: void print(String *str) { str->append('?'); } }; -class Item_int :public Item +class Item_int :public Item_num { public: - const longlong value; + longlong value; Item_int(int32 i,uint length=11) :value((longlong) i) { max_length=length; fixed= 1; } #ifdef HAVE_LONG_LONG @@ -425,12 +432,16 @@ public: Item *new_item() { return new Item_int(name,value,max_length); } // to prevent drop fixed flag (no need parent cleanup call) void cleanup() { fixed= 1; } - void print(String *strclass Item_uint :public Item_int + void print(String *str); + void neg() { value= -value; } +}; + + +class Item_uint :public Item_int { public: Item_uint(const char *str_arg, uint length) : - Item_int(str_arg, (longlong) strtoull(str_arg,(char**) 0,10), length) - Item_int(str_arg, (longlong) strtoull(str_arg,(char**) 0,10), length) + Item_int(str_arg, (longlong) strtoull(str_arg, (char**) 0,10), length) { unsigned_flag= 1; } Item_uint(uint32 i) :Item_int((longlong) i, 10) { unsigned_flag= 1; } @@ -443,10 +454,10 @@ public: }; -class Item_real :public Item +class Item_real :public Item_num { public: - const double value; + double value; // Item_real() :value(0) {} Item_real(const char *str_arg,uint length) :value(my_atof(str_arg)) { @@ -474,6 +485,7 @@ public: String *val_str(String*); bool basic_const_item() const { return 1; } Item *new_item() { return new Item_real(name,value,decimals,max_length); } + void neg() { value= -value; } }; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index e2c33584bdf..41c5e8f43ad 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -64,6 +64,7 @@ inline Item *or_or_concat(THD *thd, Item* A, Item* B) Table_ident *table; char *simple_string; Item *item; + Item_num *item_num; List<Item> *item_list; List<String> *string_list; String *string; @@ -628,7 +629,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); using_list expr_or_default set_expr_or_default interval_expr param_marker singlerow_subselect singlerow_subselect_init exists_subselect exists_subselect_init geometry_function - signed_literal NUM_literal + signed_literal + +%type <item_num> + NUM_literal %type <item_list> expr_list udf_expr_list when_list ident_list ident_list_arg @@ -4525,8 +4529,9 @@ signed_literal: | '+' NUM_literal { $$ = $2; } | '-' NUM_literal { - /* $2 it's Item_int -> we can get value without fix_fields call */ - $$= new Item_int(-$2->val_int(), $2->max_length+1); + $2->neg(); + $2->max_length++; + $$= $2; } ; |