package com.sap.finex.interpreter.expressions;
import structure.Association;
import structure.Field;
import structure.FinexClass;
import structure.Type;
import behavior.actions.Statement;
import behavior.expressions.Expression;
import behavior.expressions.literals.DateLiteral;
import behavior.functions.NativeImpl;
import behavior.functions.SignatureImplementation;
import com.sap.finex.interpreter.FinexInterpreter;
import com.sap.finex.interpreter.FinexStackFrame;
import com.sap.finex.interpreter.objects.FinexNativeObject;
import com.sap.runlet.abstractinterpreter.Interpreter;
import com.sap.runlet.abstractinterpreter.util.DateParser;
import com.sap.runlet.abstractinterpreter.util.InvalidDateException;
public class DateLiteralInterpreter implements Interpreter<DateLiteral, FinexClass, Type, FinexClass,
Association, Field, Statement, Expression, SignatureImplementation, FinexStackFrame, NativeImpl, FinexInterpreter> {
private DateLiteral literal;
public DateLiteralInterpreter(DateLiteral literal) {
this.literal = literal;
}
@Override
public FinexNativeObject evaluate(FinexInterpreter interpreter) {
// a native object is used to encode the number value
try {
return new FinexNativeObject((FinexClass) literal.getType(), DateParser.parse(literal.getLiteral()),
interpreter.getDefaultSnapshot(), interpreter);
} catch (InvalidDateException e) {
throw new RuntimeException("Date "+literal.getLiteral()+" could not be parsed although lexer considered it an ISO date", e);
}
}
}