From 278f7fdd7e62b71bb1693c97b69c0ad515da9e2c Mon Sep 17 00:00:00 2001
From: Sergei Golubchik <serg@mariadb.org>
Date: Tue, 19 Aug 2014 21:06:20 +0200
Subject: [PATCH] cleanup: get rid of (Item_splocal*)item downcast

---
 sql/item.h       | 7 ++++---
 sql/sp_head.cc   | 4 ++--
 sql/sql_parse.cc | 2 +-
 sql/sql_yacc.yy  | 4 ++--
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/sql/item.h b/sql/item.h
index c0c562c7c7..a9021f355e 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -570,6 +570,7 @@ class COND_EQUAL;
 class st_select_lex_unit;
 
 class Item_func_not;
+class Item_splocal;
 
 class Item {
   Item(const Item &);			/* Prevent use of these */
@@ -1431,7 +1432,7 @@ public:
     delete this;
   }
 
-  virtual bool is_splocal() { return 0; } /* Needed for error checking */
+  virtual Item_splocal *get_item_splocal() { return 0; }
 
   /*
     Return Settable_routine_parameter interface of the Item.  Return 0
@@ -1729,8 +1730,6 @@ public:
                enum_field_types sp_var_type,
                uint pos_in_q= 0, uint len_in_q= 0);
 
-  bool is_splocal() { return 1; } /* Needed for error checking */
-
   Item *this_item();
   const Item *this_item() const;
   Item **this_item_addr(THD *thd, Item **);
@@ -1750,6 +1749,8 @@ private:
   bool set_value(THD *thd, sp_rcontext *ctx, Item **it);
 
 public:
+  Item_splocal *get_item_splocal() { return this; }
+
   Settable_routine_parameter *get_settable_routine_parameter()
   {
     return this;
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index a000c486e5..7150220084 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -985,9 +985,9 @@ subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str)
   /* Find all instances of Item_splocal used in this statement */
   for (Item *item= instr->free_list; item; item= item->next)
   {
-    if (item->is_splocal())
+    Item_splocal *item_spl= item->get_item_splocal();
+    if (item_spl)
     {
-      Item_splocal *item_spl= (Item_splocal*)item;
       if (item_spl->pos_in_query)
         sp_vars_uses.append(item_spl);
     }
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 5c39e63cf4..bc5fa3a9e2 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3189,7 +3189,7 @@ mysql_execute_command(THD *thd)
         /* Count SP local vars in the top-level SELECT list */
         while ((item= it++))
         {
-          if (item->is_splocal())
+          if (item->get_item_splocal())
             splocal_refs++;
         }
         /*
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 4cf45aa5fb..333b3a2183 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -9230,9 +9230,9 @@ simple_expr:
           }
         | DEFAULT '(' simple_ident ')'
           {
-            if ($3->is_splocal())
+            Item_splocal *il= $3->get_item_splocal();
+            if (il)
             {
-              Item_splocal *il= static_cast<Item_splocal *>($3);
 
               my_error(ER_WRONG_COLUMN_NAME, MYF(0), il->my_name()->str);
               MYSQL_YYABORT;
-- 
2.30.9