use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Template method reArrangeInitCode.
@Override
public /**
* {@inheritDoc}
*/
void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
final ISubReference tempSubreference = reference.getSubreferences().get(0);
if (tempSubreference instanceof ParameterisedSubReference) {
// generate code for the templates that are used in the actual parameter
// list of the reference
final ActualParameterList actualParameterList = ((ParameterisedSubReference) tempSubreference).getActualParameters();
if (actualParameterList != null) {
actualParameterList.reArrangeInitCode(aData, source, usageModule);
}
}
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment.getAssignmentType() != Assignment_type.A_TEMPLATE) {
return;
}
ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
if (formalParameterList != null) {
// the reference points to a parameterized template
// we must perform the rearrangement for all non-parameterized templates
// that are referred by the parameterized template regardless of the
// sub-references of reference
template.reArrangeInitCode(aData, source, usageModule);
// be generated when the template's definition is reached)
if (assignment.getMyScope().getModuleScope() == usageModule) {
formalParameterList.generateCodeDefaultValues(aData, source);
}
} else {
// the reference points to a non-parameterized template
final List<ISubReference> subReferences = reference.getSubreferences();
if (subReferences != null && subReferences.size() > 1) {
// and perform the rearrangement for the referred field only
for (int i = 1; i < subReferences.size(); i++) {
final ISubReference subReference = subReferences.get(i);
if (subReference instanceof FieldSubReference) {
// stop if the body does not have fields
if (template.getTemplatetype() != Template_type.NAMED_TEMPLATE_LIST) {
break;
}
// the field reference can be followed
final Identifier fieldId = ((FieldSubReference) subReference).getId();
template = ((Named_Template_List) template).getNamedTemplate(fieldId).getTemplate();
} else {
// stop if the body is not a list
if (template.getTemplatetype() != Template_type.TEMPLATE_LIST) {
break;
}
IValue arrayIndex = ((ArraySubReference) subReference).getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
arrayIndex = arrayIndex.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (arrayIndex.getValuetype() != Value_type.INTEGER_VALUE) {
break;
}
// the index is available at compilation time
long index = ((Integer_Value) arrayIndex).getValue();
// index transformation in case of arrays
if (template.getMyGovernor().getTypetype() == Type_type.TYPE_ARRAY) {
index = index - ((Array_Type) template.getMyGovernor()).getDimension().getOffset();
}
template = ((Template_List) template).getTemplateByIndex((int) index);
}
}
}
// we should initialize its entire body
if (assignment.getMyScope().getModuleScope() == usageModule) {
template.generateCodeInit(aData, source, template.get_lhs_name());
}
}
if (lengthRestriction != null) {
lengthRestriction.reArrangeInitCode(aData, source, usageModule);
}
}
use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Template method getTemplateReferencedLast.
@Override
public /**
* {@inheritDoc}
*/
TTCN3Template getTemplateReferencedLast(final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) {
if (reference == null) {
setIsErroneous(true);
return this;
}
final boolean newChain = null == referenceChain;
IReferenceChain tempReferenceChain;
if (newChain) {
tempReferenceChain = ReferenceChain.getInstance(CIRCULARTEMPLATEREFERENCE, true);
} else {
tempReferenceChain = referenceChain;
}
TTCN3Template template = this;
final Assignment ass = reference.getRefdAssignment(timestamp, true);
if (ass != null) {
switch(ass.getAssignmentType()) {
case A_TEMPLATE:
tempReferenceChain.markState();
if (tempReferenceChain.add(this)) {
final ITTCN3Template refd = getTemplateReferenced(timestamp, tempReferenceChain);
if (refd != this) {
template = refd.getTemplateReferencedLast(timestamp, referenceChain);
}
} else {
setIsErroneous(true);
}
tempReferenceChain.previousState();
break;
case A_VAR_TEMPLATE:
case A_FUNCTION_RTEMP:
case A_MODULEPAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
return this;
default:
setIsErroneous(true);
}
} else {
setIsErroneous(true);
}
if (newChain) {
tempReferenceChain.release();
}
return template;
}
use of org.eclipse.titan.designer.AST.IReferenceChain in project titan.EclipsePlug-ins by eclipse.
the class SingleLenghtRestriction method checkArraySize.
@Override
public /**
* {@inheritDoc}
*/
void checkArraySize(final CompilationTimeStamp timestamp, final ArrayDimension dimension) {
if (lastTimeChecked == null || dimension.getIsErroneous(timestamp) || value == null) {
return;
}
boolean errorFlag = false;
final long arraySize = dimension.getSize();
final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, chain);
chain.release();
if (Value_type.INTEGER_VALUE.equals(last.getValuetype()) && !last.getIsErroneous(timestamp)) {
final BigInteger length = ((Integer_Value) last).getValueValue();
final int compareResult = length.compareTo(BigInteger.valueOf(arraySize));
if (compareResult != 0) {
final String message = MessageFormat.format("There number of elements allowed by the length restriction ({0}) contradicts the array size ({1})", length, arraySize);
value.getLocation().reportSemanticError(message);
errorFlag = true;
}
}
if (!errorFlag) {
getLocation().reportSemanticWarning("Length restriction is useless for an array template");
}
}
use of org.eclipse.titan.designer.AST.IReferenceChain 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.IReferenceChain in project titan.EclipsePlug-ins by eclipse.
the class Start_Referenced_Component_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct expression = new ExpressionStruct();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = dereferredValue.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (last.getValuetype() == Value_type.FUNCTION_REFERENCE_VALUE) {
Definition definition = ((Function_Reference_Value) last).getReferredFunction();
expression.expression.append(MessageFormat.format("{0}(", definition.getGenNameFromScope(aData, source, myScope, "start_")));
} else {
dereferredValue.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(".start(");
}
componentReference.generateCodeExpression(aData, expression, false);
if (actualParameterList2.getNofParameters() > 0) {
expression.expression.append(", ");
actualParameterList2.generateCodeNoAlias(aData, expression);
}
expression.expression.append(')');
expression.mergeExpression(source);
}
Aggregations