use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class SubType method checkThisValue.
/**
* Checks if a given value is valid according to this sub-type.
*
* @param timestamp
* the time stamp of the actual semantic check cycle.
* @param value
* the value to be checked
*/
public void checkThisValue(final CompilationTimeStamp timestamp, final IValue value) {
if (getIsErroneous(timestamp) || (subtypeConstraint == null)) {
return;
}
if (value.getIsErroneous(timestamp)) {
return;
}
final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (last.getIsErroneous(timestamp)) {
return;
}
boolean isValid = true;
switch(last.getValuetype()) {
case INTEGER_VALUE:
if (subtypeType != SubType_type.ST_INTEGER) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(new IntegerLimit(((Integer_Value) last).getValueValue()));
break;
case REAL_VALUE:
if (subtypeType == SubType_type.ST_FLOAT) {
isValid = subtypeConstraint.isElement(((Real_Value) last).getValue());
break;
} else if (subtypeType == SubType_type.ST_INTEGER) {
final Real_Value real = (Real_Value) last;
if (real.isNegativeInfinity()) {
isValid = subtypeConstraint.isElement(IntegerLimit.MINIMUM);
break;
} else if (real.isPositiveInfinity()) {
isValid = subtypeConstraint.isElement(IntegerLimit.MAXIMUM);
break;
}
}
ErrorReporter.INTERNAL_ERROR();
return;
case BOOLEAN_VALUE:
if (subtypeType != SubType_type.ST_BOOLEAN) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Boolean_Value) last).getValue());
break;
case VERDICT_VALUE:
if (subtypeType != SubType_type.ST_VERDICTTYPE) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Verdict_Value) last).getValue());
break;
case BITSTRING_VALUE:
if (subtypeType != SubType_type.ST_BITSTRING) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Bitstring_Value) last).getValue());
break;
case HEXSTRING_VALUE:
if (subtypeType != SubType_type.ST_HEXSTRING) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Hexstring_Value) last).getValue());
break;
case OCTETSTRING_VALUE:
if (subtypeType != SubType_type.ST_OCTETSTRING) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((Octetstring_Value) last).getValue());
break;
case CHARSTRING_VALUE:
switch(subtypeType) {
case ST_CHARSTRING:
isValid = subtypeConstraint.isElement(((Charstring_Value) last).getValue());
break;
case ST_UNIVERSAL_CHARSTRING:
isValid = subtypeConstraint.isElement(new UniversalCharstring(((Charstring_Value) last).getValue()));
break;
default:
ErrorReporter.INTERNAL_ERROR();
return;
}
break;
case UNIVERSALCHARSTRING_VALUE:
if (subtypeType != SubType_type.ST_UNIVERSAL_CHARSTRING) {
ErrorReporter.INTERNAL_ERROR();
return;
}
isValid = subtypeConstraint.isElement(((UniversalCharstring_Value) last).getValue());
break;
case SEQUENCEOF_VALUE:
case SETOF_VALUE:
case OBJECTID_VALUE:
case ENUMERATED_VALUE:
case CHOICE_VALUE:
case SEQUENCE_VALUE:
case SET_VALUE:
case FUNCTION_REFERENCE_VALUE:
case ALTSTEP_REFERENCE_VALUE:
case TESTCASE_REFERENCE_VALUE:
if (value.isUnfoldable(timestamp)) {
return;
}
isValid = subtypeConstraint.isElement(last);
break;
default:
return;
}
if (!isValid) {
value.getLocation().reportSemanticError(MessageFormat.format("{0} is not a valid value for type `{1}'' which has subtype {2}", last.createStringRepresentation(), myOwner.getTypename(), subtypeConstraint.toString()));
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class DecodeBase64Expression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
if (value == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp)) {
return lastValue;
}
if (isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last.getValuetype()) {
case CHARSTRING_VALUE:
final String tempBitstring = ((Charstring_Value) last).getValue();
lastValue = new Octetstring_Value(calculateValue(tempBitstring));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class Bit2OctExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
if (value == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp)) {
return lastValue;
}
if (isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last.getValuetype()) {
case BITSTRING_VALUE:
final String tempBitstring = ((Bitstring_Value) last).getValue();
lastValue = new Octetstring_Value(bit2oct(tempBitstring));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class Char2OctExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
if (value == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp)) {
return lastValue;
}
if (isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last.getValuetype()) {
case CHARSTRING_VALUE:
final String string = ((Charstring_Value) last).getValue();
final CharstringExtractor cs = new CharstringExtractor(string);
lastValue = new Octetstring_Value(char2oct(cs.getExtractedString()));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Function_Writer method writeAssignmentStatement.
// updated
public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
StringBuilder functionString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if ((specValTemplate.getSpecificValue() instanceof Bitstring_Value) || (specValTemplate.getSpecificValue() instanceof Integer_Value) || (specValTemplate.getSpecificValue() instanceof Charstring_Value) || (specValTemplate.getSpecificValue() instanceof Boolean_Value) || (specValTemplate.getSpecificValue() instanceof Octetstring_Value) || (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) || (specValTemplate.getSpecificValue() instanceof Referenced_Value) || (specValTemplate.getSpecificValue() instanceof And4bExpression) || (specValTemplate.getSpecificValue() instanceof Xor4bExpression) || (specValTemplate.getSpecificValue() instanceof Not4bExpression) || (specValTemplate.getSpecificValue() instanceof Or4bExpression) || (specValTemplate.getSpecificValue() instanceof ShiftLeftExpression) || (specValTemplate.getSpecificValue() instanceof ShiftRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateRightExpression) || (specValTemplate.getSpecificValue() instanceof RotateLeftExpression) || (specValTemplate.getSpecificValue() instanceof StringConcatenationExpression) || (specValTemplate.getSpecificValue() instanceof AddExpression) || (specValTemplate.getSpecificValue() instanceof SubstractExpression) || (specValTemplate.getSpecificValue() instanceof MultiplyExpression) || (specValTemplate.getSpecificValue() instanceof DivideExpression) || (specValTemplate.getSpecificValue() instanceof ModuloExpression) || (specValTemplate.getSpecificValue() instanceof RemainderExpression) || (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression)) {
// TODO assignments for indexed bitstrings
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
}
/*StringBuilder functionString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if (specValTemplate.getSpecificValue() instanceof Bitstring_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BITSTRING(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Integer_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Charstring_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new CHARSTRING(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Boolean_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new BOOLEAN("
+ functionAssignValues.get(assignCounter) + ");\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Undefined_LowerIdentifier_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof Referenced_Value) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "="
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if ((specValTemplate.getSpecificValue() instanceof AddExpression)
|| (specValTemplate.getSpecificValue() instanceof SubstractExpression)
|| (specValTemplate.getSpecificValue() instanceof MultiplyExpression)
|| (specValTemplate.getSpecificValue() instanceof DivideExpression)
|| (specValTemplate.getSpecificValue() instanceof ModuloExpression)
|| (specValTemplate.getSpecificValue() instanceof RemainderExpression)) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter)
+ functionAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
if (specValTemplate.getSpecificValue() instanceof UnaryMinusExpression) {
functionString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
functionString.append(functionAssignIdentifiers.get(assignCounter) + "=new INTEGER(\""
+ functionAssignValues.get(assignCounter) + "\");\r\n");
// TODO: add logging here
}
}
*/
return functionString.toString();
}
Aggregations