use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class Def_Testcase_Writer method writeAssignmentStatement.
public String writeAssignmentStatement(Assignment_Statement tc_assignStatement) {
StringBuilder testCaseString = new StringBuilder("");
if (tc_assignStatement.getTemplate() instanceof SpecificValue_Template) {
SpecificValue_Template specValTemplate = (SpecificValue_Template) tc_assignStatement.getTemplate();
if (specValTemplate.getSpecificValue() instanceof ComponentCreateExpression) {
ComponentCreateExpression componenetCreateExp = (ComponentCreateExpression) specValTemplate.getSpecificValue();
createCounter++;
logCreateCounter++;
int logSizeValue = 1;
while (tcCreateCounter.get(logCreateCounter).equals(String.valueOf(createCounter))) {
logCreateCounter++;
logSizeValue++;
if (tcCreateCounter.size() == (logCreateCounter)) {
break;
}
}
String[] logValues = new String[logSizeValue];
int logWriteCounter = 0;
testCaseString.append("rownum=" + componenetCreateExp.getLocation().getLine() + ";\r\n");
if (tcAssignIdentifiers.get(assignCounter).endsWith("=")) {
tcAssignIdentifiers.set(assignCounter, tcAssignIdentifiers.get(assignCounter).substring(0, tcAssignIdentifiers.get(assignCounter).length() - 1));
}
testCaseString.append("hc.create(" + "\"" + tcAssignIdentifiers.get(assignCounter) + "\"");
logValues[logWriteCounter] = tcAssignIdentifiers.get(assignCounter);
currentCounterValue++;
// assignCounter++;
logWriteCounter++;
while (tcCreateCounter.get(currentCounterValue).equals(String.valueOf(createCounter))) {
testCaseString.append(",\"" + tcCreateValues.get(currentCounterValue) + "\"");
logValues[logWriteCounter] = tcCreateValues.get(currentCounterValue);
logWriteCounter++;
currentCounterValue++;
if (tcCreateCounter.size() == (currentCounterValue)) {
break;
}
}
testCaseString.append("); " + "\r\n");
testCaseString.append("TTCN3Logger.writeLog(\"mtc\", \"PARALLEL\", sourcefilename, rownum, \"testcase\", \"" + nodeName + "\", \"Starting PTC " + logValues[0] + " type " + logValues[1] + " on " + logValues[2] + "\", false);" + "\r\n");
} else 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
testCaseString.append("rownum=" + specValTemplate.getLocation().getLine() + ";\r\n");
testCaseString.append(tcAssignIdentifiers.get(assignCounter) + tcAssignValues.get(assignCounter) + ";\r\n");
// TODO: add logging here
}
}
return testCaseString.toString();
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class Unichar2OctExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
// TODO: reimplement if needed
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) || isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last.getValuetype()) {
case UNIVERSALCHARSTRING_VALUE:
{
final UniversalCharstring string = ((UniversalCharstring_Value) last).getValue();
final UniversalChar uchar = string.get(0);
final byte[] bytes = new byte[] { (byte) uchar.cell() };
lastValue = new Octetstring_Value(new String(bytes));
break;
}
default:
return this;
}
lastValue.copyGeneralProperties(this);
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class ReplaceExpression 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 (templateInstance1 == null || value2 == null || value3 == null || templateInstance4 == null) {
setIsErroneous(true);
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp)) {
return lastValue;
}
if (isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
ITTCN3Template temp = templateInstance1.getTemplateBody();
final IValue value1 = ((SpecificValue_Template) temp).getSpecificValue();
final IValue v1 = value1.getValueRefdLast(timestamp, referenceChain);
final IValue v2 = value2.getValueRefdLast(timestamp, referenceChain);
final IValue v3 = value3.getValueRefdLast(timestamp, referenceChain);
temp = templateInstance4.getTemplateBody();
final IValue value4 = ((SpecificValue_Template) temp).getSpecificValue();
final IValue v4 = value4.getValueRefdLast(timestamp, referenceChain);
final Value_type vt = v1.getValuetype();
final int index = ((Integer_Value) v2).intValue();
final int len = ((Integer_Value) v3).intValue();
switch(vt) {
case BITSTRING_VALUE:
{
final String v1Str = ((Bitstring_Value) v1).getValue();
final String v4Str = ((Bitstring_Value) v4).getValue();
String result = v1Str.substring(0, index);
result = result.concat(v4Str);
result = result.concat(v1Str.substring(index + len));
lastValue = new Bitstring_Value(result);
lastValue.copyGeneralProperties(this);
break;
}
case HEXSTRING_VALUE:
{
final String v1Str = ((Hexstring_Value) v1).getValue();
final String v4Str = ((Hexstring_Value) v4).getValue();
String result = v1Str.substring(0, index);
result = result.concat(v4Str);
result = result.concat(v1Str.substring(index + len));
lastValue = new Hexstring_Value(result);
lastValue.copyGeneralProperties(this);
break;
}
case OCTETSTRING_VALUE:
{
final String v1Str = ((Octetstring_Value) v1).getValue();
final String v4Str = ((Octetstring_Value) v4).getValue();
String result = v1Str.substring(0, index * 2);
result = result.concat(v4Str);
result = result.concat(v1Str.substring((index + len) * 2));
lastValue = new Octetstring_Value(result);
lastValue.copyGeneralProperties(this);
break;
}
case CHARSTRING_VALUE:
{
final String v1Str = ((Charstring_Value) v1).getValue();
final String v4Str = ((Charstring_Value) v4).getValue();
String result = v1Str.substring(0, index);
result = result.concat(v4Str);
result = result.concat(v1Str.substring(index + len));
lastValue = new Charstring_Value(result);
lastValue.copyGeneralProperties(this);
break;
}
case UNIVERSALCHARSTRING_VALUE:
{
final UniversalCharstring v1Str = ((UniversalCharstring_Value) v1).getValue();
final UniversalCharstring v4Str = ((UniversalCharstring_Value) v4).getValue();
final UniversalCharstring result = v1Str.substring(0, index);
// This append() is not like concat().
result.append(v4Str);
result.append(v1Str.substring(index + len));
lastValue = new UniversalCharstring_Value(result);
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 RotateLeftExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
Type_type tempType1 = null;
Type_type tempType2 = null;
long valueSize = 0;
long rotationSize = 0;
IValue tempValue;
if (value1 != null) {
value1.setLoweridToReference(timestamp);
tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
switch(tempType1) {
case TYPE_BITSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.BITSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Bitstring_Value) tempValue).getValueLength();
}
break;
case TYPE_HEXSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Hexstring_Value) tempValue).getValueLength();
}
break;
case TYPE_OCTETSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Octetstring_Value) tempValue).getValueLength();
}
break;
case TYPE_CHARSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.CHARSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Charstring_Value) tempValue).getValueLength();
}
break;
case TYPE_UCHARSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((UniversalCharstring_Value) tempValue).getValueLength();
}
break;
case TYPE_SET_OF:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
tempValue = tempValue.setValuetype(timestamp, Value_type.SETOF_VALUE);
}
if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((SetOf_Value) tempValue).getNofComponents();
}
break;
case TYPE_SEQUENCE_OF:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((SequenceOf_Value) tempValue).getNofComponents();
} else if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((SetOf_Value) tempValue).getNofComponents();
}
break;
case TYPE_ARRAY:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
tempValue = tempValue.setValuetype(timestamp, Value_type.ARRAY_VALUE);
}
if (Value_type.ARRAY_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Array_Value) tempValue).getNofComponents();
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(FIRSTOPERANDERROR);
setIsErroneous(true);
break;
}
}
if (value2 != null) {
value2.setLoweridToReference(timestamp);
tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
switch(tempType2) {
case TYPE_INTEGER:
tempValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.INTEGER_VALUE.equals(tempValue.getValuetype()) && !getIsErroneous(timestamp)) {
if (!((Integer_Value) tempValue).isNative()) {
value2.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERSECONDOPERANDERROR, ((Integer_Value) tempValue).getValueValue()));
setIsErroneous(true);
break;
}
rotationSize = ((Integer_Value) tempValue).getValue();
if (value1 != null && !value1.isUnfoldable(timestamp)) {
final String severtiy = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINCORRECTSHIFTROTATESIZE, GeneralConstants.WARNING, null);
if (valueSize == 0 || valueSize == 1) {
location.reportConfigurableSemanticProblem(severtiy, EFFECTLESSROTATION);
} else if (rotationSize < 0) {
location.reportConfigurableSemanticProblem(severtiy, NEGATIVEROTATEPROBLEM);
} else if (rotationSize == 0) {
location.reportConfigurableSemanticProblem(severtiy, ZEROROTATEPROBLEM);
} else if (rotationSize > valueSize) {
location.reportConfigurableSemanticProblem(severtiy, MessageFormat.format(TOOBIGROTATEPROBLEM, valueSize, rotationSize, rotationSize % valueSize));
}
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(SECONDOPERANDERROR);
setIsErroneous(true);
break;
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value in project titan.EclipsePlug-ins by eclipse.
the class RotateRightExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
Type_type tempType1 = null;
Type_type tempType2 = null;
long valueSize = 0;
long rotationSize = 0;
IValue tempValue;
if (value1 != null) {
value1.setLoweridToReference(timestamp);
tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
switch(tempType1) {
case TYPE_BITSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.BITSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Bitstring_Value) tempValue).getValueLength();
}
break;
case TYPE_HEXSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Hexstring_Value) tempValue).getValueLength();
}
break;
case TYPE_OCTETSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Octetstring_Value) tempValue).getValueLength();
}
break;
case TYPE_CHARSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.CHARSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Charstring_Value) tempValue).getValueLength();
}
break;
case TYPE_UCHARSTRING:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((UniversalCharstring_Value) tempValue).getValueLength();
}
break;
case TYPE_SET_OF:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
tempValue = tempValue.setValuetype(timestamp, Value_type.SETOF_VALUE);
}
if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((SetOf_Value) tempValue).getNofComponents();
}
break;
case TYPE_SEQUENCE_OF:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((SequenceOf_Value) tempValue).getNofComponents();
} else if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((SetOf_Value) tempValue).getNofComponents();
}
break;
case TYPE_ARRAY:
tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
tempValue = tempValue.setValuetype(timestamp, Value_type.ARRAY_VALUE);
}
if (Value_type.ARRAY_VALUE.equals(tempValue.getValuetype())) {
valueSize = ((Array_Value) tempValue).getNofComponents();
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(FIRSTOPERANDERROR);
setIsErroneous(true);
break;
}
}
if (value2 != null) {
value2.setLoweridToReference(timestamp);
tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
switch(tempType2) {
case TYPE_INTEGER:
tempValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (Value_type.INTEGER_VALUE.equals(tempValue.getValuetype()) && !getIsErroneous(timestamp)) {
if (!((Integer_Value) tempValue).isNative()) {
value2.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERSECONDOPERANDERROR, ((Integer_Value) tempValue).getValueValue()));
setIsErroneous(true);
break;
}
rotationSize = ((Integer_Value) tempValue).getValue();
if (value1 != null && !value1.isUnfoldable(timestamp)) {
final String severity = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINCORRECTSHIFTROTATESIZE, GeneralConstants.WARNING, null);
if (valueSize == 0 || valueSize == 1) {
location.reportConfigurableSemanticProblem(severity, EFFECTLESSROTATION);
} else if (rotationSize < 0) {
location.reportConfigurableSemanticProblem(severity, NEGATIVEROTATEPROBLEM);
} else if (rotationSize == 0) {
location.reportConfigurableSemanticProblem(severity, ZEROROTATEPROBLEM);
} else if (rotationSize > valueSize) {
location.reportConfigurableSemanticProblem(severity, MessageFormat.format(TOOBIGROTATEPROBLEM, valueSize, rotationSize, rotationSize % valueSize));
}
}
}
break;
case TYPE_UNDEFINED:
setIsErroneous(true);
break;
default:
location.reportSemanticError(SECONDOPERANDERROR);
setIsErroneous(true);
break;
}
}
}
Aggregations