Explorar el Código

script parsing: helper function updated & moved

- helper function for computing the file position of an expression
Andrei Pelinescu-Onciul hace 16 años
padre
commit
33d560253c
Se han modificado 3 ficheros con 28 adiciones y 22 borrados
  1. 1 22
      cfg.y
  2. 24 0
      route_struct.c
  3. 3 0
      route_struct.h

+ 1 - 22
cfg.y

@@ -201,8 +201,6 @@ static struct rvalue* rval_tmp;
 
 static void warn(char* s);
 static void get_cpos(struct cfg_pos* pos);
-static void get_rve2_pos(struct cfg_pos* res,
-							struct cfg_pos* pos1, struct cfg_pos* pos2);
 static struct rval_expr* mk_rve_rval(enum rval_type, void* v);
 static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1);
 static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
@@ -2613,25 +2611,6 @@ static void yyerror(char* format, ...)
 
 
 
-static void get_rve2_pos(struct cfg_pos* res,
-							struct cfg_pos* pos1, struct cfg_pos* pos2)
-{
-	*res=*pos1;
-	if ((res->s_line == 0) || (res->s_line > pos2->s_line)){
-		res->s_line=pos2->s_line;
-		res->s_col=pos2->s_col;
-	}else if ((res->s_line == pos2->s_line) && (res->s_col > pos2->s_col)){
-		res->s_col=pos2->s_col;
-	}
-	if ((res->e_line == 0) || (res->e_line < pos2->e_line)){
-		res->e_line=pos2->e_line;
-		res->e_col=pos2->e_col;
-	}else if ((res->e_line == pos2->e_line) && (res->e_col < pos2->e_col)){
-		res->e_col=pos2->e_col;
-	}
-}
-
-
 /** mk_rval_expr_v wrapper.
  *  checks mk_rval_expr_v return value and sets the cfg. pos
  *  (line and column numbers)
@@ -2688,7 +2667,7 @@ static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
 	
 	if ((rve1==0) || (rve2==0))
 		return 0;
-	get_rve2_pos(&pos, &rve1->fpos, &rve2->fpos);
+	cfg_pos_join(&pos, &rve1->fpos, &rve2->fpos);
 	ret=mk_rval_expr2(op, rve1, rve2, &pos);
 	if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
 		yyerror_at(&pos, "bad expression: type mismatch:"

+ 24 - 0
route_struct.c

@@ -52,6 +52,30 @@
 #include "ut.h" /* ZSW() */
 
 
+
+/** joins to cfg file positions into a new one. */
+void cfg_pos_join(struct cfg_pos* res,
+							struct cfg_pos* pos1, struct cfg_pos* pos2)
+{
+	struct cfg_pos ret;
+	ret=*pos1;
+	if ((ret.s_line == 0) || (ret.s_line > pos2->s_line)){
+		ret.s_line=pos2->s_line;
+		ret.s_col=pos2->s_col;
+	}else if ((ret.s_line == pos2->s_line) && (ret.s_col > pos2->s_col)){
+		ret.s_col=pos2->s_col;
+	}
+	if ((ret.e_line == 0) || (ret.e_line < pos2->e_line)){
+		ret.e_line=pos2->e_line;
+		ret.e_col=pos2->e_col;
+	}else if ((ret.e_line == pos2->e_line) && (ret.e_col < pos2->e_col)){
+		ret.e_col=pos2->e_col;
+	}
+	*res=ret;
+}
+
+
+
 struct expr* mk_exp(int op, struct expr* left, struct expr* right)
 {
 	struct expr * e;

+ 3 - 0
route_struct.h

@@ -167,5 +167,8 @@ void print_action(struct action* a);
 void print_actions(struct action* a);
 void print_expr(struct expr* exp);
 
+/** joins to cfg file positions into a new one. */
+void cfg_pos_join(struct cfg_pos* res,
+							struct cfg_pos* pos1, struct cfg_pos* pos2);
 #endif