use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class DecodeExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
aData.addBuiltinTypeImport("TitanOctetString");
aData.addCommonLibraryImport("TTCN_EncDec");
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);
}
final Scope scope = reference2.getMyScope();
final boolean isOptional = fieldType.fieldIsOptional(reference2.getSubreferences());
final ExpressionStruct expression3 = new ExpressionStruct();
// TODO add support for 5th 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.bit2oct({1}));\n", bufferID, expression1.expression));
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}.assign(AdditionalFunctions.oct2bit({1}));\n", expression1.expression, bufferID));
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);
}
}
use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class DecodeExpression method checkFirstExpressionOperand.
private void checkFirstExpressionOperand(final CompilationTimeStamp timestamp) {
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("Reference to `{0}'' cannot be used as the first operand of the `decvalue'' operation", 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("Specific value template was expected instead of `{0}''", last.getTemplateTypeName()));
setIsErroneous(true);
return;
}
break;
}
default:
reference1.getLocation().reportSemanticError(MessageFormat.format("Reference to `{0}'' cannot be used as the first operand of the `decvalue' operation", 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;
}
if (temporalType.getTypeRefdLast(timestamp).getTypetype() != Type_type.TYPE_BITSTRING) {
if (!isErroneous) {
reference1.getLocation().reportSemanticError(OPERANDERROR1);
setIsErroneous(true);
}
return;
}
}
use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class ImportModule method addDeclaration.
/**
* Adds the imported module or definitions contained in it, to the list
* declaration proposals.
*
* @param declarationCollector
* the declaration collector.
* @param targetModuleId
* the identifier of the module where the declaration
* should be inserted into.
*/
@Override
public /**
* {@inheritDoc}
*/
void addDeclaration(final DeclarationCollector declarationCollector, final Identifier targetModuleId) {
final Module savedReferredModule = referredModule;
if (savedReferredModule != null) {
final Assignments assignments = savedReferredModule.getAssignments();
for (int i = 0; i < assignments.getNofAssignments(); i++) {
final Assignment temporalAssignment = assignments.getAssignmentByIndex(i);
if (savedReferredModule.isVisible(CompilationTimeStamp.getBaseTimestamp(), targetModuleId, temporalAssignment)) {
temporalAssignment.addDeclaration(declarationCollector, 0);
}
}
final Identifier moduleId = declarationCollector.getReference().getModuleIdentifier();
final List<ISubReference> subrefs = declarationCollector.getReference().getSubreferences();
if (moduleId == null && subrefs.size() == 1 && identifier.getName().equals(subrefs.get(0).getId().getName())) {
declarationCollector.addDeclaration(savedReferredModule.getIdentifier().getDisplayName(), savedReferredModule.getIdentifier().getLocation(), (Scope) null);
}
}
}
use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class ImportModule method importAssignment.
@Override
public /**
* {@inheritDoc}
*/
Assignment importAssignment(final CompilationTimeStamp timestamp, final ModuleImportationChain referenceChain, final Identifier moduleId, final Reference reference, final List<ModuleImportation> usedImports) {
// endpoint of an importation chain.
if (referredModule == null) {
return null;
}
final Assignment result = referredModule.importAssignment(timestamp, moduleId, reference);
if (result != null) {
usedImports.add(this);
setUsedForImportation();
}
return result;
}
use of org.eclipse.titan.designer.AST.Assignment in project titan.EclipsePlug-ins by eclipse.
the class ObjectClass_refd method getRefd.
protected ObjectClass getRefd(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
if (null != reference && referenceChain.add(this)) {
final Assignment assignment = reference.getRefdAssignment(timestamp, true, referenceChain);
if (null == assignment) {
return newObjectClassDefinitionInstance();
}
final ISetting setting = reference.getRefdSetting(timestamp);
if (Setting_type.S_ERROR.equals(setting.getSettingtype())) {
return newObjectClassDefinitionInstance();
} else if (!Setting_type.S_OC.equals(setting.getSettingtype())) {
reference.getLocation().reportSemanticError(OBJECTCLASSEXPECTED);
return newObjectClassDefinitionInstance();
}
return (ObjectClass) setting;
}
return newObjectClassDefinitionInstance();
}
Aggregations