use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Enumerated_Value method getDeclaration.
@Override
public /**
* {@inheritDoc}
*/
Declaration getDeclaration() {
IType type = getMyGovernor();
if (type == null) {
return null;
}
type = type.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (type instanceof ITypeWithComponents) {
final Identifier resultId = ((ITypeWithComponents) type).getComponentIdentifierByName(value);
return Declaration.createInstance(type.getDefiningAssignment(), resultId);
}
return null;
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class Expression_Value method generateCodeExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpression(final JavaGenData aData, final ExpressionStruct expression, final boolean forceObject) {
if (lastValue != null && lastValue != this) {
lastValue.generateCodeExpression(aData, expression, forceObject);
return;
}
if (canGenerateSingleExpression()) {
if (returnsNative() && forceObject) {
final IType gov = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
expression.expression.append(MessageFormat.format("new {0}(", gov.getGenNameValue(aData, new StringBuilder(), myScope)));
expression.expression.append(generateSingleExpression(aData));
expression.expression.append(")");
} else {
expression.expression.append(generateSingleExpression(aData));
}
return;
}
if (returnsNative() && forceObject) {
final ExpressionStruct tempExpression = new ExpressionStruct();
generateCodeExpressionExpression(aData, tempExpression);
final IType gov = getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
expression.preamble.append(tempExpression.preamble);
expression.expression.append(MessageFormat.format("new {0}(", gov.getGenNameValue(aData, new StringBuilder(), myScope)));
expression.expression.append(tempExpression.expression);
expression.expression.append(")");
} else {
generateCodeExpressionExpression(aData, expression);
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class ComponentCreateExpression method checkCreate.
private Component_Type checkCreate(final CompilationTimeStamp timestamp) {
if (checkCreateTimestamp != null && !checkCreateTimestamp.isLess(timestamp)) {
return checkCreateCache;
}
checkCreateTimestamp = timestamp;
checkCreateCache = null;
final Assignment assignment = componentReference.getRefdAssignment(timestamp, true);
if (assignment == null) {
setIsErroneous(true);
return null;
}
if (!Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
componentReference.getLocation().reportSemanticError(MessageFormat.format(COMPONENTEXPECTED, assignment.getDescription()));
setIsErroneous(true);
return null;
}
final IType type = ((Def_Type) assignment).getType(timestamp).getFieldType(timestamp, componentReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
setIsErroneous(true);
return null;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
componentReference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH1, type.getTypename()));
setIsErroneous(true);
return null;
}
if (myGovernor != null) {
final IType last = myGovernor.getTypeRefdLast(timestamp);
if (Type_type.TYPE_COMPONENT.equals(last.getTypetype()) && !last.isCompatible(timestamp, type, null, null, null)) {
componentReference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH2, last.getTypename(), type.getTypename()));
setIsErroneous(true);
return null;
}
}
checkCreateCache = (Component_Type) type;
return checkCreateCache;
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class DecodeExpression method checkSecondExpressionOperand.
private void checkSecondExpressionOperand(final CompilationTimeStamp timestamp) {
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:
// if (!isErroneous) {
reference2.getLocation().reportSemanticError(OPERANDERROR2);
setIsErroneous(true);
// }
break;
default:
break;
}
}
use of org.eclipse.titan.designer.AST.IType in project titan.EclipsePlug-ins by eclipse.
the class DecvalueUnicharExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
aData.addBuiltinTypeImport("TitanOctetString");
aData.addCommonLibraryImport("AdditionalFunctions");
final ExpressionStruct expression1 = new ExpressionStruct();
final ExpressionStruct expression2 = new ExpressionStruct();
reference1.generateCode(aData, expression1);
reference2.generateCode(aData, expression2);
final Assignment tempAssignment = reference2.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
final IType type = tempAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
final IType fieldType = type.getFieldType(CompilationTimeStamp.getBaseTimestamp(), reference2, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (expression1.preamble.length() > 0) {
expression.preamble.append(expression1.preamble);
}
if (expression2.preamble.length() > 0) {
expression.preamble.append(expression2.preamble);
}
String v3_code;
if (value3 == null) {
v3_code = "\"UTF-8\"";
} else {
final ExpressionStruct tempExpression = new ExpressionStruct();
value3.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");
v3_code = tempID;
}
final Scope scope = reference2.getMyScope();
final boolean isOptional = fieldType.fieldIsOptional(reference2.getSubreferences());
final ExpressionStruct expression3 = new ExpressionStruct();
// TODO add support for 4th parameter
expression3.expression.append(MessageFormat.format("{0}_default_coding", fieldType.getGenNameDefaultCoding(aData, expression.expression, scope)));
final String bufferID = aData.getTemporaryVariableName();
final String returnValueID = aData.getTemporaryVariableName();
// TOOD add handling for non-built-in encoding
expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_WARNING);\n");
expression.preamble.append("TTCN_EncDec.clear_error();\n");
expression.preamble.append(MessageFormat.format("TitanOctetString {0} = new TitanOctetString(AdditionalFunctions.unichar2oct({1}, {2}));\n", bufferID, expression1.expression, v3_code));
expression.preamble.append(MessageFormat.format("TitanInteger {0} = new TitanInteger({1}_decoder({2}, {3}{4}, {5}));\n", returnValueID, fieldType.getGenNameCoder(aData, expression.expression, scope), bufferID, expression2.expression, isOptional ? ".get()" : "", expression3.expression));
expression.preamble.append(MessageFormat.format("if ({0}.operatorEquals(0)) '{'\n", returnValueID));
expression.preamble.append(MessageFormat.format("{0} = AdditionalFunctions.oct2unichar({1}, {2});\n", expression1.expression, bufferID, v3_code));
expression.preamble.append("}\n");
// TOOD add handling for non-built-in encoding
expression.preamble.append("TTCN_EncDec.set_error_behavior(TTCN_EncDec.error_type.ET_ALL, TTCN_EncDec.error_behavior_type.EB_DEFAULT);\n");
expression.preamble.append("TTCN_EncDec.clear_error();\n");
expression.expression.append(returnValueID);
if (expression1.postamble.length() > 0) {
expression.postamble.append(expression1.postamble);
}
if (expression2.postamble.length() > 0) {
expression.postamble.append(expression2.postamble);
}
if (expression3.postamble.length() > 0) {
expression.postamble.append(expression3.postamble);
}
}
Aggregations