use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkFromClause.
/**
* Checks a from clause reference and a sender redirect to see if they
* really references valid component types.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param source
* the source statement to report errors to.
* @param portType
* the type of the port used in the statement. Used to
* find the address type in effect.
* @param fromClause
* the from clause to check
* @param redirectSender
* the sender redirect to check.
*/
public static void checkFromClause(final CompilationTimeStamp timestamp, final Statement source, final Port_Type portType, final TemplateInstance fromClause, final Reference redirectSender) {
IType addressType = null;
if (portType != null) {
addressType = portType.getPortBody().getAddressType(timestamp);
} else if (source != null && source.getMyStatementBlock() != null) {
final Module module = source.getMyStatementBlock().getModuleScope();
if (module != null && module_type.TTCN3_MODULE.equals(module.getModuletype())) {
addressType = ((TTCN3Module) module).getAddressType(timestamp);
}
}
boolean senderRedirectChecked = false;
IType fromClauseType = null;
if (fromClause != null) {
fromClauseType = fromClause.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
ITTCN3Template templateBody = fromClause.getTemplateBody();
if (fromClauseType == null) {
if (addressType != null) {
templateBody = addressType.checkThisTemplateRef(timestamp, templateBody);
} else {
templateBody = templateBody.setLoweridToReference(timestamp);
}
fromClauseType = templateBody.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
}
if (fromClauseType == null) {
fromClauseType = checkSenderRedirect(timestamp, addressType, redirectSender);
senderRedirectChecked = true;
}
if (fromClauseType == null) {
// trying to figure out whether the template is
// a component reference or an SUT address
boolean isComponentReference;
if (Type_type.TYPE_COMPONENT.equals(templateBody.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE))) {
isComponentReference = true;
} else {
switch(templateBody.getTemplatetype()) {
case SPECIFIC_VALUE:
// treat 'null' as component
// reference
isComponentReference = Value_type.TTCN3_NULL_VALUE.equals(((SpecificValue_Template) templateBody).getSpecificValue().getValuetype());
break;
case ANY_VALUE:
case ANY_OR_OMIT:
isComponentReference = true;
break;
default:
isComponentReference = false;
break;
}
}
if (isComponentReference) {
// the argument is a component
// reference: get a pool type
fromClauseType = TypeFactory.createType(Type_type.TYPE_COMPONENT);
} else if (addressType != null) {
// the argument is not a component
// reference: try the address type
fromClauseType = addressType;
}
}
if (fromClauseType != null) {
fromClause.check(timestamp, fromClauseType);
if (addressType == null || !addressType.isCompatible(timestamp, fromClauseType, null, null, null)) {
// from_clause_type must be a component
// type
final IType last = fromClauseType.getTypeRefdLast(timestamp);
if (last.getIsErroneous(timestamp)) {
fromClauseType = null;
} else if (Type_type.TYPE_COMPONENT.equals(last.getTypetype())) {
if (Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype())) {
checkComponentReference(timestamp, source, ((SpecificValue_Template) templateBody).getSpecificValue(), true, true);
}
} else {
final String message = MessageFormat.format("The type of the template should be a component type {0} instead of `{1}''", (addressType == null) ? "" : "or the `address' type ", fromClauseType.getTypename());
fromClause.getLocation().reportSemanticError(message);
fromClauseType = null;
}
}
} else {
fromClause.getLocation().reportSemanticError("Cannot determine the type of the template");
}
}
if (!senderRedirectChecked) {
final IType senderRedirectType = checkSenderRedirect(timestamp, addressType, redirectSender);
if (fromClauseType != null && senderRedirectType != null && !fromClauseType.isIdentical(timestamp, senderRedirectType)) {
final String message = MessageFormat.format("The types in `from'' clause and `sender'' redirect are not the same: `{0}'' was expected instead of `{1}''", fromClauseType.getTypename(), senderRedirectType.getTypename());
senderRedirectType.getLocation().reportSemanticError(message);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.
the class Return_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
// TODO more nuanced code generation
getLocation().release_location_object(aData, source);
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append("return ");
// No return value:
if (template == null) {
expression.mergeExpression(source);
return;
}
final Definition definition = myStatementBlock.getMyDefinition();
if (definition.getAssignmentType() == Assignment_type.A_FUNCTION_RVAL && template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
final IValue value = ((SpecificValue_Template) template).getValue();
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
final Definition myDefinition = myStatementBlock.getMyDefinition();
if (myDefinition.getTemplateRestriction() != TemplateRestriction.Restriction_type.TR_NONE && genRestrictionCheck) {
template.generateCodeExpression(aData, expression, myDefinition.getTemplateRestriction());
} else {
template.generateCodeExpression(aData, expression, Restriction_type.TR_NONE);
}
}
expression.mergeExpression(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.
the class ComplementedList_Template method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
return;
}
lastTimeBuilt = aData.getBuildTimstamp();
aData.addBuiltinTypeImport("Base_Template.template_sel");
final ArrayList<Integer> variables = new ArrayList<Integer>();
long fixedPart = 0;
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
variables.add(i);
} else {
fixedPart++;
}
}
final String typeName = myGovernor.getGenNameTemplate(aData, source, myScope);
if (variables.size() > 0) {
final StringBuilder preamble = new StringBuilder();
final StringBuilder setType = new StringBuilder();
final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
setType.append(MessageFormat.format("{0}.setType(template_sel.COMPLEMENTED_LIST, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
if (template instanceof All_From_Template) {
template = ((All_From_Template) template).getAllFrom();
}
final Reference reference = ((SpecificValue_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
setType.append(" + ");
final ExpressionStruct expression = new ExpressionStruct();
reference.generateCode(aData, expression);
if (expression.preamble.length() > 0) {
preamble.append(expression.preamble);
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
setType.append(".get()");
}
break;
default:
break;
}
variableReferences[variables.get(v)] = expression.expression;
setType.append(expression.expression);
setType.append(".n_elem().getInt()");
}
source.append(preamble);
source.append(setType);
source.append(");\n");
final StringBuilder shifty = new StringBuilder();
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
switch(template.getTemplatetype()) {
case ALL_FROM:
{
// the template must be all from
final StringBuilder storedExpression = variableReferences[i];
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
String embeddedName = MessageFormat.format("{0}.listItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
break;
}
default:
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.listItem({3}{4});\n", typeName, tempId, name, i, shifty));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.listItem({1}{2})", name, i, shifty);
template.generateCodeInit(aData, source, embeddedName);
}
break;
}
}
} else {
source.append(MessageFormat.format("{0}.setType(template_sel.COMPLEMENTED_LIST, {1});\n", name, templates.getNofTemplates()));
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.listItem({3});\n", typeName, tempId, name, i));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.listItem({1})", name, i);
template.generateCodeInit(aData, source, embeddedName);
}
}
}
if (lengthRestriction != null) {
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
}
lengthRestriction.generateCodeInit(aData, source, name);
}
if (isIfpresent) {
source.append(name);
source.append(".set_ifPresent();\n");
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.
the class Signature_Type method checkThisTemplate.
@Override
public /**
* {@inheritDoc}
*/
boolean checkThisTemplate(final CompilationTimeStamp timestamp, final ITTCN3Template template, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
registerUsage(template);
template.setMyGovernor(this);
boolean selfReference = false;
switch(template.getTemplatetype()) {
case TEMPLATE_LIST:
final ITTCN3Template transformed = template.setTemplatetype(timestamp, Template_type.NAMED_TEMPLATE_LIST);
selfReference = checkThisNamedTemplateList(timestamp, (Named_Template_List) transformed, isModified, lhs);
break;
case NAMED_TEMPLATE_LIST:
selfReference = checkThisNamedTemplateList(timestamp, (Named_Template_List) template, isModified, lhs);
break;
case SPECIFIC_VALUE:
((SpecificValue_Template) template).checkSpecificValue(timestamp, false);
break;
default:
template.getLocation().reportSemanticError(MessageFormat.format(TEMPLATENOTALLOWED, template.getTemplateTypeName(), getTypename()));
break;
}
if (template.getLengthRestriction() != null) {
template.getLocation().reportSemanticError(MessageFormat.format(LENGTHRESTRICTIONNOTALLOWED, getTypename()));
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template in project titan.EclipsePlug-ins by eclipse.
the class SubsetMatch_Template method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
return;
}
lastTimeBuilt = aData.getBuildTimstamp();
aData.addBuiltinTypeImport("Base_Template.template_sel");
String ofTypeName;
switch(myGovernor.getTypetype()) {
case TYPE_SEQUENCE_OF:
ofTypeName = ((SequenceOf_Type) myGovernor).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_SET_OF:
ofTypeName = ((SetOf_Type) myGovernor).getOfType().getGenNameTemplate(aData, source, myScope);
break;
case TYPE_ARRAY:
ofTypeName = ((Array_Type) myGovernor).getElementType().getGenNameTemplate(aData, source, myScope);
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing subset match template `" + getFullName() + "''");
return;
}
final ArrayList<Integer> variables = new ArrayList<Integer>();
long fixedPart = 0;
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template templateListItem = templates.getTemplateByIndex(i);
if (templateListItem.getTemplatetype() == Template_type.ALL_FROM) {
variables.add(i);
} else {
fixedPart++;
}
}
if (variables.size() > 0) {
final StringBuilder preamble = new StringBuilder();
final StringBuilder setType = new StringBuilder();
final StringBuilder[] variableReferences = new StringBuilder[templates.getNofTemplates()];
setType.append(MessageFormat.format("{0}.setType(template_sel.SUBSET_MATCH, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) {
TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
if (template instanceof All_From_Template) {
template = ((All_From_Template) template).getAllFrom();
}
final Reference reference = ((SpecificValue_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
setType.append(" + ");
final ExpressionStruct expression = new ExpressionStruct();
reference.generateCode(aData, expression);
if (expression.preamble.length() > 0) {
preamble.append(expression.preamble);
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
if (assignment.getType(CompilationTimeStamp.getBaseTimestamp()).fieldIsOptional(reference.getSubreferences())) {
expression.expression.append(".get()");
}
break;
default:
break;
}
variableReferences[variables.get(v)] = expression.expression;
setType.append(expression.expression);
setType.append(".n_elem().getInt()");
}
source.append(preamble);
source.append(setType);
source.append(");\n");
final StringBuilder shifty = new StringBuilder();
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
switch(template.getTemplatetype()) {
case ALL_FROM:
{
// the template must be all from
final StringBuilder storedExpression = variableReferences[i];
source.append(MessageFormat.format("for (int i_i = 0, i_lim = {0}.n_elem().getInt(); i_i < i_lim; ++i_i ) '{'\n", storedExpression));
final String embeddedName = MessageFormat.format("{0}.setItem({1}{2} + i_i)", name, i, shifty);
((All_From_Template) template).generateCodeInitAllFrom(aData, source, embeddedName, storedExpression);
source.append("}\n");
shifty.append(MessageFormat.format("-1 + {0}.n_elem().getInt()", storedExpression));
break;
}
default:
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.setItem({3}{4});\n", ofTypeName, tempId, name, i, shifty));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.setItem({1}{2})", name, i, shifty);
template.generateCodeInit(aData, source, embeddedName);
}
break;
}
}
} else {
source.append(MessageFormat.format("{0}.setType(template_sel.SUBSET_MATCH, {1});\n", name, templates.getNofTemplates()));
for (int i = 0; i < templates.getNofTemplates(); i++) {
final TTCN3Template template = templates.getTemplateByIndex(i);
if (template.needsTemporaryReference()) {
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.setItem({3});\n", ofTypeName, tempId, name, i));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.setItem({1})", name, i);
template.generateCodeInit(aData, source, embeddedName);
}
}
}
if (lengthRestriction != null) {
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
}
lengthRestriction.generateCodeInit(aData, source, name);
}
if (isIfpresent) {
source.append(name);
source.append(".set_ifPresent();\n");
}
}
Aggregations