use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Return_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
// TODO more nuanced code generation
getLocation().release_location_object(aData, source);
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append("return ");
// No return value:
if (template == null) {
expression.mergeExpression(source);
return;
}
final Definition definition = myStatementBlock.getMyDefinition();
if (definition.getAssignmentType() == Assignment_type.A_FUNCTION_RVAL && template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
final IValue value = ((SpecificValue_Template) template).getValue();
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
final Definition myDefinition = myStatementBlock.getMyDefinition();
if (myDefinition.getTemplateRestriction() != TemplateRestriction.Restriction_type.TR_NONE && genRestrictionCheck) {
template.generateCodeExpression(aData, expression, myDefinition.getTemplateRestriction());
} else {
template.generateCodeExpression(aData, expression, Restriction_type.TR_NONE);
}
}
expression.mergeExpression(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Scope method checkRunsOnScope.
/**
* Checks that operations that can only be executed in definitions that
* have a runs on scope, are really executed in such a definition. And
* that the required runs on component is compatible with the runs on
* component of the definition.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param type
* the fat type to check (used or referred to by the
* location).
* @param errorLocation
* the location to report the error to.
* @param operation
* the name of the operation.
*/
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final IType type, final ILocateableNode errorLocation, final String operation) {
if (type == null) {
return;
}
Component_Type referencedComponent;
String typename;
switch(type.getTypetype()) {
case TYPE_FUNCTION:
referencedComponent = ((Function_Type) type).getRunsOnType(timestamp);
typename = "function";
break;
case TYPE_ALTSTEP:
referencedComponent = ((Altstep_Type) type).getRunsOnType(timestamp);
typename = "altstep";
break;
default:
return;
}
if (referencedComponent == null) {
return;
}
final RunsOnScope runsOnScope = getScopeRunsOn();
if (runsOnScope == null) {
errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED2, operation, typename, type.getTypename(), referencedComponent.getTypename()));
} else {
final Component_Type localType = runsOnScope.getComponentType();
if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH2, localType.getTypename(), operation, typename, type.getTypename(), referencedComponent.getTypename()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class Scope method checkRunsOnScope.
/**
* Checks that operations that can only be executed in definitions that
* have a runs on scope, are really executed in such a definition. And
* that the required runs on component is compatible with the runs on
* component of the definition.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param assignment
* the assignment to check (used or referred to by the
* statement).
* @param errorLocation
* the location to report the error to.
* @param operation
* the name of the operation.
*/
public void checkRunsOnScope(final CompilationTimeStamp timestamp, final Assignment assignment, final ILocateableNode errorLocation, final String operation) {
Component_Type referencedComponent;
switch(assignment.getAssignmentType()) {
case A_ALTSTEP:
referencedComponent = ((Def_Altstep) assignment).getRunsOnType(timestamp);
break;
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
referencedComponent = ((Def_Function) assignment).getRunsOnType(timestamp);
break;
case A_TESTCASE:
referencedComponent = ((Def_Testcase) assignment).getRunsOnType(timestamp);
break;
default:
return;
}
if (referencedComponent == null) {
return;
}
final RunsOnScope runsOnScope = getScopeRunsOn();
if (runsOnScope == null) {
errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONREQUIRED, operation, assignment.getDescription(), referencedComponent.getTypename()));
} else {
final Component_Type localType = runsOnScope.getComponentType();
if (!referencedComponent.isCompatible(timestamp, localType, null, null, null)) {
errorLocation.getLocation().reportSemanticError(MessageFormat.format(RUNSONMISSMATCH, localType.getTypename(), operation, assignment.getDescription(), referencedComponent.getTypename()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class PortReference method getRefdAssignment.
@Override
public Assignment getRefdAssignment(final CompilationTimeStamp timestamp, final boolean checkParameterList) {
if (myScope == null || componentType == null) {
return null;
}
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return referredAssignment;
}
// just for error compatibility with...
super.getRefdAssignment(timestamp, checkParameterList);
final Identifier portIdentifier = getId();
final ComponentTypeBody componentBody = componentType.getComponentBody();
if (!componentBody.hasLocalAssignmentWithId(portIdentifier)) {
getLocation().reportSemanticError(MessageFormat.format(NOPORTWITHNAME, componentType.getTypename(), portIdentifier.getDisplayName()));
setIsErroneous(true);
referredAssignment = null;
lastTimeChecked = timestamp;
return null;
}
referredAssignment = componentBody.getLocalAssignmentById(portIdentifier);
if (referredAssignment != null) {
referredAssignment.check(timestamp);
referredAssignment.setUsed();
if (referredAssignment instanceof Definition) {
final String referingModuleName = getMyScope().getModuleScope().getName();
if (!((Definition) referredAssignment).referingHere.contains(referingModuleName)) {
((Definition) referredAssignment).referingHere.add(referingModuleName);
}
}
}
lastTimeChecked = timestamp;
return referredAssignment;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definition in project titan.EclipsePlug-ins by eclipse.
the class TemplateRestriction method check.
public static boolean check(final CompilationTimeStamp timestamp, final Definition definition, final ITTCN3Template template, final Reference ref) {
if (template.getIsErroneous(timestamp)) {
return false;
}
final ITTCN3Template last = template.getTemplateReferencedLast(timestamp);
Restriction_type tr = definition.getTemplateRestriction();
tr = getSubRestriction(tr, timestamp, ref);
switch(tr) {
case TR_NONE:
return false;
case TR_VALUE:
return last.checkValueomitRestriction(timestamp, definition.getAssignmentName(), false, template.getLocation());
case TR_OMIT:
return last.checkValueomitRestriction(timestamp, definition.getAssignmentName(), true, template.getLocation());
case TR_PRESENT:
return last.checkPresentRestriction(timestamp, definition.getAssignmentName(), template.getLocation());
default:
return false;
}
}
Aggregations