Re: [PATCHES] Re: ORBit2, IDL compiler improvements



Sorry, I forgot the -u switch for cvs diff !! :-(

Michael Rumpf wrote:
> 
> Hi,
> 
> great news !

Of course for ORBit2, not for my own patches ;-) ( might be a little bit confusing...? ).

> 
> I'm currently working on a CORBA 2.2 conformance test suite for any kind of idl-compiler.
> The tests with orbit-idl surfaced the following problems:
> 
> 1. 1.5E+15 results in an error because the + sign has not been specified
>    in the rule from lexer.l
>    -> FIXED, by updating the rule in lexer.l.
> 2. octal constants having digits greater or equal 8 are recognized without
>    an error as floating point constants ( 088 is written as 88.000000 )
>    -> FIXED, by updating the regular expression in lexer.l
> 3. \n in string constants gets interpreted instead of just printed into the
>    header file (this applies to all escaped characters).
>    -> FIXED, by changing IDL_do_escapes() in libIDL.
> 4. The lexer connects the two string literals incorrectly:
>     "\xA" "B" to "\xAB". It should be "\x0AB".
>    -> Fixed, by changing IDL_do_escapes() in util.c
> 5. orbit-idl was not returning an error value (<>0) when the compilation
>    failed. I need this for automatic compilation of invalid IDL constructs.
>    -> FIXED, by returning -1 in this case (orbit-idl-main.c).
> 6. orbit-idl accepts \0 in a string constant
>    -> TODO (still working on that)
> 7. libIDL is matching const float x = 1;
>    This is illegal, because const_type is float and literal is an integer!
>    But worse, you can even write const float x = "test"; !!!!!
>    I found the following comment in the code (parser.y: const_dcl_def)
>    /* We should really do some type checking here */
>    Obviously the literal's type is not checked against the const_type
>    qualifier.
>    -> FIXED, by implementing the type checking.
> 
> TODO (what *I* will do next):
> 1. range checking
> 2. testing operators +, -, *, /, ...
> 
> So, more patches are likely to follow... ;-)
> 
> Michael
>
Index: lexer.l
===================================================================
RCS file: /cvs/gnome/libIDL/lexer.l,v
retrieving revision 1.75
diff -u -r1.75 lexer.l
--- lexer.l	2000/08/02 23:08:55	1.75
+++ lexer.l	2000/08/25 06:35:44
@@ -97,10 +97,11 @@
 newline			\n
 cpp_pragma		^{whitespace}#{whitespace}pragma{whitespace}.*
 cpp_status		^{whitespace}#.*
-b8_int			0[0-9]*
+b8_int			0[0-7]*
 b10_uint		[1-9][0-9]*
 b16_int			0[xX][0-9A-Fa-f]+
-float_lit		[0-9]*\.[0-9]+([eE]-?[0-9]+)?|[0-9]+\.?([eE]-?[0-9]+)?
+expo			[eE][-+]?[0-9]+
+float_lit		-?(([0-9]+{expo})|((([0-9]*\.[0-9]+)|([0-9]+\.[0-9]*)){expo}?))
 fixed_lit		([0-9]*\.[0-9]+|-?[0-9]+\.?[0-9]*)[dD]
 declspec		__declspec{whitespacenl}\({whitespacenl}[A-Za-z]*{whitespacenl}\)
 happy_ident		[A-Za-z][A-Za-z0-9]*
@@ -110,7 +111,8 @@
 prop_value		\([^\)]+\)
 native_type		[^\)]+\)
 sqstring		\'[^\'\n]*[\'\n]
-dqstring		\"[^\"\n]*[\"\n]
+dqstring		\"(([^\"\n\t\0])|("\\"[ntvbrfa\\\?\'\"])|("\\"(([1-7][0-7]?[0-7]?)|([0-7][1-7][0-7]?)|([0-7][0-7][1-7])))|("\\"[xX][0-9a-fA-F]{1,2}))*\"
 
 %p 5000
 
Index: orbit-idl-main.c
===================================================================
RCS file: /cvs/gnome/ORBit/src/orbit-idl-compiler/orbit-idl-main.c,v
retrieving revision 1.10
diff -u -r1.10 orbit-idl-main.c
--- orbit-idl-main.c	2000/08/02 23:10:16	1.10
+++ orbit-idl-main.c	2000/08/25 06:36:30
@@ -127,7 +127,7 @@
 int main(int argc, const char *argv[])
 {
   poptContext pcon;
-  int rc;
+  int rc=0;
   const char *arg;
   OIDL_Run_Info rinfo;
 
@@ -149,7 +149,7 @@
     g_print("orbit-idl: bad argument %s: %s\n", 
     		poptBadOption(pcon, POPT_BADOPTION_NOALIAS),
 		poptStrerror(rc));
-    exit(0);
+    exit(rc);
   }
 
   /* Prep our run info for the backend */
@@ -173,8 +173,9 @@
   /* Do it */
   while((arg=poptGetArg(pcon))!=NULL) {
     rinfo.input_filename = g_basename(arg);
-    if (!orbit_idl_to_backend(arg, &rinfo)) {
+    if (!(rc=orbit_idl_to_backend(arg, &rinfo))) {
       g_warning("%s compilation failed", arg);
+      exit(-1);
     }
   }
 
Index: parser.y
===================================================================
RCS file: /cvs/gnome/libIDL/parser.y,v
retrieving revision 1.156
diff -u -r1.156 parser.y
--- parser.y	2000/08/02 23:08:55	1.156
+++ parser.y	2000/08/25 06:35:39
@@ -681,9 +681,46 @@
 
 const_dcl_def:		TOK_CONST const_type new_ident
 			'=' const_exp			{
+	switch(IDL_NODE_TYPE ($2))
+	{
+		case IDLN_TYPE_INTEGER:
+			if(IDL_NODE_TYPE ($5) != IDLN_INTEGER)
+				yyerrorv ("Type mismatch in const long declaration!");
+			break;
+		case IDLN_TYPE_CHAR:
+			if(IDL_NODE_TYPE ($5) != IDLN_CHAR)
+				yyerrorv ("Type mismatch in const char declaration!");
+			break;
+		case IDLN_TYPE_WIDE_CHAR:
+			if(IDL_NODE_TYPE ($5) != IDLN_WIDE_CHAR)
+				yyerrorv ("Type mismatch in const wchar declaration!");
+			break;
+		case IDLN_TYPE_BOOLEAN:
+			if(IDL_NODE_TYPE ($5) != IDLN_BOOLEAN)
+				yyerrorv ("Type mismatch in const boolean declaration!");
+			break;
+		case IDLN_TYPE_FLOAT:
+			if(IDL_NODE_TYPE ($5) != IDLN_FLOAT)
+				yyerrorv ("Type mismatch in const float declaration!");
+			break;
+		case IDLN_TYPE_STRING:
+			if(IDL_NODE_TYPE ($5) != IDLN_STRING)
+				yyerrorv ("Type mismatch in const string declaration!");
+			break;
+		case IDLN_TYPE_WIDE_STRING:
+			if(IDL_NODE_TYPE ($5) != IDLN_WIDE_STRING)
+				yyerrorv ("Type mismatch in const wstring declaration!");
+			break;
+		case IDLN_TYPE_FIXED:
+			if(IDL_NODE_TYPE ($5) != IDLN_FIXED)
+				yyerrorv ("Type mismatch in const fixed declaration!");
+			break;
+		default:
+			yyerrorv ("Illegal type for const declaration!");
+			break;
+	}		
 	$$ = IDL_const_dcl_new ($2, $3, $5);
-	/* Should probably do some type checking here... */
-}
+}	
 	;
 
 except_dcl:		z_declspec except_dcl_def	{
Index: util.c
===================================================================
RCS file: /cvs/gnome/libIDL/util.c,v
retrieving revision 1.120
diff -u -r1.120 util.c
--- util.c	2000/08/02 23:08:55	1.120
+++ util.c	2000/08/25 06:34:33
@@ -2115,60 +2115,59 @@
 	}
 }
 
-#define C_ESC(a,b)				case a: *p++ = b; ++s; break
 gchar *IDL_do_escapes (const char *s)
 {
-	char *p, *q;
+	char *temp = s, *ret;
 
-	if (!s)
-		return NULL;
+        GString *gstr = g_string_new( "" );
 
-	p = q = g_malloc (strlen (s) + 1);
+        if (!s)
+                return NULL;
 
-	while (*s) {
-		if (*s != '\\') {
-			*p++ = *s++;
-			continue;
-		}
-		++s;
-		if (*s == 'x') {
-			char hex[3];
-			int n;
-			hex[0] = 0;
-			++s;
-			sscanf (s, "%2[0-9a-fA-F]", hex);
- 			s += strlen (hex);
-			sscanf (hex, "%x", &n);
-			*p++ = n;
-			continue;
-		}
-		if (*s >= '0' && *s <= '7') {
-			char oct[4];
-			int n;
-			oct[0] = 0;
-			sscanf (s, "%3[0-7]", oct);
- 			s += strlen (oct);
-			sscanf (oct, "%o", &n);
-			*p++ = n;
-			continue;
-		}
-		switch (*s) {
-			C_ESC ('n','\n');
-			C_ESC ('t','\t');
-			C_ESC ('v','\v');
-			C_ESC ('b','\b');
-			C_ESC ('r','\r');
-			C_ESC ('f','\f');
-			C_ESC ('a','\a');
-			C_ESC ('\\','\\');
-			C_ESC ('?','?');
-			C_ESC ('\'','\'');
-			C_ESC ('"','"');
-		}
-	}
-	*p = 0;
+        while( *temp )
+        {
+                if( *temp == '\\' )
+                {
+                        g_string_append_c( gstr, '\\' );
+                        ++temp;
+                        if( *temp == 'x' )
+                        {
+                                char hex[3];
+				int c = 0;
+                                g_string_append_c( gstr, 'x' );
+                                hex[0] = 0;
+                                ++temp;
+                                sscanf(temp, "%2[0-9a-fA-F]", hex);
+				c = strlen( hex );
+				temp += c;
+                                if( c == 1 )
+                                        g_string_append_c( gstr, '0' );
+                                g_string_append( gstr, hex );
+				continue;
+                        }
+                        if( *temp >= '0' && *temp <= '7' )
+                        {
+                                char oct[4];
+                                int c = 0;
+                                oct[0] = 0;
+                                sscanf(temp, "%3[0-7]", oct);
+                                c = strlen( oct );
+				temp += c;
+                                for( c; c < 3; c++ )
+                                        g_string_append_c( gstr, '0' );
+                                g_string_append( gstr, oct );
+				continue;
+                        }
+			g_string_append_c( gstr, *temp );
+                }
+		else
+			g_string_append_c( gstr, *temp );
+		temp++;
+        }
 
-	return q;
+        ret = g_strdup( gstr->str );
+        g_string_free( gstr, FALSE );
+	return ret;
 }
 
 int IDL_list_length (IDL_tree list)


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