Re: [Jastadd] [Q] unknown type ?

From: Na, Hyunik <hina_at_kaist.ac.kr>
Date: Thu, 22 Dec 2011 10:58:51 +0900

> -----Original Message-----
> From: jastadd-bounces_at_cs.lth.se [mailto:jastadd-bounces_at_cs.lth.se] On
> Behalf Of Jesper Oqvist
> Sent: Wednesday, December 21, 2011 8:38 PM
> To: jastadd_at_cs.lth.se
> Subject: Re: [Jastadd] [Q] unknown type ?
>
> Hello Hyunik,
> I think the reason AssignExpr.sourceType() is the unkown type unless
> it's a primitive type is to handle arithmetic assign expressions such as
> AssignAddExpr with reference operands. The AssignSimpleExpr has the
> following equation for sourceType:
>
> syn TypeDecl AssignSimpleExpr.sourceType() = getSource().type();
>
> which always returns the actual type of the source operand.

Aha! I missed this line.

Given this, however, it still appears to me that the
AssignSimpleExpr.typeCheck() should be as follows:

    public void AssignSimpleExpr.typeCheck() {
      if(!getDest().isVariable())
        error("left hand side is not a variable");
      else if ( sourceType().isUnknown() )
        error( "source type is unknown" );
      else if( !sourceType().assignConversionTo(getDest().type(),
getSource()) )
        error( "can not assign " + getDest() + " of type " +
getDest().type().typeName() +
                 " a value of type " + sourceType().typeName() );
    }

Am I missing something?


> AssignSimpleExpr, I think, is the only assignment expression that works
> with reference operands.
>
> /Jesper
>
> On 12/21/2011 10:36 AM, Na, Hyunik wrote:
> > Hello JastAddJ developers,
> >
> > In Java1.4Frontend/TypeCheck.jrag, the following line exists:
> >
> > syn TypeDecl AssignExpr.sourceType() =
> > getSource().type().isPrimitive() ? getSource().type() : unknownType();
> >
> > which means the source type of an assign expression is the unknown type
> > unless it is a primitive type.
> > Why should it be?
> >
> > and the AssignSimpleExpr.typeCheck() is written as follows:
> >
> > public void AssignSimpleExpr.typeCheck() {
> > if(!getDest().isVariable())
> > error("left hand side is not a variable");
> > else if(!sourceType().assignConversionTo(getDest().type(),
> getSource())
> > && !sourceType().isUnknown())
> > error("can not assign " + getDest() + " of type " +
> > getDest().type().typeName() +
> > " a value of type " + sourceType().typeName());
> > }
> >
> > This means that, if the source type is unknown, it is not an error even
> when
> > the source type is not assign-compatible
> > with the destination type for a simple assignment.
> > It is hard for me to figure out what's going on here.
> >
> > Why do you introduce the unknown type during the type checking process?
> >
> >
> > - Hyunik
> >
> > _______________________________________________
> > JastAdd mailing list
> > JastAdd_at_cs.lth.se
> > https://mail1.cs.lth.se/cgi-bin/mailman/listinfo/jastadd
> >
>
> _______________________________________________
> JastAdd mailing list
> JastAdd_at_cs.lth.se
> https://mail1.cs.lth.se/cgi-bin/mailman/listinfo/jastadd
Received on Thu Dec 22 2011 - 02:59:08 CET

This archive was generated by hypermail 2.3.0 : Wed Apr 16 2014 - 17:19:06 CEST