use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class TableConstraint method getOpenTypeAlternativeName.
// Original titan.core version: t_type->get_otaltname(is_strange);
private Identifier getOpenTypeAlternativeName(final CompilationTimeStamp timestamp, final Type type, final AtomicBoolean isStrange) {
StringBuffer sb = new StringBuffer();
// TODO: if (is_tagged() || is_constrained() || hasRawAttrs()) {
if (!type.getIsErroneous(timestamp) && type.isConstrained()) {
sb.append(type.getGenNameOwn());
isStrange.set(true);
} else if (!type.getIsErroneous(timestamp) && type instanceof Referenced_Type) {
Reference t_ref = ((Referenced_Type) type).getReference();
if (t_ref != null) {
final Identifier id = t_ref.getId();
final String dn = id.getDisplayName();
int i = dn.indexOf('.');
if (i >= 0 && i < dn.length()) {
// id is not regular because t_ref is a parameterized reference
sb.append(id.getName());
isStrange.set(true);
} else {
Assignment as = t_ref.getRefdAssignment(timestamp, true);
if (as == null) {
return null;
}
Scope assScope = as.getMyScope();
if (assScope.getParentScope() == assScope.getModuleScope()) {
sb.append(id.getName());
isStrange.set(false);
} else {
// t_ref is a dummy reference in a parameterized assignment
// (i.e. it points to a parameter assignment of an instantiation)
// perform the same examination recursively on the referenced type
// (which is the actual parameter)
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
chain.release();
return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
}
}
} else {
// the type comes from an information object [class]
// examine the referenced type recursively
IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
IType referencedType = ((Referenced_Type) type).getTypeRefd(timestamp, chain);
chain.release();
return getOpenTypeAlternativeName(timestamp, (Type) referencedType, isStrange);
}
} else {
Identifier tmpId1 = new Identifier(Identifier_type.ID_NAME, type.getFullName());
String s = tmpId1.getDisplayName();
// module name will be cut off:
if (s.startsWith("@") && s.indexOf('.') > 0) {
s = s.substring(s.indexOf('.') + 1);
}
Identifier tmpId2 = new Identifier(Identifier_type.ID_ASN, s);
sb.append(tmpId2.getTtcnName());
}
// conversion to lower case initial:
sb.replace(0, 1, sb.substring(0, 1).toLowerCase());
// trick:
Identifier tmpId = new Identifier(Identifier_type.ID_NAME, sb.toString());
return new Identifier(Identifier_type.ID_ASN, tmpId.getAsnName());
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class ASN1Module method addDeclaration.
@Override
public /**
* {@inheritDoc}
*/
void addDeclaration(final DeclarationCollector declarationCollector) {
final Identifier moduleId = declarationCollector.getReference().getModuleIdentifier();
if (null == moduleId) {
final List<ISubReference> subrefs = declarationCollector.getReference().getSubreferences();
if (1 == subrefs.size() && null != identifier && identifier.getName().equals(subrefs.get(0).getId().getName())) {
declarationCollector.addDeclaration(name, identifier.getLocation(), this);
}
imports.addDeclaration(declarationCollector);
} else if (null != identifier && moduleId.getName().equals(identifier.getName())) {
for (int i = 0; i < assignments.getNofAssignments(); i++) {
assignments.getAssignmentByIndex(i).addDeclaration(declarationCollector, 0);
}
} else {
if (imports.hasImportedModuleWithId(moduleId)) {
final ImportModule importation = imports.getImportedModuleById(moduleId);
if (null != importation) {
importation.addDeclaration(declarationCollector, identifier);
}
}
}
super.addDeclaration(declarationCollector);
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class ObjectClass_Definition method addDeclaration.
@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 Identifier identifier = subreference.getId();
final FieldSpecification fieldSpecification = fieldSpecifications.getFieldSpecificationByIdentifier(identifier);
if (null == fieldSpecification) {
return;
}
fieldSpecification.addDeclaration(declarationCollector, i + 1);
} else {
// final part of the reference
final String name = subreference.getId().getName();
final List<FieldSpecification> fieldSpecs = fieldSpecifications.getFieldSpecificationsWithPrefix(name);
for (final FieldSpecification field : fieldSpecs) {
declarationCollector.addDeclaration(field.getIdentifier().getDisplayName(), field.getLocation(), this);
}
}
}
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class InformationFromObj method getRefdSetting.
@Override
public /**
* {@inheritDoc}
*/
ISetting getRefdSetting(final CompilationTimeStamp timestamp) {
setIsErroneous(false);
ISetting temporalSetting = reference.getRefdSetting(timestamp);
if (null == temporalSetting) {
setIsErroneous(true);
return new Error_Setting();
}
SettingDetectionState currentState;
ObjectClass_Definition objectClass = null;
ObjectSet_definition objectSet = null;
Object_Definition object = null;
object = new Object_Definition(null);
ObjectSet_definition fromObjectSet = newObjectSetDefinitionInstance();
/* the first part */
switch(temporalSetting.getSettingtype()) {
case S_OS:
currentState = SettingDetectionState.ObjectSet;
objectSet = ((ObjectSet) temporalSetting).getRefdLast(timestamp, null);
objectClass = objectSet.getMyGovernor().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector = new ObjectSetElementVisitor_objectCollector(objectSet.getLocation(), objectClass, timestamp);
objectCollector.visitObjectSet(objectSet, false);
fromObjectSet = newObjectSetDefinitionInstance(objectCollector.giveObjects());
fromObjectSet.setMyGovernor(objectClass);
break;
case S_O:
currentState = SettingDetectionState.Object;
object = ((ASN1Object) temporalSetting).getRefdLast(timestamp, null);
objectClass = object.getMyGovernor().getRefdLast(timestamp, null);
break;
case S_OC:
currentState = SettingDetectionState.ObjectClass;
objectClass = ((ObjectClass) temporalSetting).getRefdLast(timestamp, null);
break;
case S_ERROR:
setIsErroneous(true);
return new Error_Setting();
default:
location.reportSemanticError(MessageFormat.format(INVALIDREFERENCE, getDisplayName()));
setIsErroneous(true);
return new Error_Setting();
}
final int nofFields = fieldName.getNofFields();
/* the middle part */
Identifier currentFieldName;
FieldSpecification currentFieldSpecification;
for (int i = 0; i < nofFields - 1; i++) {
currentFieldName = fieldName.getFieldByIndex(i);
currentFieldSpecification = objectClass.getFieldSpecifications().getFieldSpecificationByIdentifier(currentFieldName).getLast();
if (Fieldspecification_types.FS_ERROR.equals(currentFieldSpecification.getFieldSpecificationType())) {
setIsErroneous(true);
return new Error_Setting();
}
switch(currentState) {
case ObjectClass:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_O:
{
final Object_FieldSpecification temporalFieldspec = (Object_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
}
break;
case FS_OS:
{
final ObjectSet_FieldSpecification temporalFieldspec = (ObjectSet_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
}
break;
case FS_ERROR:
setIsErroneous(true);
return new Error_Setting();
default:
location.reportSemanticError(INVALIDNOTATION1);
setIsErroneous(true);
return new Error_Setting();
}
break;
case ObjectSet:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_O:
{
final Object_FieldSpecification temporalFieldspec = (Object_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector = new ObjectSetElementVisitor_objectCollector(location, objectClass, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
temporalObjects.trimToSize();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
object = ((Object_Definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector.visitObject(object);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
}
break;
case FS_OS:
{
final ObjectSet_FieldSpecification temporalFieldspec = (ObjectSet_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector2 = new ObjectSetElementVisitor_objectCollector(location, objectClass, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
objectSet = ((ObjectSet_definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector2.visitObjectSet(objectSet, false);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector2.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
}
break;
case FS_ERROR:
setIsErroneous(true);
return new Error_Setting();
default:
location.reportSemanticError(INVALIDNOTATION1);
setIsErroneous(true);
return new Error_Setting();
}
break;
case Object:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_O:
{
final Object_FieldSpecification temporalFieldspec = (Object_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
temporalSetting = object.getSettingByNameDefault(currentFieldName);
object = ((Object_Definition) temporalSetting).getRefdLast(timestamp, null);
}
break;
case FS_OS:
{
currentState = SettingDetectionState.ObjectSet;
final ObjectSet_FieldSpecification temporalFieldspec = (ObjectSet_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector = new ObjectSetElementVisitor_objectCollector(fromObjectSet, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
objectSet = ((ObjectSet_definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector.visitObjectSet(objectSet, false);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
}
break;
case FS_ERROR:
setIsErroneous(true);
return new Error_Setting();
default:
location.reportSemanticError(INVALIDNOTATION1);
setIsErroneous(true);
return new Error_Setting();
}
break;
default:
// if this could happen it would be FATAL ERROR
break;
}
}
/* and the last part... */
currentFieldName = fieldName.getFieldByIndex(nofFields - 1);
currentFieldSpecification = objectClass.getFieldSpecifications().getFieldSpecificationByIdentifier(currentFieldName).getLast();
temporalSetting = null;
switch(currentState) {
case ObjectClass:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_T:
{
final Open_Type type = new Open_Type(objectClass, currentFieldName);
type.setLocation(location);
type.setMyScope(myScope);
temporalSetting = type;
}
break;
case FS_V_FT:
{
final FixedTypeValue_FieldSpecification temporalFielspecification = (FixedTypeValue_FieldSpecification) currentFieldSpecification;
final ObjectClassField_Type type = new ObjectClassField_Type(temporalFielspecification.getType(), objectClass, currentFieldName);
type.setLocation(location);
temporalSetting = type;
}
break;
case FS_V_VT:
case FS_VS_FT:
case FS_VS_VT:
location.reportSemanticError(UNSUPPORTEDCONSTRUCT);
setIsErroneous(true);
break;
case FS_O:
case FS_OS:
location.reportSemanticError(INVALIDNOTATION2);
setIsErroneous(true);
break;
default:
setIsErroneous(true);
break;
}
break;
case ObjectSet:
switch(currentFieldSpecification.getFieldSpecificationType()) {
case FS_O:
{
final Object_FieldSpecification temporalFieldspec = (Object_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector = new ObjectSetElementVisitor_objectCollector(location, objectClass, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
object = ((Object_Definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector.visitObject(object);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
fromObjectSet.setMyScope(myScope);
temporalSetting = fromObjectSet;
}
break;
case FS_OS:
{
final ObjectSet_FieldSpecification temporalFieldspec = (ObjectSet_FieldSpecification) currentFieldSpecification;
objectClass = temporalFieldspec.getObjectClass().getRefdLast(timestamp, null);
final ObjectSetElementVisitor_objectCollector objectCollector2 = new ObjectSetElementVisitor_objectCollector(location, objectClass, timestamp);
final ASN1Objects temporalObjects = fromObjectSet.getObjs();
for (int j = 0; j < temporalObjects.getNofObjects(); j++) {
object = temporalObjects.getObjectByIndex(j).getRefdLast(timestamp, null);
if (!object.hasFieldSettingWithNameDefault(currentFieldName)) {
continue;
}
temporalSetting = object.getSettingByNameDefault(currentFieldName);
objectSet = ((ObjectSet_definition) temporalSetting).getRefdLast(timestamp, null);
objectCollector2.visitObjectSet(objectSet, false);
}
fromObjectSet = newObjectSetDefinitionInstance(objectCollector2.giveObjects());
fromObjectSet.setLocation(location);
fromObjectSet.setMyGovernor(objectClass);
fromObjectSet.setMyScope(myScope);
temporalSetting = fromObjectSet;
}
break;
case FS_V_FT:
case FS_VS_FT:
location.reportSemanticError(VALUESETFROMOBJECTS_NOT_SUPPORTED);
setIsErroneous(true);
break;
case FS_ERROR:
setIsErroneous(true);
break;
default:
location.reportSemanticError(INVALIDNOTATION3);
setIsErroneous(true);
break;
}
break;
case Object:
temporalSetting = object.getSettingByNameDefault(currentFieldName);
break;
default:
setIsErroneous(true);
break;
}
return temporalSetting;
}
use of org.eclipse.titan.designer.AST.Identifier in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST_Action method exportDebugAST.
private void exportDebugAST(final ZipOutputStream out, final Module module) throws Exception {
out.putNextEntry(new ZipEntry("DebugAST_for_" + module.getIdentifier().getName() + ".txt"));
out.write("*************************".getBytes());
out.write(lineend);
out.write(("Printing DEBUG information for module `" + module.getName() + "':").getBytes());
out.write(lineend);
out.write("*************************".getBytes());
out.write(lineend);
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(out, padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(out, padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(out, padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(out, padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(out, padding + 1, "This reference was last pointing to " + old.getFullName() + " analyzed at " + old.getLastTimeChecked());
}
} else if (node instanceof ComponentTypeBody) {
ComponentTypeBody body = (ComponentTypeBody) node;
Map<String, Definition> map = body.getDefinitionMap();
printInfoln(out, padding + 1, " contains definitions:");
if (map != null) {
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(out, padding + 2, entry.getKey() + " was last checked at " + entry.getValue().getLastTimeChecked());
}
}
}
if (node instanceof StatementBlock || node instanceof Definition) {
padding++;
}
return super.visit(node);
}
@Override
public int leave(IVisitableNode node) {
if (node instanceof StatementBlock || node instanceof Definition) {
padding--;
}
return super.leave(node);
}
});
out.write("*************************".getBytes());
out.write(lineend);
out.write(("Printing DEBUG information for module `" + module.getName() + "' finished").getBytes());
out.write(lineend);
out.write("*************************".getBytes());
out.write(lineend);
out.closeEntry();
}
Aggregations