use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.
the class Array_Value method getReferencedSubValue.
@Override
public /**
* {@inheritDoc}
*/
IValue getReferencedSubValue(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final IReferenceChain refChain) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (getIsErroneous(timestamp) || subreferences.size() <= actualSubReference) {
return this;
}
final IType type = myGovernor.getTypeRefdLast(timestamp);
if (type.getIsErroneous(timestamp) || !Type_type.TYPE_ARRAY.equals(type.getTypetype())) {
return null;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
final Value arrayIndex = ((ArraySubReference) subreference).getValue();
final IValue valueIndex = arrayIndex.getValueRefdLast(timestamp, refChain);
if (valueIndex.isUnfoldable(timestamp)) {
return null;
}
if (Value_type.INTEGER_VALUE.equals(valueIndex.getValuetype())) {
final ArrayDimension dimension = ((Array_Type) type).getDimension();
dimension.checkIndex(timestamp, valueIndex, Expected_Value_type.EXPECTED_CONSTANT);
if (dimension.getIsErroneous(timestamp)) {
return null;
}
final int index = ((Integer_Value) valueIndex).intValue() - (int) dimension.getOffset();
if (isIndexed()) {
for (int i = 0; i < values.getNofIndexedValues(); i++) {
IValue indexedValue = values.getIndexedValueByIndex(i).getIndex().getValue();
indexedValue = indexedValue.getValueRefdLast(timestamp, refChain);
if (Value_type.INTEGER_VALUE.equals(indexedValue.getValuetype()) && ((Integer_Value) indexedValue).intValue() == index) {
return values.getIndexedValueByIndex(i).getValue().getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
}
arrayIndex.getLocation().reportSemanticError(MessageFormat.format(NOINDEX, index, values.getFullName()));
} else if (index < 0 || index >= values.getNofValues()) {
// the error was already reported
} else {
return values.getValueByIndex(index).getReferencedSubValue(timestamp, reference, actualSubReference + 1, refChain);
}
return null;
}
arrayIndex.getLocation().reportSemanticError(ArraySubReference.INTEGERINDEXEXPECTED);
return null;
case fieldSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), type.getTypename()));
return null;
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(ParameterisedSubReference.INVALIDVALUESUBREFERENCE);
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.
the class Def_Timer method hasDefaultDuration.
/**
* Returns false if it is sure that the timer referred by array indices
* reference does not have a default duration. Otherwise it returns
* true.
*
* @param timestamp
* the timestamp of the actual semantic check cycle
* @param reference
* might be NULL when examining a single timer.
*
* @return true if the timer has a default duration, false otherwise.
*/
public boolean hasDefaultDuration(final CompilationTimeStamp timestamp, final Reference reference) {
if (defaultDuration == null) {
return false;
} else if (dimensions == null || reference == null) {
return true;
}
IValue v = defaultDuration;
final List<ISubReference> subreferences = reference.getSubreferences();
final int nofDimensions = dimensions.size();
final int nofReferences = subreferences.size() - 1;
final int upperLimit = (nofDimensions < nofReferences) ? nofDimensions : nofReferences;
for (int i = 0; i < upperLimit; i++) {
v = v.getValueRefdLast(timestamp, null);
if (Value_type.SEQUENCEOF_VALUE.equals(v.getValuetype())) {
final ISubReference ref = subreferences.get(i + 1);
if (!Subreference_type.arraySubReference.equals(ref.getReferenceType())) {
return true;
}
final IValue index = ((ArraySubReference) ref).getValue();
if (!Value_type.INTEGER_VALUE.equals(index.getValuetype())) {
return true;
}
final long realIndex = ((Integer_Value) index).getValue() - dimensions.get(i).getOffset();
if (realIndex >= 0 && realIndex < ((SequenceOf_Value) v).getNofComponents()) {
v = ((SequenceOf_Value) v).getValueByIndex((int) realIndex);
}
}
}
return !Value_type.NOTUSED_VALUE.equals(v.getValuetype());
}
use of org.eclipse.titan.designer.AST.ArraySubReference 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.ArraySubReference 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(')');
}
}
}
use of org.eclipse.titan.designer.AST.ArraySubReference in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Template method reArrangeInitCode.
@Override
public /**
* {@inheritDoc}
*/
void reArrangeInitCode(final JavaGenData aData, final StringBuilder source, final Module usageModule) {
final ISubReference tempSubreference = reference.getSubreferences().get(0);
if (tempSubreference instanceof ParameterisedSubReference) {
// generate code for the templates that are used in the actual parameter
// list of the reference
final ActualParameterList actualParameterList = ((ParameterisedSubReference) tempSubreference).getActualParameters();
if (actualParameterList != null) {
actualParameterList.reArrangeInitCode(aData, source, usageModule);
}
}
final Assignment assignment = reference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment.getAssignmentType() != Assignment_type.A_TEMPLATE) {
return;
}
ITTCN3Template template = ((Def_Template) assignment).getTemplate(CompilationTimeStamp.getBaseTimestamp());
final FormalParameterList formalParameterList = ((Def_Template) assignment).getFormalParameterList();
if (formalParameterList != null) {
// the reference points to a parameterized template
// we must perform the rearrangement for all non-parameterized templates
// that are referred by the parameterized template regardless of the
// sub-references of reference
template.reArrangeInitCode(aData, source, usageModule);
// be generated when the template's definition is reached)
if (assignment.getMyScope().getModuleScope() == usageModule) {
formalParameterList.generateCodeDefaultValues(aData, source);
}
} else {
// the reference points to a non-parameterized template
final List<ISubReference> subReferences = reference.getSubreferences();
if (subReferences != null && subReferences.size() > 1) {
// and perform the rearrangement for the referred field only
for (int i = 1; i < subReferences.size(); i++) {
final ISubReference subReference = subReferences.get(i);
if (subReference instanceof FieldSubReference) {
// stop if the body does not have fields
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 {
// stop if the body is not a list
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);
}
}
}
// we should initialize its entire body
if (assignment.getMyScope().getModuleScope() == usageModule) {
template.generateCodeInit(aData, source, template.get_lhs_name());
}
}
if (lengthRestriction != null) {
lengthRestriction.reArrangeInitCode(aData, source, usageModule);
}
}
Aggregations