use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class Referenced_ObjectSet method getRefdObjectClass.
/**
* Returns the referenced ObjectClass. The evaluation depends on the type of the reference
* @param timestamp
* @return the referenced ObjectClass if found. Otherwise returns null.
*/
public ObjectClass getRefdObjectClass(final CompilationTimeStamp timestamp) {
ObjectClass refdClass = null;
if (reference instanceof InformationFromObj) {
final ObjectClass tempGovernor = getRefdLast(timestamp, null).getMyGovernor();
if (tempGovernor == null) {
return null;
}
refdClass = tempGovernor.getRefdLast(timestamp, null);
final FieldName fn = ((InformationFromObj) reference).getFieldName();
if (fn.getNofFields() == 1) {
final Identifier fieldId = fn.getFieldByIndex(0);
final FieldSpecifications fss = refdClass.getFieldSpecifications();
FieldSpecification fs = fss.getFieldSpecificationByIdentifier(fieldId);
if (fs instanceof Undefined_FieldSpecification) {
fs = ((Undefined_FieldSpecification) fs).getRealFieldSpecification();
}
switch(fs.getFieldSpecificationType()) {
case FS_OS:
refdClass = ((ObjectSet_FieldSpecification) fs).getObjectClass().getRefdLast(timestamp, null);
break;
case FS_T:
// TODO: implement the other cases
break;
default:
// TODO: implement the other cases
break;
}
}
} else if (reference instanceof Parameterised_Reference) {
final Defined_Reference dref = ((Parameterised_Reference) reference).getRefDefdSimple();
if (dref == null) {
return null;
}
final Assignment ass = dref.getRefdAssignment(timestamp, false, null);
if (ass instanceof ObjectSet_Assignment) {
ass.check(timestamp);
// experimental
osReferenced = ((ObjectSet_Assignment) ass).getObjectSet(timestamp);
refdClass = ((ObjectSet_Assignment) ass).getObjectSet(timestamp).getMyGovernor().getRefdLast(timestamp, null);
}
} else if (reference instanceof Defined_Reference) {
final Assignment ass = ((Defined_Reference) reference).getRefdAssignment(timestamp, false, null);
if (ass instanceof ObjectSet_Assignment) {
ass.check(timestamp);
// experimental
osReferenced = ((ObjectSet_Assignment) ass).getObjectSet(timestamp);
refdClass = ((ObjectSet_Assignment) ass).getObjectSet(timestamp).getMyGovernor().getRefdLast(timestamp, null);
}
} else {
// to debug
return refdClass;
}
return refdClass;
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class ASN1Assignment method newInstance.
/**
* Creates a new instance of a parameterized assignment and returns i.
* In case of assignments which are not parameterized should return
* null.
*
* @param module
* the module in which the new assignment should be
* created.
*
* @return the assignment created.
*/
public final ASN1Assignment newInstance(final Module module) {
if (null == assPard) {
if (null != location) {
location.reportSemanticError(MessageFormat.format(NOTPARAMETERIZEDASSIGNMENT, getFullName()));
}
return null;
}
String newName = getIdentifier().getAsnName() + "." + module.getIdentifier().getAsnName() + ".inst";
newName += assPard.newInstanceNumber(module);
return internalNewInstance(new Identifier(Identifier_type.ID_ASN, newName));
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class NamedTemplates method checkUniqueness.
/**
* Checks the uniqueness of the named templates.
*
* @param timestamp
* the timestamp of the actual build cycle
*/
public void checkUniqueness(final CompilationTimeStamp timestamp) {
if (lastUniquenessCheck != null && !lastUniquenessCheck.isLess(timestamp)) {
return;
}
Identifier identifier;
String name;
if (lastUniquenessCheck == null) {
namedTemplateMap = new HashMap<String, NamedTemplate>(named_templates.size());
duplicatedNames = new ArrayList<NamedTemplate>();
for (NamedTemplate template : named_templates) {
identifier = template.getName();
name = identifier.getName();
if (namedTemplateMap.containsKey(name)) {
if (duplicatedNames == null) {
duplicatedNames = new ArrayList<NamedTemplate>();
}
duplicatedNames.add(template);
} else {
namedTemplateMap.put(name, template);
}
}
if (duplicatedNames != null) {
for (NamedTemplate template : duplicatedNames) {
named_templates.remove(template);
}
}
}
if (duplicatedNames != null) {
for (NamedTemplate template : duplicatedNames) {
identifier = template.getName();
name = identifier.getName();
final Location namedLocation = namedTemplateMap.get(name).getName().getLocation();
namedLocation.reportSingularSemanticError(MessageFormat.format(DUPLICATEFIELDNAMEFIRST, identifier.getDisplayName()));
template.getLocation().reportSemanticError(MessageFormat.format(DUPLICATEFIELDNAMEREPEATED, identifier.getDisplayName()));
}
}
lastUniquenessCheck = timestamp;
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class Named_Template_List method convert.
/**
* function used to convert a template written without naming the fields into a template with all field names provided.
*
* @param timestamp the timestamp of the actual build cycle
* @param other the template to be converted
*/
public static Named_Template_List convert(final CompilationTimeStamp timestamp, final Template_List other) {
final IType lastType = other.getMyGovernor().getTypeRefdLast(timestamp);
final int nofTemplates = other.getNofTemplates();
int nofTypeComponents = 0;
switch(lastType.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
nofTypeComponents = ((TTCN3_Sequence_Type) lastType).getNofComponents();
break;
case TYPE_ASN1_SEQUENCE:
nofTypeComponents = ((ASN1_Sequence_Type) lastType).getNofComponents(timestamp);
break;
case TYPE_SIGNATURE:
nofTypeComponents = ((Signature_Type) lastType).getNofParameters();
break;
case TYPE_TTCN3_SET:
nofTypeComponents = ((TTCN3_Set_Type) lastType).getNofComponents();
break;
case TYPE_ASN1_SET:
nofTypeComponents = ((ASN1_Set_Type) lastType).getNofComponents(timestamp);
break;
default:
}
if (nofTemplates > nofTypeComponents) {
other.getLocation().reportSemanticError(MessageFormat.format(TOOMANYELEMENTS, lastType.getTypename(), nofTypeComponents, nofTemplates));
other.setIsErroneous(true);
}
int upperLimit;
boolean allNotUsed;
if (nofTemplates <= nofTypeComponents) {
upperLimit = nofTemplates;
allNotUsed = true;
} else {
upperLimit = nofTypeComponents;
allNotUsed = false;
}
final NamedTemplates namedTemplates = new NamedTemplates();
for (int i = 0; i < upperLimit; i++) {
final TTCN3Template template = other.getTemplateByIndex(i);
if (!Template_type.TEMPLATE_NOTUSED.equals(template.getTemplatetype())) {
allNotUsed = false;
Identifier identifier = null;
switch(lastType.getTypetype()) {
case TYPE_TTCN3_SEQUENCE:
identifier = ((TTCN3_Sequence_Type) lastType).getComponentIdentifierByIndex(i);
break;
case TYPE_ASN1_SEQUENCE:
identifier = ((ASN1_Sequence_Type) lastType).getComponentIdentifierByIndex(i);
break;
case TYPE_SIGNATURE:
identifier = ((Signature_Type) lastType).getParameterIdentifierByIndex(i);
break;
case TYPE_TTCN3_SET:
identifier = ((TTCN3_Set_Type) lastType).getComponentIdentifierByIndex(i);
break;
case TYPE_ASN1_SET:
identifier = ((ASN1_Set_Type) lastType).getComponentIdentifierByIndex(i);
break;
default:
// previous check
break;
}
if (identifier != null) {
final NamedTemplate namedTemplate = new NamedTemplate(identifier.newInstance(), template);
namedTemplate.setLocation(template.getLocation());
namedTemplates.addTemplate(namedTemplate);
}
}
}
namedTemplates.setMyScope(other.getMyScope());
namedTemplates.setFullNameParent(other);
if (allNotUsed && nofTemplates > 0 && !Type_type.TYPE_SIGNATURE.equals(lastType.getTypetype())) {
other.getLocation().reportSemanticWarning(MessageFormat.format(ALLARENOTUSED, lastType.getTypename()));
other.setIsErroneous(true);
}
final Named_Template_List target = new Named_Template_List(namedTemplates);
target.copyGeneralProperties(other);
return target;
}
use of org.eclipse.titan.designer.AST.Identifier 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