use of org.eclipse.titan.designer.AST.IType.Type_type in project titan.EclipsePlug-ins by eclipse.
the class Str2IntExpression 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) {
if (value == null) {
return;
}
value.setLoweridToReference(timestamp);
final Type_type tempType = value.getExpressionReturntype(timestamp, expectedValue);
switch(tempType) {
case TYPE_CHARSTRING:
final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last.isUnfoldable(timestamp)) {
String string = ((Charstring_Value) last).getValue();
string = string.trim();
if (!string.isEmpty() && string.charAt(0) == '+') {
string = string.substring(1);
}
try {
new Integer_Value(string);
} catch (NumberFormatException e) {
// The exception is thrown by BigInteger
// not Integer_Value.
value.getLocation().reportSemanticError(OPERANDERROR2);
}
}
return;
case TYPE_UNDEFINED:
setIsErroneous(true);
return;
default:
if (!isErroneous) {
location.reportSemanticError(OPERANDERROR1);
setIsErroneous(true);
}
return;
}
}
use of org.eclipse.titan.designer.AST.IType.Type_type in project titan.EclipsePlug-ins by eclipse.
the class StringConcatenationExpression method getExpressionReturntype.
@Override
public /**
* {@inheritDoc}
*/
Type_type getExpressionReturntype(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
final IValue last = getValueRefdLast(timestamp, expectedValue, null);
if (last == null || value1 == null || value2 == null) {
return Type_type.TYPE_UNDEFINED;
}
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
Type_type tempType;
if (last == this) {
// not good, but in case of recursive call this is the
// only way out.
value1.setLoweridToReference(timestamp);
tempType = value1.getExpressionReturntype(timestamp, expectedValue);
if (!Type_type.TYPE_UCHARSTRING.equals(tempType)) {
value2.setLoweridToReference(timestamp);
tempType = value2.getExpressionReturntype(timestamp, expectedValue);
}
} else {
last.setLoweridToReference(timestamp);
tempType = last.getExpressionReturntype(timestamp, expectedValue);
}
switch(tempType) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_SET_OF:
case TYPE_SEQUENCE_OF:
return tempType;
case TYPE_UNDEFINED:
return tempType;
default:
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
}
use of org.eclipse.titan.designer.AST.IType.Type_type in project titan.EclipsePlug-ins by eclipse.
the class SubstrExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
if (lastValue != null && lastValue != this) {
lastValue.generateCodeExpression(aData, expression, true);
return;
}
final IValue lastValue2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
final IValue lastValue3 = value3.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
// TODO handle the needs conversion case
final Type_type expressionType = templateInstance1.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
switch(expressionType) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
{
aData.addCommonLibraryImport("AdditionalFunctions");
expression.expression.append("AdditionalFunctions.subString( ");
final ITTCN3Template temp = templateInstance1.getTemplateBody();
if (temp.isValue(CompilationTimeStamp.getBaseTimestamp())) {
final IValue value = temp.getValue();
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(", ");
if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
lastValue2.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue2).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
lastValue3.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue3).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(')');
break;
}
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(".substr( ");
if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
lastValue2.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue2).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
lastValue3.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue3).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(')');
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
break;
}
}
use of org.eclipse.titan.designer.AST.IType.Type_type in project titan.EclipsePlug-ins by eclipse.
the class SubstrExpression method isUnfoldable.
@Override
public /**
* {@inheritDoc}
*/
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (templateInstance1 == null || value2 == null || value3 == null || getIsErroneous(timestamp)) {
return true;
}
ITTCN3Template template = templateInstance1.getTemplateBody();
if (template == null || !Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
return true;
}
final IValue value1 = ((SpecificValue_Template) template).getSpecificValue();
if (value1 == null) {
return true;
}
template = template.setLoweridToReference(timestamp);
final Type_type tempType = template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
switch(tempType) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
break;
default:
return true;
}
return value1.isUnfoldable(timestamp, expectedValue, referenceChain) || value2.isUnfoldable(timestamp, expectedValue, referenceChain) || value3.isUnfoldable(timestamp, expectedValue, referenceChain);
}
use of org.eclipse.titan.designer.AST.IType.Type_type in project titan.EclipsePlug-ins by eclipse.
the class SubstrExpression method getExpressionReturntype.
@Override
public /**
* {@inheritDoc}
*/
Type_type getExpressionReturntype(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
final IValue last = getValueRefdLast(timestamp, expectedValue, null);
if (last == null || templateInstance1 == null) {
return Type_type.TYPE_UNDEFINED;
}
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
final ITTCN3Template template = templateInstance1.getTemplateBody().setLoweridToReference(timestamp);
final Type_type tempType = template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
switch(tempType) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_SET_OF:
case TYPE_SEQUENCE_OF:
return tempType;
case TYPE_UNDEFINED:
return tempType;
default:
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
}
Aggregations