use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkComponentReference.
/**
* 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 source statement to report errors to.
* @param value
* the value reference to check.
* @param allowMtc
* tells if the mtc component is allowed or not.
* @param allowSystem
* tells if the system component is allowed or not.
*
* @return the referenced component type, or null if there were
* problems.
*/
public static Component_Type checkComponentReference(final CompilationTimeStamp timestamp, final Statement source, final IValue value, final boolean allowMtc, final boolean allowSystem) {
if (source.getMyStatementBlock() != null && source.getMyStatementBlock().getMyDefinition() == null) {
source.getLocation().reportSemanticError(COMPONENTOPINCONTROLPART);
}
if (value == null || value.getIsErroneous(timestamp)) {
return null;
}
final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
switch(last.getValuetype()) {
case REFERENCED_VALUE:
break;
case TTCN3_NULL_VALUE:
value.getLocation().reportSemanticError(MessageFormat.format(NULLCOMPONENTREFERENCE, source.getStatementName()));
break;
case EXPRESSION_VALUE:
final Expression_Value expression = (Expression_Value) last;
switch(expression.getOperationType()) {
case APPLY_OPERATION:
if (!Type_type.TYPE_COMPONENT.equals(last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE))) {
value.getLocation().reportSemanticError(VALUERETURNEXPECTED);
}
break;
case COMPONENT_NULL_OPERATION:
value.getLocation().reportSemanticError(MessageFormat.format(NULLCOMPONENTREFERENCE, source.getStatementName()));
break;
case MTC_COMPONENT_OPERATION:
if (!allowMtc) {
value.getLocation().reportSemanticError(MessageFormat.format(MTCCOMPONENTREFERENCE, source.getStatementName()));
}
break;
case SYSTEM_COMPONENT_OPERATION:
if (!allowSystem) {
value.getLocation().reportSemanticError(MessageFormat.format(SYSTEMCOMPONENTREFERENCE, source.getStatementName()));
}
break;
case SELF_COMPONENT_OPERATION:
break;
case COMPONENT_CREATE_OPERATION:
break;
case VALUEOF_OPERATION:
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
((ValueofExpression) expression).evaluateValue(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
referenceChain.release();
break;
default:
value.getLocation().reportSemanticError(COMPONENTREFERENCEEXPECTED);
return null;
}
break;
default:
value.getLocation().reportSemanticError(COMPONENTREFERENCEEXPECTED);
return null;
}
IType result = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (result == null) {
return null;
}
result = result.getTypeRefdLast(timestamp);
if (result.getIsErroneous(timestamp)) {
return null;
} else if (Type_type.TYPE_COMPONENT.equals(result.getTypetype())) {
return (Component_Type) result;
}
value.getLocation().reportSemanticError(MessageFormat.format(COMPONENTTYPEMISMATCH, result.getTypename()));
return null;
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class Port_Utility method checkPortReference.
/**
* Checks a port reference.
* Statement independent version.
*
* @param timestamp
* the timestamp of the actual build cycle.
* @param portReference
* the port reference to be checked
*
* @return the port type of the reference if it is a correct port
* reference, or null otherwise
*/
public static Port_Type checkPortReference(final CompilationTimeStamp timestamp, final Reference portReference) {
if (portReference == null) {
return null;
}
final Assignment assignment = portReference.getRefdAssignment(timestamp, true);
if (assignment == null || assignment.getIsErroneous()) {
return null;
}
IType result = null;
switch(assignment.getAssignmentType()) {
case A_PORT:
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("Reference to single {0} cannot have field or array sub-references", assignment.getDescription()));
}
result = ((Def_Port) assignment).getType(timestamp);
break;
case A_PAR_PORT:
if (portReference.getSubreferences().size() > 1) {
portReference.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} cannot have field or array sub-references", assignment.getDescription()));
}
result = ((FormalParameter) assignment).getType(timestamp);
break;
default:
portReference.getLocation().reportSemanticError(MessageFormat.format(PORTREFERENCEEXPECTED, assignment.getAssignmentName()));
break;
}
if (result == null) {
return null;
}
result = result.getTypeRefdLast(timestamp);
if (Type_type.TYPE_PORT.equals(result.getTypetype())) {
return (Port_Type) result;
}
return null;
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement 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);
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class If_Clause method check.
/**
* Does the semantic checking of this branch.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param unreachable
* boolean parameter telling if this if statement was
* already found unreachable by previous clauses or not
*
* @return true if following clauses are unreachable
*/
public boolean check(final CompilationTimeStamp timestamp, final boolean unreachable) {
if (unreachable) {
location.reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), NEVERREACH1);
}
boolean unreachable2 = unreachable;
if (expression != null) {
final IValue last = expression.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
final Type_type temporalType = last.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (!last.getIsErroneous(timestamp) && !Type_type.TYPE_UNDEFINED.equals(temporalType)) {
if (!Type_type.TYPE_BOOL.equals(temporalType)) {
last.getLocation().reportSemanticError(BOOLEANEXPECTED);
expression.setIsErroneous(true);
} else if (!expression.isUnfoldable(timestamp)) {
if (((Boolean_Value) last).getValue()) {
expression.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), UNNECESSARYCONTROL1);
unreachable2 = true;
} else {
expression.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), UNNECESSARYCONTROL2);
statementblock.getLocation().reportConfigurableSemanticProblem(Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTUNNECESSARYCONTROLS, GeneralConstants.WARNING, null), NEVERREACH2);
}
}
if (expression.getMyGovernor() == null) {
expression.setMyGovernor(new Boolean_Type());
}
}
}
if (statementblock != null) {
statementblock.check(timestamp);
}
return unreachable2;
}
use of org.eclipse.titan.designer.AST.TTCN3.statements.Statement in project titan.EclipsePlug-ins by eclipse.
the class StatementBlock method registerDefinition.
/**
* Registers a definition (for example new variable) into the list of
* definitions available in this statement block.
*
* Please note, that this is done while the semantic check is happening,
* as it must not be allowed to reach definitions not yet defined.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param definition
* the definition to register.
*/
public void registerDefinition(final CompilationTimeStamp timestamp, final Definition definition) {
if (definition == null) {
return;
}
final Identifier identifier = definition.getIdentifier();
if (identifier == null) {
return;
}
if (definitionMap == null) {
definitionMap = new HashMap<String, Definition>(3);
}
final String definitionName = identifier.getName();
if (definitionMap.containsKey(definitionName)) {
if (definition.getLocation() != null && definitionMap.get(definitionName).getLocation() != null) {
final Location otherLocation = definitionMap.get(definitionName).getLocation();
otherLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
definition.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
}
} else {
definitionMap.put(definitionName, definition);
if (parentScope != null && definition.getLocation() != null) {
if (parentScope.hasAssignmentWithId(timestamp, identifier)) {
definition.getLocation().reportSemanticError(MessageFormat.format(HIDINGSCOPEELEMENT, identifier.getDisplayName()));
final List<ISubReference> subReferences = new ArrayList<ISubReference>();
subReferences.add(new FieldSubReference(identifier));
final Reference reference = new Reference(null, subReferences);
final Assignment assignment = parentScope.getAssBySRef(timestamp, reference);
if (assignment != null && assignment.getLocation() != null) {
assignment.getLocation().reportSingularSemanticError(MessageFormat.format(HIDDENSCOPEELEMENT, identifier.getDisplayName()));
}
} else if (parentScope.isValidModuleId(identifier)) {
definition.getLocation().reportSemanticWarning(MessageFormat.format(HIDINGMODULEIDENTIFIER, identifier.getDisplayName()));
}
}
}
}
Aggregations