use of org.eclipse.titan.designer.AST.FieldSubReference 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;
}
}
use of org.eclipse.titan.designer.AST.FieldSubReference in project titan.EclipsePlug-ins by eclipse.
the class ASN1_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);
if (compField.isOptional()) {
return false;
}
return compField.getType().isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
use of org.eclipse.titan.designer.AST.FieldSubReference in project titan.EclipsePlug-ins by eclipse.
the class Exports method check.
/**
* Checks this export list.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
*/
public void check(final CompilationTimeStamp timestamp) {
if (null != lastCompilationTimeStamp && !lastCompilationTimeStamp.isLess(timestamp)) {
return;
}
if (exportAll) {
lastCompilationTimeStamp = timestamp;
return;
}
symbols.checkUniqueness(timestamp);
for (int i = 0; i < symbols.size(); i++) {
final List<ISubReference> list = new ArrayList<ISubReference>();
list.add(new FieldSubReference(symbols.getNthElement(i)));
final Defined_Reference reference = new Defined_Reference(null, list);
/* check whether exists or not */
module.getAssBySRef(timestamp, reference);
}
lastCompilationTimeStamp = timestamp;
}
use of org.eclipse.titan.designer.AST.FieldSubReference in project titan.EclipsePlug-ins by eclipse.
the class Parameterised_Reference method getRefDefdSimple.
/**
* Resolve the formal parameters of the referenced assignment with the
* help of the actual parameters. Instantiate a new assignment from it
* and return a reference to this assignment.
*
* @return the reference to the newly instantiated assignment.
*/
public Defined_Reference getRefDefdSimple() {
final Module module = myScope.getModuleScope();
// This is a little trick, but otherwise we would not have the
// true compilation timestamp
final CompilationTimeStamp compilationTimeStamp = module.getLastImportationCheckTimeStamp();
if (compilationTimeStamp == null) {
// compilationTimeStamp = CompilationTimeStamp.getNewCompilationCounter(); //this forces re-check
return null;
}
if (null != lastCheckTimeStamp && !lastCheckTimeStamp.isLess(compilationTimeStamp)) {
if (isErroneous) {
return null;
}
return finalReference;
}
lastCheckTimeStamp = compilationTimeStamp;
final Assignment parass = assignmentReference.getRefdAssignment(compilationTimeStamp, true, null);
if (null == parass) {
isErroneous = true;
return null;
} else if (!(parass instanceof ASN1Assignment)) {
assignmentReference.getLocation().reportSemanticError(ASSIGNMENTEXPECTED);
isErroneous = true;
return null;
}
final Ass_pard assPard = ((ASN1Assignment) parass).getAssPard();
if (null == assPard) {
assignmentReference.getLocation().reportSemanticError(PARAMETERISEDASSIGNMENTEXPECTED);
isErroneous = true;
return assignmentReference;
}
addAssignments(assPard, compilationTimeStamp);
// Add the assignments made from the formal and actual
// parameters to the actual module
assignments.setRightScope(myScope);
assignments.setParentScope(parass.getMyScope());
assignments.setFullNameParent(this);
assignments.check(compilationTimeStamp);
// create a copy of the assignment and add it to the actual
// module
final ASN1Assignment newAssignment = ((ASN1Assignment) parass).newInstance(module);
newAssignmentNameStart = new NameReStarter(new StringBuilder(module.getFullName()).append(INamedNode.DOT).append(newAssignment.getIdentifier().getDisplayName()).toString());
newAssignmentNameStart.setFullNameParent(parass);
newAssignment.setFullNameParent(newAssignmentNameStart);
newAssignment.setLocation(location);
newAssignment.getIdentifier().setLocation(assignmentReference.getLocation());
((ASN1Assignments) module.getAssignments()).addDynamicAssignment(compilationTimeStamp, newAssignment);
newAssignment.setMyScope(assignments);
newAssignment.check(compilationTimeStamp);
final List<ISubReference> subreferences = new ArrayList<ISubReference>(1);
subreferences.add(new FieldSubReference(newAssignment.getIdentifier()));
finalReference = new Defined_Reference(module.getIdentifier(), subreferences);
finalReference.setFullNameParent(this);
finalReference.setMyScope(module);
return finalReference;
}
use of org.eclipse.titan.designer.AST.FieldSubReference in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Template method generateRearrangeInitCodeReferenced.
private void generateRearrangeInitCodeReferenced(final JavaGenData aData, final StringBuilder source, final ExpressionStruct expression) {
/**
* Initially we can assume that:
* - this is a referenced template and a part of a non-parameterized template
* - u.ref.ref points to (a field of) a non-parameterized template within the same module as this.
* - this ensures that the do-while loop will run at least twice (i.e. the first continue statement will be reached in the first iteration)
*/
final Stack<ISubReference> referenceStack = new Stack<ISubReference>();
ITTCN3Template template = this;
for (; ; ) {
if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
final Reference reference = ((Referenced_Template) template).getReference();
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
/**
* Don't follow the reference if:
* - the referenced definition is not a template
* - the referenced template is parameterized or
* - the referenced template is in different module
*/
if (assignment.getAssignmentType() == Assignment_type.A_TEMPLATE && ((Def_Template) assignment).getFormalParameterList() == null && assignment.getMyScope().getModuleScope() == myScope.getModuleScope()) {
// accumulate the sub-references of the referred reference
final List<ISubReference> subReferences = reference.getSubreferences();
if (subReferences != null && subReferences.size() > 1) {
for (int i = subReferences.size(); i > 1; i--) {
referenceStack.push(subReferences.get(i - 1));
}
}
// jump to the referred top-level template
template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
// start the iteration from the beginning
continue;
} else {
// the reference cannot be followed
break;
}
}
// stop if there are no sub-references
if (referenceStack.isEmpty()) {
break;
}
// take the topmost sub-reference
final ISubReference subReference = referenceStack.peek();
if (subReference instanceof FieldSubReference) {
if (template.getTemplatetype() != Template_type.NAMED_TEMPLATE_LIST) {
break;
}
// the field reference can be followed
final Identifier fieldId = ((FieldSubReference) subReference).getId();
template = ((Named_Template_List) template).getNamedTemplate(fieldId).getTemplate();
} else {
// trying to follow an array reference
if (template.getTemplatetype() != Template_type.TEMPLATE_LIST) {
break;
}
IValue arrayIndex = ((ArraySubReference) subReference).getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
arrayIndex = arrayIndex.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (arrayIndex.getValuetype() != Value_type.INTEGER_VALUE) {
break;
}
// the index is available at compilation time
long index = ((Integer_Value) arrayIndex).getValue();
// index transformation in case of arrays
if (template.getMyGovernor().getTypetype() == Type_type.TYPE_ARRAY) {
index = index - ((Array_Type) template.getMyGovernor()).getDimension().getOffset();
}
template = ((Template_List) template).getTemplateByIndex((int) index);
}
// the topmost sub-reference was processed
// it can be erased from the stack
referenceStack.pop();
}
// the smallest dependent template is now in t
// generate the initializer sequence for t
template.generateCodeInit(aData, source, template.get_lhs_name());
// the equivalent Java code of the referenced template is composed of the
// genname of t and the remained sub-references in refstack
expression.expression.append(template.getGenNameOwn(myScope));
while (!referenceStack.isEmpty()) {
final ISubReference subReference = referenceStack.pop();
if (subReference instanceof FieldSubReference) {
expression.expression.append(MessageFormat.format(".get{0}()", FieldSubReference.getJavaGetterName(((FieldSubReference) subReference).getId().getName())));
} else {
expression.expression.append(".getAt(");
((ArraySubReference) subReference).getValue().generateCodeExpression(aData, expression, false);
expression.expression.append(')');
}
}
}
Aggregations