use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class Def_Extfunction method checkPrototype.
/**
* Checks the prototype attribute set for this external function
* definition.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
*/
private void checkPrototype(final CompilationTimeStamp timestamp) {
if (EncodingPrototype_type.NONE.equals(prototype)) {
return;
}
// checking formal parameter list
if (EncodingPrototype_type.CONVERT.equals(prototype)) {
if (formalParList.getNofParameters() == 1) {
final FormalParameter parameter = formalParList.getParameterByIndex(0);
switch(parameter.getRealAssignmentType()) {
case A_PAR_VAL:
case A_PAR_VAL_IN:
inputType = parameter.getType(timestamp);
break;
default:
{
final String message = MessageFormat.format("The parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), parameter.getAssignmentName());
parameter.getLocation().reportSemanticError(message);
break;
}
}
} else {
final String message = MessageFormat.format("The external function must have one parameter instead of {0} for attribute `prototype({1})''", formalParList.getNofParameters(), prototype.getName());
formalParList.getLocation().reportSemanticError(message);
}
} else if (formalParList.getNofParameters() == 2) {
final FormalParameter firstParameter = formalParList.getParameterByIndex(0);
if (EncodingPrototype_type.SLIDING.equals(prototype)) {
if (Assignment_type.A_PAR_VAL_INOUT.semanticallyEquals(firstParameter.getRealAssignmentType())) {
final Type firstParameterType = firstParameter.getType(timestamp);
final IType last = firstParameterType.getTypeRefdLast(timestamp);
if (last.getIsErroneous(timestamp)) {
inputType = firstParameterType;
} else {
switch(last.getTypetypeTtcn3()) {
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_BITSTRING:
inputType = firstParameterType;
break;
default:
{
final String message = MessageFormat.format("The type of the first parameter must be `octetstring'' or `charstring'' for attribute `prototype({0})''", prototype.getName());
firstParameter.getLocation().reportSemanticError(message);
break;
}
}
}
} else {
firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `inout'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
}
} else {
if (Assignment_type.A_PAR_VAL_IN.semanticallyEquals(firstParameter.getRealAssignmentType())) {
inputType = firstParameter.getType(timestamp);
} else {
firstParameter.getLocation().reportSemanticError(MessageFormat.format("The first parameter must be an `in'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), firstParameter.getAssignmentName()));
}
}
final FormalParameter secondParameter = formalParList.getParameterByIndex(1);
if (Assignment_type.A_PAR_VAL_OUT.semanticallyEquals(secondParameter.getRealAssignmentType())) {
outputType = secondParameter.getType(timestamp);
} else {
secondParameter.getLocation().reportSemanticError(MessageFormat.format("The second parameter must be an `out'' value parameter for attribute `prototype({0})'' instead of {1}", prototype.getName(), secondParameter.getAssignmentName()));
}
} else {
formalParList.getLocation().reportSemanticError(MessageFormat.format("The function must have two parameters for attribute `prototype({0})'' instead of {1}", prototype.getName(), formalParList.getNofParameters()));
}
// checking the return type
if (EncodingPrototype_type.FAST.equals(prototype)) {
if (returnType != null) {
returnType.getLocation().reportSemanticError(MessageFormat.format("The external function cannot have return type fo attribute `prototype({0})''", prototype.getName()));
}
} else {
if (returnType == null) {
location.reportSemanticError(MessageFormat.format("The external function must have a return type for attribute `prototype({0})''", prototype.getName()));
} else {
if (Assignment_type.A_FUNCTION_RTEMP.semanticallyEquals(assignmentType)) {
returnType.getLocation().reportSemanticError(MessageFormat.format("The external function must return a value instead of a template for attribute `prototype({0})''", prototype.getName()));
}
if (EncodingPrototype_type.CONVERT.equals(prototype)) {
outputType = returnType;
} else {
final IType last = returnType.getTypeRefdLast(timestamp);
if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_INTEGER.equals(last.getTypetypeTtcn3())) {
returnType.getLocation().reportSemanticError(MessageFormat.format("The return type of the function must be `integer'' instead of `{0}'' for attribute `prototype({1})''", returnType.getTypename(), prototype.getName()));
}
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter 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.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class FormalParameterList method checkActualParameterList.
/**
* Check if a list of parsed actual parameters is semantically correct
* according to a list of formal parameters (the called entity).
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param parsedParameters
* the parsed actual parameters (may contain named, and
* unnamed parts too).
* @param actualParameters
* the list of actual parameters returned for later
* usage.
*
* @return true if a semantic error was found, false otherwise
*/
public final boolean checkActualParameterList(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualParameters) {
parsedParameters.setFormalParList(this);
checkUniqueness(timestamp);
boolean isErroneous = false;
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);
if (parameterMap != null && parameterMap.containsKey(namedParameter.getName().getName())) {
final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
final int isAt = formalParameterMap.get(formalParameter);
if (isAt >= nofLocated) {
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++;
} else {
isErroneous = true;
if (isAt >= unnamed.getNofTis()) {
namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is out of order", namedParameter.getName().getDisplayName()));
} else {
namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is assigned more than once", namedParameter.getName().getDisplayName()));
}
}
} else {
String name;
switch(myDefinition.getAssignmentType()) {
case A_TYPE:
switch(((Def_Type) myDefinition).getType(timestamp).getTypetype()) {
case TYPE_FUNCTION:
name = "Function reference";
break;
case TYPE_ALTSTEP:
name = "Altstep reference";
break;
case TYPE_TESTCASE:
name = "Testcase reference";
break;
default:
name = "";
break;
}
break;
default:
name = myDefinition.getAssignmentName();
break;
}
isErroneous = true;
namedParameter.getLocation().reportSemanticError(MessageFormat.format("{0} `{1}'' has no formal parameter with name `{2}''", name, myDefinition.getFullName(), namedParameter.getName().getDisplayName()));
}
}
if (isErroneous) {
return false;
}
finalUnnamed.setLocation(parsedParameters.getLocation());
return checkActualParameterList(timestamp, finalUnnamed, actualParameters);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class Assignment_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
isErroneous = false;
selfReference = false;
templateRestriction = Restriction_type.TR_NONE;
generateRestrictionCheck = false;
if (reference == null) {
return;
}
reference.setUsedOnLeftHandSide();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null || assignment.getIsErroneous()) {
isErroneous = true;
return;
}
if (template == null) {
return;
}
switch(assignment.getAssignmentType()) {
case A_PAR_VAL_IN:
((FormalParameter) assignment).useAsLValue(reference);
if (template.isValue(timestamp)) {
// TODO: isValue should be checked within the previous line! This is double check!
final IValue temporalValue = template.getValue();
checkVarAssignment(timestamp, assignment, temporalValue);
template.setMyGovernor(temporalValue.getMyGovernor());
break;
} else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
// TODO: convert (x) to x to compilation!
break;
} else {
template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
template.setIsErroneous(true);
return;
}
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
case A_PAR_VAL:
((FormalParameter) assignment).setWritten();
if (template.isValue(timestamp)) {
// TODO: isValue should be checked within the previous line! This is double check!
final IValue temporalValue = template.getValue();
checkVarAssignment(timestamp, assignment, temporalValue);
template.setMyGovernor(temporalValue.getMyGovernor());
break;
} else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
// TODO: convert (x) to x to compilation!
break;
} else {
template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
template.setIsErroneous(true);
return;
}
// break
case A_VAR:
((Def_Var) assignment).setWritten();
if (template.getIsErroneous(timestamp)) {
return;
}
final IValue temporalValue = template.getValue();
if (temporalValue != null) {
checkVarAssignment(timestamp, assignment, temporalValue);
template.setMyGovernor(temporalValue.getMyGovernor());
break;
} else if (Template_type.VALUE_LIST.equals(template.getTemplatetype()) && ((ValueList_Template) template).getNofTemplates() == 1) {
break;
} else {
template.getLocation().reportSemanticError(TEMPLATEASSIGNMENTTOVALUE);
template.setIsErroneous(true);
return;
}
case A_PAR_TEMP_IN:
((FormalParameter) assignment).useAsLValue(reference);
checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
break;
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
((FormalParameter) assignment).setWritten();
checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
break;
case A_VAR_TEMPLATE:
((Def_Var_Template) assignment).setWritten();
checkTemplateAssignment(timestamp, assignment, Expected_Value_type.EXPECTED_TEMPLATE, null);
break;
default:
reference.getLocation().reportSemanticError(MessageFormat.format(VARIABLEREFERENCEEXPECTED, assignment.getAssignmentName()));
reference.setIsErroneous(true);
isErroneous = true;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class Reference method checkVariableReference.
/**
* Checks and returns the type of the variable referred to by this
* reference.
* <p>
* This is used to detect the type of value redirects.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
*
* @return the type of the referred variable or null in case of
* problems.
*/
public IType checkVariableReference(final CompilationTimeStamp timestamp) {
final Assignment assignment = getRefdAssignment(timestamp, true);
if (assignment == null) {
return null;
}
IType type;
switch(assignment.getAssignmentType()) {
case A_PAR_VAL_IN:
((FormalParameter) assignment).useAsLValue(this);
type = ((FormalParameter) assignment).getType(timestamp);
((FormalParameter) assignment).setUsed();
break;
case A_PAR_VAL:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
type = ((FormalParameter) assignment).getType(timestamp);
((FormalParameter) assignment).setUsed();
break;
case A_VAR:
type = ((Def_Var) assignment).getType(timestamp);
((Def_Var) assignment).setUsed();
break;
default:
getLocation().reportSemanticError(MessageFormat.format(VARIABLEXPECTED, assignment.getDescription()));
setIsErroneous(true);
return null;
}
final IType result = type.getFieldType(timestamp, this, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null, false);
if (result != null && subReferences != null && refersToStringElement()) {
getLocation().reportSemanticError(MessageFormat.format(STRINGELEMENTUNUSABLE, result.getTypename()));
setIsErroneous(true);
}
return result;
}
Aggregations