use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class DecvalueUnicharExpression method checkExpressionOperand2.
/**
* Checks the 2nd operand
* out any_type
* @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 checkExpressionOperand2(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (reference1 == null) {
setIsErroneous(true);
return;
}
final Assignment temporalAssignment = reference2.getRefdAssignment(timestamp, true);
if (temporalAssignment == null) {
setIsErroneous(true);
return;
}
IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference2, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (temporalType == null) {
setIsErroneous(true);
return;
}
temporalType = temporalType.getTypeRefdLast(timestamp);
switch(temporalType.getTypetype()) {
case TYPE_UNDEFINED:
case TYPE_NULL:
case TYPE_REFERENCED:
case TYPE_VERDICT:
case TYPE_PORT:
case TYPE_COMPONENT:
case TYPE_DEFAULT:
case TYPE_SIGNATURE:
case TYPE_FUNCTION:
case TYPE_ALTSTEP:
case TYPE_TESTCASE:
reference2.getLocation().reportSemanticError(OPERAND2_ERROR1);
setIsErroneous(true);
break;
default:
break;
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class DecvalueUnicharExpression method checkExpressionOperand1.
/**
* Checks the 1st operand
* inout universal charstring
* @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 checkExpressionOperand1(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (reference1 == null) {
setIsErroneous(true);
return;
}
final Assignment temporalAssignment = reference1.getRefdAssignment(timestamp, true);
if (temporalAssignment == null) {
setIsErroneous(true);
return;
}
switch(temporalAssignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_TEMPLATE:
reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR2, temporalAssignment.getAssignmentName()));
setIsErroneous(true);
break;
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
break;
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
final Referenced_Template template = new Referenced_Template(reference1);
template.setMyScope(getMyScope());
template.setFullNameParent(new BridgingNamedNode(this, ".<operand>"));
final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
if (!Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype()) && last != template) {
reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR3, last.getTemplateTypeName()));
setIsErroneous(true);
return;
}
break;
}
default:
reference1.getLocation().reportSemanticError(MessageFormat.format(OPERAND1_ERROR4, temporalAssignment.getAssignmentName()));
setIsErroneous(true);
return;
}
final IType temporalType = temporalAssignment.getType(timestamp).getFieldType(timestamp, reference1, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (temporalType == null) {
setIsErroneous(true);
return;
}
final Type_type type_type = temporalType.getTypeRefdLast(timestamp).getTypetype();
if (type_type != Type_type.TYPE_UCHARSTRING) {
if (!isErroneous) {
location.reportSemanticError(OPERAND1_ERROR1);
setIsErroneous(true);
}
return;
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class EncodeExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
aData.addBuiltinTypeImport("TitanOctetString");
aData.addCommonLibraryImport("AdditionalFunctions");
final boolean isValue = templateInstance.getTemplateBody().isValue(CompilationTimeStamp.getBaseTimestamp());
final ExpressionStruct expression2 = new ExpressionStruct();
if (isValue) {
templateInstance.getTemplateBody().getValue().generateCodeExpressionMandatory(aData, expression2, true);
} else {
templateInstance.generateCode(aData, expression2, Restriction_type.TR_NONE);
}
final Scope scope = templateInstance.getTemplateBody().getMyScope();
final IType governor = templateInstance.getTemplateBody().getMyGovernor();
if (expression2.preamble.length() > 0) {
expression.postamble.append(expression2.preamble);
}
final ExpressionStruct expression3 = new ExpressionStruct();
// FIXME handle third parameter
expression3.expression.append(MessageFormat.format("{0}_default_coding", governor.getGenNameDefaultCoding(aData, expression.expression, scope)));
final String tempID = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString();\n", tempID));
expression.preamble.append(MessageFormat.format("{0}_encoder({1}{2}, {3}, {4});\n", governor.getGenNameCoder(aData, expression.expression, scope), expression2.expression, isValue ? "" : ".valueOf()", tempID, expression3.expression));
expression.expression.append(MessageFormat.format("AdditionalFunctions.oct2bit({0})", tempID));
if (expression2.postamble.length() > 0) {
expression.postamble.append(expression2.postamble);
}
if (expression3.postamble.length() > 0) {
expression.postamble.append(expression3.postamble);
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class EncodeExpression 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 the value to be 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 (templateInstance == null) {
setIsErroneous(true);
return;
}
final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
IType type = templateInstance.getExpressionGovernor(timestamp, internalExpectation);
ITTCN3Template template = templateInstance.getTemplateBody();
if (type == null) {
template = template.setLoweridToReference(timestamp);
type = template.getExpressionGovernor(timestamp, internalExpectation);
}
if (type == null) {
if (!template.getIsErroneous(timestamp)) {
templateInstance.getLocation().reportSemanticError(OPERANDERROR1);
}
setIsErroneous(true);
return;
}
IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance, type, referenceChain, expectedValue);
if (getIsErroneous(timestamp)) {
return;
}
template.checkSpecificValue(timestamp, false);
type = type.getTypeRefdLast(timestamp);
switch(type.getTypetype()) {
case TYPE_UNDEFINED:
case TYPE_NULL:
case TYPE_REFERENCED:
case TYPE_VERDICT:
case TYPE_PORT:
case TYPE_COMPONENT:
case TYPE_DEFAULT:
case TYPE_SIGNATURE:
case TYPE_FUNCTION:
case TYPE_ALTSTEP:
case TYPE_TESTCASE:
if (!isErroneous) {
location.reportSemanticError(OPERANDERROR2);
setIsErroneous(true);
}
break;
default:
break;
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class EncvalueUnicharExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
aData.addBuiltinTypeImport("TitanOctetString");
aData.addCommonLibraryImport("AdditionalFunctions");
final boolean isValue = templateInstance1.getTemplateBody().isValue(CompilationTimeStamp.getBaseTimestamp());
final ExpressionStruct expression2 = new ExpressionStruct();
if (isValue) {
templateInstance1.getTemplateBody().getValue().generateCodeExpressionMandatory(aData, expression2, true);
} else {
templateInstance1.generateCode(aData, expression2, Restriction_type.TR_NONE);
}
String v2_code;
if (value2 == null) {
v2_code = "\"UTF-8\"";
} else {
final ExpressionStruct tempExpression = new ExpressionStruct();
value2.generateCodeExpressionMandatory(aData, tempExpression, true);
final String tempID = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("TitanCharString {0} = {1};\n", tempID, tempExpression.expression));
expression.preamble.append(MessageFormat.format("if ({0}.operatorNotEquals(\"UTF-8\") && {0}.operatorNotEquals(\"UTF-16\") && {0}.operatorNotEquals(\"UTF-16LE\") && {0}.operatorNotEquals(\"UTF-16BE\") && {0}.operatorNotEquals(\"UTF-32\") && {0}.operatorNotEquals(\"UTF-32LE\") && {0}.operatorNotEquals(\"UTF-32BE\")) '{'\n", tempID));
expression.preamble.append(MessageFormat.format("throw new TtcnError(MessageFormat.format(\"decvalue_unichar: Invalid encoding parameter: '{'0'}'\", {0}));\n", tempID));
expression.preamble.append("}\n");
v2_code = tempID;
}
final Scope scope = templateInstance1.getTemplateBody().getMyScope();
final IType governor = templateInstance1.getTemplateBody().getMyGovernor();
if (expression2.preamble.length() > 0) {
expression.postamble.append(expression2.preamble);
}
final ExpressionStruct expression3 = new ExpressionStruct();
// FIXME handle 4th parameter
expression3.expression.append(MessageFormat.format("{0}_default_coding", governor.getGenNameDefaultCoding(aData, expression.expression, scope)));
final String tempID = aData.getTemporaryVariableName();
expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString();\n", tempID));
expression.preamble.append(MessageFormat.format("{0}_encoder({1}{2}, {3}, {4});\n", governor.getGenNameCoder(aData, expression.expression, scope), expression2.expression, isValue ? "" : ".valueOf()", tempID, expression3.expression));
expression.expression.append(MessageFormat.format("AdditionalFunctions.oct2unichar({0}, {1})", tempID, v2_code));
if (expression2.postamble.length() > 0) {
expression.postamble.append(expression2.postamble);
}
if (expression3.postamble.length() > 0) {
expression.postamble.append(expression3.postamble);
}
}
Aggregations