use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class SpecialASN1Module method createSpecAsss.
/**
* Creates the special assignments by parsing the strings as if they
* were coming from an internal file and creating a module around them.
*
* @return the module of the special assignments created.
*/
private static ASN1Module createSpecAsss() {
if (null != specialAssignmentsModule) {
return specialAssignmentsModule;
}
final ASN1Assignments parsedAssignments = new ASN1Assignments();
ASN1Assignment actualAssignment;
for (String[] assignment : INTERNAL_ASSIGNMENTS) {
actualAssignment = SpecialASN1Module.parseSpecialInternalAssignment(assignment[1], new Identifier(Identifier_type.ID_ASN, assignment[0]));
parsedAssignments.addAssignment(actualAssignment);
}
// null as a project might not be a good idea
specialAssignmentsModule = new ASN1Module(new Identifier(Identifier_type.ID_ASN, INTERNAL_MODULE), null, Tag_types.AUTOMATIC_TAGS, false);
specialAssignmentsModule.setExports(new Exports(true));
specialAssignmentsModule.setImports(new Imports());
specialAssignmentsModule.setAssignments(parsedAssignments);
specialAssignmentsModule.setLocation(NULL_Location.INSTANCE);
specialAssignmentsModule.setScopeName(INTERNAL_MODULE);
final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
final ModuleImportationChain referenceChain = new ModuleImportationChain(ModuleImportationChain.CIRCULARREFERENCE, false);
specialAssignmentsModule.checkImports(timestamp, referenceChain, new ArrayList<Module>());
specialAssignmentsModule.check(timestamp);
return specialAssignmentsModule;
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ASN1_BitString_Type method check.
@Override
public /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (null != myScope) {
final Module module = myScope.getModuleScope();
if (null != module) {
if (module.getSkippedFromSemanticChecking()) {
return;
}
}
}
isErroneous = false;
if (null == namedValues) {
parseBlockBitstring();
}
if (isErroneous || null == namedValues) {
return;
}
/* check named bits */
final Map<String, Identifier> nameMap = new HashMap<String, Identifier>();
for (int i = 0, size = namedValues.getSize(); i < size; i++) {
final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
final Identifier identifier = namedValue.getName();
if (nameMap.containsKey(identifier.getName())) {
final Location tempLocation = nameMap.get(identifier.getName()).getLocation();
tempLocation.reportSingularSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONFIRST, identifier.getDisplayName()));
identifier.getLocation().reportSemanticError(MessageFormat.format(Assignments.DUPLICATEDEFINITIONREPEATED, identifier.getDisplayName()));
} else {
nameMap.put(identifier.getName(), identifier);
}
}
final Map<Integer, NamedValue> valueMap = new HashMap<Integer, NamedValue>();
for (int i = 0, size = namedValues.getSize(); i < size; i++) {
final NamedValue namedValue = namedValues.getNamedValueByIndex(i);
final IValue value = namedValue.getValue();
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
referenceChain.release();
if (last.getIsErroneous(timestamp)) {
continue;
}
switch(last.getValuetype()) {
case INTEGER_VALUE:
{
final Integer_Value integerValue = (Integer_Value) last;
if (integerValue.isNative()) {
final int intValue = integerValue.intValue();
final Integer intValueObject = Integer.valueOf(intValue);
if (intValue < 0) {
value.getLocation().reportSemanticError(MessageFormat.format("A non-negative INTEGER value was expected for named bit `{0}'' instead of {1}", namedValue.getName().getDisplayName(), intValueObject));
value.setIsErroneous(true);
continue;
}
if (valueMap.containsKey(intValueObject)) {
value.getLocation().reportSemanticError(MessageFormat.format("Duplicate value {0} for named bit `{1}''", intValueObject, namedValue.getName().getDisplayName()));
value.setIsErroneous(true);
final NamedValue temp = valueMap.get(intValueObject);
temp.getLocation().reportSemanticError(MessageFormat.format("Bit {0} is already assigned to name `{1}''", intValueObject, temp.getName().getDisplayName()));
} else {
valueMap.put(intValueObject, namedValue);
}
} else {
value.getLocation().reportSemanticError(MessageFormat.format("INTEGER value `{0}'' is too big to be used as a named bit", integerValue.getValueValue()));
value.setIsErroneous(true);
}
break;
}
default:
namedValue.getLocation().reportSemanticError(MessageFormat.format("INTEGER value was expected for named bit `{0}''", namedValue.getName().getDisplayName()));
break;
}
}
nameMap.clear();
if (null != constraints) {
constraints.check(timestamp);
}
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Enumerated_Type method check.
@Override
public final /**
* {@inheritDoc}
*/
void check(final CompilationTimeStamp timestamp) {
if (null != lastTimeChecked && !lastTimeChecked.isLess(timestamp)) {
return;
}
lastTimeChecked = timestamp;
if (null != myScope) {
final Module module = myScope.getModuleScope();
if (null != module) {
if (module.getSkippedFromSemanticChecking()) {
return;
}
}
}
isErroneous = false;
if (null == enumerations) {
parseBlockEnumeration();
}
if (isErroneous || null == enumerations) {
return;
}
/* check duplications and set missing values */
firstUnused = Integer.valueOf(0);
nameMap = new HashMap<String, EnumItem>();
final Map<Integer, EnumItem> valueMap = new HashMap<Integer, EnumItem>();
if (null != enumerations.enumItems1) {
final List<EnumItem> enumItems = enumerations.enumItems1.getItems();
for (EnumItem item : enumItems) {
checkEnumItem(timestamp, item, false, valueMap);
}
// set the default values
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
for (EnumItem item : enumItems) {
if (null == item.getValue() || !item.isOriginal()) {
final Integer_Value tempValue = new Integer_Value(firstUnused.longValue());
tempValue.setLocation(item.getLocation());
item.setValue(tempValue);
valueMap.put(firstUnused, item);
while (valueMap.containsKey(firstUnused)) {
firstUnused++;
}
}
}
}
if (null != enumerations.enumItems2) {
final List<EnumItem> enumItems = enumerations.enumItems2.getItems();
for (EnumItem item : enumItems) {
checkEnumItem(timestamp, item, true, valueMap);
}
}
if (null != constraints) {
constraints.check(timestamp);
}
if (myScope != null) {
checkEncode(timestamp);
checkVariants(timestamp);
}
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class ASN1Module method getAssBySRef.
@Override
public /**
* {@inheritDoc}
*/
Assignment getAssBySRef(final CompilationTimeStamp timestamp, final Reference reference, final IReferenceChain refChain) {
Identifier moduleId = reference.getModuleIdentifier();
final Identifier id = reference.getId();
if (null == id) {
return null;
}
Module module = null;
if (null == moduleId || moduleId.getName().equals(identifier.getName())) {
if (assignments.hasLocalAssignmentWithID(timestamp, id)) {
return assignments.getLocalAssignmentByID(timestamp, id);
}
if (null != moduleId) {
id.getLocation().reportSemanticError(MessageFormat.format(NOASSIGNMENT, id.getDisplayName(), identifier.getDisplayName()));
return null;
}
if (imports.singularImportedSymbols_map.containsKey(id.getName())) {
module = imports.singularImportedSymbols_map.get(id.getName());
moduleId = module.getIdentifier();
imports.getImportedModuleById(moduleId).setUsedForImportation();
} else if (imports.pluralImportedSymbols.contains(id.getName())) {
id.getLocation().reportSemanticError(MessageFormat.format(MORESYMBOLS, id.getDisplayName(), identifier.getDisplayName()));
return null;
} else {
id.getLocation().reportSemanticError(MessageFormat.format(NOASSIGNMENTORSYMBOL, id.getDisplayName(), identifier.getDisplayName()));
return null;
}
}
if (null == module) {
if (!imports.hasImportedModuleWithId(moduleId)) {
moduleId.getLocation().reportSemanticError(MessageFormat.format(NOIMPORTEDMODULE, moduleId.getDisplayName()));
return null;
}
if (!imports.getImportedModuleById(moduleId).hasSymbol(id)) {
id.getLocation().reportSemanticError(MessageFormat.format(NOSYMBOLSIMPORTED, id.getDisplayName(), moduleId.getDisplayName()));
return null;
}
imports.getImportedModuleById(moduleId).setUsedForImportation();
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
if (null == parser) {
return null;
}
module = parser.getModuleByName(moduleId.getName());
}
if (this == module || null == module) {
return null;
}
final List<ISubReference> newSubreferences = new ArrayList<ISubReference>();
newSubreferences.add(new FieldSubReference(id));
final Defined_Reference finalReference = new Defined_Reference(null, newSubreferences);
// FIXME add semantic check guard on project level.
return module.getAssBySRef(timestamp, finalReference);
}
use of org.eclipse.titan.designer.AST.Module in project titan.EclipsePlug-ins by eclipse.
the class Export_Debug_AST method run.
@Override
public void run(IAction action) {
if (targetEditor == null)
return;
IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
ProjectSourceParser parser = GlobalParser.getProjectSourceParser(file.getProject());
Module module = parser.containedModule(file);
if (module == null) {
TITANDebugConsole.getConsole().newMessageStream().println("No module was found");
}
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "':");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
module.accept(new ASTVisitor() {
private int padding = 0;
@Override
public int visit(IVisitableNode node) {
if (node instanceof Assignment) {
Assignment assignment = (Assignment) node;
printInfoln(padding, assignment.getAssignmentName(), assignment.getFullName(), assignment.getLastTimeChecked(), assignment.getLocation());
} else if (node instanceof Identifier) {
printInfoln(padding, "identifier", ((Identifier) node).getDisplayName(), null, ((Identifier) node).getLocation());
} else if (node instanceof Statement) {
Statement statement = (Statement) node;
printInfoln(padding, "statement", statement.getFullName(), statement.getLastTimeChecked(), statement.getLocation());
} else if (node instanceof Reference) {
Reference ref = (Reference) node;
printInfoln(padding, "reference", ref.getFullName(), ref.getLastTimeChecked(), ref.getLocation());
Assignment old = ref.getAssOld();
if (old != null) {
printInfoln(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(padding + 1, " contains definitions:");
for (Map.Entry<String, Definition> entry : map.entrySet()) {
printInfoln(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);
}
});
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
TITANDebugConsole.getConsole().newMessageStream().println("Printing DEBUG information for module `" + module.getName() + "' finished");
TITANDebugConsole.getConsole().newMessageStream().println("*************************");
}
Aggregations