[Groonga-commit] groonga/groonga at 29aa5cc [master] grn_ts: implicitly insert a typecast operator for arithmetic operation

Back to archive index

susumu.yata null+****@clear*****
Tue Nov 17 18:24:13 JST 2015


susumu.yata	2015-11-17 18:24:13 +0900 (Tue, 17 Nov 2015)

  New Revision: 29aa5ccad05f651d7ddfe4a9d04aaeceb7d3b0a3
  https://github.com/groonga/groonga/commit/29aa5ccad05f651d7ddfe4a9d04aaeceb7d3b0a3

  Message:
    grn_ts: implicitly insert a typecast operator for arithmetic operation
    
    GitHub: #390

  Modified files:
    lib/ts/ts_expr_node.c

  Modified: lib/ts/ts_expr_node.c (+61 -4)
===================================================================
--- lib/ts/ts_expr_node.c    2015-11-17 17:27:33 +0900 (8a593eb)
+++ lib/ts/ts_expr_node.c    2015-11-17 18:24:13 +0900 (15ad1ab)
@@ -2884,6 +2884,25 @@ grn_ts_expr_op_node_deref_args(grn_ctx *ctx, grn_ts_expr_op_node *node)
 static grn_rc
 grn_ts_op_plus_check_args(grn_ctx *ctx, grn_ts_expr_op_node *node)
 {
+  grn_rc rc;
+  if ((node->args[0]->data_kind == GRN_TS_INT) &&
+      (node->args[1]->data_kind == GRN_TS_FLOAT)) {
+    rc = grn_ts_expr_op_node_open(ctx, GRN_TS_OP_FLOAT, &node->args[0],
+                                  1, &node->args[0]);
+    if (rc != GRN_SUCCESS) {
+      node->args[0] = NULL;
+      return rc;
+    }
+  } else if ((node->args[0]->data_kind == GRN_TS_FLOAT) &&
+             (node->args[1]->data_kind == GRN_TS_INT)) {
+    rc = grn_ts_expr_op_node_open(ctx, GRN_TS_OP_FLOAT, &node->args[1],
+                                  1, &node->args[1]);
+    if (rc != GRN_SUCCESS) {
+      node->args[1] = NULL;
+      return rc;
+    }
+  }
+
   switch (node->args[0]->data_kind) {
     case GRN_TS_INT: {
       switch (node->args[1]->data_kind) {
@@ -2957,6 +2976,25 @@ grn_ts_op_plus_check_args(grn_ctx *ctx, grn_ts_expr_op_node *node)
 static grn_rc
 grn_ts_op_minus_check_args(grn_ctx *ctx, grn_ts_expr_op_node *node)
 {
+  grn_rc rc;
+  if ((node->args[0]->data_kind == GRN_TS_INT) &&
+      (node->args[1]->data_kind == GRN_TS_FLOAT)) {
+    rc = grn_ts_expr_op_node_open(ctx, GRN_TS_OP_FLOAT, &node->args[0],
+                                  1, &node->args[0]);
+    if (rc != GRN_SUCCESS) {
+      node->args[0] = NULL;
+      return rc;
+    }
+  } else if ((node->args[0]->data_kind == GRN_TS_FLOAT) &&
+             (node->args[1]->data_kind == GRN_TS_INT)) {
+    rc = grn_ts_expr_op_node_open(ctx, GRN_TS_OP_FLOAT, &node->args[1],
+                                  1, &node->args[1]);
+    if (rc != GRN_SUCCESS) {
+      node->args[1] = NULL;
+      return rc;
+    }
+  }
+
   switch (node->args[0]->data_kind) {
     case GRN_TS_INT: {
       if (node->args[1]->data_kind != GRN_TS_INT) {
@@ -3223,10 +3261,29 @@ grn_ts_expr_op_node_check_args(grn_ctx *ctx, grn_ts_expr_op_node *node)
       case GRN_TS_OP_DIVISION:
       case GRN_TS_OP_MODULUS: {
         if (node->args[0]->data_kind != node->args[1]->data_kind) {
-          GRN_TS_ERR_RETURN(GRN_INVALID_ARGUMENT,
-                            "data kind conflict: %d != %d",
-                            node->args[0]->data_kind,
-                            node->args[1]->data_kind);
+          grn_rc rc;
+          if ((node->args[0]->data_kind == GRN_TS_INT) &&
+              (node->args[1]->data_kind == GRN_TS_FLOAT)) {
+            rc = grn_ts_expr_op_node_open(ctx, GRN_TS_OP_FLOAT, &node->args[0],
+                                          1, &node->args[0]);
+            if (rc != GRN_SUCCESS) {
+              node->args[0] = NULL;
+              return rc;
+            }
+          } else if ((node->args[0]->data_kind == GRN_TS_FLOAT) &&
+                     (node->args[1]->data_kind == GRN_TS_INT)) {
+            rc = grn_ts_expr_op_node_open(ctx, GRN_TS_OP_FLOAT, &node->args[1],
+                                          1, &node->args[1]);
+            if (rc != GRN_SUCCESS) {
+              node->args[1] = NULL;
+              return rc;
+            }
+          } else {
+            GRN_TS_ERR_RETURN(GRN_INVALID_ARGUMENT,
+                              "data kind conflict: %d != %d",
+                              node->args[0]->data_kind,
+                              node->args[1]->data_kind);
+          }
         }
         switch (node->args[0]->data_kind) {
           case GRN_TS_INT:
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index