use of org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter in project titan.EclipsePlug-ins by eclipse.
the class Signature_Type method checkThisValueSequence.
/**
* Checks the Sequence_Value kind value against this type.
* <p>
* Please note, that this function can only be called once we know for sure
* that the value is of sequence type.
*
* @param timestamp the timestamp of the actual semantic check cycle.
* @param value the value to be checked
* @param expectedValue the kind of value expected here.
* @param incompleteAllowed wheather incomplete value is allowed or not.
* @param implicitOmit true if the implicit omit optional attribute was set
* for the value, false otherwise
*/
private boolean checkThisValueSequence(final CompilationTimeStamp timestamp, final Sequence_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean implicitOmit, final boolean strElem) {
boolean selfReference = false;
final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
boolean inSnyc = true;
final int nofTypeComponents = getNofParameters();
final int nofvalueComponents = value.getNofComponents();
int nextIndex = 0;
SignatureFormalParameter lastParameter = null;
for (int i = 0; i < nofvalueComponents; i++) {
final NamedValue namedValue = value.getSeqValueByIndex(i);
final Identifier valueId = namedValue.getName();
if (!formalParList.hasParameterWithName(valueId.getName())) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTPARAMETER, valueId.getDisplayName(), getTypename()));
inSnyc = false;
continue;
} else if (componentMap.containsKey(valueId.getName())) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEPARAMETERAGAIN, valueId.getDisplayName(), getTypename()));
componentMap.get(valueId.getName()).getLocation().reportSemanticError(MessageFormat.format("Parameter `{0}'' is already given here", valueId.getDisplayName()));
inSnyc = false;
} else {
componentMap.put(valueId.getName(), namedValue);
}
final SignatureFormalParameter formalParameter = formalParList.getParameterByName(valueId.getName());
if (inSnyc) {
if (incompleteAllowed) {
boolean found = false;
for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
final SignatureFormalParameter formalParameter2 = formalParList.getParameterByIndex(j);
if (valueId.getName().equals(formalParameter2.getIdentifier().getName())) {
lastParameter = formalParameter2;
nextIndex = j + 1;
found = true;
}
}
if (lastParameter != null && !found) {
namedValue.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' cannot appear after parameter `{1}'' in signature value", valueId.getDisplayName(), lastParameter.getIdentifier().getDisplayName()));
inSnyc = false;
}
} else {
final SignatureFormalParameter formalParameter2 = formalParList.getParameterByIndex(i);
if (formalParameter != formalParameter2) {
namedValue.getLocation().reportSemanticError(MessageFormat.format("Unexpected field `{0}'' in signature value, expecting `{1}''", valueId.getDisplayName(), formalParameter2.getIdentifier().getDisplayName()));
inSnyc = false;
}
}
}
final Type type = formalParameter.getType();
final IValue componentValue = namedValue.getValue();
if (componentValue != null) {
componentValue.setMyGovernor(type);
final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, false, false, true, implicitOmit, strElem));
}
}
if (!incompleteAllowed) {
for (int i = 0; i < formalParList.getNofInParameters(); i++) {
final SignatureFormalParameter formalParameter = formalParList.getInParameterByIndex(i);
final Identifier identifier = formalParameter.getIdentifier();
if (!componentMap.containsKey(identifier.getName()) && SignatureFormalParameter.ParamaterDirection.PARAM_OUT != formalParameter.getDirection()) {
value.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' is missing from signature value", identifier.getDisplayName()));
}
}
}
return selfReference;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter in project titan.EclipsePlug-ins by eclipse.
the class Signature_Type method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final String genName = getGenNameOwn();
final ArrayList<SignatureParameter> parameters = new ArrayList<SignatureParameter>();
for (int i = 0; i < formalParList.getNofParameters(); i++) {
final SignatureFormalParameter formalPar = formalParList.getParameterByIndex(i);
final Type type = formalPar.getType();
SignatureGenerator.signatureParamaterDirection direction;
switch(formalPar.getDirection()) {
case PARAM_OUT:
direction = signatureParamaterDirection.PAR_OUT;
break;
case PARAM_INOUT:
direction = signatureParamaterDirection.PAR_INOUT;
break;
default:
direction = signatureParamaterDirection.PAR_IN;
break;
}
final SignatureParameter temp = new SignatureParameter(direction, type.getGenNameValue(aData, source, myScope), type.getGenNameTemplate(aData, source, myScope), formalPar.getIdentifier().getName());
parameters.add(temp);
}
SignatureReturnType signatueReturnType = null;
if (returnType != null) {
signatueReturnType = new SignatureReturnType(returnType.getGenNameValue(aData, source, myScope), returnType.getGenNameTemplate(aData, source, myScope));
}
final ArrayList<SignatureException> signatureExceptions = new ArrayList<SignatureGenerator.SignatureException>();
if (exceptions != null) {
for (int i = 0; i < exceptions.getNofExceptions(); i++) {
final Type exceptionType = exceptions.getExceptionByIndex(i);
final IType last = exceptionType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
final SignatureException temp = new SignatureException(last.getGenNameValue(aData, source, myScope), last.getGenNameTemplate(aData, source, myScope), last.getFullName());
signatureExceptions.add(temp);
}
}
final SignatureDefinition def = new SignatureDefinition(genName, getFullName(), parameters, signatueReturnType, noBlock, signatureExceptions);
SignatureGenerator.generateClasses(aData, source, def);
if (hasDoneAttribute()) {
generateCodeDone(aData, source);
}
if (subType != null) {
subType.generateCode(aData, source);
}
generateCodeForCodingHandlers(aData, source);
}
use of org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter in project titan.EclipsePlug-ins by eclipse.
the class VariableList_Parameter_Redirect method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp, final Signature_Type signature, final boolean isOut) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
this.checkErroneous(timestamp);
if (signature == null) {
return;
}
final SignatureFormalParameterList parameterList = signature.getParameterList();
if (parameterList.getNofParameters() == 0) {
getLocation().reportSemanticError(MessageFormat.format(SIGNATUREWITHOUTPARAMETERS, signature.getTypename()));
checkErroneous(timestamp);
return;
}
final int nofVariableEntries = entries.getNofEntries();
final int nofParameters = isOut ? parameterList.getNofOutParameters() : parameterList.getNofInParameters();
if (nofVariableEntries != nofParameters) {
getLocation().reportSemanticError(MessageFormat.format("Too {0} variable entries compared to the number of {1}/inout parameters in signature `{2}'': {3} was expected instead of {4}", (nofVariableEntries > nofParameters) ? "many" : "few", isOut ? "out" : "in", signature.getTypename(), nofParameters, nofVariableEntries));
}
for (int i = 0; i < nofVariableEntries; i++) {
final Variable_Entry entry = entries.getEntryByIndex(i);
if (i < nofParameters) {
final SignatureFormalParameter parameter = isOut ? parameterList.getOutParameterByIndex(i) : parameterList.getInParameterByIndex(i);
checkVariableReference(timestamp, entry.getReference(), parameter.getType());
} else {
checkVariableReference(timestamp, entry.getReference(), null);
}
}
lastTimeChecked = timestamp;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter in project titan.EclipsePlug-ins by eclipse.
the class AssignmentList_Parameter_Redirect method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp, final Signature_Type signature, final boolean isOut) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
return;
}
final SignatureFormalParameterList parameterList = signature.getParameterList();
if (parameterList.getNofParameters() == 0) {
getLocation().reportSemanticError(MessageFormat.format(SIGNATUREWITHOUTPARAMETERS, signature.getTypename()));
checkErroneous(timestamp);
return;
}
boolean errorFlag = false;
final HashMap<String, Parameter_Assignment> parameterMap = new HashMap<String, Parameter_Assignment>();
for (int i = 0, size = assignments.getNofParameterAssignments(); i < size; i++) {
final Parameter_Assignment assignment = assignments.getParameterAssignmentByIndex(i);
final String name = assignment.getIdentifier().getName();
if (parameterMap.containsKey(name)) {
assignment.getLocation().reportSemanticError(MessageFormat.format("Duplicate redirect for parameter `{0}''", assignment.getIdentifier().getDisplayName()));
final Location otherLocation = parameterMap.get(name).getLocation();
otherLocation.reportSemanticWarning(MessageFormat.format("A variable entry for parameter `{0}'' is already given here", assignment.getIdentifier().getDisplayName()));
errorFlag = true;
} else {
parameterMap.put(name, assignment);
}
if (parameterList.hasParameterWithName(name)) {
final SignatureFormalParameter parameterTemplate = parameterList.getParameterByName(name);
if (isOut) {
if (SignatureFormalParameter.ParamaterDirection.PARAM_IN == parameterTemplate.getDirection()) {
final String message = MessageFormat.format("Parameter `{0}'' of signature `{1}'' has `in'' direction", assignment.getIdentifier().getDisplayName(), signature.getTypename());
assignment.getLocation().reportSemanticError(message);
errorFlag = true;
}
} else {
if (SignatureFormalParameter.ParamaterDirection.PARAM_OUT == parameterTemplate.getDirection()) {
final String message = MessageFormat.format("Parameter `{0}'' of signature `{1}'' has `out'' direction", assignment.getIdentifier().getDisplayName(), signature.getTypename());
assignment.getLocation().reportSemanticError(message);
errorFlag = true;
}
}
checkVariableReference(timestamp, assignment.getReference(), parameterTemplate.getType());
} else {
assignment.getLocation().reportSemanticError(MessageFormat.format("Signature `{0}'' does not have parameter named `{1}''", signature.getTypename(), assignment.getIdentifier().getDisplayName()));
errorFlag = true;
checkVariableReference(timestamp, assignment.getReference(), null);
}
}
if (!errorFlag) {
// converting the AssignmentList to VariableList
final Variable_Entries variableEntries = new Variable_Entries();
final int upperLimit = isOut ? parameterList.getNofOutParameters() : parameterList.getNofInParameters();
for (int i = 0; i < upperLimit; i++) {
final SignatureFormalParameter parameter = isOut ? parameterList.getOutParameterByIndex(i) : parameterList.getInParameterByIndex(i);
final String name = parameter.getIdentifier().getName();
if (parameterMap.containsKey(name)) {
variableEntries.add(new Variable_Entry(parameterMap.get(name).getReference()));
} else {
variableEntries.add(new Variable_Entry());
}
}
}
lastTimeChecked = timestamp;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.SignatureFormalParameter in project titan.EclipsePlug-ins by eclipse.
the class Signature_Type method checkThisNamedTemplateList.
// see void Type::chk_this_template_Signature(Template *t, namedbool incomplete_allowed) in Type_chk.cc
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List template, final boolean isModified, final Assignment lhs) {
final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
boolean inSynch = true;
// TODO: alternatives:formalParList.getNofInParameters(); formalParList.getNofOutParameters()
final int nofTypeParameters = getNofParameters();
final int nofTemplateComponents = template.getNofTemplates();
int tI = 0;
boolean selfReference = false;
for (int vI = 0; vI < nofTemplateComponents; vI++) {
final NamedTemplate namedTemplate = template.getTemplateByIndex(vI);
final Identifier identifier = namedTemplate.getName();
final String name = identifier.getName();
if (hasParameterWithName(name)) {
if (componentMap.containsKey(name)) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEPARAMETERAGAIN, identifier.getDisplayName(), getTypename()));
componentMap.get(name).getLocation().reportSingularSemanticError(MessageFormat.format(DUPLICATEPARAMETERFIRST, identifier.getDisplayName()));
inSynch = false;
} else {
componentMap.put(name, namedTemplate);
}
final SignatureFormalParameter parameter = formalParList.getParameterByName(name);
if (inSynch) {
SignatureFormalParameter parameter2 = null;
boolean found = false;
for (; tI < nofTypeParameters && !found; tI++) {
parameter2 = formalParList.getParameterByIndex(tI);
if (parameter == parameter2) {
found = true;
break;
}
}
if (!found) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(UNEXPECTEDPARAMETER, identifier.getDisplayName()));
inSynch = false;
}
}
final Type parameterType = parameter.getType();
ITTCN3Template componentTemplate = namedTemplate.getTemplate();
// FIXME: will be overwritten?
componentTemplate.setMyGovernor(parameterType);
componentTemplate = parameterType.checkThisTemplateRef(timestamp, componentTemplate);
selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, parameterType, isModified, false, false, true, false, lhs);
} else {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTPARAMETER, identifier.getDisplayName(), getTypename()));
inSynch = false;
}
}
if (isModified) {
SignatureFormalParameter firstUndefIn = null;
SignatureFormalParameter firstUndefOut = null;
for (int i = 0; i < nofTypeParameters; i++) {
final SignatureFormalParameter parameter = formalParList.getParameterByIndex(i);
final Identifier identifier = parameter.getIdentifier();
if (!componentMap.containsKey(identifier.getName()) || Template_type.TEMPLATE_NOTUSED.equals(componentMap.get(identifier.getName()).getTemplate().getTemplatetype())) {
switch(parameter.getDirection()) {
case PARAM_IN:
if (firstUndefIn == null) {
firstUndefIn = parameter;
}
break;
case PARAM_OUT:
if (firstUndefOut == null) {
firstUndefOut = parameter;
}
break;
default:
template.getLocation().reportSemanticError(MessageFormat.format(INCOMPLETE1, identifier.getDisplayName()));
break;
}
}
}
if (firstUndefIn != null && firstUndefOut != null) {
template.getLocation().reportSemanticError(MessageFormat.format(INCOMPLETE2, firstUndefIn.getIdentifier().getDisplayName(), firstUndefOut.getIdentifier().getDisplayName()));
}
}
return selfReference;
}
Aggregations