Project

General

Profile

Bug #9905

EOF file is not matched during preprocessing

Added by Stefan Vieru over 1 year ago. Updated 3 months ago.

Status:
Internal Test
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:
4GL Preprocessor

oe_basic.png (36.4 KB) Stefan Vieru, 04/15/2025 09:41 AM

fwd_basic.png (40.9 KB) Stefan Vieru, 04/15/2025 09:41 AM

fwd_keep.png (17.7 KB) Stefan Vieru, 04/15/2025 09:52 AM

oe_keep.png (17.8 KB) Stefan Vieru, 04/15/2025 09:52 AM


Related issues

Related to Testing - Support #6859: preprocessor tests Test

History

#1 Updated by Stefan Vieru over 1 year ago

  • File Screenshot from 2025-04-15 16-38-47.png added
  • File Screenshot from 2025-04-15 16-36-31.png added

During preprocessing EOF is not matching the expected baseline.
For example:


&SCOPED-DEFINE nothing better than nothing
&GLOBAL-DEFINE something something else

&if false &then
   /* this can never be included since the expression is false */
&elseif defined(something) &then
   /* welcome to a preprocessed program */
&else
   /* this can never be included since the elseif will always be true */
&endif

{tests/preproc/support/top.i "isn't it?" "second (unused positional argument)"}

We have to preprocess this .p

#2 Updated by Stefan Vieru over 1 year ago

  • Assignee set to Stefan Vieru

This is the output from OE

This is the output from FWD

As we can see, at the end in FWD it should be 0A 20 0A but it actually is 0A 20 0A 20.
What FWD does is adding a " " at the end of the file.

#3 Updated by Stefan Vieru over 1 year ago

  • File deleted (Screenshot from 2025-04-15 16-36-31.png)

#4 Updated by Stefan Vieru over 1 year ago

  • File deleted (Screenshot from 2025-04-15 16-38-47.png)

#5 Updated by Stefan Vieru over 1 year ago

#6 Updated by Stefan Vieru over 1 year ago

With this file:

def var txt as char.
txt = "hel~nlo".
message txt.

We got the OE output:

The FWD output:

Same issue, a " " is added at the EOF.

#7 Updated by Stefan Vieru over 1 year ago

  • Status changed from New to WIP

#8 Updated by Stefan Vieru over 1 year ago

I looked into this issue and what I've found is:
In ClearStream mread, at the end

-      if (sym.size() == 1 && fspre.getFileName().equals("/"))
+      if (sym.size() == 2 && fspre.getFileName().equals("/"))
       {
          return super.read();
       }
       else
       {
+         super.unread(' ');
          clearCount++;
-         return ' ';
+         return '\n';
       }
    }

This change fixes all the harness EOF errors, but only if we dont have a NL present at any of the files(also include files)
Having a empty NL at the EOF in any of those files sometimes breaks this mread() method and it doesn't respect OE preprocessing, even before my changes.

#9 Updated by Greg Shah over 1 year ago

This change fixes all the harness EOF errors, but only if we dont have a NL present at any of the files(also include files)

What happens in OE (and FWD) when there is an NL present at EOF in a file? It sounds like the fix needs some work. Also, please put the changes into a branch.

#10 Updated by Stefan Vieru over 1 year ago

I will explain the issue better after some analysis:
When sym.size() = = 2 (sym being the "stack call" of the files) it means that we are in the rootfile, meaning that when preprocessing a simple file, we shouldn't append a ' '.
In the code from trunk that size is checked for value 1, thus having all tests appending at the EOF a ' '.
When sym has a bigger size (meaning that the rootfile included other .i files) it has to append this ' ' and a NL.

I have taken basic.p as example.
Let's say we replace the ' ' at the end of mread with L, this is the output in FWD:

MESSAGE "Hello World!".
L

MESSAGE "This is something else, isn't it?".
L
L

The first 'L' is from nested.i, and the second 'L' is from top.i and the last one is from FWD itself as mentioned above because of == 1.

Now if we preprocess in OE:

MESSAGE "Hello World!".
L

MESSAGE "This is something else, isn't it?".
L


The first and second L is for the same reason as in FWD but at the end we just have a NL, not a ' '.
So for some reason in FWD we just append a ' ' at the end because what I think it's happening is that FWD doesn't treat this file as root, that's why we need to have == 2.

Now doing the same test on named_args_.._03.p

display "1" label "~{name1}" 
        "2" label "~{name2}" 
        "1"      label "~{1}" 
        "2"      label "~{2}" 
        ""      label "~{3}" 
        ""      label "~{4}" 
        ""      label "~{5}" 
        ""      label "~{6}" 
        ""      label "~{7}" 
        "1 2"      label "~{*}" 
        '&name1="1" &name2="2"'     label "~{* (named)}".
        LL

When in OE is:
display "1" label "~{name1}" 
        "2" label "~{name2}" 
        "1"      label "~{1}" 
        "2"      label "~{2}" 
        ""      label "~{3}" 
        ""      label "~{4}" 
        ""      label "~{5}" 
        ""      label "~{6}" 
        ""      label "~{7}" 
        "1 2"      label "~{*}" 
        '&name1="1" &name2="2"'     label "~{* (named)}".

L


This procedure is including show_preproc_args.

So basic.p has 1 include file and inside that is another include file(2 per total) vs named_args.. which has only one include.
Now what is wierd is that in FWD basic.p the 2 L's at the end are on different lines, not the same line, like in the example above.
I am looking into why this is the case, why these two are on different lines.
So having a single value for L for those 2 cases it's not possible since the L in the 2nd testcase is right next to the first L.

#11 Updated by Greg Shah over 1 year ago

OK, the bottom line here: please keep going with the fixes. The FWD output should match OE output exactly.

#12 Updated by Stefan Vieru about 1 year ago

I have created 9905a with rev 15868 with my changes.
I have added the following change

-      if (sym.size() == 1 && fspre.getFileName().equals("/"))
+      if (sym.size() == 2 && fspre.getFileName().equals("/"))
       {
          return super.read();
       }
       else
       {
-         clearCount++;
-         return ' ';
+         super.unread(' ');
+         clearCount += 2;
+         return '\n';
       }

After every include file a new line and a space must be added. When sym.size() is 2, it means we are in the root file, thus we only need to read from the file stream, rather than returning ' ' before the changes.

#13 Updated by Stefan Vieru about 1 year ago

  • Status changed from WIP to Review
  • % Done changed from 0 to 100

#14 Updated by Stefan Vieru about 1 year ago

  • reviewer Greg Shah added

#15 Updated by Stefan Vieru about 1 year ago

The issue i addressed earlier about the random NL that appear:
When we have a .i file that we include, in OE if it has a empty NL at the end, it ignores it and follows the convention of '\n ' being appended at the end.
In FWD the include file is copied as is, meaning that we have that last empty NL.

#16 Updated by Greg Shah about 1 year ago

  • Status changed from Review to Internal Test

Code Review Task Branch 9905a Revision 15868

The changes look good.

#17 Updated by Stefan Vieru about 1 year ago

All changes have been moved to 6859b.

#18 Updated by Greg Shah about 1 year ago

#19 Updated by Greg Shah 5 months ago

  • topics 4GL Preprocessor added

#20 Updated by Alexandru Lungu 3 months ago

  • Assignee changed from Stefan Vieru to Octavian Adrian Gavril

Also available in: Atom PDF