Beispiel #1
0
 def interpret(self, context):
     value = self.expression.interpret(context)
     if value is not None:
         target = getTargetType(context, self.itype, self.mutable)
         if isinstance(value,
                       IntegerValue) and target == DecimalType.instance:
             value = DecimalValue(value.DecimalValue())
         elif isinstance(value,
                         DecimalValue) and target == IntegerType.instance:
             return IntegerValue(value.IntegerValue())
         elif target.isMoreSpecificThan(context, value.itype):
             value.itype = self.itype
     return value
Beispiel #2
0
 def interpret(self, context):
     value = self.expression.interpret(context)
     if value is not None and value != NullValue.instance:
         target = getTargetType(context, self.itype, self.mutable)
         if target != value.itype:
             if isinstance(value, IntegerValue) and target == DecimalType.instance:
                 value = DecimalValue(value.DecimalValue())
             elif isinstance(value, DecimalValue) and target == IntegerType.instance:
                 return IntegerValue(value.IntegerValue())
             elif value.itype.isAssignableFrom(context, target):
                 value.itype = self.itype
             elif not target.isAssignableFrom(context, value.itype):
                 raise SyntaxError("Cannot cast " + str(value.itype) + " to " + str(self.itype))
     return value