use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class IsChoosenExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeoperandsChecked != null && !lastTimeoperandsChecked.isLess(timestamp)) {
return;
}
lastTimeoperandsChecked = timestamp;
value = null;
identifier = null;
if (reference == null || reference.getSubreferences().size() < 2) {
setIsErroneous(true);
return;
}
final Reference tempReference = reference.newInstance();
tempReference.setFullNameParent(this);
tempReference.setMyScope(getMyScope());
final ISubReference subreference = tempReference.removeLastSubReference();
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
identifier = ((FieldSubReference) subreference).getId();
} else {
setIsErroneous(true);
return;
}
final Assignment assignment = tempReference.getRefdAssignment(timestamp, true);
if (assignment == null) {
setIsErroneous(true);
return;
}
IType governor;
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:
{
value = new Referenced_Value(tempReference);
value.setLocation(tempReference.getLocation());
value.setMyScope(getMyScope());
final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
value.setFullNameParent(tempNamedNode);
governor = value.getExpressionGovernor(timestamp, expectedValue);
if (governor == null) {
setIsErroneous(true);
} else {
value.setMyGovernor(governor);
final IValue tempValue2 = governor.checkThisValueRef(timestamp, value);
if (tempValue2.getIsErroneous(timestamp)) {
setIsErroneous(true);
}
}
break;
}
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
template = new Referenced_Template(tempReference);
template.setLocation(tempReference.getLocation());
template.setMyScope(getMyScope());
final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
template.setFullNameParent(tempNamedNode);
if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) || Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
governor = template.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
} else {
governor = template.getExpressionGovernor(timestamp, expectedValue);
}
if (governor == null) {
setIsErroneous(true);
} else {
template.setMyGovernor(governor);
final TTCN3Template last = template.getTemplateReferencedLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
}
}
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && !Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(CONSTANTREFERENCEEXPECTED, assignment.getDescription()));
} else {
template.getLocation().reportSemanticError(MessageFormat.format(STATICREFERENCEEXPECTED, assignment.getDescription()));
}
setIsErroneous(true);
}
break;
}
default:
tempReference.getLocation().reportSemanticError(MessageFormat.format(VALUETEMPLATEEXPECTED, assignment.getDescription()));
setIsErroneous(true);
return;
}
if (governor != null) {
governor = governor.getTypeRefdLast(timestamp);
if (!governor.getIsErroneous(timestamp)) {
CompField field = null;
switch(governor.getTypetype()) {
case TYPE_ASN1_CHOICE:
if (((ASN1_Choice_Type) governor).hasComponentWithName(identifier)) {
field = ((ASN1_Choice_Type) governor).getComponentByName(identifier);
}
break;
case TYPE_TTCN3_CHOICE:
if (((TTCN3_Choice_Type) governor).hasComponentWithName(identifier.getName())) {
field = ((TTCN3_Choice_Type) governor).getComponentByName(identifier.getName());
}
break;
case TYPE_OPENTYPE:
if (((Open_Type) governor).hasComponentWithName(identifier)) {
field = ((Open_Type) governor).getComponentByName(identifier);
}
break;
case TYPE_ANYTYPE:
if (((Anytype_Type) governor).hasComponentWithName(identifier.getName())) {
field = ((Anytype_Type) governor).getComponentByName(identifier.getName());
}
break;
default:
location.reportSemanticError(MessageFormat.format(OPERANDERROR, governor.getTypename()));
setIsErroneous(true);
return;
}
if (null == field) {
location.reportSemanticError(MessageFormat.format(MISSINGFIELD, governor.getTypename(), identifier.getDisplayName()));
setIsErroneous(true);
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class IsValueExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final TTCN3Template templateBody = templateInstance.getTemplateBody();
// FIXME actually a bit more complex
if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
final IValue value = ((SpecificValue_Template) templateBody).getValue();
// FIXME implement support for cast
value.generateCodeExpression(aData, expression, true);
} else {
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(".isValue()");
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class LengthofExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
final TTCN3Template templateBody = templateInstance.getTemplateBody();
// FIXME actually a bit more complex
if (templateInstance.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
final IValue value = ((SpecificValue_Template) templateBody).getValue();
// FIXME implement support for cast
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(".lengthOf()");
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class SpecificValue_Template method isValue.
@Override
public /**
* {@inheritDoc}
*/
boolean isValue(final CompilationTimeStamp timestamp) {
if (lengthRestriction != null || isIfpresent || getIsErroneous(timestamp)) {
return false;
}
if (realTemplate != null && realTemplate != this) {
return realTemplate.isValue(timestamp);
}
if (Value_type.FUNCTION_REFERENCE_VALUE.equals(specificValue.getValuetype())) {
final IType governor = ((Function_Reference_Value) specificValue).getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (governor == null) {
return true;
}
final IType last = governor.getTypeRefdLast(timestamp);
if (Type_type.TYPE_FUNCTION.equals(last.getTypetype()) && ((Function_Type) last).returnsTemplate()) {
return false;
}
} else if (Value_type.REFERENCED_VALUE.equals(specificValue.getValuetype())) {
final Reference reference = ((Referenced_Value) specificValue).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
return true;
}
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_TIMER:
case A_EXT_CONST:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_VAR:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
case A_MODULEPAR:
case A_MODULEPAR_TEMPLATE:
// runtime evaluation!
return true;
case A_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_INOUT:
case A_FUNCTION_RTEMP:
case A_VAR_TEMPLATE:
boolean result = true;
final Restriction_type rt = ((Definition) assignment).getTemplateRestriction();
if (TemplateRestriction.Restriction_type.TR_OMIT.equals(rt) || TemplateRestriction.Restriction_type.TR_PRESENT.equals(rt)) {
result = false;
}
final TTCN3Template ttemplate = getTemplateReferencedLast(timestamp);
if ((!ttemplate.equals(this)) && (ttemplate.isValue(timestamp))) {
// ok
return result;
} else {
return false;
}
default:
return false;
}
}
return true;
}
use of org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template in project titan.EclipsePlug-ins by eclipse.
the class SupersetMatch_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 superset 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.SUPERSET_MATCH, {1}", name, fixedPart));
for (int v = 0; v < variables.size(); v++) {
final TTCN3Template template = templates.getTemplateByIndex(variables.get(v));
// the template must be all from
TTCN3Template template2 = template;
if (template instanceof All_From_Template) {
template2 = ((All_From_Template) template).getAllFrom();
}
final Reference reference = ((SpecificValue_Template) template2).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.SUPERSET_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