gnumeric r17120 - in trunk: . plugins/excel src



Author: mortenw
Date: Sat Jan 31 23:48:39 2009
New Revision: 17120
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17120&view=rev

Log:
2009-01-31  Morten Welinder  <terra gnome org>

	* src/parser.y (build_range_ctor): Use gnm_expr_new_range_ctor,
	not build_binop.

	* src/expr.c (gnm_expr_new_range_ctor): New function.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/plugins/excel/ChangeLog
   trunk/plugins/excel/ms-formula-read.c
   trunk/src/expr.c
   trunk/src/expr.h
   trunk/src/parser.y

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Sat Jan 31 23:48:39 2009
@@ -93,6 +93,7 @@
 	too.  Fix issues with bools versus floats.
 	* Fix parsing problem for constructed ranges.  [#569730]
 	* Fix plugin menu merging.  [#569724]
+	* Improve handling of 3D ranges.  [#569372]
 
 --------------------------------------------------------------------------
 Gnumeric 1.9.3

Modified: trunk/plugins/excel/ms-formula-read.c
==============================================================================
--- trunk/plugins/excel/ms-formula-read.c	(original)
+++ trunk/plugins/excel/ms-formula-read.c	Sat Jan 31 23:48:39 2009
@@ -1012,8 +1012,7 @@
 		case FORMULA_PTG_EQUAL :
 		case FORMULA_PTG_GTE : case FORMULA_PTG_GT :
 		case FORMULA_PTG_NOT_EQUAL :
-		case FORMULA_PTG_INTERSECT :
-		case FORMULA_PTG_RANGE : {
+		case FORMULA_PTG_INTERSECT : {
 			GnmExpr const *r = parse_list_pop (&stack);
 			GnmExpr const *l = parse_list_pop (&stack);
 			parse_list_push (&stack, gnm_expr_new_binary (
@@ -1023,6 +1022,14 @@
 			break;
 		}
 
+		case FORMULA_PTG_RANGE : {
+			GnmExpr const *r = parse_list_pop (&stack);
+			GnmExpr const *l = parse_list_pop (&stack);
+			parse_list_push (&stack,
+					 gnm_expr_new_range_ctor (l, r));
+			break;
+		}
+
 		case FORMULA_PTG_UNION : {
 			GnmExpr const *r = parse_list_pop (&stack);
 			GnmExpr const *l = parse_list_pop (&stack);

Modified: trunk/src/expr.c
==============================================================================
--- trunk/src/expr.c	(original)
+++ trunk/src/expr.c	Sat Jan 31 23:48:39 2009
@@ -317,6 +317,40 @@
 
 /***************************************************************************/
 
+/**
+ * gnm_expr_new_range_ctor:
+ * @l: start range
+ * @r: end range
+ *
+ * This function builds a range constructor or something simpler,
+ * but equivalent, if the arguments allow it. 
+ *
+ * Note: this takes ownership of @l and @r and may delete them.
+ **/
+GnmExpr const *
+gnm_expr_new_range_ctor (GnmExpr const *l, GnmExpr const *r)
+{
+	GnmValue *v;
+
+	g_return_val_if_fail (l != NULL, NULL);
+	g_return_val_if_fail (r != NULL, NULL);
+
+	if (GNM_EXPR_GET_OPER (l) != GNM_EXPR_OP_CELLREF)
+		goto fallback;
+	if (GNM_EXPR_GET_OPER (r) != GNM_EXPR_OP_CELLREF)
+		goto fallback;
+
+	v = value_new_cellrange_unsafe (&l->cellref.ref, &r->cellref.ref);
+	gnm_expr_free (l);
+	gnm_expr_free (r);
+	return gnm_expr_new_constant (v);
+
+ fallback:
+	return gnm_expr_new_binary (l, GNM_EXPR_OP_RANGE_CTOR, r);
+}
+
+/***************************************************************************/
+
 GnmExpr const *
 gnm_expr_copy (GnmExpr const *expr)
 {

Modified: trunk/src/expr.h
==============================================================================
--- trunk/src/expr.h	(original)
+++ trunk/src/expr.h	Sat Jan 31 23:48:39 2009
@@ -72,6 +72,7 @@
 					 Sheet *sheet_scope, Workbook *wb_scope);
 GnmExpr const *gnm_expr_new_cellref	(GnmCellRef const *cr);
 GnmExpr const *gnm_expr_new_set		(GnmExprList *args);
+GnmExpr const *gnm_expr_new_range_ctor  (GnmExpr const *l, GnmExpr const *r);
 
 GnmValue      *gnm_expr_get_range    (GnmExpr const *expr);
 GnmFunc       *gnm_expr_get_func_def (GnmExpr const *expr);

Modified: trunk/src/parser.y
==============================================================================
--- trunk/src/parser.y	(original)
+++ trunk/src/parser.y	Sat Jan 31 23:48:39 2009
@@ -388,6 +388,8 @@
 static GnmExpr *
 build_range_ctor (GnmExpr *l, GnmExpr *r, GnmExpr *validate)
 {
+	if (!l || !r) return NULL;
+
 	if (validate != NULL) {
 		if (GNM_EXPR_GET_OPER (validate) != GNM_EXPR_OP_CELLREF ||
 		    validate->cellref.ref.sheet != NULL) {
@@ -397,7 +399,10 @@
 			return NULL;
 		    }
 	}
-	return build_binop (l, GNM_EXPR_OP_RANGE_CTOR, r);
+
+	unregister_allocation (r);
+	unregister_allocation (l);
+	return register_expr_allocation (gnm_expr_new_range_ctor (l, r));
 }
 
 /*
@@ -788,7 +793,8 @@
 		if ($$ == NULL) { YYERROR; }
 	}
 	| RANGEREF RANGE_SEP RANGEREF {
-		$$ = build_binop ($1, GNM_EXPR_OP_RANGE_CTOR, $3);
+		$$ = build_range_ctor ($1, $3, NULL);
+		if ($$ == NULL) { YYERROR; }
 	}
 	;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]