use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList 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.TTCN3.definitions.ActualParameterList in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Testcase_Instance_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (dereferredValue == null) {
return;
}
final IValue temporalValue = dereferredValue.setLoweridToReference(timestamp);
IType type = temporalValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
if (type != null) {
type = type.getTypeRefdLast(timestamp);
}
if (type == null) {
return;
}
if (!Type_type.TYPE_TESTCASE.equals(type.getTypetype())) {
dereferredValue.getLocation().reportSemanticError(MessageFormat.format("A value of type testcase was expected in the argument of `derefers()'' instead of `{0}''", type.getTypename()));
return;
}
if (myStatementBlock.getScopeRunsOn() != null) {
dereferredValue.getLocation().reportSemanticError(DEFINITIONWITHOUTRUNSONEXPECTED);
return;
}
actualParameterList2 = new ActualParameterList();
final FormalParameterList formalParameterList = ((Testcase_Type) type).getFormalParameters();
formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameterList2);
if (timerValue != null) {
timerValue.setLoweridToReference(timestamp);
final Type_type temporalType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
switch(temporalType) {
case TYPE_REAL:
final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
if (!last.isUnfoldable(timestamp)) {
final Real_Value real = (Real_Value) last;
final double i = real.getValue();
if (i < 0.0) {
timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real.createStringRepresentation()));
} else if (real.isPositiveInfinity()) {
timerValue.getLocation().reportSemanticError(MessageFormat.format(FLOATEXPECTED2, real.createStringRepresentation()));
}
}
break;
default:
timerValue.getLocation().reportSemanticError(FLOATEXPECTED);
break;
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList in project titan.EclipsePlug-ins by eclipse.
the class Start_Referenced_Component_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
Component_Type compType = null;
if (componentReference != null) {
compType = Port_Utility.checkComponentReference(timestamp, this, componentReference, false, false);
}
if (dereferredValue == null) {
return;
}
switch(dereferredValue.getValuetype()) {
case EXPRESSION_VALUE:
if (Operation_type.REFERS_OPERATION.equals(((Expression_Value) dereferredValue).getOperationType())) {
dereferredValue.getLocation().reportSemanticError("A value of a function type was expected in the argument instead of a `refers' operation," + " which does not specify any function type.");
return;
}
break;
case TTCN3_NULL_VALUE:
case FAT_NULL_VALUE:
dereferredValue.getLocation().reportSemanticError("A value of a function type was expected in the argument instead of a `null' value, which does not specify any function type.");
return;
default:
break;
}
dereferredValue.setLoweridToReference(timestamp);
IType type = dereferredValue.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type != null) {
type = type.getTypeRefdLast(timestamp);
}
if (type == null || type.getIsErroneous(timestamp)) {
return;
}
if (!Type_type.TYPE_FUNCTION.equals(type.getTypetype())) {
dereferredValue.getLocation().reportSemanticError(MessageFormat.format("A value of type function was expected in the argument of `{0}''", type.getTypename()));
return;
}
final Function_Type functionType = (Function_Type) type;
if (functionType.isRunsOnSelf()) {
dereferredValue.getLocation().reportSemanticError("The argument cannot be a function reference with 'runs on self' clause");
return;
}
if (!functionType.checkStartable(timestamp, getLocation())) {
return;
}
final IType runsOnType = functionType.getRunsOnType(timestamp);
if (compType != null && runsOnType != null && !runsOnType.isCompatible(timestamp, compType, null, null, null)) {
final String message = MessageFormat.format("Component type mismatch: the component reference os of type `{0}'', but functions of type `{1}'' run on `{2}''", compType.getTypename(), functionType.getTypename(), runsOnType.getTypename());
componentReference.getLocation().reportSemanticError(message);
}
final IType returnType = functionType.getReturnType();
if (returnType != null) {
if (functionType.returnsTemplate()) {
dereferredValue.getLocation().reportSemanticWarning(MessageFormat.format("Function of type `{0}'' return a template of type `{1}''," + " which cannot be retrieved when the test component terminates", functionType.getTypename(), returnType.getTypename()));
} else {
IType lastType = returnType;
boolean returnTypeCorrect = false;
while (!returnTypeCorrect) {
if (lastType.hasDoneAttribute()) {
returnTypeCorrect = true;
break;
}
if (lastType instanceof IReferencingType) {
final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IType refd = ((IReferencingType) lastType).getTypeRefd(timestamp, refChain);
refChain.release();
if (lastType != refd) {
lastType = refd;
} else {
break;
}
} else {
break;
}
}
if (!returnTypeCorrect) {
dereferredValue.getLocation().reportSemanticWarning(MessageFormat.format("Return type of function type `{0}'' is `{1}'', which does not have the `done'' extension attibute." + " When the test component terminates the returnes value cannot be retrived with a `done'' operation", functionType.getTypename(), returnType.getTypename()));
}
}
}
actualParameterList2 = new ActualParameterList();
final FormalParameterList formalParameters = functionType.getFormalParameters();
if (!formalParameters.checkActualParameterList(timestamp, parameters, actualParameterList2)) {
actualParameterList2.setFullNameParent(this);
actualParameterList2.setMyScope(getMyScope());
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList in project titan.EclipsePlug-ins by eclipse.
the class Reference method generateConstRef.
public void generateConstRef(final JavaGenData aData, final ExpressionStruct expression) {
if (referredAssignment == null) {
// TODO: handle null
return;
}
boolean isTemplate;
switch(referredAssignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_FUNCTION_RVAL:
case A_EXT_FUNCTION_RVAL:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
isTemplate = false;
break;
case A_MODULEPAR_TEMPLATE:
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
isTemplate = true;
break;
default:
isTemplate = false;
break;
}
FormalParameterList formalParameterList;
switch(referredAssignment.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
formalParameterList = ((Def_Function) referredAssignment).getFormalParameterList();
break;
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
formalParameterList = ((Def_Extfunction) referredAssignment).getFormalParameterList();
break;
case A_TEMPLATE:
formalParameterList = ((Def_Template) referredAssignment).getFormalParameterList();
break;
default:
formalParameterList = null;
break;
}
final IType referedGovernor = referredAssignment.getType(CompilationTimeStamp.getBaseTimestamp());
// ha parameterezett
if (subReferences.get(0) instanceof ParameterisedSubReference) {
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
expression.expression.append("( ");
final ParameterisedSubReference temp = ((ParameterisedSubReference) subReferences.get(0));
final ActualParameterList actualParameterList = temp.getActualParameters();
if (actualParameterList != null) {
actualParameterList.generateCodeAlias(aData, expression);
}
expression.expression.append(" )");
} else if (formalParameterList != null) {
// the reference does not have an actual parameter list, but the assignment has
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
expression.expression.append("( ");
// FieldSubReference temp = ((FieldSubReference)subReferences.get(0));
for (int i = 0; i < formalParameterList.getNofParameters(); i++) {
if (i > 0) {
expression.expression.append(", ");
}
formalParameterList.getParameterByIndex(i).getDefaultValue().generateCode(aData, expression);
}
// temp.getActualParameters().generateCodeAlias(aData, expression);
expression.expression.append(" )");
} else {
// TODO add fuzzy handling
expression.expression.append(referredAssignment.getGenNameFromScope(aData, expression.expression, getMyScope(), null));
}
generateCode(aData, expression, isTemplate, true, referedGovernor);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList in project titan.EclipsePlug-ins by eclipse.
the class TemplateInstance method reArrangeInitCode.
/**
* Walks through the templateinstance recursively and appends the java
* initialization sequence of all (directly or indirectly) referenced
* non-parameterized templates and the default values of all
* parameterized templates to source and returns the resulting string.
* Only objects belonging to module usageModule are initialized.
*
* @param aData the structure to put imports into and get temporal variable names from.
* @param source the source for code generated
* @param usageModule the module where the template is to be used.
*/
public void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
if (derivedReference != null) {
final List<ISubReference> subreferences = derivedReference.getSubreferences();
if (subreferences != null && !subreferences.isEmpty() && subreferences.get(0) instanceof ParameterisedSubReference) {
final ParameterisedSubReference subreference = (ParameterisedSubReference) subreferences.get(0);
final ActualParameterList actualParameterList = subreference.getActualParameters();
if (actualParameterList != null) {
actualParameterList.reArrangeInitCode(aData, source, usageModule);
}
}
final Assignment assignment = derivedReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment == null) {
return;
}
if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE) {
final ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
if (formalParameterList != null) {
// the referred template is parameterized
// the embedded referenced templates shall be visited
template.reArrangeInitCode(aData, source, usageModule);
// FIXME implement
} else {
// its entire body has to be initialized now
if (assignment.getMyScope().getModuleScope() == usageModule) {
template.generateCodeInit(aData, source, template.get_lhs_name());
}
}
}
}
if (templateBody != null) {
templateBody.reArrangeInitCode(aData, source, usageModule);
}
}
Aggregations