[Nice-commit] Nice/src/bossa/syntax Pattern.java,1.43,1.44 MethodBodyDefinition.java,1.114,1.115
Brought to you by:
bonniot
|
From: <ar...@us...> - 2003-04-01 20:25:39
|
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv10514/F:/nice/src/bossa/syntax
Modified Files:
Pattern.java MethodBodyDefinition.java
Log Message:
@type patterns are automatic replaced by at any patterns if the type is equal to the type of the declaration.
All @type and #type patterns where type is a primitive type after the previous replacement will yield an error because instanceof a primitve type make no sense (yet).
An exception is made for boolean, so instanceof boolean is made to work now.
Index: Pattern.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** Pattern.java 29 Mar 2003 19:26:23 -0000 1.43
--- Pattern.java 1 Apr 2003 20:24:57 -0000 1.44
***************
*** 369,374 ****
if (exactlyAt)
return Typing.testRigidLeq(tag, tc) && Typing.testRigidLeq(tc, tag);
! else
! return Typing.testRigidLeq(tag, tc);
}
--- 369,374 ----
if (exactlyAt)
return Typing.testRigidLeq(tag, tc) && Typing.testRigidLeq(tc, tag);
!
! return Typing.testRigidLeq(tag, tc);
}
***************
*** 377,394 ****
if (atAny())
return true;
! if (atIntValue)
! return this.value == val;
! return atPrimTypeFitting(val);
}
! //TODO: call this from methodbodydefition when the pattern has the same
! //type as the the methoddeclaration
! public void setAtAny()
{
// only set it to atAny if it's a @type pattern
! if (atValue == null && !exactlyAt && !atIntValue)
tc = null;
- }
/****************************************************************
* Printing
--- 377,401 ----
if (atAny())
return true;
!
! return atIntValue && this.value == val;
}
! public void setDomainEq(boolean equal)
{
// only set it to atAny if it's a @type pattern
! if (equal && atValue == null && !exactlyAt && !atIntValue)
tc = null;
+ // don't allow primitive types(except boolean) in @type and #type patterns
+ if (!equal && !atBool() && !atIntValue && (
+ tc == PrimitiveType.longTC ||
+ tc == PrimitiveType.intTC ||
+ tc == PrimitiveType.shortTC ||
+ tc == PrimitiveType.charTC ||
+ tc == PrimitiveType.byteTC) )
+ User.error(typeConstructor,"A pattern cannot have a primitive type that is different from the declararion.");
+
+ }
+
/****************************************************************
* Printing
***************
*** 602,612 ****
public boolean atFalse() {
return atBool() && atValue.toString().equals("false");
- }
- public boolean atPrimTypeFitting(long val){
- return ( tc == PrimitiveType.longTC ) ||
- (tc == PrimitiveType.intTC && val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE) ||
- (tc == PrimitiveType.shortTC && val >= Short.MIN_VALUE && val <= Short.MAX_VALUE) ||
- (tc == PrimitiveType.charTC && val >= Character.MIN_VALUE && val <= Character.MAX_VALUE) ||
- (tc == PrimitiveType.byteTC && val >= Byte.MIN_VALUE && val <= Byte.MAX_VALUE);
}
--- 609,612 ----
Index: MethodBodyDefinition.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodBodyDefinition.java,v
retrieving revision 1.114
retrieving revision 1.115
diff -C2 -d -r1.114 -r1.115
*** MethodBodyDefinition.java 14 Mar 2003 00:55:26 -0000 1.114
--- MethodBodyDefinition.java 1 Apr 2003 20:25:01 -0000 1.115
***************
*** 409,412 ****
--- 409,420 ----
}
+ for(int n = 0; n < formals.length; n++)
+ {
+ TypeConstructor tc = Types.rawType(domain[n]).head();
+ if (tc != null && formals[n].tc != null)
+ formals[n].setDomainEq(Typing.testRigidLeq(tc, formals[n].tc));
+
+ }
+
Node.currentFunction = this;
if (insideClass)
|