logo       

Nice/stdlib/nice/lang/inline ReferenceOp.java,1.8,1.9: msg#00013

Subject: Nice/stdlib/nice/lang/inline ReferenceOp.java,1.8,1.9
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26705/stdlib/nice/lang/inline

Modified Files:
        ReferenceOp.java 
Log Message:
Correctly compare possibly null values with primitive values by unwrapping
the possibly null value and performing a native comparison. Wrapping the
primitive value and performing reference comparison could return false even
with identical values. (fixes #1090679)


Index: ReferenceOp.java
===================================================================
RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/ReferenceOp.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ReferenceOp.java    8 Feb 2005 19:29:51 -0000       1.8
--- ReferenceOp.java    11 Feb 2005 01:39:36 -0000      1.9
***************
*** 48,51 ****
--- 48,56 ----
    {
      Expression[] args = exp.getArgs();
+     compile(args, comp, target);
+   }
+ 
+   void compile (Expression[] args, Compilation comp, Target target)
+   {
      CodeAttr code = comp.getCode();
      Target stack = Target.pushObject;
***************
*** 53,58 ****
      Label _end = new Label(code);
  
!     if (args[0] instanceof QuoteExp &&
!        ((QuoteExp)args[0]).getType() == Type.nullType)
      {
        args[1].compile(comp, stack);
--- 58,76 ----
      Label _end = new Label(code);
  
!     boolean prim0 = args[0].getType() instanceof PrimType;
!     boolean prim1 = args[1].getType() instanceof PrimType;
! 
!     if (prim1 && ! prim0)
!       {
!         compilePrimitive(false, args[0], args[1], comp);
!         return;
!       }
!     else if (prim0 && ! prim1)
!       {
!         compilePrimitive(true,  args[1], args[0], comp);
!         return;
!       }
!     else if (args[0] instanceof QuoteExp &&
!              ((QuoteExp)args[0]).getType() == Type.nullType)
      {
        args[1].compile(comp, stack);
***************
*** 61,65 ****
        else
        code.emitGotoIfNull(_else);
- 
      }
      else if (args[1] instanceof QuoteExp &&
--- 79,82 ----
***************
*** 71,75 ****
        else
        code.emitGotoIfNull(_else);
- 
      }
      else
--- 88,91 ----
***************
*** 93,96 ****
--- 109,141 ----
    }
  
+   private void compilePrimitive
+     (boolean primFirst, Expression nonPrimArg, Expression primArg,
+      Compilation comp)
+   {
+     CodeAttr code = comp.getCode();
+     Target stack = Target.pushObject;
+     Target primTarget = new StackTarget(primArg.getType());
+     boolean eq = kind == Eq;
+ 
+     if (primFirst)
+       primArg.compile(comp, primTarget);
+     nonPrimArg.compile(comp, stack);
+     code.emitDup();
+ 
+     code.emitIfNotNull();
+       primTarget.compileFromStack(comp, code.topType());
+       if (! primFirst)
+         primArg.compile(comp, primTarget);
+       code.emitIfEq();
+         code.emitPushBoolean(eq);
+       code.emitElse();
+         code.emitPushBoolean(!eq);
+       code.emitFi();
+     code.emitElse();
+       code.emitPop(primFirst ? 2 : 1);
+       code.emitPushBoolean(!eq);
+     code.emitFi();
+   }
+ 
    public void compileJump (Compilation comp, Expression[] args, Label to)
    {
***************
*** 98,102 ****
      Target stack = Target.pushObject;
  
!     if (args[0] instanceof QuoteExp &&
         ((QuoteExp)args[0]).getType() == Type.nullType)
      {
--- 143,156 ----
      Target stack = Target.pushObject;
  
!     boolean prim0 = args[0].getType() instanceof PrimType;
!     boolean prim1 = args[1].getType() instanceof PrimType;
! 
!     if (prim1 && ! prim0 || prim0 && ! prim1)
!       {
!         compile(args, comp, StackTarget.getInstance(Type.boolean_type));
!         code.emitGotoIfIntNeZero(to);
!       }
! 
!     else if (args[0] instanceof QuoteExp &&
         ((QuoteExp)args[0]).getType() == Type.nullType)
      {
***************
*** 151,155 ****
      Target stack = Target.pushObject;
  
!     if (args[0] instanceof QuoteExp &&
         ((QuoteExp)args[0]).getType() == Type.nullType)
      {
--- 205,218 ----
      Target stack = Target.pushObject;
  
!     boolean prim0 = args[0].getType() instanceof PrimType;
!     boolean prim1 = args[1].getType() instanceof PrimType;
! 
!     if (prim1 && ! prim0 || prim0 && ! prim1)
!       {
!         compile(args, comp, StackTarget.getInstance(Type.boolean_type));
!         code.emitGotoIfIntEqZero(to);
!       }
! 
!     else if (args[0] instanceof QuoteExp &&
         ((QuoteExp)args[0]).getType() == Type.nullType)
      {



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe