use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Send_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct expression = new ExpressionStruct();
portReference.generateCode(aData, expression);
expression.expression.append(".send(");
final TTCN3Template templateBody = parameter.getTemplateBody();
if (parameter.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
// optimize for value
final IValue value = ((SpecificValue_Template) templateBody).getValue();
// FIXME check if casting is needed
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
// real template, can not be optimized
parameter.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(", ");
if (toClause == null) {
expression.expression.append("new TitanComponent(TitanComponent.SYSTEM_COMPREF)");
} else {
toClause.generateCodeExpression(aData, expression, true);
}
expression.expression.append(")");
expression.mergeExpression(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class Raise_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct expression = new ExpressionStruct();
portReference.generateCode(aData, expression);
expression.expression.append(".raise( new ");
signatureReference.generateCode(aData, expression);
expression.expression.append("_exception(");
final TTCN3Template templateBody = parameter.getTemplateBody();
if (parameter.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype())) {
// the exception is a value: optimization is possible
final IValue value = ((SpecificValue_Template) templateBody).getSpecificValue();
// FIXME implement the case where cast is needed (if really needed)
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
parameter.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(')');
if (toClause != null) {
expression.expression.append(", ");
toClause.generateCodeExpression(aData, expression, true);
}
expression.expression.append(" )");
expression.mergeExpression(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class ChangeCreator method calculateEditLocations.
private WorkspaceJob calculateEditLocations(final NavigableSet<ILocateableNode> nodes, final IFile file, final MultiTextEdit rootEdit) throws CoreException {
final WorkspaceJob job = new WorkspaceJob("InsertFieldRefactoring: calculate edit locations") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
for (ILocateableNode node : nodes) {
int vmLen = settings.getType().length() + settings.getId().getTtcnName().length();
if (node instanceof Def_Type) {
Def_Type df = (Def_Type) node;
Type type = df.getType(CompilationTimeStamp.getBaseTimestamp());
if (type instanceof TTCN3_Sequence_Type || type instanceof TTCN3_Set_Type) {
vmLen = insertField((TTCN3_Set_Seq_Choice_BaseType) type, node, rootEdit, vmLen);
}
} else if (node instanceof Sequence_Value) {
Sequence_Value sv = (Sequence_Value) node;
vmLen += 6;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < sv.getNofComponents()) {
final Location valueLocation = sv.getSeqValueByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getOffset(), valueLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
} else {
int max = sv.getNofComponents();
final Location valueLocation = sv.getSeqValueByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), valueLocation.getEndOffset(), valueLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
}
} else if (node instanceof TTCN3Template) {
TTCN3Template template = (TTCN3Template) node;
vmLen += 6;
if (template instanceof Named_Template_List) {
Named_Template_List ntl = (Named_Template_List) template;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < ntl.getNofTemplates()) {
final Location templateLocation = ntl.getTemplateByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getId().getTtcnName() + " := " + settings.getValue() + ", "));
} else {
int max = ntl.getNofTemplates();
final Location templateLocation = ntl.getTemplateByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), ", " + settings.getId().getTtcnName() + " := " + settings.getValue()));
}
} else if (template instanceof Template_List) {
Template_List tl = (Template_List) template;
final Location nodeLocation = node.getLocation();
if (settings.getPosition() < tl.getNofTemplates()) {
final Location templateLocation = tl.getTemplateByIndex(settings.getPosition()).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), settings.getValue() + ","));
} else {
int max = tl.getNofTemplates();
final Location templateLocation = tl.getTemplateByIndex(max - 1).getLocation();
Location l = new Location(nodeLocation.getFile(), nodeLocation.getLine(), templateLocation.getEndOffset(), templateLocation.getEndOffset() + vmLen);
rootEdit.addChild(new InsertEdit(l.getOffset(), "," + settings.getValue()));
}
}
}
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
return job;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class FormalParameterList method setGenName.
public void setGenName(final String prefix) {
for (final FormalParameter parameter : parameters) {
final String parameterName = parameter.getIdentifier().getName();
if (!Assignment_type.A_TIMER.equals(parameter.getAssignmentType())) {
final Type parameterType = parameter.getType(CompilationTimeStamp.getBaseTimestamp());
if (parameterType != null) {
parameterType.setGenName(prefix, parameterName);
}
}
if (parameter.hasDefaultValue()) {
final StringBuilder embeddedName = new StringBuilder(prefix);
embeddedName.append('_');
embeddedName.append(parameterName);
embeddedName.append("_defval");
final ActualParameter defaultValue = parameter.getDefaultValue();
if (defaultValue instanceof Value_ActualParameter) {
final IValue value = ((Value_ActualParameter) defaultValue).getValue();
// value.setGenNamePrefix("const_");//currently does not need the prefix
value.setGenNameRecursive(embeddedName.toString());
} else if (defaultValue instanceof Template_ActualParameter) {
final TemplateInstance instance = ((Template_ActualParameter) defaultValue).getTemplateInstance();
final TTCN3Template template = instance.getTemplateBody();
// template.setGenNamePrefix("template_");//currently does not need the prefix
template.setGenNameRecursive(embeddedName.toString());
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class ExpressionUtilities method checkExpressionOperatorCompatibilityInternal.
// the same as the previous but the last arg is template
private static void checkExpressionOperatorCompatibilityInternal(final CompilationTimeStamp timestamp, final Expression_Value expression, final IReferenceChain referenceChain, final Expected_Value_type expectedValue, final IValue param1, final TemplateInstance param2) {
if (expression == null || param1 == null || param2 == null) {
return;
}
if (param1.getIsErroneous(timestamp) || param2.getTemplateBody().getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
IValue operand1 = param1;
final TemplateInstance operand2 = param2;
final Type_type tempType1 = operand1.getExpressionReturntype(timestamp, expectedValue);
final Type_type tempType2 = operand2.getExpressionReturntype(timestamp, expectedValue);
ITTCN3Template temp2 = operand2.getTemplateBody();
if (Type_type.TYPE_UNDEFINED.equals(tempType1)) {
if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype())) {
if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype())) {
final Scope scope = expression.getMyScope();
final Module module = scope.getModuleScope();
final Identifier identifier = ((Undefined_LowerIdentifier_Value) operand1).getIdentifier();
if (scope.hasAssignmentWithId(timestamp, identifier) || module.hasImportedAssignmentWithID(timestamp, identifier)) {
operand1 = operand1.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
final Identifier identifier2 = ((Undefined_LowerIdentifier_Value) ((SpecificValue_Template) temp2).getSpecificValue()).getIdentifier();
if (scope.hasAssignmentWithId(timestamp, identifier2) || module.hasImportedAssignmentWithID(timestamp, identifier2)) {
temp2 = temp2.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
} else {
operand1 = operand1.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
} else if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype())) {
temp2 = temp2.setLoweridToReference(timestamp);
// To avoid infinite loop:
final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) temp2);
if (operand2 == tempTemplateInstance2) {
return;
}
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
return;
}
if (operand1.getIsErroneous(timestamp) || temp2.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
expression.getLocation().reportSemanticError(UNDETERMINABLEOPERANDSERROR);
expression.setIsErroneous(true);
return;
}
if (Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(operand1.getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType2)) {
operand1 = operand1.setLoweridToReference(timestamp);
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, operand2);
return;
}
} else if (Type_type.TYPE_UNDEFINED.equals(tempType2)) {
if (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.UNDEFINED_LOWERIDENTIFIER_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype()) && !Type_type.TYPE_TTCN3_ENUMERATED.equals(tempType1)) {
temp2 = temp2.setLoweridToReference(timestamp);
// To avoid infinite loop:
final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) temp2);
if (operand2 == tempTemplateInstance2) {
return;
}
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
return;
}
}
final IType type1 = operand1.getExpressionGovernor(timestamp, expectedValue);
final IType type2 = operand2.getExpressionGovernor(timestamp, expectedValue);
if (operand1.getIsErroneous(timestamp) || temp2.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
if (type1 != null) {
if (type2 != null) {
final TypeCompatibilityInfo info1 = new TypeCompatibilityInfo(type1, type2, true);
final TypeCompatibilityInfo info2 = new TypeCompatibilityInfo(type2, type1, true);
final boolean retVal1 = type1.isCompatible(timestamp, type2, info1, null, null);
final boolean retVal2 = type2.isCompatible(timestamp, type1, info2, null, null);
if (!retVal1 && !retVal2) {
expression.getLocation().reportSemanticError(info1.toString());
expression.setIsErroneous(true);
return;
}
if (GeneralConstants.WARNING.equals(typeCompatibilitySeverity)) {
if (info1.getNeedsConversion()) {
expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type1.getTypename(), type2.getTypename()));
} else if (info2.getNeedsConversion()) {
expression.getLocation().reportSemanticWarning(MessageFormat.format(TYPECOMPATWARNING, type2.getTypename(), type1.getTypename()));
}
}
} else {
temp2.setMyGovernor(type1);
final ITTCN3Template tempValue = type1.checkThisTemplateRef(timestamp, temp2);
if (Template_type.OMIT_VALUE.equals(temp2.getTemplatetype()) || (Template_type.SPECIFIC_VALUE.equals(temp2.getTemplatetype()) && Value_type.OMIT_VALUE.equals(((SpecificValue_Template) temp2).getSpecificValue().getValuetype()))) {
operand1.checkExpressionOmitComparison(timestamp, expectedValue);
} else {
type1.checkThisTemplate(timestamp, tempValue, false, false, null);
final TemplateInstance tempTemplateInstance2 = new TemplateInstance(operand2.getType(), operand2.getDerivedReference(), (TTCN3Template) tempValue);
if (operand2 == tempTemplateInstance2) {
return;
}
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, operand1, tempTemplateInstance2);
return;
}
}
} else if (type2 != null) {
operand1.setMyGovernor(type2);
final IValue tempValue = type2.checkThisValueRef(timestamp, operand1);
if (Value_type.OMIT_VALUE.equals(operand1.getValuetype())) {
// temp2.check_expression_omit_comparison(timestamp,
// expectedValue); ???
} else {
type2.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(expectedValue, false, false, false, false, false));
checkExpressionOperatorCompatibilityInternal(timestamp, expression, referenceChain, expectedValue, tempValue, operand2);
return;
}
} else {
if (Type_type.TYPE_UNDEFINED.equals(tempType1) || Type_type.TYPE_UNDEFINED.equals(tempType2)) {
expression.getLocation().reportSemanticError(PLEASEUSEREFERENCES);
expression.setIsErroneous(true);
return;
}
if (!Type.isCompatible(timestamp, tempType1, tempType2, false, false) && !Type.isCompatible(timestamp, tempType2, tempType1, false, false)) {
expression.getLocation().reportSemanticError(INCOMPATIBLEOPERANDERROR);
expression.setIsErroneous(true);
}
}
}
Aggregations