use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class LazyChecker method process.
public void process(final IVisitableNode node) {
// This variable indicates occurrence of Return_Statement.
haveToContinue = true;
// Collect and store FormalParameters.
formalParameterCollector = new RelevantFormalParameterCollector();
node.accept(formalParameterCollector);
// Build structure.
final RelevantNodeBuilder relevantNodeBuilder = new RelevantNodeBuilder(node);
node.accept(relevantNodeBuilder);
// Evaluate tree and return with FormalParameters which have to be evaluated.
final Set<FormalParameter> shouldBeEvaluated = relevantNodeBuilder.collectRelevantReferences();
for (final FormalParameter formalParameter : formalParameterCollector.getItems()) {
if (!shouldBeEvaluated.contains(formalParameter) && !formalParameter.getIsLazy()) {
lazyParameterList.add(formalParameter);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class T3Doc method getCommentStringBasedOnReference.
public static String getCommentStringBasedOnReference(final DeclarationCollector declarationCollector, final List<DeclarationCollectionHelper> collected, final IEditorPart targetEditor, final IRegion hoverRegion, final IReferenceParser referenceParser, final ITextViewer textViewer) {
if (!T3Doc.isT3DocEnable()) {
return null;
}
Reference ref = declarationCollector.getReference();
if (ref == null) {
return null;
}
if ((ref.getMyScope() instanceof NamedBridgeScope || ref.getMyScope() instanceof FormalParameterList) && !collected.isEmpty()) {
DeclarationCollectionHelper declaration = collected.get(0);
if (declaration.node instanceof TTCN3_Sequence_Type || declaration.node instanceof FormalParameter) {
final IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
final Module tempModule = projectSourceParser.containedModule(file);
Assignment ass = tempModule.getEnclosingAssignment(hoverRegion.getOffset());
if (ass != null) {
Reference reference = referenceParser.findReferenceForOpening(file, hoverRegion.getOffset(), textViewer.getDocument());
String str = reference.getDisplayName();
List<String> al = T3Doc.getCommentStrings(ass.getCommentLocation(), str);
if (!al.isEmpty()) {
final StringBuilder sb = new StringBuilder();
for (String string : al) {
sb.append(string);
}
return sb.toString();
}
}
}
}
return null;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterPort.
/**
* Checks if the actual parameter paired with this formal parameter is
* semantically correct as a port parameter.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param actualParameter
* the template instance assigned as actual parameter to
* this formal parameter
* @param expectedValue
* the value kind expected from the actual parameter.
*
* @return the actual parameter created from the value, or null if there
* was an error.
*/
private ActualParameter checkActualParameterPort(final CompilationTimeStamp timestamp, final TemplateInstance actualParameter, final Expected_Value_type expectedValue) {
final Type parameterType = actualParameter.getType();
if (parameterType != null) {
parameterType.getLocation().reportSemanticWarning("Explicit type specification is useless for a port parameter");
actualParameter.checkType(timestamp, type);
}
final Reference derivedReference = actualParameter.getDerivedReference();
if (derivedReference != null) {
derivedReference.getLocation().reportSemanticError("An in-line modified temlate cannot be used as port parameter");
actualParameter.checkDerivedReference(timestamp, type);
}
final ITTCN3Template parameterTemplate = actualParameter.getTemplateBody();
if (!(parameterTemplate instanceof SpecificValue_Template) || !((SpecificValue_Template) parameterTemplate).isReference()) {
actualParameter.getLocation().reportSemanticError("Reference to a port or port parameter was expected for a port parameter");
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
final Reference reference = ((SpecificValue_Template) parameterTemplate).getReference();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
Type referredType;
switch(assignment.getAssignmentType()) {
case A_PORT:
final ArrayDimensions dimensions = ((Def_Port) assignment).getDimensions();
if (dimensions != null) {
dimensions.checkIndices(timestamp, reference, "port", false, expectedValue);
} else if (reference.getSubreferences().size() > 1) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR1, assignment.getDescription()));
}
referredType = ((Def_Port) assignment).getType(timestamp);
break;
case A_PAR_PORT:
if (reference.getSubreferences().size() > 1) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBREFERENCEERROR3, assignment.getDescription()));
}
referredType = ((FormalParameter) assignment).getType(timestamp);
break;
default:
reference.getLocation().reportSemanticError(MessageFormat.format(PORTEXPECTED, assignment.getDescription()));
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
if (referredType != null && type != null && !type.isIdentical(timestamp, referredType)) {
reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH, type.getTypename(), referredType.getTypename()));
}
return new Referenced_ActualParameter(reference);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class FormalParameter method checkActualParameterByReference.
/**
* Checks if the actual parameter paired with this formal parameter is
* semantically correct as a reference parameter.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param parameter
* the template instance assigned as actual parameter to
* this formal parameter
* @param isTemplate
* true if the formal parameter is template, false
* otherwise
* @param expectedValue
* the value kind expected from the actual parameter.
*
* @return the actual parameter created from the value, or null if there
* was an error.
*/
private ActualParameter checkActualParameterByReference(final CompilationTimeStamp timestamp, final TemplateInstance parameter, final boolean isTemplate, final Expected_Value_type expectedValue) {
final Type parameterType = parameter.getType();
if (parameterType != null) {
parameterType.getLocation().reportSemanticWarning(MessageFormat.format(EXPLICITESPECIFICATIONFORREFERENCE, getAssignmentName()));
parameter.checkType(timestamp, type);
}
final Reference derivedReference = parameter.getDerivedReference();
if (derivedReference != null) {
derivedReference.getLocation().reportSemanticError(MessageFormat.format(INLINETEMPLATEFORREFERENCE, getAssignmentName()));
parameter.checkDerivedReference(timestamp, type);
}
String expectedString;
if (isTemplate) {
expectedString = "template variable or template parameter";
} else {
expectedString = "variable or value parameter";
}
final ITTCN3Template template = parameter.getTemplateBody();
if (Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype()) && ((SpecificValue_Template) template).isReference()) {
final Reference reference = ((SpecificValue_Template) template).getReference();
reference.setUsedOnLeftHandSide();
final Assignment assignment = reference.getRefdAssignment(timestamp, true);
if (assignment == null) {
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
boolean assignmentTypeIsCorrect;
switch(assignment.getAssignmentType()) {
case A_PAR_VAL_IN:
((FormalParameter) assignment).useAsLValue(reference);
assignmentTypeIsCorrect = !isTemplate;
break;
case A_PAR_VAL:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
((FormalParameter) assignment).setWritten();
assignmentTypeIsCorrect = !isTemplate;
break;
case A_VAR:
((Def_Var) assignment).setWritten();
assignmentTypeIsCorrect = !isTemplate;
break;
case A_PAR_TEMP_IN:
assignmentTypeIsCorrect = isTemplate;
((FormalParameter) assignment).useAsLValue(reference);
break;
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
((FormalParameter) assignment).setWritten();
assignmentTypeIsCorrect = isTemplate;
break;
case A_VAR_TEMPLATE:
((Def_Var_Template) assignment).setWritten();
assignmentTypeIsCorrect = isTemplate;
break;
default:
assignmentTypeIsCorrect = false;
break;
}
if (assignmentTypeIsCorrect) {
final IType fieldType = assignment.getType(timestamp).getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (fieldType != null) {
if (type != null && !type.isCompatible(timestamp, fieldType, null, null, null)) {
reference.getLocation().reportSemanticError(MessageFormat.format(TYPEMISMATCH2, expectedString, type.getTypename(), fieldType.getTypename()));
} else if (type != null && type.getSubtype() != null && fieldType.getSubtype() != null && !type.getSubtype().isCompatible(timestamp, fieldType.getSubtype())) {
reference.getLocation().reportSemanticError(MessageFormat.format(SUBTYPEMISMATCH, type.getSubtype().toString(), fieldType.getSubtype().toString()));
}
if (!reference.getSubreferences().isEmpty() && reference.refersToStringElement()) {
reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED3, fieldType.getTypename()));
}
}
} else {
reference.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED1, expectedString, getAssignmentName(), assignment.getDescription()));
}
final ActualParameter returnActualParameter = new Referenced_ActualParameter(reference);
if (isTemplate && assignmentTypeIsCorrect) {
TemplateRestriction.Restriction_type refdRestriction;
switch(assignment.getAssignmentType()) {
case A_VAR_TEMPLATE:
{
final Def_Var_Template temp = (Def_Var_Template) assignment;
refdRestriction = temp.getTemplateRestriction();
break;
}
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
final FormalParameter par = (FormalParameter) assignment;
refdRestriction = par.getTemplateRestriction();
break;
}
default:
return returnActualParameter;
}
TemplateRestriction.getSubRestriction(refdRestriction, timestamp, reference);
if (templateRestriction != refdRestriction) {
final boolean preCallCheck = TemplateRestriction.isLessRestrictive(templateRestriction, refdRestriction);
final boolean postCallCheck = TemplateRestriction.isLessRestrictive(refdRestriction, templateRestriction);
if (preCallCheck || postCallCheck) {
final String message = MessageFormat.format("Inadequate restriction on the referenced {0} `{1}'' this may cause a dynamic test case error at runtime", assignment.getAssignmentName(), reference.getDisplayName());
reference.getLocation().reportSemanticWarning(message);
}
}
// written C++ code
if (!Restriction_type.TR_NONE.equals(refdRestriction)) {
switch(myParameterList.getMyDefinition().getAssignmentType()) {
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
// here
break;
default:
break;
}
}
}
return returnActualParameter;
}
parameter.getLocation().reportSemanticError(MessageFormat.format(REFERENCEEXPECTED2, expectedString, getAssignmentName()));
final ActualParameter temp = new Value_ActualParameter(null);
temp.setIsErroneous();
return temp;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter in project titan.EclipsePlug-ins by eclipse.
the class FormalParameterList method checkActualParameterList.
/**
* Check if a list of parsed actual parameters is semantically correct
* according to a list of formal parameters (the called entity).
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param instances
* the list of actual parameters containing both the
* named and the unnamed part converted into an unnamed
* list, that is full and in correct order.
* @param actualParameters
* the list of actual parameters returned for later
* usage.
*
* @return true if a semantic error was found, false otherwise
*/
private boolean checkActualParameterList(final CompilationTimeStamp timestamp, final TemplateInstances instances, final ActualParameterList actualParameters) {
boolean isErroneous = false;
if (minimumNofParameters == parameters.size()) {
if (instances.getNofTis() != parameters.size()) {
instances.getLocation().reportSemanticError(MessageFormat.format("Too {0} parameters: {1} was expected instead of {2}", (instances.getNofTis() < parameters.size()) ? "few" : "many", parameters.size(), instances.getNofTis()));
isErroneous = true;
}
} else {
if (instances.getNofTis() < minimumNofParameters) {
instances.getLocation().reportSemanticError(MessageFormat.format("Too few parameters: at least {0} was expected instaed of {1}", minimumNofParameters, instances.getNofTis()));
isErroneous = true;
} else if (instances.getNofTis() > parameters.size()) {
instances.getLocation().reportSemanticError(MessageFormat.format("Too many parameters: at most {0} was expected instead of {1}", parameters.size(), instances.getNofTis()));
isErroneous = true;
}
}
final int upperLimit = (instances.getNofTis() < parameters.size()) ? instances.getNofTis() : parameters.size();
for (int i = 0; i < upperLimit; i++) {
final TemplateInstance instance = instances.getInstanceByIndex(i);
final FormalParameter formalParameter = parameters.get(i);
if (instance.getType() == null && instance.getDerivedReference() == null && Template_type.TEMPLATE_NOTUSED.equals(instance.getTemplateBody().getTemplatetype())) {
if (formalParameter.hasDefaultValue()) {
final ActualParameter defaultValue = formalParameter.getDefaultValue();
final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
actualParameters.addParameter(temp);
if (defaultValue == null || defaultValue.getIsErroneous()) {
isErroneous = true;
} else {
temp.setLocation(defaultValue.getLocation());
}
} else if (instance.getTemplateBody().getIsErroneous(timestamp)) {
instances.getLocation().reportSemanticError(MessageFormat.format(MISSINGPARAMETER, formalParameter.getIdentifier().getDisplayName()));
isErroneous = true;
} else {
instance.getLocation().reportSemanticError("Not used symbol (`-'') cannot be used for parameter that does not have a default value");
final ActualParameter temp = new Value_ActualParameter(null);
temp.setLocation(instances.getLocation());
temp.setIsErroneous();
actualParameters.addParameter(temp);
isErroneous = true;
}
} else {
final ActualParameter actualParameter = formalParameter.checkActualParameter(timestamp, instance, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
actualParameter.setLocation(instance.getLocation());
actualParameters.addParameter(actualParameter);
if (actualParameter.getIsErroneous()) {
isErroneous = true;
}
}
}
for (int i = upperLimit; i < parameters.size(); i++) {
final FormalParameter formalParameter = parameters.get(i);
if (formalParameter.hasDefaultValue()) {
final ActualParameter defaultValue = formalParameter.getDefaultValue();
final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
actualParameters.addParameter(temp);
if (defaultValue == null || defaultValue.getIsErroneous()) {
isErroneous = true;
} else {
temp.setLocation(defaultValue.getLocation());
}
} else {
final ActualParameter temp = new Value_ActualParameter(null);
temp.setLocation(instances.getLocation());
temp.setIsErroneous();
actualParameters.addParameter(temp);
isErroneous = true;
}
}
return isErroneous;
}
Aggregations