use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Seq_Choice_BaseType method resolveReference.
@Override
public /**
* {@inheritDoc}
*/
Declaration resolveReference(final Reference reference, final int subRefIdx, final ISubReference lastSubreference) {
final List<ISubReference> subreferences = reference.getSubreferences();
int actualIndex = subRefIdx;
while (actualIndex < subreferences.size() && subreferences.get(actualIndex) instanceof ArraySubReference) {
++actualIndex;
}
if (actualIndex == subreferences.size()) {
return null;
}
final Identifier fieldID = subreferences.get(actualIndex).getId();
if (subreferences.get(actualIndex) == lastSubreference) {
return Declaration.createInstance(getDefiningAssignment(), fieldID);
}
final CompField compField = getComponentByName(fieldID);
final IType compFieldType = compField.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (compFieldType instanceof IReferenceableElement) {
final Declaration decl = ((IReferenceableElement) compFieldType).resolveReference(reference, actualIndex + 1, lastSubreference);
return decl != null ? decl : Declaration.createInstance(getDefiningAssignment(), compField.getIdentifier());
}
return null;
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Seq_Choice_BaseType method addProposal.
/**
* Searches and adds a completion proposal to the provided collector if
* a valid one is found.
* <p>
* In case of structural types, the member fields are checked if they
* could complete the proposal.
*
* @param propCollector
* the proposal collector to add the proposal to, and
* used to get more information
* @param i
* index, used to identify which element of the reference
* (used by the proposal collector) should be checked for
* completions.
*/
@Override
public /**
* {@inheritDoc}
*/
void addProposal(final ProposalCollector propCollector, final int i) {
final List<ISubReference> subreferences = propCollector.getReference().getSubreferences();
if (subreferences.size() <= i || components == null) {
return;
}
final ISubReference subreference = subreferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
if (subreferences.size() > i + 1) {
// the reference might go on
final CompField compField = components.getCompByName(subreference.getId());
if (compField == null) {
return;
}
final IType type = compField.getType();
if (type != null) {
type.addProposal(propCollector, i + 1);
}
} else {
// final part of the reference
final List<CompField> compFields = components.getComponentsWithPrefix(subreference.getId().getName());
for (final CompField compField : compFields) {
final String proposalKind = compField.getType().getProposalDescription(new StringBuilder()).toString();
propCollector.addProposal(compField.getIdentifier(), " - " + proposalKind, ImageCache.getImage(getOutlineIcon()), proposalKind);
}
}
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Seq_Choice_BaseType method addDeclaration.
/**
* Searches and adds a declaration proposal to the provided collector if
* a valid one is found.
* <p>
* In case of structural types, the member fields are checked if they
* could be the declaration searched for.
*
* @param declarationCollector
* the declaration collector to add the declaration to,
* and used to get more information.
* @param i
* index, used to identify which element of the reference
* (used by the declaration collector) should be checked.
*/
@Override
public /**
* {@inheritDoc}
*/
void addDeclaration(final DeclarationCollector declarationCollector, final int i) {
final List<ISubReference> subreferences = declarationCollector.getReference().getSubreferences();
if (subreferences.size() <= i) {
return;
}
final ISubReference subreference = subreferences.get(i);
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
if (subreferences.size() > i + 1) {
// the reference might go on
final CompField compField = components.getCompByName(subreference.getId());
if (compField == null) {
return;
}
final IType type = compField.getType();
if (type != null) {
type.addDeclaration(declarationCollector, i + 1);
}
} else {
// final part of the reference
final List<CompField> compFields = components.getComponentsWithPrefix(subreference.getId().getName());
for (final CompField compField : compFields) {
declarationCollector.addDeclaration(compField.getIdentifier().getDisplayName(), compField.getIdentifier().getLocation(), this);
}
}
}
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Seq_Choice_BaseType method generateCodeIsPresentBoundChosen.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, String field) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return;
}
if (subReferenceIndex >= subreferences.size()) {
return;
}
final StringBuilder closingBrackets = new StringBuilder();
if (isTemplate) {
boolean anyvalueReturnValue = true;
if (optype == Operation_type.ISPRESENT_OPERATION) {
anyvalueReturnValue = isPresentAnyvalueEmbeddedField(expression, subreferences, subReferenceIndex);
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
anyvalueReturnValue = false;
}
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", externalId));
expression.expression.append("case UNINITIALIZED_TEMPLATE:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("case ANY_VALUE:\n");
expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, anyvalueReturnValue ? "true" : "false"));
expression.expression.append("break;\n");
expression.expression.append("case SPECIFIC_VALUE:{\n");
closingBrackets.append("break;}\n");
closingBrackets.append("default:\n");
closingBrackets.append(MessageFormat.format("{0} = false;\n", globalId));
closingBrackets.append("break;\n");
closingBrackets.append("}\n");
closingBrackets.append("}\n");
}
final ISubReference subReference = subreferences.get(subReferenceIndex);
if (!(subReference instanceof FieldSubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return;
}
final Identifier fieldId = ((FieldSubReference) subReference).getId();
final CompField compField = getComponentByName(fieldId);
final Type nextType = compField.getType();
final boolean nextOptional = !isTemplate && compField.isOptional();
if (nextOptional) {
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("Optional<{0}{1}> {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
if (subReferenceIndex == subreferences.size() - 1) {
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
expression.expression.append("case OPTIONAL_UNBOUND:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("case OPTIONAL_OMIT:\n");
expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, optype == Operation_type.ISBOUND_OPERATION ? "true" : "false"));
expression.expression.append("break;\n");
expression.expression.append("default:\n");
expression.expression.append("{\n");
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
if (optype == Operation_type.ISBOUND_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
} else if (optype == Operation_type.ISPRESENT_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isPresent({2});\n", globalId, temporalId2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
}
expression.expression.append("break;}\n");
expression.expression.append("}\n");
// at the end of the reference chain
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
} else {
// still more to go
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
expression.expression.append("case OPTIONAL_UNBOUND:\n");
expression.expression.append("case OPTIONAL_OMIT:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("default:\n");
expression.expression.append("break;\n");
expression.expression.append("}\n");
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
}
} else {
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId = aData.getTemporaryVariableName();
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = new {0}{1}({3});\n", getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId));
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
if (optype == Operation_type.ISBOUND_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
} else if (optype == Operation_type.ISPRESENT_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.{2}({3});\n", globalId, temporalId2, subReferenceIndex != subreferences.size() - 1 ? "isBound" : "isPresent", subReferenceIndex == subreferences.size() - 1 && isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
if (subReferenceIndex == subreferences.size() - 1) {
expression.expression.append(MessageFormat.format("if ({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
expression.expression.append("}\n");
}
}
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
}
expression.expression.append(closingBrackets);
}
use of org.eclipse.titan.designer.AST.ISubReference in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Type method getSubrefsAsArray.
// This is the same as in ASN1_Sequence_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:
{
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