use of org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkConnectionEndpoint.
/**
* Checks a reference to see if it really references a valid component
* type.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param source
* the statement to report an error to, in case it is in
* a control part.
* @param componentReference
* the reference of the component to be checked.
* @param portReference
* the reference to a port of the component to be
* checked.
* @param allowSystem
* tells if the system component should be allowed or not
* as an endpoint.
*
* @return the referenced component type, or null if there were
* problems.
*/
public static IType checkConnectionEndpoint(final CompilationTimeStamp timestamp, final Statement source, final Value componentReference, final PortReference portReference, final boolean allowSystem) {
final IType componentType = checkComponentReference(timestamp, source, componentReference, true, allowSystem);
if (portReference == null) {
return componentType;
}
if (componentType == null) {
// the component type can not be determined
final List<ISubReference> subreferences = portReference.getSubreferences();
if (subreferences.size() > 1) {
// check array indices
for (int i = 0; i < subreferences.size(); i++) {
final ISubReference subreference = subreferences.get(i);
if (subreference instanceof ArraySubReference) {
final Value value = ((ArraySubReference) subreference).getValue();
value.setLoweridToReference(timestamp);
final Type_type temporalType1 = value.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
switch(temporalType1) {
case TYPE_INTEGER:
{
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last1 = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
referenceChain.release();
if (!last1.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last1.getValuetype())) {
if (((Integer_Value) last1).signum() < 0) {
value.getLocation().reportSemanticError(ArraySubReference.NATIVEINTEGEREXPECTED);
value.setIsErroneous(true);
}
}
break;
}
case TYPE_UNDEFINED:
value.setIsErroneous(true);
break;
default:
if (!value.getIsErroneous(timestamp)) {
value.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
value.setIsErroneous(true);
}
break;
}
}
}
}
return null;
}
final ComponentTypeBody componentBody = ((Component_Type) componentType).getComponentBody();
portReference.setBaseScope(componentBody);
portReference.setComponent((Component_Type) componentType);
// for compatibility
portReference.getRefdAssignment(timestamp, false);
final Identifier portIdentifier = portReference.getId();
if (!componentBody.hasLocalAssignmentWithId(portIdentifier)) {
portReference.getLocation().reportSemanticError(MessageFormat.format(NOPORTWITHNAME, componentType.getTypename(), portIdentifier.getDisplayName()));
return null;
}
final Assignment assignment = componentBody.getLocalAssignmentById(portIdentifier);
if (assignment == null) {
return null;
}
if (!Assignment_type.A_PORT.semanticallyEquals(assignment.getAssignmentType())) {
portReference.getLocation().reportSemanticError(MessageFormat.format(DEFINITIONNOTPORT, portIdentifier.getDisplayName(), componentType.getTypename(), assignment.getAssignmentName()));
return null;
}
final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, portReference, "port", false, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
} else if (portReference.getSubreferences().size() > 1) {
portReference.getLocation().reportSemanticError(MessageFormat.format("Port `{0}'' is not an array. The reference cannot have field or array sub-references", portIdentifier.getDisplayName()));
}
Port_Type portType = ((Def_Port) assignment).getType(timestamp);
if (portType != null) {
final PortTypeBody portBody = portType.getPortBody();
if (PortType_type.PT_USER.equals(portBody.getPortType())) {
final IType providerType = portBody.getProviderType();
if (providerType instanceof Port_Type) {
portType = (Port_Type) providerType;
}
}
}
return portType;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Send_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
final Port_Type portType = Port_Utility.checkPortReference(timestamp, this, portReference);
if (parameter == null) {
return;
}
IType messageType = null;
boolean messageTypeDetermined = false;
if (portType != null) {
// the port type is known
portType.check(timestamp);
final PortTypeBody portTypeBody = portType.getPortBody();
final TypeSet outMessages = portTypeBody.getOutMessage();
if (OperationModes.OP_Procedure.equals(portTypeBody.getOperationMode())) {
portReference.getLocation().reportSemanticError(MessageFormat.format(SENDONPORT, portType.getTypename()));
} else if (outMessages != null) {
if (outMessages.getNofTypes() == 1) {
messageType = outMessages.getTypeByIndex(0);
} else {
messageType = Port_Utility.getOutgoingType(timestamp, parameter);
if (messageType == null) {
parameter.getLocation().reportSemanticError(UNKNOWNOUTGOINGMESSAGE);
} else {
final int nofCompatibleTypes = outMessages.getNofCompatibleTypes(timestamp, messageType);
if (nofCompatibleTypes == 0) {
parameter.getLocation().reportSemanticError(MessageFormat.format(TYPENOTPRESENT, messageType.getTypename(), portType.getTypename()));
} else if (nofCompatibleTypes > 1) {
parameter.getLocation().reportSemanticError(MessageFormat.format(TYPEISAMBIGUOUS, messageType.getTypename(), portType.getTypename()));
}
}
}
messageTypeDetermined = true;
} else {
portReference.getLocation().reportSemanticError(MessageFormat.format(NOOUTGOINGMESSAGETYPES, portType.getTypename()));
}
}
if (!messageTypeDetermined) {
messageType = Port_Utility.getOutgoingType(timestamp, parameter);
}
if (messageType != null) {
parameter.check(timestamp, messageType);
messageType = messageType.getTypeRefdLast(timestamp);
switch(messageType.getTypetype()) {
case TYPE_SIGNATURE:
parameter.getLocation().reportSemanticError(MessageFormat.format(SENDPARAMETERSIGNATURE, messageType.getTypename()));
break;
case TYPE_PORT:
parameter.getLocation().reportSemanticError(MessageFormat.format(SENDPARAMETERPORT, messageType.getTypename()));
break;
case TYPE_DEFAULT:
parameter.getLocation().reportSemanticError(MessageFormat.format(SENDPARAMETERDEFAULT, messageType.getTypename()));
break;
default:
break;
}
parameter.getTemplateBody().checkSpecificValue(timestamp, false);
Port_Utility.checkToClause(timestamp, this, portType, toClause);
}
lastTimeChecked = timestamp;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Reply_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
final Port_Type portType = Port_Utility.checkPortReference(timestamp, this, portReference);
IType signature = null;
boolean signatureDetermined = false;
if (portType != null) {
// the port type is known
final PortTypeBody portTypeBody = portType.getPortBody();
final TypeSet inSignatures = portTypeBody.getInSignatures();
if (OperationModes.OP_Message.equals(portTypeBody.getOperationMode())) {
portReference.getLocation().reportSemanticError(MessageFormat.format(REPLYONMESSAGEPORT, portType.getTypename()));
} else if (inSignatures != null) {
if (inSignatures.getNofTypes() == 1) {
signature = inSignatures.getTypeByIndex(0);
} else {
signature = Port_Utility.getOutgoingType(timestamp, parameter);
if (signature == null) {
parameter.getLocation().reportSemanticError(UNKNOWNINCOMINGSIGNATURE);
} else {
if (!inSignatures.hasType(timestamp, signature)) {
parameter.getLocation().reportSemanticError(MessageFormat.format(INCOMINGSIGNATURENOTPRESENT, signature.getTypename(), portType.getTypename()));
}
}
}
signatureDetermined = true;
} else {
portReference.getLocation().reportSemanticError(MessageFormat.format(NOINCOMINGSIGNATURES, portType.getTypename()));
}
}
if (!signatureDetermined) {
signature = Port_Utility.getOutgoingType(timestamp, parameter);
}
if (signature != null) {
parameter.check(timestamp, signature);
signature = signature.getTypeRefdLast(timestamp);
Type returnType = null;
switch(signature.getTypetype()) {
case TYPE_SIGNATURE:
if (((Signature_Type) signature).isNonblocking()) {
getLocation().reportSemanticError(MessageFormat.format("Operation `reply'' is not applicable to non-blocking signature `{0}''", signature.getTypename()));
} else {
returnType = ((Signature_Type) signature).getSignatureReturnType();
}
// checking the presence/absence of reply value
if (replyValue != null) {
if (returnType == null) {
final String message = MessageFormat.format("Unexpected return value. Signature `{0}'' does not have return type", signature.getTypename());
replyValue.getLocation().reportSemanticError(message);
}
} else if (returnType != null) {
getLocation().reportSemanticError(MessageFormat.format("Missing return value. Signature `{0}'' returns type `{1}''", signature.getTypename(), returnType.getTypename()));
}
break;
default:
parameter.getLocation().reportSemanticError(MessageFormat.format("The type of parameter is `{0}'', which is not a signature", signature.getTypename()));
break;
}
// checking the reply value if present
if (replyValue != null && returnType != null) {
replyValue.setMyGovernor(returnType);
final IValue temp = returnType.checkThisValueRef(timestamp, replyValue);
returnType.checkThisValue(timestamp, temp, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
}
Port_Utility.checkToClause(timestamp, this, portType, toClause);
}
lastTimeChecked = timestamp;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Raise_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
final Port_Type portType = Port_Utility.checkPortReference(timestamp, this, portReference);
IType signature = Port_Utility.checkSignatureReference(timestamp, signatureReference);
if (portType != null) {
final PortTypeBody portTypeBody = portType.getPortBody();
final TypeSet inSignatures = portTypeBody.getInSignatures();
if (OperationModes.OP_Message.equals(portTypeBody.getOperationMode())) {
portReference.getLocation().reportSemanticError(MessageFormat.format(RAISEONPORT, portType.getTypename()));
} else if (inSignatures != null) {
if (signature != null) {
if (!inSignatures.hasType(timestamp, signature)) {
portReference.getLocation().reportSemanticError(MessageFormat.format(SIGNATURENOTPRESENT, signature.getTypename(), portType.getTypename()));
}
} else if (inSignatures.getNofTypes() == 1) {
signature = inSignatures.getTypeByIndex(0).getTypeRefdLast(timestamp);
}
} else {
portReference.getLocation().reportSemanticError(MessageFormat.format(NOINCOMINGSIGNATURES, portType.getTypename()));
}
}
IType exception = null;
boolean exceptionDetermined = false;
if (signature != null) {
final SignatureExceptions exceptions = ((Signature_Type) signature).getSignatureExceptions();
if (exceptions == null) {
signatureReference.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREWITHOUTEXCEPTIONS, signature.getTypename()));
} else {
if (exceptions.getNofExceptions() == 1) {
exception = exceptions.getExceptionByIndex(0);
} else {
exception = Port_Utility.getOutgoingType(timestamp, parameter);
if (exception == null) {
parameter.getLocation().reportSemanticError(UNKNOWNEXCEPTIONTYPE);
} else {
final int nofCompatibleTypes = exceptions.getNofCompatibleExceptions(timestamp, exception);
if (nofCompatibleTypes == 0) {
parameter.getLocation().reportSemanticError(MessageFormat.format(TYPENOTONEXCEPTIONLIST, exception.getTypename(), signature.getTypename()));
} else if (nofCompatibleTypes > 1) {
parameter.getLocation().reportSemanticError(MessageFormat.format(AMBIGUOUSEXCEPTION, exception.getTypename(), signature.getTypename()));
}
}
}
exceptionDetermined = true;
}
}
if (!exceptionDetermined) {
exception = Port_Utility.getOutgoingType(timestamp, parameter);
}
if (exception != null) {
parameter.check(timestamp, exception);
exception = exception.getTypeRefdLast(timestamp);
switch(exception.getTypetype()) {
case TYPE_SIGNATURE:
parameter.getLocation().reportSemanticError(MessageFormat.format(SIGNATUREEXCEPTION, exception.getTypename()));
break;
case TYPE_PORT:
parameter.getLocation().reportSemanticError(MessageFormat.format(PORTEXCEPTION, exception.getTypename()));
break;
case TYPE_DEFAULT:
parameter.getLocation().reportSemanticError(MessageFormat.format(DEFAULTEXCEPTION, exception.getTypename()));
break;
default:
break;
}
}
parameter.getTemplateBody().checkSpecificValue(timestamp, false);
Port_Utility.checkToClause(timestamp, this, portType, toClause);
lastTimeChecked = timestamp;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.PortTypeBody in project titan.EclipsePlug-ins by eclipse.
the class Receive_Port_Statement method checkReceivingStatement.
/**
* Checks a port receiving statement.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param origin
* the original statement.
* @param statementName
* the name of the original statement.
* @param portReference
* the port reference.
* @param receiveParameter
* the receiving parameter.
* @param fromClause
* the from clause of the statement
* @param redirectValue
* the redirection value of the statement.
* @param redirectSender
* the sender redirection of the statement.
*/
public static void checkReceivingStatement(final CompilationTimeStamp timestamp, final Statement origin, final String statementName, final Reference portReference, final TemplateInstance receiveParameter, final TemplateInstance fromClause, final Reference redirectValue, final Reference redirectSender) {
final Port_Type portType = Port_Utility.checkPortReference(timestamp, origin, portReference);
if (receiveParameter == null) {
if (portType != null && Type_type.TYPE_PORT.equals(portType.getTypetype())) {
final PortTypeBody body = portType.getPortBody();
if (OperationModes.OP_Procedure.equals(body.getOperationMode())) {
portReference.getLocation().reportSemanticError(MessageFormat.format(MESSAGEBASEOPERATIONONPROCEDUREPORT, statementName, portType.getTypename()));
} else if (body.getInMessages() == null) {
portReference.getLocation().reportSemanticError(MessageFormat.format(NOINCOMINGMESSAGETYPES, portType.getTypename()));
}
}
if (redirectValue != null) {
redirectValue.getLocation().reportSemanticError(VALUEREDIRECTWITHOUTRECEIVEPARAMETER);
Port_Utility.checkValueRedirect(timestamp, redirectValue, null);
}
} else {
// determine the type of the incoming message
IType messageType = null;
boolean messageTypeDetermined = false;
final boolean[] valueRedirectChecked = new boolean[] { false };
if (portType != null) {
// the port type is known
final PortTypeBody portTypeBody = portType.getPortBody();
final TypeSet inMessages = portTypeBody.getInMessages();
if (OperationModes.OP_Procedure.equals(portTypeBody.getOperationMode())) {
portReference.getLocation().reportSemanticError(MessageFormat.format(RECEIVEONPORT, statementName, portType.getTypename()));
} else if (inMessages != null) {
if (inMessages.getNofTypes() == 1) {
messageType = inMessages.getTypeByIndex(0);
} else {
messageType = Port_Utility.getIncomingType(timestamp, receiveParameter, redirectValue, valueRedirectChecked);
if (messageType == null) {
receiveParameter.getLocation().reportSemanticError(UNKNOWNINCOMINGMESSAGE);
} else {
final int nofCompatibleTypes = inMessages.getNofCompatibleTypes(timestamp, messageType);
if (nofCompatibleTypes == 0) {
receiveParameter.getLocation().reportSemanticError(MessageFormat.format(TYPENOTPRESENT, messageType.getTypename(), portType.getTypename()));
} else if (nofCompatibleTypes > 1) {
receiveParameter.getLocation().reportSemanticError(MessageFormat.format(TYPEISAMBIGUOUS, messageType.getTypename(), portType.getTypename()));
}
}
}
messageTypeDetermined = true;
} else {
portReference.getLocation().reportSemanticError(MessageFormat.format(NOINCOMINGMESSAGETYPES, portType.getTypename()));
}
} else if (portReference == null) {
// any port
receiveParameter.getLocation().reportSemanticError(MessageFormat.format(ANYPORTWITHPARAMETER, statementName));
if (redirectValue != null) {
redirectValue.getLocation().reportSemanticError(MessageFormat.format(RECEIVEWITHVALUEREDIRECT, statementName));
}
}
if (!messageTypeDetermined) {
messageType = Port_Utility.getIncomingType(timestamp, receiveParameter, redirectValue, valueRedirectChecked);
}
if (messageType != null) {
receiveParameter.check(timestamp, messageType);
if (!valueRedirectChecked[0]) {
Port_Utility.checkValueRedirect(timestamp, redirectValue, messageType);
}
}
}
Port_Utility.checkFromClause(timestamp, origin, portType, fromClause, redirectSender);
}
Aggregations