use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.
the class Return_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
genRestrictionCheck = false;
final Definition definition = myStatementBlock.getMyDefinition();
if (definition == null) {
location.reportSemanticError(USAGEINCONTROLPART);
return;
}
switch(definition.getAssignmentType()) {
case A_FUNCTION:
if (template != null) {
template.getLocation().reportSemanticError(UNEXPECTEDRETURNVALUE);
}
break;
case A_FUNCTION_RVAL:
final Type returnType = ((Def_Function) definition).getType(timestamp);
if (template == null) {
location.reportSemanticError(MessageFormat.format(MISSINGVALUE, returnType.getTypename()));
break;
}
if (!template.isValue(timestamp)) {
template.getLocation().reportSemanticError(SPECIFICVALUEEXPECTED);
break;
}
// General:
template.setMyGovernor(returnType);
final IValue value = template.getValue();
if (value != null) {
value.setMyGovernor(returnType);
returnType.checkThisValueRef(timestamp, value);
returnType.checkThisValue(timestamp, value, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false, false, true, false, false));
}
break;
case A_FUNCTION_RTEMP:
if (template == null) {
location.reportSemanticError(MessageFormat.format(MISSINGTEMPLATE, ((Def_Function) definition).getType(timestamp).getTypename()));
} else {
final Type returnType1 = ((Def_Function) definition).getType(timestamp);
template.setMyGovernor(returnType1);
final ITTCN3Template temporalTemplate1 = returnType1.checkThisTemplateRef(timestamp, template, Expected_Value_type.EXPECTED_TEMPLATE, null);
temporalTemplate1.checkThisTemplateGeneric(timestamp, returnType1, true, /* isModified */
true, /* allowOmit */
true, /* allowAnyOrOmit */
true, /* subCheck */
true, /* implicitOmit */
null);
genRestrictionCheck = TemplateRestriction.check(timestamp, definition, temporalTemplate1, null);
}
break;
case A_ALTSTEP:
if (template != null) {
template.getLocation().reportSemanticError(ALTSTEPRETURNINGVALUE);
}
break;
default:
location.reportSemanticError(MessageFormat.format(UNEXPETEDRETURNSTATEMENT, definition.getAssignmentName()));
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.
the class Start_Component_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
final Component_Type componentType = Port_Utility.checkComponentReference(timestamp, this, componentReference, false, false);
final Assignment assignment = functionInstanceReference.getRefdAssignment(timestamp, true);
if (assignment == null) {
return;
}
switch(assignment.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RTEMP:
case A_FUNCTION_RVAL:
break;
default:
functionInstanceReference.getLocation().reportSemanticError(MessageFormat.format(REFERENCETOFUNCTIONWASEXPECTED, assignment.getDescription()));
return;
}
final Def_Function function = (Def_Function) assignment;
if (!function.checkStartable(timestamp, getLocation())) {
return;
}
final IType runsOnType = function.getRunsOnType(timestamp);
if (componentType == null || runsOnType == null) {
return;
}
if (!runsOnType.isCompatible(timestamp, componentType, null, null, null)) {
componentReference.getLocation().reportSemanticError(MessageFormat.format(COMPONENTTYPEMISMATCH, componentType.getTypename(), function.getDescription(), runsOnType.getTypename()));
}
switch(function.getAssignmentType()) {
case A_FUNCTION_RTEMP:
functionInstanceReference.getLocation().reportSemanticWarning(MessageFormat.format(TEMPLATERETURN, function.getFullName(), function.getType(timestamp).getTypename()));
break;
case A_FUNCTION_RVAL:
{
IType type = function.getType(timestamp);
boolean returnTypeCorrect = false;
while (!returnTypeCorrect) {
if (type.hasDoneAttribute()) {
returnTypeCorrect = true;
break;
}
if (type instanceof IReferencingType) {
final IReferenceChain refChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IType refd = ((IReferencingType) type).getTypeRefd(timestamp, refChain);
refChain.release();
if (type != refd) {
type = refd;
} else {
break;
}
} else {
break;
}
}
if (!returnTypeCorrect) {
final String message = MessageFormat.format(RETURNWITHOUTDONE, function.getDescription(), function.getType(timestamp).getTypename());
functionInstanceReference.getLocation().reportSemanticWarning(message);
}
break;
}
default:
break;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.
the class FunctionContext method process_internal.
@Override
protected void process_internal() {
final Def_Function func = getNode();
final FormalParameterList fpl = func.getFormalParameterList();
final ParameterListVisitor vis = new ParameterListVisitor();
fpl.accept(vis);
paramIds = vis.getResult();
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.
the class RefersExpression method evaluateValue.
@Override
public /**
* {@inheritDoc}
*/
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return lastValue;
}
isErroneous = false;
lastTimeChecked = timestamp;
lastValue = this;
if (referred == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp) || referredAssignment == null) {
return lastValue;
}
if (isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
switch(referredAssignment.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RTEMP:
case A_FUNCTION_RVAL:
lastValue = new Function_Reference_Value((Def_Function) referredAssignment);
lastValue.copyGeneralProperties(this);
break;
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RTEMP:
case A_EXT_FUNCTION_RVAL:
lastValue = new Function_Reference_Value((Def_Extfunction) referredAssignment);
lastValue.copyGeneralProperties(this);
break;
case A_ALTSTEP:
lastValue = new Altstep_Reference_Value((Def_Altstep) referredAssignment);
lastValue.copyGeneralProperties(this);
break;
case A_TESTCASE:
lastValue = new Testcase_Reference_Value((Def_Testcase) referredAssignment);
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function in project titan.EclipsePlug-ins by eclipse.
the class RunsOnScopeReduction method process.
@Override
protected void process(IVisitableNode node, Problems problems) {
final Set<Identifier> definitions = new HashSet<Identifier>();
final Identifier componentIdentifier;
final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
final Identifier identifier;
boolean isTestCase = false;
if (node instanceof Def_Function) {
final Def_Function variable = (Def_Function) node;
final Component_Type componentType = variable.getRunsOnType(timestamp);
if (componentType == null) {
return;
}
componentIdentifier = componentType.getComponentBody().getIdentifier();
identifier = variable.getIdentifier();
} else if (node instanceof Def_Altstep) {
final Def_Altstep variable = (Def_Altstep) node;
final Component_Type componentType = variable.getRunsOnType(timestamp);
if (componentType == null) {
return;
}
componentIdentifier = componentType.getComponentBody().getIdentifier();
identifier = variable.getIdentifier();
} else {
final Def_Testcase variable = (Def_Testcase) node;
final Component_Type componentType = variable.getRunsOnType(timestamp);
if (componentType == null) {
return;
}
componentIdentifier = componentType.getComponentBody().getIdentifier();
identifier = variable.getIdentifier();
isTestCase = true;
}
final ReferenceCheck chek = new ReferenceCheck();
node.accept(chek);
definitions.addAll(chek.getIdentifiers());
if (definitions.isEmpty()) {
if (isTestCase) {
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.", componentIdentifier.getDisplayName()));
} else {
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used, can be removed.", componentIdentifier.getDisplayName()));
}
} else if (!definitions.contains(componentIdentifier)) {
ArrayList<Identifier> list = new ArrayList<Identifier>(definitions);
if (definitions.size() == 1) {
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use `{1}'' component.", componentIdentifier.getName(), list.get(0).getDisplayName()));
} else {
// FIXME: implement other cases
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used.", componentIdentifier.getDisplayName()));
}
}
}
Aggregations