Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michael Schwarz
CUP Eclipse Plugin
Commits
0a6fa6b6
Commit
0a6fa6b6
authored
Feb 23, 2016
by
Michael Schwarz
🤔
Browse files
Refactoring. Also everywhere correct conflict count
parent
42e5f1d1
Changes
5
Hide whitespace changes
Inline
Side-by-side
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ConflictFilter.java
0 → 100644
View file @
0a6fa6b6
package
de.tum.in.www2.cupplugin.conflictresolution
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.eclipse.jface.text.BadLocationException
;
import
org.eclipse.jface.text.IDocument
;
import
de.in.tum.www2.cup.Conflict
;
import
de.in.tum.www2.cup.ConflictResolutionManager
;
import
de.in.tum.www2.cup.ReduceReduceConflict
;
public
class
ConflictFilter
{
public
static
final
String
TRESHOLD_STRING
=
"~~ CUP-ECLIPSE:CONFLICT-RES-RR ~~ "
;
private
IDocument
document
;
private
int
ignored
=
0
;
/**
*
* @param document document that contains specification
*/
public
ConflictFilter
(
IDocument
document
){
this
.
document
=
document
;
}
/**
* Get list of all conflicts from the CRM that are not resolved
* (resolved here means ignored because order was specified)
* @param crm ConflictResolutionManager
* @return list of conflicts that are yet to be resolved
*/
public
List
<
Conflict
>
getConflictsNotResolved
(
ConflictResolutionManager
crm
){
ignored
=
0
;
ArrayList
<
Conflict
>
conflicts
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
crm
.
getAllConflicts
().
size
();
i
++)
{
Conflict
c
=
crm
.
getAllConflicts
().
get
(
i
);
if
(!
isIgnored
(
c
))
{
conflicts
.
add
(
c
);
}
else
{
ignored
++;
}
}
return
conflicts
;
}
/**
* Get the number of conflicts in the last crm that was "resolved"
* Only meaningful after call to getConflictsNotResolved(...)
* @return number of conflicts resolved
*/
public
int
getResolvedCountLastRun
(){
return
ignored
;
}
private
boolean
isIgnored
(
Conflict
c
)
{
if
(
c
instanceof
ReduceReduceConflict
)
{
ReduceReduceConflict
rrc
=
(
ReduceReduceConflict
)
c
;
int
ignoreRRAfterLine
=
computeIgnoreRRAfter
();
return
((
ignoreRRAfterLine
>=
0
)
&&
(
rrc
.
getConflictItem1
().
the_production
().
getAstNode
().
getEnd
().
getLine
()
>
ignoreRRAfterLine
)
&&
(
rrc
.
getConflictItem2
().
the_production
().
getAstNode
().
getEnd
().
getLine
()
>
ignoreRRAfterLine
));
}
else
{
return
false
;
}
}
private
int
computeIgnoreRRAfter
()
{
int
offset
=
document
.
get
().
indexOf
(
TRESHOLD_STRING
);
if
(
offset
==
-
1
)
{
return
-
1
;
}
try
{
return
document
.
getLineOfOffset
(
offset
)
+
1
;
}
catch
(
BadLocationException
e
)
{
return
-
1
;
}
}
}
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ReduceReduceReorder.java
View file @
0a6fa6b6
...
...
@@ -12,7 +12,6 @@ import de.in.tum.www2.cup.ast.Production;
import
de.in.tum.www2.cup.ast.ProductionRight
;
import
de.in.tum.www2.cup.internal.lr_item_core
;
import
de.tum.in.www2.cupplugin.model.Model
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView
;
public
class
ReduceReduceReorder
{
IDocument
document
;
...
...
@@ -39,7 +38,7 @@ public class ReduceReduceReorder {
public
ReduceReduceReorder
(
IDocument
document
){
this
.
document
=
document
;
this
.
flagPresent
=
(
document
.
get
().
indexOf
(
Cup
Conflict
sView
.
TRESHOLD_STRING
)
!=
-
1
);
this
.
flagPresent
=
(
document
.
get
().
indexOf
(
Conflict
Filter
.
TRESHOLD_STRING
)
!=
-
1
);
textToAppend
=
""
;
rangesToRemove
=
new
ArrayList
<>();
}
...
...
@@ -130,7 +129,7 @@ public class ReduceReduceReorder {
}
if
(!
flagPresent
){
toInsert
=
"\n\n// "
+
Cup
Conflict
sView
.
TRESHOLD_STRING
+
"\n // After this the order of productions matters"
+
toInsert
;
toInsert
=
"\n\n// "
+
Conflict
Filter
.
TRESHOLD_STRING
+
"\n // After this the order of productions matters"
+
toInsert
;
flagPresent
=
true
;
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/editors/MultiPageEditor.java
View file @
0a6fa6b6
...
...
@@ -31,6 +31,7 @@ import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart;
import
org.eclipse.zest.core.viewers.ZoomContributionViewItem
;
import
de.in.tum.www2.cup.ConflictManager
;
import
de.in.tum.www2.cup.ConflictResolutionManager
;
import
de.in.tum.www2.cup.CupContext
;
import
de.in.tum.www2.cup.LALRResult
;
import
de.in.tum.www2.cup.internal.parse_action
;
...
...
@@ -38,6 +39,7 @@ import de.in.tum.www2.cup.internal.parse_action_row;
import
de.in.tum.www2.cup.internal.parse_action_table
;
import
de.in.tum.www2.cup.internal.parse_reduce_row
;
import
de.in.tum.www2.cup.internal.parse_reduce_table
;
import
de.tum.in.www2.cupplugin.conflictresolution.ConflictFilter
;
import
de.tum.in.www2.cupplugin.controller.Controller
;
import
de.tum.in.www2.cupplugin.controller.Controller.JobsToDo
;
import
de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges
;
...
...
@@ -400,8 +402,10 @@ public class MultiPageEditor extends MultiPageEditorPart implements
CupContext
ctx
=
model
.
getLaLrContext
();
if
(
result
==
null
)
return
;
ConflictManager
cm
=
result
.
getContext
().
getConflictManager
();
setCounter
(
CONFLICTS_PAGE_INDEX
,
cm
.
getConflicts
().
size
());
ConflictFilter
cf
=
new
ConflictFilter
(
editor
.
getDocument
());
ConflictResolutionManager
crm
=
new
ConflictResolutionManager
(
ctx
);
setCounter
(
CONFLICTS_PAGE_INDEX
,
cf
.
getConflictsNotResolved
(
crm
).
size
());
parse_action_table
actionTable
=
result
.
getActionTable
();
if
(
actionTable
!=
null
)
{
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/views/CupConflictsView.java
View file @
0a6fa6b6
...
...
@@ -47,6 +47,7 @@ import de.in.tum.www2.cup.internal.internal_error;
import
de.in.tum.www2.cup.internal.lr_item_core
;
import
de.in.tum.www2.cup.internal.terminal
;
import
de.tum.in.www2.cupplugin.Colors
;
import
de.tum.in.www2.cupplugin.conflictresolution.ConflictFilter
;
import
de.tum.in.www2.cupplugin.conflictresolution.PrecedenceToInsert
;
import
de.tum.in.www2.cupplugin.conflictresolution.PrecedenceToInsert.PrecedenceCyclicException
;
import
de.tum.in.www2.cupplugin.conflictresolution.ReduceReduceReorder
;
...
...
@@ -69,8 +70,6 @@ public class CupConflictsView extends FailableView
private
static
final
int
OUTER_MARGIN
=
10
;
static
final
int
INNER_MARGIN
=
5
;
public
static
final
String
TRESHOLD_STRING
=
"~~ CUP-ECLIPSE:CONFLICT-RES-RR ~~ "
;
Jumper
jumper
;
private
CupTextEditor
editor
;
private
boolean
isVisible
;
...
...
@@ -228,24 +227,17 @@ public class CupConflictsView extends FailableView
}
private
void
updateConflicts
(
ConflictResolutionManager
crm
)
{
ignoreRRAfterLine
=
computeIgnoreRRAfter
();
List
<
Conflict
>
conflicts
=
new
ArrayList
<>();
ConflictFilter
cf
=
new
ConflictFilter
(
editor
.
getDocument
());
List
<
Conflict
>
conflicts
=
cf
.
getConflictsNotResolved
(
crm
);
int
size
=
conflicts
.
size
();
terminalsAffectConflicts
=
new
HashMap
<>();
ordersAffectConflicts
=
new
HashMap
<>();
int
ignored
=
0
;
for
(
int
i
=
0
;
i
<
crm
.
getAllConflicts
().
size
();
i
++)
{
Conflict
c
=
crm
.
getAllConflicts
().
get
(
i
);
if
(!
isIgnored
(
c
))
{
conflicts
.
add
(
c
);
addToTerminalSet
(
crm
,
c
);
addToOrderSet
(
c
);
}
else
{
ignored
++;
}
for
(
Conflict
c
:
conflicts
){
addToTerminalSet
(
crm
,
c
);
addToOrderSet
(
c
);
}
int
size
=
conflicts
.
size
();
// Do this less often
// updateBuildfile(ignored);
...
...
@@ -321,7 +313,6 @@ public class CupConflictsView extends FailableView
incrementOrSetTo1
(
ordersAffectConflicts
,
item1
);
incrementOrSetTo1
(
ordersAffectConflicts
,
item2
);
}
catch
(
internal_error
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
...
...
@@ -472,7 +463,8 @@ public class CupConflictsView extends FailableView
}
/**
* Set currentPrecs Doesn't mark affected conflicts
* Start connected resolution
* Doesn't mark affected conflicts
*/
void
beginConnectedResolutionSR
()
{
Shell
shell
=
new
Shell
(
Display
.
getCurrent
());
...
...
@@ -490,6 +482,10 @@ public class CupConflictsView extends FailableView
refreshScrolledLayout
();
}
/**
* Start connected resolution
* Doesn't mark affected conflicts
*/
void
beginConnectedResolutionRR
(){
Shell
shell
=
new
Shell
(
Display
.
getCurrent
());
MessageBox
box
=
new
MessageBox
(
shell
,
SWT
.
ICON_WARNING
|
SWT
.
OK
);
...
...
@@ -586,10 +582,6 @@ public class CupConflictsView extends FailableView
}
}
boolean
isThresholdPresent
()
{
return
(
ignoreRRAfterLine
!=
-
1
);
}
boolean
settingOrderAffetsOtherConflicts
(
lr_item_core
item1
,
lr_item_core
item2
)
{
Integer
affected
=
ordersAffectConflicts
.
get
(
item1
);
...
...
@@ -605,33 +597,6 @@ public class CupConflictsView extends FailableView
}
}
private
int
computeIgnoreRRAfter
()
{
IDocument
document
=
editor
.
getDocument
();
int
offset
=
document
.
get
().
indexOf
(
TRESHOLD_STRING
);
if
(
offset
==
-
1
)
{
return
-
1
;
}
try
{
return
document
.
getLineOfOffset
(
offset
)
+
1
;
}
catch
(
BadLocationException
e
)
{
return
-
1
;
}
}
private
boolean
isIgnored
(
Conflict
c
)
{
if
(
c
instanceof
ReduceReduceConflict
)
{
ReduceReduceConflict
rrc
=
(
ReduceReduceConflict
)
c
;
return
((
ignoreRRAfterLine
>=
0
)
&&
(
rrc
.
getConflictItem1
().
the_production
().
getAstNode
().
getEnd
().
getLine
()
>
ignoreRRAfterLine
)
&&
(
rrc
.
getConflictItem2
().
the_production
().
getAstNode
().
getEnd
().
getLine
()
>
ignoreRRAfterLine
));
}
else
{
return
false
;
}
}
public
IDocument
getDocument
()
{
return
editor
.
getDocument
();
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/views/CupOverviewView.java
View file @
0a6fa6b6
...
...
@@ -26,6 +26,7 @@ import de.in.tum.www2.cup.analysis.StatisticsVisitor;
import
de.in.tum.www2.cup.ast.ParserResult
;
import
de.tum.in.www2.cupplugin.Colors
;
import
de.tum.in.www2.cupplugin.Pair
;
import
de.tum.in.www2.cupplugin.conflictresolution.ConflictFilter
;
import
de.tum.in.www2.cupplugin.controller.ControllerStatistics
;
import
de.tum.in.www2.cupplugin.editors.CupTextEditor
;
import
de.tum.in.www2.cupplugin.editors.ICupEditorPageVisibility
;
...
...
@@ -121,6 +122,7 @@ public class CupOverviewView extends FailableView
private
static
final
int
CONFLICTS_TOTAL
=
0
;
private
static
final
int
CONFLICTS_SR
=
1
;
private
static
final
int
CONFLICTS_RR
=
2
;
private
static
final
int
CONFLICTS_RR_RESOLVED
=
3
;
private
static
final
int
DEBUGGER_TARGET_FILE
=
0
;
private
static
final
int
DEBUGGER_BREAKPOINTS
=
1
;
...
...
@@ -177,10 +179,11 @@ public class CupOverviewView extends FailableView
st
.
setRowLabel
(
STATUS_PRODUCTION_NOTREDUCED
,
"Not reduced Productions:"
);
st
.
setRowLabel
(
STATUS_ERRORS
,
"Errors:"
);
conflictsSection
=
createTableSection
(
"Unresolved conflicts"
,
""
,
false
,
3
);
conflictsSection
=
createTableSection
(
"Unresolved conflicts"
,
""
,
false
,
4
);
conflictsSection
.
getSecond
().
setRowLabel
(
CONFLICTS_TOTAL
,
"Total:"
);
conflictsSection
.
getSecond
().
setRowLabel
(
CONFLICTS_SR
,
"Shift/Reduce:"
);
conflictsSection
.
getSecond
().
setRowLabel
(
CONFLICTS_RR
,
"Reduce/Reduce:"
);
conflictsSection
.
getSecond
().
setRowLabel
(
CONFLICTS_RR_RESOLVED
,
"Resolved Reduce/Reduce:"
);
debuggerSection
=
createTableSection
(
"Debugger"
,
""
,
false
,
2
);
...
...
@@ -282,18 +285,7 @@ public class CupOverviewView extends FailableView
visible
=
false
;
System
.
out
.
println
(
"CupOverviewView became hidden."
);
}
/*
@Override
public EnumSet<JobsToDo> getRequiredJobs() {
// we never request jobs ourselves.
return EnumSet.noneOf(JobsToDo.class);
}
@Override
public void jobStatusChanged(JobStatus status) {
// do nothing
}
*/
private
void
updateStatistics
()
{
boolean
commonSectionNeedsLayout
=
false
;
if
(
this
.
ast
!=
null
)
{
...
...
@@ -364,8 +356,10 @@ public class CupOverviewView extends FailableView
if
(
this
.
crm
!=
null
){
SimpleTable
tbl
=
conflictsSection
.
getSecond
();
ConflictFilter
cf
=
new
ConflictFilter
(
editor
.
getDocument
());
int
sr
=
0
,
rr
=
0
;
for
(
Conflict
c
:
c
rm
.
get
All
Conflicts
(
)){
for
(
Conflict
c
:
c
f
.
getConflicts
NotResolved
(
crm
)){
if
(
c
instanceof
ShiftReduceConflict
){
sr
++;
}
else
{
...
...
@@ -376,6 +370,7 @@ public class CupOverviewView extends FailableView
tbl
.
setRowValue
(
CONFLICTS_TOTAL
,
sr
+
rr
);
tbl
.
setRowValue
(
CONFLICTS_SR
,
sr
);
tbl
.
setRowValue
(
CONFLICTS_RR
,
rr
);
tbl
.
setRowValue
(
CONFLICTS_RR_RESOLVED
,
cf
.
getResolvedCountLastRun
());
conflictsSection
.
getFirst
().
layout
();
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment