Commit 345c805a authored by ekrisza's avatar ekrisza
Browse files

some improvements for incremental parsing when handling overlapping

definitions
parent 55ff90e2
......@@ -54,8 +54,6 @@ public final class Def_Const extends Definition {
public static final String SIGNATURENOTALLOWED = "Constant can not be defined for signature type `{0}''";
private static final String KIND = "constant ";
private Location comulativeDefinitionLocation = null;
public static String getKind() {
return KIND;
......@@ -103,19 +101,6 @@ public final class Def_Const extends Definition {
value.setMyScope(scope);
}
}
@Override
public Location getComulativeDefinitionLocation() {
if (comulativeDefinitionLocation != null) {
return comulativeDefinitionLocation;
}
return super.getComulativeDefinitionLocation();
}
public void setComulativeDefinitionLocation(final Location location) {
this.comulativeDefinitionLocation = location;
}
@Override
public Type getType(final CompilationTimeStamp timestamp) {
......
......@@ -83,6 +83,8 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
private VisibilityModifier visibilityModifier;
private Location commentLocation = null;
private Location cumulativeDefinitionLocation = null;
//TODO this should be removed as the same functionality is present in Titanium as codesmell.
public List<String> referingHere = new ArrayList<String>();
......@@ -203,10 +205,21 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
*
* @return the location of the same typed definition list the definition is located in.
* */
public Location getComulativeDefinitionLocation() {
public Location getCumulativeDefinitionLocation() {
if (cumulativeDefinitionLocation != null) {
return cumulativeDefinitionLocation;
}
return getLocation();
}
/**
* Set the cumulative location of this definition
* */
public void setCumulativeDefinitionLocation(final Location location) {
this.cumulativeDefinitionLocation = location;
}
/**
* @return the with attribute path element of this definition. If it did
* not exist it will be created.
......
......@@ -636,25 +636,25 @@ public final class Definitions extends Assignments implements ILocateableNode {
Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
Location tempLocation = temp.getLocation();
Location comulativeLocation = temp.getComulativeDefinitionLocation();
if (tempLocation.equals(comulativeLocation) && reparser.envelopsDamage(tempLocation)) {
Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (tempLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(comulativeLocation)) {
leftBoundary = cumulativeLocation.getOffset();
rightBoundary = cumulativeLocation.getEndOffset();
} else if (reparser.isDamaged(cumulativeLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == comulativeLocation.getEndOffset()) {
if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
lastAppendableBeforeChange = temp;
} else if (reparser.getDamageEnd() == comulativeLocation.getOffset()) {
} else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
lastPrependableBeforeChange = temp;
}
} else {
if (comulativeLocation.getEndOffset() < damageOffset && comulativeLocation.getEndOffset() > leftBoundary) {
leftBoundary = comulativeLocation.getEndOffset() + 1;
if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
leftBoundary = cumulativeLocation.getEndOffset() + 1;
lastAppendableBeforeChange = temp;
}
if (comulativeLocation.getOffset() >= damageOffset && comulativeLocation.getOffset() < rightBoundary) {
rightBoundary = comulativeLocation.getOffset();
if (cumulativeLocation.getOffset() >= damageOffset && cumulativeLocation.getOffset() < rightBoundary) {
rightBoundary = cumulativeLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
......@@ -793,7 +793,8 @@ public final class Definitions extends Assignments implements ILocateableNode {
Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(cumulativeLocation)) {
try {
boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, isDamaged);
......@@ -811,7 +812,7 @@ public final class Definitions extends Assignments implements ILocateableNode {
if (e.getDepth() == 1) {
enveloped = false;
definitions.remove(temp);
reparser.extendDamagedRegion(tempLocation);
reparser.extendDamagedRegion(cumulativeLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
......@@ -866,7 +867,11 @@ public final class Definitions extends Assignments implements ILocateableNode {
Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
Location tempLocation = temp.getLocation();
Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(tempLocation)) {
if(!tempLocation.equals(cumulativeLocation)) {
reparser.updateLocation(cumulativeLocation);
}
reparser.updateLocation(tempLocation);
}
}
......@@ -979,8 +984,8 @@ public final class Definitions extends Assignments implements ILocateableNode {
for (Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext();) {
Definition temp = iterator.next();
if (reparser.isDamaged(temp.getLocation())) {
reparser.extendDamagedRegion(temp.getLocation());
if (reparser.isDamaged(temp.getCumulativeDefinitionLocation())) {
reparser.extendDamagedRegion(temp.getCumulativeDefinitionLocation());
definitions.remove(temp);
}
}
......
......@@ -409,7 +409,11 @@ public final class For_Loop_Definitions extends Assignments implements ILocateab
for (Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext();) {
Definition temp = iterator.next();
Location temporalLocation = temp.getLocation();
Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(temporalLocation)) {
if(!temporalLocation.equals(cumulativeLocation)) {
reparser.updateLocation(cumulativeLocation);
}
reparser.updateLocation(temporalLocation);
}
}
......@@ -431,24 +435,25 @@ public final class For_Loop_Definitions extends Assignments implements ILocateab
for (Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped;) {
Definition temp = iterator.next();
Location tempLocation = temp.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (tempLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
leftBoundary = cumulativeLocation.getOffset();
rightBoundary = cumulativeLocation.getEndOffset();
} else if (reparser.isDamaged(cumulativeLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == tempLocation.getEndOffset()) {
if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
lastAppendableBeforeChange = temp;
} else if (reparser.getDamageEnd() == tempLocation.getOffset()) {
} else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
lastPrependableBeforeChange = temp;
}
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset() + 1;
if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
leftBoundary = cumulativeLocation.getEndOffset() + 1;
lastAppendableBeforeChange = temp;
}
if (tempLocation.getOffset() >= damageOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
if (cumulativeLocation.getOffset() >= damageOffset && cumulativeLocation.getOffset() < rightBoundary) {
rightBoundary = cumulativeLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
......@@ -495,7 +500,8 @@ public final class For_Loop_Definitions extends Assignments implements ILocateab
for (Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext();) {
Definition temp = iterator.next();
Location temporalLocation = temp.getLocation();
if (reparser.isAffected(temporalLocation)) {
Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(cumulativeLocation)) {
try {
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(temporalLocation));
if (reparser.getNameChanged()) {
......@@ -506,7 +512,7 @@ public final class For_Loop_Definitions extends Assignments implements ILocateab
if (e.getDepth() == 1) {
enveloped = false;
definitions.remove(temp);
reparser.extendDamagedRegion(temporalLocation);
reparser.extendDamagedRegion(cumulativeLocation);
result = 1;
} else {
e.decreaseDepth();
......@@ -524,7 +530,11 @@ public final class For_Loop_Definitions extends Assignments implements ILocateab
for (Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext();) {
Definition temp = iterator.next();
Location temporalLocation = temp.getLocation();
Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(temporalLocation)) {
if(!temporalLocation.equals(cumulativeLocation)) {
reparser.updateLocation(cumulativeLocation);
}
reparser.updateLocation(temporalLocation);
}
}
......@@ -550,8 +560,8 @@ public final class For_Loop_Definitions extends Assignments implements ILocateab
private void removeStuffInRange(final TTCN3ReparseUpdater reparser) {
for (Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext();) {
Definition temp = iterator.next();
if (reparser.isDamaged(temp.getLocation())) {
reparser.extendDamagedRegion(temp.getLocation());
if (reparser.isDamaged(temp.getCumulativeDefinitionLocation())) {
reparser.extendDamagedRegion(temp.getCumulativeDefinitionLocation());
definitions.remove(temp);
}
}
......
......@@ -146,6 +146,9 @@ public final class Definition_Statement extends Statement {
if (definition != null) {
definition.updateSyntax(reparser, false);
reparser.updateLocation(definition.getLocation());
if(!definition.getLocation().equals(definition.getCumulativeDefinitionLocation())) {
reparser.updateLocation(definition.getCumulativeDefinitionLocation());
}
}
}
......
......@@ -1080,25 +1080,31 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
for (int i = 0, size = statements.size(); i < size && !enveloped; i++) {
final Statement statement = statements.get(i);
final Location temporalLocation = statement.getLocation();
Location cumulativeLocation;
if(statement instanceof Definition_Statement) {
cumulativeLocation = ((Definition_Statement) statement).getDefinition().getCumulativeDefinitionLocation();
} else {
cumulativeLocation = temporalLocation;
}
if (reparser.envelopsDamage(temporalLocation)) {
if (temporalLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
enveloped = true;
leftBoundary = temporalLocation.getOffset();
rightBoundary = temporalLocation.getEndOffset();
} else if (reparser.isDamaged(temporalLocation)) {
leftBoundary = cumulativeLocation.getOffset();
rightBoundary = cumulativeLocation.getEndOffset();
} else if (reparser.isDamaged(cumulativeLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == temporalLocation.getEndOffset()) {
if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
lastAppendableBeforeChange = statement;
} else if (reparser.getDamageEnd() == temporalLocation.getOffset()) {
} else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
lastPrependableBeforeChange = statement;
}
} else {
if (temporalLocation.getEndOffset() < damageOffset && temporalLocation.getEndOffset() > leftBoundary) {
leftBoundary = temporalLocation.getEndOffset() + 1;
if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
leftBoundary = cumulativeLocation.getEndOffset() + 1;
lastAppendableBeforeChange = statement;
}
if (temporalLocation.getOffset() >= damageOffset && temporalLocation.getOffset() < rightBoundary) {
rightBoundary = temporalLocation.getOffset();
if (cumulativeLocation.getOffset() >= damageOffset && cumulativeLocation.getOffset() < rightBoundary) {
rightBoundary = cumulativeLocation.getOffset();
lastPrependableBeforeChange = statement;
}
}
......@@ -1141,16 +1147,22 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
for (final Iterator<Statement> iterator = statements.iterator(); iterator.hasNext();) {
final Statement statement = iterator.next();
final Location temporalLocation = statement.getLocation();
Location cumulativeLocation;
if(statement instanceof Definition_Statement) {
cumulativeLocation = ((Definition_Statement) statement).getDefinition().getCumulativeDefinitionLocation();
} else {
cumulativeLocation = temporalLocation;
}
if (reparser.isAffectedAppended(temporalLocation)) {
if (reparser.isAffectedAppended(cumulativeLocation)) {
try {
statement.updateSyntax(reparser, enveloped && reparser.envelopsDamage(temporalLocation));
statement.updateSyntax(reparser, enveloped && reparser.envelopsDamage(cumulativeLocation));
reparser.updateLocation(statement.getLocation());
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
iterator.remove();
reparser.extendDamagedRegion(temporalLocation);
reparser.extendDamagedRegion(cumulativeLocation);
} else {
e.decreaseDepth();
throw e;
......@@ -1183,11 +1195,16 @@ public final class StatementBlock extends TTCN3Scope implements ILocateableNode,
}
private void removeStuffInRange(final TTCN3ReparseUpdater reparser) {
Location temp;
for (int i = statements.size() - 1; i >= 0; i--) {
temp = statements.get(i).getLocation();
if (reparser.isDamaged(temp)) {
reparser.extendDamagedRegion(temp);
final Statement statement = statements.get(i);
Location cumulativeLocation;
if(statement instanceof Definition_Statement) {
cumulativeLocation = ((Definition_Statement) statement).getDefinition().getCumulativeDefinitionLocation();
} else {
cumulativeLocation = statement.getLocation();
}
if (reparser.isDamaged(cumulativeLocation)) {
reparser.extendDamagedRegion(cumulativeLocation);
statements.remove(i);
}
}
......
......@@ -877,6 +877,9 @@ public final class ComponentTypeBody extends TTCN3Scope implements IReferenceCha
for (Definition definition : definitions) {
definition.updateSyntax(reparser, false);
reparser.updateLocation(definition.getLocation());
if(!definition.getLocation().equals(definition.getCumulativeDefinitionLocation())) {
reparser.updateLocation(definition.getCumulativeDefinitionLocation());
}
}
if (extendsReferences != null) {
......
......@@ -636,6 +636,7 @@ pr_ModuleDef returns [List<Definition> definitions]
Location loc = definition.getLocation();
loc.setEndOffset(offset + getStopToken().getStopIndex() + 1);
}
definition.setCumulativeDefinitionLocation(getLocation( $start, getStopToken()));
}
if (commentLocation == null) {
commentLocation = lexer.getLastCommentLocation();
......@@ -1554,12 +1555,14 @@ pr_ComponentElementDef returns[List<Definition> definitions = null]
)
)
{
if ( modifier != null) {
for(int i = 0; i < $definitions.size(); i++) {
Definition definition = $definitions.get(i);
for(int i = 0; i < $definitions.size(); i++) {
Definition definition = $definitions.get(i);
if ( modifier != null) {
definition.setVisibility( modifier );
}
}
definition.setCumulativeDefinitionLocation(getLocation( $start, getStopToken()));
}
};
pr_ComponentElementVisibility returns[VisibilityModifier modifier = VisibilityModifier.Public]:
......@@ -1619,7 +1622,6 @@ pr_ConstDef returns[List<Definition> array = null]:
Location loc = temp.getLocation();
loc.setOffset( offset + $col.start.getStartIndex() );
}
((Def_Const)temp).setComulativeDefinitionLocation(getLocation( $col.start, $a.stop));
}
}
};
......@@ -2487,6 +2489,7 @@ pr_FunctionStatementOrDef returns[List<Statement> statements]
{
if(definitions != null) {
for(Definition definition : definitions) {
definition.setCumulativeDefinitionLocation(getLocation( $start, getStopToken()));
Statement temp_statement = new Definition_Statement(definition);
temp_statement.setLocation(getLocation( $start, getStopToken()));
$statements.add(temp_statement);
......@@ -3033,7 +3036,13 @@ pr_AltstepLocalDef returns[ List<Definition> definitions = null]:
$definitions.add($def.def_template);
}
}
);
)
{
for ( int i = 0; i < $definitions.size(); i++ ) {
Definition definition = $definitions.get(i);
definition.setCumulativeDefinitionLocation(getLocation( $start, getStopToken()));
}
};
pr_AltstepInstance returns[Reference temporalReference = null]:
( t = pr_FunctionInstance { $temporalReference = $t.temporalReference; }
......@@ -3806,6 +3815,7 @@ pr_ControlStatementOrDef returns [List<Statement> statements]
if(definitions != null) {
for(Definition definition : definitions) {
if(definition != null) {
definition.setCumulativeDefinitionLocation(getLocation( $start, getStopToken()));
Statement temp_statement = new Definition_Statement(definition);
temp_statement.setLocation(getLocation( $start, getStopToken()));
$statements.add(temp_statement);
......@@ -6762,6 +6772,10 @@ pr_InitialDefinitions returns[For_Loop_Definitions definitions]
{
if ( $d.definitions != null ) {
$definitions.addDefinitions( $d.definitions );
for ( int i = 0; i < $definitions.getNofAssignments(); i++ ) {
Definition definition = $definitions.getAssignmentByIndex(i);
definition.setCumulativeDefinitionLocation(getLocation( $start, getStopToken()));
}
}
$definitions.setLocation( getLocation( $d.start, $d.stop ) );
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment