use of org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value 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.Expression_Value in project titan.EclipsePlug-ins by eclipse.
the class Unmap_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
IType portType1;
IType portType2;
PortTypeBody body1;
PortTypeBody body2;
boolean cref1IsTestcomponents = false;
boolean cref1IsSystem = false;
boolean cref2IsTestcomponent = false;
boolean cref2IsSystem = false;
portType1 = Port_Utility.checkConnectionEndpoint(timestamp, this, componentReference1, portReference1, true);
if (portType1 == null) {
body1 = null;
} else {
body1 = ((Port_Type) portType1).getPortBody();
if (body1.isInternal()) {
componentReference1.getLocation().reportSemanticWarning(MessageFormat.format("Port type `{0}'' was marked as `internal''", portType1.getTypename()));
}
}
final IValue configReference1 = componentReference1.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (Value_type.EXPRESSION_VALUE.equals(configReference1.getValuetype())) {
switch(((Expression_Value) configReference1).getOperationType()) {
case MTC_COMPONENT_OPERATION:
cref1IsTestcomponents = true;
break;
case SELF_COMPONENT_OPERATION:
cref1IsTestcomponents = true;
break;
case COMPONENT_CREATE_OPERATION:
cref1IsTestcomponents = true;
break;
case SYSTEM_COMPONENT_OPERATION:
cref1IsSystem = true;
break;
default:
break;
}
}
portType2 = Port_Utility.checkConnectionEndpoint(timestamp, this, componentReference2, portReference2, true);
if (portType2 == null) {
body2 = null;
} else {
body2 = ((Port_Type) portType2).getPortBody();
if (body2.isInternal()) {
componentReference2.getLocation().reportSemanticWarning(MessageFormat.format("Port type `{0}'' was marked as `internal''", portType2.getTypename()));
}
}
final IValue configReference2 = componentReference2.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (Value_type.EXPRESSION_VALUE.equals(configReference2.getValuetype())) {
switch(((Expression_Value) configReference2).getOperationType()) {
case MTC_COMPONENT_OPERATION:
cref2IsTestcomponent = true;
break;
case SELF_COMPONENT_OPERATION:
cref2IsTestcomponent = true;
break;
case COMPONENT_CREATE_OPERATION:
cref2IsTestcomponent = true;
break;
case SYSTEM_COMPONENT_OPERATION:
cref2IsSystem = true;
break;
default:
break;
}
}
lastTimeChecked = timestamp;
if (cref1IsTestcomponents && cref2IsTestcomponent) {
location.reportSemanticError(Map_Statement.BOTHENDSARETESTCOMPONENTPORTS);
return;
}
if (cref1IsSystem && cref2IsSystem) {
location.reportSemanticError(Map_Statement.BOTHENDSARESYSTEMPORTS);
return;
}
if (portType1 == null || portType2 == null || body1 == null || body2 == null) {
return;
}
if (cref1IsTestcomponents || cref2IsSystem) {
if (!body1.isMappable(timestamp, body2)) {
location.reportSemanticError(MessageFormat.format(Map_Statement.INCONSISTENTMAPPING1, portType1.getTypename(), portType2.getTypename()));
body1.reportMappingErrors(timestamp, body2);
}
} else if (cref2IsTestcomponent || cref1IsSystem) {
if (!body2.isMappable(timestamp, body1)) {
location.reportSemanticError(MessageFormat.format(Map_Statement.INCONSISTENTMAPPING2, portType1.getTypename(), portType2.getTypename()));
body2.reportMappingErrors(timestamp, body1);
}
} else {
// we don't know which is the system port
if (!body1.isMappable(timestamp, body2) && !body2.isMappable(timestamp, body1)) {
location.reportSemanticError(MessageFormat.format(Map_Statement.INCONSISTENTMAPPING3, portType1.getTypename(), portType2.getTypename()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value in project titan.EclipsePlug-ins by eclipse.
the class Kill_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
aData.addCommonLibraryImport("TTCN_Runtime");
final ExpressionStruct expression = new ExpressionStruct();
if (componentReference == null) {
aData.addBuiltinTypeImport("TitanComponent");
expression.expression.append("TTCN_Runtime.kill_component(TitanComponent.ALL_COMPREF)");
} else {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = componentReference.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (last.getValuetype() == Value_type.REFERENCED_VALUE) {
// the argument is a simple component reference
last.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(".kill()");
} else {
boolean refers_to_self = false;
if (last.getValuetype() == Value_type.EXPRESSION_VALUE) {
// the argument is a special component reference (mtc, self, etc.)
switch(((Expression_Value) last).getOperationType()) {
case MTC_COMPONENT_OPERATION:
{
Definition myDefinition = myStatementBlock.getMyDefinition();
if (myDefinition != null && myDefinition.getAssignmentType() == Assignment_type.A_TESTCASE) {
refers_to_self = true;
}
break;
}
case SELF_COMPONENT_OPERATION:
refers_to_self = true;
default:
break;
}
}
if (refers_to_self) {
expression.expression.append("TTCN_Runtime.kill_execution()");
} else {
expression.expression.append("TTCN_Runtime.kill_component(");
last.generateCodeExpression(aData, expression, false);
expression.expression.append(')');
}
}
}
expression.mergeExpression(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value in project titan.EclipsePlug-ins by eclipse.
the class Map_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
IType portType1;
IType portType2;
PortTypeBody body1 = null;
PortTypeBody body2 = null;
boolean cref1IsTestcomponents = false;
boolean cref1IsSystem = false;
boolean cref2IsTestcomponent = false;
boolean cref2IsSystem = false;
portType1 = Port_Utility.checkConnectionEndpoint(timestamp, this, componentReference1, portReference1, true);
if (portType1 != null) {
body1 = ((Port_Type) portType1).getPortBody();
if (body1.isInternal()) {
componentReference1.getLocation().reportSemanticWarning(MessageFormat.format("Port type `{0}'' was marked as `internal''", portType1.getTypename()));
}
// sets the referenced assignment of this reference
portReference1.getRefdAssignment(timestamp, false);
}
if (componentReference1 != null) {
final IValue configReference1 = componentReference1.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (Value_type.EXPRESSION_VALUE.equals(configReference1.getValuetype())) {
switch(((Expression_Value) configReference1).getOperationType()) {
case MTC_COMPONENT_OPERATION:
cref1IsTestcomponents = true;
break;
case SELF_COMPONENT_OPERATION:
cref1IsTestcomponents = true;
break;
case COMPONENT_CREATE_OPERATION:
cref1IsTestcomponents = true;
break;
case SYSTEM_COMPONENT_OPERATION:
cref1IsSystem = true;
break;
default:
break;
}
}
}
portType2 = Port_Utility.checkConnectionEndpoint(timestamp, this, componentReference2, portReference2, true);
if (portType2 != null) {
body2 = ((Port_Type) portType2).getPortBody();
if (body2.isInternal()) {
componentReference2.getLocation().reportSemanticWarning(MessageFormat.format("Port type `{0}'' was marked as `internal''", portType2.getTypename()));
}
// sets the referenced assignment of this reference
portReference2.getRefdAssignment(timestamp, false);
}
if (componentReference2 != null) {
final IValue configReference2 = componentReference2.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (Value_type.EXPRESSION_VALUE.equals(configReference2.getValuetype())) {
switch(((Expression_Value) configReference2).getOperationType()) {
case MTC_COMPONENT_OPERATION:
cref2IsTestcomponent = true;
break;
case SELF_COMPONENT_OPERATION:
cref2IsTestcomponent = true;
break;
case COMPONENT_CREATE_OPERATION:
cref2IsTestcomponent = true;
break;
case SYSTEM_COMPONENT_OPERATION:
cref2IsSystem = true;
break;
default:
break;
}
}
}
lastTimeChecked = timestamp;
if (cref1IsTestcomponents && cref2IsTestcomponent) {
location.reportSemanticError(BOTHENDSARETESTCOMPONENTPORTS);
return;
}
if (cref1IsSystem && cref2IsSystem) {
location.reportSemanticError(BOTHENDSARESYSTEMPORTS);
return;
}
if (body1 == null || body2 == null || portType1 == null || portType2 == null) {
return;
}
if (cref1IsTestcomponents || cref2IsSystem) {
if (!body1.isMappable(timestamp, body2)) {
location.reportSemanticError(MessageFormat.format(INCONSISTENTMAPPING1, portType1.getTypename(), portType2.getTypename()));
body1.reportMappingErrors(timestamp, body2);
}
} else if (cref2IsTestcomponent || cref1IsSystem) {
if (!body2.isMappable(timestamp, body1)) {
location.reportSemanticError(MessageFormat.format(INCONSISTENTMAPPING2, portType1.getTypename(), portType2.getTypename()));
body2.reportMappingErrors(timestamp, body1);
}
} else {
// we don't know which one is the system port
if (!body1.isMappable(timestamp, body2) && !body2.isMappable(timestamp, body1)) {
location.reportSemanticError(MessageFormat.format(INCONSISTENTMAPPING3, portType1.getTypename(), portType2.getTypename()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value in project titan.EclipsePlug-ins by eclipse.
the class Type method checkThisTemplateRef.
@Override
public /**
* {@inheritDoc}
*/
ITTCN3Template checkThisTemplateRef(final CompilationTimeStamp timestamp, final ITTCN3Template t, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
switch(t.getTemplatetype()) {
case SUPERSET_MATCH:
case SUBSET_MATCH:
final IType it1 = getTypeRefdLast(timestamp);
final Type_type tt = it1.getTypetype();
if (Type_type.TYPE_SEQUENCE_OF.equals(tt) || Type_type.TYPE_SET_OF.equals(tt)) {
return t;
} else {
t.getLocation().reportSemanticError(MessageFormat.format("{0} cannot be used for type {1}", t.getTemplateTypeName(), getTypename()));
t.setIsErroneous(true);
return t;
}
case SPECIFIC_VALUE:
// cont below
break;
default:
return t;
}
// Case of specific value:
final ITTCN3Template template = t;
IValue value = ((SpecificValue_Template) template).getSpecificValue();
if (value == null) {
return template;
}
value = checkThisValueRef(timestamp, value);
switch(value.getValuetype()) {
case REFERENCED_VALUE:
// FIXME: referenceChain or null?
final Assignment assignment = ((Referenced_Value) value).getReference().getRefdAssignment(timestamp, false, referenceChain);
if (assignment == null) {
template.setIsErroneous(true);
} else {
switch(assignment.getAssignmentType()) {
case A_VAR_TEMPLATE:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
template.setIsErroneous(true);
}
final IType type = ((Def_Var_Template) assignment).getType(timestamp);
switch(type.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_UTF8STRING:
case TYPE_NUMERICSTRING:
case TYPE_PRINTABLESTRING:
case TYPE_TELETEXSTRING:
case TYPE_VIDEOTEXSTRING:
case TYPE_IA5STRING:
case TYPE_GRAPHICSTRING:
case TYPE_VISIBLESTRING:
case TYPE_GENERALSTRING:
case TYPE_UNIVERSALSTRING:
case TYPE_BMPSTRING:
case TYPE_UTCTIME:
case TYPE_GENERALIZEDTIME:
case TYPE_OBJECTDESCRIPTOR:
{
final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
final int nofSubreferences = subReferences.size();
if (nofSubreferences > 1) {
final ISubReference subreference = subReferences.get(nofSubreferences - 1);
if (subreference instanceof ArraySubReference) {
template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
template.setIsErroneous(true);
return template;
}
}
break;
}
default:
break;
}
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
case A_CONST:
IType type1;
if (assignment instanceof Value_Assignment) {
type1 = ((Value_Assignment) assignment).getType(timestamp);
} else {
type1 = ((Def_Const) assignment).getType(timestamp);
}
switch(type1.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_UTF8STRING:
case TYPE_NUMERICSTRING:
case TYPE_PRINTABLESTRING:
case TYPE_TELETEXSTRING:
case TYPE_VIDEOTEXSTRING:
case TYPE_IA5STRING:
case TYPE_GRAPHICSTRING:
case TYPE_VISIBLESTRING:
case TYPE_GENERALSTRING:
case TYPE_UNIVERSALSTRING:
case TYPE_BMPSTRING:
case TYPE_UTCTIME:
case TYPE_GENERALIZEDTIME:
case TYPE_OBJECTDESCRIPTOR:
{
final List<ISubReference> subReferences = ((Referenced_Value) value).getReference().getSubreferences();
final int nofSubreferences = subReferences.size();
if (nofSubreferences > 1) {
final ISubReference subreference = subReferences.get(nofSubreferences - 1);
if (subreference instanceof ArraySubReference) {
template.getLocation().reportSemanticError(MessageFormat.format("Reference to {0} can not be indexed", assignment.getDescription()));
template.setIsErroneous(true);
return template;
}
}
break;
}
default:
break;
}
break;
case A_TEMPLATE:
case A_MODULEPAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RTEMP:
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(REFTOVALUEEXPECTED, assignment.getDescription()));
template.setIsErroneous(true);
}
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_REFD);
default:
break;
}
}
break;
case EXPRESSION_VALUE:
{
final Expression_Value expression = (Expression_Value) value;
if (Operation_type.APPLY_OPERATION.equals(expression.getOperationType())) {
IType type = expression.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (type == null) {
break;
}
type = type.getTypeRefdLast(timestamp);
if (type != null && Type_type.TYPE_FUNCTION.equals(type.getTypetype()) && ((Function_Type) type).returnsTemplate()) {
return template.setTemplatetype(timestamp, Template_type.TEMPLATE_INVOKE);
}
}
break;
}
default:
break;
}
return template;
}
Aggregations