use of org.eclipse.titan.designer.AST.Identifier 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.Identifier in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Choice_Type method checkCodingAttributes.
@Override
public /**
* {@inheritDoc}
*/
void checkCodingAttributes(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
// TODO can unions have length restriction?
if (rawAttribute != null) {
// TODO force_raw()
if (rawAttribute.taglist != null) {
for (int c = 0; c < rawAttribute.taglist.size(); c++) {
final rawAST_single_tag singleTag = rawAttribute.taglist.get(c);
final Identifier fieldname = singleTag.fieldName;
if (!hasComponentWithName(fieldname.getName())) {
fieldname.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter TAG for type `{1}''", fieldname.getDisplayName(), getTypename()));
continue;
}
if (singleTag.keyList != null) {
for (int a = 0; a < singleTag.keyList.size(); a++) {
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(fieldname));
for (int b = 0; b < singleTag.keyList.get(a).keyField.names.size(); b++) {
reference.addSubReference(new FieldSubReference(singleTag.keyList.get(a).keyField.names.get(b)));
}
final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (t != null) {
final Value v = singleTag.keyList.get(a).v_value;
if (v != null) {
v.setMyScope(getMyScope());
v.setMyGovernor(t);
final IValue tempValue = t.checkThisValueRef(timestamp, v);
t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
}
}
}
}
}
}
}
if (refChain.contains(this)) {
return;
}
refChain.add(this);
refChain.markState();
for (int i = 0; i < getNofComponents(); i++) {
final CompField cf = getComponentByIndex(i);
cf.getType().checkCodingAttributes(timestamp, refChain);
}
refChain.previousState();
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Sequence_Type method checkThisValueSeq.
/**
* 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 checkThisValueSeq(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;
check(timestamp);
final CompilationTimeStamp valueTimeStamp = value.getLastTimeChecked();
if (valueTimeStamp == null || valueTimeStamp.isLess(timestamp)) {
value.removeGeneratedValues();
}
final Map<String, NamedValue> componentMap = new HashMap<String, NamedValue>();
final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
final boolean isAsn = value.isAsn();
boolean inSnyc = true;
final int nofTypeComponents = realComponents.size();
final int nofValueComponents = value.getNofComponents();
int nextIndex = 0;
CompField lastCompField = null;
int sequenceIndex = 0;
for (int i = 0; i < nofValueComponents; i++, sequenceIndex++) {
final NamedValue namedValue = value.getSeqValueByIndex(i);
final Identifier valueId = namedValue.getName();
if (!realComponents.containsKey(valueId.getName())) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? NONEXISTENTFIELDERRORASN1 : NONEXISTENTFIELDERRORTTCN3, namedValue.getName().getDisplayName(), getTypename()));
inSnyc = false;
} else {
if (componentMap.containsKey(valueId.getName())) {
final String duplicateAgain = MessageFormat.format(isAsn ? DUPLICATEDFIELDAGAINASN1 : DUPLICATEDFIELDAGAINTTCN3, valueId.getDisplayName());
namedValue.getLocation().reportSemanticError(duplicateAgain);
final String duplicateFirst = MessageFormat.format(isAsn ? DUPLICATEDFIELDFIRSTASN1 : DUPLICATEDFIELDFIRSTTTCN3, valueId.getDisplayName());
componentMap.get(valueId.getName()).getLocation().reportSingularSemanticError(duplicateFirst);
inSnyc = false;
} else {
componentMap.put(valueId.getName(), namedValue);
}
final CompField componentField = realComponents.get(valueId.getName());
if (inSnyc) {
if (incompleteAllowed) {
boolean found = false;
for (int j = nextIndex; j < nofTypeComponents && !found; j++) {
final CompField field2 = getComponentByIndex(j);
if (valueId.getName().equals(field2.getIdentifier().getName())) {
lastCompField = field2;
nextIndex = j + 1;
found = true;
}
}
if (lastCompField != null && !found) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? WRONGFIELDORDERASN1 : WRONGFIELDORDERTTCN3, valueId.getDisplayName(), lastCompField.getIdentifier().getDisplayName()));
inSnyc = false;
}
} else {
CompField field2 = getComponentByIndex(sequenceIndex);
final CompField field2Original = field2;
while (implicitOmit && sequenceIndex < getNofComponents() && componentField != field2 && field2.isOptional()) {
field2 = getComponentByIndex(sequenceIndex);
}
if (sequenceIndex >= getNofComponents() || componentField != field2) {
namedValue.getLocation().reportSemanticError(MessageFormat.format(isAsn ? UNEXPECTEDFIELDASN1 : UNEXPECTEDFIELDTTCN3, valueId.getDisplayName(), field2Original.getIdentifier().getDisplayName()));
}
}
}
final Type type = componentField.getType();
final IValue componentValue = namedValue.getValue();
if (componentValue != null) {
componentValue.setMyGovernor(type);
if (Value_type.NOTUSED_VALUE.equals(componentValue.getValuetype())) {
if (!incompleteAllowed) {
componentValue.getLocation().reportSemanticError(INCOMPLETEPRESENTERROR);
}
} else {
final IValue tempValue = type.checkThisValueRef(timestamp, componentValue);
selfReference |= type.checkThisValue(timestamp, tempValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, componentField.isOptional(), true, implicitOmit, strElem));
}
}
}
}
if (!incompleteAllowed || strictConstantCheckingSeverity) {
for (int i = 0; i < nofTypeComponents; i++) {
final Identifier id = compFieldMap.fields.get(i).getIdentifier();
if (!componentMap.containsKey(id.getName())) {
if (getComponentByIndex(i).isOptional() && implicitOmit) {
value.addNamedValue(new NamedValue(new Identifier(Identifier_type.ID_TTCN, id.getDisplayName()), new Omit_Value(), false));
} else {
value.getLocation().reportSemanticError(MessageFormat.format(isAsn ? MISSINGFIELDASN1 : MISSINGFIELDTTCN3, id.getDisplayName()));
}
}
}
}
value.setLastTimeChecked(timestamp);
return selfReference;
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Sequence_Type method isPresentAnyvalueEmbeddedField.
@Override
public /**
* {@inheritDoc}
*/
boolean isPresentAnyvalueEmbeddedField(final ExpressionStruct expression, final List<ISubReference> subreferences, final int beginIndex) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return true;
}
if (beginIndex >= subreferences.size()) {
return true;
}
final ISubReference subReference = subreferences.get(beginIndex);
if (!(subReference instanceof FieldSubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return true;
}
final Identifier fieldId = ((FieldSubReference) subReference).getId();
final CompField compField = getComponentByName(fieldId.getName());
if (compField.isOptional()) {
return false;
}
return compField.getType().isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Set_Seq_Choice_BaseType method getSubrefsAsArray.
@Override
public /**
* {@inheritDoc}
*/
boolean getSubrefsAsArray(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final List<Integer> subrefsArray, final List<IType> typeArray) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return true;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDSUBREFERENCE, getTypename()));
return false;
case fieldSubReference:
final Identifier id = subreference.getId();
final CompField compField = compFieldMap.getCompWithName(id);
if (compField == null) {
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.NONEXISTENTSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return false;
}
final IType fieldType = compField.getType();
if (fieldType == null) {
return false;
}
final int fieldIndex = compFieldMap.fields.indexOf(compField);
subrefsArray.add(fieldIndex);
typeArray.add(this);
return fieldType.getSubrefsAsArray(timestamp, reference, actualSubReference + 1, subrefsArray, typeArray);
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
return false;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return false;
}
}
Aggregations