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
Dr. Michael Petter
CUP Eclipse Plugin
Commits
3eef45a1
Commit
3eef45a1
authored
Feb 23, 2016
by
Michael Schwarz
🤔
Browse files
Restructering for Reduce/Reduce
parent
69166194
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
CupPlugin/src/de/tum/in/www2/cupplugin/views/ConflictPanel.java
View file @
3eef45a1
This diff is collapsed.
Click to expand it.
CupPlugin/src/de/tum/in/www2/cupplugin/views/CupConflictsView.java
View file @
3eef45a1
...
...
@@ -87,8 +87,8 @@ public class CupConflictsView extends FailableView
private
HashMap
<
terminal
,
Integer
>
terminalsAffectConflicts
;
private
HashMap
<
lr_item_core
,
Integer
>
ordersAffectConflicts
;
PrecedenceToInsert
currentPrecs
;
ResolutionStrategy
currentResolution
;
public
int
ignoreRRAfterLine
;
class
ShiftReduceDetails
{
...
...
@@ -261,7 +261,7 @@ public class CupConflictsView extends FailableView
panel
.
update
(
crm
,
conflict
);
}
if
(
current
Precs
!=
null
&&
current
Precs
.
isActive
())
{
if
(
current
Resolution
!=
null
&&
current
Resolution
.
isActive
())
{
markAllAffected
();
}
...
...
@@ -401,7 +401,7 @@ public class CupConflictsView extends FailableView
@Override
public
void
modelChanged
(
Model
model
)
{
if
(
current
Precs
!=
null
&&
current
Precs
.
isActive
())
{
if
(
current
Resolution
!=
null
&&
current
Resolution
.
isActive
())
{
// Connected resolution does no longer make sense
abortConnectedResolution
(
false
);
}
...
...
@@ -437,7 +437,7 @@ public class CupConflictsView extends FailableView
void
markAllAffected
()
{
int
affected
=
0
;
for
(
ConflictPanel
c
:
conflictPanels
)
{
if
(
c
.
markIfAffected
(
current
Precs
))
{
if
(
c
.
markIfAffected
(
current
Resolution
))
{
affected
++;
}
}
...
...
@@ -446,25 +446,29 @@ public class CupConflictsView extends FailableView
+
affected
+
" conflicts involved)."
);
}
private
PrecedenceToInsert
getPti
(){
return
(
PrecedenceToInsert
)
currentResolution
;
}
void
addFirstPrecedence
(
terminal
t
,
terminal
other
)
{
currentPrecs
.
add
(
t
,
other
);
getPti
()
.
add
(
t
,
other
);
markAllAffected
();
}
void
addFurtherPrecedence
(
terminal
higher
,
terminal
lower
)
throws
PrecedenceCyclicException
{
currentPrecs
.
addPrecedence
(
higher
,
lower
);
getPti
()
.
addPrecedence
(
higher
,
lower
);
markAllAffected
();
}
void
setTerminalAssoc
(
terminal
t
,
Precedence
.
Type
p
)
{
currentPrecs
.
setAssoc
(
t
,
p
);
getPti
()
.
setAssoc
(
t
,
p
);
markAllAffected
();
}
/**
* Set currentPrecs Doesn't mark affected conflicts
*/
void
beginConnectedResolution
()
{
void
beginConnectedResolution
SR
()
{
Shell
shell
=
new
Shell
(
Display
.
getCurrent
());
MessageBox
box
=
new
MessageBox
(
shell
,
SWT
.
ICON_WARNING
|
SWT
.
OK
);
box
.
setText
(
"Information"
);
...
...
@@ -472,7 +476,7 @@ public class CupConflictsView extends FailableView
+
"The effects if no further precedences are inserted are simulated right now."
);
box
.
open
();
current
Precs
=
new
PrecedenceToInsert
();
current
Resolution
=
new
PrecedenceToInsert
();
// Text of label already set in the markAllAffected()
this
.
connectedResolutionLabel
.
setVisible
(
true
);
this
.
connectedResolutionAbort
.
setVisible
(
true
);
...
...
@@ -480,15 +484,31 @@ public class CupConflictsView extends FailableView
refreshScrolledLayout
();
}
void
beginConnectedResolutionRR
(){
Shell
shell
=
new
Shell
(
Display
.
getCurrent
());
MessageBox
box
=
new
MessageBox
(
shell
,
SWT
.
ICON_WARNING
|
SWT
.
OK
);
box
.
setText
(
"Information"
);
box
.
setMessage
(
"This affects some other conflicts. These are marked now. Please resolve all those as well.\n"
+
"The effects if no further orderings are inserted are simulated right now."
);
box
.
open
();
currentResolution
=
new
ReordersToDo
();
// Text of label already set in the markAllAffected()
this
.
connectedResolutionLabel
.
setVisible
(
true
);
this
.
connectedResolutionAbort
.
setVisible
(
true
);
this
.
connectedResolutionApply
.
setVisible
(
true
);
refreshScrolledLayout
();
}
/**
* Abort connected resolution and reset all panels
* Abort connected resolution
(regardless of SR or RR)
and reset all panels
*
* @param refresh
* Refresh UI to make changes visible (true unless panels will
* change later anyway)
*/
private
void
abortConnectedResolution
(
boolean
refresh
)
{
current
Precs
=
new
PrecedenceToInsert
()
;
current
Resolution
=
null
;
this
.
connectedResolutionLabel
.
setVisible
(
false
);
this
.
connectedResolutionAbort
.
setVisible
(
false
);
this
.
connectedResolutionApply
.
setVisible
(
false
);
...
...
@@ -521,12 +541,25 @@ public class CupConflictsView extends FailableView
return
;
}
}
if
(
currentResolution
instanceof
PrecedenceToInsert
){
applyConnectedResolutionSR
();
}
else
{
applyConnectedResolutionRR
();
}
}
private
void
applyConnectedResolutionRR
(){
}
private
void
applyConnectedResolutionSR
(){
try
{
IDocument
document
=
editor
.
getDocument
();
ParserResult
r
=
Model
.
getInstanceForDocument
(
document
).
getAstModel
();
String
toInsert
=
currentPrecs
.
precsToInsert
();
String
toInsert
=
getPti
()
.
precsToInsert
();
int
positionForPrec
=
0
;
if
(
r
.
precedences
.
size
()
==
0
)
{
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/views/GraphHelper.java
View file @
3eef45a1
...
...
@@ -8,14 +8,16 @@ import java.util.Set;
import
java.util.Stack
;
import
java.util.Map.Entry
;
import
de.in.tum.www2.cup.Conflict
;
import
de.in.tum.www2.cup.internal.terminal
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails
;
public
class
GraphHelper
<
X
>
{
public
abstract
class
GraphHelper
<
X
>
{
// Edges are stored in reverse order (i.e. there is a edge from a to b iff b has a explicit
// higher precedence / order in general than a
protected
HashMap
<
X
,
Set
<
X
>>
edges
;
p
ublic
class
TarjanNodeInfo
{
p
rotected
class
TarjanNodeInfo
{
public
int
index
;
public
boolean
onStack
;
public
int
lowlink
;
...
...
@@ -124,5 +126,4 @@ public class GraphHelper<X> {
return
false
;
}
}
\ No newline at end of file
CupPlugin/src/de/tum/in/www2/cupplugin/views/PrecedenceToInsert.java
View file @
3eef45a1
...
...
@@ -9,13 +9,16 @@ import java.util.Set;
import
java.util.Stack
;
import
java.util.Map.Entry
;
import
de.in.tum.www2.cup.Conflict
;
import
de.in.tum.www2.cup.ReduceReduceConflict
;
import
de.in.tum.www2.cup.ShiftReduceConflict
;
import
de.in.tum.www2.cup.ast.Precedence
;
import
de.in.tum.www2.cup.internal.terminal
;
import
de.tum.in.www2.cupplugin.Pair
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails
;
import
de.tum.in.www2.cupplugin.views.GraphHelper.TarjanNodeInfo
;
class
PrecedenceToInsert
extends
GraphHelper
<
terminal
>{
class
PrecedenceToInsert
extends
GraphHelper
<
terminal
>
implements
ResolutionStrategy
{
private
HashMap
<
terminal
,
Precedence
.
Type
>
precs
=
new
HashMap
<>();
// These need to be inserted whenever an edge that contains the key is to be inserted
...
...
@@ -294,11 +297,18 @@ class PrecedenceToInsert extends GraphHelper<terminal>{
}
}
/**
* Check if active (i.e. more than 0 precedences)
* @return
*/
@Override
public
boolean
isActive
(){
return
precs
.
size
()
!=
0
;
}
@Override
public
boolean
isAffected
(
Conflict
c
,
ShiftReduceDetails
details
)
{
if
(
c
instanceof
ShiftReduceConflict
&&
isAffected
(
details
)){
return
true
;
}
else
{
return
false
;
}
}
}
\ No newline at end of file
CupPlugin/src/de/tum/in/www2/cupplugin/views/ReordersToDo.java
View file @
3eef45a1
...
...
@@ -7,6 +7,9 @@ import java.util.List;
import
java.util.Stack
;
import
java.util.Map.Entry
;
import
de.in.tum.www2.cup.Conflict
;
import
de.in.tum.www2.cup.ReduceReduceConflict
;
import
de.in.tum.www2.cup.ShiftReduceConflict
;
import
de.in.tum.www2.cup.ast.Precedence
;
import
de.in.tum.www2.cup.internal.internal_error
;
import
de.in.tum.www2.cup.internal.lalr_item
;
...
...
@@ -14,9 +17,10 @@ import de.in.tum.www2.cup.internal.lr_item_core;
import
de.in.tum.www2.cup.internal.terminal
;
import
de.tum.in.www2.cupplugin.Pair
;
import
de.tum.in.www2.cupplugin.views.GraphHelper.TarjanNodeInfo
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails
;
import
de.tum.in.www2.cupplugin.views.PrecedenceToInsert.PrecedenceCyclicException
;
public
class
ReordersToDo
extends
GraphHelper
<
lr_item_core
>{
public
class
ReordersToDo
extends
GraphHelper
<
lr_item_core
>
implements
ResolutionStrategy
{
private
LinkedList
<
lr_item_core
>
result
;
public
ReordersToDo
(){
...
...
@@ -190,6 +194,21 @@ public class ReordersToDo extends GraphHelper<lr_item_core>{
return
result
;
}
@Override
public
boolean
isAffected
(
Conflict
c
,
ShiftReduceDetails
details
)
{
if
(
c
instanceof
ReduceReduceConflict
){
ReduceReduceConflict
rrc
=
(
ReduceReduceConflict
)
c
;
return
isAffected
(
rrc
.
getConflictItem1
(),
rrc
.
getConflictItem2
());
}
else
{
return
false
;
}
}
@Override
public
boolean
isActive
(){
return
edges
.
keySet
().
size
()
!=
0
;
}
}
CupPlugin/src/de/tum/in/www2/cupplugin/views/ResolutionStrategy.java
0 → 100644
View file @
3eef45a1
package
de.tum.in.www2.cupplugin.views
;
import
de.in.tum.www2.cup.Conflict
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails
;
public
interface
ResolutionStrategy
{
/**
* return true iff the conflict is affected
* @param c Conflict
* @param details details if conflict is Shiftreduce, null otherwise
* @return true iff conflict is affected
*/
public
abstract
boolean
isAffected
(
Conflict
c
,
ShiftReduceDetails
details
);
/**
* Check if active (i.e. more than 0 item)
* @return
*/
public
abstract
boolean
isActive
();
}
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