| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.stoex.analyser.visitors; |
| 5 | |
| 6 | import de.uka.ipd.sdq.stoex.Expression; |
| 7 | import de.uka.ipd.sdq.stoex.PowerExpression; |
| 8 | |
| 9 | /** |
| 10 | * @author Steffen |
| 11 | * |
| 12 | */ |
| 13 | public class NonProbabilisticExpressionInferTypeVisitor extends |
| 14 | ExpressionInferTypeVisitor { |
| 15 | |
| 16 | /** |
| 17 | * |
| 18 | */ |
| 19 | public NonProbabilisticExpressionInferTypeVisitor() { |
| 20 | super(); |
| 21 | } |
| 22 | |
| 23 | @Override |
| 24 | public TypeEnum getType(Expression e) { |
| 25 | TypeEnum result = super.getType(e); |
| 26 | if (result == TypeEnum.INT_PMF) |
| 27 | result = TypeEnum.INT; |
| 28 | if (result == TypeEnum.DOUBLE_PMF || result == TypeEnum.DOUBLE_PDF) |
| 29 | result = TypeEnum.DOUBLE; |
| 30 | if (result == TypeEnum.ENUM_PMF) |
| 31 | result = TypeEnum.ENUM; |
| 32 | if (result == TypeEnum.BOOL_PMF) |
| 33 | result = TypeEnum.BOOL; |
| 34 | if (result == TypeEnum.ANY_PMF) |
| 35 | result = TypeEnum.ANY; |
| 36 | return result; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Result of a power expression so far only be of type DOUBLE, |
| 41 | * as the power operation is only allowed on NUMBERs, not PMFs. |
| 42 | */ |
| 43 | @Override |
| 44 | public Object casePowerExpression(PowerExpression expr) { |
| 45 | doSwitch(expr.getBase()); |
| 46 | doSwitch(expr.getExponent()); |
| 47 | |
| 48 | TypeEnum baseType = getType(expr.getBase()); |
| 49 | TypeEnum exponentType = getType(expr.getExponent()); |
| 50 | |
| 51 | if (baseType == TypeEnum.INT && exponentType == TypeEnum.INT) |
| 52 | getTypeAnnotation().put(expr, TypeEnum.INT); |
| 53 | else if (isNumeric(baseType) && isNumeric(exponentType)){ |
| 54 | getTypeAnnotation().put(expr, TypeEnum.DOUBLE); |
| 55 | } else |
| 56 | getTypeAnnotation().put(expr, TypeEnum.ANY); |
| 57 | return expr; |
| 58 | } |
| 59 | } |