gnumeric r16724 - in trunk: . plugins/excel plugins/fn-lookup src



Author: mortenw
Date: Fri Jul 25 18:08:09 2008
New Revision: 16724
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16724&view=rev

Log:
2008-07-25  Morten Welinder  <terra gnome org>

	[Initial patch from Nick Lamb, see bug 69813.]

	* src/expr.h (enum GnmExprOp): Add new GNM_EXPR_OP_PAREN for
	parentheses.

	* src/parser.y: Create GNM_EXPR_OP_PAREN node.

	* src/auto-format.c (do_af_suggest): Handle GNM_EXPR_OP_PAREN.
	* src/expr.c (gnm_expr_eval): Ditto.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/plugins/excel/ms-formula-read.c
   trunk/plugins/excel/ms-formula-write.c
   trunk/plugins/fn-lookup/functions.c
   trunk/src/auto-format.c
   trunk/src/expr.c
   trunk/src/expr.h
   trunk/src/parser.y

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Fri Jul 25 18:08:09 2008
@@ -19,6 +19,9 @@
 	* Make ssgrep a lot more grep-like.
 	* Unify functions that work on sorted ranges.
 
+Nick Lamb:
+	* Retain ()s.  [#69813]
+
 --------------------------------------------------------------------------
 Gnumeric 1.9.1
 

Modified: trunk/plugins/excel/ms-formula-read.c
==============================================================================
--- trunk/plugins/excel/ms-formula-read.c	(original)
+++ trunk/plugins/excel/ms-formula-read.c	Fri Jul 25 18:08:09 2008
@@ -755,6 +755,7 @@
 	GNM_EXPR_OP_UNARY_PLUS,/* 0x12, ptgU_PLUS  */
 	GNM_EXPR_OP_UNARY_NEG,	/* 0x13, ptgU_MINUS */
 	GNM_EXPR_OP_PERCENTAGE,	/* 0x14, ptgPERCENT */
+	GNM_EXPR_OP_PAREN,      /* 0x15, pgtPAREN */
 };
 
 static gboolean
@@ -1049,16 +1050,12 @@
 		case FORMULA_PTG_U_PLUS :
 		case FORMULA_PTG_U_MINUS :
 		case FORMULA_PTG_PERCENT :
+		case FORMULA_PTG_PAREN:
 			parse_list_push (&stack, gnm_expr_new_unary (
 				unary_ops [ptgbase - FORMULA_PTG_U_PLUS],
 				parse_list_pop (&stack)));
 			break;
 
-		case FORMULA_PTG_PAREN:
-/*	  fprintf (stderr, "Ignoring redundant parenthesis ptg\n"); */
-			ptg_length = 0;
-			break;
-
 		case FORMULA_PTG_MISSARG:
 			parse_list_push_raw (&stack, value_new_empty ());
 			ptg_length = 0;

Modified: trunk/plugins/excel/ms-formula-write.c
==============================================================================
--- trunk/plugins/excel/ms-formula-write.c	(original)
+++ trunk/plugins/excel/ms-formula-write.c	Fri Jul 25 18:08:09 2008
@@ -651,6 +651,7 @@
 		int prec;		      /* Precedences -- should match parser.y  */
 		int assoc_left, assoc_right;  /* 0: no, 1: yes.  */
 	} const operations [] = {
+		{ FORMULA_PTG_PAREN,	 0, 0, 0 }, /* Parentheses for clarity  */
 		{ FORMULA_PTG_EQUAL,	 1, 1, 0 },
 		{ FORMULA_PTG_GT,	 1, 1, 0 },
 		{ FORMULA_PTG_LT,	 1, 1, 0 },

Modified: trunk/plugins/fn-lookup/functions.c
==============================================================================
--- trunk/plugins/fn-lookup/functions.c	(original)
+++ trunk/plugins/fn-lookup/functions.c	Fri Jul 25 18:08:09 2008
@@ -629,11 +629,6 @@
 	case GNM_EXPR_OP_INTERSECT:
 		res = 1;
 		break;
-	case GNM_EXPR_OP_ANY_BINARY:
-	case GNM_EXPR_OP_ANY_UNARY:
-	case GNM_EXPR_OP_ARRAY_CORNER:
-	case GNM_EXPR_OP_ARRAY_ELEM:
-		break;
 
 	case GNM_EXPR_OP_FUNCALL: {
 		GnmValue *v = gnm_expr_eval (expr, ei->pos,
@@ -655,8 +650,12 @@
 		res = expr->set.argc;
 		break;
 
+	case GNM_EXPR_OP_PAREN:
+		expr = expr->unary.value;
+		goto restart;
+
 	default:
-		g_warning ("unknown expr type.");
+		break;
 	}
 
 	if (res > 0)

Modified: trunk/src/auto-format.c
==============================================================================
--- trunk/src/auto-format.c	(original)
+++ trunk/src/auto-format.c	Fri Jul 25 18:08:09 2008
@@ -215,6 +215,7 @@
 		return *explicit ? AF_EXPLICIT : GNM_FUNC_AUTO_UNKNOWN;
 	}
 
+	case GNM_EXPR_OP_PAREN:
 	case GNM_EXPR_OP_UNARY_NEG:
 	case GNM_EXPR_OP_UNARY_PLUS:
 		return do_af_suggest (expr->unary.value, epos, explicit);

Modified: trunk/src/expr.c
==============================================================================
--- trunk/src/expr.c	(original)
+++ trunk/src/expr.c	Fri Jul 25 18:08:09 2008
@@ -1227,6 +1227,9 @@
 		value_release (b);
 		return res;
 
+	case GNM_EXPR_OP_PAREN:
+		return gnm_expr_eval (expr->unary.value, pos, flags);
+
 	case GNM_EXPR_OP_PERCENTAGE:
 	case GNM_EXPR_OP_UNARY_NEG:
 	case GNM_EXPR_OP_UNARY_PLUS:
@@ -1478,6 +1481,7 @@
 		guint8 assoc_left, assoc_right;  /* 0: no, 1: yes.  */
 		guint8 is_prefix;                /* for unary operators */
 	} const operations[] = {
+		{ "",   0, 0, 0, 0 }, /* Parentheses for clarity */
 		{ "=",  1, 1, 0, 0 },
 		{ ">",  1, 1, 0, 0 },
 		{ "<",  1, 1, 0, 0 },

Modified: trunk/src/expr.h
==============================================================================
--- trunk/src/expr.h	(original)
+++ trunk/src/expr.h	Fri Jul 25 18:08:09 2008
@@ -10,6 +10,7 @@
 /* Warning: if you add something here, see do_expr_as_string   ! */
 /* Warning: if you add something here, see ms-formula-write.c  ! */
 typedef enum {
+	GNM_EXPR_OP_PAREN,	/* Parentheses for clarity */
 	GNM_EXPR_OP_EQUAL,	/* Compare value equal */
 	GNM_EXPR_OP_GT,		/* Compare value greather than  */
 	GNM_EXPR_OP_LT,		/* Compare value less than */
@@ -45,7 +46,7 @@
 	case GNM_EXPR_OP_LTE: case GNM_EXPR_OP_NOT_EQUAL: \
 	case GNM_EXPR_OP_ADD: case GNM_EXPR_OP_SUB: case GNM_EXPR_OP_MULT: case GNM_EXPR_OP_DIV: \
 	case GNM_EXPR_OP_EXP: case GNM_EXPR_OP_CAT
-#define GNM_EXPR_OP_ANY_UNARY GNM_EXPR_OP_UNARY_NEG: case GNM_EXPR_OP_UNARY_PLUS : case GNM_EXPR_OP_PERCENTAGE
+#define GNM_EXPR_OP_ANY_UNARY GNM_EXPR_OP_PAREN: case GNM_EXPR_OP_UNARY_NEG: case GNM_EXPR_OP_UNARY_PLUS: case GNM_EXPR_OP_PERCENTAGE
 
 GnmExpr const *gnm_expr_new_constant	(GnmValue *v);
 GnmExpr const *gnm_expr_new_unary	(GnmExprOp op, GnmExpr const *e);

Modified: trunk/src/parser.y
==============================================================================
--- trunk/src/parser.y	(original)
+++ trunk/src/parser.y	Fri Jul 25 18:08:09 2008
@@ -619,7 +619,7 @@
 		} else {
 			if ($2->next == NULL) {
 				unregister_allocation ($2);
-				$$ = register_expr_allocation ($2->data);
+				$$ = register_expr_allocation (gnm_expr_new_unary (GNM_EXPR_OP_PAREN, $2->data));
 				/* NOTE : free list not content */
 				gnm_expr_list_free ($2);
 			} else {



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