use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList in project titan.EclipsePlug-ins by eclipse.
the class FormalParameterList method collateLazyAndNonLazyActualParameters.
/**
* Read the parsed actual parameters, and collate the lazy and non-lazy actual parameters
* according to their associated formal parameters.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param parsedParameters
* the parsed actual parameters (may contain named, and unnamed parts too).
* @param actualLazyParameters
* the list of actual lazy parameters returned for later usage.
* @param actualNonLazyParameters
* the list of actual non lazy parameters returned for later usage.
*/
public final void collateLazyAndNonLazyActualParameters(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualLazyParameters, final ActualParameterList actualNonLazyParameters) {
final TemplateInstances unnamed = parsedParameters.getInstances();
final NamedParameters named = parsedParameters.getNamedParameters();
int nofLocated = unnamed.getNofTis();
final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
for (int i = 0, size = parameters.size(); i < size; i++) {
formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
}
final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
for (int i = 0, size = named.getNofParams(); i < size; i++) {
final NamedParameter namedParameter = named.getParamByIndex(i);
final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
final int isAt = formalParameterMap.get(formalParameter);
for (; nofLocated < isAt; nofLocated++) {
final NotUsed_Template temp = new NotUsed_Template();
if (!parameters.get(nofLocated).hasDefaultValue()) {
temp.setIsErroneous(true);
}
final TemplateInstance instance = new TemplateInstance(null, null, temp);
instance.setLocation(parsedParameters.getLocation());
finalUnnamed.addTemplateInstance(instance);
}
finalUnnamed.addTemplateInstance(namedParameter.getInstance());
nofLocated++;
}
finalUnnamed.setLocation(parsedParameters.getLocation());
final int upperLimit = (finalUnnamed.getNofTis() < parameters.size()) ? finalUnnamed.getNofTis() : parameters.size();
for (int i = 0; i < upperLimit; i++) {
final TemplateInstance instance = finalUnnamed.getInstanceByIndex(i);
final FormalParameter formalParameter = parameters.get(i);
if (instance.getType() == null && instance.getDerivedReference() == null && Template_type.TEMPLATE_NOTUSED.equals(instance.getTemplateBody().getTemplatetype())) {
final ActualParameter defaultValue = formalParameter.getDefaultValue();
final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
if (defaultValue != null && !defaultValue.getIsErroneous()) {
temp.setLocation(defaultValue.getLocation());
}
if (formalParameter.getIsLazy()) {
actualLazyParameters.addParameter(temp);
} else {
actualNonLazyParameters.addParameter(temp);
}
} else {
final ActualParameter actualParameter = formalParameter.checkActualParameter(timestamp, instance, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
actualParameter.setLocation(instance.getLocation());
if (formalParameter.getIsLazy()) {
actualLazyParameters.addParameter(actualParameter);
} else {
actualNonLazyParameters.addParameter(actualParameter);
}
}
}
for (int i = upperLimit; i < parameters.size(); i++) {
final FormalParameter formalParameter = parameters.get(i);
final ActualParameter defaultValue = formalParameter.getDefaultValue();
final Default_ActualParameter temp = new Default_ActualParameter(defaultValue);
if (defaultValue != null && !defaultValue.getIsErroneous()) {
temp.setLocation(defaultValue.getLocation());
}
if (formalParameter.getIsLazy()) {
actualLazyParameters.addParameter(temp);
} else {
actualNonLazyParameters.addParameter(temp);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList 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 parsedParameters
* the parsed actual parameters (may contain named, and
* unnamed parts too).
* @param actualParameters
* the list of actual parameters returned for later
* usage.
*
* @return true if a semantic error was found, false otherwise
*/
public final boolean checkActualParameterList(final CompilationTimeStamp timestamp, final ParsedActualParameters parsedParameters, final ActualParameterList actualParameters) {
parsedParameters.setFormalParList(this);
checkUniqueness(timestamp);
boolean isErroneous = false;
final TemplateInstances unnamed = parsedParameters.getInstances();
final NamedParameters named = parsedParameters.getNamedParameters();
int nofLocated = unnamed.getNofTis();
final Map<FormalParameter, Integer> formalParameterMap = new HashMap<FormalParameter, Integer>();
for (int i = 0, size = parameters.size(); i < size; i++) {
formalParameterMap.put(parameters.get(i), Integer.valueOf(i));
}
final TemplateInstances finalUnnamed = new TemplateInstances(unnamed);
for (int i = 0, size = named.getNofParams(); i < size; i++) {
final NamedParameter namedParameter = named.getParamByIndex(i);
if (parameterMap != null && parameterMap.containsKey(namedParameter.getName().getName())) {
final FormalParameter formalParameter = parameterMap.get(namedParameter.getName().getName());
final int isAt = formalParameterMap.get(formalParameter);
if (isAt >= nofLocated) {
for (; nofLocated < isAt; nofLocated++) {
final NotUsed_Template temp = new NotUsed_Template();
if (!parameters.get(nofLocated).hasDefaultValue()) {
temp.setIsErroneous(true);
}
final TemplateInstance instance = new TemplateInstance(null, null, temp);
instance.setLocation(parsedParameters.getLocation());
finalUnnamed.addTemplateInstance(instance);
}
finalUnnamed.addTemplateInstance(namedParameter.getInstance());
nofLocated++;
} else {
isErroneous = true;
if (isAt >= unnamed.getNofTis()) {
namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is out of order", namedParameter.getName().getDisplayName()));
} else {
namedParameter.getLocation().reportSemanticError(MessageFormat.format("Named parameter `{0}'' is assigned more than once", namedParameter.getName().getDisplayName()));
}
}
} else {
String name;
switch(myDefinition.getAssignmentType()) {
case A_TYPE:
switch(((Def_Type) myDefinition).getType(timestamp).getTypetype()) {
case TYPE_FUNCTION:
name = "Function reference";
break;
case TYPE_ALTSTEP:
name = "Altstep reference";
break;
case TYPE_TESTCASE:
name = "Testcase reference";
break;
default:
name = "";
break;
}
break;
default:
name = myDefinition.getAssignmentName();
break;
}
isErroneous = true;
namedParameter.getLocation().reportSemanticError(MessageFormat.format("{0} `{1}'' has no formal parameter with name `{2}''", name, myDefinition.getFullName(), namedParameter.getName().getDisplayName()));
}
}
if (isErroneous) {
return false;
}
finalUnnamed.setLocation(parsedParameters.getLocation());
return checkActualParameterList(timestamp, finalUnnamed, actualParameters);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList in project titan.EclipsePlug-ins by eclipse.
the class Activate_Referenced_Statement method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
isErroneous = false;
lastTimeChecked = timestamp;
if (dereferredValue == null) {
setIsErroneous();
return;
}
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)) {
setIsErroneous();
return;
}
if (!Type_type.TYPE_ALTSTEP.equals(type.getTypetype())) {
dereferredValue.getLocation().reportSemanticError(MessageFormat.format(ALTSTEPEXPECTED, type.getTypename()));
setIsErroneous();
return;
}
if (((Altstep_Type) type).isRunsOnSelf()) {
dereferredValue.getLocation().reportSemanticError(RUNONSELFERROR);
setIsErroneous();
return;
}
if (myStatementBlock != null) {
myStatementBlock.checkRunsOnScope(timestamp, type, this, STATEMENT_NAME);
}
actualParameterList2 = new ActualParameterList();
final FormalParameterList formalParameterList = ((Altstep_Type) type).getFormalParameters();
if (formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameterList2)) {
setIsErroneous();
return;
}
actualParameterList2.setFullNameParent(this);
actualParameterList2.setMyScope(getMyScope());
if (!formalParameterList.checkActivateArgument(timestamp, actualParameterList2, getFullName())) {
setIsErroneous();
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Template method checkInvoke.
public void checkInvoke(final CompilationTimeStamp timestamp) {
if (getIsErroneous(timestamp) || actualParameterList == null || value == null) {
return;
}
value.setLoweridToReference(timestamp);
IType type = value.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (type != null) {
type = type.getTypeRefdLast(timestamp);
}
if (type == null) {
if (!value.getIsErroneous(timestamp)) {
value.getLocation().reportSemanticError("A value of type function was expected in the argument");
}
setIsErroneous(true);
return;
}
if (!Type_type.TYPE_FUNCTION.equals(type.getTypetype())) {
value.getLocation().reportSemanticError(MessageFormat.format("A value of type function was expected in the argument instead of `{0}''", type.getTypename()));
setIsErroneous(true);
return;
}
if (myScope == null) {
return;
}
myScope.checkRunsOnScope(timestamp, type, this, "call");
final FormalParameterList formalParameterList = ((Function_Type) type).getFormalParameters();
actualParameter_list = new ActualParameterList();
if (!formalParameterList.checkActualParameterList(timestamp, actualParameterList, actualParameter_list)) {
actualParameter_list.setFullNameParent(this);
actualParameter_list.setMyScope(getMyScope());
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList in project titan.EclipsePlug-ins by eclipse.
the class Invoke_Template method updateSyntax.
@Override
public /**
* {@inheritDoc}
*/
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (isDamaged) {
throw new ReParseException();
}
if (lengthRestriction != null) {
lengthRestriction.updateSyntax(reparser, false);
reparser.updateLocation(lengthRestriction.getLocation());
}
if (baseTemplate instanceof IIncrementallyUpdateable) {
((IIncrementallyUpdateable) baseTemplate).updateSyntax(reparser, false);
reparser.updateLocation(baseTemplate.getLocation());
} else if (baseTemplate != null) {
throw new ReParseException();
}
if (value != null) {
value.updateSyntax(reparser, false);
reparser.updateLocation(value.getLocation());
}
if (actualParameterList != null) {
actualParameterList.updateSyntax(reparser, false);
reparser.updateLocation(actualParameterList.getLocation());
}
}
Aggregations