use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions in project titan.EclipsePlug-ins by eclipse.
the class For_Loop_Definitions method updateSyntax.
/**
* Handles the incremental parsing of this list of definitions.
*
* @param reparser
* the parser doing the incremental parsing.
* @param isDamaged
* true if the location contains the damaged area, false
* if only its' location needs to be updated.
*/
@Override
public /**
* {@inheritDoc}
*/
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (!isDamaged) {
// handle the simple case quickly
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
final Location temporalLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(temporalLocation)) {
if (!temporalLocation.equals(cumulativeLocation)) {
reparser.updateLocation(cumulativeLocation);
}
reparser.updateLocation(temporalLocation);
}
}
return;
}
// calculate damaged region
int result = 0;
lastCompilationTimeStamp = null;
boolean enveloped = false;
int nofDamaged = 0;
int leftBoundary = location.getOffset();
int rightBoundary = location.getEndOffset();
final int damageOffset = reparser.getDamageStart();
IAppendableSyntax lastAppendableBeforeChange = null;
IAppendableSyntax lastPrependableBeforeChange = null;
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
final Definition temp = iterator.next();
final Location tempLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (tempLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
enveloped = true;
leftBoundary = cumulativeLocation.getOffset();
rightBoundary = cumulativeLocation.getEndOffset();
} else if (reparser.isDamaged(cumulativeLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
lastAppendableBeforeChange = temp;
} else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
lastPrependableBeforeChange = temp;
}
} else {
if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
leftBoundary = cumulativeLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (cumulativeLocation.getOffset() >= damageOffset && cumulativeLocation.getOffset() < rightBoundary) {
rightBoundary = cumulativeLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
}
// was not enveloped
if (!enveloped && isDamaged) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
// the extension might be correct
if (lastAppendableBeforeChange != null) {
final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
if (isBeingExtended) {
leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (lastPrependableBeforeChange != null) {
final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
if (temp != null && reparser.endsWithToken(temp)) {
rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (nofDamaged != 0) {
// remove damaged stuff
removeStuffInRange(reparser);
lastUniquenessCheckTimeStamp = null;
}
}
// update what is left
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
final Location temporalLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(cumulativeLocation)) {
try {
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(temporalLocation));
if (reparser.getNameChanged()) {
lastUniquenessCheckTimeStamp = null;
reparser.setNameChanged(false);
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
definitions.remove(temp);
reparser.extendDamagedRegion(cumulativeLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
if (result == 1) {
removeStuffInRange(reparser);
lastUniquenessCheckTimeStamp = null;
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
final Location temporalLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(temporalLocation)) {
if (!temporalLocation.equals(cumulativeLocation)) {
reparser.updateLocation(cumulativeLocation);
}
reparser.updateLocation(temporalLocation);
}
}
if (!enveloped && reparser.envelopsDamage(location)) {
// whole definition region has to be re-parsed
throw new ReParseException();
}
if (result != 0) {
lastUniquenessCheckTimeStamp = null;
throw new ReParseException(result);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions in project titan.EclipsePlug-ins by eclipse.
the class Group method updateSyntax.
/**
* Handles the incremental parsing of this list of definitions.
*
* @param reparser
* the parser doing the incremental parsing.
* @param allImportedModules
* the list of module importations found in the same
* module.
* @param allDefinitions
* the list of definitions found in the same module.
* @param allFriends
* the list of friend module declarations found in the
* same module.
* @return in case of processing error the minimum amount of semantic
* levels that must be destroyed to handle the syntactic
* changes, otherwise 0.
*/
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> allImportedModules, final List<Definition> allDefinitions, final List<FriendModule> allFriends) throws ReParseException {
int result = 0;
Location tempLocation = identifier.getLocation();
if (reparser.isDamaged(tempLocation)) {
if (reparser.envelopsDamage(tempLocation) || reparser.isExtending(tempLocation)) {
reparser.extendDamagedRegion(tempLocation);
result = reparseIdentifier(reparser);
if (result != 0) {
throw new ReParseException(result);
}
} else {
throw new ReParseException();
}
} else {
reparser.updateLocation(tempLocation);
}
if (reparser.isDamaged(innerLocation) && !reparser.envelopsDamage(innerLocation)) {
throw new ReParseException();
}
boolean enveloped = false;
int nofDamaged = 0;
int leftBoundary = innerLocation.getOffset();
int rightBoundary = innerLocation.getEndOffset();
final int damageOffset = reparser.getDamageStart();
IAppendableSyntax lastAppendableBeforeChange = null;
IAppendableSyntax lastPrependableBeforeChange = null;
for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
final Group temp = groups.get(i);
tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
}
for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
final ImportModule temp = importedModules.get(i);
tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
}
for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
final FriendModule temp = friendModules.get(i);
tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
final Definition temp = iterator.next();
tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
lastAppendableBeforeChange = temp;
} else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
lastPrependableBeforeChange = temp;
}
// reparser.extendDamagedRegion(temp_location);
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
final Location tempCommentLocation = temp.getCommentLocation();
if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
rightBoundary = tempCommentLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
// was not enveloped
if (!enveloped && reparser.envelopsDamage(location)) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
// correct
if (lastAppendableBeforeChange != null) {
final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
if (isBeingExtended) {
leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (lastPrependableBeforeChange != null) {
final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
if (temp != null && reparser.endsWithToken(temp)) {
rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (nofDamaged != 0) {
// remove damaged stuff
removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
}
// update what is left
for (int i = 0; i < groups.size(); i++) {
final Group temp = groups.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
temp.updateSyntax(reparser, allImportedModules, allDefinitions, friendModules);
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
groups.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
for (int i = 0; i < importedModules.size(); i++) {
final ImportModule temp = importedModules.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
importedModules.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
for (int i = 0; i < friendModules.size(); i++) {
final FriendModule temp = friendModules.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
friendModules.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, isDamaged);
if (reparser.getNameChanged()) {
lastUniquenessCheckTimeStamp = null;
reparser.setNameChanged(false);
}
if (isDamaged) {
temp.checkRoot();
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
definitions.remove(temp);
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
e.decreaseDepth();
throw e;
}
}
}
}
if (result == 1) {
removeStuffInRange(reparser, allImportedModules, allDefinitions, friendModules);
}
for (int i = 0, size = groups.size(); i < size; i++) {
final Group temp = groups.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
for (int i = 0, size = importedModules.size(); i < size; i++) {
final ImportModule temp = importedModules.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
for (int i = 0, size = friendModules.size(); i < size; i++) {
final FriendModule temp = friendModules.get(i);
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
if (withAttributesPath != null && reparser.isAffected(withAttributesPath.getLocation())) {
if (reparser.envelopsDamage(withAttributesPath.getLocation())) {
reparser.extendDamagedRegion(withAttributesPath.getLocation());
result = reparseOptionalWithStatement(reparser);
if (result != 0) {
throw new ReParseException(result);
}
return;
}
withAttributesPath.updateSyntax(reparser, reparser.envelopsDamage(withAttributesPath.getLocation()));
reparser.updateLocation(withAttributesPath.getLocation());
}
if (!enveloped && reparser.envelopsDamage(innerLocation)) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
result = reparseModuleDefinitionsList(reparser);
}
reparser.updateLocation(innerLocation);
if (result > 1) {
throw new ReParseException(result - 1);
}
return;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions in project titan.EclipsePlug-ins by eclipse.
the class RunsOnScopeReduction method process.
@Override
protected void process(IVisitableNode node, Problems problems) {
final Set<Identifier> definitions = new HashSet<Identifier>();
final Identifier componentIdentifier;
final CompilationTimeStamp timestamp = CompilationTimeStamp.getBaseTimestamp();
final Identifier identifier;
boolean isTestCase = false;
if (node instanceof Def_Function) {
final Def_Function variable = (Def_Function) node;
final Component_Type componentType = variable.getRunsOnType(timestamp);
if (componentType == null) {
return;
}
componentIdentifier = componentType.getComponentBody().getIdentifier();
identifier = variable.getIdentifier();
} else if (node instanceof Def_Altstep) {
final Def_Altstep variable = (Def_Altstep) node;
final Component_Type componentType = variable.getRunsOnType(timestamp);
if (componentType == null) {
return;
}
componentIdentifier = componentType.getComponentBody().getIdentifier();
identifier = variable.getIdentifier();
} else {
final Def_Testcase variable = (Def_Testcase) node;
final Component_Type componentType = variable.getRunsOnType(timestamp);
if (componentType == null) {
return;
}
componentIdentifier = componentType.getComponentBody().getIdentifier();
identifier = variable.getIdentifier();
isTestCase = true;
}
final ReferenceCheck chek = new ReferenceCheck();
node.accept(chek);
definitions.addAll(chek.getIdentifiers());
if (definitions.isEmpty()) {
if (isTestCase) {
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.", componentIdentifier.getDisplayName()));
} else {
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used, can be removed.", componentIdentifier.getDisplayName()));
}
} else if (!definitions.contains(componentIdentifier)) {
ArrayList<Identifier> list = new ArrayList<Identifier>(definitions);
if (definitions.size() == 1) {
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use `{1}'' component.", componentIdentifier.getName(), list.get(0).getDisplayName()));
} else {
// FIXME: implement other cases
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used.", componentIdentifier.getDisplayName()));
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method updateSyntax.
@Override
public /**
* {@inheritDoc}
*/
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (isDamaged) {
throw new ReParseException();
}
for (final Definition definition : definitions) {
definition.updateSyntax(reparser, false);
reparser.updateLocation(definition.getLocation());
if (!definition.getLocation().equals(definition.getCumulativeDefinitionLocation())) {
reparser.updateLocation(definition.getCumulativeDefinitionLocation());
}
}
if (extendsReferences != null) {
extendsReferences.updateSyntax(reparser, false);
reparser.updateLocation(extendsReferences.getLocation());
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions in project titan.EclipsePlug-ins by eclipse.
the class ComponentTypeBody method collectDefinitionsFromAttributeExtends.
/**
* Collects the definitions coming from extends attributes.
* In reality no collection is done, but it is checked that the actual component has all definitions from the extended component.
*/
private void collectDefinitionsFromAttributeExtends() {
final List<ComponentTypeBody> parents = getAttributeExtendsInheritedComponentBodies();
for (final ComponentTypeBody parent : parents) {
for (final Definition definition : parent.getDefinitions()) {
final Identifier id = definition.getIdentifier();
final String name = id.getName();
// Check if we have inherited 2 different definitions with the same name
if (extendsGainedDefinitions.containsKey(name)) {
final Definition myDefinition = extendsGainedDefinitions.get(name);
if (definition != myDefinition) {
location.reportSemanticError(MessageFormat.format(INHERITANCECOLLISSION, id.getDisplayName(), definition.getMyScope().getFullName(), myDefinition.getMyScope().getFullName()));
}
continue;
}
if (!definitions.hasDefinition(name)) {
location.reportSemanticError(MessageFormat.format("Missing local definition of `{0}'', which was inherited from component type `{1}''", id.getDisplayName(), definition.getMyScope().getFullName()));
continue;
}
attributeGainedDefinitions.put(name, definition);
}
}
}
Aggregations