use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class Assignment_Statement method checkVarAssignment.
private void checkVarAssignment(final CompilationTimeStamp timestamp, final Assignment assignment, final IValue value) {
final IType varType = getType(timestamp, assignment);
if (varType == null || value == null) {
isErroneous = true;
return;
}
final IType type = varType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (type == null) {
isErroneous = true;
return;
}
value.setMyGovernor(type);
IValue lastValue = type.checkThisValueRef(timestamp, value);
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
lastValue = lastValue.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (Value_type.OMIT_VALUE.equals(lastValue.getValuetype())) {
final ISubReference lastReference = reference.removeLastSubReference();
if (lastReference == null || lastReference.getId() == null) {
value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
isErroneous = true;
reference.addSubReference(lastReference);
return;
}
final Identifier lastField = lastReference.getId();
final List<ISubReference> baseReference = reference.getSubreferences(0, reference.getSubreferences().size() - 1);
reference.addSubReference(lastReference);
final Reference newReference = new TemporalReference(null, baseReference);
newReference.clearStringElementReferencing();
IType baseType = varType.getFieldType(timestamp, newReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (baseType == null) {
isErroneous = true;
return;
}
baseType = baseType.getTypeRefdLast(timestamp);
if (baseType.getIsErroneous(timestamp)) {
isErroneous = true;
return;
}
CompField componentField;
switch(baseType.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
componentField = ((TTCN3_Sequence_Type) baseType).getComponentByName(lastField.getName());
if (componentField != null && !componentField.isOptional()) {
value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
value.setIsErroneous(true);
}
break;
case TYPE_ASN1_SEQUENCE:
componentField = ((ASN1_Sequence_Type) baseType).getComponentByName(lastField);
if (componentField != null && !componentField.isOptional()) {
value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
value.setIsErroneous(true);
}
break;
case TYPE_TTCN3_SET:
componentField = ((TTCN3_Set_Type) baseType).getComponentByName(lastField.getName());
if (componentField != null && !componentField.isOptional()) {
value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
value.setIsErroneous(true);
}
break;
case TYPE_ASN1_SET:
componentField = ((ASN1_Set_Type) baseType).getComponentByName(lastField);
if (componentField != null && !componentField.isOptional()) {
value.getLocation().reportSemanticError(MessageFormat.format(OMITTOMANDATORYASSIGNMENT2, lastField.getDisplayName(), baseType.getTypename()));
value.setIsErroneous(true);
}
break;
default:
// TODO:check this!!!
value.getLocation().reportSemanticError(OMITTOMANDATORYASSIGNMENT1);
value.setIsErroneous(true);
isErroneous = true;
break;
}
} else {
final boolean isStringElement = reference.refersToStringElement();
selfReference = type.checkThisValue(timestamp, value, assignment, new ValueCheckingOptions(Expected_Value_type.EXPECTED_DYNAMIC_VALUE, true, false, !isStringElement, false, isStringElement));
if (isStringElement) {
// The length of the right hand side should be 1
final IType lastType = type.getTypeRefdLast(timestamp);
int stringLength = 1;
switch(lastType.getTypetype()) {
case TYPE_BITSTRING:
case TYPE_BITSTRING_A:
if (!Value_type.BITSTRING_VALUE.equals(lastValue.getValuetype())) {
return;
}
stringLength = ((Bitstring_Value) lastValue).getValueLength();
break;
case TYPE_HEXSTRING:
if (!Value_type.HEXSTRING_VALUE.equals(lastValue.getValuetype())) {
lastValue = null;
} else {
stringLength = ((Hexstring_Value) lastValue).getValueLength();
}
break;
case TYPE_OCTETSTRING:
if (!Value_type.OCTETSTRING_VALUE.equals(lastValue.getValuetype())) {
return;
}
stringLength = ((Octetstring_Value) lastValue).getValueLength();
break;
case TYPE_CHARSTRING:
case TYPE_NUMERICSTRING:
case TYPE_PRINTABLESTRING:
case TYPE_IA5STRING:
case TYPE_VISIBLESTRING:
case TYPE_UTCTIME:
case TYPE_GENERALIZEDTIME:
if (!Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
return;
}
stringLength = ((Charstring_Value) lastValue).getValueLength();
break;
case TYPE_UCHARSTRING:
case TYPE_UTF8STRING:
case TYPE_TELETEXSTRING:
case TYPE_VIDEOTEXSTRING:
case TYPE_GRAPHICSTRING:
case TYPE_GENERALSTRING:
case TYPE_UNIVERSALSTRING:
case TYPE_BMPSTRING:
case TYPE_OBJECTDESCRIPTOR:
if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(lastValue.getValuetype())) {
stringLength = ((UniversalCharstring_Value) lastValue).getValueLength();
} else if (Value_type.CHARSTRING_VALUE.equals(lastValue.getValuetype())) {
stringLength = ((Charstring_Value) lastValue).getValueLength();
} else {
return;
}
break;
default:
lastValue = null;
return;
}
if (stringLength != 1) {
final String message = MessageFormat.format("The length of the string to be assigned to a string element of type `{0}'' should be 1 instead of {1}", type.getTypename(), stringLength);
value.getLocation().reportSemanticError(message);
value.setIsErroneous(true);
}
}
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class ImportModule method addProposal.
// FIXME ezeket sem teszteltuk
@Override
public /**
* {@inheritDoc}
*/
void addProposal(final ProposalCollector propCollector, final Identifier targetModuleId) {
final List<ISubReference> subrefs = propCollector.getReference().getSubreferences();
if (propCollector.getReference().getModuleIdentifier() == null && subrefs.size() == 1) {
propCollector.addProposal(identifier, ImageCache.getImage(getOutlineIcon()), KIND);
}
final Module savedReferredModule = referredModule;
if (savedReferredModule != null) {
final Assignments assignments = savedReferredModule.getAssignments();
for (int i = 0, size = assignments.getNofAssignments(); i < size; i++) {
final Assignment temporalAssignment = assignments.getAssignmentByIndex(i);
if (savedReferredModule.isVisible(CompilationTimeStamp.getBaseTimestamp(), targetModuleId, temporalAssignment)) {
temporalAssignment.addProposal(propCollector, 0);
}
}
if (savedReferredModule instanceof TTCN3Module) {
final TTCN3Module ttcnmodule = (TTCN3Module) savedReferredModule;
final List<ImportModule> imports = ttcnmodule.getImports();
for (final ImportModule importation : imports) {
if (importation.getVisibilityModifier() == VisibilityModifier.Public) {
importation.addProposal(propCollector, targetModuleId);
} else if (importation.getVisibilityModifier() == VisibilityModifier.Friend) {
// The import is the friendly one
if (ttcnmodule.isVisible(CompilationTimeStamp.getBaseTimestamp(), targetModuleId, importation)) {
importation.addProposal(propCollector, targetModuleId);
}
}
}
}
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class Timer method addProposal.
/**
* Adds the completion possibilities of timers to the proposal
* collector..
* <p>
* handles the following proposals:
* <ul>
* <li>start, start(timer)
* <li>stop
* <li>read
* <li>running
* <li>timeout
* </ul>
*
* @param propCollector
* the proposal collector.
* @param i
* the index of a part of the full reference, for which
* we wish to find completions.
*/
public static void addProposal(final ProposalCollector propCollector, final int i) {
final List<ISubReference> subrefs = propCollector.getReference().getSubreferences();
if (subrefs.size() != i + 1 || Subreference_type.arraySubReference.equals(subrefs.get(i).getReferenceType())) {
return;
}
propCollector.addProposal(START_OPERATION, START_OPERATION, ImageCache.getImage("timer.gif"));
propCollector.addTemplateProposal(START_OPERATION, new Template(START_TEMPLATE_NAME, "", propCollector.getContextIdentifier(), START_TEMPLATE, false), TTCN3CodeSkeletons.SKELETON_IMAGE);
propCollector.addProposal(STOP_OPERATION, STOP_OPERATION, ImageCache.getImage("timer.gif"));
propCollector.addProposal(READ_OPERATION, READ_OPERATION, ImageCache.getImage("timer.gif"));
propCollector.addProposal(RUNNING_OPERATION, RUNNING_OPERATION, ImageCache.getImage("timer.gif"));
propCollector.addProposal(TIMEOUT_OPERATION, TIMEOUT_OPERATION, ImageCache.getImage("timer.gif"));
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class Qualifier method findReferences.
@Override
public /**
* {@inheritDoc}
*/
void findReferences(final ReferenceFinder referenceFinder, final List<Hit> foundIdentifiers) {
if (definition != null && subReferences != null) {
// qualifiers were not semantically analyzed
for (ISubReference sr : subReferences) {
sr.findReferences(referenceFinder, foundIdentifiers);
}
if (referenceFinder.fieldId != null) {
// we are searching for a field of a type
final IType t = definition.getType(CompilationTimeStamp.getBaseTimestamp());
if (t == null) {
return;
}
final List<IType> typeArray = new ArrayList<IType>();
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(definition.getIdentifier()));
for (ISubReference sr : subReferences) {
reference.addSubReference(sr);
}
reference.setLocation(location);
reference.setMyScope(definition.getMyScope());
final boolean success = t.getFieldTypesAsArray(reference, 1, typeArray);
if (!success) {
// TODO: maybe a partially erroneous reference could be searched too
return;
}
if (subReferences.size() != typeArray.size()) {
ErrorReporter.INTERNAL_ERROR();
return;
}
for (int i = 0; i < subReferences.size(); i++) {
if (typeArray.get(i) == referenceFinder.type && !(subReferences.get(i) instanceof ArraySubReference) && subReferences.get(i).getId().equals(referenceFinder.fieldId)) {
foundIdentifiers.add(new Hit(subReferences.get(i).getId()));
}
}
}
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Sequence_Type method getSubrefsAsArray.
// This is the same as in ASN1_Set_type
@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:
{
if (components == null) {
return false;
}
final Identifier id = subreference.getId();
final CompField compField = components.getCompByName(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 = components.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