Project

General

Profile

Feature #2082

add conversion support for 4GL's duplicate variable "feature"

Added by Constantin Asofiei about 11 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Start date:
03/06/2013
Due date:
% Done:

80%

billable:
No
vendor_id:
GCD

ca_upd20130306c.zip (5.3 KB) Constantin Asofiei, 03/06/2013 08:42 AM

ca_upd20130306d.zip (5.42 KB) Constantin Asofiei, 03/06/2013 09:10 AM

ca_upd20130307b.zip (1.1 KB) Constantin Asofiei, 03/07/2013 05:13 AM

ca_upd20130307c.zip (39.9 KB) Constantin Asofiei, 03/07/2013 06:27 AM

ca_upd20130307d.zip (302 KB) Constantin Asofiei, 03/07/2013 12:13 PM

ca_upd20130307g.zip (305 KB) Constantin Asofiei, 03/07/2013 12:42 PM

History

#1 Updated by Constantin Asofiei about 11 years ago

4GL allows two vars with the same name, if this construct is encountered:

def new global shared var ch-1 like book.book-title. /* this is used */
def shared var ch-1 as int format "x(10)". /* this is ignored */

This is possible only if the first definition is from a "DEFINE NEW GLOBAL SHARED" statement (and only this). All subsequent definitions for var with the same name (using DEFINE SHARED OR DEFINED VAR or anything else), are ignored.

#2 Updated by Constantin Asofiei about 11 years ago

Attached update hides all duplicate var defs, only if the first one is DEF NEW GLOBAL SHARED. I'm putting this through conversion regression testing now.

#3 Updated by Greg Shah about 11 years ago

The code looks good. I only have 2 questions:

1. Is there any difference in behavior when the non-global define variable is inside a nested scope (e.g. an internal procedure). In such cases, we would expect the global var to be temporarily hidden but the local var and would not think of that as a duplicate.

2. What happens in the case where the global var is created after the non-global var?

#4 Updated by Constantin Asofiei about 11 years ago

1. Is there any difference in behavior when the non-global define variable is inside a nested scope (e.g. an internal procedure). In such cases, we would expect the global var to be temporarily hidden but the local var and would not think of that as a duplicate.

Yes, you are correct, when inside a procedure/function, it should hide the global var.

2. What happens in the case where the global var is created after the non-global var?

Compile-time error.

#5 Updated by Greg Shah about 11 years ago

Please put a comment into the variable_definitions.rules about the order of the definitions and that we deliberately ignore that case since it fails in the 4GL with a compile error. That way, future readers will know that it was intentional.

#6 Updated by Constantin Asofiei about 11 years ago

Added comment and fixed the proc/function case. I'm putting it back into conversion regression testing.

#7 Updated by Constantin Asofiei about 11 years ago

The update has passed conversion regression testing. Note that even MAJIC had two cases of duplicated vars, in two files, which looked like this:

def new global shared var ch-1 as char. /* this is used */
def new shared var ch-1 as char. /* this must be ignored */

This didn't cause compile problems because one was an instance field for the class, and the other was emitted as an instance field for the Block instance associated with the external program call.

#8 Updated by Greg Shah about 11 years ago

Check it in and distribute it.

#9 Updated by Constantin Asofiei about 11 years ago

Committed to bzr revision 10255.

#10 Updated by Greg Shah about 11 years ago

  • Status changed from Review to Closed

#11 Updated by Constantin Asofiei about 11 years ago

Fixed multiple calls like:

def new global shared var ch as char.
def new global shared var ch as char.

This is going through conversion regression testing.

#12 Updated by Constantin Asofiei about 11 years ago

I need to rewrite this at the parser side, as the duped var gets ref'ed by the parser:

def new global shared var i as int. /* 1st def */

def shared var i as int. /* 2nd def */

procedure proc0.
   message i. /* the parser links this with the 2nd def. as 2nd def is hidden, it will no longer emit (as promoted) and 1st def will not be promoted, becaused is not ref'ed*/
end.

#13 Updated by Constantin Asofiei about 11 years ago

So the problem was that the parser was adding tempidx to the dupped vars too. The sollution was to not register the dupped vars with the symbol dictionary, and for the dupped vars remove their tempidx during post-parse-fixups phase. This is going through conversion regression testing.

#14 Updated by Constantin Asofiei about 11 years ago

This has regressions, one of them relaed to this, as 4GL (v9-only I think) allowed this:

def var ch as char label "adsadasd" as log init no.

if ch then message ch. /* ch is not char, but logical */

In v10, the code above does not compile.

#15 Updated by Constantin Asofiei about 11 years ago

Fixed a problem (I was using varDict.getSymbol instead of varDict.getSymbolAtScope(name, 0) to search only in the current scope). Still working on the issue at note 14.

#16 Updated by Constantin Asofiei about 11 years ago

MAJIC has the case at note 14 in only one file. I've checked the history of this file and this change was introduced after they switched to P2J server. So, the conclusion is that this is a bug in the 4GL sources, not another 4GL stupid feature.

I'll edit the file and put it in a separate task.

#17 Updated by Constantin Asofiei about 11 years ago

The edited file is in task #2085.

This update has passed conversion regression testing (there are changes in two files, a var was promoted to instance field from instead of anon class instance field).

#18 Updated by Greg Shah about 11 years ago

I'm not sure why you switched from a Set to a Map in fixups/variable_definitions.rules (did you plan to use it and then later on, find you didn't need it)?

Otherwise, I don't see a problem. Go ahead and check it in and distribute it.

#19 Updated by Constantin Asofiei about 11 years ago

Greg Shah wrote:

I'm not sure why you switched from a Set to a Map in fixups/variable_definitions.rules (did you plan to use it and then later on, find you didn't need it)?

Yes, I wanted to save the first node for the first var definition, which didn't help in the end. I've switched back to Set now.

Attached update was committed as revision 10263.

#20 Updated by Greg Shah over 7 years ago

  • Target version changed from Milestone 4 to Conversion Support for Server Features

Also available in: Atom PDF