Nice/src/bossa/syntax typecheck.nice,1.125,1.126

Artem Gr Kozarezov <[email protected]>
Newsgroups gmane.comp.lang.nice.cvs
Message-ID <[email protected]>
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20664/src/bossa/syntax

Modified Files:
	typecheck.nice 
Log Message:
Nullness analisys on assignments is partially implemented (RFE 681385).

Index: typecheck.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v
retrieving revision 1.125
retrieving revision 1.126
diff -C2 -d -r1.125 -r1.126
*** typecheck.nice	22 Feb 2005 10:26:42 -0000	1.125
--- typecheck.nice	7 Mar 2005 08:16:53 -0000	1.126
***************
*** 52,55 ****
--- 52,70 ----
      e.value = e.value.resolveOverloading(to.getType());
      checkAssignment(to.getType(), e.value);
+     
+     // RFE 681385
+     // To debug in jdb use "stop at bossa.syntax.fun:LINE".
+     if( variable != null ){
+       let valueType = e.value.type, toType = to.type, varType = variable.type;
+       if( valueType != null && toType != null && varType != null ){
+         let toNotNull = isNotNull( toType );
+         let valueNotNull = isNotNull( valueType );
+         if( ! toNotNull && valueNotNull ){
+           //bossa.util.User.warning( e, e.toString() );
+           mlsub.typing.Monotype type = varType;
+           mlsub.typing.Monotype sureType = makeSure( type );
+           variable.setVarType( now: sureType, otherBranch: type, out: type );
+     } } }
+     
    }
    catch(mlsub.typing.TypingEx t){
***************
*** 417,424 ****
  void enterElse()
  {
!   while (levels.size() > 0 && levels.peek() == ifLevel * 2)
      {
!       levels.pop();
!       (MonoSymbol variable, mlsub.typing.Monotype baseType) = conditionalTypes.pop();
        variable.type = baseType;
      }
--- 432,443 ----
  void enterElse()
  {
!   // "out" (ifLevel * 2) and "otherBranch" (ifLevel * 2 + 1) records might be mixed in the stack,
!   // therefore we scan the tail of the stack while "level >= ifLevel * 2", ignoring "out" records.
!   for (int i = levels.size() - 1; i >= 0; i--)
      {
!       int level = levels.get(i);
!       if( level < ifLevel * 2 ) break;
!       if( level != ifLevel * 2 + 1 ) continue;
!       (MonoSymbol variable, mlsub.typing.Monotype baseType) = conditionalTypes.get(i);
        variable.type = baseType;
      }
***************
*** 426,435 ****
  
  void exitIf()
! { 
!   while (levels.size() > 0 && levels.peek() == ifLevel * 2 + 1)
      {
!       levels.pop();
        (MonoSymbol variable, mlsub.typing.Monotype baseType) = conditionalTypes.pop();
!       variable.type = baseType;
      }
    ifLevel--;
--- 445,457 ----
  
  void exitIf()
! {
!   // since "out" and "otherBranch" records might be mixed,
!   // we should pop everything which is "level >= ifLevel * 2",
!   // but ignore "otherBranch" (ifLevel * 2 + 1) records.
!   while (levels.size() > 0 && levels.peek() >= ifLevel * 2)
      {
!       int level = levels.pop();
        (MonoSymbol variable, mlsub.typing.Monotype baseType) = conditionalTypes.pop();
!       if( level == ifLevel * 2 ) variable.type = baseType;
      }
    ifLevel--;
***************
*** 438,442 ****
  void pushBranchType(MonoSymbol variable, mlsub.typing.Monotype baseType)
  {
!   levels.push(2 * ifLevel);
    conditionalTypes.push((variable, baseType));
  }
--- 460,464 ----
  void pushBranchType(MonoSymbol variable, mlsub.typing.Monotype baseType)
  {
!   levels.push(2 * ifLevel + 1);
    conditionalTypes.push((variable, baseType));
  }
***************
*** 444,448 ****
  void pushOuterType(MonoSymbol variable, mlsub.typing.Monotype baseType)
  {
!   levels.push(2 * ifLevel + 1);
    conditionalTypes.push((variable, baseType));
  }
--- 466,470 ----
  void pushOuterType(MonoSymbol variable, mlsub.typing.Monotype baseType)
  {
!   levels.push(2 * ifLevel);
    conditionalTypes.push((variable, baseType));
  }
***************
*** 451,455 ****
  {
    for (int i = 0; i < levels.size(); i++)
!     if (levels.get(i) % 2 == 1)
        {
  	(MonoSymbol v, mlsub.typing.Monotype t) = conditionalTypes.get(i);
--- 473,477 ----
  {
    for (int i = 0; i < levels.size(); i++)
!     if (levels.get(i) % 2 == 0)
        {
  	(MonoSymbol v, mlsub.typing.Monotype t) = conditionalTypes.get(i);
***************
*** 940,946 ****
  typecheck(TryStmt t)
  {
!   typecheck(t.body);
!   t.catches.foreach(ACatch c => typecheck(c.body));
!   typecheck(t.finallyBody);
  }
  
--- 962,975 ----
  typecheck(TryStmt t)
  {
!   enterBlock();
!   try{
!     typecheck( t.body );
!     enterElse();
!     for( ACatch c : t.catches ){
!       typecheck( c.body );
!       enterElse();
!     }
!     typecheck( t.finallyBody );
!   }finally{ exitIf(); }
  }
  
***************
*** 1066,1069 ****
--- 1095,1108 ----
  }
  
+ boolean isNotNull( mlsub.typing.Polytype type )
+ {
+   try{
+     checkNotNull( type ); // Will throw a TypingEx if the 'value' is not a sureTC.
+     return true;
+   }catch( mlsub.typing.TypingEx skip ){
+     return false;
+   }
+ }
+ 
  // Local Variables:
  // nice-xprogram: "../bin/nicec -d ../classes"



-------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.