use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkValueRedirect.
/**
* Calculates the type of a variable when it was to be used as a value
* redirect target.
*
* @param timestamp
* the timestamp of the actual build cycle.
* @param redirectValue
* the reference to which the redirection is targeted
* @param type
* the expected type of the value redirection.
*
* @return the the type of a variable referenced when it was to be used
* as a value redirection target.
*/
public static IType checkValueRedirect(final CompilationTimeStamp timestamp, final Reference redirectValue, final IType type) {
if (redirectValue == null) {
return null;
}
final IType variableType = redirectValue.checkVariableReference(timestamp);
if (type != null && variableType != null && !type.isCompatible(timestamp, variableType, null, null, null)) {
redirectValue.getLocation().reportSemanticError(MessageFormat.format(VALUEREDIRECTTYPEMISSMATCH, type.getTypename(), variableType.getTypename()));
}
final Assignment assignment = redirectValue.getRefdAssignment(timestamp, true);
if (assignment != null) {
switch(assignment.getAssignmentType()) {
case A_PAR_VAL:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
((FormalParameter) assignment).setWritten();
break;
case A_VAR:
((Def_Var) assignment).setWritten();
break;
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
((FormalParameter) assignment).setWritten();
break;
case A_VAR_TEMPLATE:
((Def_Var_Template) assignment).setWritten();
break;
default:
break;
}
}
return variableType;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class All_From_Template method getNofTemplatesNotAnyornone.
/**
* Calculates the number of list members which are not the any or none
* symbol.
*
* @return the number calculated.
*/
public int getNofTemplatesNotAnyornone(final CompilationTimeStamp timestamp) {
int result = 0;
if (allFrom == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.SPECIFIC_VALUE.equals(allFrom.getTemplatetype())) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
if (!((SpecificValue_Template) allFrom).isReference()) {
allFrom.getLocation().reportSemanticError(REFERENCEEXPECTED);
allFrom.setIsErroneous(true);
return result;
}
// isReference branch:
final Reference reference = ((SpecificValue_Template) allFrom).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
allFrom.getLocation().reportSemanticError("Assignment not found");
allFrom.setIsErroneous(true);
return result;
}
ITTCN3Template body = null;
switch(assignment.getAssignmentType()) {
case A_TEMPLATE:
body = ((Def_Template) assignment).getTemplate(timestamp);
break;
case A_VAR_TEMPLATE:
body = ((Def_Var_Template) assignment).getInitialValue();
break;
case A_CONST:
final IValue value = ((Def_Const) assignment).getValue();
return getNofValues(value, timestamp);
case A_MODULEPAR:
final IValue mvalue = ((Def_ModulePar) assignment).getDefaultValue();
return getNofValues(mvalue, timestamp);
case A_MODULEPAR_TEMPLATE:
body = ((Def_ModulePar_Template) assignment).getDefaultTemplate();
break;
default:
return result;
}
if (body == null) {
ErrorReporter.INTERNAL_ERROR();
return result;
}
if (!Template_type.TEMPLATE_LIST.equals(body.getTemplatetype())) {
allFrom.getLocation().reportSemanticError("Template must be a record of or a set of values");
allFrom.setIsErroneous(true);
return result;
}
result = ((Template_List) body).getNofTemplatesNotAnyornone(timestamp);
return result;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterByReference.
/**
* Checks if the actual parameter paired with this formal parameter is
* semantically correct as a reference parameter.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param parameter
* the template instance assigned as actual parameter to
* this formal parameter
* @param isTemplate
* true if the formal parameter is template, false
* otherwise
* @param expectedValue
* the value kind expected from the actual parameter.
*
* @return the actual parameter created from the value, or null if there
* was an error.
*/
private ActualParameter checkActualParameterByReference(final CompilationTimeStamp timestamp, final TemplateInstance parameter, final boolean isTemplate, final Expected_Value_type expectedValue) {
final Type parameterType = parameter.getType();
if (parameterType != null) {
parameterType.getLocation().reportSemanticWarning(MessageFormat.format(EXPLICITESPECIFICATIONFORREFERENCE, getAssignmentName()));
parameter.checkType(timestamp, type);
}
final Reference derivedReference = parameter.getDerivedReference();
if (derivedReference != null) {
derivedReference.getLocation().reportSemanticError(MessageFormat.format(INLINETEMPLATEFORREFERENCE, getAssignmentName()));
parameter.checkDerivedReference(timestamp, type);
}
String expectedString;
if (isTemplate) {
expectedString = "template variable or template parameter";
} else {
expectedString = "variable or value parameter";
}
final ITTCN3Template template = parameter.getTemplateBody();
if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
final Reference reference = ((SpecificValue_Template) template).getReference();
reference.setUsedOnLeftHandSide();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
boolean assignmentTypeIsCorrect;
switch(assignment.getAssignmentType()) {
case A_PAR_VAL_IN:
((FormalParameter) assignment).useAsLValue(reference);
assignmentTypeIsCorrect = !isTemplate;
break;
case A_PAR_VAL:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
((FormalParameter) assignment).setWritten();
assignmentTypeIsCorrect = !isTemplate;
break;
case A_VAR:
((Def_Var) assignment).setWritten();
assignmentTypeIsCorrect = !isTemplate;
break;
case A_PAR_TEMP_IN:
assignmentTypeIsCorrect = isTemplate;
((FormalParameter) assignment).useAsLValue(reference);
break;
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
((FormalParameter) assignment).setWritten();
assignmentTypeIsCorrect = isTemplate;
break;
case A_VAR_TEMPLATE:
((Def_Var_Template) assignment).setWritten();
assignmentTypeIsCorrect = isTemplate;
break;
default:
assignmentTypeIsCorrect = false;
break;
}
if (assignmentTypeIsCorrect) {
final IType fieldType = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (fieldType != null) {
if (type != null && !type.isCompatible(timestamp, fieldType, null, null, null)) {
reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH2, expectedString, type.getTypename(), fieldType.getTypename()));
} else if (type != null && type.getSubtype() != null && fieldType.getSubtype() != null && !type.getSubtype().isCompatible(timestamp, fieldType.getSubtype())) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBTYPEMISMATCH, type.getSubtype().toString(), fieldType.getSubtype().toString()));
}
if (!reference.getSubreferences().isEmpty() && reference.refersToStringElement()) {
reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED3, fieldType.getTypename()));
}
}
} else {
reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED1, expectedString, getAssignmentName(), assignment.getDescription()));
}
final ActualParameter returnActualParameter = new Referenced_ActualParameter(reference);
if (isTemplate && assignmentTypeIsCorrect) {
TemplateRestriction.Restriction_type refdRestriction;
switch(assignment.getAssignmentType()) {
case A_VAR_TEMPLATE:
{
final Def_Var_Template temp = (Def_Var_Template) assignment;
refdRestriction = temp.getTemplateRestriction();
break;
}
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
final FormalParameter par = (FormalParameter) assignment;
refdRestriction = par.getTemplateRestriction();
break;
}
default:
return returnActualParameter;
}
TemplateRestriction.getSubRestriction(refdRestriction, timestamp, reference);
if (templateRestriction != refdRestriction) {
final boolean preCallCheck = TemplateRestriction.isLessRestrictive(templateRestriction, refdRestriction);
final boolean postCallCheck = TemplateRestriction.isLessRestrictive(refdRestriction, templateRestriction);
if (preCallCheck || postCallCheck) {
final String message = MessageFormat.format("Inadequate restriction on the referenced {0} `{1}'' this may cause a dynamic test case error at runtime", assignment.getAssignmentName(), reference.getDisplayName());
reference.getLocation().reportSemanticWarning(message);
}
}
// written C++ code
if (!Restriction_type.TR_NONE.equals(refdRestriction)) {
switch(myParameterList.getMyDefinition().getAssignmentType()) {
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
// here
break;
default:
break;
}
}
}
return returnActualParameter;
}
parameter.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED2, expectedString, getAssignmentName()));
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class Assignment_Statement method checkTemplateRestriction.
/**
* Checks the template restriction on the assignment referenced on the left hand side.
*
* @param timestamp the time stamp of the actual semantic check cycle.
*/
private void checkTemplateRestriction(final CompilationTimeStamp timestamp) {
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass == null) {
return;
}
switch(ass.getAssignmentType()) {
case A_VAR_TEMPLATE:
templateRestriction = ((Def_Var_Template) ass).getTemplateRestriction();
break;
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
templateRestriction = ((FormalParameter) ass).getTemplateRestriction();
break;
default:
templateRestriction = TemplateRestriction.Restriction_type.TR_NONE;
break;
}
templateRestriction = TemplateRestriction.getSubRestriction(templateRestriction, timestamp, reference);
generateRestrictionCheck = TemplateRestriction.check(timestamp, (Definition) ass, template, reference);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template in project titan.EclipsePlug-ins by eclipse.
the class Type method checkThisTemplateRef.
@Override
public /**
* {@inheritDoc}
*/
ITTCN3Template checkThisTemplateRef(final CompilationTimeStamp timestamp, final ITTCN3Template t, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
switch(t.getTemplatetype()) {
case SUPERSET_MATCH:
case SUBSET_MATCH:
final IType it1 = getTypeRefdLast(timestamp);
final Type_type tt = it1.getTypetype();
if (Type_type.TYPE_SEQUENCE_OF.equals(tt) || Type_type.TYPE_SET_OF.equals(tt)) {
return t;
} else {
t.getLocation().reportSemanticError(MessageFormat.format("{0} cannot be used for type {1}", t.getTemplateTypeName(), getTypename()));
t.setIsErroneous(true);
return t;
}
case SPECIFIC_VALUE:
// cont below
break;
default:
return t;
}
// Case of specific value:
final ITTCN3Template template = t;
IValue value = ((SpecificValue_Template) template).getSpecificValue();
if (value == null) {
return template;
}
value = checkThisValueRef(timestamp, value);
switch(value.getValuetype()) {
case REFERENCED_VALUE:
// FIXME: referenceChain or null?
final Assignment assignment = ((Referenced_Value) value).getReference().getRefdAssignment(timestamp, false, referenceChain);
if (assignment == null) {
template.setIsErroneous(true);
} else {
switch(assignment.getAssignmentType()) {
case A_VAR_TEMPLATE:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
template.setIsErroneous(true);
}
final IType type = ((Def_Var_Template) assignment).getType(timestamp);
switch(type.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_UTF8STRING:
case TYPE_NUMERICSTRING:
case TYPE_PRINTABLESTRING:
case TYPE_TELETEXSTRING:
case TYPE_VIDEOTEXSTRING:
case TYPE_IA5STRING:
case TYPE_GRAPHICSTRING:
case TYPE_VISIBLESTRING:
case TYPE_GENERALSTRING:
case TYPE_UNIVERSALSTRING:
case TYPE_BMPSTRING:
case TYPE_UTCTIME:
case TYPE_GENERALIZEDTIME:
case TYPE_OBJECTDESCRIPTOR:
{
final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
final int nofSubreferences = subReferences.size();
if (nofSubreferences > 1) {
final ISubReference subreference = subReferences.get(nofSubreferences - 1);
if (subreference instanceof ArraySubReference) {
template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
template.setIsErroneous(true);
return template;
}
}
break;
}
default:
break;
}
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
case A_CONST:
IType type1;
if (assignment instanceof Value_Assignment) {
type1 = ((Value_Assignment) assignment).getType(timestamp);
} else {
type1 = ((Def_Const) assignment).getType(timestamp);
}
switch(type1.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_UTF8STRING:
case TYPE_NUMERICSTRING:
case TYPE_PRINTABLESTRING:
case TYPE_TELETEXSTRING:
case TYPE_VIDEOTEXSTRING:
case TYPE_IA5STRING:
case TYPE_GRAPHICSTRING:
case TYPE_VISIBLESTRING:
case TYPE_GENERALSTRING:
case TYPE_UNIVERSALSTRING:
case TYPE_BMPSTRING:
case TYPE_UTCTIME:
case TYPE_GENERALIZEDTIME:
case TYPE_OBJECTDESCRIPTOR:
{
final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
final int nofSubreferences = subReferences.size();
if (nofSubreferences > 1) {
final ISubReference subreference = subReferences.get(nofSubreferences - 1);
if (subreference instanceof ArraySubReference) {
template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
template.setIsErroneous(true);
return template;
}
}
break;
}
default:
break;
}
break;
case A_TEMPLATE:
case A_MODULEPAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RTEMP:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
template.setIsErroneous(true);
}
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
default:
break;
}
}
break;
case EXPRESSION_VALUE:
{
final Expression_Value expression = (Expression_Value) value;
if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
IType type = expression.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (type == null) {
break;
}
type = type.getTypeRefdLast(timestamp);
if (type != null && Type_type.TYPE_FUNCTION.equals(type.getTypetype()) && ((Function_Type) type).returnsTemplate()) {
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_INVOKE);
}
}
break;
}
default:
break;
}
return template;
}
Aggregations