use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class SizeOfExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final TTCN3Template templateBody = templateInstance.getTemplateBody();
// FIXME actually a bit more complex
if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
final IValue value = ((SpecificValue_Template) templateBody).getValue();
// FIXME implement support for cast
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(".sizeOf()");
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct 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.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class IsBoundExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final TTCN3Template template = templateInstance.getTemplateBody();
if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
final IValue value = ((SpecificValue_Template) template).getSpecificValue();
if (Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
final Reference reference = ((Referenced_Value) value).getReference();
if (reference != null) {
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment != null) {
switch(assignment.getAssignmentType()) {
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_MODULEPAR_TEMPLATE:
case A_EXT_FUNCTION_RTEMP:
case A_FUNCTION_RTEMP:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
return;
default:
break;
}
}
reference.generateCodeIsPresentBoundChosen(aData, expression, false, getOperationType(), null);
return;
}
} else {
// FIXME cast_needed case
value.generateCodeExpressionMandatory(aData, expression, true);
}
} else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
final Reference reference = ((Referenced_Template) template).getReference();
if (reference != null) {
reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
return;
}
} else {
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(".isBound()");
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class IsPresentExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final TTCN3Template template = templateInstance.getTemplateBody();
if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
final IValue value = ((SpecificValue_Template) template).getSpecificValue();
if (Value_type.REFERENCED_VALUE.equals(value.getValuetype())) {
final Reference reference = ((Referenced_Value) value).getReference();
if (reference != null) {
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment != null) {
switch(assignment.getAssignmentType()) {
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_MODULEPAR_TEMPLATE:
case A_EXT_FUNCTION_RTEMP:
case A_FUNCTION_RTEMP:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
return;
default:
break;
}
}
reference.generateCodeIsPresentBoundChosen(aData, expression, false, getOperationType(), null);
return;
}
} else {
// FIXME cast_needed case
value.generateCodeExpressionMandatory(aData, expression, true);
}
} else if (Template_type.TEMPLATE_REFD.equals(template.getTemplatetype())) {
final Reference reference = ((Referenced_Template) template).getReference();
if (reference != null) {
reference.generateCodeIsPresentBoundChosen(aData, expression, true, getOperationType(), null);
return;
}
} else {
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(".isPresent()");
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Value method generateCodeTmp.
/**
* as above
* @param aData the structure to put imports into and get temporal variable names from.
* @param source the source code to be updated
* @param init is the content to be generated before the current value
*/
public StringBuilder generateCodeTmp(final JavaGenData aData, final StringBuilder source, final StringBuilder init) {
final ExpressionStruct expression = new ExpressionStruct();
generateCodeExpressionMandatory(aData, expression, false);
if (expression.preamble.length() > 0 || expression.postamble.length() > 0) {
String typeName;
final String tempId = aData.getTemporaryVariableName();
final IType lastType = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (Type_type.TYPE_BOOL.equals(lastType.getTypetype())) {
typeName = "boolean";
} else {
typeName = myGovernor.getGenNameValue(aData, init, myScope);
}
init.append(MessageFormat.format("{0} {1};\n", typeName, tempId));
init.append("{\n");
if (expression.preamble.length() > 0) {
init.append(expression.preamble);
}
if (Type_type.TYPE_BOOL.equals(lastType.getTypetype()) && !returnsNative()) {
init.append(MessageFormat.format("{0} = TitanBoolean.getNative({1});\n", tempId, expression.expression));
} else {
init.append(MessageFormat.format("{0} = {1};\n", tempId, expression.expression));
}
if (expression.postamble.length() > 0) {
init.append(expression.postamble);
}
init.append("}\n");
source.append(tempId);
} else {
source.append(expression.expression);
}
return source;
}
Aggregations