use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ValueofExpression 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.values.expressions.ValueofExpression in project titan.EclipsePlug-ins by eclipse.
the class UnnecessaryValueof method process.
@Override
public void process(final IVisitableNode node, final Problems problems) {
if (node instanceof ValueofExpression) {
final ValueofExpression exp = (ValueofExpression) node;
final CompilationTimeStamp stamp = CompilationTimeStamp.getBaseTimestamp();
if (exp.getIsErroneous(stamp) || exp.isUnfoldable(stamp, null)) {
return;
}
final TemplateInstance inst = exp.getTemplateInstance();
if (inst != null && inst.getDerivedReference() == null && inst.getTemplateBody().isValue(stamp)) {
final String msg = MessageFormat.format(TEXT, inst.getTemplateBody().getValue().createStringRepresentation());
problems.report(exp.getLocation(), msg);
}
}
}
Aggregations