Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CUP Eclipse Plugin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Schwarz
CUP Eclipse Plugin
Commits
55068302
Commit
55068302
authored
Feb 23, 2016
by
Michael Schwarz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring to reduce complexity
parent
69f5e1f7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
63 deletions
+69
-63
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/PrecedenceToInsert.java
...www2/cupplugin/conflictresolution/PrecedenceToInsert.java
+32
-0
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ReduceReduceReorder.java
...ww2/cupplugin/conflictresolution/ReduceReduceReorder.java
+2
-2
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ReordersToDo.java
...um/in/www2/cupplugin/conflictresolution/ReordersToDo.java
+25
-0
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ResolutionStrategy.java
...www2/cupplugin/conflictresolution/ResolutionStrategy.java
+8
-0
CupPlugin/src/de/tum/in/www2/cupplugin/views/CupConflictsView.java
.../src/de/tum/in/www2/cupplugin/views/CupConflictsView.java
+2
-61
No files found.
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/PrecedenceToInsert.java
View file @
55068302
...
...
@@ -7,11 +7,16 @@ import java.util.List;
import
java.util.Map.Entry
;
import
java.util.Stack
;
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.ShiftReduceConflict
;
import
de.in.tum.www2.cup.ast.ParserResult
;
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.model.Model
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails
;
public
class
PrecedenceToInsert
extends
GraphHelper
<
terminal
>
implements
ResolutionStrategy
{
...
...
@@ -307,4 +312,31 @@ public class PrecedenceToInsert extends GraphHelper<terminal> implements Resolut
return
false
;
}
}
@Override
public
void
apply
(
IDocument
doc
)
{
try
{
ParserResult
r
=
Model
.
getInstanceForDocument
(
doc
).
getAstModel
();
String
toInsert
=
precsToInsert
();
int
positionForPrec
=
0
;
if
(
r
.
precedences
.
size
()
==
0
)
{
// Precedences are located immediately after the last symbol
// decl
positionForPrec
=
r
.
symbols
.
get
(
r
.
symbols
.
size
()
-
1
).
getEnd
().
getOffsetFromStart
();
toInsert
=
"\n\n//Precedences added by Eclipse plugin\n"
+
toInsert
;
}
else
{
positionForPrec
=
r
.
precedences
.
get
(
0
).
getRange
().
getBegin
().
getOffsetFromStart
();
toInsert
=
toInsert
+
"\n"
;
}
doc
.
replace
(
positionForPrec
,
0
,
toInsert
);
}
catch
(
BadLocationException
e
)
{
e
.
printStackTrace
();
}
catch
(
de
.
tum
.
in
.
www2
.
cupplugin
.
conflictresolution
.
PrecedenceToInsert
.
PrecedenceCyclicException
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ReduceReduceReorder.java
View file @
55068302
...
...
@@ -37,9 +37,9 @@ public class ReduceReduceReorder {
}
}
public
ReduceReduceReorder
(
IDocument
document
,
boolean
flagPresent
){
public
ReduceReduceReorder
(
IDocument
document
){
this
.
document
=
document
;
this
.
flagPresent
=
flagPresent
;
this
.
flagPresent
=
(
document
.
get
().
indexOf
(
CupConflictsView
.
TRESHOLD_STRING
)
!=
-
1
)
;
textToAppend
=
""
;
rangesToRemove
=
new
ArrayList
<>();
}
...
...
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ReordersToDo.java
View file @
55068302
...
...
@@ -7,11 +7,15 @@ import java.util.List;
import
java.util.Map.Entry
;
import
java.util.Stack
;
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.ReduceReduceConflict
;
import
de.in.tum.www2.cup.internal.internal_error
;
import
de.in.tum.www2.cup.internal.lalr_item
;
import
de.in.tum.www2.cup.internal.lr_item_core
;
import
de.tum.in.www2.cupplugin.conflictresolution.ReordersToDo.OrderCyclicException
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails
;
public
class
ReordersToDo
extends
GraphHelper
<
lr_item_core
>
implements
ResolutionStrategy
{
...
...
@@ -204,5 +208,26 @@ public class ReordersToDo extends GraphHelper<lr_item_core> implements Resolutio
public
boolean
isActive
(){
return
edges
.
keySet
().
size
()
!=
0
;
}
@Override
public
void
apply
(
IDocument
doc
)
{
try
{
LinkedList
<
lr_item_core
>
order
=
getItemsOrdered
();
java
.
util
.
Collections
.
reverse
(
order
);
ReduceReduceReorder
rrr
=
new
ReduceReduceReorder
(
doc
);
for
(
lr_item_core
item
:
order
){
rrr
.
moveItemToVeryEnd
(
item
);
}
rrr
.
apply
();
}
catch
(
OrderCyclicException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
BadLocationException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
}
CupPlugin/src/de/tum/in/www2/cupplugin/conflictresolution/ResolutionStrategy.java
View file @
55068302
package
de.tum.in.www2.cupplugin.conflictresolution
;
import
org.eclipse.jface.text.IDocument
;
import
de.in.tum.www2.cup.Conflict
;
import
de.tum.in.www2.cupplugin.views.CupConflictsView.ShiftReduceDetails
;
...
...
@@ -17,4 +19,10 @@ public interface ResolutionStrategy {
* @return
*/
public
abstract
boolean
isActive
();
/**
* Apply the strategy to the file
* @param doc file to which the strategy is to be applied
*/
public
abstract
void
apply
(
IDocument
doc
);
}
CupPlugin/src/de/tum/in/www2/cupplugin/views/CupConflictsView.java
View file @
55068302
...
...
@@ -533,7 +533,6 @@ public class CupConflictsView extends FailableView
* insert to appropriate position and end connected resolution
*/
private
void
applyConnectedResolution
()
{
// Conflicts are part of current connected conflicts that are not
// resolved yet.
for
(
ConflictPanel
p
:
conflictPanels
)
{
...
...
@@ -548,66 +547,8 @@ public class CupConflictsView extends FailableView
}
}
if
(
currentResolution
instanceof
PrecedenceToInsert
){
applyConnectedResolutionSR
();
}
else
{
applyConnectedResolutionRR
();
}
}
private
void
applyConnectedResolutionRR
()
{
try
{
ReordersToDo
rtd
=
(
ReordersToDo
)
currentResolution
;
LinkedList
<
lr_item_core
>
order
=
rtd
.
getItemsOrdered
();
java
.
util
.
Collections
.
reverse
(
order
);
ReduceReduceReorder
rrr
=
new
ReduceReduceReorder
(
editor
.
getDocument
(),
isThresholdPresent
());
for
(
lr_item_core
item
:
order
){
rrr
.
moveItemToVeryEnd
(
item
);
}
rrr
.
apply
();
}
catch
(
OrderCyclicException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
catch
(
BadLocationException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
finally
{
abortConnectedResolution
(
true
);
}
}
private
void
applyConnectedResolutionSR
(){
try
{
IDocument
document
=
editor
.
getDocument
();
ParserResult
r
=
Model
.
getInstanceForDocument
(
document
).
getAstModel
();
String
toInsert
=
getPti
().
precsToInsert
();
int
positionForPrec
=
0
;
if
(
r
.
precedences
.
size
()
==
0
)
{
// Precedences are located immediately after the last symbol
// decl
positionForPrec
=
r
.
symbols
.
get
(
r
.
symbols
.
size
()
-
1
).
getEnd
().
getOffsetFromStart
();
toInsert
=
"\n\n//Precedences added by Eclipse plugin\n"
+
toInsert
;
}
else
{
positionForPrec
=
r
.
precedences
.
get
(
0
).
getRange
().
getBegin
().
getOffsetFromStart
();
toInsert
=
toInsert
+
"\n"
;
}
document
.
replace
(
positionForPrec
,
0
,
toInsert
);
}
catch
(
BadLocationException
e
)
{
e
.
printStackTrace
();
}
catch
(
de
.
tum
.
in
.
www2
.
cupplugin
.
conflictresolution
.
PrecedenceToInsert
.
PrecedenceCyclicException
e
)
{
e
.
printStackTrace
();
}
finally
{
abortConnectedResolution
(
true
);
}
currentResolution
.
apply
(
editor
.
getDocument
());
abortConnectedResolution
(
true
);
}
/**
...
...
Write
Preview
Markdown
is supported
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