Project

General

Profile

Bug #2093

VALEXP support in P2J

Added by Ovidiu Maxiniuc about 11 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Start date:
03/15/2013
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:

History

#1 Updated by Ovidiu Maxiniuc about 11 years ago

This issue is dedicated to note 80 from Issue #2068.

There is this validation expression for the dvofrsts.dvofrsts-cde field: VALEXP "CAN-FIND(dvofrsts WHERE dvofrsts.dvofrsts-cde = dvofrinv.dvofrsts-cde)" P2J can't seem to convert CAN-FIND in the VALEXP, as the resulted validation is:

public logical validateExpression(BaseDataType _newValue_)
{
   final character _dvofrstsCde = (character) _newValue_;
   return _dvofrstsCde; /* compile error here */
}

Later addition (Constantin, note 124):

The above documentation it wrong, and the real VALEXP in the .df file is wrong (the real VALEXP for dvofrsts.dvofrsts-cde is VALEXP("dvofrsts.dvofrsts-cde NE = "" """), which is corrupted.

Anyway, 4GL doesn't fail on this I think because the field is not used in a UI-update, is used for display only. So, as this doesn't even need to get generated as a Validation inner class, I've instructed Ovidiu to work on this:
  • do not emit Validation inner classes in cases the field is not used in interactive UI statements.
  • search for cases where P2J doesn't emit the Validation inner class, when VALEXP is used at the field.

#2 Updated by Eric Faulhaber about 11 years ago

  • Parent task deleted (#2068)
  • Project changed from Liberty to Database

#3 Updated by Eric Faulhaber about 11 years ago

  • Target version set to Milestone 4

#4 Updated by Constantin Asofiei about 11 years ago

Ovidiu: with the #1620 changes, I can't see any more schema VALEXP problems in the logs (I think P2J was too aggressive in emitting the schema VALEXP for the frames used in FORM statements). We should make this a low priority. Please document here all your findings and start working on the last notes on #2068.

#5 Updated by Ovidiu Maxiniuc about 11 years ago

Everything seems to work smooth, validation is only generated in schema-validation:

<rule>((parent.type == prog.kw_enable   or
        parent.type == prog.kw_prmt_for or
        parent.type == prog.kw_set      or
        parent.type == prog.kw_update   or
        parent.type == prog.kw_insert   or
        parent.type == prog.kw_form)      and
       parent.parent.type == prog.statement)             or
      upPath("STATEMENT/KW_FORM/FORM_ITEM")              or
      upPath("STATEMENT/KW_FORM/FORM_ITEM/EXPRESSION")
   <rule>evalLib("fields")
      ...

Later in @validation_post@s rules the nodes are dispatched to corresponding frames.

Here is a special cases when P2J fails:

form person.schedule validate(person.schedule[1] = "a", "must type 'a'") with frame f1.

which will result in a
ref = getAst(#(long) widref.getAnnotation("refid"))
                            ^  { java.lang.NullPointerException }

Rule Type :   WALK
Source AST:  [ validate ] BLOCK/STATEMENT/KW_FORM/FORMAT_PHRASE/KW_VALIDATE/ @34:22 {704374636766}
Copy AST  :  [ validate ] BLOCK/STATEMENT/KW_FORM/FORMAT_PHRASE/KW_VALIDATE/ @34:22 {704374636766}
Condition :  ref = getAst(#(long) widref.getAnnotation("refid"))
Loop      :  false
--- END RULE REPORT ---

    at com.goldencode.p2j.pattern.PatternEngine.run(PatternEngine.java:732)
    at com.goldencode.p2j.convert.ConversionDriver.processTrees(ConversionDriver.java:948)
    at com.goldencode.p2j.convert.ConversionDriver.back(ConversionDriver.java:836)
    at com.goldencode.p2j.convert.ConversionDriver.main(ConversionDriver.java:1729)
Caused by: com.goldencode.expr.ExpressionException: Expression execution error @1:29 [KW_VALIDATE id=704374636766]


The AST look loke this:
<ast col="1" id="704374636547" line="34" text="form" type="KW_FORM">
   <ast col="0" id="704374636555" line="0" text="form item" type="FORM_ITEM">
      <ast col="0" id="704374636556" line="0" text="expression" type="EXPRESSION">
         <ast col="6" id="704374636557" line="34" text="person.schedule" type="FIELD_CHAR" />
         <ast col="0" id="704374636679" line="0" text="" type="FORMAT_PHRASE">
            <ast col="0" id="704374636680" line="0" text="" type="KW_VALIDATE">
               <ast col="0" id="704374636681" line="0" text="" type="EXPRESSION" />
               <ast col="0" id="704374636688" line="0" text="" type="EXPRESSION" />
      <ast col="0" id="704374636560" line="0" text="format phrase" type="FORMAT_PHRASE">
         <ast col="22" id="704374636561" line="34" text="validate" type="KW_VALIDATE">
           <ast col="0" id="704374636563" line="0" text="expression" type="EXPRESSION" />
           <ast col="0" id="704374636571" line="0" text="expression" type="EXPRESSION" />

The valexp from schema and validation clause are created as ASTs at different levels but in validation.rules at about line 110, widref = copy.parent.getPrevSibling() which is assumed to be a FIELD_CHAR with refid annotation.

There was an additional case when the generated code was not compilable because some widget accesor of an extend field from a frame was not generated. However, when writing this note I observed that it was my mistake - wrong index of extend was accessed without being added by a form statement to respective frame. In fact, this should be somehow detected and an error/warning be generated (the P4GL does this test at compile time).

#6 Updated by Constantin Asofiei about 11 years ago

Please check the failed case in the previous note with the latest #1620 fix, if you haven't done already so.

#7 Updated by Ovidiu Maxiniuc about 11 years ago

The AST is slightly different with last revision from bzr:

<ast col="1" id="704374636547" line="5" text="form" type="KW_FORM">
  <ast col="0" id="704374636760" line="0" text="" type="FORM_ITEM">
    <ast col="0" id="704374636761" line="0" text="" type="EXPRESSION">
      <ast col="6" id="704374636764" line="5" text="person.schedule" type="FIELD_CHAR">
    </ast>
  </ast>
  <ast col="0" id="704374636767" line="0" text="format phrase" type="FORMAT_PHRASE">
    <ast col="22" id="704374636768" line="5" text="validate" type="KW_VALIDATE">
      <ast col="0" id="704374636769" line="0" text="expression" type="EXPRESSION">
        <ast col="50" id="704374636770" line="5" text="=" type="EQUALS">
          <ast col="31" id="704374636771" line="5" text="person.schedule" type="FIELD_CHAR">
            <annotation datatype="java.lang.Long" key="refid" value="704374636777"/>
          </ast>
        </ast>
      </ast>
      <ast col="0" id="704374636775" line="0" text="expression" type="EXPRESSION">
    </ast>
  </ast>

The refid annotation is somewhere else as you can see from the trimmed subtree: as 704374636768 is processed (type prog.kw_validate and parent.type prog.format_phrase and !isNote("ignore")), widref is calculated as: copy.parent.getPrevSibling() which is FORM_ITEM 704374636760. Anyway, that field none of its sub-nodes are not annotated with refid. The only node with this property in the region is 704374636771.

#8 Updated by Eric Faulhaber about 11 years ago

  • Tracker changed from Support to Bug

#9 Updated by Eric Faulhaber about 11 years ago

Is there anything left to do on this issue or can it be closed?

#10 Updated by Ovidiu Maxiniuc about 11 years ago

At this moment, with the exception of the cases where the expression from the string condition is not valid, I don't have any test-cases that do not work.

#11 Updated by Eric Faulhaber about 11 years ago

  • % Done changed from 0 to 100
  • Status changed from New to Closed

#12 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