Permalink
Browse files

jtrsrc: Assignment.java (processOutput): Fix outputFloatCast calls (add

check for target variable type to be primitive); add assertions to
CastExpression.outputFloatCast
  • Loading branch information...
1 parent c05918b commit 8feb4efb6d84513d6afbd613c9c12266c35e053c @ivmai committed Aug 25, 2012
Showing with 9 additions and 5 deletions.
  1. +6 −4 jtrsrc/com/ivmaisoft/jcgo/Assignment.java
  2. +3 −1 jtrsrc/com/ivmaisoft/jcgo/CastExpression.java
@@ -40,7 +40,7 @@
/**
* Grammar production for assignments (simple and compound).
- **
+ **
* Formats: LeftHandSide EQUALS AssignmentExpression LeftHandSide FLSHIFT_EQUALS
* AssignmentExpression LeftHandSide SHRIGHT_EQUALS AssignmentExpression
* LeftHandSide SHLEFT_EQUALS AssignmentExpression LeftHandSide XOR_EQUALS
@@ -504,7 +504,8 @@ void processOutput(OutputContext oc) {
t0.processOutput(oc);
} else if (rcvr2 > 0) {
t1.processOutput(oc);
- } else if (s2 >= Type.FLOAT && s0 < s2) {
+ } else if (s2 >= Type.FLOAT && s0 < s2
+ && s0 <= Type.FLOAT) {
if (s0 < Type.INT) {
oc.cPrint("(");
oc.cPrint(Type.cName[s0]);
@@ -570,7 +571,8 @@ void processOutput(OutputContext oc) {
}
}
if (rcvr3 > 0) {
- if (s2 >= Type.FLOAT && s0 < s2) {
+ if (s2 >= Type.FLOAT && s0 < s2
+ && s0 <= Type.FLOAT) {
if (s0 < Type.INT) {
oc.cPrint("(");
oc.cPrint(Type.cName[s0]);
@@ -799,7 +801,7 @@ void processOutput(OutputContext oc) {
}
}
} else {
- if (isString || (s2 >= Type.FLOAT && s0 < s2)
+ if (isString || (s2 >= Type.FLOAT && s0 < s2 && s0 <= Type.FLOAT)
|| sym == LexTerm.DIVIDE_EQUALS
|| sym == LexTerm.MOD_EQUALS
|| sym == LexTerm.FLSHIFT_EQUALS
@@ -40,7 +40,7 @@
/**
* Grammar production for an expression cast.
- **
+ **
* Formats: LPAREN Expression(Name) RPAREN UnaryExpressionNotPlusMinus LPAREN
* Expression(PrimitiveType) RPAREN UnaryExpression LPAREN
* Expression(TypeWithDims) RPAREN UnaryExpressionNotPlusMinus
@@ -278,6 +278,8 @@ int tokenCount() {
}
static void outputFloatCast(OutputContext oc, int s0, int s1) {
+ assertCond(s0 < Type.VOID);
+ assertCond(s1 < Type.VOID);
oc.cPrint(s1 > Type.FLOAT ? (s0 <= Type.INT ? "JCGO_JDOUBLE_TOJINT"
: s0 < Type.FLOAT ? "JCGO_JDOUBLE_TOJLONG"
: "JCGO_JDOUBLE_TOJFLOAT")

0 comments on commit 8feb4ef

Please sign in to comment.