use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method addProposal.
/**
* Adds the port related proposals.
*
* handles the following proposals:
*
* <ul>
* <li>in message mode:
* <ul>
* <li>send(template), receive, trigger
* </ul>
* <li>in procedure mode:
* <ul>
* <li>call, getcall, reply, raise, getreply, catch
* </ul>
* <li>general:
* <ul>
* <li>check
* <li>clear, start, stop, halt
* </ul>
* </ul>
*
* @param propCollector the proposal collector.
* @param i the index of a part of the full reference, for which we wish to find completions.
*/
public void addProposal(final ProposalCollector propCollector, final int i) {
final List<ISubReference> subrefs = propCollector.getReference().getSubreferences();
if (subrefs.size() != i + 1 || Subreference_type.arraySubReference.equals(subrefs.get(i).getReferenceType())) {
return;
}
if (OperationModes.OP_Message.equals(operationMode) || OperationModes.OP_Mixed.equals(operationMode)) {
propCollector.addTemplateProposal("send", new Template("send( templateInstance )", "", propCollector.getContextIdentifier(), "send( ${templateInstance} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("send", new Template("send( templateInstance ) to location", "", propCollector.getContextIdentifier(), "send( ${templateInstance} ) to ${location};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
addReceiveProposals(propCollector, i);
addTriggerProposals(propCollector, i);
}
if (OperationModes.OP_Procedure.equals(operationMode) || OperationModes.OP_Mixed.equals(operationMode)) {
propCollector.addTemplateProposal("call", new Template("call( templateInstance )", "", propCollector.getContextIdentifier(), "call( ${templateInstance} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("call", new Template("call( templateInstance , callTimer )", "with timer", propCollector.getContextIdentifier(), "call( ${templateInstance} , ${callTimer} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("call", new Template("call( templateInstance ) to location", "with to clause", propCollector.getContextIdentifier(), "call( ${templateInstance} ) to ${location};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("call", new Template("call( templateInstance , callTimer ) to location", "with timer and to clause", propCollector.getContextIdentifier(), "call( ${templateInstance} , ${callTimer} ) to ${location};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
addGetcallProposals(propCollector, i);
propCollector.addTemplateProposal("reply", new Template("reply( templateInstance )", "", propCollector.getContextIdentifier(), "reply( ${templateInstance} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("reply", new Template("reply( templateInstance ) to location", "", propCollector.getContextIdentifier(), "reply( ${templateInstance} ) to ${location};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
addGetreplyProposals(propCollector, i);
propCollector.addTemplateProposal("raise", new Template("raise( signature, templateInstance )", "", propCollector.getContextIdentifier(), "raise( ${signature}, ${templateInstance} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("raise", new Template("raise( signature, templateInstance ) to location", "with to clause", propCollector.getContextIdentifier(), "raise( ${signature}, ${templateInstance} ) to ${location};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
addCatchProposals(propCollector, i);
}
addCheckProposals(propCollector, i);
propCollector.addProposal("clear;", "clear", ImageCache.getImage("port.gif"), "");
propCollector.addProposal("start;", "start", ImageCache.getImage("port.gif"), "");
propCollector.addProposal("stop;", "stop", ImageCache.getImage("port.gif"), "");
propCollector.addProposal("halt;", "halt", ImageCache.getImage("port.gif"), "");
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method addTriggerProposals.
/**
* Adds the "trigger" related operations of port types, to the completion
* list.
*
* @param propCollector the proposal collector
* @param i index, not used
*/
public static void addTriggerProposals(final ProposalCollector propCollector, final int i) {
propCollector.addProposal("trigger", "trigger", ImageCache.getImage("port.gif"), "");
propCollector.addTemplateProposal("trigger", new Template("trigger -> value myVar", "value redirect", propCollector.getContextIdentifier(), "trigger -> value ${myVar};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger -> sender myPeer", "sender redirect", propCollector.getContextIdentifier(), "trigger -> sender ${myPeer};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger -> value myVar sender myPeer", "value and sender redirect", propCollector.getContextIdentifier(), "trigger -> value ${myVar} sender ${myPeer};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger from myPeer", "from clause", propCollector.getContextIdentifier(), "trigger from ${myPeer};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger from myPeer -> value myVar", "from clause with value redirect", propCollector.getContextIdentifier(), "trigger from ${myPeer} -> value ${myVar};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger( templateInstance )", "", propCollector.getContextIdentifier(), "trigger( ${templateInstance} );", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger( templateInstance ) -> value myVar", "value redirect", propCollector.getContextIdentifier(), "trigger( ${templateInstance} ) -> value ${myVar};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger( templateInstance ) -> sender myPeer", "sender redirect", propCollector.getContextIdentifier(), "trigger( ${templateInstance} ) -> sender ${myPeer};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger( templateInstance ) -> value myVar sender myPeer", "value and sender redirect", propCollector.getContextIdentifier(), "trigger( ${templateInstance} ) -> value ${myVar} sender ${myPeer};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger( templateInstance ) from myPeer", "from clause", propCollector.getContextIdentifier(), "trigger( ${templateInstance} ) from ${myPeer};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("trigger", new Template("trigger( templateInstance ) from myPeer -> value myVar", "from clause with value redirect", propCollector.getContextIdentifier(), "trigger( ${templateInstance} ) from ${myPeer} -> value ${myVar};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method addGetreplyProposals.
/**
* Adds the "getreply" related operations of port types, to the completion
* list.
*
* @param propCollector the proposal collector
* @param i index, not used
*/
public static void addGetreplyProposals(final ProposalCollector propCollector, final int i) {
propCollector.addProposal("getreply", "getreply", ImageCache.getImage("port.gif"), "");
propCollector.addTemplateProposal("getreply", new Template("getreply from myPartner", "from clause", propCollector.getContextIdentifier(), "getreply from ${myPartner};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addTemplateProposal("getreply", new Template("getreply( templateInstance ) -> value myReturnValue param(parameters) sender mySenderVar", "value, parameters and sender clause", propCollector.getContextIdentifier(), "getreply( ${templateInstance} ) -> value ${myReturnValue} param( ${parameters} ) sender ${mySenderVar};", false), TTCN3CodeSkeletons.SKELETON_IMAGE);
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class TemplateInstance method reArrangeInitCode.
/**
* Walks through the templateinstance recursively and appends the java
* initialization sequence of all (directly or indirectly) referenced
* non-parameterized templates and the default values of all
* parameterized templates to source and returns the resulting string.
* Only objects belonging to module usageModule are initialized.
*
* @param aData the structure to put imports into and get temporal variable names from.
* @param source the source for code generated
* @param usageModule the module where the template is to be used.
*/
public void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
if (derivedReference != null) {
final List<ISubReference> subreferences = derivedReference.getSubreferences();
if (subreferences != null && !subreferences.isEmpty() && subreferences.get(0) instanceof ParameterisedSubReference) {
final ParameterisedSubReference subreference = (ParameterisedSubReference) subreferences.get(0);
final ActualParameterList actualParameterList = subreference.getActualParameters();
if (actualParameterList != null) {
actualParameterList.reArrangeInitCode(aData, source, usageModule);
}
}
final Assignment assignment = derivedReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment == null) {
return;
}
if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
final ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
if (formalParameterList != null) {
// the referred template is parameterized
// the embedded referenced templates shall be visited
template.reArrangeInitCode(aData, source, usageModule);
// FIXME implement
} else {
// its entire body has to be initialized now
if (assignment.getMyScope().getModuleScope() == usageModule) {
template.generateCodeInit(aData, source, template.get_lhs_name());
}
}
}
}
if (templateBody != null) {
templateBody.reArrangeInitCode(aData, source, usageModule);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance in project titan.EclipsePlug-ins by eclipse.
the class SelectCase method generateCode.
/**
* Add generated java code for a single select case.
*
* @param aData the structure to put imports into and get temporal variable names from.
* @param source the source code generated
* @param name the name to compare the branch variables to (expression or temporary name)
* @param unReachable tells whether this branch is already unreachable because of previous conditions
*/
public void generateCode(final JavaGenData aData, final StringBuilder source, final String name, final AtomicBoolean unreach) {
ExpressionStruct expression = new ExpressionStruct();
StringBuilder condition = new StringBuilder();
if (templateInstances != null) {
for (int i = 0; i < templateInstances.getNofTis(); i++) {
final String tmp = aData.getTemporaryVariableName();
final TemplateInstance templateInstance = templateInstances.getInstanceByIndex(i);
final TTCN3Template templateBody = templateInstance.getTemplateBody();
final boolean isValue = templateInstance.getDerivedReference() == null && templateBody.isValue(CompilationTimeStamp.getBaseTimestamp());
final IType last = templateInstance.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (i > 0) {
condition.append(" || ");
}
if (isValue) {
final String genName = last.getGenNameValue(aData, expression.expression, last.getMyScope());
expression.expression.append(MessageFormat.format("{0} {1} = new {0} (", genName, tmp));
IValue value = templateBody.getValue();
value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
value.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(");\n");
condition.append(MessageFormat.format("{0}.operatorEquals({1})", tmp, name));
} else {
final String genName = last.getGenNameTemplate(aData, expression.expression, last.getMyScope());
expression.expression.append(MessageFormat.format("{0} {1} = new {0} (", genName, tmp));
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(");\n");
condition.append(MessageFormat.format("{0}.match({1})", tmp, name));
}
}
source.append(expression.preamble);
source.append(expression.expression);
source.append(expression.postamble);
getLocation().update_location_object(aData, source);
source.append("if (").append(condition).append(") {\n");
statementBlock.generateCode(aData, source);
source.append("}\n");
} else {
statementBlock.generateCode(aData, source);
unreach.set(true);
}
}
Aggregations