use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameter in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterTimer.
/**
* Checks if the actual parameter paired with this formal parameter is
* semantically correct as a timer parameter.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param actualParameter
* the template instance assigned as actual parameter to
* this formal parameter
* @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 checkActualParameterTimer(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
final IType parameterType = actualParameter.getType();
if (parameterType != null) {
actualParameter.getLocation().reportSemanticError(EXPLICITESPECIFICATIONFORTIMER);
actualParameter.checkType(timestamp, null);
}
final Reference derivedReference = actualParameter.getDerivedReference();
if (derivedReference != null) {
derivedReference.getLocation().reportSemanticError(INLINETEMPLATEFORTIMER);
actualParameter.checkDerivedReference(timestamp, null);
}
final ITTCN3Template template = actualParameter.getTemplateBody();
if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
final Reference reference = ((SpecificValue_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true, null);
if (assignment == null) {
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
switch(assignment.getAssignmentType()) {
case A_TIMER:
final ArrayDimensions dimensions = ((Def_Timer) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, reference, "timer", false, expectedValue);
} else if (reference.getSubreferences().size() > 1) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
}
break;
case A_PAR_TIMER:
if (reference.getSubreferences().size() > 1) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR2, assignment.getDescription()));
}
break;
default:
reference.getLocation().reportSemanticError(MessageFormat.format(TIMEREXPECTED1, assignment.getAssignmentName()));
break;
}
return new Referenced_ActualParameter(reference);
}
actualParameter.getLocation().reportSemanticError(TIMEREXPECTED2);
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameter in project titan.EclipsePlug-ins by eclipse.
the class FormalParameterList method collateLazyAndNonLazyActualParameters.
/**
* Read the parsed actual parameters, and collate the lazy and non-lazy actual parameters
* according to their associated formal parameters.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param parsedParameters
* the parsed actual parameters (may contain named, and unnamed parts too).
* @param actualLazyParameters
* the list of actual lazy parameters returned for later usage.
* @param actualNonLazyParameters
* the list of actual non lazy parameters returned for later usage.
*/
public final void collateLazyAndNonLazyActualParameters(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualLazyParameters, final ActualParameterList actualNonLazyParameters) {
final TemplateInstances unnamed = parsedParameters.getInstances();
final NamedParameters named = parsedParameters.getNamedParameters();
int nofLocated = unnamed.getNofTis();
final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
for (int i = 0, size = parameters.size(); i < size; i++) {
formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
}
final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
for (int i = 0, size = named.getNofParams(); i < size; i++) {
final NamedParameter namedParameter = named.getParamByIndex(i);
final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
final int isAt = formalParameterMap.get(formalParameter);
for (; nofLocated < isAt; nofLocated++) {
final NotUsed_Template temp = new NotUsed_Template();
if (!parameters.get(nofLocated).hasDefaultValue()) {
temp.setIsErroneous(true);
}
final TemplateInstance instance = new TemplateInstance(null, null, temp);
instance.setLocation(parsedParameters.getLocation());
finalUnnamed.addTemplateInstance(instance);
}
finalUnnamed.addTemplateInstance(namedParameter.getInstance());
nofLocated++;
}
finalUnnamed.setLocation(parsedParameters.getLocation());
final int upperLimit = (finalUnnamed.getNofTis() < parameters.size()) ? finalUnnamed.getNofTis() : parameters.size();
for (int i = 0; i < upperLimit; i++) {
final TemplateInstance instance = finalUnnamed.getInstanceByIndex(i);
final FormalParameter formalParameter = parameters.get(i);
if (instance.getType() == null && instance.getDerivedReference() == null && Template_type.TEMPLATE_NOTUSED.equals(instance.getTemplateBody().getTemplatetype())) {
final ActualParameter defaultValue = formalParameter.getDefaultValue();
final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
if (defaultValue != null && !defaultValue.getIsErroneous()) {
temp.setLocation(defaultValue.getLocation());
}
if (formalParameter.getIsLazy()) {
actualLazyParameters.addParameter(temp);
} else {
actualNonLazyParameters.addParameter(temp);
}
} else {
final ActualParameter actualParameter = formalParameter.checkActualParameter(timestamp, instance, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
actualParameter.setLocation(instance.getLocation());
if (formalParameter.getIsLazy()) {
actualLazyParameters.addParameter(actualParameter);
} else {
actualNonLazyParameters.addParameter(actualParameter);
}
}
}
for (int i = upperLimit; i < parameters.size(); i++) {
final FormalParameter formalParameter = parameters.get(i);
final ActualParameter defaultValue = formalParameter.getDefaultValue();
final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
if (defaultValue != null && !defaultValue.getIsErroneous()) {
temp.setLocation(defaultValue.getLocation());
}
if (formalParameter.getIsLazy()) {
actualLazyParameters.addParameter(temp);
} else {
actualNonLazyParameters.addParameter(temp);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameter in project titan.EclipsePlug-ins by eclipse.
the class All_From_Template method checkThisTemplateParameterizedReference.
private boolean checkThisTemplateParameterizedReference(final Reference reference, final Assignment lhs) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.isEmpty() || !(subreferences.get(0) instanceof ParameterisedSubReference)) {
return false;
}
final ParameterisedSubReference subReference = (ParameterisedSubReference) subreferences.get(0);
final ActualParameterList actualParameterList = subReference.getActualParameters();
if (actualParameterList == null) {
return false;
}
final int nofParameters = actualParameterList.getNofParameters();
for (int i = 0; i < nofParameters; i++) {
Reference parameterReference = null;
final ActualParameter actualParameter = actualParameterList.getParameter(i);
if (actualParameter instanceof Template_ActualParameter) {
TemplateInstance templateInstance = ((Template_ActualParameter) actualParameter).getTemplateInstance();
ITTCN3Template template = templateInstance.getTemplateBody();
template = template.setLoweridToReference(CompilationTimeStamp.getBaseTimestamp());
if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
parameterReference = ((Referenced_Template) template).getReference();
}
} else if (actualParameter instanceof Referenced_ActualParameter) {
parameterReference = ((Referenced_ActualParameter) actualParameter).getReference();
}
if (parameterReference != null) {
final Assignment assignment = parameterReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment == lhs) {
return true;
}
// check their parameters as well
switch(assignment.getAssignmentType()) {
case A_TEMPLATE:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
if (checkThisTemplateParameterizedReference(parameterReference, lhs)) {
return true;
}
break;
default:
break;
}
}
}
return false;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameter in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterTemplate.
private ActualParameter checkActualParameterTemplate(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter) {
actualParameter.check(timestamp, type);
final TemplateInstance instance = new TemplateInstance(actualParameter.getType(), actualParameter.getDerivedReference(), actualParameter.getTemplateBody());
final ActualParameter returnValue = new Template_ActualParameter(instance);
if (!Restriction_type.TR_NONE.equals(templateRestriction)) {
instance.checkRestriction(timestamp, this);
}
return returnValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameter in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterPort.
/**
* Checks if the actual parameter paired with this formal parameter is
* semantically correct as a port parameter.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param actualParameter
* the template instance assigned as actual parameter to
* this formal parameter
* @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 checkActualParameterPort(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
final Type parameterType = actualParameter.getType();
if (parameterType != null) {
parameterType.getLocation().reportSemanticWarning("Explicit type specification is useless for a port parameter");
actualParameter.checkType(timestamp, type);
}
final Reference derivedReference = actualParameter.getDerivedReference();
if (derivedReference != null) {
derivedReference.getLocation().reportSemanticError("An in-line modified temlate cannot be used as port parameter");
actualParameter.checkDerivedReference(timestamp, type);
}
final ITTCN3Template parameterTemplate = actualParameter.getTemplateBody();
if (!(parameterTemplate instanceof SpecificValue_Template) || !((SpecificValue_Template) parameterTemplate).isReference()) {
actualParameter.getLocation().reportSemanticError("Reference to a port or port parameter was expected for a port parameter");
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
final Reference reference = ((SpecificValue_Template) parameterTemplate).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
Type referredType;
switch(assignment.getAssignmentType()) {
case A_PORT:
final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, reference, "port", false, expectedValue);
} else if (reference.getSubreferences().size() > 1) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
}
referredType = ((Def_Port) assignment).getType(timestamp);
break;
case A_PAR_PORT:
if (reference.getSubreferences().size() > 1) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR3, assignment.getDescription()));
}
referredType = ((FormalParameter) assignment).getType(timestamp);
break;
default:
reference.getLocation().reportSemanticError(MessageFormat.format(PORTEXPECTED, assignment.getDescription()));
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
if (referredType != null && type != null && !type.isIdentical(timestamp, referredType)) {
reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH, type.getTypename(), referredType.getTypename()));
}
return new Referenced_ActualParameter(reference);
}
Aggregations