use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst in project titan.EclipsePlug-ins by eclipse.
the class Component_Type method checkExpressionOperandComponentRefernce.
/**
* Checks if the provided value is a reference to a component or not.
*
* @param timestamp the timestamp of the actual semantic check cycle.
* @param value the value to be checked
* @param expected_value the value kind expected from the actual parameter.
*/
public static void checkExpressionOperandComponentRefernce(final CompilationTimeStamp timestamp, final IValue value, final String operationName) {
switch(value.getValuetype()) {
case EXPRESSION_VALUE:
{
final Expression_Value expression = (Expression_Value) value;
if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, chain);
chain.release();
if (last == null || last.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
return;
}
IType type = last.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
}
break;
}
case REFERENCED_VALUE:
{
final Reference reference = ((Referenced_Value) value).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
value.setIsErroneous(true);
return;
}
switch(assignment.getAssignmentType()) {
case A_CONST:
{
IType type = ((Def_Const) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
IValue tempValue = ((Def_Const) assignment).getValue();
if (tempValue == null) {
return;
}
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
tempValue = tempValue.getReferencedSubValue(timestamp, reference, 1, chain);
chain.release();
if (tempValue == null) {
return;
}
chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
tempValue = tempValue.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.TTCN3_NULL_VALUE.equals(tempValue.getValuetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
value.setIsErroneous(true);
return;
}
if (!Value_type.EXPRESSION_VALUE.equals(tempValue.getValuetype())) {
return;
}
switch(((Expression_Value) tempValue).getOperationType()) {
case MTC_COMPONENT_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `mtc''", operationName));
value.setIsErroneous(true);
return;
case COMPONENT_NULL_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the `null'' component reference", operationName));
value.setIsErroneous(true);
return;
case SYSTEM_COMPONENT_OPERATION:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' refers to the component reference of the `system''", operationName));
value.setIsErroneous(true);
return;
default:
break;
}
break;
}
case A_EXT_CONST:
{
IType type = ((Def_ExternalConst) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_MODULEPAR:
{
IType type = ((Def_ModulePar) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_VAR:
{
IType type = ((Def_Var) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_FUNCTION_RVAL:
{
IType type = ((Def_Function) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_EXT_FUNCTION_RVAL:
{
IType type = ((Def_Extfunction) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
{
IType type = ((FormalParameter) assignment).getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
value.setIsErroneous(true);
return;
}
type = type.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp)) {
value.setIsErroneous(true);
// don't let spread an earlier mistake
return;
}
if (!Type_type.TYPE_COMPONENT.equals(type.getTypetype())) {
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'': Type mismatch: component reference was expected instead of `{1}''", operationName, type.getTypename()));
value.setIsErroneous(true);
return;
}
break;
}
default:
reference.getLocation().reportSemanticError(MessageFormat.format("The first operand of operation `{0}'' should be a component reference instead of `{1}''", operationName, assignment.getDescription()));
value.setIsErroneous(true);
return;
}
break;
}
default:
// the error was already reported if possible.
return;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_ExternalConst in project titan.EclipsePlug-ins by eclipse.
the class TypenameInDef method process.
@Override
protected void process(final IVisitableNode node, final Problems problems) {
if (!(node instanceof Def_Const) && !(node instanceof Def_ExternalConst) && !(node instanceof Def_Extfunction) && !(node instanceof Def_Function) && !(node instanceof Def_ModulePar) && !(node instanceof Def_Template) && !(node instanceof Def_Var_Template) && !(node instanceof Def_Var)) {
return;
}
final Definition s = (Definition) node;
check(s.getIdentifier(), s.getType(timestamp), s.getDescription(), problems);
}
Aggregations