Ver código fonte

tripl: fix bug and I'm going to have lunch

rain 4 anos atrás
pai
commit
8e6746f778
3 arquivos alterados com 27 adições e 24 exclusões
  1. 16 20
      arch/arch_templ.c
  2. 10 0
      arch/cstyles.c
  3. 1 4
      sample.trp

+ 16 - 20
arch/arch_templ.c

@@ -239,7 +239,7 @@ static int math_set_name(char *p, struct arch *arch_fn) {
 }
 
 
-static int name_defined(char *name) {
+int name_defined(char *name) {
 	struct klist_node *n;
 
 	for (n = names_list.next; n != &names_list; n = n->next) 
@@ -297,7 +297,7 @@ static int declare_object(char *p, struct arch *arch_fn) {
 
 		/* we will not free the name because interp_libs_dump uses it */
 
-		break;
+		return 0;
 
 	case WORDTYPE_NAME:
 		/* functions or variables */
@@ -311,8 +311,6 @@ static int declare_object(char *p, struct arch *arch_fn) {
 
 		n->payload = name;
 
-		klist_add(&names_list, n);
-
 		guess = NAMES;
 
 		p += out;
@@ -325,9 +323,6 @@ static int declare_object(char *p, struct arch *arch_fn) {
 
 	_skip_spaces(p);
 
-	if (guess == SHARED) 
-		goto skip;
-
 	/* try to getword */
 
 	getword(p, &type, &out);
@@ -412,29 +407,30 @@ skip:	attr = getattrmask(p, declare_attrtab);
 	if (unlikely(!attr && guess != SHARED)) 
 		exit(generic_error("you must give attributes for declares", psave, lno));
 
-	if (guess != SHARED) {
-		if (attr & 2) 
-			n->value |= DECLARE_FN;
+	if (attr & 2) 
+		n->value |= DECLARE_FN;
 
-		else if (attr & 4) {
-			if (unlikely(guess == FUNCTION)) 
-				exit(generic_error("you gave us a function declare but told us this is a variable declare? ", 
-							psave, lno));
+	else if (attr & 4) {
+		if (unlikely(guess == FUNCTION)) 
+			exit(generic_error("you gave us a function declare but told us this is a variable declare? ", 
+						psave, lno));
 
-			/* variable */
-			n->value = DECLARE_VAR;
-		}
-
-		else 
-			exit(generic_error("one of 'fn' or 'var' must be gave", psave, lno));
+		/* variable */
+		n->value = DECLARE_VAR;
 	}
 
+	else 
+		exit(generic_error("one of 'fn' or 'var' must be gave", psave, lno));
+
+
 	if (unlikely(name_defined(n->payload))) {
 		error((char *) n->payload);
 
 		exit(generic_error("name already defined", psave, lno));
 	}
 
+	klist_add(&names_list, n);
+
 	return 0;
 }
 

+ 10 - 0
arch/cstyles.c

@@ -36,6 +36,9 @@
 /* compatible of c-style function defines */
 
 
+/* arch/arch_templ.c */
+int name_defined(char *name);
+
 extern struct klist_node names_list;
 extern char *psave;
 
@@ -164,6 +167,13 @@ __arch_templ int cstyle_declare(char *p, struct arch *arch_fn) {
 		n->value = DECLARE_FN | nargs;
 
 	n->payload = fname;
+
+	if (name_defined(n->payload)) {
+		error((char *) n->payload);
+
+		exit(generic_error("name already defined", psave, lno));
+	}
+
 	klist_add(&names_list, n);
 
 	return 1;

+ 1 - 4
sample.trp

@@ -6,12 +6,9 @@
 
 extern int *function(int arg, const asdf);
 int function2();
+char *functio2n(void);
 
 
-# buggy
-#
-< function 		@ fn;
-< function2 2 		@ fn;
 < function3 ( a, b, c ) @ fn;
 
 !  			@ fn var;