Bug 1824 - tao_idl fails to generate code for bound strings with subtraction operator
Summary: tao_idl fails to generate code for bound strings with subtraction operator
Status: ASSIGNED
Alias: None
Product: TAO
Classification: Unclassified
Component: IDL Compiler (show other bugs)
Version: 1.4.1
Hardware: All All
: P3 minor
Assignee: DOC Center Support List (internal)
URL:
Depends on: 2821
Blocks:
  Show dependency tree
 
Reported: 2004-05-19 15:21 CDT by robert.a.boag
Modified: 2018-01-15 11:21 CST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description robert.a.boag 2004-05-19 15:21:57 CDT
The tao_idl compiler generates syntax errors for strings with lengths defined 
using a subtraction, "-", operation.  As long as the resulting length is 
positive, this should be legal IDL.  The other arithmetic operations are 
handled correctly.

The following code sample illustrates the bug:
---
#ifndef BUG_IDL
#define BUG_IDL

const long MY_STRING_LENGTH = 40;

typedef string<MY_STRING_LENGTH-1> MyStringType;

#endif // !BUG_IDL
---

tao_idl generates the following error messages for this code:
---
syntax error
tao_idl: "bug.idl", line 6: Illegal syntax or missing '>' after size expr in 
string
tao_idl: "bug.idl", line 6: Illegal syntax or missing '>' after size expr in 
string
tao_idl: "bug.idl", line 6: Illegal syntax or missing '>' after size expr in 
string
tao_idl: "bug.idl", line 6: Illegal syntax or missing '>' after size expr in 
string
tao_idl: bug.idl: found 4 errors
Fatal Error - Aborting
---

Workaround:
Change
< typedef string<MY_STRING_LENGTH-1> MyStringType;
to
> typedef string<MY_STRING_LENGTH - 1> MyStringType;
and tao_idl will successfully generate the C++ code.
Comment 1 Jeff Parsons 2004-05-19 19:20:58 CDT
In the IDL compiler front end, the lexer has regular expressions for the usual 
stuff, including integers with a possible leading '-'. The arithemetic and 
logical operators are in the parser, as grammar rules for the different types 
of expressions. So when the lexer sees a '-' and an integer with no whitespace 
separator, it returns the negative integer as a token, eating up the '-' so the 
grammar cannot use it. If there is whitespace, then the lexer cannot match the 
lone '-' to anything so it just passes it through, and the parser can then pick 
it up.

This problem could be fixed by either:

- moving the expression operators into the lexer as tokens

- removing the optional leading '-' for integer tokens. Then the IDL compiler
  would have to add negative integers to the tree as unary expressions. This 
  would probably have some consequences that would have to be dealt with

Either of these is doable I think, but not trivial, and I'm not sure when there 
will be time for it. At any rate, I'm assigning the bug to myself.
Comment 2 Jeff Parsons 2004-08-25 09:13:59 CDT
accepted again.
Comment 3 Jeff Parsons 2007-02-20 07:50:19 CST
Adding a dependency on a new bug entry by Jules Colding. These two bugs are 
very closely related, since they both revolve around the parsing of the '-' 
token in expressions.
Comment 4 Jules Colding 2007-02-22 07:25:14 CST
I've tried TAO 1.5.6 on FC6 with the same unfortunate result. The error message is:

syntax error
tao_idl: "./defines.idl", line 15: Illegal component in scoped name
terminate called after throwing an instance of 'FE_Bailout'

Just compile the following IDL with tao_idl (without any options) to confirm the
error.

############### Sample IDL ##################
#ifndef _DEFINES_DEF_
#define _DEFINES_DEF_

#pragma prefix "omc.brutus"

module BRUTUS {

        typedef unsigned long BDEFINE;
	typedef BDEFINE PT_TYPE;

        const PT_TYPE BRUTUS_PT_LONG = 0x00000004;

        const BDEFINE BRUTUS_pidExchangeXmitReservedMin = 0x3FE0;

	const BDEFINE BRUTUS_PR_AUTO_RESPONSE_SUPPRESS = BRUTUS_PT_LONG |
((BRUTUS_pidExchangeXmitReservedMin - 0x01)<<16);
}; // End of module BRUTUS


#endif
####################### END ##########################
Comment 5 Jeff Parsons 2007-02-22 07:54:59 CST
I have a
hunch the problem may be in the regular expressions.
When the lexer tries to match the input with one of
the regular expressions that accepts a leading '-',
it will (if I remember correctly) try to match as
long a string as possible, and also ignore whitespace,
so the expression

5 - 2

is going to cause the tokens IDL_UINTEGER and IDL_INTEGER
to be returned, while

5 - - 2

will return IDL_UINTEGER, '-', IDL_INTEGER and will parse
correctly (I've tried it).

I'm sure there's a way to fix the first case above, but 
I don't see it at the moment. I'll wait for help or more
time to focus on it.

Comment 6 Jeff Parsons 2007-02-22 07:57:24 CST
Changed host and compiler values above to All.
Comment 7 Jules Colding 2007-02-22 08:55:21 CST
OK. I'm trying to see when to problem arose...

TAO 1.5.3 is OK.
TAO 1.5.4 is OK.
TAO 1.5.5 is NOT OK.

so the problem started with 1.5.5.
Comment 8 Jules Colding 2007-03-26 07:40:40 CDT
All of my IDL files now compiles with tao_idl from TAO 1.5.7.